Skip to content

Shaders: a formatted load converts only the fields its DST_SEL reads - #33

Merged
ThatRecompDev merged 1 commit into
ThatRecompDev:mainfrom
Sr-0w:shaders/format-load-swizzle
Nov 25, 2026
Merged

ThatRecompDev merged 1 commit into
ThatRecompDev:mainfrom
Sr-0w:shaders/format-load-swizzle

Conversation

@Sr-0w

@Sr-0w Sr-0w commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Until now, FmtLoad converted all four fields of an element, and fmt_swizzle picked among them afterwards. Every component's conversion (int-to-float, two divides, f16 widening and the format selects) therefore stayed live, even when the program reads only x.

FmtLoad now takes V# dword3. Each result component converts only the one field its selector names, so unread components fold away. Results are unchanged bit for bit. fmt_swizzle and fmt_select are gone, and probe_FmtLoad gets the extra argument.

A retail game's 122k-dword compute program has 3,281 format loads. Its DXIL backend output shrinks as follows:

before after
instructions 1,256,697 735,530 (−41%)
fdiv 26,260 6,574
DXIL size 7.4 MB 4.9 MB

The driver compile scales with that size. That program is the one that stays a stand-in for the longest.

Tests: the new cs_buffer_rule_format_select case loads an 8_8_8_8_UINT element through DST_SEL z,y,x,1 and w,0. It fails when the selectors are ignored. The full suite is green.

🤖 Generated with Claude Code

FmtLoad converted all four fields of the element and fmt_swizzle chose
among them after, so every component's conversion (int-to-float, two
divides, f16 widening and the format selects) stayed live even where
the program reads only x. FmtLoad now takes V# dword3 and each result
component converts the one field its selector names: the unread
components fold away. The results are unchanged bit for bit.

In a retail game's 122k-dword compute program with 3,281 format loads,
the DXIL backend output goes from 1,256,697 to 735,530 instructions
(-41%), 26,260 to 6,574 divides, 7.4 to 4.9 MB.

Tests: cs_buffer_rule_format_select loads an 8_8_8_8_UINT element
through DST_SEL z,y,x,1 and w,0; it fails when the selectors are
ignored.

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

Copy link
Copy Markdown
Owner

41% fewer instructions on the biggest compute program with identical results is a great win, especially since that's the one stuck as a stand-in longest. merged, thanks!

@ThatRecompDev
ThatRecompDev merged commit 7d0393d into ThatRecompDev:main Nov 25, 2026
2 checks passed
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.

2 participants