Skip to content

(RFC) Remove schema validation in createBuffer #2075

@iwoplaza

Description

@iwoplaza

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions