Unfortunately the page http://gpuopen.com/gcn-shader-extensions-for-direct3d-and-vulkan/ does not contain any information.
Also nothing here: https://www.opengl.org/registry/specs/ARB/shader_ballot.txt
Trying to compile with AMDs glslangValidator only gives me 'no matching overloaded function found', no matter how many parameters i give.
So, is the extension working and what are the function parameters we need to set? What's the returned value?
Solved! Go to Solution.
Due to reasons beyond our control, we had to put the release of the AMD_shader_ballot extension specification on hold for now. We are in the process of sorting the situation out, please allow us a few more weeks.
The example attached to the article you posted a link to should work just fine. It's just the ARB_shader_ballot functions apart from ballotARB() and mbcntAMD() which are not supported yet.
Due to reasons beyond our control, we had to put the release of the AMD_shader_ballot extension specification on hold for now. We are in the process of sorting the situation out, please allow us a few more weeks.
The example attached to the article you posted a link to should work just fine. It's just the ARB_shader_ballot functions apart from ballotARB() and mbcntAMD() which are not supported yet.
Thanks.
In the meantime i was able to figure it out with the help of function signatures found on this page: glslang/Initialize.cpp at master · KhronosGroup/glslang · GitHub
So here is a small example if someone is interested:
void main ()
{
uint r = gl_LocalInvocationID.x;
uvec4 v = uvec4(3,2,1,0);
output[gl_LocalInvocationID.x] = swizzleInvocationsAMD(r, v); // output: 3,2,1,0, 7,6,5,4, ...
}
Unfortunately glslangValidator.exe coming with the ballot example breaks if the shader contains math functions like sqrt or floor, i've opened an issue on GutHub.
I really hope permute instructions (http://gpuopen.com/amd-gcn-assembly-cross-lane-operations/) will get exposed too in the future
We're going to keep that request in mind 🙂
In the meantime, would you mind posting an example shader which is crashing for you? I'd love to have a peek .. Thanks!
To reproduce the math functions issue and crash,
you can use the VkMBCNT project from github and modify the shader to use a math function, e.g:
#version 450
#extension GL_AMD_shader_ballot : require
#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];
float thisLaneData = floor(inputDataArray [gl_LocalInvocationID.x]); // <- usage of floor() breaks in combination with extensions
bool laneActive = (thisLaneData > 0);
uint thisLaneOutputSlot = mbcntAMD (ballotARB (laneActive));
if (laneActive) {
outputDataArray[thisLaneOutputSlot] = thisLaneData;
}
}
It should be irrelevant, but i modified the demo to load spv directly to avoid python. The crash then happens at vkCreateShaderModule():
static VkShaderModule LoadSPV (VkDevice device, const char *filename)
{
long int size;
size_t retval;
void *shader_code;
FILE *fp = fopen(filename, "rb");
if (!fp) return NULL;
fseek(fp, 0L, SEEK_END);
size = ftell(fp);
fseek(fp, 0L, SEEK_SET);
shader_code = malloc(size);
retval = fread(shader_code, size, 1, fp);
assert(retval == 1);
//*psize = size;
fclose(fp);
//return (char *) shader_code;
VkResult err;
VkShaderModuleCreateInfo moduleCreateInfo = {};
moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
moduleCreateInfo.pNext = NULL;
moduleCreateInfo.codeSize = size;
moduleCreateInfo.pCode = (const uint32_t*) shader_code;
moduleCreateInfo.flags = 0;
VkShaderModule module;
err = vkCreateShaderModule (device, &moduleCreateInfo, NULL, &module); // <- access violation
assert(!err);
free(shader_code);
return module;
}
I can't get that issue to reproduce on my end, which means we have very likely already addressed this problem internally. Let's resume this thread once shader_ballot extension is out and the problem persists, if that's OK.
One last request. Would you be able to send me the SPIR-V blob you pass to vkCreateShaderModule(), which causes the func to crash? You can find my e-mail address in my profile page. Thanks!
Sorry, i can't see your e-mail address on profile (dwitczak ).
Can you send me a message?
Done
Just as promised, we've just a released a SPV extension which adds support for the functions you were asking for: SPIR-V Extension SPV_AMD_shader_ballot . A corresponding VK extension will be released later this or next week. 🙂
Yes! staying tuned...