diff options
author | Hans-Kristian Arntzen <post@arntzen-software.no> | 2019-01-04 15:19:50 +0300 |
---|---|---|
committer | Hans-Kristian Arntzen <post@arntzen-software.no> | 2019-01-04 16:56:12 +0300 |
commit | acae607703ce8a3a417cbe0417041de5b891f300 (patch) | |
tree | 213e3222757ab0006513bdc38645f93dd516cd0b /reference/opt/shaders/comp | |
parent | 2154d7f06471f2178224d5da3190b1eb2190e008 (diff) |
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.
Diffstat (limited to 'reference/opt/shaders/comp')
-rw-r--r-- | reference/opt/shaders/comp/generate_height.comp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/reference/opt/shaders/comp/generate_height.comp b/reference/opt/shaders/comp/generate_height.comp index d9b1a7b8..feb8d41c 100644 --- a/reference/opt/shaders/comp/generate_height.comp +++ b/reference/opt/shaders/comp/generate_height.comp @@ -41,6 +41,7 @@ void main() } 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; @@ -48,8 +49,8 @@ void main() vec2 _387 = _316.xx; vec2 _392 = _316.yy; vec2 _395 = _392 * _137.distribution[_280].yx; - vec2 _421 = _392 * _137.distribution[(_455 * _276) + _454].yx; - vec2 _429 = (_137.distribution[(_455 * _276) + _454] * _387) + vec2(-_421.x, _421.y); + 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)); } |