From 6948a01d8ce4c65f939f6f31ea3bc607f703ac93 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Wed, 3 Dec 2025 17:24:09 -0500 Subject: [PATCH] fix(core): remove `max_inter_stage_shader_components` validation --- wgpu-core/src/validation.rs | 101 ++++++++++++--------------------- wgpu-hal/src/dx12/adapter.rs | 1 - wgpu-hal/src/gles/adapter.rs | 13 ----- wgpu-hal/src/metal/adapter.rs | 1 - wgpu-hal/src/noop/mod.rs | 1 - wgpu-hal/src/vulkan/adapter.rs | 3 - wgpu-info/src/human.rs | 2 - wgpu-types/src/limits.rs | 10 ---- wgpu/src/backend/webgpu.rs | 1 - 9 files changed, 36 insertions(+), 97 deletions(-) diff --git a/wgpu-core/src/validation.rs b/wgpu-core/src/validation.rs index dcfccea75..aa60dcca1 100644 --- a/wgpu-core/src/validation.rs +++ b/wgpu-core/src/validation.rs @@ -102,16 +102,6 @@ impl fmt::Display for NumericDimension { } } -impl NumericDimension { - fn num_components(&self) -> u32 { - match *self { - Self::Scalar => 1, - Self::Vector(size) => size as u32, - Self::Matrix(w, h) => w as u32 * h as u32, - } - } -} - #[derive(Clone, Copy, Debug)] pub struct NumericType { dim: NumericDimension, @@ -302,8 +292,6 @@ pub enum StageError { per_dimension_limit: &'static str, total_limit: &'static str, }, - #[error("Shader uses {used} inter-stage components above the limit of {limit}")] - TooManyVaryings { used: u32, limit: u32 }, #[error("Unable to find entry point '{0}'")] MissingEntryPoint(String), #[error("Shader global {0:?} is not available in the pipeline layout")] @@ -426,7 +414,6 @@ impl WebGpuError for StageError { error, } => error, Self::InvalidWorkgroupSize { .. } - | Self::TooManyVaryings { .. } | Self::MissingEntryPoint(..) | Self::NoEntryPointFound | Self::MultipleEntryPointsFound @@ -1424,7 +1411,6 @@ impl Interface { } } - let mut inter_stage_components = 0; let mut this_stage_primitive_index = false; let mut has_draw_id = false; @@ -1437,38 +1423,36 @@ impl Interface { .get(&location) .ok_or(InputError::Missing) .and_then(|provided| { - let (compatible, num_components, per_primitive_correct) = - match shader_stage.to_naga() { - // For vertex attributes, there are defaults filled out - // by the driver if data is not provided. - naga::ShaderStage::Vertex => { - let is_compatible = - iv.ty.scalar.kind == provided.ty.scalar.kind; - // vertex inputs don't count towards inter-stage - (is_compatible, 0, !iv.per_primitive) + let (compatible, per_primitive_correct) = match shader_stage.to_naga() { + // For vertex attributes, there are defaults filled out + // by the driver if data is not provided. + naga::ShaderStage::Vertex => { + let is_compatible = + iv.ty.scalar.kind == provided.ty.scalar.kind; + // vertex inputs don't count towards inter-stage + (is_compatible, !iv.per_primitive) + } + naga::ShaderStage::Fragment => { + if iv.interpolation != provided.interpolation { + return Err(InputError::InterpolationMismatch( + provided.interpolation, + )); } - naga::ShaderStage::Fragment => { - if iv.interpolation != provided.interpolation { - return Err(InputError::InterpolationMismatch( - provided.interpolation, - )); - } - if iv.sampling != provided.sampling { - return Err(InputError::SamplingMismatch( - provided.sampling, - )); - } - ( - iv.ty.is_subtype_of(&provided.ty), - iv.ty.dim.num_components(), - iv.per_primitive == provided.per_primitive, - ) + if iv.sampling != provided.sampling { + return Err(InputError::SamplingMismatch( + provided.sampling, + )); } - // These can't have varying inputs - naga::ShaderStage::Compute - | naga::ShaderStage::Task - | naga::ShaderStage::Mesh => (false, 0, false), - }; + ( + iv.ty.is_subtype_of(&provided.ty), + iv.per_primitive == provided.per_primitive, + ) + } + // These can't have varying inputs + naga::ShaderStage::Compute + | naga::ShaderStage::Task + | naga::ShaderStage::Mesh => (false, false), + }; if !compatible { return Err(InputError::WrongType(provided.ty)); } else if !per_primitive_correct { @@ -1477,19 +1461,15 @@ impl Interface { shader: iv.per_primitive, }); } - Ok(num_components) + Ok(()) + }); + + if let Err(error) = result { + return Err(StageError::Input { + location, + var: iv.clone(), + error, }); - match result { - Ok(num_components) => { - inter_stage_components += num_components; - } - Err(error) => { - return Err(StageError::Input { - location, - var: iv.clone(), - error, - }) - } } } Varying::BuiltIn(naga::BuiltIn::PrimitiveIndex) => { @@ -1544,7 +1524,6 @@ impl Interface { }); } num_user_defined_outputs += 1; - inter_stage_components += iv.ty.dim.num_components() } Varying::BuiltIn(_) => {} }; @@ -1625,7 +1604,6 @@ impl Interface { }); } num_user_defined_inputs += 1; - inter_stage_components += iv.ty.dim.num_components() } Varying::BuiltIn(_) => {} }; @@ -1655,13 +1633,6 @@ impl Interface { _ => (), } - if inter_stage_components > self.limits.max_inter_stage_shader_components { - return Err(StageError::TooManyVaryings { - used: inter_stage_components, - limit: self.limits.max_inter_stage_shader_components, - }); - } - if let Some(ref mesh_info) = entry_point.mesh_info { if mesh_info.max_vertices > self.limits.max_mesh_output_vertices { return Err(StageError::TooManyMeshVertices { diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index 2a11ec99c..9d74e2e96 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -809,7 +809,6 @@ impl super::Adapter { min_uniform_buffer_offset_alignment: Direct3D12::D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT, min_storage_buffer_offset_alignment: 4, - max_inter_stage_shader_components: base.max_inter_stage_shader_components, max_inter_stage_shader_variables: base.max_inter_stage_shader_variables, max_color_attachments, max_color_attachment_bytes_per_sample, diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index ec8646a88..026dc08fc 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -755,19 +755,6 @@ impl super::Adapter { max_immediate_size: super::MAX_IMMEDIATES as u32 * 4, min_uniform_buffer_offset_alignment, min_storage_buffer_offset_alignment, - max_inter_stage_shader_components: { - // MAX_VARYING_COMPONENTS may return 0, because it is deprecated since OpenGL 3.2 core, - // and an OpenGL Context with the core profile and with forward-compatibility=true, - // will make deprecated constants unavailable. - let max_varying_components = - unsafe { gl.get_parameter_i32(glow::MAX_VARYING_COMPONENTS) } as u32; - if max_varying_components == 0 { - // default value for max_inter_stage_shader_components - 60 - } else { - max_varying_components - } - }, max_inter_stage_shader_variables: { // MAX_VARYING_COMPONENTS may return 0, because it is deprecated since OpenGL 3.2 core, // and an OpenGL Context with the core profile and with forward-compatibility=true, diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index eed40c8fe..fed8bab16 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -1194,7 +1194,6 @@ impl super::PrivateCapabilities { max_inter_stage_shader_variables: self.max_varying_components / 4, min_uniform_buffer_offset_alignment: self.buffer_alignment as u32, min_storage_buffer_offset_alignment: self.buffer_alignment as u32, - max_inter_stage_shader_components: self.max_varying_components, max_color_attachments: self.max_color_render_targets as u32, max_color_attachment_bytes_per_sample: self.max_color_attachment_bytes_per_sample as u32, diff --git a/wgpu-hal/src/noop/mod.rs b/wgpu-hal/src/noop/mod.rs index 277335a10..c8b59850c 100644 --- a/wgpu-hal/src/noop/mod.rs +++ b/wgpu-hal/src/noop/mod.rs @@ -185,7 +185,6 @@ pub const CAPABILITIES: crate::Capabilities = { max_inter_stage_shader_variables: ALLOC_MAX_U32, min_uniform_buffer_offset_alignment: 1, min_storage_buffer_offset_alignment: 1, - max_inter_stage_shader_components: ALLOC_MAX_U32, max_color_attachments: ALLOC_MAX_U32, max_color_attachment_bytes_per_sample: ALLOC_MAX_U32, max_compute_workgroup_storage_size: ALLOC_MAX_U32, diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index 83eda5ed2..796f660e3 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -1437,9 +1437,6 @@ impl PhysicalDeviceProperties { / 4, min_uniform_buffer_offset_alignment: limits.min_uniform_buffer_offset_alignment as u32, min_storage_buffer_offset_alignment: limits.min_storage_buffer_offset_alignment as u32, - max_inter_stage_shader_components: limits - .max_vertex_output_components - .min(limits.max_fragment_input_components), max_color_attachments: limits.max_color_attachments, max_color_attachment_bytes_per_sample, max_compute_workgroup_storage_size: limits.max_compute_shared_memory_size, diff --git a/wgpu-info/src/human.rs b/wgpu-info/src/human.rs index c66b2e215..48317f8d0 100644 --- a/wgpu-info/src/human.rs +++ b/wgpu-info/src/human.rs @@ -167,7 +167,6 @@ fn print_adapter(output: &mut impl io::Write, report: &AdapterReport, idx: usize max_inter_stage_shader_variables, min_uniform_buffer_offset_alignment, min_storage_buffer_offset_alignment, - max_inter_stage_shader_components, max_color_attachments, max_color_attachment_bytes_per_sample, max_compute_workgroup_storage_size, @@ -223,7 +222,6 @@ fn print_adapter(output: &mut impl io::Write, report: &AdapterReport, idx: usize writeln!(output, "\t\t Max Inter-stage Shader Variables: {max_inter_stage_shader_variables}")?; writeln!(output, "\t\t Min Uniform Buffer Offset Alignment: {min_uniform_buffer_offset_alignment}")?; writeln!(output, "\t\t Min Storage Buffer Offset Alignment: {min_storage_buffer_offset_alignment}")?; - writeln!(output, "\t\t Max Inter-Stage Shader Component: {max_inter_stage_shader_components}")?; writeln!(output, "\t\t Max Color Attachments: {max_color_attachments}")?; writeln!(output, "\t\t Max Color Attachment Bytes per sample: {max_color_attachment_bytes_per_sample}")?; writeln!(output, "\t\t Max Compute Workgroup Storage Size: {max_compute_workgroup_storage_size}")?; diff --git a/wgpu-types/src/limits.rs b/wgpu-types/src/limits.rs index fa348b08c..5fbc6c318 100644 --- a/wgpu-types/src/limits.rs +++ b/wgpu-types/src/limits.rs @@ -46,7 +46,6 @@ macro_rules! with_limits { $macro_name!(max_vertex_buffer_array_stride, Ordering::Less); $macro_name!(min_uniform_buffer_offset_alignment, Ordering::Greater); $macro_name!(min_storage_buffer_offset_alignment, Ordering::Greater); - $macro_name!(max_inter_stage_shader_components, Ordering::Less); $macro_name!(max_color_attachments, Ordering::Less); $macro_name!(max_color_attachment_bytes_per_sample, Ordering::Less); $macro_name!(max_compute_workgroup_storage_size, Ordering::Less); @@ -193,10 +192,6 @@ pub struct Limits { /// when creating a `BindGroup`, or for `set_bind_group` `dynamicOffsets`. /// Defaults to 256. Lower is "better". pub min_storage_buffer_offset_alignment: u32, - /// Maximum allowed number of components (scalars) of input or output locations for - /// inter-stage communication (vertex outputs to fragment inputs). Defaults to 60. - /// Higher is "better". - pub max_inter_stage_shader_components: u32, /// The maximum allowed number of color attachments. pub max_color_attachments: u32, /// The maximum number of bytes necessary to hold one sample (pixel or subpixel) of render @@ -333,7 +328,6 @@ impl Limits { /// max_inter_stage_shader_variables: 16, /// min_uniform_buffer_offset_alignment: 256, /// min_storage_buffer_offset_alignment: 256, - /// max_inter_stage_shader_components: 60, /// max_color_attachments: 8, /// max_color_attachment_bytes_per_sample: 32, /// max_compute_workgroup_storage_size: 16384, @@ -392,7 +386,6 @@ impl Limits { max_inter_stage_shader_variables: 16, min_uniform_buffer_offset_alignment: 256, min_storage_buffer_offset_alignment: 256, - max_inter_stage_shader_components: 60, max_color_attachments: 8, max_color_attachment_bytes_per_sample: 32, max_compute_workgroup_storage_size: 16384, @@ -455,7 +448,6 @@ impl Limits { /// min_uniform_buffer_offset_alignment: 256, /// min_storage_buffer_offset_alignment: 256, /// max_inter_stage_shader_variables: 15, - /// max_inter_stage_shader_components: 60, /// max_color_attachments: 4, /// max_color_attachment_bytes_per_sample: 32, /// max_compute_workgroup_storage_size: 16352, // * @@ -534,7 +526,6 @@ impl Limits { /// min_uniform_buffer_offset_alignment: 256, /// min_storage_buffer_offset_alignment: 256, /// max_inter_stage_shader_variables: 15, - /// max_inter_stage_shader_components: 31, /// max_color_attachments: 4, /// max_color_attachment_bytes_per_sample: 32, /// max_compute_workgroup_storage_size: 0, // + @@ -584,7 +575,6 @@ impl Limits { // Value supported by Intel Celeron B830 on Windows (OpenGL 3.1) max_inter_stage_shader_variables: 15, - max_inter_stage_shader_components: 31, // Most of the values should be the same as the downlevel defaults ..Self::downlevel_defaults() diff --git a/wgpu/src/backend/webgpu.rs b/wgpu/src/backend/webgpu.rs index 1c5da044f..8b1fb2b4a 100644 --- a/wgpu/src/backend/webgpu.rs +++ b/wgpu/src/backend/webgpu.rs @@ -821,7 +821,6 @@ fn map_wgt_limits(limits: webgpu_sys::GpuSupportedLimits) -> wgt::Limits { max_compute_workgroups_per_dimension: limits.max_compute_workgroups_per_dimension(), max_immediate_size: wgt::Limits::default().max_immediate_size, max_non_sampler_bindings: wgt::Limits::default().max_non_sampler_bindings, - max_inter_stage_shader_components: wgt::Limits::default().max_inter_stage_shader_components, max_task_mesh_workgroup_total_count: wgt::Limits::default() .max_task_mesh_workgroup_total_count,