device: the identity pointer and handle domains, taken as a pair

The new runtime's form: pointers are device addresses used directly and a texture's or sampler's
handle is its gpuResourceID (docs/RESOURCE-ID.md). The variants come beside the old domains,
which stay until the cutover; nothing lowers under them yet.

- PointerDomain::Identity and HandleDomain::Identity.
- Device::new refuses one identity domain without the other (InvalidDescriptor) and the identity
  domains on a device without bufferDeviceAddress and shaderInt64 (Unsupported{IdentityDomains},
  naming both features as one alternative).
- A compile under the identity domains is Unsupported{IdentityDomains}, not implemented, at the
  start of analysis, so no old form is ever emitted under them. Later steps lift it as the
  lowering lands.
- The profile fingerprint covers the domains (tested).
- docs/API.md's policy section names the domains; docs/REFUSALS.md and the reach table carry the
  new refusal; api_signatures regenerated.

Verified (this commit's tree, rebased with the ledger commit before it onto b216007f0a):
- msi 41071: clippy -p metal2vulkan --all-targets --all-features -D warnings, rustdoc -D warnings,
  nextest -p metal2vulkan in full, 3,663 of 3,663 (the golden table included: no cell moved; the
  new test the_identity_domains_come_as_a_pair_on_a_device_with_addresses among them).
- msi 41072: clippy under --cfg m2v_gpu and --cfg m2v_cpu_icd.
- msi 41073: the conformance crate's ledger tests, 7 of 7.
This commit is contained in:
Anees Iqbal committed 2026-11-17 07:46:08 -08:00
1 parent 32b1c1578c
commit 94071f82a2
10 files changed
+142 -10

No files matched your search

+27 -3
View File
@@ -16,7 +16,8 @@ use crate::device::policy::{ContainmentPolicy, DevicePolicy};
use crate::device::profile::{
BufferAccess, Containment, CubeGradientRoute, CubeGradients, DescriptorCaps, DeviceProfile,
DriverWorkaround, EnabledCaps, FloatFunctions, FormatTable, FragmentCaps, GuestIsolation,
ImageCaps, Independence, LeafCaps, NanEncoding, ProfileFields, Robustness,
HandleDomain, ImageCaps, Independence, LeafCaps, NanEncoding, PointerDomain, ProfileFields,
Robustness,
};
use crate::device::requirements::{
ApiVersion, FloatControl, FloatWidth, FormatUsage, ResolveMode, SubgroupOp, VkExtension,
@@ -57,8 +58,10 @@ impl Device {
/// Refuses a device below Vulkan 1.2 (`Unsupported{VulkanVersion}`), a description that lists
/// a feature neither its version nor its listed extensions expose or a feature without the
/// feature Vulkan requires enabled with it (`InvalidDescriptor`, the invariants
/// `device::enables` states), and a policy that turns containment off while guest isolation
/// is on (`InvalidDescriptor`).
/// `device::enables` states), a policy that turns containment off while guest isolation
/// is on (`InvalidDescriptor`), a policy that takes one identity domain without the other
/// (`InvalidDescriptor`), and the identity domains on a device without `bufferDeviceAddress`
/// and `shaderInt64` (`Unsupported{IdentityDomains}`).
pub fn new(desc: DeviceDescription, policy: DevicePolicy) -> Result<Device, Error> {
// The driver's measured deviations on its GPU, never its name.
let deviations = super::driver_facts::deviations(&desc);
@@ -108,6 +111,7 @@ impl Device {
},
));
}
identity_domains(&desc, &policy)?;
let fields = derive_fields(&desc, &policy, &deviations);
let profile = DeviceProfile::of(fields);
let metal = MetalDeviceProperties::derive(&profile, &desc.allocation);
@@ -164,6 +168,26 @@ impl Device {
}
}
/// The identity domains come as a pair, and need device addresses and 64-bit integers: a
/// pointer is a 64-bit device address.
fn identity_domains(desc: &DeviceDescription, policy: &DevicePolicy) -> Result<(), Error> {
let pointers = policy.pointer_domain == PointerDomain::Identity;
let handles = policy.handle_domain == HandleDomain::Identity;
if pointers != handles {
return Err(Error::InvalidDescriptor(
DescriptorError::DeviceDescription {
detail: "the identity pointer and handle domains are taken together".into(),
},
));
}
let needs = [VkFeature::BufferDeviceAddress, VkFeature::ShaderInt64];
if pointers && !needs.iter().all(|&f| desc.has(f)) {
let all = needs.iter().map(|&f| Capability::Feature(f)).collect();
return Err(Unsupported::needs_any_of(Feature::IdentityDomains, vec![all]).into());
}
Ok(())
}
fn derive_fields(
desc: &DeviceDescription,
policy: &DevicePolicy,
+3 -2
View File
@@ -29,9 +29,10 @@ use std::time::Duration;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DevicePolicy {
/// How pointer values resolve to resources (v1 ships `ResidentTable` only).
/// How pointer values resolve to resources: `ResidentTable`, or `Identity` with
/// `handle_domain` `Identity`.
pub pointer_domain: PointerDomain,
/// How resource handles resolve (v1 ships `Table` only).
/// How resource handles resolve: `Table`, or `Identity` with `pointer_domain` `Identity`.
pub handle_domain: HandleDomain,
/// Whether accesses are contained to the resources the binder supplied.
pub containment: ContainmentPolicy,
+14 -2
View File
@@ -709,22 +709,34 @@ pub enum BufferAccess {
Floor,
}
/// How pointer values are resolved to resources. v1 ships `ResidentTable` only.
/// How pointer values are resolved to resources. A device takes `Identity` only with
/// [`HandleDomain::Identity`], and the other two together.
#[non_exhaustive]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PointerDomain {
/// The sorted resident set of bound arguments and used resources.
ResidentTable,
/// Pointers are device addresses used directly: a `device` or `constant` pointer is the
/// 64-bit Vulkan device address of the byte it names, as Metal's `gpuAddress` is. Needs
/// `bufferDeviceAddress` and `shaderInt64`. No function compiles under it yet: a compile is
/// refused as [`Feature::IdentityDomains`](crate::error::Feature::IdentityDomains).
Identity,
}
/// How resource handles are resolved. v1 ships `Table` only.
/// How resource handles are resolved. A device takes `Identity` only with
/// [`PointerDomain::Identity`], and the other two together.
#[non_exhaustive]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum HandleDomain {
/// The handle table plus the set-1 heap.
Table,
/// A texture's or sampler's handle is its `gpuResourceID`: the low 32 bits index the
/// pipeline's descriptor arrays and the high 32 bits are the word of its Metal descriptor
/// (`docs/RESOURCE-ID.md`). No function compiles under it yet: a compile is refused as
/// [`Feature::IdentityDomains`](crate::error::Feature::IdentityDomains).
Identity,
}
/// Out-of-bounds containment encoding.
@@ -1,7 +1,10 @@
//! `Device::new`, profile derivation, the fingerprint, and `requirements ⊆ profile`.
use super::*;
use crate::device::profile::{BufferAccess, Containment, GuestIsolation, Independence, Robustness};
use crate::device::profile::{
BufferAccess, Containment, GuestIsolation, HandleDomain, Independence, PointerDomain,
Robustness,
};
use crate::device::requirements::{Requirements, StageCreateFlag, VkLimit, VkProperty};
use crate::error::{Capability, Feature, Needs};
@@ -306,6 +309,71 @@ fn below_1_2_and_contradictory_policies_are_refused() {
assert_eq!(dev.profile().fields().containment, Containment::UnsafeOff);
}
/// The identity domains come as a pair (`InvalidDescriptor` for one alone), need
/// `bufferDeviceAddress` and `shaderInt64` (`Unsupported{IdentityDomains}` naming both, on a
/// device without `shaderInt64`), and lower no function yet: a compile under them is
/// `Unsupported{IdentityDomains}`, not implemented, where the same function compiles under the
/// other domains.
#[test]
fn the_identity_domains_come_as_a_pair_on_a_device_with_addresses() {
let identity = DevicePolicy {
pointer_domain: PointerDomain::Identity,
handle_domain: HandleDomain::Identity,
..DevicePolicy::default()
};
for half in [
DevicePolicy {
pointer_domain: PointerDomain::Identity,
..DevicePolicy::default()
},
DevicePolicy {
handle_domain: HandleDomain::Identity,
..DevicePolicy::default()
},
] {
assert!(
matches!(
Device::new(profile("lavapipe"), half),
Err(Error::InvalidDescriptor(
DescriptorError::DeviceDescription { .. }
))
),
"{half:?}"
);
}
// roadmap-2022 has device addresses but not shaderInt64.
match Device::new(profile("roadmap-2022"), identity) {
Err(Error::Unsupported(u)) => {
assert_eq!(u.feature, Feature::IdentityDomains);
let both = [VkFeature::BufferDeviceAddress, VkFeature::ShaderInt64];
let both = both.map(Capability::Feature).to_vec();
assert_eq!(u.needs, Needs::AnyOf(vec![both]));
}
other => panic!("{other:?}"),
}
use crate::pipeline::testing::{compile, engine_dir, llvm_assemble, AssembleError};
let bc = match llvm_assemble(&engine_dir().join("a1_bool_from_float.ll")) {
Ok(bc) => bc,
Err(AssembleError::Missing(why)) => {
eprintln!("SKIPPED: {why}");
return;
}
Err(e) => panic!("{e:?}"),
};
let under = |policy| {
let dev = Device::new(profile("lavapipe"), policy).unwrap();
compile(&bc, "a1_bool_from_float", dev.profile())
};
assert!(under(DevicePolicy::default()).is_ok());
match under(identity) {
Err(Error::Unsupported(u)) => {
assert_eq!(u.feature, Feature::IdentityDomains);
assert_eq!(u.needs, Needs::NotImplemented);
}
other => panic!("{other:?}"),
}
}
#[test]
fn fingerprint_covers_every_policy_field() {
let desc = profile("lavapipe");
@@ -323,6 +391,12 @@ fn fingerprint_covers_every_policy_field() {
variants.push(("isolation", p));
p.containment = ContainmentPolicy::UnsafeOff;
variants.push(("containment", p));
let identity = DevicePolicy {
pointer_domain: PointerDomain::Identity,
handle_domain: HandleDomain::Identity,
..base
};
variants.push(("domains", identity));
let mut seen = vec![reference];
for (name, p) in variants {
let h = fp(p);
+4
View File
@@ -1410,6 +1410,10 @@ pub enum Feature {
// ---- Device ----
/// The device's Vulkan version is below the 1.2 floor.
VulkanVersion,
/// The identity pointer and handle domains (`PointerDomain::Identity`,
/// `HandleDomain::Identity`): on a device without `bufferDeviceAddress` and `shaderInt64`,
/// and, on any device, a compile of a function they do not lower yet.
IdentityDomains,
/// A constants-block record LLVM defines that the typed model has no form for (a block
/// address, a `select` and the other constant expressions of [`ConstantRecord`]), by LLVM's
/// name for it.
@@ -2853,6 +2853,10 @@ impl Analyzed {
/// [`plan_one`]'s reads before it selects ([`Analyzed`]).
fn analyze_one(r: &Request<'_>, p: &DeviceProfile, m: &mut Meter) -> Result<Analyzed, Error> {
// The identity domains lower no function yet.
if p.fields().pointer_domain == crate::device::PointerDomain::Identity {
return Err(Unsupported::not_implemented(Feature::IdentityDomains).into());
}
let Specialized {
air_hash,
entry,
@@ -14289,6 +14289,7 @@ variant metal2vulkan::device::GuestIsolation::Off Off
variant metal2vulkan::device::GuestIsolation::On On
variant metal2vulkan::device::HalfChainPolicy::AtExits AtExits
variant metal2vulkan::device::HalfChainPolicy::EachOperation EachOperation
variant metal2vulkan::device::HandleDomain::Identity Identity
variant metal2vulkan::device::HandleDomain::Table Table
variant metal2vulkan::device::HeapAnswerPolicy::Device Device
variant metal2vulkan::device::HeapAnswerPolicy::Metal Metal
@@ -14305,6 +14306,7 @@ variant metal2vulkan::device::ManagedCopyInPolicy::AtCommit AtCommit
variant metal2vulkan::device::ManagedCopyInPolicy::AtSubmission AtSubmission
variant metal2vulkan::device::PipelineWaitPolicy::Bounded Bounded
variant metal2vulkan::device::PipelineWaitPolicy::Exact Exact
variant metal2vulkan::device::PointerDomain::Identity Identity
variant metal2vulkan::device::PointerDomain::ResidentTable ResidentTable
variant metal2vulkan::device::QueueSharingPolicy::Adaptive Adaptive
variant metal2vulkan::device::QueueSharingPolicy::PerQueue PerQueue
@@ -14994,6 +14996,7 @@ variant metal2vulkan::error::Feature::GroupCount GroupCount { axis: Option<Axis>
variant metal2vulkan::error::Feature::HandleAsPointer HandleAsPointer
variant metal2vulkan::error::Feature::HeapTextureTiling HeapTextureTiling { missing: LinearNeed }
variant metal2vulkan::error::Feature::HostMemory HostMemory
variant metal2vulkan::error::Feature::IdentityDomains IdentityDomains
variant metal2vulkan::error::Feature::ImageAtomics ImageAtomics
variant metal2vulkan::error::Feature::Imageblocks Imageblocks
variant metal2vulkan::error::Feature::ImplicitLodOutsideFragment ImplicitLodOutsideFragment
Can't render this file because it is too large.
+7
View File
@@ -105,6 +105,13 @@ compile does. `DevicePolicy::default()` is `DevicePolicy::UNTRUSTED`:
rounding of each `half` operation
on a device without `shaderFloat16` and Metal's filter of planes read in place (below), each listed in [FAST-PATHS.md](FAST-PATHS.md)
with its bound and the measured cost of its exact form.
- **The resident-table and handle-table domains** (`PointerDomain::ResidentTable`,
`HandleDomain::Table`, the default). The identity domains (`PointerDomain::Identity` with
`HandleDomain::Identity`, taken together) are the new runtime's form: pointers are device
addresses used directly and a texture's or sampler's handle is its `gpuResourceID`
([RESOURCE-ID.md](RESOURCE-ID.md)). They need `bufferDeviceAddress` and `shaderInt64`, and
they lower no function yet: a compile under them is refused as
`Unsupported{IdentityDomains}`.
- **The model's linear sample of planes read in place** (`YCbCrInPlacePolicy::Model`, the
default; changes emitted code). On an integrated GPU or a CPU device a function that only
samples, gathers or sizes a `YCBCR8_420_2P` or `YCBCR10_420_2P` texture reads its planes' codes
+4 -2
View File
@@ -27,7 +27,7 @@ Columns:
| Kind | Variants | With a site | Reach system | Reach app | Reach rare | Reach none | Unassessed |
|---|---|---|---|---|---|---|---|
| Translator and front-end refusals | 132 | 132 | 8 | 32 | 73 | 19 | 0 |
| Translator and front-end refusals | 133 | 133 | 8 | 32 | 73 | 20 | 0 |
| Runtime gaps | 80 | 80 | 1 | 10 | 46 | 23 | 0 |
| Apple-only calls | 4 | 4 | 0 | 0 | 0 | 4 | 0 |
| Binder refusals at a device limit | 9 | 9 | 0 | 1 | 7 | 1 | 0 |
@@ -44,7 +44,7 @@ Columns:
| Kind | `metal-measured` | `metal-documented` | `metal-takes` | `device` | `ours` | `unknown` | `delegated` | `-` |
|---|---|---|---|---|---|---|---|---|
| Translator and front-end refusals | 0 | 0 | 0 | 50 | 59 | 0 | 0 | 23 |
| Translator and front-end refusals | 0 | 0 | 0 | 50 | 60 | 0 | 0 | 23 |
| Runtime gaps | 0 | 0 | 0 | 0 | 80 | 0 | 0 | 0 |
| Apple-only calls | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 4 |
| Binder refusals at a device limit | 0 | 0 | 0 | 9 | 0 | 0 | 0 | 0 |
@@ -141,6 +141,7 @@ Columns:
| `RasterizationRateMap` | | devices without VkFeature::MultiViewport; devices without VkFeature::ShaderDrawParameters; devices without VkFeature::ShaderOutputViewportIndex; devices without VkLimit::MaxGeometryTotalOutputComponents; devices without a capability the site computes; devices without a capability the site computes (`vec![Capability::Feature(lacks)]`); every device (not implemented) | `ours` | 10: `crates/metal2vulkan/src/lower/stage_io/plan.rs (region_copy, 3 sites)`, `crates/metal2vulkan/src/lower/stage_io/plan.rs (region_viewport, 2 sites)` (+3) | `rare`: rasterization rate maps |
| `GpuEncodedIndirectCommands` | | devices short of a Vulkan feature the site names; devices without buffer device addresses (`addressed_needs`); every device (no Vulkan mechanism); every device (not implemented) | `ours` | 20: `crates/metal2vulkan/src/bind/replay.rs (preprocess)`, `crates/metal2vulkan/src/bind/replay.rs (replay_preprocess_module)` (+13) | `rare`: indirect command buffers encoded by a kernel |
| `VulkanVersion` | The device's Vulkan version is below the 1.2 floor | devices without ApiVersion::V1_2 | `device` | 2: `crates/metal2vulkan/src/ash_interop/query.rs (query)`, `crates/metal2vulkan/src/device/derive.rs (with_deviations)` | `none`: a device below Vulkan 1.2 |
| `IdentityDomains` | The identity pointer and handle domains (`PointerDomain::Identity`, `HandleDomain::Identity`) | devices without a capability the site computes (`all`); every device (not implemented) | `ours` | 2: `crates/metal2vulkan/src/device/derive.rs (identity_domains)`, `crates/metal2vulkan/src/pipeline/compile.rs (analyze_one)` | `none`: the identity domains, which the new runtime alone takes and which lower no function yet |
| `Constant` | A constants-block record LLVM defines that the typed model has no form for (a block address, a `select` and the other constant expressions of... | - | `-` | via a helper: 3: `crates/metal2vulkan-air/src/bitcode/constants.rs (record, 2 sites)`, `crates/metal2vulkan/src/error/mod.rs (from)` | `none`: LLVM constant forms AIR does not emit |
| `Attribute` | An LLVM attribute kind that changes the calling ABI and that AIR does not use (`inalloca`, `preallocated`, `byref`, `nest`, the `swift*` kinds) | - | `-` | via a helper: 2: `crates/metal2vulkan-air/src/bitcode/attrs.rs (known)`, `crates/metal2vulkan/src/error/mod.rs (from)` | `none`: LLVM ABI attributes AIR does not use |
| `BitcodeRecord` | A bitcode record LLVM defines in `block` that the typed model does not cover and that has no more specific variant (legacy spellings predating... | - | `-` | via a helper: 8: `crates/metal2vulkan-air/src/bitcode/attrs.rs (decode_lists)`, `crates/metal2vulkan-air/src/bitcode/function.rs (symtab)` (+5) | `none`: bitcode records AIR does not emit |
@@ -706,6 +707,7 @@ Each refusal's sites, with the function that builds it.
- `feature::RasterizationRateMap`: `crates/metal2vulkan/src/lower/stage_io/plan.rs (region_copy, 3 sites)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs (region_viewport, 2 sites)`; `crates/metal2vulkan/src/pipeline/link.rs (region_box)`; `crates/metal2vulkan/src/pipeline/link/geometry.rs (check_limits)`; `crates/metal2vulkan/src/pipeline/link/geometry.rs (fan_plan, 3 sites)`
- `feature::GpuEncodedIndirectCommands`: `crates/metal2vulkan/src/bind/replay.rs (preprocess)`; `crates/metal2vulkan/src/bind/replay.rs (replay_preprocess_module)`; `crates/metal2vulkan/src/bind/replay/draws.rs (draw_replay_module)`; `crates/metal2vulkan/src/bind/replay/draws.rs (draw_replay_preprocess)`; `crates/metal2vulkan/src/bind/replay/flat.rs (flat_dispatch_module)`; `crates/metal2vulkan/src/bind/replay/merged.rs (draw_merge_module)`; `crates/metal2vulkan/src/lower/access/encode.rs (needs, 2 sites)`; `crates/metal2vulkan/src/lower/access/encode.rs (select_command)`; `crates/metal2vulkan/src/lower/access/mod.rs (plan_replay, 3 sites)`; `crates/metal2vulkan/src/lower/mesh/mod.rs (plan_partial_groups)`; `crates/metal2vulkan/src/lower/select.rs (finish, 2 sites)`; `crates/metal2vulkan/src/lower/simd/divergent.rs (barriers)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs (merged)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs (param)`; `crates/metal2vulkan/src/pipeline/compile.rs (analyze_one, 2 sites)`
- `feature::VulkanVersion`: `crates/metal2vulkan/src/ash_interop/query.rs (query)`; `crates/metal2vulkan/src/device/derive.rs (with_deviations)`
- `feature::IdentityDomains`: `crates/metal2vulkan/src/device/derive.rs (identity_domains)`; `crates/metal2vulkan/src/pipeline/compile.rs (analyze_one)`
- `feature::Constant`: `crates/metal2vulkan-air/src/bitcode/constants.rs (record, 2 sites)`; `crates/metal2vulkan/src/error/mod.rs (from)`
- `feature::Attribute`: `crates/metal2vulkan-air/src/bitcode/attrs.rs (known)`; `crates/metal2vulkan/src/error/mod.rs (from)`
- `feature::BitcodeRecord`: `crates/metal2vulkan-air/src/bitcode/attrs.rs (decode_lists)`; `crates/metal2vulkan-air/src/bitcode/function.rs (symtab)`; `crates/metal2vulkan-air/src/bitcode/metadata.rs (decode, 2 sites)`; `crates/metal2vulkan-air/src/bitcode/module.rs (check_bodies)`; `crates/metal2vulkan-air/src/bitcode/module.rs (read)`; `crates/metal2vulkan-air/src/bitcode/module.rs (symtab)`; `crates/metal2vulkan/src/error/mod.rs (from)`
+1
View File
@@ -82,6 +82,7 @@ feature Tensors rare shader tensors
feature RasterizationRateMap rare rasterization rate maps
feature GpuEncodedIndirectCommands rare indirect command buffers encoded by a kernel
feature VulkanVersion none a device below Vulkan 1.2
feature IdentityDomains none the identity domains, which the new runtime alone takes and which lower no function yet
feature Constant none LLVM constant forms AIR does not emit
feature Attribute none LLVM ABI attributes AIR does not use
feature BitcodeRecord none bitcode records AIR does not emit
Can't render this file because it contains an unexpected character in line 17 and column 65.