Updated spirv-cross.

This commit is contained in:
Бранимир Караџић 2021-06-06 18:16:43 -07:00
parent e0b3c2635d
commit 9390ad819e
4 changed files with 57 additions and 3 deletions

View File

@ -1137,6 +1137,7 @@ static string compile_iteration(const CLIArguments &args, std::vector<uint32_t>
msl_opts.emulate_subgroups = args.msl_emulate_subgroups;
msl_opts.fixed_subgroup_size = args.msl_fixed_subgroup_size;
msl_opts.force_sample_rate_shading = args.msl_force_sample_rate_shading;
msl_opts.ios_support_base_vertex_instance = true;
msl_comp->set_msl_options(msl_opts);
for (auto &v : args.msl_discrete_descriptor_sets)
msl_comp->add_discrete_descriptor_set(v);

View File

@ -823,6 +823,22 @@ void CompilerGLSL::emit_header()
statement("#extension ", ext, " : enable");
statement("#endif");
}
else if (ext == "GL_EXT_control_flow_attributes")
{
// These are just hints so we can conditionally enable and fallback in the shader.
statement("#if defined(GL_EXT_control_flow_attributes)");
statement("#extension GL_EXT_control_flow_attributes : require");
statement("#define SPIRV_CROSS_FLATTEN [[flatten]]");
statement("#define SPIRV_CROSS_BRANCH [[dont_flatten]]");
statement("#define SPIRV_CROSS_UNROLL [[unroll]]");
statement("#define SPIRV_CROSS_LOOP [[dont_unroll]]");
statement("#else");
statement("#define SPIRV_CROSS_FLATTEN");
statement("#define SPIRV_CROSS_BRANCH");
statement("#define SPIRV_CROSS_UNROLL");
statement("#define SPIRV_CROSS_LOOP");
statement("#endif");
}
else
statement("#extension ", ext, " : require");
}
@ -7108,7 +7124,11 @@ string CompilerGLSL::to_function_args(const TextureFunctionArguments &args, bool
{
forward = forward && should_forward(args.component);
farg_str += ", ";
farg_str += to_expression(args.component);
auto &component_type = expression_type(args.component);
if (component_type.basetype == SPIRType::Int)
farg_str += to_expression(args.component);
else
farg_str += join("int(", to_expression(args.component), ")");
}
*p_forward = forward;
@ -14000,7 +14020,10 @@ void CompilerGLSL::branch(BlockID from, uint32_t cond, BlockID true_block, Block
if (!true_block_needs_code && !false_block_needs_code)
return;
emit_block_hints(get<SPIRBlock>(from));
// We might have a loop merge here. Only consider selection flattening constructs.
// Loop hints are handled explicitly elsewhere.
if (from_block.hint == SPIRBlock::HintFlatten || from_block.hint == SPIRBlock::HintDontFlatten)
emit_block_hints(from_block);
if (true_block_needs_code)
{
@ -14506,6 +14529,7 @@ void CompilerGLSL::emit_block_chain(SPIRBlock &block)
// for (;;) { create-temporary; break; } consume-temporary;
// so force-declare temporaries here.
emit_hoisted_temporaries(block.potential_declare_temporary);
emit_block_hints(block);
statement("for (;;)");
begin_scope();
@ -15372,8 +15396,32 @@ void CompilerGLSL::convert_non_uniform_expression(string &expr, uint32_t ptr_id)
expr.substr(end_array_index, string::npos));
}
void CompilerGLSL::emit_block_hints(const SPIRBlock &)
void CompilerGLSL::emit_block_hints(const SPIRBlock &block)
{
if ((options.es && options.version < 310) || (!options.es && options.version < 140))
return;
switch (block.hint)
{
case SPIRBlock::HintFlatten:
require_extension_internal("GL_EXT_control_flow_attributes");
statement("SPIRV_CROSS_FLATTEN");
break;
case SPIRBlock::HintDontFlatten:
require_extension_internal("GL_EXT_control_flow_attributes");
statement("SPIRV_CROSS_BRANCH");
break;
case SPIRBlock::HintUnroll:
require_extension_internal("GL_EXT_control_flow_attributes");
statement("SPIRV_CROSS_UNROLL");
break;
case SPIRBlock::HintDontUnroll:
require_extension_internal("GL_EXT_control_flow_attributes");
statement("SPIRV_CROSS_LOOP");
break;
default:
break;
}
}
void CompilerGLSL::preserve_alias_on_reset(uint32_t id)

View File

@ -15936,3 +15936,7 @@ const char *CompilerMSL::get_combined_sampler_suffix() const
{
return sampler_name_suffix.c_str();
}
void CompilerMSL::emit_block_hints(const SPIRBlock &)
{
}

View File

@ -730,6 +730,7 @@ protected:
const std::string &qualifier = "", uint32_t base_offset = 0) override;
void emit_struct_padding_target(const SPIRType &type) override;
std::string type_to_glsl(const SPIRType &type, uint32_t id = 0) override;
void emit_block_hints(const SPIRBlock &block) override;
// Allow Metal to use the array<T> template to make arrays a value type
std::string type_to_array_glsl(const SPIRType &type) override;