Repository navigation
Shaders: a per-lane code load indexes only the program's data words - #50
Conversation
|
thanks, 26 s to 14 s on that tiled-lighting program is a nice win, and the test case is neat. my worry is the "data only after the last translated instruction" assumption. if a table ever sits before some later code (between functions, or ahead of a long jump target), the lane load quietly reads g_data[0] where CodeLoad used to return the right word. so it'd be wrong without any error. could the start come from the s_getpc-relative offsets the program actually adds (like the .Ltable-.Lpc add here) instead of the end of the code? also heads up: this changes the hlsl of every s_getpc program with a global load, even ones with no data words, so everything gets re-translated and recompiled. fine if we go in knowing it, but if you can keep programs without data words byte-identical that'd help a lot. tiny thing, the comment says 54 words and the doc says 55 |
Review of ThatRecompDev#50: - The data start is the earliest table the program's s_getpc pointers are moved to (s_add_u32 / s_sub_u32 of the low half right after each s_getpc), not the end of the translated code: a table between functions or before a long jump's target is found, and code after it is kept in g_data. - When an s_getpc is used otherwise, or there is no table, the loads keep CodeLoad: the program's HLSL is byte for byte what it was before. - Comment and doc agree on the word count (53 from 0x6ca0 in the program measured). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6455818 to
11c61d3
Compare
|
Good catch, reworked (rebased on main):
Driver time is unchanged: 14 s, 0.4 GB, against 26 s / 1.9 GB before. New |
A program reads constant tables placed after its last s_endpgm through s_getpc_b64 pointers. The translation emits the whole code as a static array (g_code) and reads it through CodeLoad. A scalar load has a constant address that dxc folds. A per-lane (vector) load indexes the array per lane, and the driver then materializes the whole array. For a tiled-lighting pixel program (7,005 code words, 9 per-lane loads into a 55-word table at its end), the AMD driver took 26 s and 1.9 GB to create the pipeline. A game run builds hundreds of these material programs, at about 0.3 pipelines a second, and skipped 2 million draws waiting for them. A per-lane code load now goes through CodeLoadLane, which indexes g_data: the code words after the last translated instruction, where the compiler puts the tables. The same program takes 14 s and 0.5 GB. An address before the data reads its first word, as CodeLoad clamps one past the end; a program without data words keeps g_code. Test: a compute case reads an 8-entry table after its s_endpgm per lane through an s_getpc_b64 pointer (dxc and the DXIL backend); an off-by-one in CodeLoadLane fails it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of ThatRecompDev#50: - The data start is the earliest table the program's s_getpc pointers are moved to (s_add_u32 / s_sub_u32 of the low half right after each s_getpc), not the end of the translated code: a table between functions or before a long jump's target is found, and code after it is kept in g_data. - When an s_getpc is used otherwise, or there is no table, the loads keep CodeLoad: the program's HLSL is byte for byte what it was before. - Comment and doc agree on the word count (53 from 0x6ca0 in the program measured). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
11c61d3 to
e2276c2
Compare
|
In game (recorded runs, RX 7800 XT, 600 s each, same input script)
The tiled-lighting material programs are most of the backlog. While a pipeline builds, its draws are skipped, so faster compiles mean more of the scene is actually drawn and the queue drains sooner. With this PR, the cinematic and its credits render over the lit scene in the second half of the run. |
|
thanks, taking the data start from the s_getpc offsets is a much safer rule, and keeping programs without a table byte-identical means no recompile churn. merged (566a88d). i fixed two rule hits in CodeData on the way in (a named hex prefix and an explicit if/else instead of the conditional). one thing worth adding sometime: a test that the HLSL actually contains g_data for cs_code_table_lanes, since the case would also pass if it silently fell back to CodeLoad |
A program reads constant tables placed after its last
s_endpgmthroughs_getpc_b64pointers. The translation emits the whole code as a static array (g_code) read throughCodeLoad:Measured on an RX 7800 XT, cold (
fivestar shader pso, never-compiled DXIL), for a tiled-lighting material pixel program from a retail game. It has 7,005 code words and 9 per-lane loads into a 55-word table at the end of its code.In a game run, hundreds of these material programs were queued behind each other. They were built at about 0.3 pipelines per second, and 2 million draws were skipped while they waited.
Change
CodeLoadLane, which indexesg_data: the code words after the last translated instruction (CodeData.Start), where the compiler puts the tables.s_branchskips over, as in this program at 0x3074.CodeLoadalready clamps an address past the end.g_code.Ruled out along the way
g_codewith a wave-uniform index (a readfirstlane loop) brought back 28 s and 1.9 GB: any dynamic index into the whole array costs this much.CODE_TAGtest to pointers derived froms_getpcproduced byte-identical DXIL, because dxc already folds those tests. It is not included.Test: a compute case reads an 8-entry table placed after its
s_endpgm, per lane, through ans_getpc_b64pointer. It runs through dxc and through the DXIL backend, and an off-by-one inCodeLoadLanefails it. The Shaders tests (404) and the architecture rules pass. Docs are updated inshader-translation.md.🤖 Generated with Claude Code