cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

joej
Adept I

How to use swizzleInvocationsAMD extension for Vulkan

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?

0 Likes
1 Solution
dwitczak
Staff

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.

View solution in original post

0 Likes
10 Replies
dwitczak
Staff

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.

0 Likes

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

0 Likes

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!

0 Likes

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;

    }

0 Likes

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.

0 Likes

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!

0 Likes

Sorry, i can't see your e-mail address on profile (dwitczak ).

Can you send me a message?

0 Likes

Done

0 Likes

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. 🙂

0 Likes

Yes! staying tuned...

0 Likes