diff --git a/deno_webgpu/01_webgpu.js b/deno_webgpu/01_webgpu.js index 5f09cf3af..d0a1c704c 100644 --- a/deno_webgpu/01_webgpu.js +++ b/deno_webgpu/01_webgpu.js @@ -273,8 +273,7 @@ ObjectDefineProperty(GPUSupportedLimitsPrototype, privateCustomInspect, { "maxBufferSize", "maxVertexAttributes", "maxVertexBufferArrayStride", - // TODO(@crowlKats): support max_inter_stage_shader_variables - // "maxInterStageShaderVariables", + "maxInterStageShaderVariables", "maxColorAttachments", "maxColorAttachmentBytesPerSample", "maxComputeWorkgroupStorageSize", diff --git a/deno_webgpu/adapter.rs b/deno_webgpu/adapter.rs index 42d24d88c..d73fec74e 100644 --- a/deno_webgpu/adapter.rs +++ b/deno_webgpu/adapter.rs @@ -339,7 +339,10 @@ impl GPUSupportedLimits { self.0.max_vertex_buffer_array_stride } - // TODO(@crowlKats): support max_inter_stage_shader_variables + #[getter] + fn maxInterStageShaderVariables(&self) -> u32 { + self.0.max_inter_stage_shader_variables + } #[getter] fn maxColorAttachments(&self) -> u32 { diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index 36f30365b..2a11ec99c 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -810,6 +810,7 @@ impl super::Adapter { 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, // From: https://microsoft.github.io/DirectX-Specs/d3d/archive/D3D11_3_FunctionalSpec.htm#18.6.6%20Inter-Thread%20Data%20Sharing diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index 971819092..ec8646a88 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -768,6 +768,19 @@ impl super::Adapter { 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, + // 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_variables + 15 + } else { + max_varying_components / 4 + } + }, max_color_attachments, max_color_attachment_bytes_per_sample, max_compute_workgroup_storage_size: if supports_work_group_params { diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index 9ff5a04bd..eed40c8fe 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -1191,6 +1191,7 @@ impl super::PrivateCapabilities { max_vertex_attributes: 31, max_vertex_buffer_array_stride: base.max_vertex_buffer_array_stride, max_immediate_size: 0x1000, + 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, diff --git a/wgpu-hal/src/noop/mod.rs b/wgpu-hal/src/noop/mod.rs index 0efec2d98..277335a10 100644 --- a/wgpu-hal/src/noop/mod.rs +++ b/wgpu-hal/src/noop/mod.rs @@ -182,6 +182,7 @@ pub const CAPABILITIES: crate::Capabilities = { max_buffer_size: ALLOC_MAX_U32 as u64, max_vertex_attributes: ALLOC_MAX_U32, max_vertex_buffer_array_stride: ALLOC_MAX_U32, + 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, diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index 7ece600f5..83eda5ed2 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -1431,6 +1431,10 @@ impl PhysicalDeviceProperties { max_vertex_attributes: limits.max_vertex_input_attributes, max_vertex_buffer_array_stride: limits.max_vertex_input_binding_stride, max_immediate_size: limits.max_push_constants_size, + max_inter_stage_shader_variables: limits + .max_vertex_output_components + .min(limits.max_fragment_input_components) + / 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 diff --git a/wgpu-info/src/human.rs b/wgpu-info/src/human.rs index 5145d5b83..c66b2e215 100644 --- a/wgpu-info/src/human.rs +++ b/wgpu-info/src/human.rs @@ -164,6 +164,7 @@ fn print_adapter(output: &mut impl io::Write, report: &AdapterReport, idx: usize max_buffer_size, max_vertex_attributes, max_vertex_buffer_array_stride, + max_inter_stage_shader_variables, min_uniform_buffer_offset_alignment, min_storage_buffer_offset_alignment, max_inter_stage_shader_components, @@ -219,6 +220,7 @@ fn print_adapter(output: &mut impl io::Write, report: &AdapterReport, idx: usize writeln!(output, "\t\t Max Vertex Attributes: {max_vertex_attributes}")?; writeln!(output, "\t\t Max Vertex Buffer Array Stride: {max_vertex_buffer_array_stride}")?; writeln!(output, "\t\t Max Immediate data Size: {max_immediate_size}")?; + 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}")?; diff --git a/wgpu-types/src/limits.rs b/wgpu-types/src/limits.rs index b50b85b49..fa348b08c 100644 --- a/wgpu-types/src/limits.rs +++ b/wgpu-types/src/limits.rs @@ -180,6 +180,11 @@ pub struct Limits { /// Maximum value for `VertexBufferLayout::array_stride` when creating a `RenderPipeline`. /// Defaults to 2048. Higher is "better". pub max_vertex_buffer_array_stride: u32, + /// Maximum value for the number of input or output variables for inter-stage communication + /// (like vertex outputs or fragment inputs) `@location(…)`s (in WGSL parlance) + /// when creating a `RenderPipeline`. + /// Defaults to 16. Higher is "better". + pub max_inter_stage_shader_variables: u32, /// Required `BufferBindingType::Uniform` alignment for `BufferBinding::offset` /// when creating a `BindGroup`, or for `set_bind_group` `dynamicOffsets`. /// Defaults to 256. Lower is "better". @@ -325,6 +330,7 @@ impl Limits { /// max_buffer_size: 256 << 20, // (256 MiB) /// max_vertex_attributes: 16, /// max_vertex_buffer_array_stride: 2048, + /// max_inter_stage_shader_variables: 16, /// min_uniform_buffer_offset_alignment: 256, /// min_storage_buffer_offset_alignment: 256, /// max_inter_stage_shader_components: 60, @@ -383,6 +389,7 @@ impl Limits { max_buffer_size: 256 << 20, // (256 MiB) max_vertex_attributes: 16, max_vertex_buffer_array_stride: 2048, + max_inter_stage_shader_variables: 16, min_uniform_buffer_offset_alignment: 256, min_storage_buffer_offset_alignment: 256, max_inter_stage_shader_components: 60, @@ -447,6 +454,7 @@ impl Limits { /// max_immediate_size: 0, /// 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, @@ -487,6 +495,7 @@ impl Limits { max_texture_dimension_3d: 256, max_storage_buffers_per_shader_stage: 4, max_uniform_buffer_binding_size: 16 << 10, // (16 KiB) + max_inter_stage_shader_variables: 15, max_color_attachments: 4, // see: https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf#page=7 max_compute_workgroup_storage_size: 16352, @@ -524,6 +533,7 @@ impl Limits { /// max_immediate_size: 0, /// 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, @@ -573,6 +583,7 @@ impl Limits { max_compute_workgroups_per_dimension: 0, // 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 diff --git a/wgpu/src/backend/webgpu.rs b/wgpu/src/backend/webgpu.rs index f1abc97d3..1c5da044f 100644 --- a/wgpu/src/backend/webgpu.rs +++ b/wgpu/src/backend/webgpu.rs @@ -808,6 +808,7 @@ fn map_wgt_limits(limits: webgpu_sys::GpuSupportedLimits) -> wgt::Limits { max_buffer_size: limits.max_buffer_size() as u64, max_vertex_attributes: limits.max_vertex_attributes(), max_vertex_buffer_array_stride: limits.max_vertex_buffer_array_stride(), + max_inter_stage_shader_variables: limits.max_inter_stage_shader_variables(), min_uniform_buffer_offset_alignment: limits.min_uniform_buffer_offset_alignment(), min_storage_buffer_offset_alignment: limits.min_storage_buffer_offset_alignment(), max_color_attachments: limits.max_color_attachments(), @@ -895,7 +896,7 @@ fn map_js_sys_limits(limits: &wgt::Limits) -> js_sys::Object { (maxBufferSize, max_buffer_size), (maxVertexAttributes, max_vertex_attributes), (maxVertexBufferArrayStride, max_vertex_buffer_array_stride), - // TODO: (maxInterStageShaderVariables, max_inter_stage_shader_variables), + (maxInterStageShaderVariables, max_inter_stage_shader_variables), (maxColorAttachments, max_color_attachments), (maxColorAttachmentBytesPerSample, max_color_attachment_bytes_per_sample), (maxComputeWorkgroupStorageSize, max_compute_workgroup_storage_size),