Path: blob/master/dep/reshadefx/include/effect_module.hpp
4246 views
/*1* Copyright (C) 2014 Patrick Mours2* SPDX-License-Identifier: BSD-3-Clause3*/45#pragma once67#include "effect_expression.hpp"8#include <cstdint>910namespace reshadefx11{12/// <summary>13/// Describes an annotation attached to a variable.14/// </summary>15struct annotation16{17reshadefx::type type = {};18std::string name;19reshadefx::constant value = {};20};2122/// <summary>23/// Describes a struct member or parameter.24/// </summary>25struct member_type26{27reshadefx::type type = {};28uint32_t id = 0;29std::string name;30std::string semantic;31reshadefx::location location;32bool has_default_value = false;33reshadefx::constant default_value = {};34};3536/// <summary>37/// Describes a struct type defined in effect code.38/// </summary>39struct struct_type40{41uint32_t id = 0;42std::string name;43std::string unique_name;44std::vector<member_type> member_list;45};4647/// <summary>48/// Available texture types.49/// </summary>50enum class texture_type : uint8_t51{52texture_1d = 1,53texture_2d = 2,54texture_3d = 355};5657/// <summary>58/// Available texture formats.59/// </summary>60enum class texture_format : uint8_t61{62unknown,6364r8,65r16,66r16f,67r32i,68r32u,69r32f,70rg8,71rg16,72rg16f,73rg32f,74rgba8,75rgba16,76rgba16f,77rgba32f,78rgb10a279};8081/// <summary>82/// Describes the properties of a <see cref="texture"/> object.83/// </summary>84struct texture_desc85{86uint32_t width = 1;87uint32_t height = 1;88uint16_t depth = 1;89uint16_t levels = 1;90texture_type type = texture_type::texture_2d;91texture_format format = texture_format::rgba8;92};9394/// <summary>95/// Describes a texture object defined in effect code.96/// </summary>97struct texture : texture_desc98{99uint32_t id = 0;100std::string name;101std::string unique_name;102std::string semantic;103std::vector<annotation> annotations;104bool render_target = false;105bool storage_access = false;106};107108/// <summary>109/// Describes the binding of a <see cref="texture"/> object.110/// </summary>111struct texture_binding112{113uint32_t binding = 0;114std::string texture_name;115bool srgb = false;116};117118/// <summary>119/// Texture filtering modes available for texture sampling operations.120/// </summary>121enum class filter_mode : uint8_t122{123min_mag_mip_point = 0,124min_mag_point_mip_linear = 0x1,125min_point_mag_linear_mip_point = 0x4,126min_point_mag_mip_linear = 0x5,127min_linear_mag_mip_point = 0x10,128min_linear_mag_point_mip_linear = 0x11,129min_mag_linear_mip_point = 0x14,130min_mag_mip_linear = 0x15,131anisotropic = 0x55132};133134/// <summary>135/// Sampling behavior at texture coordinates outside the bounds of a texture resource.136/// </summary>137enum class texture_address_mode : uint8_t138{139wrap = 1,140mirror = 2,141clamp = 3,142border = 4143};144145/// <summary>146/// Describes the properties of a <see cref="sampler"/> object.147/// </summary>148struct sampler_desc149{150filter_mode filter = filter_mode::min_mag_mip_linear;151texture_address_mode address_u = texture_address_mode::clamp;152texture_address_mode address_v = texture_address_mode::clamp;153texture_address_mode address_w = texture_address_mode::clamp;154float min_lod = -3.402823466e+38f;155float max_lod = +3.402823466e+38f; // FLT_MAX156float lod_bias = 0.0f;157};158159/// <summary>160/// Describes a texture sampler object defined in effect code.161/// </summary>162struct sampler : sampler_desc163{164reshadefx::type type = {};165uint32_t id = 0;166std::string name;167std::string unique_name;168std::string texture_name;169std::vector<annotation> annotations;170bool srgb = false;171};172173/// <summary>174/// Describes the binding of a <see cref="sampler"/> object.175/// </summary>176struct sampler_binding : sampler_desc177{178uint32_t binding = 0;179};180181/// <summary>182/// Describes the properties of a <see cref="storage"/> object.183/// </summary>184struct storage_desc185{186uint16_t level = 0;187};188189/// <summary>190/// Describes a texture storage object defined in effect code.191/// </summary>192struct storage : storage_desc193{194reshadefx::type type = {};195uint32_t id = 0;196std::string name;197std::string unique_name;198std::string texture_name;199};200201/// <summary>202/// Describes the binding of a <see cref="storage"/> object.203/// </summary>204struct storage_binding : storage_desc205{206uint32_t binding = 0;207std::string texture_name;208};209210/// <summary>211/// Describes a uniform variable defined in effect code.212/// </summary>213struct uniform214{215reshadefx::type type = {};216std::string name;217uint32_t size = 0;218uint32_t offset = 0;219std::vector<annotation> annotations;220bool has_initializer_value = false;221reshadefx::constant initializer_value = {};222};223224/// <summary>225/// Type of a shader entry point.226/// </summary>227enum class shader_type228{229unknown,230vertex,231pixel,232compute233};234235/// <summary>236/// Describes a function defined in effect code.237/// </summary>238struct function239{240reshadefx::type return_type = {};241uint32_t id = 0;242std::string name;243std::string unique_name;244std::string return_semantic;245std::vector<member_type> parameter_list;246shader_type type = shader_type::unknown;247int num_threads[3] = {};248std::vector<uint32_t> referenced_samplers;249std::vector<uint32_t> referenced_storages;250std::vector<uint32_t> referenced_functions;251};252253/// <summary>254/// Color or alpha blending operations.255/// </summary>256enum class blend_op : uint8_t257{258add = 1,259subtract,260reverse_subtract,261min,262max263};264265/// <summary>266/// Blend factors in color or alpha blending operations, which modulate values between the pixel shader output and render target.267/// </summary>268enum class blend_factor : uint8_t269{270zero = 0,271one = 1,272source_color,273one_minus_source_color,274dest_color,275one_minus_dest_color,276source_alpha,277one_minus_source_alpha,278dest_alpha,279one_minus_dest_alpha280};281282/// <summary>283/// Stencil operations that can be performed during depth-stencil testing.284/// </summary>285enum class stencil_op : uint8_t286{287zero = 0,288keep,289replace,290increment_saturate,291decrement_saturate,292invert,293increment,294decrement295};296297/// <summary>298/// Comparison operations for depth-stencil testing.299/// </summary>300enum class stencil_func : uint8_t301{302never,303less,304equal,305less_equal,306greater,307not_equal,308greater_equal,309always310};311312/// <summary>313/// Specifies the possible primitives.314/// </summary>315enum class primitive_topology : uint8_t316{317point_list = 1,318line_list,319line_strip,320triangle_list,321triangle_strip322};323324/// <summary>325/// Describes a render pass with all its state info.326/// </summary>327struct pass328{329std::string name;330std::string render_target_names[8] = {};331std::string vs_entry_point;332std::string ps_entry_point;333std::string cs_entry_point;334bool generate_mipmaps = true;335bool clear_render_targets = false;336bool blend_enable[8] = { false, false, false, false, false, false, false, false };337blend_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 };338blend_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 };339blend_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 };340blend_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 };341blend_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 };342blend_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 };343bool srgb_write_enable = false;344uint8_t render_target_write_mask[8] = { 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF };345bool stencil_enable = false;346uint8_t stencil_read_mask = 0xFF;347uint8_t stencil_write_mask = 0xFF;348stencil_func stencil_comparison_func = stencil_func::always;349stencil_op stencil_pass_op = stencil_op::keep;350stencil_op stencil_fail_op = stencil_op::keep;351stencil_op stencil_depth_fail_op = stencil_op::keep;352primitive_topology topology = primitive_topology::triangle_list;353uint32_t stencil_reference_value = 0;354uint32_t num_vertices = 3;355uint32_t viewport_width = 0;356uint32_t viewport_height = 0;357uint32_t viewport_dispatch_z = 1;358359// 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)360std::vector<texture_binding> texture_bindings;361std::vector<sampler_binding> sampler_bindings;362std::vector<storage_binding> storage_bindings;363};364365/// <summary>366/// A collection of passes that make up an effect.367/// </summary>368struct technique369{370std::string name;371std::vector<pass> passes;372std::vector<annotation> annotations;373};374375/// <summary>376/// In-memory representation of an effect file.377/// </summary>378struct effect_module379{380std::vector<std::pair<std::string, shader_type>> entry_points;381382std::vector<texture> textures;383std::vector<sampler> samplers;384std::vector<storage> storages;385386std::vector<uniform> uniforms;387std::vector<uniform> spec_constants;388std::vector<technique> techniques;389390uint32_t total_uniform_size = 0;391uint32_t num_texture_bindings = 0;392uint32_t num_sampler_bindings = 0;393uint32_t num_storage_bindings = 0;394};395}396397398