Aqoole_Hateenaの技術日記

vulkan+raytraceで色々描いてます

Input Assemble Stageの指定

Input Assembler Stage

Input Assembler Stageでの処理の記述について調べる。
graphics pipelineのstageの概要は以下に記載。
aqoole-hateena.hatenablog.com

Vertex Input State

レンダリングを行うためには、pipelineにデータを入力する必要がある。
データを入力する際に、どのbufferからデータを取ってくるのかを指定するために、vertex indexやinstance indexを使用できる。

VkPipelineVertexInputStateCreateInfo

shaderがデータを扱えるようにvertex inputの情報を記述する。

// Provided by VK_VERSION_1_0
typedef struct VkPipelineVertexInputStateCreateInfo {
    VkStructureType                             sType;
    const void*                                 pNext;
    VkPipelineVertexInputStateCreateFlags       flags;
    uint32_t                                    vertexBindingDescriptionCount;
    const VkVertexInputBindingDescription*      pVertexBindingDescriptions;
    uint32_t                                    vertexAttributeDescriptionCount;
    const VkVertexInputAttributeDescription*    pVertexAttributeDescriptions;
} VkPipelineVertexInputStateCreateInfo;

VertexInputAttributesとVertexInputBindings

VertexInputAttributes : Vertex shader variablesがbufferにどのように存在しているかを表す。variablesがvkbufferにboundされる際に、variablesとVertexInputAttributesのnumberが紐づく。
VertexInputBindings : vertex dataにbufferをbindする。VertexInputAttributesがVertexInputBindingsに紐づき、VertexInputBindingsはvkbufferに紐づく。

Vertex shaders can define input variables, which receive vertex attribute data transferred from one or more VkBuffer(s) by drawing commands. Vertex shader input variables are bound to buffers via an indirect binding where the vertex shader associates a vertex input attribute number with each variable, vertex input attributes are associated to vertex input bindings on a per-pipeline basis, and vertex input bindings are associated with specific buffers on a per-draw basis via the vkCmdBindVertexBuffers command.
Vulkan® 1.2.203 - A Specification (with all registered Vulkan extensions)

VkVertexInputAttributeDescription

vertex bufferにある各vertexに対して、vertex attributeがどこにあるのかを表す。

// Provided by VK_VERSION_1_0
typedef struct VkVertexInputAttributeDescription {
    uint32_t    location;
    uint32_t    binding;
    VkFormat    format;
    uint32_t    offset;
} VkVertexInputAttributeDescription;

  • location is the shader input location number for this attribute.
  • binding is the binding number which this attribute takes its data from.
  • format is the size and type of the vertex attribute data.
  • offset is a byte offset of this attribute relative to the start of an element in the vertex input binding.

VkVertexInputAttributeDescription(3)

location
vertex shader内で使われるindex。locationは連続である必要もなければ、すべてのlocationがパイプライン内で使用される必要もない。

binding
どのbufferからbindされているのか、このattributeがどこからデータを取ってくるのかを表す。対応するVkVertexInputBindingDescriptionのbindingと一致する。

VkVertexInputBindingDescription

bindしているbufferの詳細を表す。

// Provided by VK_VERSION_1_0
typedef struct VkVertexInputBindingDescription {
    uint32_t             binding;
    uint32_t             stride;
    VkVertexInputRate    inputRate;
} VkVertexInputBindingDescription;

  • binding is the binding number that this structure describes.
  • stride is the byte stride between consecutive elements within the buffer.
  • inputRate is a VkVertexInputRate value specifying whether vertex attribute addressing is a function of the vertex index or of the instance index.

VkVertexInputBindingDescription(3)

binding
bindのindexを表す。

stride
bindされている情報がbufferの先頭からどの距離にあるかを示す(bytes)。

inputRate
vertex attributesのデータがvertex indexかinstance indexであるかを指定する。

VkPipelineInputAssemblyStateCreateInfo


Drawing can be achieved in two modes:

  • Programmable Mesh Shading, the mesh shader assembles primitives, or
  • Programmable Primitive Shading, the input primitives are assembled

as follows.
Each draw is made up of zero or more vertices and zero or more instances, which are processed by the device and result in the assembly of primitives. Primitives are assembled according to the pInputAssemblyState member of the VkGraphicsPipelineCreateInfo structure, which is of type VkPipelineInputAssemblyStateCreateInfo:

mesh shading :
Vulkan® 1.2.203 - A Specification (with all registered Vulkan extensions)
primitive shading :
Vulkan® 1.2.203 - A Specification (with all registered Vulkan extensions)

描画には大きく2つのアプローチがあり、

  • mesh shading : 図形がmesh shaderでassembleされる(組み立てられる)。
  • primitive shading : 頂点やinstanceをもとにassembleされる。

VkPipelineInputAssemblyStateCreateInfoは後者の方法で実行する。

// Provided by VK_VERSION_1_0
typedef struct VkPipelineInputAssemblyStateCreateInfo {
    VkStructureType                            sType;
    const void*                                pNext;
    VkPipelineInputAssemblyStateCreateFlags    flags;
    VkPrimitiveTopology                        topology;
    VkBool32                                   primitiveRestartEnable;
} VkPipelineInputAssemblyStateCreateInfo;

VkPipelineInputAssemblyStateCreateInfo(3)

topology

topology is a VkPrimitiveTopology defining the primitive topology

VkPrimitiveTopology
// Provided by VK_VERSION_1_0
typedef enum VkPrimitiveTopology {
    VK_PRIMITIVE_TOPOLOGY_POINT_LIST = 0,
    VK_PRIMITIVE_TOPOLOGY_LINE_LIST = 1,
    VK_PRIMITIVE_TOPOLOGY_LINE_STRIP = 2,
    VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST = 3,
    VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP = 4,
    VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN = 5,
    VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY = 6,
    VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY = 7,
    VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY = 8,
    VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY = 9,
    VK_PRIMITIVE_TOPOLOGY_PATCH_LIST = 10,
} VkPrimitiveTopology;

VkPrimitiveTopology(3)

primitiveRestartEnable

primitiveRestartEnable controls whether a special vertex index value is treated as restarting the assembly of primitives. This enable only applies to indexed draws (vkCmdDrawIndexed, vkCmdDrawMultiIndexedEXT, and vkCmdDrawIndexedIndirect), and the special index value is either 0xFFFFFFFF when the indexType parameter of vkCmdBindIndexBuffer is equal to VK_INDEX_TYPE_UINT32, 0xFF when indexType is equal to VK_INDEX_TYPE_UINT8_EXT, or 0xFFFF when indexType is equal to VK_INDEX_TYPE_UINT16. Primitive restart is not allowed for “list” topologies, unless one of the features primitiveTopologyPatchListRestart (for VK_PRIMITIVE_TOPOLOGY_PATCH_LIST) or primitiveTopologyListRestart (for all other list topologies) is enabled.

特別なvertex indexで図形のassembleをrestartするかどうかを決める。topoligyがlist系のものでは有効にできない。

Special Value IndexType of vkCmdBindIndexBuffer
0xFFFFFFFF VK_INDEX_TYPE_UINT32
0xFFFF VK_INDEX_TYPE_UINT16
0xFF VK_INDEX_TYPE_UINT8_EXT

更新履歴

2022/1/23 Vertex Input State 新規追加