diff --git a/crates/metal2vulkan/src/lower/mesh/mod.rs b/crates/metal2vulkan/src/lower/mesh/mod.rs index 0b4afcce0..95704f09d 100644 --- a/crates/metal2vulkan/src/lower/mesh/mod.rs +++ b/crates/metal2vulkan/src/lower/mesh/mod.rs @@ -624,7 +624,9 @@ pub fn plan_entry(cx: &mut SelectCx<'_>) -> Result<(), Error> { .vertex .iter() .any(|f| matches!(f.role, MeshFieldRole::PointSize) && !f.gated_off); - if point_size { + // The rasterizer reads a vertex's size for points alone: a line or triangle mesh's size draws + // nothing, whatever the device's largest point. + if point_size && shape.topology == MeshTopology::Point { crate::lower::stage_io::note_device_point_size(cx); } // Staged indices are the wrapper's workgroup words, held to the stage's limit whether or not diff --git a/crates/metal2vulkan/src/pipeline/artifact.rs b/crates/metal2vulkan/src/pipeline/artifact.rs index 9e0582e3c..5ad8e5b15 100644 --- a/crates/metal2vulkan/src/pipeline/artifact.rs +++ b/crates/metal2vulkan/src/pipeline/artifact.rs @@ -1564,8 +1564,9 @@ pub enum PrecisionNote { /// function does not know, is refused there (`SamplerAnisotropy`). Validation derives no /// tolerance from it. DeviceAnisotropicFilter, - /// A vertex function writes `[[point_size]]`, or a mesh function `set_point_size`, on a device - /// whose `pointSizeRange` ends below Metal's largest point, 511 pixels + /// A vertex function writes `[[point_size]]`, or a mesh function that outputs points + /// `set_point_size` (a line or triangle mesh's size draws nothing, and records no note), on a + /// device whose `pointSizeRange` ends below Metal's largest point, 511 pixels /// ([`Limits::max_point_size`](crate::device::Limits::max_point_size): 255 on ANV, 256 on /// lavapipe). The module stores a size past 511 as 511, as Metal draws it, and the device /// clamps a size past its own bound to that bound, so a point between the device's bound and diff --git a/crates/metal2vulkan/src/tests/engine_mesh.rs b/crates/metal2vulkan/src/tests/engine_mesh.rs index dd4070d0c..5df37c495 100644 --- a/crates/metal2vulkan/src/tests/engine_mesh.rs +++ b/crates/metal2vulkan/src/tests/engine_mesh.rs @@ -597,6 +597,58 @@ fn a_mesh_point_size_past_metals_largest_point_is_stored_as_it() { } } +/// A mesh function's `set_point_size` records `PrecisionNote::DevicePointSize` only where the mesh +/// outputs points: the rasterizer reads a vertex's size for points alone, so a line or triangle +/// mesh's size draws nothing, whatever the device's largest point. Apple's compiler refuses +/// `[[point_size]]` in a triangle mesh's vertex, so the triangle mesh is `mesh_outputs_points` +/// with its type's topology (`air.mesh_type_info`) made `air.triangle`, every other word of the +/// module kept. On every profile with mesh shading, its largest point set below Metal's, both +/// functions store the size and only the point mesh records the note. +#[test] +fn a_mesh_point_size_is_noted_only_where_the_mesh_outputs_points() { + use crate::device::{Device, DeviceDescription, DevicePolicy}; + use crate::pipeline::artifact::PrecisionNote; + let text = std::fs::read_to_string(engine_dir().join("mesh_outputs.ll")).expect("fixture"); + let point = "!\"air.point\"}"; + assert_eq!(text.matches(point).count(), 1, "one point mesh type"); + let mut modules = Vec::new(); + for (topology, text) in [ + ("points", text.clone()), + ("triangles", text.replace(point, "!\"air.triangle\"}")), + ] { + match crate::pipeline::testing::llvm_assemble_text(&text) { + Ok(bitcode) => modules.push((topology, bitcode)), + Err(AssembleError::Missing(why)) => { + eprintln!("SKIPPED: {why}"); + return; + } + Err(AssembleError::Rejected(why)) => panic!("llvm-as rejected {topology}: {why}"), + } + } + for (stem, _) in &mesh_profiles() { + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .join(format!("../metal2vulkan-validation/profiles/{stem}.json")); + let text = std::fs::read_to_string(path).expect("profile"); + let mut desc = DeviceDescription::from_khronos_json(&text, None).expect("description"); + desc.limits.max_point_size = 64; + let dev = Device::new(desc, DevicePolicy::default()).expect("device"); + for (topology, bitcode) in &modules { + let a = compile(bitcode, "mesh_outputs_points", dev.profile()) + .unwrap_or_else(|e| panic!("{stem} {topology}: {e}")); + let stores = super::engine_stage_io::point_size_stores(&a.module.words); + assert!( + stores.contains(&Some(true)), + "{stem} {topology}: the written size is stored: {stores:?}" + ); + assert_eq!( + a.precision.contains(&PrecisionNote::DevicePointSize), + *topology == "points", + "{stem} {topology}: the device's largest point is noted for points alone" + ); + } + } +} + /// A device of committed profile `stem`. pub(super) fn device(stem: &str) -> crate::device::Device { use crate::device::{Device, DeviceDescription, DevicePolicy}; diff --git a/docs/API.md b/docs/API.md index adacf1251..07de18b6d 100644 --- a/docs/API.md +++ b/docs/API.md @@ -3993,11 +3993,13 @@ bound. sampler slot whose word states anisotropy (under that word alone). An argument buffer's anisotropic sampler, which the function cannot record, is refused there (`SamplerAnisotropy`). - `metal2vulkan-degrade-device-point-size` (precision). `PrecisionNote::DevicePointSize`: A vertex - function writes `[[point_size]]`, or a mesh function `set_point_size`, on a device whose - `pointSizeRange` ends below Metal's largest point, 511 pixels (`Limits::max_point_size`: 255 on - ANV, 256 on lavapipe). Announced at the first draw of such a pipeline that rasterizes points: a - draw of `MTLPrimitiveTypePoint`, or a mesh draw whose mesh function outputs points. A draw of - lines or triangles of the same pipeline is Metal's exactly and announces nothing. + function writes `[[point_size]]`, or a mesh function that outputs points `set_point_size`, on a + device whose `pointSizeRange` ends below Metal's largest point, 511 pixels + (`Limits::max_point_size`: 255 on ANV, 256 on lavapipe). A line or triangle mesh's size draws + nothing, and its function records no note. Announced at the first draw of such a pipeline that + rasterizes points: a draw of `MTLPrimitiveTypePoint`, or a mesh draw of a mesh function that + outputs points. A draw of lines or triangles of the same pipeline is Metal's exactly and + announces nothing. - `metal2vulkan-degrade-clipped-coverage-split` (precision). `PrecisionNote::ClippedCoverageSplit`: A fragment function compiled for a multisampled pipeline reads `[[sample_mask]]` on a device whose rasterizer is not Apple's (`DriverWorkaround::ClippedCoverageNotMetals`): Apple's GPU draws a