• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2015-2021 The Khronos Group, Inc.
2//
3// SPDX-License-Identifier: CC-BY-4.0
4
5[[fxvertex]]
6= Fixed-Function Vertex Processing
7
8Vertex fetching is controlled via configurable state, as a logically
9distinct graphics pipeline stage.
10
11
12[[fxvertex-attrib]]
13== Vertex Attributes
14
15Vertex shaders can: define input variables, which receive _vertex attribute_
16data transferred from one or more sname:VkBuffer(s) by drawing commands.
17Vertex shader input variables are bound to buffers via an indirect binding
18where the vertex shader associates a _vertex input attribute_ number with
19each variable, vertex input attributes are associated to _vertex input
20bindings_ on a per-pipeline basis, and vertex input bindings are associated
21with specific buffers on a per-draw basis via the
22fname:vkCmdBindVertexBuffers command.
23Vertex input attribute and vertex input binding descriptions also contain
24format information controlling how data is extracted from buffer memory and
25converted to the format expected by the vertex shader.
26
27There are sname:VkPhysicalDeviceLimits::pname:maxVertexInputAttributes
28number of vertex input attributes and
29sname:VkPhysicalDeviceLimits::pname:maxVertexInputBindings number of vertex
30input bindings (each referred to by zero-based indices), where there are at
31least as many vertex input attributes as there are vertex input bindings.
32Applications can: store multiple vertex input attributes interleaved in a
33single buffer, and use a single vertex input binding to access those
34attributes.
35
36In GLSL, vertex shaders associate input variables with a vertex input
37attribute number using the code:location layout qualifier.
38The code:component layout qualifier associates components of a vertex shader
39input variable with components of a vertex input attribute.
40
41.GLSL example
42[source,glsl]
43---------------------------------------------------
44// Assign location M to variableName
45layout (location=M, component=2) in vec2 variableName;
46
47// Assign locations [N,N+L) to the array elements of variableNameArray
48layout (location=N) in vec4 variableNameArray[L];
49---------------------------------------------------
50
51In SPIR-V, vertex shaders associate input variables with a vertex input
52attribute number using the code:Location decoration.
53The code:Component decoration associates components of a vertex shader input
54variable with components of a vertex input attribute.
55The code:Location and code:Component decorations are specified via the
56code:OpDecorate instruction.
57
58.SPIR-V example
59[source,spirv]
60---------------------------------------------------
61               ...
62          %1 = OpExtInstImport "GLSL.std.450"
63               ...
64               OpName %9 "variableName"
65               OpName %15 "variableNameArray"
66               OpDecorate %18 BuiltIn VertexIndex
67               OpDecorate %19 BuiltIn InstanceIndex
68               OpDecorate %9 Location M
69               OpDecorate %9 Component 2
70               OpDecorate %15 Location N
71               ...
72          %2 = OpTypeVoid
73          %3 = OpTypeFunction %2
74          %6 = OpTypeFloat 32
75          %7 = OpTypeVector %6 2
76          %8 = OpTypePointer Input %7
77          %9 = OpVariable %8 Input
78         %10 = OpTypeVector %6 4
79         %11 = OpTypeInt 32 0
80         %12 = OpConstant %11 L
81         %13 = OpTypeArray %10 %12
82         %14 = OpTypePointer Input %13
83         %15 = OpVariable %14 Input
84               ...
85---------------------------------------------------
86
87
88[[fxvertex-attrib-location]]
89=== Attribute Location and Component Assignment
90
91Vertex shaders allow code:Location and code:Component decorations on input
92variable declarations.
93The code:Location decoration specifies which vertex input attribute is used
94to read and interpret the data that a variable will consume.
95The code:Component decoration allows the location to be more finely
96specified for scalars and vectors, down to the individual components within
97a location that are consumed.
98The components within a location are 0, 1, 2, and 3.
99A variable starting at component N will consume components N, N+1, N+2, ...
100up through its size.
101For single precision types, it is invalid if the sequence of components gets
102larger than 3.
103
104When a vertex shader input variable declared using a 16- or 32-bit scalar or
105vector data type is assigned a location, its value(s) are taken from the
106components of the input attribute specified with the corresponding
107sname:VkVertexInputAttributeDescription::pname:location.
108The components used depend on the type of variable and the code:Component
109decoration specified in the variable declaration, as identified in
110<<fxvertex-attrib-components>>.
111Any 16-bit or 32-bit scalar or vector input will consume a single location.
112For 16-bit and 32-bit data types, missing components are filled in with
113default values as described <<fxvertex-input-extraction,below>>.
114
115
116[[fxvertex-attrib-components]]
117.Input attribute components accessed by 16-bit and 32-bit input variables
118[width="65%",cols="<5,<3,<3",options="header"]
119|====
120| 16-bit or 32-bit data type | code:Component decoration | Components consumed
121| scalar                     | 0 or unspecified             | (x, o, o, o)
122| scalar                     | 1                            | (o, y, o, o)
123| scalar                     | 2                            | (o, o, z, o)
124| scalar                     | 3                            | (o, o, o, w)
125| two-component vector       | 0 or unspecified             | (x, y, o, o)
126| two-component vector       | 1                            | (o, y, z, o)
127| two-component vector       | 2                            | (o, o, z, w)
128| three-component vector     | 0 or unspecified             | (x, y, z, o)
129| three-component vector     | 1                            | (o, y, z, w)
130| four-component vector      | 0 or unspecified             | (x, y, z, w)
131|====
132
133Components indicated by "`o`" are available for use by other input variables
134which are sourced from the same attribute, and if used, are either filled
135with the corresponding component from the input format (if present), or the
136default value.
137
138When a vertex shader input variable declared using a 32-bit floating point
139matrix type is assigned a location _i_, its values are taken from
140consecutive input attributes starting with the corresponding
141sname:VkVertexInputAttributeDescription::pname:location.
142Such matrices are treated as an array of column vectors with values taken
143from the input attributes identified in <<fxvertex-attrib-matrix>>.
144The sname:VkVertexInputAttributeDescription::pname:format must: be specified
145with a elink:VkFormat that corresponds to the appropriate type of column
146vector.
147The code:Component decoration must: not be used with matrix types.
148
149[[fxvertex-attrib-matrix]]
150.Input attributes accessed by 32-bit input matrix variables
151[width="100%",cols="<10%,<24%,<21%,<45%",options="header"]
152|====
153| Data type     | Column vector type        | Locations consumed    | Components consumed
154| mat2          | two-component vector      | i, i+1                | (x, y, o, o), (x, y, o, o)
155| mat2x3        | three-component vector    | i, i+1                | (x, y, z, o), (x, y, z, o)
156| mat2x4        | four-component vector     | i, i+1                | (x, y, z, w), (x, y, z, w)
157| mat3x2        | two-component vector      | i, i+1, i+2           | (x, y, o, o), (x, y, o, o), (x, y, o, o)
158| mat3          | three-component vector    | i, i+1, i+2           | (x, y, z, o), (x, y, z, o), (x, y, z, o)
159| mat3x4        | four-component vector     | i, i+1, i+2           | (x, y, z, w), (x, y, z, w), (x, y, z, w)
160| mat4x2        | two-component vector      | i, i+1, i+2, i+3      | (x, y, o, o), (x, y, o, o), (x, y, o, o), (x, y, o, o)
161| mat4x3        | three-component vector    | i, i+1, i+2, i+3      | (x, y, z, o), (x, y, z, o), (x, y, z, o), (x, y, z, o)
162| mat4          | four-component vector     | i, i+1, i+2, i+3      | (x, y, z, w), (x, y, z, w), (x, y, z, w), (x, y, z, w)
163|====
164
165Components indicated by "`o`" are available for use by other input variables
166which are sourced from the same attribute, and if used, are either filled
167with the corresponding component from the input (if present), or the default
168value.
169
170When a vertex shader input variable declared using a scalar or vector 64-bit
171data type is assigned a location _i_, its values are taken from consecutive
172input attributes starting with the corresponding
173sname:VkVertexInputAttributeDescription::pname:location.
174The locations and components used depend on the type of variable and the
175code:Component decoration specified in the variable declaration, as
176identified in <<fxvertex-attrib-double>>.
177For 64-bit data types, no default attribute values are provided.
178Input variables must: not use more components than provided by the
179attribute.
180Input attributes which have one- or two-component 64-bit formats will
181consume a single location.
182Input attributes which have three- or four-component 64-bit formats will
183consume two consecutive locations.
184A 64-bit scalar data type will consume two components, and a 64-bit
185two-component vector data type will consume all four components available
186within a location.
187A three- or four-component 64-bit data type must: not specify a component.
188A three-component 64-bit data type will consume all four components of the
189first location and components 0 and 1 of the second location.
190This leaves components 2 and 3 available for other component-qualified
191declarations.
192A four-component 64-bit data type will consume all four components of the
193first location and all four components of the second location.
194It is invalid for a scalar or two-component 64-bit data type to specify a
195component of 1 or 3.
196
197[[fxvertex-attrib-double]]
198.Input attribute locations and components accessed by 64-bit input variables
199[width="100%",cols="<18%,^12%,<25%,^14%,^18%,<13%",options="header"]
200|====
201^.^| Input format | Locations consumed
202        ^.^| 64-bit data type   |code:Location decoration |code:Component decoration ^| 32-bit components consumed
203| R64          | i
204        | scalar                  | i                         | 0 or unspecified           | (x, y, -, -)
205.3+<.^| R64G64 .3+^.^| i
206        | scalar                  | i                         | 0 or unspecified           | (x, y, o, o)
207        | scalar                  | i                         | 2                          | (o, o, z, w)
208        | two-component vector    | i                         | 0 or unspecified           | (x, y, z, w)
209.5+<.^| R64G64B64 .5+^.^| i, i+1
210        | scalar                  | i                         | 0 or unspecified           | (x, y, o, o), (o, o, -, -)
211        | scalar                  | i                         | 2                          | (o, o, z, w), (o, o, -, -)
212        | scalar                  | i+1                       | 0 or unspecified           | (o, o, o, o), (x, y, -, -)
213        | two-component vector    | i                         | 0 or unspecified           | (x, y, z, w), (o, o, -, -)
214        | three-component vector  | i                         | unspecified                | (x, y, z, w), (x, y, -, -)
215.8+<.^| R64G64B64A64 .8+^.^| i, i+1
216        | scalar                  | i                         | 0 or unspecified           | (x, y, o, o), (o, o, o, o)
217        | scalar                  | i                         | 2                          | (o, o, z, w), (o, o, o, o)
218        | scalar                  | i+1                       | 0 or unspecified           | (o, o, o, o), (x, y, o, o)
219        | scalar                  | i+1                       | 2                          | (o, o, o, o), (o, o, z, w)
220        | two-component vector    | i                         | 0 or unspecified           | (x, y, z, w), (o, o, o, o)
221        | two-component vector    | i+1                       | 0 or unspecified           | (o, o, o, o), (x, y, z, w)
222        | three-component vector  | i                         | unspecified                | (x, y, z, w), (x, y, o, o)
223        | four-component vector   | i                         | unspecified                | (x, y, z, w), (x, y, z, w)
224|====
225
226Components indicated by "`o`" are available for use by other input variables
227which are sourced from the same attribute.
228Components indicated by "`-`" are not available for input variables as there
229are no default values provided for 64-bit data types, and there is no data
230provided by the input format.
231
232When a vertex shader input variable declared using a 64-bit floating-point
233matrix type is assigned a location _i_, its values are taken from
234consecutive input attribute locations.
235Such matrices are treated as an array of column vectors with values taken
236from the input attributes as shown in <<fxvertex-attrib-double>>.
237Each column vector starts at the location immediately following the last
238location of the previous column vector.
239The number of attributes and components assigned to each matrix is
240determined by the matrix dimensions and ranges from two to eight locations.
241
242When a vertex shader input variable declared using an array type is assigned
243a location, its values are taken from consecutive input attributes starting
244with the corresponding
245sname:VkVertexInputAttributeDescription::pname:location.
246The number of attributes and components assigned to each element are
247determined according to the data type of the array elements and
248code:Component decoration (if any) specified in the declaration of the
249array, as described above.
250Each element of the array, in order, is assigned to consecutive locations,
251but all at the same specified component within each location.
252
253Only input variables declared with the data types and component decorations
254as specified above are supported.
255_Location aliasing_ is causing two variables to have the same location
256number.
257_Component aliasing_ is assigning the same (or overlapping) component number
258for two location aliases.
259Location aliasing is allowed only if it does not cause component aliasing.
260Further, when location aliasing, the aliases sharing the location must: all
261have the same SPIR-V floating-point component type or all have the same
262width integer-type components.
263
264
265[[fxvertex-input]]
266== Vertex Input Description
267
268Applications specify vertex input attribute and vertex input binding
269descriptions as part of graphics pipeline creation by setting the
270slink:VkGraphicsPipelineCreateInfo::pname:pVertexInputState pointer to a
271slink:VkPipelineVertexInputStateCreateInfo structure.
272ifdef::VK_EXT_vertex_input_dynamic_state[]
273Alternatively, if the graphics pipeline is created with the
274ename:VK_DYNAMIC_STATE_VERTEX_INPUT_EXT dynamic state enabled, then the
275vertex input attribute and vertex input binding descriptions are specified
276dynamically with flink:vkCmdSetVertexInputEXT, and the
277slink:VkGraphicsPipelineCreateInfo::pname:pVertexInputState pointer is
278ignored.
279endif::VK_EXT_vertex_input_dynamic_state[]
280
281[open,refpage='VkPipelineVertexInputStateCreateInfo',desc='Structure specifying parameters of a newly created pipeline vertex input state',type='structs']
282--
283The sname:VkPipelineVertexInputStateCreateInfo structure is defined as:
284
285include::{generated}/api/structs/VkPipelineVertexInputStateCreateInfo.txt[]
286
287  * pname:sType is the type of this structure.
288  * pname:pNext is `NULL` or a pointer to a structure extending this
289    structure.
290  * pname:flags is reserved for future use.
291  * pname:vertexBindingDescriptionCount is the number of vertex binding
292    descriptions provided in pname:pVertexBindingDescriptions.
293  * pname:pVertexBindingDescriptions is a pointer to an array of
294    sname:VkVertexInputBindingDescription structures.
295  * pname:vertexAttributeDescriptionCount is the number of vertex attribute
296    descriptions provided in pname:pVertexAttributeDescriptions.
297  * pname:pVertexAttributeDescriptions is a pointer to an array of
298    sname:VkVertexInputAttributeDescription structures.
299
300.Valid Usage
301****
302  * [[VUID-VkPipelineVertexInputStateCreateInfo-vertexBindingDescriptionCount-00613]]
303    pname:vertexBindingDescriptionCount must: be less than or equal to
304    sname:VkPhysicalDeviceLimits::pname:maxVertexInputBindings
305  * [[VUID-VkPipelineVertexInputStateCreateInfo-vertexAttributeDescriptionCount-00614]]
306    pname:vertexAttributeDescriptionCount must: be less than or equal to
307    sname:VkPhysicalDeviceLimits::pname:maxVertexInputAttributes
308  * [[VUID-VkPipelineVertexInputStateCreateInfo-binding-00615]]
309    For every pname:binding specified by each element of
310    pname:pVertexAttributeDescriptions, a
311    sname:VkVertexInputBindingDescription must: exist in
312    pname:pVertexBindingDescriptions with the same value of pname:binding
313  * [[VUID-VkPipelineVertexInputStateCreateInfo-pVertexBindingDescriptions-00616]]
314    All elements of pname:pVertexBindingDescriptions must: describe distinct
315    binding numbers
316  * [[VUID-VkPipelineVertexInputStateCreateInfo-pVertexAttributeDescriptions-00617]]
317    All elements of pname:pVertexAttributeDescriptions must: describe
318    distinct attribute locations
319****
320
321include::{generated}/validity/structs/VkPipelineVertexInputStateCreateInfo.txt[]
322--
323
324[open,refpage='VkPipelineVertexInputStateCreateFlags',desc='Reserved for future use',type='flags']
325--
326include::{generated}/api/flags/VkPipelineVertexInputStateCreateFlags.txt[]
327
328tname:VkPipelineVertexInputStateCreateFlags is a bitmask type for setting a
329mask, but is currently reserved for future use.
330--
331
332[open,refpage='VkVertexInputBindingDescription',desc='Structure specifying vertex input binding description',type='structs']
333--
334Each vertex input binding is specified by the
335sname:VkVertexInputBindingDescription structure, defined as:
336
337include::{generated}/api/structs/VkVertexInputBindingDescription.txt[]
338
339  * pname:binding is the binding number that this structure describes.
340  * pname:stride is the byte stride between consecutive elements within the
341    buffer.
342  * pname:inputRate is a elink:VkVertexInputRate value specifying whether
343    vertex attribute addressing is a function of the vertex index or of the
344    instance index.
345
346.Valid Usage
347****
348  * [[VUID-VkVertexInputBindingDescription-binding-00618]]
349    pname:binding must: be less than
350    sname:VkPhysicalDeviceLimits::pname:maxVertexInputBindings
351  * [[VUID-VkVertexInputBindingDescription-stride-00619]]
352    pname:stride must: be less than or equal to
353    sname:VkPhysicalDeviceLimits::pname:maxVertexInputBindingStride
354ifdef::VK_KHR_portability_subset[]
355  * [[VUID-VkVertexInputBindingDescription-stride-04456]]
356    If the `apiext:VK_KHR_portability_subset` extension is enabled,
357    pname:stride must: be a multiple of, and at least as large as,
358    slink:VkPhysicalDevicePortabilitySubsetPropertiesKHR::pname:minVertexInputBindingStrideAlignment
359endif::VK_KHR_portability_subset[]
360****
361
362include::{generated}/validity/structs/VkVertexInputBindingDescription.txt[]
363--
364
365[open,refpage='VkVertexInputRate',desc='Specify rate at which vertex attributes are pulled from buffers',type='enums']
366--
367Possible values of slink:VkVertexInputBindingDescription::pname:inputRate,
368specifying the rate at which vertex attributes are pulled from buffers, are:
369
370include::{generated}/api/enums/VkVertexInputRate.txt[]
371
372  * ename:VK_VERTEX_INPUT_RATE_VERTEX specifies that vertex attribute
373    addressing is a function of the vertex index.
374  * ename:VK_VERTEX_INPUT_RATE_INSTANCE specifies that vertex attribute
375    addressing is a function of the instance index.
376--
377
378[open,refpage='VkVertexInputAttributeDescription',desc='Structure specifying vertex input attribute description',type='structs']
379--
380Each vertex input attribute is specified by the
381sname:VkVertexInputAttributeDescription structure, defined as:
382
383include::{generated}/api/structs/VkVertexInputAttributeDescription.txt[]
384
385  * pname:location is the shader input location number for this attribute.
386  * pname:binding is the binding number which this attribute takes its data
387    from.
388  * pname:format is the size and type of the vertex attribute data.
389  * pname:offset is a byte offset of this attribute relative to the start of
390    an element in the vertex input binding.
391
392.Valid Usage
393****
394  * [[VUID-VkVertexInputAttributeDescription-location-00620]]
395    pname:location must: be less than
396    sname:VkPhysicalDeviceLimits::pname:maxVertexInputAttributes
397  * [[VUID-VkVertexInputAttributeDescription-binding-00621]]
398    pname:binding must: be less than
399    sname:VkPhysicalDeviceLimits::pname:maxVertexInputBindings
400  * [[VUID-VkVertexInputAttributeDescription-offset-00622]]
401    pname:offset must: be less than or equal to
402    sname:VkPhysicalDeviceLimits::pname:maxVertexInputAttributeOffset
403  * [[VUID-VkVertexInputAttributeDescription-format-00623]]
404    pname:format must: be allowed as a vertex buffer format, as specified by
405    the ename:VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT flag in
406    sname:VkFormatProperties::pname:bufferFeatures returned by
407    fname:vkGetPhysicalDeviceFormatProperties
408ifdef::VK_KHR_portability_subset[]
409  * [[VUID-VkVertexInputAttributeDescription-vertexAttributeAccessBeyondStride-04457]]
410    If the `apiext:VK_KHR_portability_subset` extension is enabled, and
411    slink:VkPhysicalDevicePortabilitySubsetFeaturesKHR::pname:vertexAttributeAccessBeyondStride
412    is ename:VK_FALSE, the sum of pname:offset plus the size of the vertex
413    attribute data described by pname:format must: not be greater than
414    pname:stride in the slink:VkVertexInputBindingDescription referenced in
415    pname:binding
416endif::VK_KHR_portability_subset[]
417****
418
419include::{generated}/validity/structs/VkVertexInputAttributeDescription.txt[]
420--
421
422ifdef::VK_EXT_vertex_input_dynamic_state[]
423[open,refpage='vkCmdSetVertexInputEXT',desc='Set the vertex input state dynamically for a command buffer',type='protos']
424--
425To <<pipelines-dynamic-state, dynamically set>> the vertex input attribute
426and vertex input binding descriptions, call:
427
428include::{generated}/api/protos/vkCmdSetVertexInputEXT.txt[]
429
430  * pname:commandBuffer is the command buffer into which the command will be
431    recorded.
432  * pname:vertexBindingDescriptionCount is the number of vertex binding
433    descriptions provided in pname:pVertexBindingDescriptions.
434  * pname:pVertexBindingDescriptions is a pointer to an array of
435    sname:VkVertexInputBindingDescription2EXT structures.
436  * pname:vertexAttributeDescriptionCount is the number of vertex attribute
437    descriptions provided in pname:pVertexAttributeDescriptions.
438  * pname:pVertexAttributeDescriptions is a pointer to an array of
439    sname:VkVertexInputAttributeDescription2EXT structures.
440
441This command sets the vertex input attribute and vertex input binding
442descriptions state for subsequent drawing commands when the graphics
443pipeline is created with ename:VK_DYNAMIC_STATE_VERTEX_INPUT_EXT set in
444slink:VkPipelineDynamicStateCreateInfo::pname:pDynamicStates.
445Otherwise, this state is specified by the
446slink:VkGraphicsPipelineCreateInfo::pname:pVertexInputState values used to
447create the currently active pipeline.
448
449ifdef::VK_EXT_extended_dynamic_state[]
450If the bound pipeline state object was also created with the
451ename:VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT dynamic state
452enabled, then flink:vkCmdBindVertexBuffers2EXT can be used instead of
453fname:vkCmdSetVertexInputEXT to dynamically set the stride.
454endif::VK_EXT_extended_dynamic_state[]
455
456.Valid Usage
457****
458  * [[VUID-vkCmdSetVertexInputEXT-None-04790]]
459    The <<features-vertexInputDynamicState, vertexInputDynamicState>>
460    feature must: be enabled
461  * [[VUID-vkCmdSetVertexInputEXT-vertexBindingDescriptionCount-04791]]
462    pname:vertexBindingDescriptionCount must: be less than or equal to
463    sname:VkPhysicalDeviceLimits::pname:maxVertexInputBindings
464  * [[VUID-vkCmdSetVertexInputEXT-vertexAttributeDescriptionCount-04792]]
465    pname:vertexAttributeDescriptionCount must: be less than or equal to
466    sname:VkPhysicalDeviceLimits::pname:maxVertexInputAttributes
467  * [[VUID-vkCmdSetVertexInputEXT-binding-04793]]
468    For every pname:binding specified by each element of
469    pname:pVertexAttributeDescriptions, a
470    sname:VkVertexInputBindingDescription2EXT must: exist in
471    pname:pVertexBindingDescriptions with the same value of pname:binding
472  * [[VUID-vkCmdSetVertexInputEXT-pVertexBindingDescriptions-04794]]
473    All elements of pname:pVertexBindingDescriptions must: describe distinct
474    binding numbers
475  * [[VUID-vkCmdSetVertexInputEXT-pVertexAttributeDescriptions-04795]]
476    All elements of pname:pVertexAttributeDescriptions must: describe
477    distinct attribute locations
478****
479
480include::{generated}/validity/protos/vkCmdSetVertexInputEXT.txt[]
481--
482
483[open,refpage='VkVertexInputBindingDescription2EXT',desc='Structure specifying the extended vertex input binding description',type='structs']
484--
485The sname:VkVertexInputBindingDescription2EXT structure is defined as:
486
487include::{generated}/api/structs/VkVertexInputBindingDescription2EXT.txt[]
488
489  * pname:sType is the type of this structure.
490  * pname:pNext is `NULL` or a pointer to a structure extending this
491    structure.
492  * pname:binding is the binding number that this structure describes.
493  * pname:stride is the byte stride between consecutive elements within the
494    buffer.
495  * pname:inputRate is a elink:VkVertexInputRate value specifying whether
496    vertex attribute addressing is a function of the vertex index or of the
497    instance index.
498ifdef::VK_EXT_vertex_attribute_divisor[]
499  * pname:divisor is the number of successive instances that will use the
500    same value of the vertex attribute when instanced rendering is enabled.
501    This member can: be set to a value other than `1` if the
502    <<features-vertexAttributeInstanceRateDivisor,
503    vertexAttributeInstanceRateDivisor>> feature is enabled.
504    For example, if the divisor is N, the same vertex attribute will be
505    applied to N successive instances before moving on to the next vertex
506    attribute.
507    The maximum value of pname:divisor is implementation-dependent and can
508    be queried using
509    sname:VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT::pname:maxVertexAttribDivisor.
510    A value of `0` can: be used for the divisor if the
511    <<features-vertexAttributeInstanceRateZeroDivisor,pname:vertexAttributeInstanceRateZeroDivisor>>
512    feature is enabled.
513    In this case, the same vertex attribute will be applied to all
514    instances.
515endif::VK_EXT_vertex_attribute_divisor[]
516ifndef::VK_EXT_vertex_attribute_divisor[]
517  * pname:divisor must: be set to `1`
518endif::VK_EXT_vertex_attribute_divisor[]
519
520.Valid Usage
521****
522  * [[VUID-VkVertexInputBindingDescription2EXT-binding-04796]]
523    pname:binding must: be less than
524    sname:VkPhysicalDeviceLimits::pname:maxVertexInputBindings
525  * [[VUID-VkVertexInputBindingDescription2EXT-stride-04797]]
526    pname:stride must: be less than or equal to
527    sname:VkPhysicalDeviceLimits::pname:maxVertexInputBindingStride
528  * [[VUID-VkVertexInputBindingDescription2EXT-divisor-04798]]
529    If the <<features-vertexAttributeInstanceRateZeroDivisor,
530    vertexAttributeInstanceRateZeroDivisor>> feature is not enabled,
531    pname:divisor must: not be `0`
532  * [[VUID-VkVertexInputBindingDescription2EXT-divisor-04799]]
533    If the <<features-vertexAttributeInstanceRateDivisor,
534    vertexAttributeInstanceRateDivisor>> feature is not enabled,
535    pname:divisor must: be `1`
536  * [[VUID-VkVertexInputBindingDescription2EXT-divisor-06226]]
537    pname:divisor must: be a value between `0` and
538    sname:VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT::pname:maxVertexAttribDivisor,
539    inclusive
540  * [[VUID-VkVertexInputBindingDescription2EXT-divisor-06227]]
541    If pname:divisor is not `1` then pname:inputRate must: be of type
542    ename:VK_VERTEX_INPUT_RATE_INSTANCE
543****
544
545include::{generated}/validity/structs/VkVertexInputBindingDescription2EXT.txt[]
546--
547
548[open,refpage='VkVertexInputAttributeDescription2EXT',desc='Structure specifying the extended vertex input attribute description',type='structs']
549--
550The sname:VkVertexInputAttributeDescription2EXT structure is defined as:
551
552include::{generated}/api/structs/VkVertexInputAttributeDescription2EXT.txt[]
553
554  * pname:sType is the type of this structure.
555  * pname:pNext is `NULL` or a pointer to a structure extending this
556    structure.
557  * pname:location is the shader input location number for this attribute.
558  * pname:binding is the binding number which this attribute takes its data
559    from.
560  * pname:format is the size and type of the vertex attribute data.
561  * pname:offset is a byte offset of this attribute relative to the start of
562    an element in the vertex input binding.
563
564.Valid Usage
565****
566  * [[VUID-VkVertexInputAttributeDescription2EXT-location-06228]]
567    pname:location must: be less than
568    sname:VkPhysicalDeviceLimits::pname:maxVertexInputAttributes
569  * [[VUID-VkVertexInputAttributeDescription2EXT-binding-06229]]
570    pname:binding must: be less than
571    sname:VkPhysicalDeviceLimits::pname:maxVertexInputBindings
572  * [[VUID-VkVertexInputAttributeDescription2EXT-offset-06230]]
573    pname:offset must: be less than or equal to
574    sname:VkPhysicalDeviceLimits::pname:maxVertexInputAttributeOffset
575  * [[VUID-VkVertexInputAttributeDescription2EXT-format-04805]]
576    pname:format must: be allowed as a vertex buffer format, as specified by
577    the ename:VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT flag in
578    sname:VkFormatProperties::pname:bufferFeatures returned by
579    fname:vkGetPhysicalDeviceFormatProperties
580ifdef::VK_KHR_portability_subset[]
581  * [[VUID-VkVertexInputAttributeDescription2EXT-vertexAttributeAccessBeyondStride-04806]]
582    If the `apiext:VK_KHR_portability_subset` extension is enabled, and
583    slink:VkPhysicalDevicePortabilitySubsetFeaturesKHR::pname:vertexAttributeAccessBeyondStride
584    is ename:VK_FALSE, the sum of pname:offset plus the size of the vertex
585    attribute data described by pname:format must: not be greater than
586    pname:stride in the slink:VkVertexInputBindingDescription2EXT referenced
587    in pname:binding
588endif::VK_KHR_portability_subset[]
589****
590
591include::{generated}/validity/structs/VkVertexInputAttributeDescription2EXT.txt[]
592--
593endif::VK_EXT_vertex_input_dynamic_state[]
594
595[open,refpage='vkCmdBindVertexBuffers',desc='Bind vertex buffers to a command buffer',type='protos']
596--
597To bind vertex buffers to a command buffer for use in subsequent drawing
598commands, call:
599
600include::{generated}/api/protos/vkCmdBindVertexBuffers.txt[]
601
602  * pname:commandBuffer is the command buffer into which the command is
603    recorded.
604  * pname:firstBinding is the index of the first vertex input binding whose
605    state is updated by the command.
606  * pname:bindingCount is the number of vertex input bindings whose state is
607    updated by the command.
608  * pname:pBuffers is a pointer to an array of buffer handles.
609  * pname:pOffsets is a pointer to an array of buffer offsets.
610
611The values taken from elements [eq]#i# of pname:pBuffers and pname:pOffsets
612replace the current state for the vertex input binding
613[eq]#pname:firstBinding {plus} i#, for [eq]#i# in [eq]#[0,
614pname:bindingCount)#.
615The vertex input binding is updated to start at the offset indicated by
616pname:pOffsets[i] from the start of the buffer pname:pBuffers[i].
617All vertex input attributes that use each of these bindings will use these
618updated addresses in their address calculations for subsequent drawing
619commands.
620ifdef::VK_EXT_robustness2[]
621If the <<features-nullDescriptor,nullDescriptor>> feature is enabled,
622elements of pname:pBuffers can: be dlink:VK_NULL_HANDLE, and can: be used by
623the vertex shader.
624If a vertex input attribute is bound to a vertex input binding that is
625dlink:VK_NULL_HANDLE, the values taken from memory are considered to be
626zero, and missing G, B, or A components are
627<<fxvertex-input-extraction,filled with [eq]#(0,0,1)#>>.
628endif::VK_EXT_robustness2[]
629
630.Valid Usage
631****
632  * [[VUID-vkCmdBindVertexBuffers-firstBinding-00624]]
633    pname:firstBinding must: be less than
634    sname:VkPhysicalDeviceLimits::pname:maxVertexInputBindings
635  * [[VUID-vkCmdBindVertexBuffers-firstBinding-00625]]
636    The sum of pname:firstBinding and pname:bindingCount must: be less than
637    or equal to sname:VkPhysicalDeviceLimits::pname:maxVertexInputBindings
638  * [[VUID-vkCmdBindVertexBuffers-pOffsets-00626]]
639    All elements of pname:pOffsets must: be less than the size of the
640    corresponding element in pname:pBuffers
641  * [[VUID-vkCmdBindVertexBuffers-pBuffers-00627]]
642    All elements of pname:pBuffers must: have been created with the
643    ename:VK_BUFFER_USAGE_VERTEX_BUFFER_BIT flag
644  * [[VUID-vkCmdBindVertexBuffers-pBuffers-00628]]
645    Each element of pname:pBuffers that is non-sparse must: be bound
646    completely and contiguously to a single sname:VkDeviceMemory object
647  * [[VUID-vkCmdBindVertexBuffers-pBuffers-04001]]
648    If the <<features-nullDescriptor,nullDescriptor>> feature is not
649    enabled, all elements of pname:pBuffers must: not be
650    dlink:VK_NULL_HANDLE
651ifdef::VK_EXT_robustness2[]
652  * [[VUID-vkCmdBindVertexBuffers-pBuffers-04002]]
653    If an element of pname:pBuffers is dlink:VK_NULL_HANDLE, then the
654    corresponding element of pname:pOffsets must: be zero
655endif::VK_EXT_robustness2[]
656****
657
658include::{generated}/validity/protos/vkCmdBindVertexBuffers.txt[]
659--
660
661ifdef::VK_EXT_extended_dynamic_state[]
662[open,refpage='vkCmdBindVertexBuffers2EXT',desc='Bind vertex buffers to a command buffer and dynamically set strides',type='protos']
663--
664Alternatively, to bind vertex buffers, along with their sizes and strides,
665to a command buffer for use in subsequent drawing commands, call:
666
667include::{generated}/api/protos/vkCmdBindVertexBuffers2EXT.txt[]
668
669  * pname:commandBuffer is the command buffer into which the command is
670    recorded.
671  * pname:firstBinding is the index of the first vertex input binding whose
672    state is updated by the command.
673  * pname:bindingCount is the number of vertex input bindings whose state is
674    updated by the command.
675  * pname:pBuffers is a pointer to an array of buffer handles.
676  * pname:pOffsets is a pointer to an array of buffer offsets.
677  * pname:pSizes is `NULL` or a pointer to an array of the size in bytes of
678    vertex data bound from pname:pBuffers.
679  * pname:pStrides is `NULL` or a pointer to an array of buffer strides.
680
681The values taken from elements [eq]#i# of pname:pBuffers and pname:pOffsets
682replace the current state for the vertex input binding
683[eq]#pname:firstBinding {plus} i#, for [eq]#i# in [eq]#[0,
684pname:bindingCount)#.
685The vertex input binding is updated to start at the offset indicated by
686pname:pOffsets[i] from the start of the buffer pname:pBuffers[i].
687If pname:pSizes is not `NULL` then pname:pSizes[i] specifies the bound size
688of the vertex buffer starting from the corresponding elements of
689pname:pBuffers[i] plus pname:pOffsets[i].
690All vertex input attributes that use each of these bindings will use these
691updated addresses in their address calculations for subsequent drawing
692commands.
693ifdef::VK_EXT_robustness2[]
694If the <<features-nullDescriptor,nullDescriptor>> feature is enabled,
695elements of pname:pBuffers can: be dlink:VK_NULL_HANDLE, and can: be used by
696the vertex shader.
697If a vertex input attribute is bound to a vertex input binding that is
698dlink:VK_NULL_HANDLE, the values taken from memory are considered to be
699zero, and missing G, B, or A components are
700<<fxvertex-input-extraction,filled with [eq]#(0,0,1)#>>.
701endif::VK_EXT_robustness2[]
702
703This command also <pipelines-dynamic-state, dynamically sets>> the byte
704strides between consecutive elements within buffer pname:pBuffers[i] to the
705corresponding pname:pStrides[i] value when the graphics pipeline is created
706with ename:VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT set in
707slink:VkPipelineDynamicStateCreateInfo::pname:pDynamicStates.
708Otherwise, strides are specified by the
709sname:VkVertexInputBindingDescription::pname:stride values used to create
710the currently active pipeline.
711
712ifdef::VK_EXT_vertex_input_dynamic_state[]
713If the bound pipeline state object was also created with the
714ename:VK_DYNAMIC_STATE_VERTEX_INPUT_EXT dynamic state enabled then
715flink:vkCmdSetVertexInputEXT can: be used instead of
716fname:vkCmdBindVertexBuffers2EXT to set the stride.
717endif::VK_EXT_vertex_input_dynamic_state[]
718
719.Valid Usage
720****
721  * [[VUID-vkCmdBindVertexBuffers2EXT-firstBinding-03355]]
722    pname:firstBinding must: be less than
723    sname:VkPhysicalDeviceLimits::pname:maxVertexInputBindings
724  * [[VUID-vkCmdBindVertexBuffers2EXT-firstBinding-03356]]
725    The sum of pname:firstBinding and pname:bindingCount must: be less than
726    or equal to sname:VkPhysicalDeviceLimits::pname:maxVertexInputBindings
727  * [[VUID-vkCmdBindVertexBuffers2EXT-pOffsets-03357]]
728    All elements of pname:pOffsets must: be less than the size of the
729    corresponding element in pname:pBuffers
730  * [[VUID-vkCmdBindVertexBuffers2EXT-pSizes-03358]]
731    If pname:pSizes is not `NULL`, all elements of pname:pOffsets plus
732    pname:pSizes must: be less than or equal to the size of the
733    corresponding element in pname:pBuffers
734  * [[VUID-vkCmdBindVertexBuffers2EXT-pBuffers-03359]]
735    All elements of pname:pBuffers must: have been created with the
736    ename:VK_BUFFER_USAGE_VERTEX_BUFFER_BIT flag
737  * [[VUID-vkCmdBindVertexBuffers2EXT-pBuffers-03360]]
738    Each element of pname:pBuffers that is non-sparse must: be bound
739    completely and contiguously to a single sname:VkDeviceMemory object
740  * [[VUID-vkCmdBindVertexBuffers2EXT-pBuffers-04111]]
741    If the <<features-nullDescriptor,nullDescriptor>> feature is not
742    enabled, all elements of pname:pBuffers must: not be
743    dlink:VK_NULL_HANDLE
744ifdef::VK_EXT_robustness2[]
745  * [[VUID-vkCmdBindVertexBuffers2EXT-pBuffers-04112]]
746    If an element of pname:pBuffers is dlink:VK_NULL_HANDLE, then the
747    corresponding element of pname:pOffsets must: be zero
748endif::VK_EXT_robustness2[]
749  * [[VUID-vkCmdBindVertexBuffers2EXT-pStrides-03362]]
750    If pname:pStrides is not `NULL` each element of pname:pStrides must: be
751    less than or equal to
752    sname:VkPhysicalDeviceLimits::pname:maxVertexInputBindingStride
753  * [[VUID-vkCmdBindVertexBuffers2EXT-pStrides-06209]]
754    If pname:pStrides is not `NULL` each element of pname:pStrides must: be
755    either 0 or greater than or equal to the maximum extent of all vertex
756    input attributes fetched from the corresponding binding, where the
757    extent is calculated as the
758    slink:VkVertexInputAttributeDescription::pname:offset plus
759    slink:VkVertexInputAttributeDescription::pname:format size
760****
761
762include::{generated}/validity/protos/vkCmdBindVertexBuffers2EXT.txt[]
763--
764endif::VK_EXT_extended_dynamic_state[]
765
766
767ifdef::VK_EXT_vertex_attribute_divisor[]
768
769[[fxvertex-attribute_divisor]]
770== Vertex Attribute Divisor in Instanced Rendering
771
772[open,refpage='VkPipelineVertexInputDivisorStateCreateInfoEXT',desc='Structure specifying vertex attributes assignment during instanced rendering',type='structs']
773--
774If
775<<features-vertexAttributeInstanceRateDivisor,pname:vertexAttributeInstanceRateDivisor>>
776feature is enabled and the pname:pNext chain of
777slink:VkPipelineVertexInputStateCreateInfo includes a
778sname:VkPipelineVertexInputDivisorStateCreateInfoEXT structure, then that
779structure controls how vertex attributes are assigned to an instance when
780instanced rendering is enabled.
781
782The sname:VkPipelineVertexInputDivisorStateCreateInfoEXT structure is
783defined as:
784
785include::{generated}/api/structs/VkPipelineVertexInputDivisorStateCreateInfoEXT.txt[]
786
787  * pname:sType is the type of this structure.
788  * pname:pNext is `NULL` or a pointer to a structure extending this
789    structure.
790  * pname:vertexBindingDivisorCount is the number of elements in the
791    pname:pVertexBindingDivisors array.
792  * pname:pVertexBindingDivisors is a pointer to an array of
793    sname:VkVertexInputBindingDivisorDescriptionEXT structures specifying
794    the divisor value for each binding.
795
796include::{generated}/validity/structs/VkPipelineVertexInputDivisorStateCreateInfoEXT.txt[]
797--
798
799[open,refpage='VkVertexInputBindingDivisorDescriptionEXT',desc='Structure specifying a divisor used in instanced rendering',type='structs']
800--
801The individual divisor values per binding are specified using the
802sname:VkVertexInputBindingDivisorDescriptionEXT structure which is defined
803as:
804
805include::{generated}/api/structs/VkVertexInputBindingDivisorDescriptionEXT.txt[]
806
807  * pname:binding is the binding number for which the divisor is specified.
808  * pname:divisor is the number of successive instances that will use the
809    same value of the vertex attribute when instanced rendering is enabled.
810    For example, if the divisor is N, the same vertex attribute will be
811    applied to N successive instances before moving on to the next vertex
812    attribute.
813    The maximum value of pname:divisor is implementation-dependent and can
814    be queried using
815    sname:VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT::pname:maxVertexAttribDivisor.
816    A value of `0` can: be used for the divisor if the
817    <<features-vertexAttributeInstanceRateZeroDivisor,pname:vertexAttributeInstanceRateZeroDivisor>>
818    feature is enabled.
819    In this case, the same vertex attribute will be applied to all
820    instances.
821
822If this structure is not used to define a divisor value for an attribute,
823then the divisor has a logical default value of 1.
824
825.Valid Usage
826****
827  * [[VUID-VkVertexInputBindingDivisorDescriptionEXT-binding-01869]]
828    pname:binding must: be less than
829    sname:VkPhysicalDeviceLimits::pname:maxVertexInputBindings
830  * [[VUID-VkVertexInputBindingDivisorDescriptionEXT-vertexAttributeInstanceRateZeroDivisor-02228]]
831    If the pname:vertexAttributeInstanceRateZeroDivisor feature is not
832    enabled, pname:divisor must: not be `0`
833  * [[VUID-VkVertexInputBindingDivisorDescriptionEXT-vertexAttributeInstanceRateDivisor-02229]]
834    If the pname:vertexAttributeInstanceRateDivisor feature is not enabled,
835    pname:divisor must: be `1`
836  * [[VUID-VkVertexInputBindingDivisorDescriptionEXT-divisor-01870]]
837    pname:divisor must: be a value between `0` and
838    sname:VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT::pname:maxVertexAttribDivisor,
839    inclusive
840  * [[VUID-VkVertexInputBindingDivisorDescriptionEXT-inputRate-01871]]
841    slink:VkVertexInputBindingDescription::pname:inputRate must: be of type
842    ename:VK_VERTEX_INPUT_RATE_INSTANCE for this pname:binding
843****
844
845include::{generated}/validity/structs/VkVertexInputBindingDivisorDescriptionEXT.txt[]
846--
847
848endif::VK_EXT_vertex_attribute_divisor[]
849
850[[fxvertex-input-address-calculation]]
851== Vertex Input Address Calculation
852The address of each attribute for each code:vertexIndex and
853code:instanceIndex is calculated as follows:
854
855  * Let code:attribDesc be the member of
856    slink:VkPipelineVertexInputStateCreateInfo::pname:pVertexAttributeDescriptions
857    with sname:VkVertexInputAttributeDescription::pname:location equal to
858    the vertex input attribute number.
859  * Let code:bindingDesc be the member of
860    slink:VkPipelineVertexInputStateCreateInfo::pname:pVertexBindingDescriptions
861    with sname:VkVertexInputAttributeDescription::pname:binding equal to
862    code:attribDesc.binding.
863  * Let code:vertexIndex be the index of the vertex within the draw (a value
864    between pname:firstVertex and pname:firstVertex+pname:vertexCount for
865    fname:vkCmdDraw, or a value taken from the index buffer for
866    fname:vkCmdDrawIndexed), and let code:instanceIndex be the instance
867    number of the draw (a value between pname:firstInstance and
868    pname:firstInstance+pname:instanceCount).
869ifdef::VK_EXT_vertex_attribute_divisor[]
870  * Let code:divisor be the member of
871    slink:VkPipelineVertexInputDivisorStateCreateInfoEXT::pname:pVertexBindingDivisors
872    with sname:VkVertexInputBindingDivisorDescriptionEXT::pname:binding
873    equal to code:attribDesc.binding.
874endif::VK_EXT_vertex_attribute_divisor[]
875
876[source,c]
877---------------------------------------------------
878bufferBindingAddress = buffer[binding].baseAddress + offset[binding];
879
880if (bindingDesc.inputRate == VK_VERTEX_INPUT_RATE_VERTEX)
881    vertexOffset = vertexIndex * bindingDesc.stride;
882else
883ifndef::VK_EXT_vertex_attribute_divisor[]
884    vertexOffset = instanceIndex * bindingDesc.stride;
885endif::VK_EXT_vertex_attribute_divisor[]
886ifdef::VK_EXT_vertex_attribute_divisor[]
887    if (divisor == 0)
888        vertexOffset = firstInstance * bindingDesc.stride;
889    else
890        vertexOffset = (firstInstance + ((instanceIndex - firstInstance) / divisor)) * bindingDesc.stride;
891endif::VK_EXT_vertex_attribute_divisor[]
892
893attribAddress = bufferBindingAddress + vertexOffset + attribDesc.offset;
894---------------------------------------------------
895
896[[fxvertex-input-extraction]]
897=== Vertex Input Extraction
898For each attribute, raw data is extracted starting at `attribAddress` and is
899converted from the sname:VkVertexInputAttributeDescription's pname:format to
900either floating-point, unsigned integer, or signed integer based on the base
901type of the format; the base type of the format must: match the base type of
902the input variable in the shader.
903The input variable in the shader must: be declared as a 64-bit data type if
904and only if pname:format is a 64-bit data type.
905If pname:format is a packed format, `attribAddress` must: be a multiple of
906the size in bytes of the whole attribute data type as described in
907<<formats-packed,Packed Formats>>.
908Otherwise, `attribAddress` must: be a multiple of the size in bytes of the
909component type indicated by pname:format (see <<formats,Formats>>).
910For attributes that are not 64-bit data types, each component is converted
911to the format of the input variable based on its type and size (as defined
912in the <<formats-definition,Format Definition>> section for each
913elink:VkFormat), using the appropriate equations in <<fundamentals-fp16,
91416-Bit Floating-Point Numbers>>, <<fundamentals-fp11,Unsigned 11-Bit
915Floating-Point Numbers>>, <<fundamentals-fp10,Unsigned 10-Bit Floating-Point
916Numbers>>, <<fundamentals-fixedconv,Fixed-Point Data Conversion>>, and
917<<textures-sexp-RGB,Shared Exponent to RGB>>.
918Signed integer components smaller than 32 bits are sign-extended.
919Attributes that are not 64-bit data types are expanded to four components in
920the same way as described in <<textures-conversion-to-rgba,conversion to
921RGBA>>.
922The number of components in the vertex shader input variable need not
923exactly match the number of components in the format.
924If the vertex shader has fewer components, the extra components are
925discarded.
926