software-mansion / software-mansion/TypeGPU

feat: Detect change in externals across shader invocations and suggest alternative

Open
#1,573 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

A first instinct when using TypeGPU functions could be to use variables from the outer scope and expect them to auto-update:

let time = 0;

const getDirection = tgpu.fn([], d.vec2f)(() => {
  // Using the `time` variable inside shader code
  return d.vec2f(std.cos(time), std.sin(time));
});

// before render
time += deltaTime;
// draw...

However, the shader will compile with the value that the variable had at the moment of compilation, and not change between invocations.
This is a silent error/bug, and could be hard to grasp on first use.

Possible solution

In DEV mode, we can gather the externals that were used by a shader, and check if their values match the ones that were captured during compilation.

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

No files, tests, or entry points are named. Start by locating the shader compilation path and how external values are captured, then determine how DEV-mode comparisons and an alternative suggestion should be exposed. Done means changed externals are detected across shader invocations without affecting production behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
computer-graphics
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.