9.1. 计算管线
计算管线有单个静态计算着色器阶段和管线布局组成。
计算管线代表着一个计算着色器,通过参数module
和 pName
从计算着色器中选择一个入口点来 调用vkCreateComputePipelines
, 这个入口点定义了一个有效的计算着色器,包含在VkComputePipelineCreateInfo
数据结构中的VkPipelineShaderStageCreateInfo
。
可调用如下命令来创建计算管线:
VkResult vkCreateComputePipelines(
VkDevice device,
VkPipelineCache pipelineCache,
uint32_t createInfoCount,
const VkComputePipelineCreateInfo* pCreateInfos,
const VkAllocationCallbacks* pAllocator,
VkPipeline* pPipelines);
-
device
是创建计算管线的逻辑设备。 -
pipelineCache
要么是VK_NULL_HANDLE
,表示禁止使用管线缓存;要么是一个有效的 pipeline cache 对象的 handle, 此时命令执行期间启用管线缓存。 -
createInfoCount
是pCreateInfos
和pPipelines
数组的长度。 -
pCreateInfos
是一个VkComputePipelineCreateInfo
数组。 -
pAllocator
控制了CPU端内存分配,如 Memory Allocation 一章所描述 -
pPipelines
是一个指针,指向了承载被返回的计算管线对象的数组。editing-noteTODO (Jon) - Should we say something like ``the i’th element of the
pPipelines
array is created based on the corresponding element of thepCreateInfos
array''? Also forvkCreateGraphicsPipelines
below.
VkComputePipelineCreateInfo
数据结构定义如下:
typedef struct VkComputePipelineCreateInfo {
VkStructureType sType;
const void* pNext;
VkPipelineCreateFlags flags;
VkPipelineShaderStageCreateInfo stage;
VkPipelineLayout layout;
VkPipeline basePipelineHandle;
int32_t basePipelineIndex;
} VkComputePipelineCreateInfo;
-
sType
是数据结构的类型。 -
pNext
是NULL
或者一个指向拓展特定的数据结构的指针。 -
flags
提供了管线创建的可选信息,枚举类型为VkPipelineCreateFlagBits
。 -
stage
是一个VkPipelineShaderStageCreateInfo
,描述了计算着色器。 -
layout
is the description of binding locations used by both the pipeline and descriptor sets used with the pipeline. -
basePipelineHandle
is a pipeline to derive from -
basePipelineIndex
is an index into thepCreateInfos
parameter to use as a pipeline to derive from
参数 basePipelineHandle
和 basePipelineIndex
在Pipeline Derivatives 中有详细描述。
stage
指向一个类型为VkPipelineShaderStageCreateInfo
的数据
VkPipelineShaderStageCreateInfo
类型数据结构定义如下:
typedef struct VkPipelineShaderStageCreateInfo {
VkStructureType sType;
const void* pNext;
VkPipelineShaderStageCreateFlags flags;
VkShaderStageFlagBits stage;
VkShaderModule module;
const char* pName;
const VkSpecializationInfo* pSpecializationInfo;
} VkPipelineShaderStageCreateInfo;
-
sType
是数据结构的类型。 -
pNext
是NULL
或者一个指向拓展特定的数据结构的指针。 -
flags
被保留。 -
stage
是给管线阶段起的名字。 Bits which can be set include: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;
-
module
是一个VkShaderModule
类型对象,包含了这个阶段的着色器。 -
pName
是一个指针,指向了一个以null结尾的UTF-8字符串,指定了这个阶段着色器入口的名字。 -
pSpecializationInfo
是一个指针,指向了一个VkSpecializationInfo
,在 Specialization Constants中有详细描述, 可以为NULL
。