Skip to content

SHADER-836: what tier C costs in pixels, at subgroup 64 and 32 on one AMD GPU - #7613

Open
emirduran707 wants to merge 3 commits into
ItsNotRexed:mainfrom
emirduran707:shader-836-tier-c-cost
Open

emirduran707 wants to merge 3 commits into
ItsNotRexed:mainfrom
emirduran707:shader-836-tier-c-cost

Conversation

@emirduran707

Copy link
Copy Markdown
Contributor

SHADER-836 (the pixel side; claim). The compile and size side is SHADER-836b, done by @Etr0p in #7333 without code. #7161 (@Invictus2076) covers the synthetic fixtures.

What

The two-GPU pixel sweep (tools/ps_sweep.py, vk_ps_sweep) compares two 32-wide GPUs, so it cannot show tier C of tools/wave64_halves.py: a tier C shader is inexact the same way on both. An AMD RDNA GPU whose driver lists the fragment stage in requiredSubgroupSizeStages can draw one shader at subgroup 64 and again at 32. Only the subgroup size changes between the two draws.

  • vk_ps_sweep: VKS_SUBGROUP=32|64 sets VkPipelineShaderStageRequiredSubgroupSizeCreateInfo on the fragment stage and enables subgroupSizeControl. The run exits 77 when the device cannot require that size. Without the variable nothing changes.
  • ps_sweep.py run --subgroup N passes the size on.
  • ps_sweep.py sample --tier-n C=240,B=27,A=60 samples each wave64_graphics tier on its own. A rare tier gets the count asked for instead of its share of the population. sample.json records the tier and the reasons.
  • ps_sweep.py compare adds a breakdown by tier, and for tier C by reason.
  • docs/shader_validation.md gets a new subsection with the measurement. It contains counts only.

Result (RX 9060 XT, AMD 26.10.44, 360 pixel shaders, seed 836)

tier sampled same at 64 and 32 differ NaN / zero / unwritten at one size
A 93 93 0 0
B 27 24 3 0
C 240 219 16 5

The table shows the gradient-texture variant. With fallback (zero) images, tier C drops to 2 + 4.

  • Tier C differs in 21 of 240 shaders (8.8 %). Every difference is larger than 0.1. Nearly all of these shaders carry the cross-lane and tainted-exec reasons.
  • In tier B, 3 of 27 shaders differ in both variants, and all 3 carry readfirstlane-uniform. I'll post that as a finding: in the coordination issue.
  • Re-draws at the same size are bit-identical for all differing shaders, at 64 and at 32, so the differences are not noise.

Tested

  • Windows 11, MSVC (Visual Studio 2022), AMD Radeon RX 9060 XT (RDNA4), AMD driver 26.10.44.
  • python -I tests/test_ps_sweep.py: 24 tests, OK (3 skipped). A new test covers the tier-weighted sample.
  • vk_ps_sweep builds and draws at VKS_SUBGROUP=64 and 32. Requiring 16, which the device does not offer, exits 77.
  • The sweep used shaders from my own 1.0.2.1 copy and posts counts only. No shader names or bytes are in the PR. sample.json stays local.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

…2 on one AMD GPU

vk_ps_sweep takes VKS_SUBGROUP=32|64 and draws the pixel shader with that
required subgroup size (subgroupSizeControl, fragment stage in
requiredSubgroupSizeStages; exit 77 otherwise). ps_sweep.py run passes it with
--subgroup, ps_sweep.py sample --tier-n samples each wave64_graphics tier on
its own, and compare breaks the classes down by tier and tier C reason.

On an RX 9060 XT (AMD 26.10.44), 360 translated pixel shaders, seed 836:
tier A 93/93 the same at 64 and 32; tier B 3 of 27 differ (all carry
readfirstlane-uniform); tier C 21 of 240 differ in the gradient variant, 6 in
the zero variant. Re-draws at the same size are bit-identical. Counts only,
in docs/shader_validation.md.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ECHOZwei

Copy link
Copy Markdown

