Skip to content

Commit 50841c3

Browse files
ErichDonGublerteoxoy
authored andcommitted
refactor(dx12): merge PipelineLayoutShared::special_constants_{root_index,cmd_signatures} into new struct
1 parent 03a396d commit 50841c3

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

wgpu-hal/src/dx12/command.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,13 @@ impl super::CommandEncoder {
107107
);
108108
}
109109
}
110-
if let Some(root_index) = self.pass.layout.special_constants_root_index {
110+
if let Some(root_index) = self
111+
.pass
112+
.layout
113+
.special_constants
114+
.as_ref()
115+
.map(|sc| sc.root_index)
116+
{
111117
let needs_update = match self.pass.root_elements[root_index as usize] {
112118
super::RootElement::SpecialConstantBuffer {
113119
first_vertex: other_vertex,
@@ -130,7 +136,13 @@ impl super::CommandEncoder {
130136
}
131137

132138
fn prepare_dispatch(&mut self, count: [u32; 3]) {
133-
if let Some(root_index) = self.pass.layout.special_constants_root_index {
139+
if let Some(root_index) = self
140+
.pass
141+
.layout
142+
.special_constants
143+
.as_ref()
144+
.map(|sc| sc.root_index)
145+
{
134146
let needs_update = match self.pass.root_elements[root_index as usize] {
135147
super::RootElement::SpecialConstantBuffer {
136148
first_vertex,
@@ -230,7 +242,7 @@ impl super::CommandEncoder {
230242
}
231243

232244
fn reset_signature(&mut self, layout: &super::PipelineLayoutShared) {
233-
if let Some(root_index) = layout.special_constants_root_index {
245+
if let Some(root_index) = layout.special_constants.as_ref().map(|sc| sc.root_index) {
234246
self.pass.root_elements[root_index as usize] =
235247
super::RootElement::SpecialConstantBuffer {
236248
first_vertex: 0,
@@ -1214,8 +1226,9 @@ impl crate::CommandEncoder for super::CommandEncoder {
12141226
let cmd_signature = &self
12151227
.pass
12161228
.layout
1217-
.special_constants_cmd_signatures
1229+
.special_constants
12181230
.as_ref()
1231+
.map(|sc| &sc.cmd_signatures)
12191232
.unwrap_or_else(|| &self.shared.cmd_signatures)
12201233
.dispatch;
12211234
unsafe {

wgpu-hal/src/dx12/device.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,9 +1123,7 @@ impl crate::Device for super::Device {
11231123
}
11241124
.into_device_result("Root signature creation")?;
11251125

1126-
let special_constants_cmd_signatures = if let Some(root_index) =
1127-
special_constants_root_index
1128-
{
1126+
let special_constants = if let Some(root_index) = special_constants_root_index {
11291127
let constant_indirect_argument_desc = Direct3D12::D3D12_INDIRECT_ARGUMENT_DESC {
11301128
Type: Direct3D12::D3D12_INDIRECT_ARGUMENT_TYPE_CONSTANT,
11311129
Anonymous: Direct3D12::D3D12_INDIRECT_ARGUMENT_DESC_0 {
@@ -1153,7 +1151,7 @@ impl crate::Device for super::Device {
11531151
};
11541152
size_of_val(&first_vertex) + size_of_val(&first_instance) + size_of_val(&other)
11551153
};
1156-
Some(super::CommandSignatures {
1154+
let cmd_signatures = super::CommandSignatures {
11571155
draw: Self::create_command_signature(
11581156
&self.raw,
11591157
Some(&raw),
@@ -1193,6 +1191,11 @@ impl crate::Device for super::Device {
11931191
],
11941192
0,
11951193
)?,
1194+
};
1195+
1196+
Some(super::PipelineLayoutSpecialConstants {
1197+
root_index,
1198+
cmd_signatures,
11961199
})
11971200
} else {
11981201
None
@@ -1209,8 +1212,7 @@ impl crate::Device for super::Device {
12091212
shared: super::PipelineLayoutShared {
12101213
signature: Some(raw),
12111214
total_root_elements: parameters.len() as super::RootIndex,
1212-
special_constants_root_index,
1213-
special_constants_cmd_signatures,
1215+
special_constants,
12141216
root_constant_info,
12151217
},
12161218
bind_group_infos,

wgpu-hal/src/dx12/mod.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,7 @@ impl PassState {
685685
layout: PipelineLayoutShared {
686686
signature: None,
687687
total_root_elements: 0,
688-
special_constants_root_index: None,
689-
special_constants_cmd_signatures: None,
688+
special_constants: None,
690689
root_constant_info: None,
691690
},
692691
root_elements: [RootElement::Empty; MAX_ROOT_ELEMENTS],
@@ -923,14 +922,22 @@ struct RootConstantInfo {
923922
struct PipelineLayoutShared {
924923
signature: Option<Direct3D12::ID3D12RootSignature>,
925924
total_root_elements: RootIndex,
926-
special_constants_root_index: Option<RootIndex>,
927-
special_constants_cmd_signatures: Option<CommandSignatures>,
925+
special_constants: Option<PipelineLayoutSpecialConstants>,
928926
root_constant_info: Option<RootConstantInfo>,
929927
}
930928

931929
unsafe impl Send for PipelineLayoutShared {}
932930
unsafe impl Sync for PipelineLayoutShared {}
933931

932+
#[derive(Debug, Clone)]
933+
struct PipelineLayoutSpecialConstants {
934+
root_index: RootIndex,
935+
cmd_signatures: CommandSignatures,
936+
}
937+
938+
unsafe impl Send for PipelineLayoutSpecialConstants {}
939+
unsafe impl Sync for PipelineLayoutSpecialConstants {}
940+
934941
#[derive(Debug)]
935942
pub struct PipelineLayout {
936943
shared: PipelineLayoutShared,

0 commit comments

Comments
 (0)