acae607703
This is required to avoid relying on complex sub-expression elimination in compilers, and generates cleaner code. The problem case is if a complex expression is used in an access chain, like: Composite comp = buffer[texture(...)]; vec4 a = comp.a + comp.b + comp.c; Before, we did not have common subexpression tracking for OpLoad/OpAccessChain, so we easily ended up with code like: vec4 a = buffer[texture(...)].a + buffer[texture(...)].b + buffer[texture(...)].c; A good compiler will optimize this, but we should not rely on it, and forcing texture(...) to a temporary also looks better. The solution is to add a vector "implied_expression_reads", which works similarly to expression_dependencies. We also need an extra mechanism in to_expression which lets us skip expression read checking and do it later. E.g. for expr -> access chain -> load, we should only trigger a read of expr when using the loaded expression.
45 lines
1.2 KiB
GLSL
45 lines
1.2 KiB
GLSL
Texture2D<float4> uCombined[4] : register(t0);
|
|
SamplerState _uCombined_sampler[4] : register(s0);
|
|
Texture2D<float4> uTex[4] : register(t4);
|
|
SamplerState uSampler[4] : register(s8);
|
|
RWTexture2D<float4> uImage[8] : register(u12);
|
|
|
|
static float4 gl_FragCoord;
|
|
static float2 vTex;
|
|
static int vIndex;
|
|
|
|
struct SPIRV_Cross_Input
|
|
{
|
|
float2 vTex : TEXCOORD0;
|
|
nointerpolation int vIndex : TEXCOORD1;
|
|
float4 gl_FragCoord : SV_Position;
|
|
};
|
|
|
|
float4 sample_in_function(Texture2D<float4> samp, SamplerState _samp_sampler)
|
|
{
|
|
return samp.Sample(_samp_sampler, vTex);
|
|
}
|
|
|
|
float4 sample_in_function2(Texture2D<float4> tex, SamplerState samp)
|
|
{
|
|
return tex.Sample(samp, vTex);
|
|
}
|
|
|
|
void frag_main()
|
|
{
|
|
float4 color = uCombined[vIndex].Sample(_uCombined_sampler[vIndex], vTex);
|
|
color += uTex[vIndex].Sample(uSampler[vIndex], vTex);
|
|
int _72 = vIndex + 1;
|
|
color += sample_in_function(uCombined[_72], _uCombined_sampler[_72]);
|
|
color += sample_in_function2(uTex[vIndex + 1], uSampler[vIndex + 1]);
|
|
uImage[vIndex][int2(gl_FragCoord.xy)] = color;
|
|
}
|
|
|
|
void main(SPIRV_Cross_Input stage_input)
|
|
{
|
|
gl_FragCoord = stage_input.gl_FragCoord;
|
|
vTex = stage_input.vTex;
|
|
vIndex = stage_input.vIndex;
|
|
frag_main();
|
|
}
|