Repository navigation
Conversation
…E::rla()
In HLSL 2021 pixel shaders (#define XCL_PIXEL 1), PRELUDE::rla() indexed
uint4 xcl_lv with a runtime index xcl_lv[min(h >> 5, 3u)] and used scalar
ternary/if chains. DXC lowered every rla() call site into a [4 x i32]
alloca local array plus conditional branches; across the retail pixel
shader corpus (12,056 unique PS), 7,634 shaders call rla() (up to 212
calls / 212 local arrays in a single pixel shader).
Replace xcl_lv[min(h >> 5, 3u)] with inline branchless select() over
xcl_lv.{x,y,z,w} (self-contained inside PRELUDE without depending on
PRELUDE_MEM::pick4) and replace the scalar ?: and if chains in rla() with
select() and and().
Part of xcl-dev#2088
Part of xcl-dev#1269
Assisted-by: Google Antigravity (Gemini 4 Neon)
|
Tested Independent Windows check on clean
Both logged 20 native-wave64 skips, three per-lane f16/f32 refusals, and one skip each for unavailable driver-cache control and heap windows. The RTX 2080 SUPER also logged two missing-D3D12-debug-layer skips. Focused The two workspace failures on both PCs matched the author's baseline report: Not tested Retail smoke, full AMD workspace, Intel, non-Windows hosts, driver compile performance or gameplay timing. AI use Ran via Samaritan:
|
What is in it
Eliminates local arrays (
alloca [4 x i32]) and scalar control-flow branches inside the pixel-shader lane-read helperPRELUDE::rla()(crates/xcl/src/gpu/recomp/emit.rs), continuing#2088Workstream 5 (following commit9f65f95, which removed runtimeuint4indexing fromPRELUDE_MEMformat helpers but leftPRELUDE::rla()):xcl_lv[min(h >> 5, 3u)](WaveActiveBallot(true)indexed by a runtime dword index) with inline branchlessselect()overxcl_lv.{x,y,z,w}(uint hw = h >> 5; uint lv_w = select(hw < 2u, select(hw == 0u, xcl_lv.x, xcl_lv.y), select(hw == 2u, xcl_lv.z, xcl_lv.w));). Kept inline insidePRELUDErather than callingPRELUDE_MEM::pick4(), becausePRELUDE_MEMis omitted when!uses_mem.?:andifchains inrla()(q,r, and the twowupdates) with branchlessselect()andand(), matchingPRELUDE::ballot().Across a 12,056-shader retail pixel-shader corpus (
windows=4, split_wave64=true), 7,634 pixel shaders (63.3%) callrla()(213,536 total call sites, up to 212 calls in a single pixel shader), and DXC lowered every call site into a[4 x i32]local array plus conditional branches. Removing these eliminates 100% ofrla()local arrays (212 -> 0on the largest outlier), cuts DXIL basic blocks by up to 24.4% and conditional branches by up to 27.4%, and reduces cold NVIDIACreateGraphicsPipelineStatecompile time by 16.5%–27.9% on the largestrla()-heavy retail pixel shaders.Adds three tests in
gpu::recomp::emit::tests:rla_pixel_helper_avoids_runtime_vector_indexing_and_branches(pure CPU, asserts noxcl_lv[,?:,if (, orpick4(dependency inPRELUDE::rla()).rla_pixel_shader_compiles_without_local_arrays(DXCps_6_6+-dumpbindisassembly on a self-contained#define XCL_PIXEL 1+PRELUDEpixel shader withoutPRELUDE_MEM, asserting 0allocas and 0 conditional branches).gpu_rla_pixel_shader_matches_reference_including_helper_lanes(WARP-guarded GPU draw across two diagonal-splitting triangles comparingPRELUDE::rla()against the original reference implementation on own-quad and cross-quad helper/live lanes in the same hardware wave, plus exact analytical checks forx^1/y^1quad neighbors).Part of #2088
Part of #1269
Tested
Hardware / toolchain: Windows 11 Home (26200), Intel Core i5-11400F (6C/12T), 32 GB RAM, NVIDIA GeForce RTX 4060 8 GB VRAM (32-lane waves, driver 621.14), DXC
1.9.2609.5 (01b62ad4), Rust1.100.0.Base commit:
707b84c7df012bff2b6f30cd5d7149b5d407fce4(git merge-tree --write-treealso verified clean againstorigin/mainf087b998).Head commit:
5081dc8b6e22fc74f6fe7d31de333182e8f7ec92.Unit & GPU test results:
gpu::recomp::emit::tests:::rla_pixel_helper_avoids_runtime_vector_indexing_and_branchesfailed (runtime vector index remains in rla()) andrla_pixel_shader_compiles_without_local_arraysfailed (expected 0 local arrays in rla() DXIL, got 3).cargo test --release -p xcl --lib gpu::recomp::emit::tests:: -- --nocapture --test-threads=1on RTX 4060: 4 passed, 0 failed, 0 ignored (0 skipped).cargo test --release -p xcl --lib gpu::recomp::tests::gpu_ps_masks_hold_helper_lanes_on_triangle_edges -- --nocapture --test-threads=1on RTX 4060: 1 passed, 0 failed (wave64 true: 0 of 1024 pixels wrong,wave64 false: 0 of 1024 pixels wrong).XCL_ADAPTER="Microsoft Basic Render Driver"andXCL_ADAPTER=warp) ongpu::recomp::emit::tests::: 4 passed, 0 failed, 0 ignored (3 CPU/DXC tests passed;gpu_rla_pixel_shader_matches_reference_including_helper_lanescleanly printedSKIPPED).cargo build --release --workspace: exit 0.cargo test --release --workspace --no-fail-fast -- --test-threads=4: 1226 passed, 2 failed, 46 ignored across 22 test suites, with 26 pre-existing runtimeSKIPPEDlines (0 new skips). Both failures are pre-existing upstream merge regressions onorigin/main707b84c7unrelated toemit.rs:hle::d3d12x::device_x::tests::pc_resource_desc_strips_uav_on_unsupported_formats_and_msaa(device_x.rs:1376:format 85 kept,left: 28, right: 85after#1991promoted format85UAVs to28)gpu::recomp::pso::shader_cache_tests::rerouted_disk_entries_follow_the_direct_translator(pso.rs:1360:left: 68, right: 1after#2120met DXBC-header test fixtures).Cold NVIDIA
CreateGraphicsPipelineStatebenchmark (#2088Required Evidence):XCL_DXC_DIR=%LOCALAPPDATA%\XCL\dxc\bin\x64,XCL_DXIL_CACHE=<empty scratch dir>(XCL DXIL cache cold/empty;windows=4,split_wave64=true,ps_6_6paired with a minimal signature-matchedvs_6_6andabi_root_signature_with). Windows Developer Mode is unavailable on this host (ID3D12Device9::ShaderCacheControlcannot disable implicit caches), so cold NVIDIA implicit DXCache misses were forced via fresh executable copies per mode and verified on every shader by an immediate 2ndCreateGraphicsPipelineStatecall hitting warm cache (0.03–0.40 mswarm vs780–26,909 mscold, >20,000x ratio).rla()(213,536 totalrla()call sites).568e7db7baseline vs branchlessPRELUDE::rla(), same RTX 4060,ps_rla_bench bench <corpus> <base|fix> <hashes>):rla()callsalloca [4 x i32]CreateGraphicsPipelineState547a9a33080eaab6059e34becdccf5cf11441aa968b462c5a9af041f10fd1d7ed01b5f713fdca60e4b05f6d6c18e1037707b84c7vs PR head5081dc8breproduced identicalalloca(212/211/199/129/21 -> 0) and block/instruction reductions (547a9a33080eaab6:798,012 -> 761,104 B,5137 -> 4288blocks;059e34becdccf5cf:786,228 -> 749,736 B,5097 -> 4262blocks;11441aa968b462c5:723,632 -> 689,800 B,4793 -> 4036blocks;a9af041f10fd1d7e:466,644 -> 439,328 B,3494 -> 2642blocks;4b05f6d6c18e1037:89,752 -> 86,808 B,712 -> 700blocks), reduced benchmark process peak commit from633 MBto605 MB, and reproduced the PR coldCreateGraphicsPipelineStatetimings (15,299,12,943,7,289,790 mson059e34be/11441aa9/a9af041f/4b05f6d6;22,853 mson547a9a33during concurrent CPU load vs24,586 msbaseline).Regression run
Paired 60-second
scripts/smoke.ps1runs on the same retail title build (29640639) from cleanorigin/main(707b84c7) and this branch (5081dc8b). Both reached the title menu with steady 30 FPS presents continuing (60 60 60presents per 2 s), 0 device removals, 0 crashes, and no runtime GPU-time regression (1457frames /14436 MBpeak commit on PR vs1381frames /14462 MBpeak commit on base):Base (
origin/main):PR (
fix-2088-ws5-rla-no-alloca):Not tested
ID3D12Device9::ShaderCacheControlcache-disabled API (requires Windows Developer Mode, unavailable on this Windows 11 Home host; cold driver compiles were instead forced via fresh executables and verified against 2nd-call warm hits< 0.5 ms).AI use
Drafted with Google Antigravity (Gemini 4 Neon) and verified locally by reproducing pre-fix test failures, verifying
emit::testsandgpu_ps_masks_hold_helper_lanes_on_triangle_edgeson RTX 4060 plus WARP skip checks, running the workspace test suite, measuring cold NVIDIACreateGraphicsPipelineStatecompile times across stratified retail pixel shaders, and completing the paired 60-second smoke run above.