diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index 240c6050..0b3bb6a2 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -5856,11 +5856,21 @@ std::pair CompilerGLSL::flattened_access_chain_offset(con bool CompilerGLSL::should_forward(uint32_t id) { - // Immutable expression can always be forwarded. - // If not immutable, we can speculate about it by forwarding potentially mutable variables. + // If id is a variable we will try to forward it regardless of force_temporary check below + // 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(id); - bool forward = var ? var->forwardable : false; - return (is_immutable(id) || forward) && !options.force_temporary; + if (var && var->forwardable) + 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)