Only split expression in OpCompositeExtract if we forward the temporary.

This commit is contained in:
Hans-Kristian Arntzen 2016-06-23 12:11:36 +02:00
parent 9d4360fddf
commit 4bb9f092ab
3 changed files with 30 additions and 1 deletions

View File

@ -0,0 +1,15 @@
#version 310 es
precision mediump float;
precision highp int;
layout(binding = 0) uniform mediump sampler2D Texture;
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
void main()
{
float f = texture(Texture, vTexCoord).x;
FragColor = vec4((f * f));
}

View File

@ -0,0 +1,11 @@
#version 310 es
precision mediump float;
layout(binding = 0) uniform sampler2D Texture;
layout(location = 0) out vec4 FragColor;
layout(location = 0) in vec2 vTexCoord;
void main()
{
float f = texture(Texture, vTexCoord).x;
FragColor = vec4(f * f);
}

View File

@ -2811,8 +2811,11 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
auto &type = get<SPIRType>(result_type);
// We can only split the expression here if our expression is forwarded as a temporary.
bool allow_base_expression = forced_temporaries.find(id) == end(forced_temporaries);
// Only apply this optimization if result is scalar.
if (should_forward(ops[2]) && type.vecsize == 1 && type.columns == 1 && length == 1)
if (allow_base_expression && should_forward(ops[2]) && type.vecsize == 1 && type.columns == 1 && length == 1)
{
// We want to split the access chain from the base.
// This is so we can later combine different CompositeExtract results