Tested 6e49132e0af060eedbe2b8e217166aa8724fffed on Windows (MSVC 14.51 / Visual Studio Community 2026, RelWithDebInfo, Vulkan SDK 1.4.363.0, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation) on two GPUs (synthetic shaders only; no game files): pass

  • Built vk_ps_sweep cleanly with 0 warnings.
  • python -I tests/test_ps_sweep.py -v: 24 tests OK (3 skipped, 0.189s, including test_tier_weighted_sample).
  • NVIDIA GeForce RTX 4080 SUPER (driver 621.01, validation on):
    • Synthetic fullscreen VS/FS draw with VKS_SUBGROUP unset and VKS_SUBGROUP=32: both PASS (exit 0, 0 validation errors — confirms the Vulkan 1.3 subgroupSizeControl + VkPipelineShaderStageRequiredSubgroupSizeCreateInfo pNext chain under Khronos validation).
    • VKS_SUBGROUP=64, 16, 48 (non-power-of-two), and 0: all cleanly exit 77 (unsupported: the requested fragment subgroup size (VKS_SUBGROUP)).
  • AMD Radeon(TM) Graphics iGPU (driver 25.10, LEONIDA_VK_DEVICE=AMD, validation on; requiredSubgroupSizeStages lacks FRAGMENT_BIT):
    • VKS_SUBGROUP unset: PASS (exit 0, 0 validation errors).
    • VKS_SUBGROUP=32 and 64: both cleanly exit 77 (confirms the VK_SHADER_STAGE_FRAGMENT_BIT guard).
  • git diff --check and python -I scripts/check_no_game_data.py docs/shader_validation.md runtime/test/vk_ps_sweep.cpp tests/test_ps_sweep.py tools/ps_sweep.py: clean (exit 0).

AI-assisted.

@Ekabusto

Copy link
Copy Markdown

Tested 6e49132e0 on AMD Radeon RX 9070 XT (RDNA4), driver 26.11.2, Windows 11 10.0.26300, with no game files:
pass for VKS_SUBGROUP / --subgroup, plus one note on compare.

What I ran: built vk_ps_sweep (RelWithDebInfo) and pointed the whole pipeline at the 20 hand-written ps_w64_*
fixtures from runtime/test/shaders (build.py output) instead of a game corpus:
sample --tier-n A=8,B=5,C=8 --seed 836 → run --subgroup 64 and run --subgroup 32 → compare --tags sg64 sg32.

  • Both runs: every draw exit 0. tests/test_ps_sweep.py: 24 tests OK (3 skipped).

  • VKS_SUBGROUP takes effect: the raw targets of 4 tier C fixtures differ between 64 and 32 (ps_w64_c_lane_id,
    _readlane, _bcnt_export, _waterfall_count: 512–896 of 4,096 words each). Tier A and B are byte-identical.

  • Note: the default compare reports all 20 as "OK on both", including those 4. They write integer words
    (e.g. 0x20 vs 0x0), which as floats are denormals around 1e-44, far inside TOLERANCE (1e-3), so
    classify_pair treats them as equal. compare --exact --tags sg64 sg32 gives 4 mismatch, 15 non-clear exact
    and 1 clear-only exact, which is correct. But --exact has no per-tier / per-reason breakdown.

    So the "same at 64 and 32" column of the results table may count as equal any tier C shader whose differences are
    only in bit-cast integer outputs. Possible fixes: add the tier and reason breakdown to compare_exact and report the
    exact counts for 64 vs 32, or compare word bits when either value is denormal or not finite. I haven't measured how
    many corpus shaders this affects (no game copy here).

AI-assisted: yes (Claude ran the build and tests; results checked by me).

…-exact counts and the clear-only denominator (SHADER-836)

Ekabusto noted on ItsNotRexed#7613 that the tolerance compare calls bit-cast integer words equal (they are denormals). compare --exact now prints the same per-tier / per-reason breakdown; on the RX 9060 XT sample it gives the same 24 (t) and 9 (z) draws, and 104 of the 240 tier C shaders write only the clear colour.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@emirduran707

Copy link
Copy Markdown
Contributor Author

@Ekabusto thanks, that is a real gap, and the fixture check is a good one. In 0f472751e, compare --exact now prints the same per-tier / per-tier-C-reason breakdown as the tolerance compare (the code is shared).

