SPIRV-Cross/shaders-msl/comp/shader_ballot.msl22.comp
Chip Davis 00f14ce74f MSL: Support SPV_KHR_shader_ballot and SPV_KHR_subgroup_vote.
Normally, I wouldn't have bothered with this, given that we already
support the Vulkan 1.1 subgroup functionality, but a client asked for
the legacy extensions.
2023-06-24 15:53:04 -07:00

30 lines
772 B
Plaintext

#version 450
#extension GL_ARB_shader_ballot : require
layout (local_size_x = 64) in;
layout (std430, binding = 0) buffer inputData
{
float inputDataArray[];
};
layout (std430, binding = 1) buffer outputData
{
float outputDataArray[];
};
void main ()
{
float thisLaneData = inputDataArray [gl_LocalInvocationID.x];
bool laneActive = (thisLaneData > 0);
uvec4 activeSlots = bitCount(uvec4(unpackUint2x32(gl_SubGroupLtMaskARB), uvec2(0)) & uvec4(unpackUint2x32(ballotARB (laneActive)), uvec2(0)));
uint thisLaneOutputSlot = activeSlots.x + activeSlots.y;
int firstInvocation = readFirstInvocationARB(1);
int invocation = readInvocationARB(1, 0);
if (laneActive) {
outputDataArray[thisLaneOutputSlot] = thisLaneData;
}
}