vulkano_shaders::shader! "path:" parameter doesn't incorporate changes to the referenced file by default

Created on 18 Aug 2019  路  5Comments  路  Source: vulkano-rs/vulkano

  • Version of vulkano: 0.14
  • rustc 1.39.0-nightly
  • OS: Windows 10
  • GPU (the selected PhysicalDevice): GTX 1080
  • GPU Driver: GeForce GRD 431.60
  • See this demo repo for an easy example, though any file using shader! with the path argument should work.

Issue

When using vulkano_shaders::shader! macro with the path variant, the file indicated by path is not watched by cargo. Changes to the shader file must then be coordinated with a change in the rust file the shader macro runs in (or with a clean build) for the changes to be reflected by the executable.

It appears to be possible to add an arbitrary file dependency to cargo in some cases as indicated by this code which appears to be intended for use in a cargo build script. I'm unsure if a similar technique could work for a macro, or if there's a different API the macro could use that would result in more consistent behavior.

If it isn't currently possible to make this work reliably the docs should at least include a warning of some sort, I think.

This obviously doesn't affect the src variant of shader!, which by nature changes the file when the shader code changes.

needs investigation bug

Most helpful comment

The include_str! invocations just force cargo to watch the file for changes (which I hadn鈥檛 thought of) the actual value isn鈥檛 used.

Presumably the compiler is smart enough to drop them from the final product but I haven鈥檛 played with it yet.

All 5 comments

You can use this trick as a workaround:

#[allow(dead_code)] // Used to force recompilation of shader change
const X: &str = include_str!("../shaders/fragment.glsl");
#[allow(dead_code)] // Used to force recompilation of shader change
const X1: &str = include_str!("../shaders/vertex.glsl");

src won't work with include_str! because it doesn't count as a literal, so I'm not sure how the above works.

The include_str! invocations just force cargo to watch the file for changes (which I hadn鈥檛 thought of) the actual value isn鈥檛 used.

Presumably the compiler is smart enough to drop them from the final product but I haven鈥檛 played with it yet.

I realize this is an old issue, but I have noticed this happening and the shaders seem to recompile as long as I also save the main file, even if there were no changes.

Was this page helpful?
0 / 5 - 0 ratings