Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linting shaders #5

Open
Korijn opened this issue Jan 5, 2024 · 7 comments
Open

Linting shaders #5

Korijn opened this issue Jan 5, 2024 · 7 comments

Comments

@Korijn
Copy link
Contributor

Korijn commented Jan 5, 2024

Can naga be used as a cli tool to lint shader files? Or are there other tools that can be used?

@Vipitis
Copy link
Collaborator

Vipitis commented Jan 5, 2024

naga-cli can validate and translate shaders. This will give you errors (sometimes panics without an error) but not necessarily give you feedback about style or unused names etc.
I have seen some "glsl lint" extensions for VSCode, but no experience with how they work or what they provide.

@Korijn
Copy link
Contributor Author

Korijn commented Jan 11, 2024

I'm thinking this would mean building a separate pip installable CLI tool that uses naga-cli to validate .wgsl and .glsl files.

@Vipitis
Copy link
Collaborator

Vipitis commented Jan 11, 2024

wgpu uses naga already to validate shaders. And errors do get passed all the way to Python. I use a simple try/except for my project. And this does work, apart from edge cases where the called process panics (it doesn't have any exit code). Some of these are already addressed and next wgpu-core release is targeting 17th January, which I hope includes all the naga fixes of the past 2 months.

So using naga-cli seems redundant. I wanted to parse the error message into a Python Exception with corrected span etc later on, since the shadertoy code isn't a valid fragment shader on it's own. You always have to add the compatibility code before it.
perhaps introducing a .validate_shadertoy method directly to the Shadertoy class might be a good idea.

@Korijn
Copy link
Contributor Author

Korijn commented Jan 11, 2024

I'm mostly thinking about having a CLI tool available that can be run on CI to validate all .glsl and .wgsl files. I think with what you're saying, it means we could build something like that on wgpu-py instead of on naga-cli.

@Vipitis
Copy link
Collaborator

Vipitis commented Jan 11, 2024

yes, adding a cli tool for the functionality of the shadetoy util is also something I wanted to consider. But that requires features like file I/O for example.

@Korijn
Copy link
Contributor Author

Korijn commented Jan 26, 2024

https://github.com/PolyMeilex/vscode-wgsl

Looks like this has both syntax highlighting and a CLI linting functionality

@almarklein
Copy link
Member

I hacked together a VSCode extension to syntax-highlight shaders in Python strings: https://github.com/pygfx/python-string-shaders (using a similar extension for sql as inspiration).

The workflow is not as nice as when the shader is in its own file, because it only does highlighting, the language server does not kick in, so there is no autocompletion and code analysis. But perhaps a nice middle ground.

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

No branches or pull requests

3 participants