Skip to content

Commit

Permalink
Merge #1954
Browse files Browse the repository at this point in the history
1954: [dx12] layer clears r=msiglreith a=kvark

Fixes #1943, works around #1945
PR checklist:
- [ ] `make` succeeds (on *nix)
- [x] `make reftests` succeeds
- [x] tested examples with the following backends: dx12

I found out that we didn't update the raw bit flag values in reftests after one of the recent changes... Unfortunate, but this is more of a bitflags issue than ours, and I'm pushing upstream to resolve this in bitflags/bitflags#147


Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
  • Loading branch information
bors[bot] and kvark committed Apr 19, 2018
2 parents 58b16b2 + a39a275 commit 8a7fe98
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 45 deletions.
2 changes: 1 addition & 1 deletion reftests/scenes/basic.ron
Expand Up @@ -4,7 +4,7 @@
kind: D2(1, 1, 1, 1),
num_levels: 1,
format: Rgba8Unorm,
usage: (bits: 0x24), //COLOR_ATTACHMENT | SAMPLED (temporary for GL)
usage: (bits: 0x14), //COLOR_ATTACHMENT | SAMPLED (temporary for GL)
),
"pass": RenderPass(
attachments: {
Expand Down
2 changes: 1 addition & 1 deletion reftests/scenes/compute.ron
Expand Up @@ -2,7 +2,7 @@
resources: {
"buffer.output": Buffer(
size: 4,
usage: (bits: 0x8), //STORAGE
usage: (bits: 0x20), //STORAGE
),
"desc-layout": DescriptorSetLayout(
bindings: [
Expand Down
27 changes: 16 additions & 11 deletions src/backend/dx12/src/command.rs
Expand Up @@ -1027,9 +1027,12 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
range: image::SubresourceRange,
value: com::ClearColorRaw,
) {
assert_eq!(range, image.to_subresource_range(Aspects::COLOR));
let rtv = image.clear_cv.unwrap();
self.clear_render_target_view(rtv, value, &[]);
assert_eq!(range.aspects, Aspects::COLOR);
assert_eq!(range.levels, 0 .. 1); //TODO
for layer in range.layers {
let rtv = image.clear_cv[layer as usize];
self.clear_render_target_view(rtv, value, &[]);
}
}

fn clear_depth_stencil_image_raw(
Expand All @@ -1040,14 +1043,16 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
value: com::ClearDepthStencilRaw,
) {
assert!((Aspects::DEPTH | Aspects::STENCIL).contains(range.aspects));
assert_eq!(range, image.to_subresource_range(range.aspects));
if range.aspects.contains(Aspects::DEPTH) {
let dsv = image.clear_dv.unwrap();
self.clear_depth_stencil_view(dsv, Some(value.depth), None, &[]);
}
if range.aspects.contains(Aspects::STENCIL) {
let dsv = image.clear_sv.unwrap();
self.clear_depth_stencil_view(dsv, None, Some(value.stencil as _), &[]);
assert_eq!(range.levels, 0 .. 1); //TODO
for layer in range.layers {
if range.aspects.contains(Aspects::DEPTH) {
let dsv = image.clear_dv[layer as usize];
self.clear_depth_stencil_view(dsv, Some(value.depth), None, &[]);
}
if range.aspects.contains(Aspects::STENCIL) {
let dsv = image.clear_sv[layer as usize];
self.clear_depth_stencil_view(dsv, None, Some(value.stencil as _), &[]);
}
}
}

Expand Down
78 changes: 50 additions & 28 deletions src/backend/dx12/src/device.rs
Expand Up @@ -1778,9 +1778,9 @@ impl d::Device<B> for Device {
},
format: image.desc.Format,
range: image::SubresourceRange {
aspects: Aspects::COLOR,
levels: 0 .. 1, //TODO?
layers: 0 .. num_layers,
aspects: Aspects::empty(),
levels: 0 .. 0,
layers: 0 .. 0,
},
};

Expand All @@ -1798,35 +1798,57 @@ impl d::Device<B> for Device {
block_dim: image.block_dim,
num_levels: image.num_levels,
clear_cv: if image.aspects.contains(Aspects::COLOR) && image.usage.contains(Usage::COLOR_ATTACHMENT) {
Some(self.view_image_as_render_target(info.clone()).unwrap())
(0 .. num_layers)
.map(|layer| {
self.view_image_as_render_target(
ViewInfo {
range: image::SubresourceRange {
aspects: Aspects::COLOR,
levels: 0 .. 1, //TODO?
layers: layer .. layer + 1,
},
.. info.clone()
}).unwrap()
})
.collect()
} else {
None
Vec::new()
},
clear_dv: if image.aspects.contains(Aspects::DEPTH) && image.usage.contains(Usage::DEPTH_STENCIL_ATTACHMENT) {
Some(self.view_image_as_depth_stencil(ViewInfo {
format: image.dsv_format,
range: image::SubresourceRange {
aspects: Aspects::DEPTH,
levels: 0 .. 1, //TODO?
layers: 0 .. num_layers,
},
.. info.clone()
}).unwrap())
(0 .. num_layers)
.map(|layer| {
self.view_image_as_depth_stencil(
ViewInfo {
format: image.dsv_format,
range: image::SubresourceRange {
aspects: Aspects::DEPTH,
levels: 0 .. 1, //TODO?
layers: layer .. layer + 1,
},
.. info.clone()
}).unwrap()
})
.collect()
} else {
None
Vec::new()
},
clear_sv: if image.aspects.contains(Aspects::STENCIL) && image.usage.contains(Usage::DEPTH_STENCIL_ATTACHMENT) {
Some(self.view_image_as_depth_stencil(ViewInfo {
format: image.dsv_format,
range: image::SubresourceRange {
aspects: Aspects::STENCIL,
levels: 0 .. 1, //TODO?
layers: 0 .. num_layers,
},
.. info.clone()
}).unwrap())
(0 .. num_layers)
.map(|layer| {
self.view_image_as_depth_stencil(
ViewInfo {
format: image.dsv_format,
range: image::SubresourceRange {
aspects: Aspects::STENCIL,
levels: 0 .. 1, //TODO?
layers: layer .. layer + 1,
},
.. info.clone()
}).unwrap()
})
.collect()
} else {
None
Vec::new()
},
})
}
Expand Down Expand Up @@ -2602,9 +2624,9 @@ impl d::Device<B> for Device {
bytes_per_block,
block_dim,
num_levels: 1,
clear_cv: Some(rtv_handle),
clear_dv: None,
clear_sv: None,
clear_cv: vec![rtv_handle],
clear_dv: Vec::new(),
clear_sv: Vec::new(),
}
}).collect();

