From 5f4c55cf45b7e8371c77406a60b00906e82bbba2 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Wed, 2 Dec 2026 14:27:22 -0800 Subject: [PATCH] rt test: a fragment function's primitive id behind a post-tessellation function is its patch's position (red) The owned fixture tess_primitive_ids (MSL we wrote, its companions regenerated on the Mac, job m3-max-80275) is a post-tessellation vertex function (triangle patches of three control points, no stage-in) that places patch pid of instance iid in its own tile of an 8x8 target and passes pid and iid flat, and a fragment function that writes [[primitive_id]], pid, iid and 1. Metal's answer, read on an Apple M3 Max (job m3-max-80266, the same shape at 64x32, every factor 4 with the integer partition): every fragment of every triangle of a patch reads one value, the patch's position in its draw, patch start included, the same in each instance. A draw of two patches from patch 0 over two instances reads 0 and 1 in both; a draw of two patches from patch 2 reads 2 and 3. Vulkan's PrimitiveId behind an evaluation stage counts the draw's patches from 0 and restarts in each instance, so it reads 0 and 1 for the second draw. every_device_reads_a_patch_s_position_as_its_fragments_primitive_id draws both in one pass and checks every covered texel of each drawn tile, and that the tiles no patch draws stay clear. Today the translator refuses the pipeline: Tessellation, NotImplemented, at link (a fragment function that reads [[primitive_id]] behind an evaluation stage). Red on lavapipe (llvmpipe), job m3-max-80279: "Tessellation; needs NotImplemented" for the state; the control draw passes. --- .../metal2vulkan-runtime/src/tests/patch.rs | 96 +++++++++++++++++++ .../fixtures/public/engine/README.md | 1 + .../fixtures/public/engine/TOOLCHAIN | 1 + .../public/engine/tess_primitive_ids.air.ll | 84 ++++++++++++++++ .../public/engine/tess_primitive_ids.ll | 84 ++++++++++++++++ .../public/engine/tess_primitive_ids.metal | 33 +++++++ 6 files changed, 299 insertions(+) create mode 100644 crates/metal2vulkan-validation/fixtures/public/engine/tess_primitive_ids.air.ll create mode 100644 crates/metal2vulkan-validation/fixtures/public/engine/tess_primitive_ids.ll create mode 100644 crates/metal2vulkan-validation/fixtures/public/engine/tess_primitive_ids.metal diff --git a/crates/metal2vulkan-runtime/src/tests/patch.rs b/crates/metal2vulkan-runtime/src/tests/patch.rs index ef74e7808..e43b4855e 100644 --- a/crates/metal2vulkan-runtime/src/tests/patch.rs +++ b/crates/metal2vulkan-runtime/src/tests/patch.rs @@ -27,6 +27,9 @@ //! - the owned fixture `engine/rvc_draw_bases.ll`'s `draw_bases_after_tessellation`, its state's //! rasterization disabled: each patch of each instance of a draw from a base instance of 3, //! direct and indirect, writes its patch id, its instance id and the draw's base instance. +//! - the owned fixture `engine/tess_primitive_ids.ll`: a fragment function's `[[primitive_id]]` +//! behind a post-tessellation function reads its patch's position in the draw, patch start +//! included, in every instance. //! //! `llvm-as` assembles the fixtures; without it a device test skips visibly. @@ -653,6 +656,99 @@ BUFFER_META"#; }); } + /// A fragment function reads `[[primitive_id]]` behind a post-tessellation function (the owned + /// fixture `engine/tess_primitive_ids.ll`, into an `RGBA32Uint` target): Metal's value there + /// is the patch's position in its draw, patch start included, the same in every instance, for + /// every fragment of every triangle the tessellator makes of the patch (an Apple M3 Max, every + /// factor 4). One pass draws two patches of two instances from patch 0, then two patches of + /// one instance from patch 2. Patch `pid` of instance `iid` covers part of the tile at column + /// `pid % 4`, two pixels wide, and row `iid % 2`, four high, writing (`[[primitive_id]]`, + /// `pid`, `iid`, 1): every covered texel of each drawn tile holds its patch's position, and + /// the tiles no patch draws stay clear. Vulkan's `PrimitiveId` counts a draw's patches from 0 + /// in each instance, which the second draw's tiles tell apart. + #[test] + fn every_device_reads_a_patch_s_position_as_its_fragments_primitive_id() { + let Some(engine) = library(&engine_dir().join("tess_primitive_ids.ll")) else { + return; + }; + let function = |name| { + StageSource::Function(FunctionDescriptor::new( + engine.function(name).expect("the function"), + )) + }; + let mut d = RenderPipelineDescriptor::new(function("tess_primitive_ids")); + d.fragment = Some(function("tess_primitive_ids_fragment")); + d.color_attachments[0] = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA32Uint)); + let mut t = TessellationDescriptor::default(); + t.factor_step_function = TessellationFactorStepFunction::PerPatch; + t.partition_mode = TessellationPartitionMode::Integer; + t.max_tessellation_factor = 16; + d.tessellation = Some(t); + each_device("draw_patches_primitive_ids", |name, _, device| { + let state = state(name, &device, &d); + let mut buffers = Buffers::new(&device); + let factor_bytes: Vec = (0..4).flat_map(|_| factors([FOUR; 3], FOUR)).collect(); + let factors = buffers.of(&device, &factor_bytes); + let color = target( + &device, + PixelFormat::RGBA32Uint, + TextureUsage::RENDER_TARGET, + ); + let queue = device.new_command_queue(4).expect("a queue"); + let command_buffer = queue.command_buffer().expect("a command buffer"); + // Cleared to 0 in every channel: each fragment writes 1 to the last. + let mut cleared = pass(&color, None); + cleared.color_attachments[0].clear_color = crate::ClearColor::new(0.0, 0.0, 0.0, 0.0); + let mut encoder = (command_buffer.render_command_encoder(&cleared)) + .unwrap_or_else(|error| panic!("{name}: {error}")); + let draw = |result: Result<(), Error>| result.unwrap_or_else(|e| panic!("{name}: {e}")); + draw(encoder.set_render_pipeline_state(&state)); + draw(encoder.set_tessellation_factor_buffer(Some(&factors), 0, 0)); + draw(encoder.draw_patches(3, 0, 2, None, 2, 0)); + draw(encoder.draw_patches(3, 2, 2, None, 1, 0)); + encoder.end_encoding(); + run(name, &command_buffer); + let bytes = read(&color, 16); + let words: Vec = bytes + .as_chunks::<4>() + .0 + .iter() + .map(|w| u32::from_le_bytes(*w)) + .collect(); + for column in 0..4u32 { + for row in 0..2u32 { + let drawn = column < 2 || row == 0; + let mut covered = 0; + for y in row * 4..row * 4 + 4 { + for x in column * 2..column * 2 + 2 { + let at = 4 * (y * SIDE + x) as usize; + let texel = &words[at..at + 4]; + if texel == [0; 4] { + continue; + } + assert!( + drawn, + "{name}: tile ({column}, {row}) at ({x}, {y}): {texel:?}" + ); + assert_eq!( + texel, + [column, column, row, 1], + "{name}: tile ({column}, {row}) at ({x}, {y})" + ); + covered += 1; + } + } + assert_eq!( + covered > 0, + drawn, + "{name}: tile ({column}, {row}) covered {covered}" + ); + } + } + println!("{name}: every fragment of each patch read the patch's position as its primitive id"); + }); + } + /// A post-tessellation function whose fields pass its push window ([`wide_vertex`]) spills /// the rest into its parameter block, which each draw writes into the ring and the function /// reads: the pipeline's control stage, whose fields the translator states as a second diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/README.md b/crates/metal2vulkan-validation/fixtures/public/engine/README.md index 43933a260..9983e7da3 100644 --- a/crates/metal2vulkan-validation/fixtures/public/engine/README.md +++ b/crates/metal2vulkan-validation/fixtures/public/engine/README.md @@ -106,6 +106,7 @@ threadgroup's threads); an authored case that executes a loop declares it | `k7_tess_quad_domain` | `k7_tess_quad_domain` | a quad patch's domain points with rasterization disabled: each marks the word of cell `(rint(u * grid.x), rint(v * grid.y))` in a 65 x 65 grid (`grid` a per-patch attribute) and stores its coordinates after the grid; every store is idempotent | the set of marked cells, which is the tessellator's set of points: each edge's and the inside grid's segment count and placement under the case's factors and partition mode. The cases observe the marks only; the coordinates are there for diagnosis (partition-mode and edge-and-inside cases) | | `k7_tess_triangle_domain` | `k7_tess_triangle_domain` | the same for a triangle patch, the cell of the first two barycentric coordinates, all three stored after the grid | as `k7_tess_quad_domain` (fractional-partition and edge-and-inside cases) | | `tess_rendered_patches` | `tess_rendered_patches`, `tess_rendered_patches_fragment` | a triangle patch drawn into a colour target: three control points through the vertex descriptor (a clip-space `float2` each), each domain point at its barycentric blend of them, and a per-patch colour passed flat, which the fragment function writes | a pixel says which patch covers it, if any: culled factors, which patch's factors and attributes a draw read, and the winding a cull mode sees (the conformance case `tessellation-rendered-patches`) | +| `tess_primitive_ids` | `tess_primitive_ids`, `tess_primitive_ids_fragment` | a triangle patch of three control points with no stage-in, placing patch `pid` of instance `iid` in its own tile of an 8x8 target (column `pid % 4`, two pixels wide; row `iid % 2`, four high) and passing `pid` and `iid` flat; a fragment function writing `[[primitive_id]]`, `pid`, `iid` and 1 | a fragment's `[[primitive_id]]` behind a post-tessellation function is its patch's position in the draw, patch start included, the same in every instance and for every triangle of the patch (an Apple M3 Max, every factor 4); the runtime's `every_device_reads_a_patch_s_position_as_its_fragments_primitive_id` draws it | | `nil_slots` | `nil_vertex`, `nil_post_tess`, `nil_fragment` | a plain draw and a triangle patch draw whose vertex, post-tessellation and fragment functions each read and query the width, height and levels of texture slot 0 (which they also sample) and of an argument buffer's four textures, writing one record each: texture slot 0 bound to nil, IDs of 0, of a granted index no texture took, of a texture that went, and of a live texture; the post-tessellation function also records its three control points and its patch's tint | every command buffer completes, and the live texture's texel and size, the control points, the tint and the stage words are exact in every stage of both draws (the runtime's device test `every_stage_runs_its_live_work_beside_texture_slots_that_hold_no_texture`); what a member function of a nil texture returns is undefined (Metal Shading Language, section 6.13.18) and not held | | `exf_fetch_blend` | `exf_fetch_blend` | programmable blending, `(float4(position.xy, 1, -0.5) + dst) / 2` over the color attachment it reads (one rounded sum, nothing contracts) | after `n` instances of the fullscreen triangle each pixel holds the blend applied `n` times in order (overlapping-fragment ordering cases) | | `exf_fetch_count` | `exf_fetch_count` | an integer read-modify-write, `count * 3 + (1, 2, 3, 4)` (wrapping) | after `n` ordered instances lane `k` holds `c * 3^n + (k + 1) * (3^n - 1) / 2` | diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/TOOLCHAIN b/crates/metal2vulkan-validation/fixtures/public/engine/TOOLCHAIN index 1977e17d4..75d9b4c4c 100644 --- a/crates/metal2vulkan-validation/fixtures/public/engine/TOOLCHAIN +++ b/crates/metal2vulkan-validation/fixtures/public/engine/TOOLCHAIN @@ -395,6 +395,7 @@ fixture tail_argument_cube_gradient: metal: Apple metal version 32023.921 (metal fixture tail_argument_samplers: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425) fixture tail_argument_sparse_samples: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118) fixture tail_cases: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425) +fixture tess_primitive_ids: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118) fixture tess_rendered_patches: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118) fixture tgp_composite: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425) fixture tgz_reads: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118) diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/tess_primitive_ids.air.ll b/crates/metal2vulkan-validation/fixtures/public/engine/tess_primitive_ids.air.ll new file mode 100644 index 000000000..dd0805d69 --- /dev/null +++ b/crates/metal2vulkan-validation/fixtures/public/engine/tess_primitive_ids.air.ll @@ -0,0 +1,84 @@ +; Generated by scripts/regen-air-fixtures from tess_primitive_ids.metal (typed pointers; xcrun metal-as reassembles it). Do not edit. +; ModuleID = '-' +source_filename = "-" +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32" +target triple = "air64_v28-apple-macosx26.0.0" + +; Function Attrs: mustprogress nofree nosync nounwind readnone willreturn +define <{ <4 x float>, i32, i32 }> @tess_primitive_ids(i32 noundef %0, i32 noundef %1, <3 x float> noundef %2) local_unnamed_addr #0 { + %4 = and i32 %0, 3 + %5 = tail call fast float @air.convert.f.f32.u.i32(i32 %4) #3 + %6 = extractelement <3 x float> %2, i64 1 + %7 = fadd fast float %5, %6 + %8 = and i32 %1, 1 + %9 = tail call fast float @air.convert.f.f32.u.i32(i32 %8) #3 + %10 = extractelement <3 x float> %2, i64 2 + %11 = fmul fast float %7, 5.000000e-01 + %12 = fadd fast float %11, -1.000000e+00 + %13 = fadd fast float %10, %9 + %14 = fsub fast float 1.000000e+00, %13 + %15 = insertelement <4 x float> , float %12, i64 0 + %16 = insertelement <4 x float> %15, float %14, i64 1 + %17 = insertvalue <{ <4 x float>, i32, i32 }> undef, <4 x float> %16, 0 + %18 = insertvalue <{ <4 x float>, i32, i32 }> %17, i32 %0, 1 + %19 = insertvalue <{ <4 x float>, i32, i32 }> %18, i32 %1, 2 + ret <{ <4 x float>, i32, i32 }> %19 +} + +; Function Attrs: mustprogress nofree nosync nounwind readnone willreturn +declare float @air.convert.f.f32.u.i32(i32) local_unnamed_addr #1 + +; Function Attrs: mustprogress nofree norecurse nosync nounwind readnone willreturn +define <4 x i32> @tess_primitive_ids_fragment(<4 x float> %0, i32 %1, i32 %2, i32 noundef %3) local_unnamed_addr #2 { + %5 = insertelement <4 x i32> , i32 %3, i64 0 + %6 = insertelement <4 x i32> %5, i32 %1, i64 1 + %7 = insertelement <4 x i32> %6, i32 %2, i64 2 + ret <4 x i32> %7 +} + +attributes #0 = { mustprogress nofree nosync nounwind readnone willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="96" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" } +attributes #1 = { mustprogress nofree nosync nounwind readnone willreturn } +attributes #2 = { mustprogress nofree norecurse nosync nounwind readnone willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="128" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" } +attributes #3 = { nounwind readnone willreturn } + +!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8} +!air.vertex = !{!9} +!air.fragment = !{!19} +!air.compile_options = !{!27, !28, !29} +!llvm.ident = !{!30} +!air.version = !{!31} +!air.language_version = !{!32} + +!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 27, i32 2]} +!1 = !{i32 1, !"wchar_size", i32 4} +!2 = !{i32 7, !"frame-pointer", i32 2} +!3 = !{i32 7, !"air.max_device_buffers", i32 31} +!4 = !{i32 7, !"air.max_constant_buffers", i32 31} +!5 = !{i32 7, !"air.max_threadgroup_buffers", i32 31} +!6 = !{i32 7, !"air.max_textures", i32 128} +!7 = !{i32 7, !"air.max_read_write_textures", i32 8} +!8 = !{i32 7, !"air.max_samplers", i32 16} +!9 = !{<{ <4 x float>, i32, i32 }> (i32, i32, <3 x float>)* @tess_primitive_ids, !10, !14, !18} +!10 = !{!11, !12, !13} +!11 = !{!"air.position", !"air.arg_type_name", !"float4", !"air.arg_name", !"position"} +!12 = !{!"air.vertex_output", !"generated(3pidj)", !"air.arg_type_name", !"uint", !"air.arg_name", !"pid"} +!13 = !{!"air.vertex_output", !"generated(3iidj)", !"air.arg_type_name", !"uint", !"air.arg_name", !"iid"} +!14 = !{!15, !16, !17} +!15 = !{i32 0, !"air.patch_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"pid"} +!16 = !{i32 1, !"air.instance_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"iid"} +!17 = !{i32 2, !"air.position_in_patch", !"air.arg_type_name", !"float3", !"air.arg_name", !"bc"} +!18 = !{!"air.patch", !"triangle", !"air.patch_control_point", i32 3} +!19 = !{<4 x i32> (<4 x float>, i32, i32, i32)* @tess_primitive_ids_fragment, !20, !22} +!20 = !{!21} +!21 = !{!"air.render_target", i32 0, i32 0, !"air.arg_type_name", !"uint4"} +!22 = !{!23, !24, !25, !26} +!23 = !{i32 0, !"air.position", !"air.center", !"air.no_perspective", !"air.arg_type_name", !"float4", !"air.arg_name", !"position", !"air.arg_unused"} +!24 = !{i32 1, !"air.fragment_input", !"generated(3pidj)", !"air.flat", !"air.arg_type_name", !"uint", !"air.arg_name", !"pid"} +!25 = !{i32 2, !"air.fragment_input", !"generated(3iidj)", !"air.flat", !"air.arg_type_name", !"uint", !"air.arg_name", !"iid"} +!26 = !{i32 3, !"air.primitive_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"prim"} +!27 = !{!"air.compile.denorms_disable"} +!28 = !{!"air.compile.fast_math_enable"} +!29 = !{!"air.compile.framebuffer_fetch_enable"} +!30 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"} +!31 = !{i32 2, i32 8, i32 0} +!32 = !{!"Metal", i32 4, i32 0, i32 0} diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/tess_primitive_ids.ll b/crates/metal2vulkan-validation/fixtures/public/engine/tess_primitive_ids.ll new file mode 100644 index 000000000..534816021 --- /dev/null +++ b/crates/metal2vulkan-validation/fixtures/public/engine/tess_primitive_ids.ll @@ -0,0 +1,84 @@ +; Generated by scripts/regen-air-fixtures from tess_primitive_ids.metal (llvm-dis of tess_primitive_ids.air). Do not edit. +; ModuleID = '' +source_filename = "-" +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32" +target triple = "air64_v28-apple-macosx26.0.0" + +; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none) +define <{ <4 x float>, i32, i32 }> @tess_primitive_ids(i32 noundef %0, i32 noundef %1, <3 x float> noundef %2) local_unnamed_addr #0 { + %4 = and i32 %0, 3 + %5 = tail call fast float @air.convert.f.f32.u.i32(i32 %4) #3 + %6 = extractelement <3 x float> %2, i64 1 + %7 = fadd fast float %5, %6 + %8 = and i32 %1, 1 + %9 = tail call fast float @air.convert.f.f32.u.i32(i32 %8) #3 + %10 = extractelement <3 x float> %2, i64 2 + %11 = fmul fast float %7, 5.000000e-01 + %12 = fadd fast float %11, -1.000000e+00 + %13 = fadd fast float %10, %9 + %14 = fsub fast float 1.000000e+00, %13 + %15 = insertelement <4 x float> , float %12, i64 0 + %16 = insertelement <4 x float> %15, float %14, i64 1 + %17 = insertvalue <{ <4 x float>, i32, i32 }> undef, <4 x float> %16, 0 + %18 = insertvalue <{ <4 x float>, i32, i32 }> %17, i32 %0, 1 + %19 = insertvalue <{ <4 x float>, i32, i32 }> %18, i32 %1, 2 + ret <{ <4 x float>, i32, i32 }> %19 +} + +; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none) +declare float @air.convert.f.f32.u.i32(i32) local_unnamed_addr #1 + +; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) +define <4 x i32> @tess_primitive_ids_fragment(<4 x float> %0, i32 %1, i32 %2, i32 noundef %3) local_unnamed_addr #2 { + %5 = insertelement <4 x i32> , i32 %3, i64 0 + %6 = insertelement <4 x i32> %5, i32 %1, i64 1 + %7 = insertelement <4 x i32> %6, i32 %2, i64 2 + ret <4 x i32> %7 +} + +attributes #0 = { mustprogress nofree nosync nounwind willreturn memory(none) "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="96" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" } +attributes #1 = { mustprogress nofree nosync nounwind willreturn memory(none) } +attributes #2 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="128" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" } +attributes #3 = { nounwind willreturn memory(none) } + +!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8} +!air.vertex = !{!9} +!air.fragment = !{!19} +!air.compile_options = !{!27, !28, !29} +!llvm.ident = !{!30} +!air.version = !{!31} +!air.language_version = !{!32} + +!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 27, i32 2]} +!1 = !{i32 1, !"wchar_size", i32 4} +!2 = !{i32 7, !"frame-pointer", i32 2} +!3 = !{i32 7, !"air.max_device_buffers", i32 31} +!4 = !{i32 7, !"air.max_constant_buffers", i32 31} +!5 = !{i32 7, !"air.max_threadgroup_buffers", i32 31} +!6 = !{i32 7, !"air.max_textures", i32 128} +!7 = !{i32 7, !"air.max_read_write_textures", i32 8} +!8 = !{i32 7, !"air.max_samplers", i32 16} +!9 = !{ptr @tess_primitive_ids, !10, !14, !18} +!10 = !{!11, !12, !13} +!11 = !{!"air.position", !"air.arg_type_name", !"float4", !"air.arg_name", !"position"} +!12 = !{!"air.vertex_output", !"generated(3pidj)", !"air.arg_type_name", !"uint", !"air.arg_name", !"pid"} +!13 = !{!"air.vertex_output", !"generated(3iidj)", !"air.arg_type_name", !"uint", !"air.arg_name", !"iid"} +!14 = !{!15, !16, !17} +!15 = !{i32 0, !"air.patch_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"pid"} +!16 = !{i32 1, !"air.instance_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"iid"} +!17 = !{i32 2, !"air.position_in_patch", !"air.arg_type_name", !"float3", !"air.arg_name", !"bc"} +!18 = !{!"air.patch", !"triangle", !"air.patch_control_point", i32 3} +!19 = !{ptr @tess_primitive_ids_fragment, !20, !22} +!20 = !{!21} +!21 = !{!"air.render_target", i32 0, i32 0, !"air.arg_type_name", !"uint4"} +!22 = !{!23, !24, !25, !26} +!23 = !{i32 0, !"air.position", !"air.center", !"air.no_perspective", !"air.arg_type_name", !"float4", !"air.arg_name", !"position", !"air.arg_unused"} +!24 = !{i32 1, !"air.fragment_input", !"generated(3pidj)", !"air.flat", !"air.arg_type_name", !"uint", !"air.arg_name", !"pid"} +!25 = !{i32 2, !"air.fragment_input", !"generated(3iidj)", !"air.flat", !"air.arg_type_name", !"uint", !"air.arg_name", !"iid"} +!26 = !{i32 3, !"air.primitive_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"prim"} +!27 = !{!"air.compile.denorms_disable"} +!28 = !{!"air.compile.fast_math_enable"} +!29 = !{!"air.compile.framebuffer_fetch_enable"} +!30 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"} +!31 = !{i32 2, i32 8, i32 0} +!32 = !{!"Metal", i32 4, i32 0, i32 0} diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/tess_primitive_ids.metal b/crates/metal2vulkan-validation/fixtures/public/engine/tess_primitive_ids.metal new file mode 100644 index 000000000..86d565e7a --- /dev/null +++ b/crates/metal2vulkan-validation/fixtures/public/engine/tess_primitive_ids.metal @@ -0,0 +1,33 @@ +// Owned fixture (written for this repository): a fragment function's `[[primitive_id]]` behind a +// post-tessellation vertex function. Patch `pid` of instance `iid` (triangle patches of three +// control points, no stage-in) covers part of its own tile of an 8x8 target, two pixels wide at +// column pid % 4 and four high at row iid % 2, and passes `pid` and `iid` flat; the fragment +// function writes (`[[primitive_id]]`, pid, iid, 1). Metal's `[[primitive_id]]` there is the +// patch's position in its draw, patch start included, the same in every instance. +#include +using namespace metal; + +struct TessIds { + float4 position [[position]]; + uint pid [[flat]]; + uint iid [[flat]]; +}; + +[[patch(triangle, 3)]] +vertex TessIds tess_primitive_ids(uint pid [[patch_id]], uint iid [[instance_id]], + float3 bc [[position_in_patch]]) +{ + float x = float(pid % 4) * 2.0f + 2.0f * bc.y; + float y = float(iid % 2) * 4.0f + 4.0f * bc.z; + TessIds o; + o.position = float4(x / 4.0f - 1.0f, 1.0f - y / 4.0f, 0.0f, 1.0f); + o.pid = pid; + o.iid = iid; + return o; +} + +fragment uint4 tess_primitive_ids_fragment(TessIds in [[stage_in]], + uint prim [[primitive_id]]) +{ + return uint4(prim, in.pid, in.iid, 1u); +}