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