Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/dep/reshadefx/include/effect_module.hpp
4246 views
1
/*
2
* Copyright (C) 2014 Patrick Mours
3
* SPDX-License-Identifier: BSD-3-Clause
4
*/
5
6
#pragma once
7
8
#include "effect_expression.hpp"
9
#include <cstdint>
10
11
namespace reshadefx
12
{
13
/// <summary>
14
/// Describes an annotation attached to a variable.
15
/// </summary>
16
struct annotation
17
{
18
reshadefx::type type = {};
19
std::string name;
20
reshadefx::constant value = {};
21
};
22
23
/// <summary>
24
/// Describes a struct member or parameter.
25
/// </summary>
26
struct member_type
27
{
28
reshadefx::type type = {};
29
uint32_t id = 0;
30
std::string name;
31
std::string semantic;
32
reshadefx::location location;
33
bool has_default_value = false;
34
reshadefx::constant default_value = {};
35
};
36
37
/// <summary>
38
/// Describes a struct type defined in effect code.
39
/// </summary>
40
struct struct_type
41
{
42
uint32_t id = 0;
43
std::string name;
44
std::string unique_name;
45
std::vector<member_type> member_list;
46
};
47
48
/// <summary>
49
/// Available texture types.
50
/// </summary>
51
enum class texture_type : uint8_t
52
{
53
texture_1d = 1,
54
texture_2d = 2,
55
texture_3d = 3
56
};
57
58
/// <summary>
59
/// Available texture formats.
60
/// </summary>
61
enum class texture_format : uint8_t
62
{
63
unknown,
64
65
r8,
66
r16,
67
r16f,
68
r32i,
69
r32u,
70
r32f,
71
rg8,
72
rg16,
73
rg16f,
74
rg32f,
75
rgba8,
76
rgba16,
77
rgba16f,
78
rgba32f,
79
rgb10a2
80
};
81
82
/// <summary>
83
/// Describes the properties of a <see cref="texture"/> object.
84
/// </summary>
85
struct texture_desc
86
{
87
uint32_t width = 1;
88
uint32_t height = 1;
89
uint16_t depth = 1;
90
uint16_t levels = 1;
91
texture_type type = texture_type::texture_2d;
92
texture_format format = texture_format::rgba8;
93
};
94
95
/// <summary>
96
/// Describes a texture object defined in effect code.
97
/// </summary>
98
struct texture : texture_desc
99
{
100
uint32_t id = 0;
101
std::string name;
102
std::string unique_name;
103
std::string semantic;
104
std::vector<annotation> annotations;
105
bool render_target = false;
106
bool storage_access = false;
107
};
108
109
/// <summary>
110
/// Describes the binding of a <see cref="texture"/> object.
111
/// </summary>
112
struct texture_binding
113
{
114
uint32_t binding = 0;
115
std::string texture_name;
116
bool srgb = false;
117
};
118
119
/// <summary>
120
/// Texture filtering modes available for texture sampling operations.
121
/// </summary>
122
enum class filter_mode : uint8_t
123
{
124
min_mag_mip_point = 0,
125
min_mag_point_mip_linear = 0x1,
126
min_point_mag_linear_mip_point = 0x4,
127
min_point_mag_mip_linear = 0x5,
128
min_linear_mag_mip_point = 0x10,
129
min_linear_mag_point_mip_linear = 0x11,
130
min_mag_linear_mip_point = 0x14,
131
min_mag_mip_linear = 0x15,
132
anisotropic = 0x55
133
};
134
135
/// <summary>
136
/// Sampling behavior at texture coordinates outside the bounds of a texture resource.
137
/// </summary>
138
enum class texture_address_mode : uint8_t
139
{
140
wrap = 1,
141
mirror = 2,
142
clamp = 3,
143
border = 4
144
};
145
146
/// <summary>
147
/// Describes the properties of a <see cref="sampler"/> object.
148
/// </summary>
149
struct sampler_desc
150
{
151
filter_mode filter = filter_mode::min_mag_mip_linear;
152
texture_address_mode address_u = texture_address_mode::clamp;
153
texture_address_mode address_v = texture_address_mode::clamp;
154
texture_address_mode address_w = texture_address_mode::clamp;
155
float min_lod = -3.402823466e+38f;
156
float max_lod = +3.402823466e+38f; // FLT_MAX
157
float lod_bias = 0.0f;
158
};
159
160
/// <summary>
161
/// Describes a texture sampler object defined in effect code.
162
/// </summary>
163
struct sampler : sampler_desc
164
{
165
reshadefx::type type = {};
166
uint32_t id = 0;
167
std::string name;
168
std::string unique_name;
169
std::string texture_name;
170
std::vector<annotation> annotations;
171
bool srgb = false;
172
};
173
174
/// <summary>
175
/// Describes the binding of a <see cref="sampler"/> object.
176
/// </summary>
177
struct sampler_binding : sampler_desc
178
{
179
uint32_t binding = 0;
180
};
181
182
/// <summary>
183
/// Describes the properties of a <see cref="storage"/> object.
184
/// </summary>
185
struct storage_desc
186
{
187
uint16_t level = 0;
188
};
189
190
/// <summary>
191
/// Describes a texture storage object defined in effect code.
192
/// </summary>
193
struct storage : storage_desc
194
{
195
reshadefx::type type = {};
196
uint32_t id = 0;
197
std::string name;
198
std::string unique_name;
199
std::string texture_name;
200
};
201
202
/// <summary>
203
/// Describes the binding of a <see cref="storage"/> object.
204
/// </summary>
205
struct storage_binding : storage_desc
206
{
207
uint32_t binding = 0;
208
std::string texture_name;
209
};
210
211
/// <summary>
212
/// Describes a uniform variable defined in effect code.
213
/// </summary>
214
struct uniform
215
{
216
reshadefx::type type = {};
217
std::string name;
218
uint32_t size = 0;
219
uint32_t offset = 0;
220
std::vector<annotation> annotations;
221
bool has_initializer_value = false;
222
reshadefx::constant initializer_value = {};
223
};
224
225
/// <summary>
226
/// Type of a shader entry point.
227
/// </summary>
228
enum class shader_type
229
{
230
unknown,
231
vertex,
232
pixel,
233
compute
234
};
235
236
/// <summary>
237
/// Describes a function defined in effect code.
238
/// </summary>
239
struct function
240
{
241
reshadefx::type return_type = {};
242
uint32_t id = 0;
243
std::string name;
244
std::string unique_name;
245
std::string return_semantic;
246
std::vector<member_type> parameter_list;
247
shader_type type = shader_type::unknown;
248
int num_threads[3] = {};
249
std::vector<uint32_t> referenced_samplers;
250
std::vector<uint32_t> referenced_storages;
251
std::vector<uint32_t> referenced_functions;
252
};
253
254
/// <summary>
255
/// Color or alpha blending operations.
256
/// </summary>
257
enum class blend_op : uint8_t
258
{
259
add = 1,
260
subtract,
261
reverse_subtract,
262
min,
263
max
264
};
265
266
/// <summary>
267
/// Blend factors in color or alpha blending operations, which modulate values between the pixel shader output and render target.
268
/// </summary>
269
enum class blend_factor : uint8_t
270
{
271
zero = 0,
272
one = 1,
273
source_color,
274
one_minus_source_color,
275
dest_color,
276
one_minus_dest_color,
277
source_alpha,
278
one_minus_source_alpha,
279
dest_alpha,
280
one_minus_dest_alpha
281
};
282
283
/// <summary>
284
/// Stencil operations that can be performed during depth-stencil testing.
285
/// </summary>
286
enum class stencil_op : uint8_t
287
{
288
zero = 0,
289
keep,
290
replace,
291
increment_saturate,
292
decrement_saturate,
293
invert,
294
increment,
295
decrement
296
};
297
298
/// <summary>
299
/// Comparison operations for depth-stencil testing.
300
/// </summary>
301
enum class stencil_func : uint8_t
302
{
303
never,
304
less,
305
equal,
306
less_equal,
307
greater,
308
not_equal,
309
greater_equal,
310
always
311
};
312
313
/// <summary>
314
/// Specifies the possible primitives.
315
/// </summary>
316
enum class primitive_topology : uint8_t
317
{
318
point_list = 1,
319
line_list,
320
line_strip,
321
triangle_list,
322
triangle_strip
323
};
324
325
/// <summary>
326
/// Describes a render pass with all its state info.
327
/// </summary>
328
struct pass
329
{
330
std::string name;
331
std::string render_target_names[8] = {};
332
std::string vs_entry_point;
333
std::string ps_entry_point;
334
std::string cs_entry_point;
335
bool generate_mipmaps = true;
336
bool clear_render_targets = false;
337
bool blend_enable[8] = { false, false, false, false, false, false, false, false };
338
blend_factor source_color_blend_factor[8] = { blend_factor::one, blend_factor::one, blend_factor::one, blend_factor::one, blend_factor::one, blend_factor::one, blend_factor::one, blend_factor::one };
339
blend_factor dest_color_blend_factor[8] = { blend_factor::zero, blend_factor::zero, blend_factor::zero, blend_factor::zero, blend_factor::zero, blend_factor::zero, blend_factor::zero, blend_factor::zero };
340
blend_op color_blend_op[8] = { blend_op::add, blend_op::add, blend_op::add, blend_op::add, blend_op::add, blend_op::add, blend_op::add, blend_op::add };
341
blend_factor source_alpha_blend_factor[8] = { blend_factor::one, blend_factor::one, blend_factor::one, blend_factor::one, blend_factor::one, blend_factor::one, blend_factor::one, blend_factor::one };
342
blend_factor dest_alpha_blend_factor[8] = { blend_factor::zero, blend_factor::zero, blend_factor::zero, blend_factor::zero, blend_factor::zero, blend_factor::zero, blend_factor::zero, blend_factor::zero };
343
blend_op alpha_blend_op[8] = { blend_op::add, blend_op::add, blend_op::add, blend_op::add, blend_op::add, blend_op::add, blend_op::add, blend_op::add };
344
bool srgb_write_enable = false;
345
uint8_t render_target_write_mask[8] = { 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF };
346
bool stencil_enable = false;
347
uint8_t stencil_read_mask = 0xFF;
348
uint8_t stencil_write_mask = 0xFF;
349
stencil_func stencil_comparison_func = stencil_func::always;
350
stencil_op stencil_pass_op = stencil_op::keep;
351
stencil_op stencil_fail_op = stencil_op::keep;
352
stencil_op stencil_depth_fail_op = stencil_op::keep;
353
primitive_topology topology = primitive_topology::triangle_list;
354
uint32_t stencil_reference_value = 0;
355
uint32_t num_vertices = 3;
356
uint32_t viewport_width = 0;
357
uint32_t viewport_height = 0;
358
uint32_t viewport_dispatch_z = 1;
359
360
// Bindings specific for the code generation target (in case of combined texture and sampler, 'texture_bindings' and 'sampler_bindings' will be the same size and point to the same bindings, otherwise they are independent)
361
std::vector<texture_binding> texture_bindings;
362
std::vector<sampler_binding> sampler_bindings;
363
std::vector<storage_binding> storage_bindings;
364
};
365
366
/// <summary>
367
/// A collection of passes that make up an effect.
368
/// </summary>
369
struct technique
370
{
371
std::string name;
372
std::vector<pass> passes;
373
std::vector<annotation> annotations;
374
};
375
376
/// <summary>
377
/// In-memory representation of an effect file.
378
/// </summary>
379
struct effect_module
380
{
381
std::vector<std::pair<std::string, shader_type>> entry_points;
382
383
std::vector<texture> textures;
384
std::vector<sampler> samplers;
385
std::vector<storage> storages;
386
387
std::vector<uniform> uniforms;
388
std::vector<uniform> spec_constants;
389
std::vector<technique> techniques;
390
391
uint32_t total_uniform_size = 0;
392
uint32_t num_texture_bindings = 0;
393
uint32_t num_sampler_bindings = 0;
394
uint32_t num_storage_bindings = 0;
395
};
396
}
397
398