From 0144468c545ee3a8a826caac48fc59cf9daa4ee3 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Tue, 10 Nov 2026 05:38:45 -0800 Subject: [PATCH] Color groups lane: restrict the device to four colors by an option, not the profiles layer What: DeviceOptions::color_attachment_limit (a doc-hidden test hook, as withheld_attachment_formats is) holds each device's maxColorAttachments and maxFragmentOutputAttachments to the limit in the description it plans and compiles by (hold_color_attachments, after the query in create_on, so a recovery's next generation takes it too). runtime_lane::color_groups' restricted (four-color) lane sets it to 4 in place of VK_LAYER_KHRONOS_profiles and the profile it wrote; the lane no longer needs the layer, and its 'SKIPPED: VK_LAYER_KHRONOS_profiles is not installed' exit is gone. Why: the layer is not installed on gem10 or the M3, so the restricted lane printed SKIPPED there and ran nothing, with no report counting it. The layer only simulated the two limits (SIMULATE_PROPERTIES_BIT); the device still drew eight, as it does under the hook. The lane keeps its check that the restricted device holds 4. API: one doc-hidden field of DeviceOptions (api_signatures blessed). Verified: not yet built; the lane on lavapipe and the M3 is next. (cherry picked from commit 925059cf220eb7e2f6dae4ab93d2de1d247c6596) --- .../metal2vulkan-runtime/src/device/create.rs | 24 +++++ .../src/runtime_lane/color_groups.rs | 89 +++---------------- crates/metal2vulkan/tests/api_signatures.tsv | 1 + 3 files changed, 37 insertions(+), 77 deletions(-) diff --git a/crates/metal2vulkan-runtime/src/device/create.rs b/crates/metal2vulkan-runtime/src/device/create.rs index a24123b30..bb1f4bb6d 100644 --- a/crates/metal2vulkan-runtime/src/device/create.rs +++ b/crates/metal2vulkan-runtime/src/device/create.rs @@ -229,6 +229,15 @@ pub struct DeviceOptions { /// device that renders the format. No Metal counterpart. #[doc(hidden)] pub withheld_attachment_formats: BTreeSet, + /// The most color attachments, and fragment outputs, each device draws at once, where it is + /// below the device's own: the device's `maxColorAttachments` and + /// `maxFragmentOutputAttachments` are held to it in the description the device plans and + /// compiles by (`hold_color_attachments`), so a render pass of more colors draws in color + /// groups (`render/color_groups.rs`) as on a device of that many. `None` by default. A test + /// hook, for the lanes that run the color groups on a device that draws eight. No Metal + /// counterpart. + #[doc(hidden)] + pub color_attachment_limit: Option, /// Where each device hands its pipeline records: one [`PipelineRecord`](crate::PipelineRecord) /// per pipeline state creation that made its state (compute, render, mesh render and tile /// render, and the additional-binary-functions forms; and the one-sample or factor-scaling @@ -379,6 +388,7 @@ impl std::fmt::Debug for DeviceOptions { assume_submissions_merge, pending_audit, withheld_attachment_formats, + color_attachment_limit, pipeline_records, extra_queues, reserved_queues, @@ -412,6 +422,7 @@ impl std::fmt::Debug for DeviceOptions { .field("assume_submissions_merge", assume_submissions_merge) .field("pending_audit", pending_audit) .field("withheld_attachment_formats", withheld_attachment_formats) + .field("color_attachment_limit", color_attachment_limit) .field( "pipeline_records", &pipeline_records.as_ref().map(|_| "hook"), @@ -1381,6 +1392,16 @@ pub(crate) fn reserved_queues_absent(asked: u32, reserved: usize, device: &str) /// options asked for sends as it is made ([`reserved_queues_absent`]). pub(crate) const RESERVED_QUEUES_ABSENT: &str = "metal2vulkan-reserved-queues-absent"; +/// `description` with its `maxColorAttachments` and `maxFragmentOutputAttachments` held to +/// `limit` where it is lower (`DeviceOptions::color_attachment_limit`); as it is for `None`. +pub(crate) fn hold_color_attachments(description: &mut DeviceDescription, limit: Option) { + if let Some(limit) = limit { + let limits = &mut description.limits; + limits.max_color_attachments = limits.max_color_attachments.min(limit); + limits.max_fragment_output_attachments = limits.max_fragment_output_attachments.min(limit); + } +} + /// `description` with each of `withheld` no color attachment /// (`DeviceOptions::withheld_attachment_formats`): its tilings' `COLOR_ATTACHMENT` and blend /// features and its attachment sample counts left out. @@ -1838,6 +1859,7 @@ pub(super) fn create_on( unsafe { DeviceDescription::query(&instance.raw, physical, instance.api_version) } .map_err(device_error)?; withhold_attachments(&mut description, &options.withheld_attachment_formats); + hold_color_attachments(&mut description, options.color_attachment_limit); // SAFETY: as above. unsafe { timeline_conformant(&instance.raw, physical) }?; argument_buffers_kept(&description)?; @@ -2340,6 +2362,7 @@ fn same_options(a: &DeviceOptions, b: &DeviceOptions) -> bool { assume_submissions_merge, pending_audit, withheld_attachment_formats, + color_attachment_limit, pipeline_records: _, extra_queues, reserved_queues, @@ -2368,6 +2391,7 @@ fn same_options(a: &DeviceOptions, b: &DeviceOptions) -> bool { && *assume_submissions_merge == b.assume_submissions_merge && *pending_audit == b.pending_audit && *withheld_attachment_formats == b.withheld_attachment_formats + && *color_attachment_limit == b.color_attachment_limit && *extra_queues == b.extra_queues && *reserved_queues == b.reserved_queues && *queue_limits == b.queue_limits diff --git a/crates/metal2vulkan-validation/src/runtime_lane/color_groups.rs b/crates/metal2vulkan-validation/src/runtime_lane/color_groups.rs index f53137f9a..8ab3d5599 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/color_groups.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/color_groups.rs @@ -1,8 +1,8 @@ //! Render passes of more color attachments than the device draws at once, drawn in color groups //! (the runtime's `render/color_groups.rs`), on the device the cfg selects under the validation -//! layer: restricted to four color attachments and four fragment outputs (Vulkan's floor) through -//! `VK_LAYER_KHRONOS_profiles` and a profile of those two limits alone, which the test writes, and -//! as it is, where nothing groups. The owned fixtures `color_groups` and `color_groups_fetch`, each +//! layer: restricted to four color attachments and four fragment outputs (Vulkan's floor), the +//! device's description held to four (`DeviceOptions::color_attachment_limit`, so every device +//! runs it), and as it is, where nothing groups. The owned fixtures `color_groups` and `color_groups_fetch`, each //! scene over 8x8 `RGBA16Float` colors: //! //! - **five**, **seven**, **sparse**: `cg_five` (colors 0 to 4, two groups), `cg_seven` (0 to 6, @@ -49,7 +49,6 @@ use super::framebuffer_fetch::fetches; use super::{layer_reported_nothing_at_all, validated_device_with, Messages, ScratchCache, WAIT}; use crate::air_library::AirLibrary; use crate::gpu::TEST_DEVICE; -use crate::observation::PROFILES_LAYER; use metal2vulkan::device::VkLimit; use metal2vulkan::error::{ Capability, DescriptorError, Error as CompileError, Feature, MetalAnswer, RuntimeDriverDefect, @@ -65,12 +64,11 @@ use metal2vulkan::pipeline::{ColorAttachmentDescriptor, RenderPipelineDescriptor use metal2vulkan_devtools::{engine_dir, llvm_assemble}; use metal2vulkan_runtime::{ BlitOption, Buffer, ClearColor, CommandQueue, Degradation, DepthStencilState, Device, Error, - LayerSetting, LayerSettingValue, Library, LoadAction, Origin, PipelineOptions, - RenderCommandEncoder, RenderPassDescriptor, RenderPipelineState, ResourceOptions, RuntimeGap, - ScissorRect, Size, StoreAction, Texture, TextureDescriptor, VisibilityResultMode, WorkCounts, + Library, LoadAction, Origin, PipelineOptions, RenderCommandEncoder, RenderPassDescriptor, + RenderPipelineState, ResourceOptions, RuntimeGap, ScissorRect, Size, StoreAction, Texture, + TextureDescriptor, VisibilityResultMode, WorkCounts, }; use std::collections::BTreeSet; -use std::ffi::CString; use std::time::{Duration, Instant}; /// Every target's side. @@ -96,80 +94,17 @@ struct Lane { width: Width, } -/// The profile of four color attachments and four fragment outputs alone: the profiles layer -/// reports the device's own value for every member it omits. -const FOUR_COLORS: &str = r#"{ - "$schema": "https://schema.khronos.org/vulkan/profiles-0.8-latest.json#", - "capabilities": { - "four_colors": { - "properties": { - "VkPhysicalDeviceProperties": { - "limits": { "maxColorAttachments": 4, "maxFragmentOutputAttachments": 4 } - } - } - } - }, - "profiles": { - "VP_M2V_four_colors": { - "version": 1, - "api-version": "1.2.0", - "label": "Four color attachments", - "description": "The device's own capabilities but four color attachments and fragment outputs.", - "contributors": {}, - "history": [ - { "revision": 1, "date": "2026-10-16", "author": "metal2vulkan", "comment": "A lane's." } - ], - "capabilities": ["four_colors"] - } - } -}"#; - /// The lane's device at `width`, under the validation layer where `validated`, its messages and -/// shader cache, and the directory of the profile that restricts it; `None` (skipped, visibly) -/// where the profiles layer is not installed or the device as it is draws fewer than eight. -fn lane(width: Width, validated: bool) -> Option<(Messages, ScratchCache, ScratchCache, Lane)> { +/// shader cache; `None` (skipped, visibly) where the device as it is draws fewer than eight. +fn lane(width: Width, validated: bool) -> Option<(Messages, ScratchCache, Lane)> { let messages = Messages::default(); let cache = ScratchCache::new().unwrap(); - let profile = ScratchCache::new().unwrap(); - let file = profile.path().join("four_colors.json"); - if width == Width::Four { - if !crate::candidate::profiles_layer_installed().unwrap() { - println!("SKIPPED: VK_LAYER_KHRONOS_profiles is not installed"); - return None; - } - std::fs::create_dir_all(profile.path()).unwrap(); - std::fs::write(&file, FOUR_COLORS).unwrap(); - } let device = validated_device_with(TEST_DEVICE, &messages, cache.path(), |options| { if !validated { options.layers.clear(); } if width == Width::Four { - let setting = |name: &str, value| { - LayerSetting::new( - PROFILES_LAYER.to_owned(), - CString::new(name).unwrap(), - value, - ) - }; - let strings = |values: &[&str]| { - LayerSettingValue::Strings( - values.iter().map(|v| CString::new(*v).unwrap()).collect(), - ) - }; - let path = file.to_string_lossy().into_owned(); - options.layers.push(PROFILES_LAYER.to_owned()); - options.layer_settings.extend([ - setting("profile_emulation", LayerSettingValue::Bool(true)), - setting("profile_file", strings(&[&path])), - setting("profile_name", strings(&["VP_M2V_four_colors"])), - setting( - "simulate_capabilities", - strings(&["SIMULATE_PROPERTIES_BIT"]), - ), - setting("emulate_portability", LayerSettingValue::Bool(false)), - setting("debug_fail_on_error", LayerSettingValue::Bool(false)), - ]); + options.color_attachment_limit = Some(4); } }) .unwrap(); @@ -199,7 +134,7 @@ fn lane(width: Width, validated: bool) -> Option<(Messages, ScratchCache, Scratc width, device, }; - Some((messages, cache, profile, lane)) + Some((messages, cache, lane)) } /// The fixture's `tint` at pixel `(x, y)`'s center: the fullscreen triangle's `a` is @@ -474,7 +409,7 @@ fn plain( } fn scenes(width: Width) { - let Some((messages, _cache, _profile, lane)) = lane(width, true) else { + let Some((messages, _cache, lane)) = lane(width, true) else { return; }; // Announced once, as the first state of groups is made; and where the driver counts per @@ -1012,7 +947,7 @@ fn cost(lane: &Lane, colors: &[usize], depth: bool) -> (Duration, Duration) { #[test] #[ignore = "a measurement, not a check: run by name with --run-ignored all"] fn color_group_costs() { - let Some((_messages, _cache, _profile, lane)) = lane(Width::Four, false) else { + let Some((_messages, _cache, lane)) = lane(Width::Four, false) else { return; }; let ms = |d: Duration| d.as_secs_f64() * 1e3; diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index a6b5d0a4c..b541cbd26 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -2078,6 +2078,7 @@ field metal2vulkan-runtime::DeviceHandles.queue_family pub queue_family: u32 field metal2vulkan-runtime::DeviceHandles.reserved_queues pub reserved_queues: &'a [ReservedQueue] field metal2vulkan-runtime::DeviceOptions.announce_each pub announce_each: BTreeSet field metal2vulkan-runtime::DeviceOptions.assume_submissions_merge pub assume_submissions_merge: bool +field metal2vulkan-runtime::DeviceOptions.color_attachment_limit pub color_attachment_limit: Option field metal2vulkan-runtime::DeviceOptions.device_extensions pub device_extensions: Vec field metal2vulkan-runtime::DeviceOptions.extra_queues pub extra_queues: Vec field metal2vulkan-runtime::DeviceOptions.fail_in_place_check pub fail_in_place_check: bool