software-mansion / software-mansion/TypeGPU

chore: Separating codegen from our public API (shaderbits)

Open
#2,402 0 comments 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

[!NOTE]
Draft issue

Our code directories roughly correspond to typegpu/* entry-points, as well as the tgsl directory (for code-gen functionality) and shared directory (used by everything, depends on nothing. Shared utilities).

There are currently imports to and from each directory, which sometimes causes hard to untangle circular imports. My proposal is to slowly move towards an untangled hierarchy of directories in a series of steps that we can introduce and rollout progressively, instead of a big rewrite.

The high-level goals I'd like to achieve after the whole migrations are:

  1. "Shaderbits" - Separate our public API schemas (exported from typegpu/data) from the values we use internally to infer types during shader generation. The circular dependency happens here naturally, as schemas can be called on the GPU, and often handle type coersion and conversion, which in turn needs to be reference a few numeric types by name. I call these non-public type representations "Shaderbits", and their aim is to represent WGSL schemas as JS objects, without additional fluff.
  2. One-way dependencies - Drawing high-boundaries between code directories looks to be possible. common should conceptually use the public API to define things users might want to reuse very often, no need for anything else to import from it internally. std needs to define functions that accept and return schema instances, no way around that. core APIs like buffers and variables accept and operator on schemas.
Image Image

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 by mapping imports among the typegpu/* entry points, tgsl, shared, and the named common, std, core, and typegpu/data areas. Trace the schema and code-generation dependencies first; done would mean the proposed shaderbits separation and one-way directory dependencies are implemented without the circular imports described.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
computer-graphics, tooling
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.