software-mansion / software-mansion/TypeGPU

fix: Repeat call in `d.mat4x4f.translation`

Open
#2,859 4 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

  it('...', () => {
    const myVar = tgpu.privateVar(d.u32);
    const helper = () => {
      'use gpu';
      myVar.$++;
      return myVar.$;
    };
    const main = () => {
      'use gpu';
      const t = d.mat4x4f.translation(d.vec3f(helper()));
    };

    expect(tgpu.resolve([main])).toMatchInlineSnapshot(`
      "var<private> myVar: u32;

      fn helper() -> u32 {
        myVar++;
        return myVar;
      }

      fn main() {
        let t = mat4x4f(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, vec3f(f32(helper())).x, vec3f(f32(helper())).y, vec3f(f32(helper())).z, 1);
      }"
    `);
  });

Either delegate to another function, or find a way to detect this case and throw

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

Reproduce the issue with the provided test using d.mat4x4f.translation, helper(), and tgpu.resolve. Trace the implementation of d.mat4x4f.translation and the generated shader expression, then either delegate the repeated evaluation or reject this case; done means helper() is not emitted three times or the unsupported case throws clearly.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.