Skip to content

Integrate Xbox2Windows shader translation and D3D12 rendering - #2898

Closed
denn0x wants to merge 1 commit into
R0Y00:mainfrom
denn0x:xbox2windows-renderer-integration
Closed

denn0x wants to merge 1 commit into
R0Y00:mainfrom
denn0x:xbox2windows-renderer-integration

Conversation

@denn0x

@denn0x denn0x commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Rendering changes

  • Translate graphics and compute shaders to DXIL in C++ and load translated programs through the shader database.
  • Bind descriptor heaps, streamed texture mips, indirect draws, and compute resources in the D3D12 runtime.
  • Pack small textures into shared heaps and validate deferred texture descriptors before detiling or querying the driver.
  • Load material shader profiles from a caller-supplied file. Add synthetic coverage for sampler decoding, packed shader inputs, and texture placement.

Verification

The renderer DLL and shader lowering test built on Windows. Shader lowering, heap layout, and texture placement checks passed, including texture placement on WARP and hardware. Full-suite and end-to-end validation of this snapshot are pending. This draft needs reconciliation with current main before merge.

@denn0x

denn0x commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

How the rendering path works in this draft

  • Shader translation. The C++ frontend decodes GFX10 instructions into an intermediate representation. The lowering and emission stages turn register operations, texture accesses, wave operations, and stage inputs and outputs into DXIL. The shader database stores the compiled bytecode with the binding metadata the runtime needs to construct a D3D12 pipeline. The main review entry points are src/x2w_shader/ and src/shader_db/.
  • Draw and dispatch execution. The runtime maps guest descriptor tables and root arguments to D3D12 bindings, selects a pipeline for the active render targets and depth format, and records direct draws, indirect commands, and compute dispatches. Rectangle-list draws use an expansion path so the desktop GPU can rasterize them.
  • Streamed textures. When only part of a mip chain is readable, the runtime can upload the available levels and restrict sampling to them. It retries deferred views as backing becomes available. Before detiling or querying allocation size, it checks the resource dimensions, format, and mip count. This catches malformed descriptors before they reach the driver.
  • Texture memory. Eligible small textures share D3D12 heaps through aligned, nonoverlapping placements. A material lookup can reuse a compatible cached texture even when the local memory budget prevents a new allocation. Material profiles are supplied at runtime and matched against both the shader key and the compiled bytecode checksum.
  • Diagnostics. Targeted readbacks can capture selected shader inputs and outputs around a draw or dispatch. For indirect commands, the capture can also record the argument values the GPU consumed. This helps distinguish a draw that submitted no work from one that ran with unexpected inputs.

Verification at commit 87a6003fc

The Windows renderer DLL built successfully. All 11 focused native tests passed, covering shader lowering, sampler decoding, descriptor layout, view bounds, and small-texture placement. The placement and view-bound checks ran on both WARP and Radeon hardware. The placement test writes different values to the allocated textures and reads them back to catch overlapping heap ranges.

Full-suite testing and end-to-end visual validation of this commit are still pending. The draft also needs its conflicts with current main resolved before merge.

@MasterDomino

Copy link
Copy Markdown
Collaborator

Test results for this draft at 87a6003f on an RX 9070 XT, to help with the split. No review of the code itself.

Environment: Windows 11 build 26300.9974, AMD Radeon RX 9070 XT, driver 32.0.32029.2010, MSVC 19.44.35221, release preset, D3D12 debug layer not enabled.

Build: two problems on a clean configure.

  1. tests/gpu_bind.cmake is included at CMakeLists.txt:633, but find_program(DXC_EXECUTABLE dxc REQUIRED) comes at line 1759. startup_gpu_bind_{bind,bounds}_main.h are therefore generated with an empty command, and the build fails with CreateProcess failed. I worked around it with -DDXC_EXECUTABLE=<path> at configure.
  2. cpu_placed_dxr_provider.dll fails to link: d3d12_xs_device.cpp.obj : error LNK2019: unresolved external symbol DCompositionCreateDevice from TitleComposition::show. The target needs dcomp. All eight startup stand-in DLLs build.

New tests: the 512 tests this PR registers that main does not have (--tests-from-file, -j 8). 484 passed, 19 were capability skips (77), mostly WARP mesh dispatch and startup_cx_async_*, and x2w_vs_lower_size_test is disabled. 8 failed:

test first failure
startup_scalar_pack_hh AssertionError: s_pack_hh_b32_b16 on a lane mask
startup_image_sample_b Unsupported('image_sample_b form v5, [v1, v2], s0 dim:SQ_RSRC_IMG_2D dmask:0x1')
startup_mesh_barrier_ranges negative control: X2W_MESH_BARRIER_RANGES=0 refuses again: MISMATCH
startup_mesh_exec_lineage assert 'lane-dependent vcc' in got → ('parent', 'ok')
startup_mesh_lane_scc 1 check(s) failed (all three negative controls report ok)
startup_mesh_vcc_data vccspill: the vcc pair is spilled and reloaded through s[1000:1001] as two words: MISMATCH
startup_draw_state_{warp,hardware} off: slot 51 forwarded: ['x2w-render ClearDepthStencilView ...']

Startup run: compared with main at 6ee878d8 (after #2849), run back to back for 300 s each with -Render -Translate -FakeUser -GpuMirror -StartupBelow40 -ContinueAsserts 100000, the same input script and X2W_D3D12_BUDGET=1. This PR also needed -SlabBudgetMiB 8192, because without it the new launcher check refuses to start. Each arm's shader cache was re-keyed with its own shader_cache_rekey.py and translated with gfx2hlsl.py --pending. Here that needed X2W_UPSTREAM_SHADER_CACHE_REKEY=1; --pending produced 217 translations on this PR and 297 on main. Final counters:

build storage requests done textures uploaded translated draws (not drawn) pipelines translated / missing null bindings fps
main 6ee878d8 12,972 2,268 (6.9 GiB) 139,680 (53,459) 65 / 455 3,801 23.9
this PR 87a6003f 10,940 1,358 (5.4 GiB) 71,204 (167,554) 11 / 7 667 28.6

Both runs reached the timeout with no second-chance exception. In the same 300 s this snapshot got less far than current main: fewer storage requests and textures, and far fewer pipelines requested. The PR base is 259 commits behind main, so part of the gap is likely what landed there since.

Happy to rerun any slice you split out of this against the same baseline.

AI-assisted; the commands above were run locally.

@denn0x denn0x closed this Nov 26, 2026
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