gfx-rs / wgpu

A cross-platform, safe, pure-Rust graphics API.
https://wgpu.rs
Apache License 2.0
12.8k stars 938 forks source link

Is there a way to generate clean, human-readable output? #4542

Open rafaelbeckel opened 1 year ago

rafaelbeckel commented 1 year ago

I'm using naga CLI to convert a few .glsl shaders to .wgsl with the intention of making .wgsl my new source code.

However, the output contains a lot of intermediate variables named _e{N} for each time a source variable is used, which makes the code bloated and unreadable.

I assume naga was designed as a backend tool and is not supposed to produce human-readable code, so these variables are there to produce reliable Spir-V bytecode from any source language.

However, it would be nice to introduce an option to set the output to be as human-readable and clean as possible. I was looking for something like: naga in.frag out.wgsl --clean (or maybe --format=human).

Is there a way to do that? If not, would you guys accept a PR introducing this option, or is it way out of scope?

teoxoy commented 1 year ago

I don't think it would be out of scope, it would be helpful to have more readable output especially when debugging issues.

However, I think it will not be easy to improve the status quo.

What are the steps you think of that would get us closer to generating a more human readable output?

Related: https://github.com/gfx-rs/wgpu/issues/4349

rafaelbeckel commented 1 year ago

I couldn't take a close look at that yet, but I was roughly thinking about implementing it as a post-processing step. This way, I'd avoid messing up with the internals, and it would be relatively easy to implement.