SPIRV-Cross/reference/opt/shaders/comp/generate_height.comp
Hans-Kristian Arntzen acae607703 Register implied expression reads in OpLoad/OpAccessChain.
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.
2019-01-04 14:56:12 +01:00

57 lines
1.5 KiB
Plaintext

#version 310 es
layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
layout(binding = 0, std430) readonly buffer Distribution
{
vec2 distribution[];
} _137;
layout(binding = 2, std140) uniform UBO
{
vec4 uModTime;
} _166;
layout(binding = 1, std430) writeonly buffer HeightmapFFT
{
uint heights[];
} _225;
void main()
{
uvec2 _264 = uvec2(64u, 1u) * gl_NumWorkGroups.xy;
uvec2 _269 = _264 - gl_GlobalInvocationID.xy;
bvec2 _271 = equal(gl_GlobalInvocationID.xy, uvec2(0u));
uint _454;
if (_271.x)
{
_454 = 0u;
}
else
{
_454 = _269.x;
}
uint _455;
if (_271.y)
{
_455 = 0u;
}
else
{
_455 = _269.y;
}
uint _276 = _264.x;
uint _280 = (gl_GlobalInvocationID.y * _276) + gl_GlobalInvocationID.x;
uint _290 = (_455 * _276) + _454;
vec2 _297 = vec2(gl_GlobalInvocationID.xy);
vec2 _299 = vec2(_264);
float _309 = sqrt(9.81000041961669921875 * length(_166.uModTime.xy * mix(_297, _297 - _299, greaterThan(_297, _299 * 0.5)))) * _166.uModTime.z;
vec2 _316 = vec2(cos(_309), sin(_309));
vec2 _387 = _316.xx;
vec2 _392 = _316.yy;
vec2 _395 = _392 * _137.distribution[_280].yx;
vec2 _421 = _392 * _137.distribution[_290].yx;
vec2 _429 = (_137.distribution[_290] * _387) + vec2(-_421.x, _421.y);
_225.heights[_280] = packHalf2x16(((_137.distribution[_280] * _387) + vec2(-_395.x, _395.y)) + vec2(_429.x, -_429.y));
}