Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/servers/rendering/renderer_rd/effects/metal_fx.h
21520 views
1
/**************************************************************************/
2
/* metal_fx.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#if defined(METAL_ENABLED) && !defined(VISIONOS_ENABLED)
34
#define METAL_MFXTEMPORAL_ENABLED
35
#endif
36
37
#ifdef METAL_ENABLED
38
39
#include "spatial_upscaler.h"
40
41
#include "core/templates/paged_allocator.h"
42
#include "servers/rendering/renderer_scene_render.h"
43
44
namespace MTLFX {
45
class SpatialScalerBase;
46
class TemporalScalerBase;
47
} //namespace MTLFX
48
49
namespace RendererRD {
50
51
struct MFXSpatialContext {
52
MTLFX::SpatialScalerBase *scaler = nullptr;
53
MFXSpatialContext() = default;
54
~MFXSpatialContext();
55
};
56
57
class MFXSpatialEffect : public SpatialUpscaler {
58
struct CallbackArgs {
59
MFXSpatialEffect *owner = nullptr;
60
MTLFX::SpatialScalerBase *scaler = nullptr;
61
RDD::TextureID src;
62
RDD::TextureID dst;
63
64
CallbackArgs(MFXSpatialEffect *p_owner, RDD::TextureID p_src, RDD::TextureID p_dst, const MFXSpatialContext &p_ctx) :
65
owner(p_owner), scaler(p_ctx.scaler), src(p_src), dst(p_dst) {}
66
67
static void free(CallbackArgs **p_args) {
68
(*p_args)->owner->args_allocator.free(*p_args);
69
*p_args = nullptr;
70
}
71
};
72
73
PagedAllocator<CallbackArgs, true, 16> args_allocator;
74
static void callback(RDD *p_driver, RDD::CommandBufferID p_command_buffer, CallbackArgs *p_userdata);
75
76
public:
77
virtual const Span<char> get_label() const final { return "MetalFX Spatial Upscale"; }
78
virtual void ensure_context(Ref<RenderSceneBuffersRD> p_render_buffers) final;
79
virtual void process(Ref<RenderSceneBuffersRD> p_render_buffers, RID p_src, RID p_dst) final;
80
81
struct CreateParams {
82
Vector2i input_size;
83
Vector2i output_size;
84
RD::DataFormat input_format;
85
RD::DataFormat output_format;
86
};
87
88
MFXSpatialContext *create_context(CreateParams p_params) const;
89
90
MFXSpatialEffect();
91
~MFXSpatialEffect();
92
};
93
94
#ifdef METAL_MFXTEMPORAL_ENABLED
95
96
struct MFXTemporalContext {
97
MTLFX::TemporalScalerBase *scaler = nullptr;
98
MFXTemporalContext() = default;
99
~MFXTemporalContext();
100
};
101
102
class MFXTemporalEffect {
103
struct CallbackArgs {
104
MFXTemporalEffect *owner = nullptr;
105
MTLFX::TemporalScalerBase *scaler = nullptr;
106
RDD::TextureID src;
107
RDD::TextureID depth;
108
RDD::TextureID motion;
109
RDD::TextureID exposure;
110
Vector2 jitter_offset;
111
RDD::TextureID dst;
112
bool reset = false;
113
114
CallbackArgs(
115
MFXTemporalEffect *p_owner,
116
RDD::TextureID p_src,
117
RDD::TextureID p_depth,
118
RDD::TextureID p_motion,
119
RDD::TextureID p_exposure,
120
Vector2 p_jitter_offset,
121
RDD::TextureID p_dst,
122
const MFXTemporalContext &p_ctx,
123
bool p_reset) :
124
owner(p_owner),
125
scaler(p_ctx.scaler),
126
src(p_src),
127
depth(p_depth),
128
motion(p_motion),
129
exposure(p_exposure),
130
jitter_offset(p_jitter_offset),
131
dst(p_dst),
132
reset(p_reset) {}
133
134
static void free(CallbackArgs **p_args) {
135
(*p_args)->owner->args_allocator.free(*p_args);
136
*p_args = nullptr;
137
}
138
};
139
140
PagedAllocator<CallbackArgs, true, 16> args_allocator;
141
142
static void callback(RDD *p_driver, RDD::CommandBufferID p_command_buffer, CallbackArgs *p_userdata);
143
144
public:
145
MFXTemporalEffect();
146
~MFXTemporalEffect();
147
148
struct CreateParams {
149
Vector2i input_size;
150
Vector2i output_size;
151
RD::DataFormat input_format;
152
RD::DataFormat depth_format;
153
RD::DataFormat motion_format;
154
RD::DataFormat reactive_format;
155
RD::DataFormat output_format;
156
Vector2 motion_vector_scale;
157
};
158
159
MFXTemporalContext *create_context(CreateParams p_params) const;
160
161
struct Params {
162
RID src;
163
RID depth;
164
RID motion;
165
RID exposure;
166
RID dst;
167
Vector2 jitter_offset;
168
bool reset = false;
169
};
170
171
void process(MFXTemporalContext *p_ctx, Params p_params);
172
};
173
174
#endif
175
176
} //namespace RendererRD
177
178
#endif // METAL_ENABLED
179
180