rt: argumentBuffersSupport is tier 2 on the floor, and device tests hold the four pieces tier 2 adds

Capability item 2, the planner's rule: a capability answer that promises runtime behaviour is
rt's to give, and a device test holds each promise. Apple's "Improving CPU performance by using
argument buffers" sets tier 2 against tier 1's limits. Tier 1 argument buffers can't hold
writable textures, must be immutable and CPU-accessible, and can't be pointer-indexed or point
at other argument buffers. rt had one device test over an argument buffer
(translate.rs, a CPU-written texture ID), so none of those four pieces was tested.

- Device::argument_buffers_support answers Tier2. The floor holds what tier 2 stands on: buffer
  device addresses, runtime descriptor arrays, partial binding, and update-after-bind of sampled
  and storage images (the translator's own tier rule, device/metal.rs). rt re-exports the
  translator's ArgumentBuffersTier.
- tests/argument_tier.rs, one device test a piece:
  - a8r_buffers' a8r_held reads and writes the read_write and write textures an argument
    buffer holds;
  - ab_tier2's ab_copy copies a texture member device to device, and ab_read reads through the
    copy;
  - ab_read reads through a Private argument buffer that a blit filled;
  - ab_indexed's thread g reads through element g of an array of argument buffers that a
    pointer member reaches.
- The conformance rt side answers argument_buffers_tier from the getter. The rt README states
  the answer; api_signatures.tsv is blessed (+6).

Verified: signatures.py, coverage.py and refusal_surface.py regenerate; build and the device
tests on each GPU follow.
This commit is contained in:
Anees Iqbal committed 2026-11-19 06:37:12 -08:00
1 parent d48664f6d2
commit 88d69b65b8
6 files changed
+96 -12

No files matched your search

@@ -982,6 +982,10 @@ impl Side for RtSide<'_> {
Ok(self.on.device.read_write_texture_support())
}
fn argument_buffers_tier(&mut self) -> Answer<metal2vulkan::metal::ArgumentBuffersTier> {
Ok(self.on.device.argument_buffers_support())
}
fn minimum_linear_texture_alignment(&mut self, format: PixelFormat) -> Answer<u64> {
(self.on.device.minimum_linear_texture_alignment(format))
.map_err(|error| Failure::of_rt(&error))
+6
View File
@@ -85,6 +85,12 @@ them over this crate's items:
floor: Vulkan requires storage images of tier 2's four-channel and 32-bit formats, and the
floor's `shaderStorageImageExtendedFormats` its six 8- and 16-bit single-channel ones. The
device test `read_write_tier` reads and writes each of the 18 through `access::read_write`.
- `Device::argument_buffers_support` is `MTLArgumentBuffersTier2` on every device above the
floor, which holds buffer device addresses and the set-1 arrays' runtime descriptor arrays,
partial binding and update-after-bind of sampled and storage images. The device tests
`argument_tier` read and write the writable textures an argument buffer holds, and read
through an argument buffer a kernel wrote, a Private one and the array a pointer member
indexes.
### Teardown
+10 -1
View File
@@ -28,7 +28,7 @@ use ash::vk;
use metal2vulkan::device::{
ApiVersion, DeviceDescription, DevicePolicy, HandleDomain, PointerDomain,
};
use metal2vulkan::metal::ReadWriteTextureTier;
use metal2vulkan::metal::{ArgumentBuffersTier, ReadWriteTextureTier};
use std::cell::Cell;
use std::collections::HashMap;
use std::ffi::{c_char, CString};
@@ -617,6 +617,15 @@ impl Device {
ReadWriteTextureTier::Tier2
}
/// `argumentBuffersSupport`: `MTLArgumentBuffersTier2` on every device above the floor, which
/// holds what tier 2 stands on: buffer device addresses (a program writes a buffer's
/// `gpuAddress` into an argument buffer and indexes through it), and the set-1 arrays'
/// runtime descriptor arrays, partial binding and update-after-bind of sampled and storage
/// images (a program writes a texture's `gpuResourceID`, of a writable texture too).
pub fn argument_buffers_support(&self) -> ArgumentBuffersTier {
ArgumentBuffersTier::Tier2
}
/// `hasUnifiedMemory`: true where Vulkan's device type is integrated or CPU, false for a
/// discrete or virtual GPU. On a discrete GPU, `Shared` memory is system memory the GPU reads
/// across its bus, as on a Mac with a discrete GPU.
+2 -2
View File
@@ -84,8 +84,8 @@ pub use metal2vulkan::library::Library;
pub use metal2vulkan::metal::state::{DepthStencilDescriptor, StencilDescriptor};
/// `MTLBindingAccess`, which a pipeline state's texture slots answer: the translator's.
pub use metal2vulkan::metal::BindingAccess;
/// `MTLReadWriteTextureTier`: the translator's.
pub use metal2vulkan::metal::ReadWriteTextureTier;
/// `MTLReadWriteTextureTier` and `MTLArgumentBuffersTier`: the translator's.
pub use metal2vulkan::metal::{ArgumentBuffersTier, ReadWriteTextureTier};
/// `MTLSamplerMinMagFilter`, `MTLSamplerMipFilter`, `MTLSamplerAddressMode`,
/// `MTLSamplerBorderColor`, `MTLCompareFunction` and `MTLSamplerReductionMode`: the translator's.
pub use metal2vulkan::metal::{
@@ -1,16 +1,20 @@
//! Three of the things Metal's argument buffers tier 2 adds over tier 1, under a device cfg on
//! every device of the cfg's kind, one test a piece (Apple's "Improving CPU performance by using
//! argument buffers", read against its tier 1 limits):
//! What Metal's argument buffers tier 2 adds over tier 1, under a device cfg on every device of the
//! cfg's kind, one test a piece (Apple's "Improving CPU performance by using argument buffers",
//! read against its tier 1 limits):
//!
//! - writable textures in an argument buffer: `a8r_buffers`' `a8r_held` reads a `read_write`
//! member's texels, then writes it and a `write` member;
//! - an argument buffer the GPU writes: `ab_tier2`'s `ab_copy` copies a texture member from one
//! argument buffer to another, and `ab_read` reads through the copy;
//! - an argument buffer the CPU cannot reach: a Private buffer a blit filled, which `ab_read`
//! reads through.
//! reads through;
//! - pointer indexing, and an argument buffer that points at others: `ab_indexed`'s thread `g`
//! reads through element `g` of an array of argument buffers a pointer member reaches.
//!
//! The program writes each texture member itself, as the texture's `gpuResourceID`, as tier 2's
//! layout lets it.
//! The program writes each member itself, a texture's `gpuResourceID` and a buffer's
//! `gpuAddress`, as tier 2's layout lets it. The floor holds every feature this rests on (buffer
//! device addresses, and the set-1 arrays' runtime descriptor arrays, partial binding and
//! update-after-bind of sampled and storage images), so the tier is a floor fact.
//!
//! `llvm-as` assembles the fixtures; without it the tests skip visibly.
@@ -18,9 +22,10 @@
mod on_device {
use crate::tests::command::on_device::{each_device, finished};
use crate::{
Block, Buffer, ComputePipelineDescriptor, ComputePipelineState, Device, DispatchType,
FunctionDescriptor, IndexClass, Library, MemoryClass, PixelFormat, Region, Resource,
ResourceUsage, StageSource, Texture, TextureDescriptor, TextureType, TextureUsage,
ArgumentBuffersTier, Block, Buffer, ComputePipelineDescriptor, ComputePipelineState,
Device, DispatchType, FunctionDescriptor, IndexClass, Library, MemoryClass, PixelFormat,
Region, Resource, ResourceUsage, StageSource, Texture, TextureDescriptor, TextureType,
TextureUsage,
};
use metal2vulkan_devtools::{engine_dir, llvm_assemble, AssembleError};
@@ -153,6 +158,11 @@ mod on_device {
return;
};
each_device("argument_tier_writable", |name, _, device| {
assert_eq!(
device.argument_buffers_support(),
ArgumentBuffersTier::Tier2,
"{name}"
);
let state = state(name, &device, &library, "a8r_held");
let grant = (device.grant_indices(IndexClass::Texture, 1, 2))
.unwrap_or_else(|error| panic!("{name}: {error}"));
@@ -303,4 +313,53 @@ mod on_device {
println!("{name}: a texture read through a Private argument buffer");
});
}
/// The bound argument buffer holds the address of an array of three, each holding its own
/// texture: thread `g` reads through element `g`.
#[test]
fn every_device_reads_through_the_argument_buffers_a_pointer_member_indexes() {
let Some(library) = library("ab_tier2") else {
return;
};
each_device("argument_tier_indexed", |name, _, device| {
let indexed = state(name, &device, &library, "ab_indexed");
let grant = (device.grant_indices(IndexClass::Texture, 1, 3))
.unwrap_or_else(|error| panic!("{name}: {error}"));
let textures: Vec<Texture> = (0..3)
.map(|at| texture(name, &device, 1, 1 + at as u32, &TEXELS[at + 1..at + 2]))
.collect();
let mut shared = Shared::new(&device);
let ids: Vec<u8> = (textures.iter())
.flat_map(|t| t.gpu_resource_id().to_bits().to_le_bytes())
.collect();
let array = shared.of(&device, &ids);
let table = shared.of(&device, &array.gpu_address().to_le_bytes());
let out = shared.of(&device, &[0; 48]);
let queue = device.new_command_queue(1).expect("a queue");
let command_buffer = queue.command_buffer().expect("a command buffer");
let mut encoder =
(command_buffer.compute_command_encoder(DispatchType::Serial)).expect("an encoder");
encoder
.set_compute_pipeline_state(&indexed)
.expect("a state");
encoder.set_buffer(Some(&table), 0, 0).expect("table");
encoder.set_buffer(Some(&out), 0, 1).expect("out");
(encoder.use_resource(Resource::Buffer(&array), ResourceUsage::READ))
.expect("the array");
for texture in &textures {
(encoder.use_resource(Resource::Texture(texture), ResourceUsage::READ))
.expect("a texture");
}
(encoder.dispatch_threadgroups([1, 1, 1], [3, 1, 1]))
.unwrap_or_else(|error| panic!("{name}: {error}"));
encoder.end_encoding();
command_buffer.commit().expect("a commit");
finished(name, &command_buffer);
assert_eq!(command_buffer.error(), None, "{name}");
assert_eq!(float4s(&out, 3), TEXELS[1..4], "{name}");
drop((textures, command_buffer));
(device.release_indices(grant)).unwrap_or_else(|error| panic!("{name}: {error}"));
println!("{name}: three textures read through an indexed array of argument buffers");
});
}
}
@@ -6288,6 +6288,7 @@ macro-decl metal2vulkan-air::ir::Sym ir_id! Sym
macro-decl metal2vulkan-air::ir::TypeId id_type! TypeId
macro-decl metal2vulkan-air::ir::TypeId ir_id! TypeId
macro-decl metal2vulkan-air::metal::DataType metal_enum! DataType
macro-decl metal2vulkan-rt::ArgumentBuffersTier metal_enum! ArgumentBuffersTier
macro-decl metal2vulkan-rt::BindingAccess metal_enum! BindingAccess
macro-decl metal2vulkan-rt::CompareFunction metal_enum! CompareFunction
macro-decl metal2vulkan-rt::CullMode metal_enum! CullMode
@@ -6528,6 +6529,10 @@ macro-member metal2vulkan-air::metal::DataType::UShort3 UShort3 = 43, "MTLDataTy
macro-member metal2vulkan-air::metal::DataType::UShort4 UShort4 = 44, "MTLDataTypeUShort4";
macro-member metal2vulkan-air::metal::DataType::VisibleFunctionTable VisibleFunctionTable = 115, "MTLDataTypeVisibleFunctionTable";
macro-member metal2vulkan-air::metal::DataType::aliases aliases
macro-member metal2vulkan-rt::ArgumentBuffersTier::ArgumentBuffersTier ArgumentBuffersTier = "MTLArgumentBuffersTier"
macro-member metal2vulkan-rt::ArgumentBuffersTier::Tier1 Tier1 = 0, "MTLArgumentBuffersTier1";
macro-member metal2vulkan-rt::ArgumentBuffersTier::Tier2 Tier2 = 1, "MTLArgumentBuffersTier2";
macro-member metal2vulkan-rt::ArgumentBuffersTier::aliases aliases
macro-member metal2vulkan-rt::BindingAccess::BindingAccess BindingAccess = "MTLBindingAccess"
macro-member metal2vulkan-rt::BindingAccess::ReadOnly ReadOnly = 0, "MTLBindingAccessReadOnly";
macro-member metal2vulkan-rt::BindingAccess::ReadWrite ReadWrite = 1, "MTLBindingAccessReadWrite";
@@ -9617,6 +9622,7 @@ method metal2vulkan-rt::Counters::gauges pub fn gauges(&self) -> Gauges
method metal2vulkan-rt::Counters::metrics pub fn metrics(&self) -> Metrics
method metal2vulkan-rt::DepthStencilState::descriptor pub fn descriptor(&self) -> &DepthStencilDescriptor
method metal2vulkan-rt::DepthStencilState::precision_note pub fn precision_note(&self) -> Option<PrecisionNote>
method metal2vulkan-rt::Device::argument_buffers_support pub fn argument_buffers_support(&self) -> ArgumentBuffersTier
method metal2vulkan-rt::Device::counters pub fn counters(&self) -> Counters
method metal2vulkan-rt::Device::extensions pub fn extensions(&self) -> &[CString]
method metal2vulkan-rt::Device::features pub fn features(&self) -> &[ConsumerFeature]
Can't render this file because it is too large.