From 5fdb663f457543b159d4fcd09dd9836ba6b41547 Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Tue, 25 Jun 2024 14:21:57 +0200 Subject: [PATCH] extract `set_push_constant` from `compute_pass_end_impl` --- wgpu-core/src/command/compute.rs | 80 +++++++++++++++++++------------- 1 file changed, 47 insertions(+), 33 deletions(-) diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index c80daf3236..c84b1d78d6 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -612,39 +612,15 @@ impl Global { values_offset, } => { let scope = PassErrorScope::SetPushConstant; - - let end_offset_bytes = offset + size_bytes; - let values_end_offset = - (values_offset + size_bytes / wgt::PUSH_CONSTANT_ALIGNMENT) as usize; - let data_slice = - &base.push_constant_data[(values_offset as usize)..values_end_offset]; - - let pipeline_layout = state - .binder - .pipeline_layout - .as_ref() - //TODO: don't error here, lazily update the push constants - .ok_or(ComputePassErrorInner::Dispatch( - DispatchError::MissingPipeline, - )) - .map_pass_err(scope)?; - - pipeline_layout - .validate_push_constant_ranges( - wgt::ShaderStages::COMPUTE, - offset, - end_offset_bytes, - ) - .map_pass_err(scope)?; - - unsafe { - raw.set_push_constants( - pipeline_layout.raw(), - wgt::ShaderStages::COMPUTE, - offset, - data_slice, - ); - } + set_push_constant( + &state, + raw, + &base.push_constant_data, + offset, + size_bytes, + values_offset, + ) + .map_pass_err(scope)?; } ArcComputeCommand::Dispatch(groups) => { let scope = PassErrorScope::Dispatch { @@ -989,6 +965,44 @@ fn set_pipeline( Ok(()) } +fn set_push_constant( + state: &State, + raw: &mut A::CommandEncoder, + push_constant_data: &[u32], + offset: u32, + size_bytes: u32, + values_offset: u32, +) -> Result<(), ComputePassErrorInner> { + let end_offset_bytes = offset + size_bytes; + let values_end_offset = (values_offset + size_bytes / wgt::PUSH_CONSTANT_ALIGNMENT) as usize; + let data_slice = &push_constant_data[(values_offset as usize)..values_end_offset]; + + let pipeline_layout = state + .binder + .pipeline_layout + .as_ref() + //TODO: don't error here, lazily update the push constants + .ok_or(ComputePassErrorInner::Dispatch( + DispatchError::MissingPipeline, + ))?; + + pipeline_layout.validate_push_constant_ranges( + wgt::ShaderStages::COMPUTE, + offset, + end_offset_bytes, + )?; + + unsafe { + raw.set_push_constants( + pipeline_layout.raw(), + wgt::ShaderStages::COMPUTE, + offset, + data_slice, + ); + } + Ok(()) +} + // Recording a compute pass. impl Global { pub fn compute_pass_set_bind_group(