diff --git a/crates/metal2vulkan/src/device/derive.rs b/crates/metal2vulkan/src/device/derive.rs index 52dc5d8d1..73db59b99 100644 --- a/crates/metal2vulkan/src/device/derive.rs +++ b/crates/metal2vulkan/src/device/derive.rs @@ -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 { // 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, diff --git a/crates/metal2vulkan/src/device/policy.rs b/crates/metal2vulkan/src/device/policy.rs index 4de2697f5..7355c1881 100644 --- a/crates/metal2vulkan/src/device/policy.rs +++ b/crates/metal2vulkan/src/device/policy.rs @@ -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, diff --git a/crates/metal2vulkan/src/device/profile.rs b/crates/metal2vulkan/src/device/profile.rs index a010e3567..1e91bde4a 100644 --- a/crates/metal2vulkan/src/device/profile.rs +++ b/crates/metal2vulkan/src/device/profile.rs @@ -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. diff --git a/crates/metal2vulkan/src/device/tests/profile.rs b/crates/metal2vulkan/src/device/tests/profile.rs index fe617dfd0..6ba40e8cb 100644 --- a/crates/metal2vulkan/src/device/tests/profile.rs +++ b/crates/metal2vulkan/src/device/tests/profile.rs @@ -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); diff --git a/crates/metal2vulkan/src/error/mod.rs b/crates/metal2vulkan/src/error/mod.rs index 324c4ce93..7cfc1bf71 100644 --- a/crates/metal2vulkan/src/error/mod.rs +++ b/crates/metal2vulkan/src/error/mod.rs @@ -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. diff --git a/crates/metal2vulkan/src/pipeline/compile.rs b/crates/metal2vulkan/src/pipeline/compile.rs index d91aa5d87..ec8f06c78 100644 --- a/crates/metal2vulkan/src/pipeline/compile.rs +++ b/crates/metal2vulkan/src/pipeline/compile.rs @@ -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 { + // 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, diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index 479322ce9..fe12837a2 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -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 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 diff --git a/docs/API.md b/docs/API.md index 4419b7c38..0dfd5d2fb 100644 --- a/docs/API.md +++ b/docs/API.md @@ -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 diff --git a/docs/REFUSALS.md b/docs/REFUSALS.md index f61bc2fd5..ad3a10998 100644 --- a/docs/REFUSALS.md +++ b/docs/REFUSALS.md @@ -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)` diff --git a/scripts/refusal-surface/reach.tsv b/scripts/refusal-surface/reach.tsv index 3da24e0da..aa6a81477 100644 --- a/scripts/refusal-surface/reach.tsv +++ b/scripts/refusal-surface/reach.tsv @@ -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