effect_module.hpp (8831B)
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 #include <unordered_set> 11 12 namespace reshadefx 13 { 14 /// <summary> 15 /// A list of supported texture types. 16 /// </summary> 17 enum class texture_type 18 { 19 texture_1d = 1, 20 texture_2d = 2, 21 texture_3d = 3 22 }; 23 24 /// <summary> 25 /// A list of supported texture formats. 26 /// </summary> 27 enum class texture_format 28 { 29 unknown, 30 31 r8, 32 r16, 33 r16f, 34 r32i, 35 r32u, 36 r32f, 37 rg8, 38 rg16, 39 rg16f, 40 rg32f, 41 rgba8, 42 rgba16, 43 rgba16f, 44 rgba32f, 45 rgb10a2 46 }; 47 48 /// <summary> 49 /// A filtering type used for texture lookups. 50 /// </summary> 51 enum class filter_mode 52 { 53 min_mag_mip_point = 0, 54 min_mag_point_mip_linear = 0x1, 55 min_point_mag_linear_mip_point = 0x4, 56 min_point_mag_mip_linear = 0x5, 57 min_linear_mag_mip_point = 0x10, 58 min_linear_mag_point_mip_linear = 0x11, 59 min_mag_linear_mip_point = 0x14, 60 min_mag_mip_linear = 0x15 61 }; 62 63 /// <summary> 64 /// Specifies behavior of sampling with texture coordinates outside an image. 65 /// </summary> 66 enum class texture_address_mode 67 { 68 wrap = 1, 69 mirror = 2, 70 clamp = 3, 71 border = 4 72 }; 73 74 /// <summary> 75 /// Specifies RGB or alpha blending operations. 76 /// </summary> 77 enum class pass_blend_op : uint8_t 78 { 79 add = 1, 80 subtract, 81 reverse_subtract, 82 min, 83 max 84 }; 85 86 /// <summary> 87 /// Specifies blend factors, which modulate values between the pixel shader output and render target. 88 /// </summary> 89 enum class pass_blend_factor : uint8_t 90 { 91 zero = 0, 92 one = 1, 93 source_color, 94 one_minus_source_color, 95 dest_color, 96 one_minus_dest_color, 97 source_alpha, 98 one_minus_source_alpha, 99 dest_alpha, 100 one_minus_dest_alpha 101 }; 102 103 /// <summary> 104 /// Specifies the stencil operations that can be performed during depth-stencil testing. 105 /// </summary> 106 enum class pass_stencil_op : uint8_t 107 { 108 zero = 0, 109 keep, 110 replace, 111 increment_saturate, 112 decrement_saturate, 113 invert, 114 increment, 115 decrement 116 }; 117 118 /// <summary> 119 /// Specifies comparison options for depth-stencil testing. 120 /// </summary> 121 enum class pass_stencil_func : uint8_t 122 { 123 never, 124 less, 125 equal, 126 less_equal, 127 greater, 128 not_equal, 129 greater_equal, 130 always 131 }; 132 133 /// <summary> 134 /// Specifies the possible primitives. 135 /// </summary> 136 enum class primitive_topology : uint8_t 137 { 138 point_list = 1, 139 line_list, 140 line_strip, 141 triangle_list, 142 triangle_strip 143 }; 144 145 /// <summary> 146 /// A struct type defined in the effect code. 147 /// </summary> 148 struct struct_info 149 { 150 std::string name; 151 std::string unique_name; 152 std::vector<struct struct_member_info> member_list; 153 uint32_t definition = 0; 154 }; 155 156 /// <summary> 157 /// A struct field defined in the effect code. 158 /// </summary> 159 struct struct_member_info 160 { 161 reshadefx::type type; 162 std::string name; 163 std::string semantic; 164 reshadefx::location location; 165 uint32_t definition = 0; 166 }; 167 168 /// <summary> 169 /// An annotation attached to a variable. 170 /// </summary> 171 struct annotation 172 { 173 reshadefx::type type; 174 std::string name; 175 reshadefx::constant value; 176 }; 177 178 /// <summary> 179 /// A texture defined in the effect code. 180 /// </summary> 181 struct texture_info 182 { 183 uint32_t id = 0; 184 uint32_t binding = 0; 185 std::string name; 186 std::string semantic; 187 std::string unique_name; 188 std::vector<annotation> annotations; 189 texture_type type = texture_type::texture_2d; 190 uint32_t width = 1; 191 uint32_t height = 1; 192 uint16_t depth = 1; 193 uint16_t levels = 1; 194 texture_format format = texture_format::rgba8; 195 bool render_target = false; 196 bool storage_access = false; 197 }; 198 199 /// <summary> 200 /// A texture sampler defined in the effect code. 201 /// </summary> 202 struct sampler_info 203 { 204 uint32_t id = 0; 205 uint32_t binding = 0; 206 uint32_t texture_binding = 0; 207 std::string name; 208 reshadefx::type type; 209 std::string unique_name; 210 std::string texture_name; 211 std::vector<annotation> annotations; 212 filter_mode filter = filter_mode::min_mag_mip_linear; 213 texture_address_mode address_u = texture_address_mode::clamp; 214 texture_address_mode address_v = texture_address_mode::clamp; 215 texture_address_mode address_w = texture_address_mode::clamp; 216 float min_lod = -3.402823466e+38f; 217 float max_lod = +3.402823466e+38f; // FLT_MAX 218 float lod_bias = 0.0f; 219 uint8_t srgb = false; 220 }; 221 222 /// <summary> 223 /// A texture storage object defined in the effect code. 224 /// </summary> 225 struct storage_info 226 { 227 uint32_t id = 0; 228 uint32_t binding = 0; 229 std::string name; 230 reshadefx::type type; 231 std::string unique_name; 232 std::string texture_name; 233 uint16_t level = 0; 234 }; 235 236 /// <summary> 237 /// An uniform variable defined in the effect code. 238 /// </summary> 239 struct uniform_info 240 { 241 std::string name; 242 reshadefx::type type; 243 uint32_t size = 0; 244 uint32_t offset = 0; 245 std::vector<annotation> annotations; 246 bool has_initializer_value = false; 247 reshadefx::constant initializer_value; 248 }; 249 250 /// <summary> 251 /// Type of a shader entry point. 252 /// </summary> 253 enum class shader_type 254 { 255 vs, 256 ps, 257 cs, 258 }; 259 260 /// <summary> 261 /// A shader entry point function. 262 /// </summary> 263 struct entry_point 264 { 265 std::string name; 266 shader_type type; 267 }; 268 269 /// <summary> 270 /// A function defined in the effect code. 271 /// </summary> 272 struct function_info 273 { 274 uint32_t definition; 275 std::string name; 276 std::string unique_name; 277 reshadefx::type return_type; 278 std::string return_semantic; 279 std::vector<struct_member_info> parameter_list; 280 std::unordered_set<uint32_t> referenced_samplers; 281 std::unordered_set<uint32_t> referenced_storages; 282 }; 283 284 /// <summary> 285 /// A render pass with all its state info. 286 /// </summary> 287 struct pass_info 288 { 289 std::string name; 290 std::string render_target_names[8] = {}; 291 std::string vs_entry_point; 292 std::string ps_entry_point; 293 std::string cs_entry_point; 294 uint8_t generate_mipmaps = true; 295 uint8_t clear_render_targets = false; 296 uint8_t srgb_write_enable = false; 297 uint8_t blend_enable[8] = { false, false, false, false, false, false, false, false }; 298 uint8_t stencil_enable = false; 299 uint8_t color_write_mask[8] = { 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF }; 300 uint8_t stencil_read_mask = 0xFF; 301 uint8_t stencil_write_mask = 0xFF; 302 pass_blend_op blend_op[8] = { pass_blend_op::add, pass_blend_op::add, pass_blend_op::add, pass_blend_op::add, pass_blend_op::add, pass_blend_op::add, pass_blend_op::add, pass_blend_op::add }; 303 pass_blend_op blend_op_alpha[8] = { pass_blend_op::add, pass_blend_op::add, pass_blend_op::add, pass_blend_op::add, pass_blend_op::add, pass_blend_op::add, pass_blend_op::add, pass_blend_op::add }; 304 pass_blend_factor src_blend[8] = { pass_blend_factor::one, pass_blend_factor::one, pass_blend_factor::one, pass_blend_factor::one, pass_blend_factor::one, pass_blend_factor::one, pass_blend_factor::one, pass_blend_factor::one }; 305 pass_blend_factor dest_blend[8] = { pass_blend_factor::zero, pass_blend_factor::zero, pass_blend_factor::zero, pass_blend_factor::zero, pass_blend_factor::zero, pass_blend_factor::zero, pass_blend_factor::zero, pass_blend_factor::zero }; 306 pass_blend_factor src_blend_alpha[8] = { pass_blend_factor::one, pass_blend_factor::one, pass_blend_factor::one, pass_blend_factor::one, pass_blend_factor::one, pass_blend_factor::one, pass_blend_factor::one, pass_blend_factor::one }; 307 pass_blend_factor dest_blend_alpha[8] = { pass_blend_factor::zero, pass_blend_factor::zero, pass_blend_factor::zero, pass_blend_factor::zero, pass_blend_factor::zero, pass_blend_factor::zero, pass_blend_factor::zero, pass_blend_factor::zero }; 308 pass_stencil_func stencil_comparison_func = pass_stencil_func::always; 309 uint32_t stencil_reference_value = 0; 310 pass_stencil_op stencil_op_pass = pass_stencil_op::keep; 311 pass_stencil_op stencil_op_fail = pass_stencil_op::keep; 312 pass_stencil_op stencil_op_depth_fail = pass_stencil_op::keep; 313 uint32_t num_vertices = 3; 314 primitive_topology topology = primitive_topology::triangle_list; 315 uint32_t viewport_width = 0; 316 uint32_t viewport_height = 0; 317 uint32_t viewport_dispatch_z = 1; 318 std::vector<sampler_info> samplers; 319 std::vector<storage_info> storages; 320 }; 321 322 /// <summary> 323 /// A collection of passes that make up an effect. 324 /// </summary> 325 struct technique_info 326 { 327 std::string name; 328 std::vector<pass_info> passes; 329 std::vector<annotation> annotations; 330 }; 331 332 /// <summary> 333 /// In-memory representation of an effect file. 334 /// </summary> 335 struct module 336 { 337 std::vector<char> code; 338 339 std::vector<entry_point> entry_points; 340 std::vector<texture_info> textures; 341 std::vector<sampler_info> samplers; 342 std::vector<storage_info> storages; 343 std::vector<uniform_info> uniforms, spec_constants; 344 std::vector<technique_info> techniques; 345 346 uint32_t total_uniform_size = 0; 347 uint32_t num_texture_bindings = 0; 348 uint32_t num_sampler_bindings = 0; 349 uint32_t num_storage_bindings = 0; 350 }; 351 }