SPIRV-Cross/reference/opt/shaders/amd/shader_ballot.comp
Hans-Kristian Arntzen 461f1506e7 Do not eagerly invalidate all active variables on a branch.
This is not necessary, as we must emit an invalidating store before we
potentially consume an invalid expression. In fact, we're a bit
conservative here in this case for example:

int tmp = variable;
if (...)
{
    variable = 10;
}
else
{
    // Consuming tmp here is fine, but it was
    // invalidated while emitting other branch.
    // Technically, we need to study if there is an invalidating store
    // in the CFG between the loading block and this block, and the other
    // branch will not be a part of that analysis.
    int tmp2 = tmp * tmp;
}

Fixing this case means complex CFG traversal *everywhere*, and it feels like overkill.

Fixing this exposed a bug with access chains, so fix a bug where expression dependencies were not
inherited properly in access chains. Access chains are now considered forwarded if there
is at least one dependency which is also forwarded.
2019-07-24 11:17:30 +02:00

28 lines
680 B
Plaintext

#version 450
#extension GL_ARB_gpu_shader_int64 : require
#extension GL_ARB_shader_ballot : require
#extension GL_AMD_shader_ballot : require
layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
layout(binding = 0, std430) buffer inputData
{
float inputDataArray[];
} _12;
layout(binding = 1, std430) buffer outputData
{
float outputDataArray[];
} _74;
void main()
{
bool _31 = _12.inputDataArray[gl_LocalInvocationID.x] > 0.0;
uvec4 _37 = uvec4(unpackUint2x32(ballotARB(_31)), 0u, 0u);
uint _44 = mbcntAMD(packUint2x32(uvec2(_37.xy)));
if (_31)
{
_74.outputDataArray[_44] = _12.inputDataArray[gl_LocalInvocationID.x];
}
}