20161117 - Mechanics of Vulkan SPIR-V Specialization


References
SPIR-V | Vulkan

SPIR-V Background

Human readable SPIR-V example.

%1 = OpTypeInt 32 1       ; declare a signed 32-bit type
OpDecorate %2 SpecId 3    ; set 'constantID = 3' 
%2 = OpSpecConstant %1 -8 ; some signed 32-bit integer constant

Vulkan Background
Showing below the related structures which show how to set specialization constants.

typedef struct VkSpecializationMapEntry {
  uint32_t constantID; // SpecId in SPIR-V source.
  uint32_t offset;     // Byte offset in VkSpecializationInfo.pData for value.
  size_t   size;
} VkSpecializationMapEntry;

// Passed into  VkPipelineShaderStageCreateInfo
typedef struct VkSpecializationInfo {
  uint32_t                        mapEntryCount;
  const VkSpecializationMapEntry* pMapEntries;
  size_t                          dataSize;
  const void*                     pData;
} VkSpecializationInfo;