software-mansion / software-mansion/TypeGPU

request: being able to explicitly declare vertex-buffer slots for pipelines

Open
#2,850 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
3.2k
Forks
122
Avg merge
3d 5h
Merged PRs (30d)
34

Description

TypeGPU currently assigns vertex-buffer slots consecutively in order in which vertex layouts were encountered by the shader - 0, 1, 2 etc.

I'm working on a project where it's much easier to reason about and handle things if slots were fixed. I wanted to make it so:

  • Slot 0: standard vertex data
  • Slot 1: skinning data
  • Slot 2: vertex colors
  • Slots 3+: custom

Not every pipeline has to use every slot. For example, an unskinned pipeline would use standard vertex data and vertex colors (slots 0 and 2). WebGPU supports this via null values like buffers: [standardLayout, null, colorLayout].

In the above case, typeGPU would assign the color layout to slot 1 and I couldnt find any way to reserve the unused slot (without unwrapping everything and just using basically vanilla webgpu).

Could TypeGPU support optional per pipeline slot mapping as an opt-in? I think it's totally possible to make it so current DX is unchanged while adding this as optional

root.createRenderPipeline({
    vertex,
    fragment,
    attribs,
    vertexBufferSlots: [standardLayout, null, colorLayout]
  });

This would make slots allocation predictable across pipeline variants, so render passes would not need to know which optional layouts a particular pipeline consumes.

When vertexBufferSlot option is not present, existing behaviour of assigning slots in order would remain unchanged.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the root.createRenderPipeline entry point and trace how vertex layouts become buffer slots. Compare the proposed vertexBufferSlots array, including null entries, with the existing automatic allocation path. Done means opt-in fixed slots work across pipeline variants while pipelines without the option retain their current behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
computer-graphics
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.