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

Use include_bytes! in shader! for automatic recompilation #1523

Merged

Conversation

mvilim
Copy link
Contributor

@mvilim mvilim commented Mar 30, 2021

This PR makes use of std::include_bytes to automatically recompile path-loaded shaders when they change, as suggested in #890. The resulting variable is left unused, so the compiler is free to optimize it away.

I confirmed that the shader bytes are only included in the binary if debug = true (with debug off and opt-level = 0, the bytes are not present in the final binary). Given the small size of shader files, I assume including their source by default is reasonable. If we would rather not include it by default, I can add a flag to the shader! macro to control the functionality.

I believe this should also close #1231 and #1349.

@Rua Rua mentioned this pull request Mar 31, 2021
4 tasks
@Eliah-Lakhin Eliah-Lakhin merged commit fc2e470 into vulkano-rs:master Mar 31, 2021
@Eliah-Lakhin
Copy link
Contributor

@mvilim Merged. Thank you for the improvement!

Regarding #1231 and #1349. Do I understand correctly, it affects glsl source changes detection as well?

@Eliah-Lakhin
Copy link
Contributor

Eliah-Lakhin commented Mar 31, 2021

@mvilim From my observations it didn't fully resolve the issue. This is an example of the macro use:

vulkano_shaders::shader! {
    ty: "compute",
    include: [ "./src/shader" ],
    path: "./src/shader/main.glsl",
    types_meta: {
        use serde::{Deserialize, Serialize};

        #[derive(Clone, Copy, PartialEq, Debug, Default, Serialize, Deserialize)]

        impl Eq
    }
}

When I change a file indirectly included in the entry-point(./src/shader/main.glsl) through the shaderc's #include <..> directive, it didn't detect changes. However, if I change the entry-point file itself it does detect the changes.

Perhaps, the more proper solution would be reading such directives and include their sources as well(recursively).

Would you mind working on this additional improvement?

@mvilim
Copy link
Contributor Author

mvilim commented Apr 1, 2021

I didn't even notice the include directive. Thanks for catching that issue. I have opened #1529 with a fix. Thankfully shaderc exposes a mechanism for obtaining the set of files used in the compilation.

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.

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