You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Are values in GPUVertexAttribute.shaderLocation arbitrary? #1418
When creating a render pipelines, can the shaderLocation of the attributes be arbitrary or should they be in [0, maxVertexAttributes)? Right now in the specification they are arbitrary but we should make sure this is an conscious choice.
Repacking is always possible. I'm not sure for D3D12 but both Metal and Vulkan constrain the value: it has to be one of the "vertex buffer" (uniform / ssbo / vertex combined table) so less than 32 in Metal, and less then maxVertexAttributes in Vulkan.
Since we want to be able to generate SPIR-V at shader module time, we don't have the luxury of remapping the locations.
That doesn't have to be a hard constraint but also you can easily remap in the shadermodule and use that remapping in the creation of VkRenderPipeline.
You can remap the shader module only if you require that each VS output has to have a corresponding FS input. Do we require this? IIRC only DX12 needs this, for we are going to need to patch it at pipelinecreation anyway, so we can insert the missing input locations at that stage, as an implementation detail.
Ok, I messed this up. Remapping vertex inputs is totally fine. We can allow any locations if people need. We can also say it's restricted today, and later say "ok, it's not restricted" if we find a use-case. Sorry about my confusion!
As usual, I think we might want to start restricted (to maxVertexAttributes) and later allow arbitrary numbers if people ask for it. I doubt they will given it's already a constraint in other APIs. I'll make a PR for that unless you have strong concerns.
If we do vertex attribute repacking, presumably the setPipeline() calls will internally have to issue a collection of setVertexBuffer() calls inside them, because index 3 might map to a differently mapped index for those two pipelines.
(Which may actually be okay... I have no idea whether such a design would actually decrease perf or not. It could also be that the additional flexibility is more valuable than a teeny tiny amount of perf loss.)
We aren't going to be re-packing the vertex buffer indices, but only the attribute locations. All the data bound in this encoder.setVertexBuffer(3, myVertexBuffer, ...); will be equally valid with or without re-packing. What the re-packing would change is how the shader communicates with the pipeline, internally, without affecting anything the user can see.
Right, repacking vertex buffer indices would require repacking in encoders, while repacking vertex attribute locations requires repacking in createRenderPipeline.
Regardless, unless there are objections, we can resolve not to do any repacking yet, and it's unlikely we will need to add it in the future.
Activity
kainino0x commentedon Feb 6, 2021
Are there constraints in the backend apis? Or is repacking possible?
Kangz commentedon Feb 8, 2021
Repacking is always possible. I'm not sure for D3D12 but both Metal and Vulkan constrain the value: it has to be one of the "vertex buffer" (uniform / ssbo / vertex combined table) so less than 32 in Metal, and less then
maxVertexAttributesin Vulkan.kvark commentedon Feb 8, 2021
Relevant VU:
Since we want to be able to generate SPIR-V at shader module time, we don't have the luxury of remapping the locations.
I suggest we enforce the same constraint in WebGPU.
Kangz commentedon Feb 8, 2021
That doesn't have to be a hard constraint but also you can easily remap in the shadermodule and use that remapping in the creation of VkRenderPipeline.
kvark commentedon Feb 8, 2021
You can remap the shader module only if you require that each VS output has to have a corresponding FS input. Do we require this? IIRC only DX12 needs this, for we are going to need to patch it at pipelinecreation anyway, so we can insert the missing input locations at that stage, as an implementation detail.
kainino0x commentedon Feb 9, 2021
This issue is about VS inputs, what do VS outputs have to do with it? Do they share a numbering namespace?
kvark commentedon Feb 9, 2021
Ok, I messed this up. Remapping vertex inputs is totally fine. We can allow any locations if people need. We can also say it's restricted today, and later say "ok, it's not restricted" if we find a use-case. Sorry about my confusion!
Kangz commentedon Feb 9, 2021
As usual, I think we might want to start restricted (to
maxVertexAttributes) and later allow arbitrary numbers if people ask for it. I doubt they will given it's already a constraint in other APIs. I'll make a PR for that unless you have strong concerns.litherum commentedon Feb 17, 2021
If we do repacking, what about a program that is something like
If we do vertex attribute repacking, presumably the
setPipeline()calls will internally have to issue a collection ofsetVertexBuffer()calls inside them, because index 3 might map to a differently mapped index for those two pipelines.(Which may actually be okay... I have no idea whether such a design would actually decrease perf or not. It could also be that the additional flexibility is more valuable than a teeny tiny amount of perf loss.)
kvark commentedon Feb 17, 2021
We aren't going to be re-packing the vertex buffer indices, but only the attribute locations. All the data bound in this
encoder.setVertexBuffer(3, myVertexBuffer, ...);will be equally valid with or without re-packing. What the re-packing would change is how the shader communicates with the pipeline, internally, without affecting anything the user can see.kainino0x commentedon Feb 18, 2021
Right, repacking vertex buffer indices would require repacking in encoders, while repacking vertex attribute locations requires repacking in createRenderPipeline.
Regardless, unless there are objections, we can resolve not to do any repacking yet, and it's unlikely we will need to add it in the future.
Kangz commentedon Mar 5, 2021
The spec change has already landed, closing.
kainino0x commentedon Apr 9, 2021
For the record it was #1423
wgsl: Stub tests for textureSampleCompare (gpuweb#1418)