Skip to content

Commit

Permalink
[dx12] fix handling stencil only formats for clears & barriers
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf committed Dec 26, 2021
1 parent 6cd27f1 commit 80c8e0f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
16 changes: 9 additions & 7 deletions wgpu-hal/src/dx12/command.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use crate::FormatAspects;

use super::{conv, HResult as _};
use std::{mem, ops::Range, ptr};
use winapi::um::d3d12;
Expand Down Expand Up @@ -321,9 +319,10 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
// Only one barrier if it affects the whole image.
self.temp.barriers.push(raw);
} else {
let has_stencil = FormatAspects::from(barrier.texture.format)
.contains(FormatAspects::STENCIL);
let planes = if has_stencil {
// Selected texture aspect is relevant if the texture format has both depth _and_ stencil aspects.
let planes = if crate::FormatAspects::from(barrier.texture.format)
.contains(crate::FormatAspects::DEPTH | crate::FormatAspects::STENCIL)
{
match barrier.range.aspect {
wgt::TextureAspect::All => 0..2,
wgt::TextureAspect::StencilOnly => 1..2,
Expand Down Expand Up @@ -623,11 +622,14 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
}
if let Some(ref ds) = desc.depth_stencil_attachment {
let mut flags = native::ClearFlags::empty();
if !ds.depth_ops.contains(crate::AttachmentOps::LOAD) {
let aspects = ds.target.view.format_aspects;
if !ds.depth_ops.contains(crate::AttachmentOps::LOAD)
&& aspects.contains(crate::FormatAspects::STENCIL)
{
flags |= native::ClearFlags::DEPTH;
}
if !ds.stencil_ops.contains(crate::AttachmentOps::LOAD)
&& ds.target.view.has_stencil_aspect
&& aspects.contains(crate::FormatAspects::STENCIL)
{
flags |= native::ClearFlags::STENCIL;
}
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/dx12/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ impl crate::Device<super::Api> for super::Device {

Ok(super::TextureView {
raw_format: view_desc.format,
has_stencil_aspect: FormatAspects::from(desc.format).contains(FormatAspects::STENCIL),
format_aspects: FormatAspects::from(desc.format),
target_base: (
texture.resource,
texture.calc_subresource(desc.range.base_mip_level, desc.range.base_array_layer, 0),
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/dx12/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ impl Texture {
#[derive(Debug)]
pub struct TextureView {
raw_format: native::Format,
has_stencil_aspect: bool,
format_aspects: crate::FormatAspects, // May explicitly ignore stencil aspect of raw_format!
target_base: (native::Resource, u32),
handle_srv: Option<descriptor::Handle>,
handle_uav: Option<descriptor::Handle>,
Expand Down

0 comments on commit 80c8e0f

Please sign in to comment.