diff --git a/wgpu-hal/src/dx12/command.rs b/wgpu-hal/src/dx12/command.rs index ea059636e3..09cf07775e 100644 --- a/wgpu-hal/src/dx12/command.rs +++ b/wgpu-hal/src/dx12/command.rs @@ -107,7 +107,13 @@ impl super::CommandEncoder { ); } } - if let Some(root_index) = self.pass.layout.special_constants_root_index { + if let Some(root_index) = self + .pass + .layout + .special_constants + .as_ref() + .map(|sc| sc.root_index) + { let needs_update = match self.pass.root_elements[root_index as usize] { super::RootElement::SpecialConstantBuffer { first_vertex: other_vertex, @@ -130,7 +136,13 @@ impl super::CommandEncoder { } fn prepare_dispatch(&mut self, count: [u32; 3]) { - if let Some(root_index) = self.pass.layout.special_constants_root_index { + if let Some(root_index) = self + .pass + .layout + .special_constants + .as_ref() + .map(|sc| sc.root_index) + { let needs_update = match self.pass.root_elements[root_index as usize] { super::RootElement::SpecialConstantBuffer { first_vertex, @@ -230,7 +242,7 @@ impl super::CommandEncoder { } fn reset_signature(&mut self, layout: &super::PipelineLayoutShared) { - if let Some(root_index) = layout.special_constants_root_index { + if let Some(root_index) = layout.special_constants.as_ref().map(|sc| sc.root_index) { self.pass.root_elements[root_index as usize] = super::RootElement::SpecialConstantBuffer { first_vertex: 0, @@ -1214,8 +1226,9 @@ impl crate::CommandEncoder for super::CommandEncoder { let cmd_signature = &self .pass .layout - .special_constants_cmd_signatures + .special_constants .as_ref() + .map(|sc| &sc.cmd_signatures) .unwrap_or_else(|| &self.shared.cmd_signatures) .dispatch; unsafe { diff --git a/wgpu-hal/src/dx12/device.rs b/wgpu-hal/src/dx12/device.rs index 8cd4c6374f..171e2a36be 100644 --- a/wgpu-hal/src/dx12/device.rs +++ b/wgpu-hal/src/dx12/device.rs @@ -1123,9 +1123,7 @@ impl crate::Device for super::Device { } .into_device_result("Root signature creation")?; - let special_constants_cmd_signatures = if let Some(root_index) = - special_constants_root_index - { + let special_constants = if let Some(root_index) = special_constants_root_index { let constant_indirect_argument_desc = Direct3D12::D3D12_INDIRECT_ARGUMENT_DESC { Type: Direct3D12::D3D12_INDIRECT_ARGUMENT_TYPE_CONSTANT, Anonymous: Direct3D12::D3D12_INDIRECT_ARGUMENT_DESC_0 { @@ -1153,7 +1151,7 @@ impl crate::Device for super::Device { }; size_of_val(&first_vertex) + size_of_val(&first_instance) + size_of_val(&other) }; - Some(super::CommandSignatures { + let cmd_signatures = super::CommandSignatures { draw: Self::create_command_signature( &self.raw, Some(&raw), @@ -1193,6 +1191,11 @@ impl crate::Device for super::Device { ], 0, )?, + }; + + Some(super::PipelineLayoutSpecialConstants { + root_index, + cmd_signatures, }) } else { None @@ -1209,8 +1212,7 @@ impl crate::Device for super::Device { shared: super::PipelineLayoutShared { signature: Some(raw), total_root_elements: parameters.len() as super::RootIndex, - special_constants_root_index, - special_constants_cmd_signatures, + special_constants, root_constant_info, }, bind_group_infos, diff --git a/wgpu-hal/src/dx12/mod.rs b/wgpu-hal/src/dx12/mod.rs index dc2faef32b..a91e4836d9 100644 --- a/wgpu-hal/src/dx12/mod.rs +++ b/wgpu-hal/src/dx12/mod.rs @@ -671,8 +671,7 @@ impl PassState { layout: PipelineLayoutShared { signature: None, total_root_elements: 0, - special_constants_root_index: None, - special_constants_cmd_signatures: None, + special_constants: None, root_constant_info: None, }, root_elements: [RootElement::Empty; MAX_ROOT_ELEMENTS], @@ -909,14 +908,22 @@ struct RootConstantInfo { struct PipelineLayoutShared { signature: Option, total_root_elements: RootIndex, - special_constants_root_index: Option, - special_constants_cmd_signatures: Option, + special_constants: Option, root_constant_info: Option, } unsafe impl Send for PipelineLayoutShared {} unsafe impl Sync for PipelineLayoutShared {} +#[derive(Debug, Clone)] +struct PipelineLayoutSpecialConstants { + root_index: RootIndex, + cmd_signatures: CommandSignatures, +} + +unsafe impl Send for PipelineLayoutSpecialConstants {} +unsafe impl Sync for PipelineLayoutSpecialConstants {} + #[derive(Debug)] pub struct PipelineLayout { shared: PipelineLayoutShared,