software-mansion / software-mansion/TypeGPU
(RFC) Remove schema validation in `createBuffer`
Open
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 3.2k
- Forks
- 122
- Avg merge
- 3d 5h
- Merged PRs (30d)
- 34
Description
I think we should remove schema validation in createBuffer. Reasons:
- Logic could be moved into a type-aware lint plugin
- Prevents users from creating helper functions that accept generic types
Example of a generic function that fails
import { type TgpuRoot } from 'typegpu';
import { arrayOf } from 'typegpu/data';
export function createInstanceBuffer<StructData extends d.WgslStruct>(
root: TgpuRoot,
struct: StructData,
length: number,
) {
const instanceBuffer = root
// ❌ `d.WgslArray<StructData> is not assignable to `ValidateBufferSchema<d.WgslArray<StructData>>`
.createBuffer(d.arrayOf(struct, length))
// ❌ A very long error relating to usages
.$usage('vertex', 'storage');
const instanceLayout = tgpu.vertexLayout(
(n) => arrayOf(struct, n),
'instance',
);
return [instanceBuffer, instanceLayout] as const;
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the TypeScript createBuffer API and reproduce the generic createInstanceBuffer example from the issue. Trace the current schema and usage validation types, then determine the intended boundary for validation removal; this is done when generic buffer helpers type-check without the current validation errors and existing behavior remains covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100