|
|
@@ -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)
|