Skip to content

Commit

Permalink
refactor(dx12): merge `PipelineLayoutShared::special_constants_{root_…
Browse files Browse the repository at this point in the history
…index,cmd_signatures}` into new `struct`
  • Loading branch information
ErichDonGubler committed Sep 19, 2024
1 parent f82c7ae commit e37496a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
21 changes: 17 additions & 4 deletions wgpu-hal/src/dx12/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 8 additions & 6 deletions wgpu-hal/src/dx12/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -1193,6 +1191,11 @@ impl crate::Device for super::Device {
],
0,
)?,
};

Some(super::PipelineLayoutSpecialConstants {
root_index,
cmd_signatures,
})
} else {
None
Expand All @@ -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,
Expand Down
15 changes: 11 additions & 4 deletions wgpu-hal/src/dx12/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -909,14 +908,22 @@ struct RootConstantInfo {
struct PipelineLayoutShared {
signature: Option<Direct3D12::ID3D12RootSignature>,
total_root_elements: RootIndex,
special_constants_root_index: Option<RootIndex>,
special_constants_cmd_signatures: Option<CommandSignatures>,
special_constants: Option<PipelineLayoutSpecialConstants>,
root_constant_info: Option<RootConstantInfo>,
}

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,
Expand Down

0 comments on commit e37496a

Please sign in to comment.