/* * Copyright (C) 2014 Patrick Mours * SPDX-License-Identifier: BSD-3-Clause */ #pragma once #include "effect_expression.hpp" #include namespace reshadefx { /// /// Describes an annotation attached to a variable. /// struct annotation { reshadefx::type type = {}; std::string name; reshadefx::constant value = {}; }; /// /// Describes a struct member or parameter. /// struct member_type { reshadefx::type type = {}; uint32_t id = 0; std::string name; std::string semantic; reshadefx::location location; bool has_default_value = false; reshadefx::constant default_value = {}; }; /// /// Describes a struct type defined in effect code. /// struct struct_type { uint32_t id = 0; std::string name; std::string unique_name; std::vector member_list; }; /// /// Available texture types. /// enum class texture_type : uint8_t { texture_1d = 1, texture_2d = 2, texture_3d = 3 }; /// /// Available texture formats. /// enum class texture_format : uint8_t { unknown, r8, r16, r16f, r32i, r32u, r32f, rg8, rg16, rg16f, rg32f, rgba8, rgba16, rgba16f, rgba32f, rgb10a2 }; /// /// Describes the properties of a object. /// struct texture_desc { uint32_t width = 1; uint32_t height = 1; uint16_t depth = 1; uint16_t levels = 1; texture_type type = texture_type::texture_2d; texture_format format = texture_format::rgba8; }; /// /// Describes a texture object defined in effect code. /// struct texture : texture_desc { uint32_t id = 0; std::string name; std::string unique_name; std::string semantic; std::vector annotations; bool render_target = false; bool storage_access = false; }; /// /// Describes the binding of a object. /// struct texture_binding { uint32_t binding = 0; std::string texture_name; bool srgb = false; }; /// /// Texture filtering modes available for texture sampling operations. /// enum class filter_mode : uint8_t { min_mag_mip_point = 0, min_mag_point_mip_linear = 0x1, min_point_mag_linear_mip_point = 0x4, min_point_mag_mip_linear = 0x5, min_linear_mag_mip_point = 0x10, min_linear_mag_point_mip_linear = 0x11, min_mag_linear_mip_point = 0x14, min_mag_mip_linear = 0x15, anisotropic = 0x55 }; /// /// Sampling behavior at texture coordinates outside the bounds of a texture resource. /// enum class texture_address_mode : uint8_t { wrap = 1, mirror = 2, clamp = 3, border = 4 }; /// /// Describes the properties of a object. /// struct sampler_desc { filter_mode filter = filter_mode::min_mag_mip_linear; texture_address_mode address_u = texture_address_mode::clamp; texture_address_mode address_v = texture_address_mode::clamp; texture_address_mode address_w = texture_address_mode::clamp; float min_lod = -3.402823466e+38f; float max_lod = +3.402823466e+38f; // FLT_MAX float lod_bias = 0.0f; }; /// /// Describes a texture sampler object defined in effect code. /// struct sampler : sampler_desc { reshadefx::type type = {}; uint32_t id = 0; std::string name; std::string unique_name; std::string texture_name; std::vector annotations; bool srgb = false; }; /// /// Describes the binding of a object. /// struct sampler_binding : sampler_desc { uint32_t binding = 0; }; /// /// Describes the properties of a object. /// struct storage_desc { uint16_t level = 0; }; /// /// Describes a texture storage object defined in effect code. /// struct storage : storage_desc { reshadefx::type type = {}; uint32_t id = 0; std::string name; std::string unique_name; std::string texture_name; }; /// /// Describes the binding of a object. /// struct storage_binding : storage_desc { uint32_t binding = 0; std::string texture_name; }; /// /// Describes a uniform variable defined in effect code. /// struct uniform { reshadefx::type type = {}; std::string name; uint32_t size = 0; uint32_t offset = 0; std::vector annotations; bool has_initializer_value = false; reshadefx::constant initializer_value = {}; }; /// /// Type of a shader entry point. /// enum class shader_type { unknown, vertex, pixel, compute }; /// /// Describes a function defined in effect code. /// struct function { reshadefx::type return_type = {}; uint32_t id = 0; std::string name; std::string unique_name; std::string return_semantic; std::vector parameter_list; shader_type type = shader_type::unknown; int num_threads[3] = {}; std::vector referenced_samplers; std::vector referenced_storages; std::vector referenced_functions; }; /// /// Color or alpha blending operations. /// enum class blend_op : uint8_t { add = 1, subtract, reverse_subtract, min, max }; /// /// Blend factors in color or alpha blending operations, which modulate values between the pixel shader output and render target. /// enum class blend_factor : uint8_t { zero = 0, one = 1, source_color, one_minus_source_color, dest_color, one_minus_dest_color, source_alpha, one_minus_source_alpha, dest_alpha, one_minus_dest_alpha }; /// /// Stencil operations that can be performed during depth-stencil testing. /// enum class stencil_op : uint8_t { zero = 0, keep, replace, increment_saturate, decrement_saturate, invert, increment, decrement }; /// /// Comparison operations for depth-stencil testing. /// enum class stencil_func : uint8_t { never, less, equal, less_equal, greater, not_equal, greater_equal, always }; /// /// Specifies the possible primitives. /// enum class primitive_topology : uint8_t { point_list = 1, line_list, line_strip, triangle_list, triangle_strip }; /// /// Describes a render pass with all its state info. /// struct pass { std::string name; std::string render_target_names[8] = {}; std::string vs_entry_point; std::string ps_entry_point; std::string cs_entry_point; bool generate_mipmaps = true; bool clear_render_targets = false; bool blend_enable[8] = { false, false, false, false, false, false, false, false }; 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 }; 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 }; 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 }; 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 }; 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 }; 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 }; bool srgb_write_enable = false; uint8_t render_target_write_mask[8] = { 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF }; bool stencil_enable = false; uint8_t stencil_read_mask = 0xFF; uint8_t stencil_write_mask = 0xFF; stencil_func stencil_comparison_func = stencil_func::always; stencil_op stencil_pass_op = stencil_op::keep; stencil_op stencil_fail_op = stencil_op::keep; stencil_op stencil_depth_fail_op = stencil_op::keep; primitive_topology topology = primitive_topology::triangle_list; uint32_t stencil_reference_value = 0; uint32_t num_vertices = 3; uint32_t viewport_width = 0; uint32_t viewport_height = 0; uint32_t viewport_dispatch_z = 1; // 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) std::vector texture_bindings; std::vector sampler_bindings; std::vector storage_bindings; }; /// /// A collection of passes that make up an effect. /// struct technique { std::string name; std::vector passes; std::vector annotations; }; /// /// In-memory representation of an effect file. /// struct effect_module { std::vector> entry_points; std::vector textures; std::vector samplers; std::vector storages; std::vector uniforms; std::vector spec_constants; std::vector techniques; uint32_t total_uniform_size = 0; uint32_t num_texture_bindings = 0; uint32_t num_sampler_bindings = 0; uint32_t num_storage_bindings = 0; }; }