Skip to content

Compilation Time: DXC Compile Time Issues #293

Backlog

Description

@brcly

Hey guys,

I know we're all fighting compilation times on shaders.

The number 1 suspect for that atm is DXC.

image

Our validator and translator layer is really fast, fantastic.

But DXC, which is what TuxBox uses to compile the DirectX shaders, is what's stalling and causing extremely long compile times.

I'm gonna push a change to help increase the compilation time, but I also want to hear people's ideas on how we can increase the speed even further.

If it means a home grown system, so be it.

Right now TuxBox compiles shaders in this order:

Raw RDNA2 (provided by the game) -> HLSL (this is fast) -> DXIL (this is the slow DXC step) -> SPIR-V (linux only for VKD3D) -> GPU Driver

What would be more ideal is either

Raw RDNA2 -> DXIL -> Driver (Windows)
Raw RDNA2 -> SPIR-V -> Driver (Linux)

or

Raw RDNA2 -> HLSL -> DXIL -> Driver (Windows)
Raw RDNA2 -> HLSL -> SPIR-V -> Driver (Linux)

If someone could throw some tokens to get some ideas on the way forward, I'd like to know.

The long times seem to affect only compute shaders going through DXC.

So I propose that we maybe have a specific pipeline for compute shaders first.

Activity

  1. NickStallman commented on Nov 27, 2026

    @NickStallman
    Contributor

    I'll take this on. Some context from what I measured for #229: on the host, DXC is 97.5% of CPU, and the slowest 10% of requests take 76% of that, mostly in LLVM Jump Threading. The 30-minute cold run itself looked limited by the driver stage (638 large compute pipelines through 4 slots), but that is inferred from one log on driver 595, so the first job is a per-stage baseline on 620.

    I'm running these in parallel, compute first, and will post numbers here:

    1. Per-stage baseline for the compute set: xshader, DXC, DXV, dxil-spirv, driver.
    2. DXC flags and passes per target, including what each does to dxil-spirv time.
    3. Which shapes in the emitted HLSL cost DXC the most. Measurements only; I'll stay out of your simplification work.
    4. Home-grown DXIL (RDNA2 → DXIL, no DXC): a small writer spike validated with dxv and on the GPU, how much optimising our own emitter would need so dxil-spirv and the driver don't get slower, and a size estimate. Nothing changes downstream, and it would serve Windows too.
    5. Home-grown SPIR-V: first HLSL → SPIR-V with DXC's SPIR-V backend, then how SPIR-V could reach the driver without patching Proton, then RDNA2 → SPIR-V without HLSL.
    6. Large-compile slots against memory on a 5090; results go to d3d12: adapt large shader compile concurrency to available memory #236.

    For 4 and 5: xshader has no IR between the decoder and the HLSL text, so I'll size both honestly before building anything past a spike.

    Anything that overlaps the change you're pushing, tell me and I'll drop it.

  2. akimfomin commented on Nov 27, 2026

    @akimfomin

    For the DXC question, Xbox2Windows already publishes a title-free compiler control. PortBridge measured 1.294 s median on its 2,048-branch sampling variant, with the compiler revision and the other variants recorded. It is a pixel-shader calibration and TuxBox's compute bottleneck remains an open question. Pinned generator · Archived method and results

    When your next compute change is ready, would you nominate one generated shader or public test PR for a second timing through PortBridge? A volunteer can report DXC wall time separately from native pipeline creation and return the compiler version, revision and aggregates here.

  3. brcly commented on Nov 27, 2026

    @brcly
    OwnerAuthor

    Before committing to anything, I'm going to simplify the computer shaders where possible.

    If I manage a break through, I'll update

  4. NickStallman commented on Nov 27, 2026

    @NickStallman
    Contributor

    Per-stage baseline, CPU only, at 9168b2f with DXC 1.8.2505.1 and the dxil-spirv commit GE-Proton11-14 ships (34f0ff84, built standalone). Sample: 400 random cs_6_6, 150 cs_6_0, 100 of each other target, from the recorded ProjectScarlett requests, run through the same flag policy as compile_dxil. The GPU driver compile is not in here.

    Mean CPU seconds per program (measured):

    target n HLSL KB DXC DXV dxil-spirv DXC share
    cs_6_6 400 879 8.37 0.034 0.63 92%
    ms_6_6 100 128 1.70 0.010 0.14 92%
    ps_6_6 100 255 1.32 0.010 0.06 92%
    cs_6_0 150 62 0.17 0.005 0.01 90%

    xshader is under 1% everywhere. So offline, DXC is the cost, as you suspected.

    For cs_6_6 the cost is broad, not a few outliers (measured). This corrects what I said above from the earlier mixed sample: the slowest 10% take 33% of DXC time, and 40% of the programs cost over 10 s each (p50 2.1 s, p90 20 s, max 91 s). The programs with 1 to 4 MiB of HLSL carry 89% of it, and DXC's cost per byte is about nine times higher there than for small programs. DXC time tracks the block count of the output (r = 0.95) more closely than HLSL size (r = 0.85).

    Scaled to all 24,800 translated programs (inferred from the sample): about 47,000 core-seconds of DXC, of which cs_6_6 is 22,500 (95% interval 19,900 to 25,100), ms_6_6 13,200 and ps_6_6 10,600; dxil-spirv is about 3,400.

    Two side findings (measured):

    • A DXC timeout is costly twice. The two cs_6_6 programs that fell back to -O0 then took 17 s and 68 s in dxil-spirv (57k and 78k blocks), against a p99 of 2.9 s for -O1 output.
    • Both of those had 52 to 56 s of CPU inside the 60 s wall-clock limit, on a machine that was busy. The limit is wall time in the game too, so load during a launch can push large programs onto the -O0 path.

    One early result from the home-grown DXIL test that bears on your simplification (measured, synthetic programs): dxil-spirv time grows faster than quadratically with basic blocks. For 16,000 masked register writes, DXC -O1 output had 4,000 blocks and took 1.2 s in dxil-spirv; the same writes expressed as selects were one block and took 0.23 s. I'm now testing whether emitting pure register writes as selects in the HLSL gives the same gain through DXC.

    Flags, HLSL shapes and the two home-grown routes are still running.

  5. gtb-sbe commented on Nov 27, 2026

    @gtb-sbe
    Contributor

    @NickStallman A data point from AMD, and from after the startup phase, in case it helps with 1 and 2. It's one run, so the numbers are samples, not a baseline.

    Setup: RX 9060 XT (RADV GFX1200, Mesa 26.2.6), Ryzen 7 5800X (16 threads), 31 GB, GE-Proton11-14, ProjectScarlett 1.0.2.1 offline at 3840x2160, #258 d50a51c on 12e4b06, no preload, Linux DXC 1.10.2605.37. The translator had changed since the previous run, so every request was translated live; nothing was prepared.

    Startup (first ~8 min): about 9,000 requests the title had already made in earlier runs, at about 1,100 per minute. All 150 compute CreatePipelineState ... finished in lines (5-9 s) are from these minutes.

    After the Account Picker (~65 min, loading at 3 draws per frame): about 5,900 requests no earlier run had reached, at 60-400 per minute, usually 100-150. The slow pipelines in this phase are all mesh + pixel (84 lines, mean 6.3 s, max 8 s); no compute.

    Two 60 s samples of the live worker in that phase (ps every 0.5 s, so durations are lower bounds). The worker had 8 slots (up to 8 concurrent requests) and was never full.

    UTC requests in flight, mean / max DXC processes, mean / max xshader idle CPU DXC jobs
    02:54 3.5 / 5 3.3 / 5 0.04 49% ms_6_6 30 (mean >= 3.0 s, max >= 11 s); ps_6_6 -disable-lifetime-markers 59 (mean >= 1.8 s, max >= 4.5 s)
    03:20 0.8 / 4 0.7 / 4 0.00 74% ms_6_6 31 (mean >= 1.0 s, max >= 3.0 s); pixel 8

    What I read from it:

    • In this phase the title has only a few pipeline creations in flight, and each waits for its own translation. More slots would not help here. Shorter per-request latency, or translating before the title asks, would.
    • DXC is nearly all of the translator's time; xshader and DXV barely show up.
    • Mesh programs are the largest DXC cost here. Unless it is a dispatched program, ms_6_6 goes through DXC at default optimisation. It gets neither the -disable-lifetime-markers variant (dispatched programs and pixel programs of 256 KiB or more) nor the compute flags. Whether changing that would cost dxil-spirv or the driver more is open. Your item 2 would answer it.

    Not measured: driver time separately from DXC, and the time from the title's call to the finished pipeline.

  6. NickStallman commented on Nov 27, 2026

    @NickStallman
    Contributor

    Results on what in the emitted compute HLSL costs DXC, since that's what you're working on. cs_6_6, DXC 1.8.2505.1, -O1 -disable-lifetime-markers, CPU time; dxil-spirv is the GE-Proton11-14 commit built standalone. The machine was shared, so repeat runs vary by up to 1.6x: read these as ratios. Rewrites were scripted on real recorded programs and all outputs pass DXV, but nothing here was run on a GPU, and driver compile time is not measured.

    1. ?: is a branch, not a select (measured). DXC defaults to HLSL 2021, where ?:, && and || on scalars short-circuit, and -O1 doesn't fold them back. select(c, a, b) gives a real DXIL select. Turning if (m) v = e; into v = m ? e : v; is worse than the if (2.6x the blocks). -HV 2018 alone gave −15 to −22% DXC time and −9 to −17% blocks on five programs, but is only safe if no emitted ?:/&&/|| relies on short-circuiting, which I haven't audited.

    2. Pure masked register writes as select() (measured, six of the slowest programs). Only side-effect-free right-hand sides were rewritten; loads, stores, wave ops and atomics stayed under branches.

    program variant DXC s blocks dxil-spirv s
    8 MB, paired wave64 now 48–60 32,884 13.8–16.4
    select() 37.4 10,491 1.94
    select() + -HV 2018 24.0 7,672 1.61
    677 skip flags now 44.8 16,777 6.57
    select() + -HV 2018 29.6 8,779 2.81
    dispatcher now 25.0 9,674 1.55
    select() + -HV 2018 16.5 4,662 0.69

    Across the six: blocks −35 to −68%, dxil-spirv −40 to −88%, DXC −38% to +15%. One program with 95 loops got slower in DXC (51 → 104 s, all in InstCombine); I don't know why yet. [flatten] on the same ifs changes nothing.

    3. Small [noinline] functions cut DXC time 6–10x (measured, three programs). Registers as static uint globals, each dispatcher block or guard body as a [noinline] void f():

    program variant DXC s blocks DXIL KB dxil-spirv s
    loops + skip flags now 38.5 8,324 595 1.87
    outlined + select() 5.0 6,072 1,130 0.81
    677 skip flags now 56.7 16,777 914 6.29
    outlined + select() 7.3 12,258 1,630 2.50
    dispatcher now 25.0 9,051 665 1.34
    outlined 4.0 10,912 886 3.69

    This is the largest effect, and the least proven: the DXIL is 33–80% larger because registers become memory, and the driver then has to inline and promote them, so driver time and runtime speed could get worse. Function size matters (32,000 synthetic instructions: 3.8 s in 400 functions, 54.5 s in 8). Without [noinline] DXC inlines everything and nothing changes. [noinline] with an inout struct fails validation in a compute target. Compiling as libraries and linking gave no gain.

    4. A scoped temporary across a guard is super-quadratic (measured on synthetic; inferred for the real programs). { uint r = v; if (m) r = e; v = r; }, which the paired-wave64 form emits tens of thousands of times in the 8 MB programs, costs 33.7 s in Dxil Conditional Mem2Reg at 16,000 writes against 2.2 s for writing the register directly.

    5. Loops that carry skip flags scale worst (measured, synthetic). 8,000 instructions and 400 flags: 6.4 s with no loops, 20.7 s with 40, 77.6 s with 100 (loop canonicalisation).

    No effect: comments and text volume (the front end is 1–4%), nesting depth, scalars versus an array for registers, [flatten]. || in place of | in guards costs 30–45%, as you already found.

    Overall DXC time goes as instructions^1.46 on 300 random programs, and no single text feature predicts it better than size, so keeping functions and straight-line runs small is what helps.

    Home-grown routes, short version (details to follow):

    • RDNA2 → DXIL: a 1,100-line writer with its own container hash works: dxv accepts it and it passes the Lanes wave64-shader scenario on AMD. The cost is the translator behind it, estimated at 20,000 to 28,000 lines for compute, because the lowering is tied to HLSL text.
    • HLSL → SPIR-V with dxc -spirv: not viable. It was 4x slower than DXC + dxil-spirv on compute and segfaulted on 59 of 150 programs, including all the large ones.
    • RDNA2 → SPIR-V: VKD3D_SHADER_OVERRIDE accepts our SPIR-V with no Proton patch (shown for one compute shader on RADV), but it's a debug feature, needs vkd3d-proton's private binding layout, and loses [WaveSize]. It only removes dxil-spirv, which is 7% of the CPU.

    The synthetic generator has no game content; I can put it in a PR or gist if it's useful. @gtb-sbe: the per-target flag table for ms_6_6 and ps_6_6, with the dxil-spirv cost, is still running.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions