Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ By @inner-daemons in [#9434](https://github.com/gfx-rs/wgpu/pull/9434).
- Fixed missing initialization of other aspects when writing to a single aspect of a multi-aspect texture. By @andyleiserson in [#9626](https://github.com/gfx-rs/wgpu/pull/9626).
- Fix process abort when a `SurfaceTexture` is dropped during panic unwind between `get_current_texture` and `Queue::present`. The acquired texture reference is now released without calling HAL discard. By @hack3rmann in [#9678](https://github.com/gfx-rs/wgpu/pull/9678).
- Fixed incorrect initialization tracking for 3D textures. By @andyleiserson in [#9765](https://github.com/gfx-rs/wgpu/pull/9765).
- Fix separate depth/stencil read-only state and `SYNC-HAZARD-WRITE-AFTER-WRITE` on Vulkan. By @beicause in [#9763](https://github.com/gfx-rs/wgpu/pull/9763).

#### naga

Expand Down
5 changes: 0 additions & 5 deletions cts_runner/fail.lst
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
// The `cts_runner` integration test `lst_files_are_sorted` verifies that test selectors
// appear in this file in order -- including ones in comments.

webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_testing:format="depth24plus-stencil8";depthReadOnly=false;stencilReadOnly=true // https://github.com/gfx-rs/wgpu/issues/8705
webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_testing:format="depth24plus-stencil8";depthReadOnly=true;stencilReadOnly=false // https://github.com/gfx-rs/wgpu/issues/8705
webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_testing:format="depth32float-stencil8";depthReadOnly=false;stencilReadOnly=true // https://github.com/gfx-rs/wgpu/issues/8705
webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_testing:format="depth32float-stencil8";depthReadOnly=true;stencilReadOnly=false // https://github.com/gfx-rs/wgpu/issues/8705
webgpu:api,operation,rendering,3d_texture_slices:* // https://github.com/gfx-rs/wgpu/issues/9455

webgpu:api,validation,buffer,create:new_usages,* // https://github.com/denoland/deno/issues/33846; possibly issues with wgpu extensions
Expand Down Expand Up @@ -57,7 +53,6 @@ webgpu:api,validation,render_pipeline,overrides:* // 17%, missing validation: in
webgpu:api,validation,render_pipeline,vertex_state:vertex_attribute_contained_in_stride:* // fails on metal in CI https://github.com/gfx-rs/wgpu/issues/8312
webgpu:api,validation,render_pipeline,vertex_state:vertex_attribute_offset_alignment:* // fails on metal in CI
webgpu:api,validation,resource_usages,texture,in_pass_encoder:subresources_and_binding_types_combination_for_color:* // 92%, https://github.com/gfx-rs/wgpu/issues/3126
webgpu:api,validation,resource_usages,texture,in_render_common:subresources,depth_stencil_attachment_and_bind_group:* // 69%, https://github.com/gfx-rs/wgpu/issues/8705
webgpu:api,validation,state,device_lost,destroy:* // crash
webgpu:api,validation,texture,destroy:submit_a_destroyed_texture_as_attachment:* // 44%, https://github.com/gfx-rs/wgpu/issues/8714

Expand Down
16 changes: 2 additions & 14 deletions cts_runner/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,7 @@ webgpu:api,operation,compute_pipeline,overrides:*
//FAIL: webgpu:api,operation,compute,basic:large_dispatch:*
webgpu:api,operation,compute,basic:memcpy:*
webgpu:api,operation,device,lost:*
webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_testing:format="depth16unorm";*
webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_testing:format="depth24plus";*
webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_testing:format="depth24plus-stencil8";depthReadOnly=false;stencilReadOnly=false
webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_testing:format="depth24plus-stencil8";depthReadOnly=true;stencilReadOnly=true
webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_testing:format="depth32float";*
webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_testing:format="depth32float-stencil8";depthReadOnly=false;stencilReadOnly=false
webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_testing:format="depth32float-stencil8";depthReadOnly=true;stencilReadOnly=true
webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_testing:format="stencil8";*
webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:*

webgpu:api,operation,render_pass,*
webgpu:api,operation,render_pipeline,overrides:*
Expand Down Expand Up @@ -304,12 +297,7 @@ webgpu:api,validation,resource_usages,texture,in_pass_encoder:shader_stages_and_
webgpu:api,validation,resource_usages,texture,in_pass_encoder:subresources_and_binding_types_combination_for_aspect:*
webgpu:api,validation,resource_usages,texture,in_pass_encoder:subresources_and_binding_types_combination_for_color:compute=false;type0="render-target";type1="render-target"
webgpu:api,validation,resource_usages,texture,in_pass_encoder:unused_bindings_in_pipeline:*
webgpu:api,validation,resource_usages,texture,in_render_common:subresources,color_attachment_and_bind_group:*
webgpu:api,validation,resource_usages,texture,in_render_common:subresources,color_attachments:*
// FAIL: webgpu:api,validation,resource_usages,texture,in_render_common:subresources,depth_stencil_attachment_and_bind_group:*
// https://github.com/gfx-rs/wgpu/issues/8705
webgpu:api,validation,resource_usages,texture,in_render_common:subresources,depth_stencil_texture_in_bind_groups:*
webgpu:api,validation,resource_usages,texture,in_render_common:subresources,multiple_bind_groups:*
webgpu:api,validation,resource_usages,texture,in_render_common:subresources,*
webgpu:api,validation,resource_usages,texture,in_render_misc:*
webgpu:api,validation,shader_module,*
webgpu:api,validation,texture,bgra8unorm_storage:*
Expand Down
16 changes: 4 additions & 12 deletions examples/features/src/water/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ impl crate::framework::Example for Example {
// First pass: render the reflection.
{
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: None,
label: Some("reflection"),
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &self.reflect_view,
depth_slice: None,
Expand Down Expand Up @@ -758,7 +758,7 @@ impl crate::framework::Example for Example {
// depth values, so we must use StoreOp::Store.
{
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: None,
label: Some("terrain"),
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view,
depth_slice: None,
Expand Down Expand Up @@ -789,7 +789,7 @@ impl crate::framework::Example for Example {
// to it, so it cannot be in the same render pass.
{
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: None,
label: Some("water"),
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view,
depth_slice: None,
Expand Down Expand Up @@ -832,15 +832,7 @@ pub static TEST: crate::framework::ExampleTestParams = crate::framework::Example
height: 768,
optional_features: wgpu::Features::default(),
base_test_parameters: wgpu_test::TestParameters::default()
.downlevel_flags(wgpu::DownlevelFlags::READ_ONLY_DEPTH_STENCIL)
// To be fixed in <https://github.com/gfx-rs/wgpu/issues/5231>.
.expect_fail(wgpu_test::FailureCase {
backends: Some(wgpu::Backends::VULKAN),
reasons: vec![wgpu_test::FailureReason::validation_error()
.with_message("WRITE_AFTER_WRITE hazard detected.")],
behavior: wgpu_test::FailureBehavior::AssertFailure,
..Default::default()
}),
.downlevel_flags(wgpu::DownlevelFlags::READ_ONLY_DEPTH_STENCIL),
comparisons: &[wgpu_test::ComparisonType::Mean(0.018)], // Bounded by Apple A9
_phantom: std::marker::PhantomData::<Example>,
};
34 changes: 9 additions & 25 deletions tests/tests/wgpu-gpu/regression/issue_5231_9343.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,35 @@ pub fn all_tests(vec: &mut Vec<GpuTestInitializer>) {
///
/// #9343 is a crash on dx12 when using a texture created without `TEXTURE_BINDING` as a
/// read-only depth attachment. With read-only depth, wgpu-core transitioned the depth
/// texture to `DEPTH_STENCIL_READ | RESOURCE`. This is normally a valid usage combination,
/// texture to `DEPTH_READ | RESOURCE`. This is normally a valid usage combination,
/// but when the texture view does not have `TEXTURE_BINDING` usage, the `RESOURCE` usage
/// is not allowed, and dx12 raises an error.
#[gpu_test]
static READ_ONLY_DEPTH_WITHOUT_TEXTURE_BINDING: GpuTestConfiguration = GpuTestConfiguration::new()
.parameters(
TestParameters::default()
.downlevel_flags(DownlevelFlags::READ_ONLY_DEPTH_STENCIL)
.enable_noop()
// <https://github.com/gfx-rs/wgpu/issues/5231>
.expect_fail(wgpu_test::FailureCase {
backends: Some(wgpu::Backends::VULKAN),
reasons: vec![wgpu_test::FailureReason::validation_error()
.with_message("WRITE_AFTER_WRITE hazard detected.")],
behavior: wgpu_test::FailureBehavior::AssertFailure,
..Default::default()
}),
.enable_noop(),
)
.run_sync(|ctx| read_only_depth_test(&ctx, false));

/// Test that a read-only depth attachment can simultaneously be sampled as a texture
/// binding within the same render pass. This exercises the `DEPTH_STENCIL_READ | RESOURCE`
/// binding within the same render pass. This exercises the `DEPTH_READ | RESOURCE`
/// usage combination that wgpu-core sets up in render.rs.
#[gpu_test]
static READ_ONLY_DEPTH_WITH_SAMPLED_BINDING: GpuTestConfiguration = GpuTestConfiguration::new()
.parameters(
TestParameters::default()
.downlevel_flags(DownlevelFlags::READ_ONLY_DEPTH_STENCIL)
.enable_noop()
// <https://github.com/gfx-rs/wgpu/issues/5231>
.expect_fail(wgpu_test::FailureCase {
backends: Some(wgpu::Backends::VULKAN),
reasons: vec![wgpu_test::FailureReason::validation_error()
.with_message("WRITE_AFTER_WRITE hazard detected.")],
behavior: wgpu_test::FailureBehavior::AssertFailure,
..Default::default()
}),
.enable_noop(),
)
.run_sync(|ctx| read_only_depth_test(&ctx, true));

/// Common implementation for read-only depth attachment tests.
///
/// When `sample_depth` is true, the depth texture is created with `TEXTURE_BINDING` and
/// the second (read-only) pass also binds it as a `texture_depth_2d` for sampling. This
/// exercises the `DEPTH_STENCIL_READ | RESOURCE` usage combination.
/// exercises the `DEPTH_READ | RESOURCE` usage combination.
///
/// When `sample_depth` is false, the depth texture has only `RENDER_ATTACHMENT` usage and
/// the second pass only uses it as a read-only depth attachment.
Expand Down Expand Up @@ -254,7 +238,7 @@ fn read_only_depth_test(ctx: &TestingContext, sample_depth: bool) {
.device
.create_command_encoder(&CommandEncoderDescriptor::default());

// First pass: writable depth, puts the depth texture in `DEPTH_STENCIL_WRITE` state.
// First pass: writable depth, puts the depth texture in `DEPTH_WRITE` state.
{
let mut rpass = encoder.begin_render_pass(&RenderPassDescriptor {
label: Some("depth write pass"),
Expand Down Expand Up @@ -283,9 +267,9 @@ fn read_only_depth_test(ctx: &TestingContext, sample_depth: bool) {
rpass.draw(0..1, 0..1);
}

// Second pass: read-only depth attachment, triggers the `DEPTH_STENCIL_WRITE` ->
// `DEPTH_STENCIL_READ` transition. When `sample_depth` is true, the depth texture
// is also bound as a sampled texture, exercising `DEPTH_STENCIL_READ | RESOURCE`.
// Second pass: read-only depth attachment, triggers the `DEPTH_WRITE` ->
// `DEPTH_READ` transition. When `sample_depth` is true, the depth texture
// is also bound as a sampled texture, exercising `DEPTH_READ | RESOURCE`.
{
let mut rpass = encoder.begin_render_pass(&RenderPassDescriptor {
label: Some("depth read pass"),
Expand Down
6 changes: 4 additions & 2 deletions wgpu-core/src/command/clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ pub(crate) fn clear_texture<T: TextureTrackerSetSingle>(
TextureClearMode::BufferCopy => wgt::TextureUses::COPY_DST,
TextureClearMode::RenderPass {
is_color: false, ..
} => wgt::TextureUses::DEPTH_STENCIL_WRITE,
} => wgt::TextureUses::DEPTH_WRITE | wgt::TextureUses::STENCIL_WRITE,
TextureClearMode::Surface { .. } | TextureClearMode::RenderPass { is_color: true, .. } => {
wgt::TextureUses::COLOR_TARGET
}
Expand Down Expand Up @@ -542,11 +542,13 @@ fn clear_texture_via_render_passes(
mip_level,
depth_or_layer,
),
usage: wgt::TextureUses::DEPTH_STENCIL_WRITE,
usage: wgt::TextureUses::DEPTH_WRITE | wgt::TextureUses::STENCIL_WRITE,
},
depth_ops: hal::AttachmentOps::STORE | hal::AttachmentOps::LOAD_CLEAR,
stencil_ops: hal::AttachmentOps::STORE | hal::AttachmentOps::LOAD_CLEAR,
clear_value: (0.0, 0),
depth_read_only: false,
stencil_read_only: false,
}),
)
};
Expand Down
47 changes: 33 additions & 14 deletions wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1387,24 +1387,39 @@ impl RenderPassInfo {
is_depth_read_only = at.depth.is_readonly();
is_stencil_read_only = at.stencil.is_readonly();

let usage = if is_depth_read_only
&& is_stencil_read_only
&& device
let usage = 'b: {
if device
.downlevel
.flags
.contains(wgt::DownlevelFlags::READ_ONLY_DEPTH_STENCIL)
{
// If the texture supports TEXTURE_BINDING, it can be used as a shader
// resource and a read-only depth attachment simultaneously. But if it
// doesn't support TEXTURE_BINDING, don't attempt to transition it to a
// shader resource state, because DX12 will raise an error.
if view.desc.usage.contains(TextureUsages::TEXTURE_BINDING) {
wgt::TextureUses::DEPTH_STENCIL_READ | wgt::TextureUses::RESOURCE
{
let depth_stencil_uses = match (is_depth_read_only, is_stencil_read_only) {
(true, true) => {
wgt::TextureUses::DEPTH_READ | wgt::TextureUses::STENCIL_READ
}
(true, false) => {
wgt::TextureUses::DEPTH_READ | wgt::TextureUses::STENCIL_WRITE
}
(false, true) => {
wgt::TextureUses::DEPTH_WRITE | wgt::TextureUses::STENCIL_READ
}
(false, false) => {
break 'b wgt::TextureUses::DEPTH_WRITE
| wgt::TextureUses::STENCIL_WRITE;
}
};
// If the texture supports TEXTURE_BINDING, it can be used as a shader
// resource and a read-only depth attachment simultaneously. But if it
// doesn't support TEXTURE_BINDING, don't attempt to transition it to a
// shader resource state, because DX12 will raise an error.
if view.desc.usage.contains(TextureUsages::TEXTURE_BINDING) {
depth_stencil_uses | wgt::TextureUses::RESOURCE
} else {
depth_stencil_uses
}
} else {
wgt::TextureUses::DEPTH_STENCIL_READ
wgt::TextureUses::DEPTH_WRITE | wgt::TextureUses::STENCIL_WRITE
}
} else {
wgt::TextureUses::DEPTH_STENCIL_WRITE
};
render_attachments.push(view.to_render_attachment(usage));

Expand All @@ -1416,6 +1431,8 @@ impl RenderPassInfo {
depth_ops: at.depth.hal_ops(),
stencil_ops: at.stencil.hal_ops(),
clear_value: (at.depth.clear_value(), at.stencil.clear_value()),
depth_read_only: is_depth_read_only,
stencil_read_only: is_stencil_read_only,
});
}

Expand Down Expand Up @@ -1797,11 +1814,13 @@ impl RenderPassInfo {
depth_stencil_attachment: Some(hal::DepthStencilAttachment {
target: hal::Attachment {
view: view.try_raw(snatch_guard)?,
usage: wgt::TextureUses::DEPTH_STENCIL_WRITE,
usage: wgt::TextureUses::DEPTH_WRITE | wgt::TextureUses::STENCIL_WRITE,
},
depth_ops,
stencil_ops,
clear_value: (0.0, 0),
depth_read_only: false,
stencil_read_only: false,
}),
multiview_mask: self.multiview_mask,
timestamp_writes: None,
Expand Down
9 changes: 6 additions & 3 deletions wgpu-core/src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ pub fn map_texture_usage(
usage.contains(wgt::TextureUsages::RENDER_ATTACHMENT) && is_color,
);
u.set(
wgt::TextureUses::DEPTH_STENCIL_READ | wgt::TextureUses::DEPTH_STENCIL_WRITE,
wgt::TextureUses::DEPTH_WRITE
| wgt::TextureUses::DEPTH_READ
| wgt::TextureUses::STENCIL_WRITE
| wgt::TextureUses::STENCIL_READ,
usage.contains(wgt::TextureUsages::RENDER_ATTACHMENT) && !is_color,
);
u.set(
Expand All @@ -140,11 +143,11 @@ pub fn map_texture_usage_for_texture(
desc: &TextureDescriptor,
format_features: &TextureFormatFeatures,
) -> wgt::TextureUses {
// Enforce having COPY_DST/DEPTH_STENCIL_WRITE/COLOR_TARGET otherwise we
// Enforce having COPY_DST/DEPTH_WRITE/STENCIL_WRITE/COLOR_TARGET otherwise we
// wouldn't be able to initialize the texture.
map_texture_usage(desc.usage, desc.format.into(), format_features.flags)
| if desc.format.is_depth_stencil_format() {
wgt::TextureUses::DEPTH_STENCIL_WRITE
wgt::TextureUses::DEPTH_WRITE | wgt::TextureUses::STENCIL_WRITE
} else if desc.usage.contains(wgt::TextureUsages::COPY_DST) {
wgt::TextureUses::COPY_DST // (set already)
} else {
Expand Down
19 changes: 15 additions & 4 deletions wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1883,11 +1883,15 @@ impl Device {
.map_err(|e| self.handle_hal_error_with_nonfatal_oom(e))?;

let clear_mode = if hal_usage
.intersects(wgt::TextureUses::DEPTH_STENCIL_WRITE | wgt::TextureUses::COLOR_TARGET)
&& desc.dimension == wgt::TextureDimension::D2
.contains(wgt::TextureUses::DEPTH_WRITE | wgt::TextureUses::STENCIL_WRITE)
|| hal_usage.contains(wgt::TextureUses::COLOR_TARGET)
&& desc.dimension == wgt::TextureDimension::D2
{
let (is_color, usage) = if desc.format.is_depth_stencil_format() {
(false, wgt::TextureUses::DEPTH_STENCIL_WRITE)
(
false,
wgt::TextureUses::DEPTH_WRITE | wgt::TextureUses::STENCIL_WRITE,
)
} else {
(true, wgt::TextureUses::COLOR_TARGET)
};
Expand Down Expand Up @@ -4262,7 +4266,14 @@ impl Device {
});
}
view.check_usage(wgt::TextureUsages::TEXTURE_BINDING)?;
Ok(wgt::TextureUses::RESOURCE)
let depth_stencil_uses = if view.desc.aspects() == hal::FormatAspects::DEPTH {
wgt::TextureUses::DEPTH_SAMPLED
} else if view.desc.aspects() == hal::FormatAspects::STENCIL {
wgt::TextureUses::STENCIL_SAMPLED
} else {
wgt::TextureUses::empty()
};
Ok(wgt::TextureUses::RESOURCE | depth_stencil_uses)
}
wgt::BindingType::StorageTexture {
access,
Expand Down
Loading
Loading