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

metal: fix max_buffer max_texture and max_vertex_buffers limits #2978

Merged
merged 1 commit into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ the same every time it is rendered, we now warn if it is missing.

#### Metal
- Add the missing `msg_send![view, retain]` call within `from_view` by @jinleili in [#2976](https://github.com/gfx-rs/wgpu/pull/2976)
- Fix `max_buffer` `max_texture` and `max_vertex_buffers` limits by @jinleili in [#2978](https://github.com/gfx-rs/wgpu/pull/2978)

#### Vulkan
- Fix `astc_hdr` formats support by @jinleili in [#2971]](https://github.com/gfx-rs/wgpu/pull/2971)
Expand Down
30 changes: 13 additions & 17 deletions wgpu-hal/src/metal/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,21 +616,17 @@ impl super::PrivateCapabilities {
format_bgr10a2_all: Self::supports_any(device, BGR10A2_ALL),
format_bgr10a2_no_write: !Self::supports_any(device, BGR10A2_ALL),
max_buffers_per_stage: 31,
max_textures_per_stage: if os_is_mac {
128 // On macOS, minimun value is 128
} else if device.supports_feature_set(MTLFeatureSet::iOS_GPUFamily4_v1) {
max_vertex_buffers: 31,
max_textures_per_stage: if os_is_mac
|| (family_check && device.supports_family(MTLGPUFamily::Apple6))
{
128
} else if family_check && device.supports_family(MTLGPUFamily::Apple4) {
96
} else {
31
},
max_samplers_per_stage: if (family_check
&& device.supports_family(MTLGPUFamily::Apple6))
|| (os_is_mac && rw_texture_tier == MTLReadWriteTextureTier::Tier2)
{
1024
} else {
16
},
max_samplers_per_stage: 16,
buffer_alignment: if os_is_mac { 256 } else { 64 },
max_buffer_size: if version.at_least((10, 14), (12, 0)) {
// maxBufferLength available on macOS 10.14+ and iOS 12.0+
Expand Down Expand Up @@ -833,15 +829,15 @@ impl super::PrivateCapabilities {
.max_dynamic_uniform_buffers_per_pipeline_layout,
max_dynamic_storage_buffers_per_pipeline_layout: base
.max_dynamic_storage_buffers_per_pipeline_layout,
max_sampled_textures_per_shader_stage: base.max_sampled_textures_per_shader_stage,
max_sampled_textures_per_shader_stage: self.max_textures_per_stage,
max_samplers_per_shader_stage: self.max_samplers_per_stage,
max_storage_buffers_per_shader_stage: base.max_storage_buffers_per_shader_stage,
max_storage_textures_per_shader_stage: base.max_storage_textures_per_shader_stage,
max_uniform_buffers_per_shader_stage: 12,
max_storage_buffers_per_shader_stage: self.max_buffers_per_stage,
max_storage_textures_per_shader_stage: self.max_textures_per_stage,
max_uniform_buffers_per_shader_stage: self.max_buffers_per_stage,
max_uniform_buffer_binding_size: self.max_buffer_size.min(!0u32 as u64) as u32,
max_storage_buffer_binding_size: self.max_buffer_size.min(!0u32 as u64) as u32,
max_vertex_buffers: base.max_vertex_buffers,
max_vertex_attributes: base.max_vertex_attributes,
max_vertex_buffers: self.max_vertex_buffers,
max_vertex_attributes: 31,
max_vertex_buffer_array_stride: base.max_vertex_buffer_array_stride,
max_push_constant_size: 0x1000,
min_uniform_buffer_offset_alignment: self.buffer_alignment as u32,
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/metal/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
index: u32,
binding: crate::BufferBinding<'a, super::Api>,
) {
let buffer_index = self.shared.private_caps.max_buffers_per_stage as u64 - 1 - index as u64;
let buffer_index = self.shared.private_caps.max_vertex_buffers as u64 - 1 - index as u64;
let encoder = self.state.render.as_ref().unwrap();
encoder.set_vertex_buffer(buffer_index, Some(&binding.buffer.raw), binding.offset);
}
Expand Down
4 changes: 2 additions & 2 deletions wgpu-hal/src/metal/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ impl crate::Device<super::Api> for super::Device {
};

if desc.layout.total_counters.vs.buffers + (desc.vertex_buffers.len() as u32)
> self.shared.private_caps.max_buffers_per_stage
> self.shared.private_caps.max_vertex_buffers
{
let msg = format!(
"pipeline needs too many buffers in the vertex stage: {} vertex and {} layout",
Expand All @@ -907,7 +907,7 @@ impl crate::Device<super::Api> for super::Device {
let vertex_descriptor = mtl::VertexDescriptor::new();
for (i, vb) in desc.vertex_buffers.iter().enumerate() {
let buffer_index =
self.shared.private_caps.max_buffers_per_stage as u64 - 1 - i as u64;
self.shared.private_caps.max_vertex_buffers as u64 - 1 - i as u64;
let buffer_desc = vertex_descriptor.layouts().object_at(buffer_index).unwrap();

buffer_desc.set_stride(vb.array_stride);
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/metal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ struct PrivateCapabilities {
format_bgr10a2_all: bool,
format_bgr10a2_no_write: bool,
max_buffers_per_stage: ResourceIndex,
max_vertex_buffers: ResourceIndex,
max_textures_per_stage: ResourceIndex,
max_samplers_per_stage: ResourceIndex,
buffer_alignment: u64,
Expand Down