refactor(core): Tweak dual-source blending validation

This commit is contained in:
Andy Leiserson committed 2026-01-30 09:36:29 -08:00
1 parent 6b108091cc
commit 3bacd7bee5
3 files changed
+31 -37

No files matched your search

+5 -26
View File
@@ -3905,14 +3905,11 @@ impl Device {
let mut vertex_steps;
let mut vertex_buffers;
let mut total_attributes;
let mut shader_expects_dual_source_blending = false;
let mut pipeline_expects_dual_source_blending = false;
let mut dual_source_blending = false;
if let pipeline::RenderPipelineVertexProcessor::Vertex(ref vertex) = desc.vertex {
vertex_steps = Vec::with_capacity(vertex.buffers.len());
vertex_buffers = Vec::with_capacity(vertex.buffers.len());
total_attributes = 0;
shader_expects_dual_source_blending = false;
pipeline_expects_dual_source_blending = false;
for (i, vb_state) in vertex.buffers.iter().enumerate() {
// https://gpuweb.github.io/gpuweb/#abstract-opdef-validating-gpuvertexbufferlayout
@@ -4132,7 +4129,7 @@ impl Device {
if factor.ref_second_blend_source() {
self.require_features(wgt::Features::DUAL_SOURCE_BLENDING)?;
if i == 0 {
pipeline_expects_dual_source_blending = true;
dual_source_blending = true;
break;
} else {
return Err(pipeline::CreateRenderPipelineError
@@ -4387,7 +4384,9 @@ impl Device {
let fragment_entry_point_name;
let fragment_stage = match desc.fragment {
Some(ref fragment_state) => {
let stage = validation::ShaderStageForValidation::Fragment;
let stage = validation::ShaderStageForValidation::Fragment {
dual_source_blending,
};
let stage_bit = stage.to_wgt_bit();
let shader_module = &fragment_state.stage.module;
@@ -4422,15 +4421,6 @@ impl Device {
validated_stages |= stage_bit;
}
if let Some(ref interface) = shader_module.interface {
shader_expects_dual_source_blending = interface
.fragment_uses_dual_source_blending(&fragment_entry_point_name)
.map_err(|error| pipeline::CreateRenderPipelineError::Stage {
stage: stage_bit,
error,
})?;
}
Some(hal::ProgrammableStage {
module: shader_module.raw(),
entry_point: &fragment_entry_point_name,
@@ -4443,17 +4433,6 @@ impl Device {
None => None,
};
if !pipeline_expects_dual_source_blending && shader_expects_dual_source_blending {
return Err(
pipeline::CreateRenderPipelineError::ShaderExpectsPipelineToUseDualSourceBlending,
);
}
if pipeline_expects_dual_source_blending && !shader_expects_dual_source_blending {
return Err(
pipeline::CreateRenderPipelineError::PipelineExpectsShaderToUseDualSourceBlending,
);
}
if validated_stages.contains(wgt::ShaderStages::FRAGMENT) {
for (i, output) in io.varyings.iter() {
match color_targets.get(*i as usize) {
-6
View File
@@ -719,10 +719,6 @@ pub enum CreateRenderPipelineError {
factor: wgt::BlendFactor,
target: u32,
},
#[error("Pipeline expects the shader entry point to make use of dual-source blending.")]
PipelineExpectsShaderToUseDualSourceBlending,
#[error("Shader entry point expects the pipeline to make use of dual-source blending.")]
ShaderExpectsPipelineToUseDualSourceBlending,
#[error("{}", concat!(
"At least one color attachment or depth-stencil attachment was expected, ",
"but no render target for the pipeline was specified."
@@ -759,8 +755,6 @@ impl WebGpuError for CreateRenderPipelineError {
| Self::Stage { .. }
| Self::UnalignedShader { .. }
| Self::BlendFactorOnUnsupportedTarget { .. }
| Self::PipelineExpectsShaderToUseDualSourceBlending
| Self::ShaderExpectsPipelineToUseDualSourceBlending
| Self::NoTargetSpecified
| Self::PipelineConstants { .. }
| Self::VertexAttributeStrideTooLarge { .. } => return ErrorType::Validation,
+26 -5
View File
@@ -396,6 +396,10 @@ pub enum StageError {
MissingPrimitiveIndex,
#[error("DrawId cannot be used in the same pipeline as a task shader")]
DrawIdError,
#[error("Pipeline expects the shader entry point to make use of dual-source blending.")]
PipelineExpectsShaderToUseDualSourceBlending,
#[error("Shader entry point expects the pipeline to make use of dual-source blending.")]
ShaderExpectsPipelineToUseDualSourceBlending,
}
impl WebGpuError for StageError {
@@ -428,7 +432,9 @@ impl WebGpuError for StageError {
| Self::TaskPayloadMustMatch { .. }
| Self::InvalidPrimitiveIndex
| Self::MissingPrimitiveIndex
| Self::DrawIdError => return ErrorType::Validation,
| Self::DrawIdError
| Self::PipelineExpectsShaderToUseDualSourceBlending
| Self::ShaderExpectsPipelineToUseDualSourceBlending => return ErrorType::Validation,
};
e.webgpu_error_type()
}
@@ -1569,7 +1575,9 @@ impl Interface {
});
}
}
ShaderStageForValidation::Fragment => {
ShaderStageForValidation::Fragment {
dual_source_blending,
} => {
let mut max_fragment_shader_input_variables =
self.limits.max_inter_stage_shader_variables;
@@ -1637,6 +1645,17 @@ impl Interface {
});
}
}
if !dual_source_blending && entry_point.dual_source_blending {
return Err(
StageError::ShaderExpectsPipelineToUseDualSourceBlending,
);
}
if dual_source_blending && !entry_point.dual_source_blending {
return Err(
StageError::PipelineExpectsShaderToUseDualSourceBlending,
);
}
}
_ => (),
}
@@ -1759,7 +1778,9 @@ pub enum ShaderStageForValidation {
compare_function: Option<wgt::CompareFunction>,
},
Mesh,
Fragment,
Fragment {
dual_source_blending: bool,
},
Compute,
Task,
}
@@ -1769,7 +1790,7 @@ impl ShaderStageForValidation {
match self {
Self::Vertex { .. } => naga::ShaderStage::Vertex,
Self::Mesh => naga::ShaderStage::Mesh,
Self::Fragment => naga::ShaderStage::Fragment,
Self::Fragment { .. } => naga::ShaderStage::Fragment,
Self::Compute => naga::ShaderStage::Compute,
Self::Task => naga::ShaderStage::Task,
}
@@ -1778,7 +1799,7 @@ impl ShaderStageForValidation {
pub fn to_wgt_bit(&self) -> wgt::ShaderStages {
match self {
Self::Vertex { .. } => wgt::ShaderStages::VERTEX,
Self::Mesh { .. } => wgt::ShaderStages::MESH,
Self::Mesh => wgt::ShaderStages::MESH,
Self::Fragment { .. } => wgt::ShaderStages::FRAGMENT,
Self::Compute => wgt::ShaderStages::COMPUTE,
Self::Task => wgt::ShaderStages::TASK,