From 89bc7cff16cd849338f1cfef50e87d0951fd75bd Mon Sep 17 00:00:00 2001 From: "lixiaopeng.jetspark" Date: Fri, 24 Nov 2023 13:33:26 +0800 Subject: [PATCH] fix rebase --- wgpu-core/src/device/resource.rs | 47 ++++++++++++++++++++------------ wgpu-hal/src/dx12/device.rs | 6 +++- wgpu-hal/src/dx12/view.rs | 8 +++--- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index 9057c901da..6d2e140a8b 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -804,24 +804,35 @@ impl Device { let mut clear_views = SmallVec::new(); for mip_level in 0..desc.mip_level_count { for array_layer in 0..desc.size.depth_or_array_layers { - let desc = hal::TextureViewDescriptor { - label: clear_label, - format: desc.format, - dimension, - usage, - range: wgt::ImageSubresourceRange { - aspect: wgt::TextureAspect::All, - base_mip_level: mip_level, - mip_level_count: Some(1), - base_array_layer: array_layer, - array_layer_count: Some(1), - }, - plane: None, - }; - clear_views.push(Some( - unsafe { self.raw().create_texture_view(&raw_texture, &desc) } - .map_err(DeviceError::from)?, - )); + macro_rules! push_clear_view { + ($format:expr, $plane:expr) => { + let desc = hal::TextureViewDescriptor { + label: clear_label, + format: $format, + dimension, + usage, + range: wgt::ImageSubresourceRange { + aspect: wgt::TextureAspect::All, + base_mip_level: mip_level, + mip_level_count: Some(1), + base_array_layer: array_layer, + array_layer_count: Some(1), + }, + plane: $plane, + }; + clear_views.push(Some( + unsafe { self.raw().create_texture_view(&raw_texture, &desc) } + .map_err(DeviceError::from)?, + )); + }; + } + + if desc.format == wgt::TextureFormat::NV12 { + push_clear_view!(wgt::TextureFormat::R8Unorm, Some(0)); + push_clear_view!(wgt::TextureFormat::Rg8Unorm, Some(1)); + } else { + push_clear_view!(desc.format, None); + } } } resource::TextureClearMode::RenderPass { diff --git a/wgpu-hal/src/dx12/device.rs b/wgpu-hal/src/dx12/device.rs index 649fdb4f8b..90af93661e 100644 --- a/wgpu-hal/src/dx12/device.rs +++ b/wgpu-hal/src/dx12/device.rs @@ -467,7 +467,11 @@ impl crate::Device for super::Device { aspects: view_desc.aspects, target_base: ( texture.resource.clone(), - texture.calc_subresource(desc.range.base_mip_level, desc.range.base_array_layer, 0), + texture.calc_subresource( + desc.range.base_mip_level, + desc.range.base_array_layer, + desc.plane.unwrap_or(0), + ), ), handle_srv: if desc.usage.intersects(crate::TextureUses::RESOURCE) { let raw_desc = unsafe { view_desc.to_srv() }; diff --git a/wgpu-hal/src/dx12/view.rs b/wgpu-hal/src/dx12/view.rs index 630fc149d6..9a597e464c 100644 --- a/wgpu-hal/src/dx12/view.rs +++ b/wgpu-hal/src/dx12/view.rs @@ -181,7 +181,7 @@ impl ViewDescriptor { unsafe { *desc.u.Texture2D_mut() = d3d12_ty::D3D12_TEX2D_UAV { MipSlice: self.mip_level_base, - PlaneSlice: 0, + PlaneSlice: self.plane, } } } @@ -192,7 +192,7 @@ impl ViewDescriptor { MipSlice: self.mip_level_base, FirstArraySlice: self.array_layer_base, ArraySize: self.array_layer_count, - PlaneSlice: 0, + PlaneSlice: self.plane, } } } @@ -252,7 +252,7 @@ impl ViewDescriptor { unsafe { *desc.u.Texture2D_mut() = d3d12_ty::D3D12_TEX2D_RTV { MipSlice: self.mip_level_base, - PlaneSlice: 0, + PlaneSlice: self.plane, } } } @@ -274,7 +274,7 @@ impl ViewDescriptor { MipSlice: self.mip_level_base, FirstArraySlice: self.array_layer_base, ArraySize: self.array_layer_count, - PlaneSlice: 0, + PlaneSlice: self.plane, } } }