Skip to content

Commit e237515

Browse files
committed
Support STORAGE_RESOURCE_BINDING_ARRAY on Metal
1 parent 6560412 commit e237515

File tree

6 files changed

+43
-6
lines changed

6 files changed

+43
-6
lines changed

Cargo.lock

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ which = "8"
200200
xshell = "0.2.2"
201201

202202
# Metal dependencies
203-
metal = "0.32"
203+
metal = { git = "https://github.com/msvbg/metal-rs", branch = "gpu_resource_id_for_buffer" }
204204
block = "0.1.6"
205205
core-graphics-types = "0.2"
206206
objc = "0.2.5"

naga/src/back/msl/writer.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7099,9 +7099,11 @@ template <typename A>
70997099
}
71007100
}
71017101
crate::ImageClass::Storage { .. } => {
7102-
return Err(Error::UnsupportedArrayOf(
7103-
"read-write textures".to_string(),
7104-
));
7102+
if options.lang_version < (3, 0) {
7103+
return Err(Error::UnsupportedArrayOf(
7104+
"read-write textures".to_string(),
7105+
));
7106+
}
71057107
}
71067108
crate::ImageClass::External => {
71077109
return Err(Error::UnsupportedArrayOf(

wgpu-hal/src/metal/adapter.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,13 @@ impl super::PrivateCapabilities {
985985
&& self.supports_arrays_of_textures
986986
&& self.argument_buffers as u64 >= MTLArgumentBuffersTier::Tier2 as u64,
987987
);
988+
features.set(
989+
F::STORAGE_RESOURCE_BINDING_ARRAY,
990+
self.msl_version >= MTLLanguageVersion::V3_0
991+
&& self.supports_arrays_of_textures
992+
&& self.supports_arrays_of_textures_write
993+
&& self.argument_buffers as u64 >= MTLArgumentBuffersTier::Tier2 as u64,
994+
);
988995
features.set(
989996
F::SHADER_INT64,
990997
self.int64 && self.msl_version >= MTLLanguageVersion::V2_3,

wgpu-hal/src/metal/conv.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,16 @@ pub fn map_resource_usage(ty: &wgt::BindingType) -> MTLResourceUsage {
349349
MTLResourceUsage::Read | MTLResourceUsage::Write
350350
}
351351
},
352+
wgt::BindingType::Buffer { ty, .. } => match ty {
353+
wgt::BufferBindingType::Uniform => MTLResourceUsage::Read,
354+
wgt::BufferBindingType::Storage { read_only } => {
355+
if *read_only {
356+
MTLResourceUsage::Read
357+
} else {
358+
MTLResourceUsage::Read | MTLResourceUsage::Write
359+
}
360+
}
361+
},
352362
wgt::BindingType::Sampler(..) => MTLResourceUsage::empty(),
353363
_ => unreachable!(),
354364
}

wgpu-hal/src/metal/device.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,25 @@ impl crate::Device for super::Device {
905905
};
906906

907907
match layout.ty {
908+
wgt::BindingType::Buffer { .. } => {
909+
let start = entry.resource_index as usize;
910+
let end = start + count as usize;
911+
let buffers = &desc.buffers[start..end];
912+
let compute_visible =
913+
layout.visibility.contains(wgt::ShaderStages::COMPUTE);
914+
915+
for (idx, buffer_binding) in buffers.iter().enumerate() {
916+
contents[idx] = buffer_binding.buffer.raw.gpu_resource_id();
917+
918+
let use_info = bg
919+
.resources_to_use
920+
.entry(buffer_binding.buffer.as_raw().cast())
921+
.or_default();
922+
use_info.stages |= stages;
923+
use_info.uses |= uses;
924+
use_info.visible_in_compute |= compute_visible;
925+
}
926+
}
908927
wgt::BindingType::Texture { .. }
909928
| wgt::BindingType::StorageTexture { .. } => {
910929
let start = entry.resource_index as usize;

0 commit comments

Comments
 (0)