dep/reshadefx: Update to 7bdfb03

This commit is contained in:
Stenzek
2024-09-08 19:19:58 +10:00
parent 3078339f64
commit 86bff869bc
25 changed files with 6041 additions and 3244 deletions

View File

@ -16,6 +16,8 @@ namespace reshadefx
/// </summary>
class codegen
{
friend class parser;
public:
/// <summary>
/// Virtual destructor to guarantee that memory of the implementations deriving from this interface is properly destroyed.
@ -23,12 +25,21 @@ namespace reshadefx
virtual ~codegen() {}
/// <summary>
/// Writes result of the code generation to the specified <paramref name="module"/>.
/// Gets the module describing the generated code.
/// </summary>
/// <param name="module">Target module to fill.</param>
virtual void write_result(module &module) = 0;
const effect_module &module() const { return _module; }
public:
/// <summary>
/// Finalizes and returns the generated code for the entire module (all entry points).
/// </summary>
virtual std::basic_string<char> finalize_code() const = 0;
/// <summary>
/// Finalizes and returns the generated code for the specified entry point (and no other entry points).
/// </summary>
/// <param name="entry_point_name">Name of the entry point function to generate code for.</param>
virtual std::basic_string<char> finalize_code_for_entry_point(const std::string &entry_point_name) const = 0;
protected:
/// <summary>
/// An opaque ID referring to a SSA value or basic block.
/// </summary>
@ -40,14 +51,14 @@ namespace reshadefx
/// <param name="loc">Source location matching this definition (for debugging).</param>
/// <param name="info">Description of the type.</param>
/// <returns>New SSA ID of the type.</returns>
virtual id define_struct(const location &loc, struct_info &info) = 0;
virtual id define_struct(const location &loc, struct_type &info) = 0;
/// <summary>
/// Defines a new texture binding.
/// </summary>
/// <param name="loc">Source location matching this definition (for debugging).</param>
/// <param name="info">Description of the texture object.</param>
/// <returns>New SSA ID of the binding.</returns>
virtual id define_texture(const location &loc, texture_info &info) = 0;
virtual id define_texture(const location &loc, texture &info) = 0;
/// <summary>
/// Defines a new sampler binding.
/// </summary>
@ -55,7 +66,7 @@ namespace reshadefx
/// <param name="tex_info">Description of the texture this sampler object references.</param>
/// <param name="info">Description of the sampler object.</param>
/// <returns>New SSA ID of the binding.</returns>
virtual id define_sampler(const location &loc, const texture_info &tex_info, sampler_info &info) = 0;
virtual id define_sampler(const location &loc, const texture &tex_info, sampler &info) = 0;
/// <summary>
/// Defines a new storage binding.
/// </summary>
@ -63,14 +74,14 @@ namespace reshadefx
/// <param name="tex_info">Description of the texture this storage object references.</param>
/// <param name="info">Description of the storage object.</param>
/// <returns>New SSA ID of the binding.</returns>
virtual id define_storage(const location &loc, const texture_info &tex_info, storage_info &info) = 0;
virtual id define_storage(const location &loc, const texture &tex_info, storage &info) = 0;
/// <summary>
/// Defines a new uniform variable.
/// </summary>
/// <param name="loc">Source location matching this definition (for debugging).</param>
/// <param name="info">Description of the uniform variable.</param>
/// <returns>New SSA ID of the variable.</returns>
virtual id define_uniform(const location &loc, uniform_info &info) = 0;
virtual id define_uniform(const location &loc, uniform &info) = 0;
/// <summary>
/// Defines a new variable.
/// </summary>
@ -82,26 +93,25 @@ namespace reshadefx
/// <returns>New SSA ID of the variable.</returns>
virtual id define_variable(const location &loc, const type &type, std::string name = std::string(), bool global = false, id initializer_value = 0) = 0;
/// <summary>
/// Defines a new function and its function parameters and make it current. Any code added after this call is added to this function.
/// Defines a new function and its function parameters and make it current.
/// Any code added after this call is added to this function.
/// </summary>
/// <param name="loc">Source location matching this definition (for debugging).</param>
/// <param name="info">Description of the function.</param>
/// <returns>New SSA ID of the function.</returns>
virtual id define_function(const location &loc, function_info &info) = 0;
virtual id define_function(const location &loc, function &info) = 0;
/// <summary>
/// Defines a new effect technique.
/// </summary>
/// <param name="loc">Source location matching this definition (for debugging).</param>
/// <param name="info">Description of the technique.</param>
void define_technique(technique_info &&info) { _module.techniques.push_back(std::move(info)); }
void define_technique(technique &&info) { _module.techniques.push_back(std::move(info)); }
/// <summary>
/// Makes a function a shader entry point.
/// </summary>
/// <param name="function">Function to use as entry point. May be overwritten to point to a new unique function for this entry point.</param>
/// <param name="type">Shader type (vertex, pixel or compute shader).</param>
/// <param name="num_threads">Number of local threads it this is a compute entry point.</param>
virtual void define_entry_point(function_info &function, shader_type type, int num_threads[3] = nullptr) = 0;
/// <param name="function">Function to use as entry point. May be overwritten to point to a new uniquely generated function.</param>
virtual void define_entry_point(function &function) = 0;
/// <summary>
/// Resolves the access chain and add a load operation to the output.
@ -131,6 +141,19 @@ namespace reshadefx
/// <param name="data">Actual constant data to convert into a SSA ID.</param>
/// <returns>New SSA ID with the constant value.</returns>
virtual id emit_constant(const type &type, const constant &data) = 0;
id emit_constant(const type &data_type, uint32_t value)
{
// Create a constant value of the specified type
constant data = {}; // Initialize to zero, so that components not set below still have a defined value for lookup via std::memcmp
for (unsigned int i = 0; i < data_type.components(); ++i)
{
if (data_type.is_integral())
data.as_uint[i] = value;
else
data.as_float[i] = static_cast<float>(value);
}
return emit_constant(data_type, data);
}
/// <summary>
/// Adds an unary operation to the output (built-in operation with one argument).
@ -222,7 +245,7 @@ namespace reshadefx
/// <summary>
/// Returns <see langword="true"/> if code is currently added to a function.
/// </summary>
virtual bool is_in_function() const { return is_in_block(); }
bool is_in_function() const { return _current_function != nullptr; }
/// <summary>
/// Creates a new basic block.
@ -272,93 +295,96 @@ namespace reshadefx
/// <param name="false_target">ID of the basic block to jump to when the condition is false.</param>
/// <returns>ID of the current basic block.</returns>
virtual id leave_block_and_branch_conditional(id condition, id true_target, id false_target) = 0;
/// <summary>
/// Leaves the current function. Any code added after this call is added in the global scope.
/// </summary>
virtual void leave_function() = 0;
/// <summary>
/// Recalculates sampler and storage bindings to take as little binding space as possible for each entry point.
/// </summary>
virtual void optimize_bindings();
/// <summary>
/// Looks up an existing struct type.
/// </summary>
/// <param name="id">SSA ID of the type to find.</param>
/// <returns>Reference to the struct description.</returns>
const struct_info &get_struct(id id) const
const struct_type &get_struct(id id) const
{
return *std::find_if(_structs.begin(), _structs.end(),
[id](const auto &it) { return it.definition == id; });
[id](const struct_type &info) { return info.id == id; });
}
/// <summary>
/// Looks up an existing texture binding.
/// </summary>
/// <param name="id">SSA ID of the texture binding to find.</param>
/// <returns>Reference to the texture description.</returns>
texture_info &get_texture(id id)
texture &get_texture(id id)
{
return *std::find_if(_module.textures.begin(), _module.textures.end(),
[id](const auto &it) { return it.id == id; });
[id](const texture &info) { return info.id == id; });
}
/// <summary>
/// Looks up an existing sampler binding.
/// </summary>
/// <param name="id">SSA ID of the sampler binding to find.</param>
/// <returns>Reference to the sampler description.</returns>
const sampler_info &get_sampler(id id) const
const sampler &get_sampler(id id) const
{
return *std::find_if(_module.samplers.begin(), _module.samplers.end(),
[id](const auto &it) { return it.id == id; });
[id](const sampler &info) { return info.id == id; });
}
/// <summary>
/// Looks up an existing storage binding.
/// </summary>
/// <param name="id">SSA ID of the storage binding to find.</param>
/// <returns>Reference to the storage description.</returns>
const storage_info &get_storage(id id) const
const storage &get_storage(id id) const
{
return *std::find_if(_module.storages.begin(), _module.storages.end(),
[id](const auto &it) { return it.id == id; });
[id](const storage &info) { return info.id == id; });
}
/// <summary>
/// Looks up an existing function definition.
/// </summary>
/// <param name="id">SSA ID of the function variable to find.</param>
/// <returns>Reference to the function description.</returns>
function_info &get_function(id id)
function &get_function(id id)
{
return *std::find_if(_functions.begin(), _functions.end(),
[id](const auto &it) { return it->definition == id; })->get();
[id](const std::unique_ptr<function> &info) { return info->id == id; })->get();
}
function &get_function(const std::string &unique_name)
{
return *std::find_if(_functions.begin(), _functions.end(),
[&unique_name](const std::unique_ptr<function> &info) { return info->unique_name == unique_name; })->get();
}
protected:
id make_id() { return _next_id++; }
static uint32_t align_up(uint32_t size, uint32_t alignment)
{
alignment -= 1;
return ((size + alignment) & ~alignment);
}
static uint32_t align_up(uint32_t size, uint32_t alignment, uint32_t elements)
{
return align_up(size, alignment) * (elements - 1) + size;
}
effect_module _module;
std::vector<struct_type> _structs;
std::vector<std::unique_ptr<function>> _functions;
reshadefx::module _module;
std::vector<struct_info> _structs;
std::vector<std::unique_ptr<function_info>> _functions;
id _next_id = 1;
id _last_block = 0;
id _current_block = 0;
function *_current_function = nullptr;
};
/// <summary>
/// Creates a back-end implementation for GLSL code generation.
/// </summary>
/// <param name="version">GLSL version to insert at the beginning of the file.</param>
/// <param name="gles">Generate GLSL ES code instead of core OpenGL.</param>
/// <param name="vulkan_semantics">Generate GLSL for OpenGL or for Vulkan.</param>
/// <param name="debug_info">Whether to append debug information like line directives to the generated code.</param>
/// <param name="uniforms_to_spec_constants">Whether to convert uniform variables to specialization constants.</param>
/// <param name="enable_16bit_types">Use real 16-bit types for the minimum precision types "min16int", "min16uint" and "min16float".</param>
/// <param name="flip_vert_y">Insert code to flip the Y component of the output position in vertex shaders.</param>
codegen *create_codegen_glsl(bool gles, bool vulkan_semantics, bool debug_info, bool uniforms_to_spec_constants, bool enable_16bit_types = false, bool flip_vert_y = false);
codegen *create_codegen_glsl(unsigned version, bool gles, bool vulkan_semantics, bool debug_info, bool uniforms_to_spec_constants, bool enable_16bit_types = false, bool flip_vert_y = false);
/// <summary>
/// Creates a back-end implementation for HLSL code generation.
/// </summary>