I re-ran it bit-exactly on my RX 9060 XT sample:

  • Variant t: 24 mismatching draws (tier B 3, tier C 21).
  • Variant z: 9 mismatching draws.

These are the same draws the tolerance compare reported, so on this sample no shader differs only in bit-cast integer words. The table stands.

Your note also brought out a caveat, which I added to the doc. 104 of the 240 tier C draws are clear-only: they write nothing but the clear colour, mostly because they read a zeroed heap and discard. The meaningful rate is therefore 21 of the 136 that write, about 15 %.

AI-assisted (Claude Code).

@alvaroolt

Copy link
Copy Markdown

Tested 0f472751e on NVIDIA GeForce RTX 5080 (driver 621.24) and the AMD Radeon iGPU (AMD 24.10.34, proprietary), Windows 11 26300, MSVC 19.52 RelWithDebInfo, Vulkan SDK 1.4.363, synthetic shaders only: pass. This covers the VKS_SUBGROUP skip and the positive 32 path. This AMD driver cannot run the 64-vs-32 measurement itself.

Ran:

  • vk_ps_sweep built clean (no warnings) on the head and on upstream/main dde82f27e.
  • PS_SWEEP_TEST_EXE=<vk_ps_sweep> python -I tests/test_ps_sweep.py, each GPU selected with VK_LOADER_DRIVERS_SELECT: head 24/24 OK, main 23/23 OK, 0 skips on both GPUs.
  • A synthetic fragment shader that writes gl_SubgroupSize (glslang), drawn by vk_ps_sweep at 32x32 with VK_LAYER_KHRONOS_validation on:
VKS_SUBGROUP RTX 5080, head AMD iGPU, head main control (both GPUs)
unset exit 0, size 32 exit 0, size 64 exit 0, 32 / 64
32 exit 0, size 32 exit 77 exit 0 (variable ignored)
64 exit 77 exit 77 exit 0 (variable ignored)
48, abc exit 77 exit 77 exit 0 (variable ignored)

No validation messages in any run.

  • The RTX 5080 lists the fragment stage in requiredSubgroupSizeStages, with sizes 32..32. So VKS_SUBGROUP=32 takes the new path (subgroupSizeControl enabled, the required-size create-info on the fragment stage) and draws at 32. 64 and the invalid values exit 77.
  • On this iGPU, AMD 24.10.34 lists only the compute stage in requiredSubgroupSizeStages, and fragment shaders run at 64 by default. Both sizes exit 77, as the new doc comment says, rather than drawing at the default size. The 64-vs-32 measurement needs a newer AMD driver, such as the PR's 26.10.44.

No unit test covers print_tier_breakdown (compare / compare --exact) or the --subgroup passthrough in run. The new test covers only --tier-n.

AI-assisted: yes (Claude Code); results reviewed by me.

…the tier breakdown (SHADER-836)

job_env now sets VKS_SUBGROUP itself and counts it among the per-job
variables it clears, so a value left in the shell no longer reaches runs
made without --subgroup. New tests cover that and print_tier_breakdown
(per tier, per tier C reason, a shader with two reasons, a sample made
without --tier-n), the gaps alvaroolt listed on ItsNotRexed#7613.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@emirduran707

Copy link
Copy Markdown
Contributor Author

@alvaroolt thanks for the run on both GPUs, and for the table. Your iGPU's exit 77 on 32 and 64 is the case the doc comment describes: that driver lists only the compute stage in requiredSubgroupSizeStages.

You were right about the coverage gaps. 9624007f0 adds:

  • print_tier_breakdown: a test for the per-tier and per-tier-C-reason lines, where a shader with two reasons counts under each, and for a sample made without --tier-n, which prints nothing.
  • --subgroup: the value now goes through job_env, and a test checks that VKS_SUBGROUP is set only when asked.

The second change also fixes a small bug. VKS_SUBGROUP is now one of the per-job variables job_env clears, so a value left in the shell no longer reaches runs made without --subgroup.

tests/test_ps_sweep.py: 26 OK, 3 skipped (no PS_SWEEP_TEST_EXE), on Windows 11, RX 9060 XT.

AI-assisted (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants