diff options
| author | Vonsek <45567075+Vonsek@users.noreply.github.com> | 2026-11-22 20:15:34 +0100 |
|---|---|---|
| committer | Vonsek <45567075+Vonsek@users.noreply.github.com> | 2026-11-22 20:15:34 +0100 |
| commit | 4c414d121663c06ab2cbfb04596cc2a39457be77 (patch) | |
| tree | e72d50d0ee8de6ccb4aa3a8d4650013bd69a3fbc /docs | |
| parent | 162821017ea3c286c8bec860f3ff94f037912061 (diff) | |
tools: ps_oracle.py runs hand-written RDNA2 pixel-shader ISA on AMD GPUs
hw_oracle launches compute kernels only. vk_harness can now write a
pipeline's VK_KHR_pipeline_binary data and build a pipeline from it
(VKH_BINARY_OUT / VKH_BINARY_IN). ps_oracle.py puts assembled ISA in
place of _amdgpu_ps_main in the driver's PAL ELF, raises the pixel
stage's register counts in the msgpack metadata, optionally changes
other metadata entries, and draws with it, reading every pixel's mrt0
words back.
Checked on gfx1036 (driver 26.10.1): v_interp of a varying and the
parameter words P0 / P10 come back as expected. Tests in
tests/test_ps_oracle.py, docs in docs/shader_validation.md.
AI-assisted.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/shader_validation.md | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/docs/shader_validation.md b/docs/shader_validation.md index bbc748aa9..46bf9863b 100644 --- a/docs/shader_validation.md +++ b/docs/shader_validation.md | |||
| @@ -1418,6 +1418,44 @@ Hardware validation was executed via `tools/hw_oracle` and `tools/salu_diff.py` | |||
| 1418 | - **24-bit products and 64-bit shifts (`v_mul_hi_*24`, `v_lshrrev_b64`, `v_ashrrev_i64`)**: | 1418 | - **24-bit products and 64-bit shifts (`v_mul_hi_*24`, `v_lshrrev_b64`, `v_ashrrev_i64`)**: |
| 1419 | - Verified across signed/unsigned products, edge signs, and 0..63 shift counts: **0 mismatches**. | 1419 | - Verified across signed/unsigned products, edge signs, and 0..63 shift counts: **0 mismatches**. |
| 1420 | 1420 | ||
| 1421 | ### Pixel-shader ISA on the hardware (`tools/ps_oracle.py`, EGEN-TOOL-PS-ORACLE) | ||
| 1422 | |||
| 1423 | `tools/hw_oracle` only launches compute kernels, so what only a pixel shader has (`v_interp_*` and the parameter | ||
| 1424 | words the SPI writes into LDS, the barycentric VGPRs, exports and their formats, helper lanes) could not be | ||
| 1425 | measured there. `tools/ps_oracle.py` runs hand-written RDNA2 pixel-shader ISA in a real draw on an AMD GPU, through | ||
| 1426 | Vulkan's `VK_KHR_pipeline_binary`: | ||
| 1427 | |||
| 1428 | 1. `vk_harness` builds a pipeline from a template vertex + pixel shader and writes its binary (`VKH_BINARY_OUT`). | ||
| 1429 | On the AMD Windows driver that is one PAL ELF: `.text` with `_amdgpu_gs_main` (the vertex stage) and | ||
| 1430 | `_amdgpu_ps_main`, and a `.note` with the PAL metadata in msgpack, from which the driver programs the register | ||
| 1431 | counts and the SPI setup (`spi_ps_input_ena/addr`, `spi_ps_input_cntl` per parameter, `spi_shader_col_format`). | ||
| 1432 | 2. The code under test is assembled with AMD clang (`LEONIDA_AMD_CLANG`, as for hw_oracle) and replaces | ||
| 1433 | `_amdgpu_ps_main`; `.text` grows if needed and the pixel stage's VGPR/SGPR counts are raised to the registers | ||
| 1434 | the code names. `--set PATH=JSON` changes a metadata entry as well, e.g. | ||
| 1435 | `.graphics_registers/.spi_ps_input_cntl/0/.fp16_interp_mode=true`. | ||
| 1436 | 3. `vk_harness` builds the pipeline from the patched binary (`VKH_BINARY_IN`), draws one full-screen triangle into | ||
| 1437 | an RGBA32F target and reads every pixel's four mrt0 dwords back bit for bit. | ||
| 1438 | |||
| 1439 | The template sets what the code finds when it starts, so `--show-template` prints the template's own ISA and SPI | ||
| 1440 | metadata to copy the conventions from. With the built-in `interp2` template on gfx1036 the pixel stage is wave64, | ||
| 1441 | the perspective I/J barycentrics are in v0/v1, M0 comes from s2 (`s_mov_b32 m0, s2`), and parameters 0 and 1 are | ||
| 1442 | the vertex shader's locations 0 = (u, v, 0, 1) and 1 = (u, v, 0, 0), u and v going 0..2 across the screen. | ||
| 1443 | |||
| 1444 | ```powershell | ||
| 1445 | $env:LEONIDA_VK_DEVICE = "radeon" | ||
| 1446 | python -I tools/ps_oracle.py --build <runtime build> --template interp2 --show-template | ||
| 1447 | python -I tools/ps_oracle.py --build <runtime build> --template interp2 --asm body.s --size 4 1 [--json out.json] | ||
| 1448 | ``` | ||
| 1449 | |||
| 1450 | Checked on an AMD Radeon iGPU (gfx1036, Windows driver 26.10.1): the driver accepts a patched binary (there is no | ||
| 1451 | check over the code), the patched code runs as the pixel shader, and `v_interp_p1/p2_f32` of `attr0.x` at the four | ||
| 1452 | pixel centres of a 4 x 1 target gives u = 0.125, 0.375, 0.625, 0.875, with `v_interp_mov_f32` reading the | ||
| 1453 | parameter words P0 = 0 and P10 = 2.0 (`tests/test_ps_oracle.py`, which runs it on hardware when | ||
| 1454 | `LEONIDA_PS_ORACLE_BUILD` names a runtime build). On other drivers the binary is not a single PAL ELF (the NVIDIA | ||
| 1455 | driver returns two blobs) and the tool exits 77. Limits: one draw of one triangle, mrt0 as RGBA32F only; the vertex | ||
| 1456 | stage is the template's, compiled by the driver; the SPI behaviour comes from the driver's metadata, so a `--set` | ||
| 1457 | the hardware does not support is not refused here. | ||
| 1458 | |||
| 1421 | 1459 | ||
| 1422 | ## Coverage plan and cost | 1460 | ## Coverage plan and cost |
| 1423 | 1461 | ||