View File

@ -15,7 +15,7 @@ namespace reshadefx
/// </summary>
struct type
{
enum datatype : uint8_t
enum datatype : uint32_t
{
t_void,
t_bool,
@ -101,6 +101,8 @@ namespace reshadefx
bool is_function() const { return base == t_function; }
bool is_array() const { return array_length != 0; }
bool is_bounded_array() const { return is_array() && array_length != 0xFFFFFFFF; }
bool is_unbounded_array() const { return array_length == 0xFFFFFFFF; }
bool is_scalar() const { return is_numeric() && !is_matrix() && !is_vector() && !is_array(); }
bool is_vector() const { return is_numeric() && rows > 1 && cols == 1; }
bool is_matrix() const { return is_numeric() && rows >= 1 && cols > 1; }
@ -109,27 +111,27 @@ namespace reshadefx
unsigned int components() const { return rows * cols; }
unsigned int texture_dimension() const { return base >= t_texture1d && base <= t_storage3d_float ? ((base - t_texture1d) % 3) + 1 : 0; }
friend inline bool operator==(const type &lhs, const type &rhs)
friend bool operator==(const type &lhs, const type &rhs)
{
return lhs.base == rhs.base && lhs.rows == rhs.rows && lhs.cols == rhs.cols && lhs.array_length == rhs.array_length && lhs.definition == rhs.definition;
return lhs.base == rhs.base && lhs.rows == rhs.rows && lhs.cols == rhs.cols && lhs.array_length == rhs.array_length && lhs.struct_definition == rhs.struct_definition;
}
friend inline bool operator!=(const type &lhs, const type &rhs)
friend bool operator!=(const type &lhs, const type &rhs)
{
return !operator==(lhs, rhs);
}
// Underlying base type ('int', 'float', ...)
datatype base = t_void;
datatype base : 8;
// Number of rows if this is a vector type
unsigned int rows = 0;
uint32_t rows : 4;
// Number of columns if this is a matrix type
unsigned int cols = 0;
uint32_t cols : 4;
// Bit mask of all the qualifiers decorating the type
unsigned int qualifiers = 0;
// Negative if an unsized array, otherwise the number of elements if this is an array type
int array_length = 0;
uint32_t qualifiers : 16;
// Number of elements if this is an array type, 0xFFFFFFFF if it is an unsized array
uint32_t array_length;
// ID of the matching struct if this is a struct type
uint32_t definition = 0;
uint32_t struct_definition;
};
/// <summary>
@ -168,8 +170,8 @@ namespace reshadefx
op_type op;
reshadefx::type from, to;
uint32_t index = 0;
signed char swizzle[4] = {};
uint32_t index;
signed char swizzle[4];
};
uint32_t base = 0;

