Skip to content

Commit 11d1ebe

Browse files
authored
Fix OIT shaders error with DX12 backend (#15782)
# Objective - Fixes #15781 ## Solution - DX12 backend seems to require functions with return types to return value. [WebGPU spec also requires this](https://gpuweb.github.io/gpuweb/wgsl/#behaviors-rules). Upstream issue: gfx-rs/wgpu#4458 gpuweb/gpuweb#2523 ## Testing - Tested `order_independent_transparency` example with both dx12 and vulkan backend on Windows
1 parent 0944499 commit 11d1ebe

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

crates/bevy_core_pipeline/src/oit/oit_draw.wgsl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#ifdef OIT_ENABLED
66
// Add the fragment to the oit buffer
7-
fn oit_draw(position: vec4f, color: vec4f) -> vec4f {
7+
fn oit_draw(position: vec4f, color: vec4f) {
88
// get the index of the current fragment relative to the screen size
99
let screen_index = i32(floor(position.x) + floor(position.y) * view.viewport.z);
1010
// get the size of the buffer.
@@ -19,15 +19,14 @@ fn oit_draw(position: vec4f, color: vec4f) -> vec4f {
1919
// accidentally increase the index above the maximum value
2020
atomicStore(&oit_layer_ids[screen_index], oit_layers_count);
2121
// TODO for tail blending we should return the color here
22-
discard;
22+
return;
2323
}
2424

2525
// get the layer_index from the screen
2626
let layer_index = screen_index + layer_id * buffer_size;
2727
let rgb9e5_color = bevy_pbr::rgb9e5::vec3_to_rgb9e5_(color.rgb);
2828
let depth_alpha = pack_24bit_depth_8bit_alpha(position.z, color.a);
2929
oit_layers[layer_index] = vec2(rgb9e5_color, depth_alpha);
30-
discard;
3130
}
3231
#endif // OIT_ENABLED
3332

crates/bevy_core_pipeline/src/oit/resolve/oit_resolve.wgsl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ fn fragment(in: FullscreenVertexOutput) -> @location(0) vec4<f32> {
2727
let counter = atomicLoad(&layer_ids[screen_index]);
2828
if counter == 0 {
2929
reset_indices(screen_index);
30-
discard;
30+
31+
// https://github.com/gfx-rs/wgpu/issues/4416
32+
if true {
33+
discard;
34+
}
35+
return vec4(0.0);
3136
} else {
3237
let result = sort(screen_index, buffer_size);
3338
reset_indices(screen_index);

crates/bevy_pbr/src/render/pbr.wgsl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ fn fragment(
7373
#ifdef OIT_ENABLED
7474
let alpha_mode = pbr_input.material.flags & pbr_types::STANDARD_MATERIAL_FLAGS_ALPHA_MODE_RESERVED_BITS;
7575
if alpha_mode != pbr_types::STANDARD_MATERIAL_FLAGS_ALPHA_MODE_OPAQUE {
76-
// This will always return 0.0. The fragments will only be drawn during the oit resolve pass.
77-
out.color = oit_draw(in.position, out.color);
76+
// The fragments will only be drawn during the oit resolve pass.
77+
oit_draw(in.position, out.color);
78+
discard;
7879
}
7980
#endif // OIT_ENABLED
8081

0 commit comments

Comments
 (0)