From 77b5b4446b99bae630630bdb350299d45bad238d Mon Sep 17 00:00:00 2001 From: David Srbecky Date: Mon, 26 Jun 2017 18:32:53 +0100 Subject: [PATCH] Always make a copy when handling OpCompositeInsert The modified object might not be mutable (e.g. shader input). Added a test for the case when this happens. --- reference/shaders/frag/sampler-proj.frag | 16 ++++++++++++++++ shaders/frag/sampler-proj.frag | 12 ++++++++++++ spirv_glsl.cpp | 24 +++++------------------- 3 files changed, 33 insertions(+), 19 deletions(-) create mode 100644 reference/shaders/frag/sampler-proj.frag create mode 100644 shaders/frag/sampler-proj.frag diff --git a/reference/shaders/frag/sampler-proj.frag b/reference/shaders/frag/sampler-proj.frag new file mode 100644 index 00000000..865dec6c --- /dev/null +++ b/reference/shaders/frag/sampler-proj.frag @@ -0,0 +1,16 @@ +#version 310 es +precision mediump float; +precision highp int; + +layout(binding = 0) uniform mediump sampler2D uTex; + +layout(location = 0) out vec4 FragColor; +layout(location = 0) in vec4 vTex; + +void main() +{ + highp vec4 _19 = vTex; + _19.z = vTex.w; + FragColor = textureProj(uTex, _19.xyz); +} + diff --git a/shaders/frag/sampler-proj.frag b/shaders/frag/sampler-proj.frag new file mode 100644 index 00000000..21fa5c02 --- /dev/null +++ b/shaders/frag/sampler-proj.frag @@ -0,0 +1,12 @@ +#version 310 es +precision mediump float; + +layout(location = 0) in vec4 vTex; +layout(binding = 0) uniform sampler2D uTex; +layout(location = 0) out vec4 FragColor; + +void main() +{ + FragColor = textureProj(uTex, vTex); +} + diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index 2f75aed8..7b9e66bf 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -4732,26 +4732,12 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction) flush_variable_declaration(composite); - auto *expr = maybe_get(id); - if ((expr && expr->used_while_invalidated) || !should_forward(composite)) - { - // Make a copy, then use access chain to store the variable. - statement(declare_temporary(result_type, id), to_expression(composite), ";"); - set(id, to_name(id), result_type, true); - auto chain = access_chain_internal(id, elems, length, true); - statement(chain, " = ", to_expression(obj), ";"); - } - else - { - auto chain = access_chain_internal(composite, elems, length, true); - statement(chain, " = ", to_expression(obj), ";"); - set(id, to_expression(composite), result_type, true); + // Make a copy, then use access chain to store the variable. + statement(declare_temporary(result_type, id), to_expression(composite), ";"); + set(id, to_name(id), result_type, true); + auto chain = access_chain_internal(id, elems, length, true); + statement(chain, " = ", to_expression(obj), ";"); - register_write(composite); - register_read(id, composite, true); - // Invalidate the old expression we inserted into. - invalid_expressions.insert(composite); - } break; }