Aqoole_Hateenaの技術日記

vulkan+raytraceで色々描いてます

Shader Stageの指定

Shader Stageの指定

pipeline diagramにあるように、pipelineにはshaderを使用することにより処理を行うpipeline shader stageがある。
aqoole-hateena.hatenablog.com
pipeline shader stageを指定するには、VkPipelineShaderStageCreateInfoを実装するshader stageの数だけ記述する。
最終的にVkGraphicsPipelineCreateInfoに情報を記述することで、pipelineを作成することができる。

VkPipelineShaderStageCreateInfo

VkPipelineShaderStageCreateInfo - Structure specifying parameters of a newly created pipeline shader stage

// Provided by VK_VERSION_1_0
typedef struct VkPipelineShaderStageCreateInfo {
    VkStructureType                     sType;
    const void*                         pNext;
    VkPipelineShaderStageCreateFlags    flags;
    VkShaderStageFlagBits               stage;
    VkShaderModule                      module;
    const char*                         pName;
    const VkSpecializationInfo*         pSpecializationInfo;
} VkPipelineShaderStageCreateInfo;

  • sType is the type of this structure.
  • pNext is NULL or a pointer to a structure extending this structure.
  • flags is a bitmask of VkPipelineShaderStageCreateFlagBits specifying how the pipeline shader stage will be generated.
  • stage is a VkShaderStageFlagBits value specifying a single pipeline stage.
  • module is a VkShaderModule object containing the shader for this stage.
  • pName is a pointer to a null-terminated UTF-8 string specifying the entry point name of the shader for this stage.
  • pSpecializationInfo is a pointer to a VkSpecializationInfo structure, as described in Specialization Constants, or NULL.

VkPipelineShaderStageCreateInfo(3)

VkShaderStageFlagBits

VkShaderStageFlagBits - Bitmask specifying a pipeline stage

// Provided by VK_VERSION_1_0
typedef enum VkShaderStageFlagBits {
    VK_SHADER_STAGE_VERTEX_BIT = 0x00000001,
    VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT = 0x00000002,
    VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT = 0x00000004,
    VK_SHADER_STAGE_GEOMETRY_BIT = 0x00000008,
    VK_SHADER_STAGE_FRAGMENT_BIT = 0x00000010,
    VK_SHADER_STAGE_COMPUTE_BIT = 0x00000020,
    VK_SHADER_STAGE_ALL_GRAPHICS = 0x0000001F,
    VK_SHADER_STAGE_ALL = 0x7FFFFFFF,
:
}VkShaderStageFlagBits;

  • VK_SHADER_STAGE_VERTEX_BIT specifies the vertex stage.
  • VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT specifies the tessellation control stage.
  • VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT specifies the tessellation evaluation stage.
  • VK_SHADER_STAGE_GEOMETRY_BIT specifies the geometry stage.
  • VK_SHADER_STAGE_FRAGMENT_BIT specifies the fragment stage.
  • VK_SHADER_STAGE_COMPUTE_BIT specifies the compute stage.
  • VK_SHADER_STAGE_ALL_GRAPHICS is a combination of bits used as shorthand to specify all graphics stages defined above (excluding the compute stage).
  • VK_SHADER_STAGE_ALL is a combination of bits used as shorthand to specify all shader stages supported by the device, including all additional stages which are introduced by extensions.

VkShaderStageFlagBits(3)

Ray tracingやVK_NV_などの拡張期機能は割愛している。
Rasterizationのpipelineで指定できるshader stageの種類は、基本的にはここに定義されている5種類しかない。(COMPUTE_BITを除く)