-
Notifications
You must be signed in to change notification settings - Fork 345
Closed
Labels
wgslWebGPU Shading Language IssuesWebGPU Shading Language Issues
Description
Spawned from this bug report. The availability of builtins to gets the index of the current instance and vertex in the vertex shader vary between APIs.
D3D12
SV_InstanceID: starts from 0, irrespective of thefirstInstanceinDraw/DrawIndexedSV_VertexID: starts from 0, irrespective of thefirstVertexinDrawandbaseVertexinDrawIndexed
@RafaelCintron the docs aren't super clear, can you check for SV_VertexID? (edit: confirmed that it starts from 0)
Metal (section "5.2.3.1 Vertex Function Input Attributes" of the MSL 2.3 "spec")
[[base_instance]]: thefirstInstanceinDrawIndexedandDraw[[base_vertex]]: thefirstVertexinDrawandbaseVertexinDrawIndexed[[instance_id]]: starts from[[base_instance]][[vertex_id]]: starts from[[base_vertex]]
Vulkan
BaseInstance: thefirstInstanceinDrawIndexedandDraw, requires theVK_KHR_shader_draw_parametersextension / featureBaseVertex: thefirstVertexinDrawandbaseVertexinDrawIndexed, requires theVK_KHR_shader_draw_parametersextension / featureInstanceIndex: starts from[[base_instance]]VertexIndex: starts from[[base_vertex]]
OpenGL
gl_VertexID: starts frombaseVertex/firstVertex.gl_InstanceID: starts from 0.gl_BaseVertex/gl_BaseInstance: requireGL_ARB_shader_draw_parametersor OpenGL 4.6
Conclusion
It's a mess and we're heavily limited by what D3D12 does, so we don't really have a choice. We should name builtins clearly to indicate if they start at 0 or not, to avoid the gl_InstanceID vs. gl_InstanceIndex confusion.
kvark, chirsz-ever and firesgc
Metadata
Metadata
Assignees
Labels
wgslWebGPU Shading Language IssuesWebGPU Shading Language Issues