Fix Options::force_temporary to work with OpenGL GLSL
Setting force_temporary to true produces invalid GLSL because sampler variables are copied: highp sampler2D _377 = DiffuseMapTexture; This change fixes the problem by always forwarding forwardable variables. I also took an opportunity to restructure the code to make it easier to read and add extra conditions to in the future.
This commit is contained in:
parent
236df43689
commit
7f055e8a68
@ -5856,11 +5856,21 @@ std::pair<std::string, uint32_t> CompilerGLSL::flattened_access_chain_offset(con
|
|||||||
|
|
||||||
bool CompilerGLSL::should_forward(uint32_t id)
|
bool CompilerGLSL::should_forward(uint32_t id)
|
||||||
{
|
{
|
||||||
// Immutable expression can always be forwarded.
|
// If id is a variable we will try to forward it regardless of force_temporary check below
|
||||||
// If not immutable, we can speculate about it by forwarding potentially mutable variables.
|
// This is important because otherwise we'll get local sampler copies (highp sampler2D foo = bar) that are invalid in OpenGL GLSL
|
||||||
auto *var = maybe_get<SPIRVariable>(id);
|
auto *var = maybe_get<SPIRVariable>(id);
|
||||||
bool forward = var ? var->forwardable : false;
|
if (var && var->forwardable)
|
||||||
return (is_immutable(id) || forward) && !options.force_temporary;
|
return true;
|
||||||
|
|
||||||
|
// For debugging emit temporary variables for all expressions
|
||||||
|
if (options.force_temporary)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Immutable expression can always be forwarded.
|
||||||
|
if (is_immutable(id))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompilerGLSL::track_expression_read(uint32_t id)
|
void CompilerGLSL::track_expression_read(uint32_t id)
|
||||||
|
Loading…
Reference in New Issue
Block a user