Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuring whether workgroup memory is zero initialised #5508

Merged
merged 19 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix handling in DirectX12
  • Loading branch information
DJMcNab committed Apr 10, 2024
commit 5707f1f2455cac85654772f28cdefabd61d03845
5 changes: 2 additions & 3 deletions wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2765,8 +2765,7 @@ impl<A: HalApi> Device<A> {
module: shader_module.raw(),
entry_point: final_entry_point_name.as_ref(),
constants: desc.stage.constants.as_ref(),
// Unused as in compute
zero_initialize_workgroup_memory: true,
zero_initialize_workgroup_memory: desc.stage.zero_initialize_workgroup_memory,
},
};

Expand Down Expand Up @@ -3182,7 +3181,7 @@ impl<A: HalApi> Device<A> {
module: vertex_shader_module.raw(),
entry_point: &vertex_entry_point_name,
constants: stage_desc.constants.as_ref(),
zero_initialize_workgroup_memory: true,
zero_initialize_workgroup_memory: stage_desc.zero_initialize_workgroup_memory,
}
};

Expand Down
30 changes: 11 additions & 19 deletions wgpu-hal/src/dx12/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ impl super::Device {
stage: &crate::ProgrammableStage<super::Api>,
layout: &super::PipelineLayout,
naga_stage: naga::ShaderStage,
zero_initialize_workgroup_memory: bool,
) -> Result<super::CompiledShader, crate::PipelineError> {
use naga::back::hlsl;

Expand All @@ -227,11 +226,13 @@ impl super::Device {
)
.map_err(|e| crate::PipelineError::Linkage(stage_bit, format!("HLSL: {e:?}")))?;

let mut cloned_naga_options;
let naga_options = if !zero_initialize_workgroup_memory {
cloned_naga_options = layout.naga_options.clone();
cloned_naga_options.zero_initialize_workgroup_memory = zero_initialize_workgroup_memory;
&cloned_naga_options
let needs_temp_options = stage.zero_initialize_workgroup_memory
!= layout.naga_options.zero_initialize_workgroup_memory;
let mut temp_options;
let naga_options = if needs_temp_options {
temp_options = layout.naga_options.clone();
temp_options.zero_initialize_workgroup_memory = stage.zero_initialize_workgroup_memory;
&temp_options
} else {
&layout.naga_options
};
Expand Down Expand Up @@ -1299,16 +1300,12 @@ impl crate::Device for super::Device {
let (topology_class, topology) = conv::map_topology(desc.primitive.topology);
let mut shader_stages = wgt::ShaderStages::VERTEX;

let blob_vs = self.load_shader(
&desc.vertex_stage,
desc.layout,
naga::ShaderStage::Vertex,
true,
)?;
let blob_vs =
self.load_shader(&desc.vertex_stage, desc.layout, naga::ShaderStage::Vertex)?;
let blob_fs = match desc.fragment_stage {
Some(ref stage) => {
shader_stages |= wgt::ShaderStages::FRAGMENT;
Some(self.load_shader(stage, desc.layout, naga::ShaderStage::Fragment, true)?)
Some(self.load_shader(stage, desc.layout, naga::ShaderStage::Fragment)?)
}
None => None,
};
Expand Down Expand Up @@ -1487,12 +1484,7 @@ impl crate::Device for super::Device {
&self,
desc: &crate::ComputePipelineDescriptor<super::Api>,
) -> Result<super::ComputePipeline, crate::PipelineError> {
let blob_cs = self.load_shader(
&desc.stage,
desc.layout,
naga::ShaderStage::Compute,
desc.compilation_options.zero_initialize_workgroup_memory,
)?;
let blob_cs = self.load_shader(&desc.stage, desc.layout, naga::ShaderStage::Compute)?;

let pair = {
profiling::scope!("ID3D12Device::CreateComputePipelineState");
Expand Down
Loading