diff --git a/crates/metal2vulkan-validation/src/c3.rs b/crates/metal2vulkan-validation/src/c3.rs index b25c95174..e97de4c2b 100644 --- a/crates/metal2vulkan-validation/src/c3.rs +++ b/crates/metal2vulkan-validation/src/c3.rs @@ -275,8 +275,9 @@ pub enum AnswerGap { /// The device shades a triangle it clips as several triangles (lavapipe, /// `VK_DRIVER_ID_MESA_LLVMPIPE`, whose clipper emits the clipped polygon as a fan of /// triangles; measured at Mesa 26.0.8), so a quad a seam between the pieces crosses runs once - /// per piece, each run holding only its own piece's pixels as active lanes, where Metal's quad - /// holds all four. Metal permits a partly occupied quad, so the device's answer is a valid + /// per piece, each run keeping all four lanes with the other piece's covered pixels as + /// helpers, so a helper query in either run names them, where Metal's quad, shaded once, names + /// none. Metal permits a partly occupied quad, so the device's answer is a valid /// Metal answer, not the reference's; no Vulkan mechanism keeps the clipped triangle one /// primitive (a guard band emulated by scaling the viewport and the position is exact only /// within the viewport limits). No Vulkan query states the split, so the product's modules @@ -291,8 +292,10 @@ pub enum AnswerGap { /// one whose quad or simdgroup operation reads its active lanes under a primitive the device /// may clip records `PrecisionNote::QuadsSplitByClipping`, on every device; the words it writes /// differ from Metal's where one of those notes reaches each differing word. Neither note - /// excuses a word. Why the device's words differ is not yet read, so every device has the gap. - /// A row's own words decide it ([`Self::held_by_words`]): the list holds no case under it. + /// excuses a word. The words differ by four mechanisms (docs/VALIDATION.md, "The verdict"), + /// the first of which, Apple's partial quads, sets every device's whole quad apart, so every + /// device has the gap. A row's own words decide it ([`Self::held_by_words`]): the list holds + /// no case under it. HelperThreadWords, /// Ordered fetch and blend inside one draw: a fragment function that reads a color attachment /// records `PrecisionNote::UnorderedFetchWithinDraw`, on every device, and the words it writes diff --git a/crates/metal2vulkan/src/pipeline/artifact.rs b/crates/metal2vulkan/src/pipeline/artifact.rs index 4698fafad..7cfc629cd 100644 --- a/crates/metal2vulkan/src/pipeline/artifact.rs +++ b/crates/metal2vulkan/src/pipeline/artifact.rs @@ -1073,11 +1073,11 @@ pub enum PrecisionNote { /// A fragment function runs a quad or simdgroup operation, recorded on every device: a device /// may shade a triangle it clips as several triangles, and then a quad a seam between the /// pieces crosses runs once per piece, each run with the other piece's pixels as helper - /// invocations, so the operation counts or combines fewer active lanes than Metal's, whose - /// quad holds all four. Metal permits a partly occupied quad, so the device's answer is one - /// Metal's API allows, not the reference's; no Vulkan query tells such a device apart, and no - /// Vulkan mechanism keeps the clipped triangle one primitive (a guard band emulated by scaling - /// the viewport is exact only within the viewport limits). + /// invocations, so a helper query in either run names the other piece's covered pixels as + /// helpers, where Metal's quad, shaded once, names none. Metal permits a partly occupied quad, + /// so the device's answer is one Metal's API allows, not the reference's; no Vulkan query + /// tells such a device apart, and no Vulkan mechanism keeps the clipped triangle one primitive + /// (a guard band emulated by scaling the viewport is exact only within the viewport limits). /// /// Validation derives no tolerance and no explanation from it: a difference stays a /// mismatch for review, which validation names as the answer gap of a case that meets it. @@ -1104,13 +1104,16 @@ pub enum PrecisionNote { /// API allows. Elsewhere a quad is the same 2x2 pixels on every device, and a helper computes /// what its covered pixel would, so no other quad operation tells the runs apart. /// - /// A device whose fragment subgroup holds fewer than two quads runs it as a partly occupied - /// simdgroup (`Tier::PartialFragment`), which Metal permits: there the operation combines the - /// one quad's pixels alone, so a reduction ahead of a `discard_fragment` counts no quad the - /// discard drops, where an Apple GPU's 32-lane simdgroup counts the dropped quads of its 8x4 - /// pixel block. Measured on arm64 lavapipe, whose fragment stage states one subgroup size, - /// 4 (`[minSubgroupSize, maxSubgroupSize]` is `[4, 4]`): thirteen discard shapes all answer the - /// survivors, where Metal's answer counts the + /// A device whose fragment subgroup holds fewer than 32 lanes runs it as a partly occupied + /// simdgroup (`Tier::PartialFragment`), which Metal permits, its upper lanes inactive: a fill + /// from past the subgroup reads an inactive lane, which Metal leaves undefined (MSL 4.1 + /// section 6.10.2: a thread needs to only read data from another active thread in the + /// SIMD-group), and the device reads the calling lane in its place. Where the subgroup holds + /// fewer than two quads, the operation combines the one quad's pixels alone, so a reduction + /// ahead of a `discard_fragment` counts no quad the discard drops, where an Apple GPU's 32-lane + /// simdgroup counts the dropped quads of its 8x4 pixel block. Measured on arm64 lavapipe, + /// whose fragment stage states one subgroup size, 4 (`[minSubgroupSize, maxSubgroupSize]` is + /// `[4, 4]`): thirteen discard shapes all answer the survivors, where Metal's answer counts the /// dropped quads in four of them. No required subgroup size reaches 32 lanes there, and /// nothing in Vulkan relates the invocations of two fragment subgroups, so no exact form /// exists on such a device. diff --git a/docs/API.md b/docs/API.md index a8108372a..a48918b00 100644 --- a/docs/API.md +++ b/docs/API.md @@ -2183,8 +2183,9 @@ category, and says what makes an operation carry the note and what may differ. E - `metal2vulkan-degrade-quads-split-by-clipping` (precision). `PrecisionNote::QuadsSplitByClipping`: A fragment function runs a quad or simdgroup operation, recorded on every device: a device may shade a triangle it clips as several triangles, and then a quad a seam between the pieces crosses - runs once per piece, each run with the other piece's pixels as helper invocations, so the - operation counts or combines fewer active lanes than Metal's, whose quad holds all four. + runs once per piece, each run with the other piece's pixels as helper invocations, so a helper + query in either run names the other piece's covered pixels as helpers, where Metal's quad, + shaded once, names none. - `metal2vulkan-degrade-fragment-simdgroup-grouping` (precision). `PrecisionNote::FragmentSimdgroupGrouping`: A fragment function runs a simdgroup operation (a reduction, scan, vote, ballot, shuffle, broadcast or AGX multiply-add) or reads its @@ -2199,8 +2200,12 @@ category, and says what makes an operation carry the note and what may differ. E quad's other covered pixels as helpers, where the device shades them as one quad: a ballot of the helper query names covered pixels as helpers on the M3 Max (3 of the 16 quads of an 8x8 target, 2 to 4 of the 12 of a 7x5 one, under the full-screen triangle with every third pixel discarded) and - none on the device. A device whose fragment subgroup holds fewer than two quads combines the - one quad's pixels alone, so a reduction ahead of a `discard_fragment` counts no quad the discard + none on the device. A device whose fragment subgroup holds fewer than 32 lanes runs it as a + partly occupied simdgroup, its upper lanes inactive: a fill from past the subgroup reads an + inactive lane, which Metal leaves undefined (MSL 4.1 section 6.10.2: a thread needs to only read + data from another active thread in the SIMD-group), and the device reads the calling lane in its + place. Where the subgroup holds fewer than two quads, the device combines the one quad's pixels + alone, so a reduction ahead of a `discard_fragment` counts no quad the discard drops, where an Apple GPU's simdgroup counts the dropped quads of its 8x4 pixel block; the device states one fragment subgroup size, so no required size widens it, and no exact form exists there. diff --git a/docs/VALIDATION.md b/docs/VALIDATION.md index b6a98fecd..d17cee726 100644 --- a/docs/VALIDATION.md +++ b/docs/VALIDATION.md @@ -632,6 +632,25 @@ cargo run -p metal2vulkan-validation --release --bin corpus-vulkan -- \ `FragmentSimdgroupGrouping`, or every one by `QuadsSplitByClipping`, is held open as `helper_thread_words`, and one whose every unexcused word is reached by `UnorderedFetchWithinDraw` as `ordered_fetch_within_draw`. None of these notes excuses a word. + In a case held as `helper_thread_words`, the words differ by four mechanisms, each giving a + Metal answer, not the reference's: + - *Apple's partial quads* (`FragmentSimdgroupGrouping`). Under a function that discards, the + M3 Max shades some quads as partial quads, each run naming the quad's other covered pixels as + helpers: 3 of the 16 quads of an 8x8 target, 2 to 4 of the 12 of a 7x5 one. lavapipe and the + Radeon 780M shade each quad whole and name none. + - *The clip seam* (`QuadsSplitByClipping`), lavapipe only. llvmpipe clips the full-screen + triangle to the viewport and draws two triangles that meet on the diagonal from (0, H) to + (W, 0). A quad that diagonal crosses runs once per piece, each run keeping all four lanes, so a + helper query in either run names the other piece's covered pixels as helpers: on an 8x8 target + the quad at pixel (6, 0) answers 0xe in one run and 0x1 in the other, where Metal answers 0x0. + The Radeon 780M does not split this triangle. + - *Lane order* (`FragmentSimdgroupGrouping`), the Radeon 780M. RADV's 32-lane fragment subgroup + holds the same 8x4 pixel block as Apple's simdgroup, but orders its quads by 4x4 tile (the + quads at (0, 0), (2, 0), (0, 2) and (2, 2), then the right-hand tile's) where Apple orders them + row by row, so a lane index, a shuffle or a scan reaches another pixel. + - *An 8-lane subgroup* (`FragmentSimdgroupGrouping`), lavapipe on x86. The fragment subgroup + holds 8 pixels, the pixels of Apple's lanes 0 to 7, so a fill from lanes 8 to 31 reads a lane + that holds no pixel, an inactive lane whose read Metal leaves undefined. - **Batches.** `--batch --out OUT` runs every selected case, one process per case, each killed whole after `--run-timeout`, resuming from `OUT/done.tsv`; `--batch-report` and `--batch-install STORE` read and install the results. A batch starts no GPU run while the