View File

@ -7,14 +7,48 @@
#include "effect_expression.hpp"
#include <cstdint>
#include <unordered_set>
namespace reshadefx
{
/// <summary>
/// A list of supported texture types.
/// Describes an annotation attached to a variable.
/// </summary>
enum class texture_type
struct annotation
{
reshadefx::type type = {};
std::string name;
reshadefx::constant value = {};
};
/// <summary>
/// Describes a struct member or parameter.
/// </summary>
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 = {};
};
/// <summary>
/// Describes a struct type defined in effect code.
/// </summary>
struct struct_type
{
uint32_t id = 0;
std::string name;
std::string unique_name;
std::vector<member_type> member_list;
};
/// <summary>
/// Available texture types.
/// </summary>
enum class texture_type : uint8_t
{
texture_1d = 1,
texture_2d = 2,
@ -22,9 +56,9 @@ namespace reshadefx
};
/// <summary>
/// A list of supported texture formats.
/// Available texture formats.
/// </summary>
enum class texture_format
enum class texture_format : uint8_t
{
unknown,
@ -46,9 +80,46 @@ namespace reshadefx
};
/// <summary>
/// A filtering type used for texture lookups.
/// Describes the properties of a <see cref="texture"/> object.
/// </summary>
enum class filter_mode
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;
};
/// <summary>
/// Describes a texture object defined in effect code.
/// </summary>
struct texture : texture_desc
{
uint32_t id = 0;
std::string name;
std::string unique_name;
std::string semantic;
std::vector<annotation> annotations;
bool render_target = false;
bool storage_access = false;
};
/// <summary>
/// Describes the binding of a <see cref="texture"/> object.
/// </summary>
struct texture_binding
{
uint32_t binding = 0;
std::string texture_name;
bool srgb = false;
};
/// <summary>
/// Texture filtering modes available for texture sampling operations.
/// </summary>
enum class filter_mode : uint8_t
{
min_mag_mip_point = 0,
min_mag_point_mip_linear = 0x1,
@ -57,13 +128,14 @@ namespace reshadefx
min_linear_mag_mip_point = 0x10,
min_linear_mag_point_mip_linear = 0x11,
min_mag_linear_mip_point = 0x14,
min_mag_mip_linear = 0x15
min_mag_mip_linear = 0x15,
anisotropic = 0x55
};
/// <summary>
/// Specifies behavior of sampling with texture coordinates outside an image.
/// Sampling behavior at texture coordinates outside the bounds of a texture resource.
/// </summary>
enum class texture_address_mode
enum class texture_address_mode : uint8_t
{
wrap = 1,
mirror = 2,
@ -72,9 +144,117 @@ namespace reshadefx
};
/// <summary>
/// Specifies RGB or alpha blending operations.
/// Describes the properties of a <see cref="sampler"/> object.
/// </summary>
enum class pass_blend_op : uint8_t
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;
};
/// <summary>
/// Describes a texture sampler object defined in effect code.
/// </summary>
struct sampler : sampler_desc
{
reshadefx::type type = {};
uint32_t id = 0;
std::string name;
std::string unique_name;
std::string texture_name;
std::vector<annotation> annotations;
bool srgb = false;
};
/// <summary>
/// Describes the binding of a <see cref="sampler"/> object.
/// </summary>
struct sampler_binding : sampler_desc
{
uint32_t binding = 0;
};
/// <summary>
/// Describes the properties of a <see cref="storage"/> object.
/// </summary>
struct storage_desc
{
uint16_t level = 0;
};
/// <summary>
/// Describes a texture storage object defined in effect code.
/// </summary>
struct storage : storage_desc
{
reshadefx::type type = {};
uint32_t id = 0;
std::string name;
std::string unique_name;
std::string texture_name;
};
/// <summary>
/// Describes the binding of a <see cref="storage"/> object.
/// </summary>
struct storage_binding : storage_desc
{
uint32_t binding = 0;
std::string texture_name;
};
/// <summary>
/// Describes a uniform variable defined in effect code.
/// </summary>
struct uniform
{
reshadefx::type type = {};
std::string name;
uint32_t size = 0;
uint32_t offset = 0;
std::vector<annotation> annotations;
bool has_initializer_value = false;
reshadefx::constant initializer_value = {};
};
/// <summary>
/// Type of a shader entry point.
/// </summary>
enum class shader_type
{
unknown,
vertex,
pixel,
compute
};
/// <summary>
/// Describes a function defined in effect code.
/// </summary>
struct function
{
reshadefx::type return_type = {};
uint32_t id = 0;
std::string name;
std::string unique_name;
std::string return_semantic;
std::vector<member_type> parameter_list;
shader_type type = shader_type::unknown;
int num_threads[3] = {};
std::vector<uint32_t> referenced_samplers;
std::vector<uint32_t> referenced_storages;
std::vector<uint32_t> referenced_functions;
};
/// <summary>
/// Color or alpha blending operations.
/// </summary>
enum class blend_op : uint8_t
{
add = 1,
subtract,
@ -84,9 +264,9 @@ namespace reshadefx
};
/// <summary>
/// Specifies blend factors, which modulate values between the pixel shader output and render target.
/// Blend factors in color or alpha blending operations, which modulate values between the pixel shader output and render target.
/// </summary>
enum class pass_blend_factor : uint8_t
enum class blend_factor : uint8_t
{
zero = 0,
one = 1,
@ -101,9 +281,9 @@ namespace reshadefx
};
/// <summary>
/// Specifies the stencil operations that can be performed during depth-stencil testing.
/// Stencil operations that can be performed during depth-stencil testing.
/// </summary>
enum class pass_stencil_op : uint8_t
enum class stencil_op : uint8_t
{
zero = 0,
keep,
@ -116,9 +296,9 @@ namespace reshadefx
};
/// <summary>
/// Specifies comparison options for depth-stencil testing.
/// Comparison operations for depth-stencil testing.
/// </summary>
enum class pass_stencil_func : uint8_t
enum class stencil_func : uint8_t
{
never,
less,
@ -143,205 +323,70 @@ namespace reshadefx
};
/// <summary>
/// A struct type defined in the effect code.
/// Describes a render pass with all its state info.
/// </summary>
struct struct_info
{
std::string name;
std::string unique_name;
std::vector<struct struct_member_info> member_list;
uint32_t definition = 0;
};
/// <summary>
/// A struct field defined in the effect code.
/// </summary>
struct struct_member_info
{
reshadefx::type type;
std::string name;
std::string semantic;
reshadefx::location location;
uint32_t definition = 0;
};
/// <summary>
/// An annotation attached to a variable.
/// </summary>
struct annotation
{
reshadefx::type type;
std::string name;
reshadefx::constant value;
};
/// <summary>
/// A texture defined in the effect code.
/// </summary>
struct texture_info
{
uint32_t id = 0;
uint32_t binding = 0;
std::string name;
std::string semantic;
std::string unique_name;
std::vector<annotation> annotations;
texture_type type = texture_type::texture_2d;
uint32_t width = 1;
uint32_t height = 1;
uint16_t depth = 1;
uint16_t levels = 1;
texture_format format = texture_format::rgba8;
bool render_target = false;
bool storage_access = false;
};
/// <summary>
/// A texture sampler defined in the effect code.
/// </summary>
struct sampler_info
{
uint32_t id = 0;
uint32_t binding = 0;
uint32_t texture_binding = 0;
std::string name;
reshadefx::type type;
std::string unique_name;
std::string texture_name;
std::vector<annotation> annotations;
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;
uint8_t srgb = false;
};
/// <summary>
/// A texture storage object defined in the effect code.
/// </summary>
struct storage_info
{
uint32_t id = 0;
uint32_t binding = 0;
std::string name;
reshadefx::type type;
std::string unique_name;
std::string texture_name;
uint16_t level = 0;
};
/// <summary>
/// An uniform variable defined in the effect code.
/// </summary>
struct uniform_info
{
std::string name;
reshadefx::type type;
uint32_t size = 0;
uint32_t offset = 0;
std::vector<annotation> annotations;
bool has_initializer_value = false;
reshadefx::constant initializer_value;
};
/// <summary>
/// Type of a shader entry point.
/// </summary>
enum class shader_type
{
vs,
ps,
cs,
};
/// <summary>
/// A shader entry point function.
/// </summary>
struct entry_point
{
std::string name;
shader_type type;
};
/// <summary>
/// A function defined in the effect code.
/// </summary>
struct function_info
{
uint32_t definition;
std::string name;
std::string unique_name;
reshadefx::type return_type;
std::string return_semantic;
std::vector<struct_member_info> parameter_list;
std::unordered_set<uint32_t> referenced_samplers;
std::unordered_set<uint32_t> referenced_storages;
};
/// <summary>
/// A render pass with all its state info.
/// </summary>
struct pass_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;
uint8_t generate_mipmaps = true;
uint8_t clear_render_targets = false;
uint8_t srgb_write_enable = false;
uint8_t blend_enable[8] = { false, false, false, false, false, false, false, false };
uint8_t stencil_enable = false;
uint8_t color_write_mask[8] = { 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF };
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;
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 };
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 };
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 };
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 };
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 };
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 };
pass_stencil_func stencil_comparison_func = pass_stencil_func::always;
uint32_t stencil_reference_value = 0;
pass_stencil_op stencil_op_pass = pass_stencil_op::keep;
pass_stencil_op stencil_op_fail = pass_stencil_op::keep;
pass_stencil_op stencil_op_depth_fail = pass_stencil_op::keep;
uint32_t num_vertices = 3;
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;
std::vector<sampler_info> samplers;
std::vector<storage_info> storages;
// 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_binding> texture_bindings;
std::vector<sampler_binding> sampler_bindings;
std::vector<storage_binding> storage_bindings;
};
/// <summary>
/// A collection of passes that make up an effect.
/// </summary>
struct technique_info
struct technique
{
std::string name;
std::vector<pass_info> passes;
std::vector<pass> passes;
std::vector<annotation> annotations;
};
/// <summary>
/// In-memory representation of an effect file.
/// </summary>
struct module
struct effect_module
{
std::vector<char> code;
std::vector<std::pair<std::string, shader_type>> entry_points;
std::vector<entry_point> entry_points;
std::vector<texture_info> textures;
std::vector<sampler_info> samplers;
std::vector<storage_info> storages;
std::vector<uniform_info> uniforms, spec_constants;
std::vector<technique_info> techniques;
std::vector<texture> textures;
std::vector<sampler> samplers;
std::vector<storage> storages;
std::vector<uniform> uniforms;
std::vector<uniform> spec_constants;
std::vector<technique> techniques;
uint32_t total_uniform_size = 0;
uint32_t num_texture_bindings = 0;

View File

@ -58,14 +58,14 @@ namespace reshadefx
bool peek_multary_op(unsigned int &precedence) const;
bool accept_assignment_op();
void parse_top(bool &parse_success);
bool parse_top(bool &parse_success);
bool parse_struct();
bool parse_function(type type, std::string name);
bool parse_function(type type, std::string name, shader_type stype, int num_threads[3]);
bool parse_variable(type type, std::string name, bool global = false);
bool parse_technique();
bool parse_technique_pass(pass_info &info);
bool parse_technique_pass(pass &info);
bool parse_type(type &type);
bool parse_array_size(type &type);
bool parse_array_length(type &type);
bool parse_expression(expression &expression);
bool parse_expression_unary(expression &expression);
bool parse_expression_multary(expression &expression, unsigned int precedence = 0);
@ -74,15 +74,16 @@ namespace reshadefx
bool parse_statement(bool scoped);
bool parse_statement_block(bool scoped);
codegen *_codegen = nullptr;
std::string _errors;
token _token, _token_next, _token_backup;
std::unique_ptr<class lexer> _lexer;
size_t _lexer_backup_offset = 0;
class codegen *_codegen = nullptr;
token _token;
token _token_next;
token _token_backup;
std::vector<uint32_t> _loop_break_target_stack;
std::vector<uint32_t> _loop_continue_target_stack;
reshadefx::function_info *_current_function = nullptr;
};
}

