Search code examples
assemblyshadervulkan

Is there a way to get the compiled assembly code of a shader provided to vulkan


I'd really like to know what kind of assembly code the driver generates for any given shader compiled when submitted to Vulkan, for optimization purposes obviously, and I'd like to do so without using any external tools.

I could not find any resources on this subject for vulkan, while opengl has the getBinary function...


Solution

  • There is no architected way in Vulkan to get the shader code compiled by the driver that I know of. For most proprietary drivers, there's a lot of IP in this area that the owners may not want to expose. In addition, this code is likely to be in the format of some IR or something else that won't mean much unless you have a register spec for the GPU.

    However, the Mali driver has something along these lines in their DDK. There may be other similar solutions for the other vendors, but they would involve using their tools, most likely.

    Another option is to look at the open source drivers, in Mesa for example, and see if they have options for doing this or modifying the drivers to get what you need.

    With Vulkan, the lowest-level shader code that you have easy access to is the SPIR-V generated by the high-level shader compiler (e.g., glslangvalidator). You can modify this as much as you want before "submitting" to Vulkan. And there are a lot of tools (SPIRV-Tools) for manipulating this format.