Function Prototype

vkGetShaderBinaryDataEXT

Get the binary shader code from a shader object

Binary shader code can be retrieved from a shader object using the command:

VkResult vkGetShaderBinaryDataEXT(
    VkDevice device,
    VkShaderEXT shader,
    size_t* pDataSize,
    void* pData);
  • device is the logical device that shader object was created from.
  • shader is the shader object to retrieve binary shader code from.
  • pDataSize is a pointer to a size_t value related to the size of the binary shader code, as described below.
  • pData is either NULL or a pointer to a buffer.

If pData is NULL, then the size of the binary shader code of the shader object, in bytes, is returned in pDataSize. Otherwise, pDataSize must point to a variable set by the application to the size of the buffer, in bytes, pointed to by pData, and on return the variable is overwritten with the amount of data actually written to pData. If pDataSize is less than the size of the binary shader code, nothing is written to pData, and VK_INCOMPLETE will be returned instead of VK_SUCCESS.

The behavior of this command when pDataSize is too small differs from how some other getter-type commands work in Vulkan. Because shader binary data is only usable in its entirety, it would never be useful for the implementation to return partial data. Because of this, nothing is written to pData unless pDataSize is large enough to fit the data in its entirety.

Binary shader code retrieved using vkGetShaderBinaryDataEXT can be passed to a subsequent call to vkCreateShadersEXT on a compatible physical device by specifying VK_SHADER_CODE_TYPE_BINARY_EXT in the codeType member of VkShaderCreateInfoEXT.

The shader code returned by repeated calls to this function with the same VkShaderEXT is guaranteed to be invariant for the lifetime of the VkShaderEXT object.

Valid Usage

VUID-vkGetShaderBinaryDataEXT-None-08499

If pData is not NULL, it must be aligned to 16 bytes

Valid Usage (Implicit)

VUID-vkGetShaderBinaryDataEXT-pDataSize-parameter

pDataSize must be a valid pointer to a size_t value

VUID-vkGetShaderBinaryDataEXT-pData-parameter

If the value referenced by pDataSize is not 0, and pData is not NULL, pData must be a valid pointer to an array of pDataSize bytes

VUID-vkGetShaderBinaryDataEXT-shader-parent

shader must have been created, allocated, or retrieved from device