Expand Down
2 changes: 1 addition & 1 deletion src/backend/dx12/src/lib.rs
Expand Up @@ -494,7 +494,7 @@ impl Device {
present_queue: ComPtr<d3d12::ID3D12CommandQueue>,
) -> Self {
// Allocate descriptor heaps
let max_rtvs = 256; // TODO
let max_rtvs = 512; // TODO
let rtv_pool = native::DescriptorCpuPool {
heap: Self::create_descriptor_heap_impl(
&mut device,
Expand Down
6 changes: 3 additions & 3 deletions src/backend/dx12/src/native.rs
Expand Up @@ -159,11 +159,11 @@ pub struct Image {
pub(crate) block_dim: (u8, u8),
pub(crate) num_levels: image::Level,
#[derivative(Debug="ignore")]
pub(crate) clear_cv: Option<d3d12::D3D12_CPU_DESCRIPTOR_HANDLE>,
pub(crate) clear_cv: Vec<d3d12::D3D12_CPU_DESCRIPTOR_HANDLE>,
#[derivative(Debug="ignore")]
pub(crate) clear_dv: Option<d3d12::D3D12_CPU_DESCRIPTOR_HANDLE>,
pub(crate) clear_dv: Vec<d3d12::D3D12_CPU_DESCRIPTOR_HANDLE>,
#[derivative(Debug="ignore")]
pub(crate) clear_sv: Option<d3d12::D3D12_CPU_DESCRIPTOR_HANDLE>,
pub(crate) clear_sv: Vec<d3d12::D3D12_CPU_DESCRIPTOR_HANDLE>,
}
unsafe impl Send for Image { }
unsafe impl Sync for Image { }
Expand Down

0 comments on commit 8a7fe98

Please sign in to comment.