View File

@ -154,17 +154,16 @@ namespace reshadefx
void expand_macro(const std::string &name, const macro &macro, const std::vector<std::string> &arguments);
void create_macro_replacement_list(macro &macro);
bool _success = true;
include_file_exists_callback _file_exists_cb;
include_read_file_callback _read_file_cb;
std::string _output, _errors;
std::string _current_token_raw_data;
reshadefx::token _token;
location _output_location;
std::vector<input_level> _input_stack;
size_t _next_input_index = 0;
size_t _current_input_index = 0;
reshadefx::token _token;
std::string _current_token_raw_data;
reshadefx::location _output_location;
std::vector<if_level> _if_stack;

View File

@ -42,7 +42,7 @@ namespace reshadefx
uint32_t id = 0;
reshadefx::type type = {};
reshadefx::constant constant = {};
const reshadefx::function_info *function = nullptr;
const reshadefx::function *function = nullptr;
};
struct scoped_symbol : symbol
{

View File

@ -8,6 +8,7 @@
#include <cstdint>
#include <string>
#include <vector>
#include <cstdint>
namespace reshadefx
{
@ -246,7 +247,7 @@ namespace reshadefx
};
std::string literal_as_string;
inline operator tokenid() const { return id; }
operator tokenid() const { return id; }
static std::string id_to_name(tokenid id);
};