vulkano-rs / vulkano

Safe and rich Rust wrapper around the Vulkan API
Apache License 2.0
4.53k stars 435 forks source link

Can't use precompiled shader with optimization #1896

Closed inferrna closed 2 years ago

inferrna commented 2 years ago

Code example https://github.com/inferrna/smart_denoise_rs

Issue

There are two precompiled shaders in the repo: compiled_opt.spv produced with ./bin/glslc -fshader-stage=compute shader.glsl and compiled_unopt.spv produced with ./bin/glslc -fshader-stage=compute -O shader.glsl

Using unoptimized version in src/denoise_shader_compiled.rs works fine but with optimized I got this error at compile stage:

1 | / vulkano_shaders::shader! {
2 | |         ty: "compute",
3 | |         bytes: "compiled_opt.spv"
4 | | }
  | | ^
  | | |
  | |_field already declared
  |   `__unnamed` first declared here

Using latest glslc from here https://storage.googleapis.com/shaderc/badges/build_link_linux_clang_release.html

Rua commented 2 years ago

It seems like the names of variables have been stripped out by optimising it, so when Vulkano is trying to assign names to struct fields, it can't find any names and so it just goes with "unnamed". What it really should do in this case is add numbers so that the names don't conflict anymore.

inferrna commented 2 years ago

Passing -g flag to glslc seems solved the issue for me: ./bin/glslc -g -fshader-stage=compute -O shader.glsl

But bad naming for unnamed fields is still the issue for vulkano, so I keep this open.