Skip to content

Are values in GPUVertexAttribute.shaderLocation arbitrary? #1418

Closed

Description

@Kangz

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.

Activity

  1. kainino0x commented on Feb 6, 2021

    @kainino0x
    Contributor

    Are there constraints in the backend apis? Or is repacking possible?

  2. Kangz commented on Feb 8, 2021

    @Kangz
    ContributorAuthor

    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.

  3. kvark commented on Feb 8, 2021

    @kvark
    Contributor

    Relevant VU:

    VUID-VkVertexInputAttributeDescription-location-00620
    location must be less than VkPhysicalDeviceLimits::maxVertexInputAttributes

    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.

  4. Kangz commented on Feb 8, 2021

    @Kangz
    ContributorAuthor

    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.

  5. kvark commented on Feb 8, 2021

    @kvark
    Contributor

    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.

  6. kainino0x commented on Feb 9, 2021

    @kainino0x
    Contributor

    This issue is about VS inputs, what do VS outputs have to do with it? Do they share a numbering namespace?

  7. kvark commented on Feb 9, 2021

    @kvark
    Contributor

    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!

  8. Kangz commented on Feb 9, 2021

    @Kangz
    ContributorAuthor

    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.

  9. litherum commented on Feb 17, 2021

    @litherum
    Contributor

    If we do repacking, what about a program that is something like

    encoder.setVertexBuffer(3, myVertexBuffer, ...);
    encoder.setPipeline(myPipeline1);
    encoder.draw(...);
    encoder.setPipeline(myPipeline2);
    encoder.draw(...);
    

    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.)

  10. kvark commented on Feb 17, 2021

    @kvark
    Contributor

    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.

  11. kainino0x commented on Feb 18, 2021

    @kainino0x
    Contributor

    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.

  12. Kangz commented on Mar 5, 2021

    @Kangz
    ContributorAuthor

    The spec change has already landed, closing.

  13. kainino0x commented on Apr 9, 2021

    @kainino0x
    Contributor

    For the record it was #1423

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions