Typed buffer loads: channels past the format read 0 on RDNA2, not w = 1 (all 77 formats measured) #1060
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory#1060
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Lyrnc on GitHub · 2026-11-24 15:23 UTC · original
format_loadpads the 4th channel of atbuffer_load_format_*with1/1.0when the format has fewer channels. RDNA2 hardware reads 0 there. I measured all 77 GFX10 buffer formats; the full result tables are below.Setup.
tbuffer_load_format_xyzw … format:N offenfor N = 1..77. The rows hold byte, half and float edge patterns, plus random values.MTBUFwords throughbuild_valu_cs, onmainffe310e. The test stores the 4 input dwords to the UAV, loads them back withformat:Nand stores the 4 results. It ran on an RTX 5080 (driver 610.88) and on the same Radeon iGPU (picked with #94'sVICTORY_ADAPTER). Both hosts give the same results, apart from NaN payloads of the 16-, 11- and 10-bit floats on NVIDIA.This is RDNA2 desktop silicon, not the console's GPU. No game data was used.
1. Channels a format doesn't have read 0, including the 4th. This holds on gfx1036 for every format with fewer than 4 channels and every numeric kind. All 6,208 missing-channel values in the run are 0.
maingives 1 / 1.0 in the 4th channel, so with these rows the translation differs from the hardware in 64 of 64 rows for each of the 49 formats with 1-3 channels.The descriptor's
dst_seldoesn't change this fortbufferloads. In one kernel, with one descriptor, I set the V#'sdst_selto identity, W=ONE, W=ZERO, all ONE, X↔Y, and X=W:tbuffer_load_format_xyzw format:32_32_32_FLOATbuffer_load_format_xyzw, V# format32_32_32_FLOAT(x, y, z, 0)(x, y, z, x)dst_sel_w= ONE(x, y, z, 0)(x, y, z, 1.0)dst_sel_w= ZERO(x, y, z, 0)(x, y, z, 0)(x, y, z, 0)(y, x, z, x)So the typed (
MTBUF) form ignoresdst_seland reads 0 past the format, which matches theshortcut:informat_load. TheMUBUFform appliesdst_sel. With an identity swizzle theMUBUFform reads the format's own channels again in the missing slots:32_FLOATgives(x, x, x, x),32_32_FLOATgives(x, y, x, y),8_8_UNORMgives(x, y, x, y). That second column doesn't affectformat_load. It may matter for the typed-view path ofbuffer_load_format_*, where a D3D typed view reads(…, 0, 0, 1).2. UNORM / SNORM: the hardware rounds correctly. #25's comment already notes that the division is 1 ULP off. For the record, on gfx1036 every UNORM and SNORM value in the run is the correctly rounded
k / (2^n - 1)(0 exceptions over all 20 norm formats, the 2-, 10- and 11-bit fields included). The host's division is off on these values, identically on AMD and NVIDIA:8_UNORM,8_8_UNORM,8_8_8_8_UNORM8_8_SNORM,8_8_8_8_SNORM16_UNORM,16_16_UNORM,16_16_16_16_UNORM16_SNORM,16_16_SNORM,16_16_16_16_SNORM10_11_11_UNORM,_SNORM11_11_10_UNORM,_SNORM10_10_10_2_SNORM2_10_10_10_UNORM,_SNORMFor example, byte
0xfeas8_UNORMis0x3f7efeffon the hardware and0x3f7eff00on the host.The packed formats from #25 (
10_11_11,11_11_10,10_10_10_2) otherwise match the hardware bit for bit, including the_FLOATones.A fix. On
Lyrnc/VIctorybranchfix/tbuffer-hw-channels(one commit onffe310e):k / (2^n - 1)is thenbits ofkrepeating forever. So the f32 is the first 24 bits of that stream after its leading 1, rounded up when the 25th bit is set. A tie can't happen, because the stream never ends. In the lowering,ktimes a repeat constant gives the stream in an i64.k's f32 exponent gives the shift, and a 39-bit right shift gives 24 bits plus the rounding bit. SNORM is the same on|s|withn - 1bits, then the sign, with the most negative value clamped to -1.typed loadsdiff test zero-padssnorm16x2on the PC side. That was the only case with a 2-channel format loaded as 4. I couldn't run the diff tests, since they need the console compiler.valu_tests.rs. One checks for 0 past the format's channels (8 formats). The other checks norm rounding for 15 formats, with every byte in every position and the values from the table above. Expected values come from an f64 division in the test, which is exact here.Results on that branch:
main'slower.rsformat 5: [1, 0, 0, 1], want 0 past channel 1)I'll open it as a PR once external pull requests are open again, or a maintainer can take it from the branch.
AI use: Claude Code (Claude Opus 5.5) wrote the probes, the comparison, the fix and this issue, and ran them on the GPUs above; the numbers come from those runs.
@MichaelSmithAI on GitHub · 2026-11-24 15:26 UTC · original
We checked the MTBUF changes on our integration branch on an RTX 4090 under Wine/vkd3d-proton 3.2. To isolate the load, we uploaded the input words before dispatch and supplied the integration branch’s heap bounds. Microsoft DXIL validation passed, and both the missing-channel and normalized-rounding tests passed.
With the same input, the old lowering returned
[1, 0, 0, 1]for R8_UINT where the measured expectation is[1, 0, 0, 0]. With zero padding fixed but the old normalization retained, UNORM3/255produced0x3c40c0c2; your conversion produced the expected0x3c40c0c1. The original same-dispatch store/load fixture gave inconsistent inputs on our backend, so these comparisons use the seeded fixture throughout.This covers translated MTBUF loads on an Int64-capable host. We did not test MUBUF descriptor swizzles or identify a title pass using the affected values.
@DrDarkDK on GitHub · 2026-11-24 15:29 UTC · original
Following up on the Int64-capable host result above, I checked the emitted DXIL for the same synthetic MTBUF shaders on
ffe310eandefd39a3. The patch adds the Int64 requirement bit (SFI0 & 0x8000) for8_UNORMand16_SNORM. The8_UINTcontrol keeps the same flags.All three shaders ran on an RTX 4070 Ti and WARP, both with
Int64ShaderOps=true. Do we support SM 6.6 devices withoutInt64ShaderOps? If so, the channel zero-fill could land separately because it doesn’t need the new normalization path.AI-assisted with Codex.
@Lyrnc on GitHub · 2026-11-24 15:44 UTC · original
Thanks both.
@DrDarkDK
mainalready sets the Int64 flag in other places:mul_hi(v_mul_hi_u32/_i32),src64(64-bit VALU operands) and one more site. So a title whose shaders use any of those already needsInt64ShaderOps. Still, the two parts are independent, and I'm happy to split them: one commit for the zero-fill, one for the exact norm conversion. If devices without Int64 matter, the conversion can also be done with two 32-bit words instead of one i64. That costs a few more ops and needs no new requirement.@MichaelSmithAI About the same-dispatch fixture: the tests store the inputs into the UAV and load them back in the same thread, because
View::RawUavstarts zeroed. On D3D12 that store→load is ordered (same thread, same address), and the test asserts the inputs read back first (the stored inputs). If vkd3d-proton returned something else there, I'd be curious what it was. That might be worth its own look. If a seeded buffer is preferred, I can switch the tests to one.AI use: Claude Code (Claude Opus 5.5) checked the flags in
mainand drafted this reply.@andrewpozdnakov7-jpg on GitHub · 2026-11-24 15:56 UTC · original
I tried the 32-bit approach on top of Lyrnc’s exact
efd39a3dd8eeefc67241ec7ba6d0175c1a73f83e: 78af907.I added an assertion to
tbuffer_load_norm_formats_round_correctlyfor the shader'sInt64ShaderOpsrequirement. The same test sees SFI0 bit0x8000on the original branch and passes with the bit clear after the change. Microsoft DXIL validation and WARP readback also passed, including the existing exact UNORM/SNORM bit comparisons. The full shader suite passed with 122 tests and one ignored. A separate arithmetic check matched the correctly rounded float for all 131,070 inputs across 1–16-bit normalized widths.@Marvisak on GitHub · 2026-11-25 09:59 UTC · original
Automated triage for the maintainers.
Confirmed by reading
main(940d32f):format_loadincrates/victory-shader/src/emit/lower.rspads a missing 4th channel with 1 / 1.0 (its doc comment says "0, 0, 1"), and UNORM/SNORM values are converted by a float division, which its ownshortcut:note says can be 1 ULP off the hardware.Open PRs that cover the two parts:
Int64ShaderOps: #1112, which refs this issue (the 32-bit approach discussed above).PRs are open to everyone now. @Lyrnc, if your branch
fix/tbuffer-hw-channelscarries anything those two do not (for example the 77-format comparison tests), please open it as a PR against currentmain, or add it to #1516 / #1112, so review has one place per change.Generated by Claude Code
@Lyrnc on GitHub · 2026-11-26 16:40 UTC · original
Thanks. My branch carries nothing beyond those, so I won't open it:
mainalready has it (da82e44, withoutInt64ShaderOps). The 77-format comparison against gfx1036 shows no UNORM/SNORM difference on63bcca4.63bcca4, and it gives 0 differences from the hardware on the Radeon and on an RTX 5080. The numbers and a rebased branch are in my comment there.Once #1516 is in, this issue can be closed.