From 81223fe02063969b6fe230a8d291222bd6ba5a4d Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Fri, 20 Nov 2026 20:33:32 -0800 Subject: [PATCH] rt: barycentrics are enabled where the device lists and reports them A fragment function that reads [[barycentric_coord]] has one form on the floor: it reads the device's own weights, BaryCoordKHR or BaryCoordNoPerspKHR. rt enabled VK_KHR_fragment_shader_barycentric on no device, so every such function was refused at creation (Barycentrics), where the deleted runtime enabled it. floor: BARYCENTRIC_EXTENSIONS holds VK_KHR_fragment_shader_barycentric, and BARYCENTRICS its fragmentShaderBarycentric. Device creation enables both where the device lists the extension and reports the feature, and neither otherwise, the border swizzle's shape, so Device::extensions names the extension only with its feature; the consumer's two barycentric answers follow that list. The feature structure joins Features (read only where listed), the translator's profile gets the extension and the feature through shader_enables, and device creation (and the floor test's copy of it) chains the structure where the extension is enabled. No answer chooses a second form: the translator's geometry-stage form needs geometryShader, which device creation does not enable, so a device without the feature keeps the typed refusal. Venues (vulkaninfo, rtenable's probes): NVIDIA on the RTX 3090, RTX 2080 and RTX 5080 Laptop, and RADV on the RX 7900 XTX and both 780Ms list it and report the feature (m3-max-61287 to 61290, 61296); lavapipe, ANV on the Iris Xe, RADV on the RX 550, the UHD 630's Windows driver and KosmicKrisp on the M3 Max list none (m3-max-61287, 61291, 61292, 61296). Docs: the runtime README's extension table, a Barycentrics section with the feature table, and the render pipeline states' known gap for devices without it. docs/REFUSALS.md regenerated: no change (the refusal sites are the translator's and did not move). opened_chains.txt is validation's own context's chains, which read none of rt's lists: unchanged, its test run in the gate. Tests: floor's host test barycentrics_are_enabled_where_listed_and_reported (listed alone, reported alone, both), the README tables, the device extensions test's expected list, and the device test barycentrics.rs: bary_weights' bw_vertex with bw_perspective and bw_linear drawn by a triangle whose vertices' w are 1, 2 and 4, every covered pixel reading Metal's perspective-correct and linear weights within 1e-4, the extension named exactly where the feature is enabled, or both states refused naming Barycentrics. Verified at 53df1d56d6 (this commit plus its doc fix, rebased on c8bd7123b7): lint m3-max-61450 (fmt, clippy plain, m2v_gpu and m2v_cpu_icd, Rustdoc -D warnings, the GPU archive); m3-max-61451 the runtime's tests with the opened-chains and public-signatures tests (152 passed) and the lavapipe device tests (512 passed); m3-max-61464 on the RTX 3090 and 61465 on the RX 7900 XTX print "fragmentShaderBarycentric enabled; 72 pixels read Metal's weights, perspective-correct and linear". At 9fe00df268: the private rows on the 780M, m3-max-61436, 193 cases, 178 -> 179 match, the one moved row the barycentric one (not_supported -> match); the 36-stream states-only play at aef698c439 (m3-max-61413, 61414, 61402, 61387, 61420), 0 refused render and compute states. --- crates/metal2vulkan-runtime/README.md | 24 +++ crates/metal2vulkan-runtime/src/device.rs | 4 + crates/metal2vulkan-runtime/src/extension.rs | 1 + crates/metal2vulkan-runtime/src/floor.rs | 47 +++++- .../src/tests/barycentrics.rs | 151 ++++++++++++++++++ .../metal2vulkan-runtime/src/tests/device.rs | 12 ++ .../metal2vulkan-runtime/src/tests/floor.rs | 67 +++++++- crates/metal2vulkan-runtime/src/tests/mod.rs | 1 + crates/metal2vulkan/tests/api_signatures.tsv | 3 + 9 files changed, 302 insertions(+), 8 deletions(-) create mode 100644 crates/metal2vulkan-runtime/src/tests/barycentrics.rs diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index e2ee82d2a..117d526eb 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -2859,6 +2859,16 @@ or does not check is rebuilt from the generations' names, with young counted ful 26 streams' libraries calls a SIMD-group, quad or SIMD-group matrix function (each library whose bytes name one disassembled with `llvm-dis`, jobs m3-max-52530, 52531, 52532, 52557 and 52604). Their libraries that call quad functions, 2 to 5 a stream, call them from no fragment function. +- On a device without `fragmentShaderBarycentric` (Barycentrics, under Floor), a fragment function + that reads `[[barycentric_coord]]` is refused at creation, an `Error::Translation` naming + `Barycentrics`: the translator's other form, weights a generated geometry stage writes, needs + `geometryShader`, which device creation does not enable. Of the venues run, lavapipe, ANV on the + Iris Xe, RADV on the RX 550, the UHD 630's Windows driver and KosmicKrisp on the M3 Max list no + `VK_KHR_fragment_shader_barycentric` (`vulkaninfo`, jobs m3-max-61287, 61291, 61292 and 61296); + NVIDIA's driver on the RTX 3090, RTX 2080 and RTX 5080 Laptop, and RADV on the RX 7900 XTX and + the 780M, list it and report the feature (m3-max-61287 to 61290 and 61296). No replay stream has + one: the states-only plays of the 36 streams on lavapipe refuse none of their render states + (m3-max-60927 to 60930 and 60945). - On a device without `fragmentShaderPixelInterlock` (Pixel interlock, under Floor), a fragment function's raster order group on memory it reads and writes is refused at creation, an `Error::Translation` naming `RasterOrderGroups` and `fragmentShaderPixelInterlock`. Of the venues @@ -3453,6 +3463,7 @@ Presenting runs on the runtime's own device; nothing is exported or imported. | `VK_NV_linear_color_attachment` | device, where listed | an opaque handle's surface planes in place whose `LINEAR` tiling renders as a linear colour attachment alone, through the linear-attachment feature below | | `VK_EXT_custom_border_color` | device, where reported from the image | Vulkan requires it of a device that enables the border swizzle below; none of its features is enabled | | `VK_EXT_border_color_swizzle` | device, where reported from the image | an opaque-black border sampled through a view whose component mapping is not the identity, defined and read through that mapping (Border swizzle, below) | +| `VK_KHR_fragment_shader_barycentric` | device, where reported | a fragment function's `[[barycentric_coord]]`, through the barycentric feature below; `Device::extensions` names it only where that feature is enabled | ### Features @@ -3567,6 +3578,19 @@ render encoders). No other feature of the extension is enabled. |---|---|---| | `fragmentShaderPixelInterlock` | `VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT` | a fragment function's raster order groups on memory it reads and writes | +### Barycentrics + +A fragment function that reads `[[barycentric_coord]]` has one form: it reads the device's own +weights, `BaryCoordKHR` or `BaryCoordNoPerspKHR`. Where the device lists +`VK_KHR_fragment_shader_barycentric` and reports the feature below, device creation enables both, +and the translator builds the function; elsewhere it enables neither, and the translator refuses +the function at creation, an `Error::Translation` naming `Barycentrics` (Known gaps of render +pipeline states). So `Device::extensions` names the extension only with its feature. + +| Barycentric feature | Structure | Used for | +|---|---|---| +| `fragmentShaderBarycentric` | `VkPhysicalDeviceFragmentShaderBarycentricFeaturesKHR` | a fragment function's `[[barycentric_coord]]`, read from the device's own weights | + ### Limits The descriptor limits are what the runtime's fixed arrays need: 65,536 sampled textures, 65,536 diff --git a/crates/metal2vulkan-runtime/src/device.rs b/crates/metal2vulkan-runtime/src/device.rs index 13e9039e6..162dd1640 100644 --- a/crates/metal2vulkan-runtime/src/device.rs +++ b/crates/metal2vulkan-runtime/src/device.rs @@ -502,6 +502,7 @@ impl Device { mut subgroup_uniform_control_flow, mut quad_control, mut interlock, + mut barycentric, mut robustness2, mut portability, mut feedback_loop, @@ -548,6 +549,9 @@ impl Device { if enabled(ash::ext::fragment_shader_interlock::NAME) { features = features.push_next(&mut interlock); } + if enabled(ash::khr::fragment_shader_barycentric::NAME) { + features = features.push_next(&mut barycentric); + } if enabled(ash::khr::portability_subset::NAME) { features = features.push_next(&mut portability); } diff --git a/crates/metal2vulkan-runtime/src/extension.rs b/crates/metal2vulkan-runtime/src/extension.rs index 5bd3160af..218dde968 100644 --- a/crates/metal2vulkan-runtime/src/extension.rs +++ b/crates/metal2vulkan-runtime/src/extension.rs @@ -37,6 +37,7 @@ impl DeviceExtension { /// `VkPhysicalDeviceShaderSubgroupUniformControlFlowFeaturesKHR`, /// `VkPhysicalDeviceShaderQuadControlFeaturesKHR`, /// `VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT`, + /// `VkPhysicalDeviceFragmentShaderBarycentricFeaturesKHR`, /// `VkPhysicalDeviceAttachmentFeedbackLoopLayoutFeaturesEXT`, /// `VkPhysicalDeviceAttachmentFeedbackLoopDynamicStateFeaturesEXT` or /// `VkPhysicalDeviceVertexAttributeDivisorFeaturesKHR`. diff --git a/crates/metal2vulkan-runtime/src/floor.rs b/crates/metal2vulkan-runtime/src/floor.rs index 3e84a4f64..bbd59ba53 100644 --- a/crates/metal2vulkan-runtime/src/floor.rs +++ b/crates/metal2vulkan-runtime/src/floor.rs @@ -101,6 +101,12 @@ pub const BORDER_SWIZZLE_EXTENSIONS: &[&CStr] = &[ ash::ext::border_color_swizzle::NAME, ]; +/// The device extension of a fragment function's `[[barycentric_coord]]` +/// (`VK_KHR_fragment_shader_barycentric`): device creation enables it, with its feature +/// ([`BARYCENTRICS`]), where the device lists it and reports the feature, and neither otherwise, +/// so [`Device::extensions`](crate::Device::extensions) names it only with its feature. +pub const BARYCENTRIC_EXTENSIONS: &[&CStr] = &[ash::khr::fragment_shader_barycentric::NAME]; + /// The translator's name for an extension device creation enables that its shaders may use, or /// that its description of the device must enable: the portability subset, where the device lists /// it. @@ -113,6 +119,8 @@ fn shader_extension(name: &CStr) -> Option { Some(VkExtension::KhrShaderQuadControl) } else if name == ash::ext::fragment_shader_interlock::NAME { Some(VkExtension::ExtFragmentShaderInterlock) + } else if name == ash::khr::fragment_shader_barycentric::NAME { + Some(VkExtension::KhrFragmentShaderBarycentric) } else if name == ash::ext::robustness2::NAME { Some(VkExtension::ExtRobustness2) } else if name == ash::khr::portability_subset::NAME { @@ -236,6 +244,10 @@ pub struct Features { /// `VK_EXT_fragment_shader_interlock`: read only where the device lists it, and then only /// `fragmentShaderPixelInterlock` enabled. pub interlock: vk::PhysicalDeviceFragmentShaderInterlockFeaturesEXT<'static>, + /// `VkPhysicalDeviceFragmentShaderBarycentricFeaturesKHR`, of + /// `VK_KHR_fragment_shader_barycentric`: read where the device lists it, and enabled where it + /// reports `fragmentShaderBarycentric` ([`BARYCENTRIC_EXTENSIONS`]). + pub barycentric: vk::PhysicalDeviceFragmentShaderBarycentricFeaturesKHR<'static>, /// `VkPhysicalDeviceRobustness2FeaturesEXT`, of `VK_EXT_robustness2`: `nullDescriptor` and /// `robustImageAccess2` are enabled, never the robust buffer access beside them. pub robustness2: vk::PhysicalDeviceRobustness2FeaturesEXT<'static>, @@ -301,6 +313,9 @@ macro_rules! feature { (@structure interlock) => { "VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT" }; + (@structure barycentric) => { + "VkPhysicalDeviceFragmentShaderBarycentricFeaturesKHR" + }; (@structure robustness2) => { "VkPhysicalDeviceRobustness2FeaturesEXT" }; @@ -524,6 +539,15 @@ pub(crate) const QUAD_CONTROL: &[Feature] = pub(crate) const PIXEL_INTERLOCK: &[Feature] = &[feature!(interlock.fragment_shader_pixel_interlock => FragmentShaderPixelInterlock)]; +/// The feature of `VK_KHR_fragment_shader_barycentric` ([`BARYCENTRIC_EXTENSIONS`]): enabled with +/// the extension where the device lists it and reports the feature, and neither otherwise. A +/// fragment function that reads `[[barycentric_coord]]` reads `BaryCoordKHR` or +/// `BaryCoordNoPerspKHR`, the one form the translator builds on the floor; on a device without +/// the feature the translator refuses the function (`Barycentrics`). No answer chooses a second +/// form. +pub(crate) const BARYCENTRICS: &[Feature] = + &[feature!(barycentric.fragment_shader_barycentric => FragmentShaderBarycentric)]; + /// The features of `VK_EXT_border_color_swizzle` ([`BORDER_SWIZZLE_EXTENSIONS`]): enabled together /// where the device lists the extensions and reports `borderColorSwizzleFromImage` (Vulkan requires /// `borderColorSwizzle` of a device that lists it), and neither otherwise. No answer chooses a second form, and the @@ -553,6 +577,7 @@ pub(crate) fn shader_enables(capabilities: &Capabilities) -> EnableSet { .chain(STEP_RATES) .chain(QUAD_CONTROL) .chain(PIXEL_INTERLOCK) + .chain(BARYCENTRICS) { if let Some(name) = feature.translator { if *(feature.field)(&mut features) == vk::TRUE { @@ -730,13 +755,15 @@ pub struct Capabilities { pub feedback_loop: bool, /// The features device creation enables: every one the floor requires, each of the optional, /// step-rate, quad-control, pixel-interlock and linear-attachment ones the device reports, the - /// attachment-read ones where [`feedback_loop`](Self::feedback_loop) holds, and the - /// border-swizzle ones where the device reports both. + /// attachment-read ones where [`feedback_loop`](Self::feedback_loop) holds, the border-swizzle + /// ones where the device reports both, and the barycentric one where the device lists its + /// extension and reports it. pub features: Features, /// The device extensions device creation enables: [`DEVICE_EXTENSIONS`], then each of /// [`OPTIONAL_EXTENSIONS`] the device lists, then [`ATTACHMENT_READ_EXTENSIONS`] where /// [`feedback_loop`](Self::feedback_loop) holds, then [`BORDER_SWIZZLE_EXTENSIONS`] where the - /// device lists them and reports both the border swizzle's features. + /// device lists them and reports both the border swizzle's features, then + /// [`BARYCENTRIC_EXTENSIONS`] where the device lists it and reports its feature. pub extensions: Vec<&'static CStr>, /// The first queue family with graphics and compute, whose timestamps the floor checked. pub queue_family: u32, @@ -836,6 +863,7 @@ unsafe fn query( listed(ash::khr::shader_subgroup_uniform_control_flow::NAME); let quad_control_listed = listed(ash::khr::shader_quad_control::NAME); let interlock_listed = listed(ash::ext::fragment_shader_interlock::NAME); + let barycentric_listed = listed(ash::khr::fragment_shader_barycentric::NAME); let robustness2_listed = listed(ash::ext::robustness2::NAME); let portability_listed = listed(ash::khr::portability_subset::NAME); let feedback_loop_listed = listed(ash::ext::attachment_feedback_loop_layout::NAME); @@ -856,6 +884,7 @@ unsafe fn query( subgroup_uniform_control_flow, quad_control, interlock, + barycentric, robustness2, portability, feedback_loop, @@ -881,6 +910,9 @@ unsafe fn query( if interlock_listed { features = features.push_next(&mut *interlock); } + if barycentric_listed { + features = features.push_next(&mut *barycentric); + } if robustness2_listed { features = features.push_next(&mut *robustness2); } @@ -914,6 +946,7 @@ unsafe fn query( subgroup_uniform_control_flow.p_next = std::ptr::null_mut(); quad_control.p_next = std::ptr::null_mut(); interlock.p_next = std::ptr::null_mut(); + barycentric.p_next = std::ptr::null_mut(); robustness2.p_next = std::ptr::null_mut(); portability.p_next = std::ptr::null_mut(); feedback_loop.p_next = std::ptr::null_mut(); @@ -1030,6 +1063,13 @@ pub(crate) fn decide(device: &Queried) -> Result { *(feature.field)(&mut features) = vk::TRUE; } } + let barycentric = BARYCENTRIC_EXTENSIONS.iter().all(|&name| listed(name)) + && (BARYCENTRICS.iter()).all(|feature| *(feature.field)(&mut reported) == vk::TRUE); + if barycentric { + for feature in BARYCENTRICS { + *(feature.field)(&mut features) = vk::TRUE; + } + } if listed(ash::nv::linear_color_attachment::NAME) { for feature in LINEAR_ATTACHMENTS { *(feature.field)(&mut features) = *(feature.field)(&mut reported); @@ -1060,6 +1100,7 @@ pub(crate) fn decide(device: &Queried) -> Result { ) .chain(ATTACHMENT_READ_EXTENSIONS.iter().filter(|_| feedback_loop)) .chain(BORDER_SWIZZLE_EXTENSIONS.iter().filter(|_| border_swizzle)) + .chain(BARYCENTRIC_EXTENSIONS.iter().filter(|_| barycentric)) .copied() .collect(), queue_family, diff --git a/crates/metal2vulkan-runtime/src/tests/barycentrics.rs b/crates/metal2vulkan-runtime/src/tests/barycentrics.rs new file mode 100644 index 000000000..d61a1136b --- /dev/null +++ b/crates/metal2vulkan-runtime/src/tests/barycentrics.rs @@ -0,0 +1,151 @@ +//! A fragment function that reads `[[barycentric_coord]]` (`floor`'s `BARYCENTRICS`), under a +//! device cfg on every device of the cfg's kind: where device creation enabled +//! `VK_KHR_fragment_shader_barycentric` with its feature, the device names the extension, the +//! translator's profile has `fragmentShaderBarycentric`, the state is made and each drawn pixel +//! reads Metal's weights; elsewhere the device names neither and creation refuses the state, +//! naming `Barycentrics`. +//! +//! `bw_vertex` (engine `bary_weights`) places a triangle whose three vertices have clip-space `w` +//! of 1, 2 and 4, so the perspective-correct weights (`bw_perspective`) and the linear ones +//! (`bw_linear`) differ at every drawn pixel; each writes its three weights. +//! +//! `llvm-as` assembles the functions; without it the test skips visibly. + +#[cfg(any(m2v_gpu, m2v_cpu_icd))] +mod on_device { + use crate::tests::command::on_device::each_device; + use crate::tests::draw::on_device::{floats, library, pass, read, run, target, Buffers, SIDE}; + use crate::{ + ColorAttachmentDescriptor, Error, FunctionDescriptor, PixelFormat, PrimitiveType, + RenderPipelineDescriptor, StageSource, TextureUsage, + }; + use metal2vulkan::device::VkFeature; + use metal2vulkan::error::Feature; + use metal2vulkan_devtools::engine_dir; + + /// The triangle's vertices in normalized device coordinates (y up), and each one's `w`. Its + /// long edge, `x + y = 0.125`, passes no pixel centre. + const CORNERS: [[f64; 2]; 3] = [[-1.0, -1.0], [1.125, -1.0], [-1.0, 1.125]]; + const W: [f64; 3] = [1.0, 2.0, 4.0]; + + /// The weights at pixel `[x, y]`'s centre, perspective-correct or linear, or None where the + /// centre is outside the triangle. + fn weights([x, y]: [u32; 2], perspective: bool) -> Option<[f64; 3]> { + let side = f64::from(SIDE); + let px = (2.0 * f64::from(x) + 1.0) / side - 1.0; + let py = 1.0 - (2.0 * f64::from(y) + 1.0) / side; + let [[ax, ay], [bx, _], [_, cy]] = CORNERS; + let b = (px - ax) / (bx - ax); + let c = (py - ay) / (cy - ay); + let linear = [1.0 - b - c, b, c]; + if linear.iter().any(|&weight| weight < 0.0) { + return None; + } + if !perspective { + return Some(linear); + } + let over = [0, 1, 2].map(|at| linear[at] / W[at]); + let sum: f64 = over.iter().sum(); + Some(over.map(|weight| weight / sum)) + } + + /// Where Vulkan offers `fragmentShaderBarycentric`, a fragment function's weights are Metal's, + /// perspective-correct and linear; elsewhere the state is refused naming the feature, and the + /// device names no barycentric extension. + #[test] + fn every_device_reads_metal_s_weights_where_it_offers_barycentrics() { + let Some(weights_library) = library(&engine_dir().join("bary_weights.ll")) else { + return; + }; + let function = |name| { + StageSource::Function(FunctionDescriptor::new( + weights_library.function(name).expect("the function"), + )) + }; + let descriptor = |fragment| { + let mut d = RenderPipelineDescriptor::new(function("bw_vertex")); + d.fragment = Some(function(fragment)); + d.color_attachments[0] = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA32Float)); + d + }; + let clip: Vec = (CORNERS.iter().zip(W)) + .flat_map(|(&[x, y], w)| [x * w, y * w, 0.0, w].map(|v| v as f32)) + .collect(); + each_device("barycentrics", |name, _, device| { + // The device names the extension only where device creation enabled its feature, and + // the translator's profile has the feature exactly there. + let listed = (device.extensions().iter()) + .any(|enabled| enabled.as_c_str() == ash::khr::fragment_shader_barycentric::NAME); + let core = device.core(); + let enabled = &core.translator.profile().enabled().features; + let on = enabled.contains(&VkFeature::FragmentShaderBarycentric); + assert_eq!( + listed, on, + "{name}: the extension named and the feature enabled" + ); + let mut drawn = 0; + for (fragment, perspective) in [("bw_perspective", true), ("bw_linear", false)] { + let state = match device.new_render_pipeline_state( + &descriptor(fragment), + crate::tests::no_constexpr_samplers, + ) { + Ok(state) => state, + Err(Error::Translation(metal2vulkan::error::Error::Unsupported(u))) if !on => { + assert_eq!(u.feature, Feature::Barycentrics, "{name}: {u:?}"); + println!( + "barycentrics: {name}: no fragmentShaderBarycentric; {fragment}'s \ + state is refused" + ); + continue; + } + Err(error) => panic!("{name}: {fragment}: {error}"), + }; + assert!(on, "{name}: {fragment}'s state made without the feature"); + let mut buffers = Buffers::new(&device); + let positions = buffers.of(&device, &floats(&clip)); + let color = target( + &device, + PixelFormat::RGBA32Float, + TextureUsage::RENDER_TARGET, + ); + let queue = device.new_command_queue(4).expect("a queue"); + let command_buffer = queue.command_buffer().expect("a command buffer"); + let ok = |result: Result<(), Error>| { + result.unwrap_or_else(|error| panic!("{name}: {fragment}: {error}")) + }; + let mut encoder = (command_buffer.render_command_encoder(&pass(&color, None))) + .unwrap_or_else(|error| panic!("{name}: {error}")); + ok(encoder.set_render_pipeline_state(&state)); + ok(encoder.set_vertex_buffer(Some(&positions), 0, 0)); + ok(encoder.draw_primitives(PrimitiveType::Triangle, 0, 3, 1, 0)); + encoder.end_encoding(); + run(name, &command_buffer); + let texels = read(&color, 16); + for y in 0..SIDE { + for x in 0..SIDE { + let Some(want) = weights([x, y], perspective) else { + continue; + }; + let at = ((y * SIDE + x) * 16) as usize; + let got: Vec = (texels[at..at + 12].as_chunks::<4>().0.iter()) + .map(|w| f32::from_le_bytes(*w)) + .collect(); + assert!( + (got.iter().zip(want)) + .all(|(&got, want)| (f64::from(got) - want).abs() < 1e-4), + "{name}: {fragment}: pixel [{x}, {y}] reads {got:?}, Metal's weights \ + are {want:?}" + ); + drawn += 1; + } + } + } + if on { + println!( + "barycentrics: {name}: fragmentShaderBarycentric enabled; {drawn} pixels read \ + Metal's weights, perspective-correct and linear" + ); + } + }); + } +} diff --git a/crates/metal2vulkan-runtime/src/tests/device.rs b/crates/metal2vulkan-runtime/src/tests/device.rs index d7dfd5d9d..b523ff70f 100644 --- a/crates/metal2vulkan-runtime/src/tests/device.rs +++ b/crates/metal2vulkan-runtime/src/tests/device.rs @@ -352,6 +352,14 @@ fn every_device_of_the_cfgs_kind_enables_the_consumers_extensions_it_offers() { unsafe { vk_instance.get_physical_device_features2(physical.raw(), &mut features) }; } let from_image = swizzles.border_color_swizzle_from_image == vk::TRUE; + // So is the barycentric one. + let mut weights = vk::PhysicalDeviceFragmentShaderBarycentricFeaturesKHR::default(); + if lists(ash::khr::fragment_shader_barycentric::NAME) { + let mut features = vk::PhysicalDeviceFeatures2::default().push_next(&mut weights); + // SAFETY: as above; `weights` lives through the call. + unsafe { vk_instance.get_physical_device_features2(physical.raw(), &mut features) }; + } + let barycentric = weights.fragment_shader_barycentric == vk::TRUE; let mut asked = vec![ DeviceExtension::new(missing), @@ -390,6 +398,10 @@ fn every_device_of_the_cfgs_kind_enables_the_consumers_extensions_it_offers() { if from_image { expected.extend(floor::BORDER_SWIZZLE_EXTENSIONS); } + // The barycentric one, where the device reports its feature. + if barycentric { + expected.extend(floor::BARYCENTRIC_EXTENSIONS); + } if maintenance && offered { expected.push(swapchain); } diff --git a/crates/metal2vulkan-runtime/src/tests/floor.rs b/crates/metal2vulkan-runtime/src/tests/floor.rs index 1ccdd8d6c..eecdbf439 100644 --- a/crates/metal2vulkan-runtime/src/tests/floor.rs +++ b/crates/metal2vulkan-runtime/src/tests/floor.rs @@ -4,11 +4,11 @@ use crate::floor::{ choose, decide, flag_names, limits, vulkan_name, BelowFloor, Features, MemoryTypes, Missing, - Queried, ATTACHMENT_READS, ATTACHMENT_READ_EXTENSIONS, BORDER_SWIZZLE, - BORDER_SWIZZLE_EXTENSIONS, DEVICE_EXTENSIONS, INSTANCE_EXTENSIONS, LINEAR_ATTACHMENTS, - MEMORY_FLAG_NAMES, OPTIONAL, OPTIONAL_EXTENSIONS, OPTIONAL_INSTANCE_EXTENSIONS, - PIXEL_INTERLOCK, PORTABILITY, PRIVATE_MEMORY, QUAD_CONTROL, REQUIRED, RING_MEMORY, - SHARED_MEMORY, STEP_RATES, TIMESTAMP_BITS, TIME_DOMAINS, VERSION, + Queried, ATTACHMENT_READS, ATTACHMENT_READ_EXTENSIONS, BARYCENTRICS, BARYCENTRIC_EXTENSIONS, + BORDER_SWIZZLE, BORDER_SWIZZLE_EXTENSIONS, DEVICE_EXTENSIONS, INSTANCE_EXTENSIONS, + LINEAR_ATTACHMENTS, MEMORY_FLAG_NAMES, OPTIONAL, OPTIONAL_EXTENSIONS, + OPTIONAL_INSTANCE_EXTENSIONS, PIXEL_INTERLOCK, PORTABILITY, PRIVATE_MEMORY, QUAD_CONTROL, + REQUIRED, RING_MEMORY, SHARED_MEMORY, STEP_RATES, TIMESTAMP_BITS, TIME_DOMAINS, VERSION, }; use ash::vk; use std::collections::BTreeSet; @@ -331,6 +331,7 @@ fn a_device_at_the_floor_is_above_it() { for optional in (OPTIONAL.iter().chain(STEP_RATES)) .chain(QUAD_CONTROL) .chain(PIXEL_INTERLOCK) + .chain(BARYCENTRICS) { assert!(!holds(enabled, optional), "{} is enabled", optional.member); } @@ -1213,6 +1214,49 @@ fn quad_control_is_enabled_where_reported() { .contains(&VkExtension::KhrShaderQuadControl)); } +/// A device that lists `VK_KHR_fragment_shader_barycentric` and reports +/// `fragmentShaderBarycentric` is given both, and the translator sees both; one that lists the +/// extension without the feature, or reports the feature without listing it, is given neither, so +/// the extension is named among those enabled only with its feature. +#[test] +fn barycentrics_are_enabled_where_listed_and_reported() { + use crate::floor::shader_enables; + use metal2vulkan::device::{VkExtension, VkFeature}; + let extension = ash::khr::fragment_shader_barycentric::NAME; + let answer = |device: &Queried| { + let capabilities = decide(device).unwrap_or_else(|below| panic!("{below}")); + let enables = shader_enables(&capabilities); + let enabled = capabilities.extensions.contains(&extension); + let feature = BARYCENTRICS + .iter() + .all(|feature| holds(&capabilities.features, feature)); + assert_eq!( + enables + .extensions + .contains(&VkExtension::KhrFragmentShaderBarycentric), + enabled, + "the translator's extension" + ); + assert_eq!( + enables + .features + .contains(&VkFeature::FragmentShaderBarycentric), + feature, + "the translator's feature" + ); + (enabled, feature) + }; + let mut device = at_the_floor(); + assert_eq!(answer(&device), (false, false), "at the floor"); + device.extensions.push(extension.to_owned()); + assert_eq!(answer(&device), (false, false), "listed, not reported"); + device.features.barycentric.fragment_shader_barycentric = vk::TRUE; + assert_eq!(answer(&device), (true, true), "listed and reported"); + let mut device = at_the_floor(); + device.features.barycentric.fragment_shader_barycentric = vk::TRUE; + assert_eq!(answer(&device), (false, false), "reported, not listed"); +} + /// A device that lists `VK_EXT_border_color_swizzle` and reports `borderColorSwizzleFromImage` is /// given the extension, `VK_EXT_custom_border_color` (which it requires: Vulkan's /// `VUID-vkCreateDevice-ppEnabledExtensionNames-01387`), and both its features; one that lists it @@ -1513,6 +1557,11 @@ fn the_readme_states_the_floor() { .iter() .map(|name| (name, "device, where reported from the image")), ) + .chain( + BARYCENTRIC_EXTENSIONS + .iter() + .map(|name| (name, "device, where reported")), + ) .map(|(name, place)| (name.to_string_lossy().into_owned(), place.to_string())) .collect(); assert_eq!(stated, code, "the README's extensions"); @@ -1537,6 +1586,10 @@ fn the_readme_states_the_floor() { ["Pixel-interlock feature", "Structure", "Used for"], PIXEL_INTERLOCK, ), + ( + ["Barycentric feature", "Structure", "Used for"], + BARYCENTRICS, + ), ( ["Border-swizzle feature", "Structure", "Used for"], BORDER_SWIZZLE, @@ -1717,6 +1770,7 @@ fn every_device_the_loader_lists_is_above_the_floor() { mut subgroup_uniform_control_flow, mut quad_control, mut interlock, + mut barycentric, mut robustness2, mut portability, mut feedback_loop, @@ -1746,6 +1800,9 @@ fn every_device_the_loader_lists_is_above_the_floor() { if enabled(ash::ext::fragment_shader_interlock::NAME) { features = features.push_next(&mut interlock); } + if enabled(ash::khr::fragment_shader_barycentric::NAME) { + features = features.push_next(&mut barycentric); + } if enabled(ash::khr::portability_subset::NAME) { features = features.push_next(&mut portability); } diff --git a/crates/metal2vulkan-runtime/src/tests/mod.rs b/crates/metal2vulkan-runtime/src/tests/mod.rs index befbdaaf9..6e684ab4f 100644 --- a/crates/metal2vulkan-runtime/src/tests/mod.rs +++ b/crates/metal2vulkan-runtime/src/tests/mod.rs @@ -4,6 +4,7 @@ mod alpha_test; mod argument_sampling; mod argument_tier; mod arrays; +mod barycentrics; mod bicubic; mod bicubic_draw; mod blit; diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index 4940e08c2..19737275d 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -466,6 +466,7 @@ const metal2vulkan-runtime::HOST_DOMAIN #[cfg(windows)] pub const HOST_DOMAIN: v const metal2vulkan-runtime::MAX_BUFFER_LENGTH pub const MAX_BUFFER_LENGTH: u64 const metal2vulkan-runtime::MAX_COLOR_ATTACHMENTS pub const MAX_COLOR_ATTACHMENTS: usize const metal2vulkan-runtime::floor::ATTACHMENT_READ_EXTENSIONS pub const ATTACHMENT_READ_EXTENSIONS: &[&CStr] +const metal2vulkan-runtime::floor::BARYCENTRIC_EXTENSIONS pub const BARYCENTRIC_EXTENSIONS: &[&CStr] const metal2vulkan-runtime::floor::BORDER_SWIZZLE_EXTENSIONS pub const BORDER_SWIZZLE_EXTENSIONS: &[&CStr] const metal2vulkan-runtime::floor::BUFFER_USAGE pub const BUFFER_USAGE: vk::BufferUsageFlags const metal2vulkan-runtime::floor::DEVICE_EXTENSIONS pub const DEVICE_EXTENSIONS: &[&CStr] @@ -560,6 +561,7 @@ const-value metal2vulkan-runtime::HOST_DOMAIN vk::TimeDomainKHR::QUERY_PERFORMAN const-value metal2vulkan-runtime::MAX_BUFFER_LENGTH 1 <<31 const-value metal2vulkan-runtime::MAX_COLOR_ATTACHMENTS 8 const-value metal2vulkan-runtime::floor::ATTACHMENT_READ_EXTENSIONS &[ash::ext::attachment_feedback_loop_layout::NAME, ash::ext::attachment_feedback_loop_dynamic_state::NAME] +const-value metal2vulkan-runtime::floor::BARYCENTRIC_EXTENSIONS &[ash::khr::fragment_shader_barycentric::NAME] const-value metal2vulkan-runtime::floor::BORDER_SWIZZLE_EXTENSIONS &[ash::ext::custom_border_color::NAME, ash::ext::border_color_swizzle::NAME] const-value metal2vulkan-runtime::floor::BUFFER_USAGE vk::BufferUsageFlags::from_raw(vk::BufferUsageFlags::TRANSFER_SRC.as_raw() | vk::BufferUsageFlags::TRANSFER_DST.as_raw() | vk::BufferUsageFlags::UNIFORM_TEXEL_BUFFER.as_raw() | vk::BufferUsageFlags::STORAGE_TEXEL_BUFFER.as_raw() | vk::BufferUsageFlags::UNIFORM_BUFFER.as_raw() | vk::BufferUsageFlags::STORAGE_BUFFER.as_raw() | vk::BufferUsageFlags::INDEX_BUFFER.as_raw() | vk::BufferUsageFlags::VERTEX_BUFFER.as_raw() | vk::BufferUsageFlags::INDIRECT_BUFFER.as_raw() | vk::BufferUsageFlags::SHADER_DEVICE_ADDRESS.as_raw()) const-value metal2vulkan-runtime::floor::DEVICE_EXTENSIONS &[ash::khr::swapchain::NAME, ash::ext::robustness2::NAME, ash::ext::calibrated_timestamps::NAME, ash::ext::line_rasterization::NAME] @@ -1921,6 +1923,7 @@ field metal2vulkan-runtime::floor::Capabilities.queue_family pub queue_family: u field metal2vulkan-runtime::floor::Capabilities.shared_int64_atomics pub shared_int64_atomics: bool field metal2vulkan-runtime::floor::Capabilities.storage_read_without_format pub storage_read_without_format: bool field metal2vulkan-runtime::floor::Capabilities.subgroup_uniform_control_flow pub subgroup_uniform_control_flow: bool +field metal2vulkan-runtime::floor::Features.barycentric pub barycentric: vk::PhysicalDeviceFragmentShaderBarycentricFeaturesKHR<'static> field metal2vulkan-runtime::floor::Features.border_swizzle pub border_swizzle: vk::PhysicalDeviceBorderColorSwizzleFeaturesEXT<'static> field metal2vulkan-runtime::floor::Features.core pub core: vk::PhysicalDeviceFeatures field metal2vulkan-runtime::floor::Features.divisor pub divisor: vk::PhysicalDeviceVertexAttributeDivisorFeaturesKHR<'static>