-
Notifications
You must be signed in to change notification settings - Fork 33
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
Fragment shader just copying values doesn't compile #185
Comments
Adding those entry-points to $ git show -s --oneline
f069c58c0c0 (HEAD, upstream/main, main) examples/runners/wgpu: avoid holding onto to multiple surfaces at the same time.
$ cargo run -p multibuilder --release --no-default-features --features use-installed-tools 2>&1 | rg -U 'CompileResult \{[\s\S]+\}'
CompileResult {
entry_points: [
"fragment_doesnt",
"fragment_works",
"fragment_works_again",
"main_fs",
"main_vs",
],
module: MultiModule(
{
"fragment_doesnt": "/home/eddy/Projects/rust-gpu/target/spirv-unknown-spv1.3/release/deps/sky_shader.spvs/fragment_doesnt.spv",
"fragment_works": "/home/eddy/Projects/rust-gpu/target/spirv-unknown-spv1.3/release/deps/sky_shader.spvs/fragment_works.spv",
"fragment_works_again": "/home/eddy/Projects/rust-gpu/target/spirv-unknown-spv1.3/release/deps/sky_shader.spvs/fragment_works_again.spv",
"main_fs": "/home/eddy/Projects/rust-gpu/target/spirv-unknown-spv1.3/release/deps/sky_shader.spvs/main_fs.spv",
"main_vs": "/home/eddy/Projects/rust-gpu/target/spirv-unknown-spv1.3/release/deps/sky_shader.spvs/main_vs.spv",
},
),
} The entry-points seem to all be there: $ echo target/spirv-unknown-spv1.3/release/deps/sky_shader.spvs/*.spv | xargs -t -n1 spirv-dis | rg OpEntryPoint
spirv-dis target/spirv-unknown-spv1.3/release/deps/sky_shader.spvs/fragment_doesnt.spv
OpEntryPoint Fragment %1 "fragment_doesnt" %2 %3
spirv-dis target/spirv-unknown-spv1.3/release/deps/sky_shader.spvs/fragment_works.spv
OpEntryPoint Fragment %1 "fragment_works" %2 %3
spirv-dis target/spirv-unknown-spv1.3/release/deps/sky_shader.spvs/fragment_works_again.spv
OpEntryPoint Fragment %1 "fragment_works_again" %2 %3
spirv-dis target/spirv-unknown-spv1.3/release/deps/sky_shader.spvs/main_fs.spv
OpEntryPoint Fragment %2 "main_fs" %gl_FragCoord %4
spirv-dis target/spirv-unknown-spv1.3/release/deps/sky_shader.spvs/main_vs.spv
OpEntryPoint Vertex %1 "main_vs" %gl_VertexIndex %gl_Position And we can look at the generated $ cargo install naga-cli
Updating crates.io index
Ignored package `naga-cli v23.0.0` is already installed, use --force to override
$ naga target/spirv-unknown-spv1.3/release/deps/sky_shader.spvs/fragment_doesnt.{spv,wgsl}
$ cat target/spirv-unknown-spv1.3/release/deps/sky_shader.spvs/fragment_doesnt.wgsl var<private> global: vec4<f32>;
var<private> global_1: vec4<f32>;
fn function() {
let _e2 = global;
global_1 = _e2;
return;
}
@fragment
fn fragment_doesnt(@location(0) param: vec4<f32>) -> @location(0) vec4<f32> {
global = param;
function();
let _e3 = global_1;
return _e3;
} So AFAICT, this bug isn't reproduced by Rust-GPU Only other thing I can think of is EDIT: absolutely no changes when I let it use SPIRV-Tools compiled by |
Btw, that's 100% expected. The user function is not the real entry-point, and the |
Ok, so sounds like this might be a |
Could be any of:
|
For what it’s worth, I came across the problem on this project. I’m keeping the branch that way until we can figure out what’s going on. And yes I’m using |
Thanks for the link to your project @hadronized - I've recreated your problem and indeed, only one shader entry point is produced. My guess is this is not I'll keep looking at this, thanks for the report @hadronized 👍 . |
Hey! Look what I found in my own /// Simple fragment shader that writes the input color to the output color.
#[spirv(fragment)]
pub fn tutorial_passthru_fragment(in_color: Vec4, output: &mut Vec4) {
use glam::Vec4Swizzles;
// This seems silly, but without it rust-gpu doesn't emit a .spv file...
*output = in_color.xyz().extend(in_color.w);
} So this definitely pre-dates
|
IMO that shouldn't be possible. The "user" function you're see is not the SPIR-V entry-point. The entry-point function, as pointed to by rust-gpu/crates/rustc_codegen_spirv/src/codegen_cx/entry.rs Lines 152 to 213 in 0750b30
You could even have the "user" functions (the ones on the Rust side, annotated with The much scarier thing is that not assigning the output might be UB? I suppose e.g. SPIR-V -> WGSL might just read from an "uninitialized" variable, which, WGSL trying to be as safe as possible, is probably actually initialized under the hood (but I haven't actually checked any of this?)
Can you reproduce anymore? This produces a #![cfg_attr(target_arch = "spirv", no_std)]
use spirv_std::spirv;
use spirv_std::glam::Vec4;
/// Simple fragment shader that writes the input color to the output color.
#[spirv(fragment)]
pub fn tutorial_passthru_fragment(in_color: Vec4, output: &mut Vec4) {
} And it even produces what we expected as far as WGSL is concerned: $ naga target/spirv-unknown-spv1.3/release/deps/sky_shader.spvs/tutorial_passthru_fragment.{spv,wgsl}
$ cat target/spirv-unknown-spv1.3/release/deps/sky_shader.spvs/tutorial_passthru_fragment.wgsl var<private> global: vec4<f32>;
var<private> global_1: vec4<f32>;
fn function() {
return;
}
@fragment
fn tutorial_passthru_fragment(@location(0) param: vec4<f32>) -> @location(0) vec4<f32> {
global = param;
function();
let _e3 = global_1;
return _e3;
} If you're testing with |
Either way, |
I'm now thinking this may be a difference in |
Oh, you default to (click to open console log for
|
Expected Behaviour
The following code snippet defines 3 fragment shaders, but the middle one does not get compiled / emit an entry point / generates a spv (with multibuilder true). Looks like it's somehow getting inlined / optimized away before monomorphization, so it's not picked up as an entry point?
Found while investigating an issue with hadronized on discord.
System Info
The text was updated successfully, but these errors were encountered: