Skip to content

Conversation

@aleksanderkatan
Copy link
Contributor

@aleksanderkatan aleksanderkatan commented Dec 16, 2025

Before:
image

After:
image

Changes:

  • remove isEntry from all functions shells (it was unused),
  • remove does from entrypoints,
  • add entryPoint to make entry functions differentiable,
  • add type guards for entry functions,
  • keep info on ctx regarding currently resolved stage,
  • throw when a console.log appears during vertex stage.

Currently:

  • throws an error when a log appears during vertex stage resolution (either pipeline or a standalone vertex function)
  • transforms the log to a comment in non-vertex functions resolved directly,
  • works during fragment or compute stages when resolving a pipeline.

@aleksanderkatan aleksanderkatan linked an issue Dec 16, 2025 that may be closed by this pull request
@github-actions
Copy link

github-actions bot commented Dec 16, 2025

pkg.pr.new

packages
Ready to be installed by your favorite package manager ⬇️

https://pkg.pr.new/software-mansion/TypeGPU/typegpu@2ea92235f603f7b069f74eea87009962ab0bbdbb
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/noise@2ea92235f603f7b069f74eea87009962ab0bbdbb
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@2ea92235f603f7b069f74eea87009962ab0bbdbb

benchmark
view benchmark

commit
view commit

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves error handling when console.log is used in vertex shaders by detecting the shader stage during resolution and throwing a clear error instead of allowing invalid code generation.

Key changes:

  • Replaces the isEntry boolean flag with an entryPoint string field to distinguish between shader stages ('vertex', 'fragment', 'compute')
  • Tracks the current shader stage during resolution and validates console.log usage
  • Removes the deprecated does method from entry point function shells

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/typegpu/src/types.ts Adds ShaderStage type definition for tracking shader stages
packages/typegpu/src/resolutionCtx.ts Implements stage tracking logic and validates console.log usage based on current stage
packages/typegpu/src/core/function/tgpuVertexFn.ts Replaces isEntry with entryPoint: 'vertex' and adds type guard
packages/typegpu/src/core/function/tgpuFragmentFn.ts Replaces isEntry with entryPoint: 'fragment' and adds type guard
packages/typegpu/src/core/function/tgpuFn.ts Removes unused isEntry: false from regular functions
packages/typegpu/src/core/function/tgpuComputeFn.ts Replaces isEntry with entryPoint: 'compute' and adds type guard
packages/typegpu/tests/tgsl/consoleLog.test.ts Adds test coverage for vertex shader console.log error handling
apps/typegpu-docs/src/examples/rendering/3d-fish/render.ts Demonstrates the error by adding a console.log in a vertex shader

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@aleksanderkatan aleksanderkatan marked this pull request as ready for review December 16, 2025 16:24
Copy link
Collaborator

@cieplypolar cieplypolar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

return Object.assign(Object.assign(call, shell), {
does: call,
}) as TgpuComputeFnShell<ComputeIn>;
return Object.assign(call, shell);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason, why we don't have to cast this to TgpuComputeFnShell<T> like in fragment and vertex functions?

Copy link
Contributor Author

@aleksanderkatan aleksanderkatan Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have to. In other cases this is necessary.
Damn my reading comprehension sucks today.
I don't know, I didn't investigate it.

Copy link
Contributor Author

@aleksanderkatan aleksanderkatan Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I see, it is an issue regarding createVertexFn not being generic, as well as the OmitBuiltins not being consistent. I think it's the simplest solution to just cast.

Comment on lines +341 to +346
/**
* Holds info about the currently resolved shader stage (if there is any).
* Note that if a function is used both in vertex and fragment stage,
* then it will only go through the process during the vertex stage.
*/
private _currentStage: ShaderStage;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will only allow shader code to ask which stage they're being resolved in first. If we instead create an internal slot that provides the value of the stage currently being resolved, then branches that actually use this value will be able to have branching logic based on which stage they're in.

I can definitely see someone wanting to log a value inside of a utility function that happens to execute in a compute shader and a fragment shader, and not being able to do so because of this error. If we instead emit a no-op and warn the user that a console log has been skipped because it's in a vertex shader, then it would still allow both shader stages to compile, and the other console log to run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Better error when console.logging from vertex shaders

4 participants