On a miss, `shader_cache::cached` had the cache write the new entry and
then read and decoded that file to return it. The first read of a file
just written is slow where a virus scanner looks at new files: measured
here (Windows Defender on) at about 0.5 ms for an 8 KB entry and 3.3 ms
for 60 KB, against 70-85 us for a later read, which is on the order of
a 1-12 ms translation. `translate --cache` misses on every container the
first time (some 25,000), and a run misses on every shader not cached.
The converter now keeps the translation it encoded, and a miss returns
it; entries are read only on hits. A translation whose entry could not
be written is returned as made too, where it was translated a second
time before.
The new test makes the cache folder unusable and checks the translation
is made once (twice before).
* Loader: append crash reports as single records
AI-assisted (OpenAI Codex).
* Loader: the crash-record test sits below the test module's imports
Placement only, as the triage on #2033 noted; the test is unchanged.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
---------
Co-authored-by: BaggyALPHA <257889696+BaggyALPHA@users.noreply.github.com>
Co-authored-by: BaggyALPHA <col.chipmunk@gmail.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
* GPU: heap samplers keep point mips when anisotropic, as static samplers do
A sampler the title makes in a descriptor heap from the console's
description (`CreateSamplerX`, `sampler::console`) became D3D12's plain
anisotropic filter (0x55) whenever its magnification or minification was
anisotropic, whatever its mip filter: an anisotropic sampler with point
mips blended between mip levels on the host. Static samplers in shader
code keep point mips since #1337 (`StaticSampler::filter_for_host`), on
hosts with anisotropic point-mip filtering (`D3D12_OPTIONS19`).
Heap samplers now do the same: 0x54 (with the comparison and min/max
reduction bits) where the console asks for point mips, or none, and the
host has the feature; linear mips (0x55) otherwise, as before. The
feature is asked once (`sampler::aniso_point_mip`), and pipeline
creation uses the same answer instead of asking per pipeline.
Tests: `anisotropic_samplers_keep_point_mips_where_the_host_can` checks
the filter for point, linear and no mips with and without the feature,
and with comparison and maximum reduction (on main the point-mip case
gives 0x55); `the_host_takes_its_anisotropic_samplers` makes such a
sampler in a sampler heap on the host device and checks the device is
not removed (an RTX 5070 Ti reports the feature, so it takes 0x54).
* GPU tests: minimum-reduction anisotropic samplers, and whether a sampler was made
Review (#2031): the mapping test now also checks minimum reduction (0x154
with point-mip support, 0x155 without) and maximum reduction without it
(0x1d5). The device test prints whether it made its sampler (and with
which filter) or skipped for want of a device, so a green run shows
which it was.
The library is serialised into one buffer of its whole size, allocated infallibly. On NVIDIA the library holds each pipeline's machine code, about 1.7 GB after translate --cache --pipelines, and a save in the world aborted the process: 'memory allocation of 2650101862 bytes failed' (RTX 4050 Laptop, 32 GB). The buffer is now reserved fallibly; without memory the save is left for later (the pipelines stay counted as added).
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* GPU: composite multiple PresentX planes (fixes Series S black UI/menus)
* Serialize the PresentX compositor root signature explicitly
* Exercise PresentX pipeline creation with the installed shader compiler
* Initialize the PresentX compositor before opening the copy list
* Test PresentX recovery after compositor initialization fails
* GPU tests: verify composited pixels after present initialization recovers
* GPU tests: inspect composed pixels before flip-discard Present
* Update queue.rs
* Update queue.rs
* GPU: a failed compositor still presents the first plane
When the multi-plane compositor cannot be created, the frame was dropped
(`return None`). Show plane 0 through the single-plane copy path instead,
and keep retrying the compositor on the next present. The test now asserts
that the failing frame is presented, not skipped.
* GPU: present the primary plane when compositor setup fails
(cherry picked from commit 5a1b9ad5ae79f1e7b0bb6e29ea89af928d43e6bf)
* GPU: restore each presented host texture state once
(cherry picked from commit 660568e673b20f333bc9c8c2d37267190b3b1093)
* GPU: keep the composed plane list's host textures owned
The ported fix in the previous commit was written against a `host_resource`
that lent its host texture; on `main` it returns a clone, so the composed
list cannot hold `&ID3D12Resource` across the `host.present` call. Hold the
clones and lend them to `present`; the per-texture state bookkeeping is
unchanged.
---------
Co-authored-by: Yaekai <21324379+Yaekai@users.noreply.github.com>
Co-authored-by: swarm <swarm@swarm.swarm>
Co-authored-by: Blitz Studios <271002048+jamesn-xt@users.noreply.github.com>
Co-authored-by: andrewpozdnakov7-jpg <andrewpozdnakov7-jpg@users.noreply.github.com>
`victory inspect` named six of the optional header's DllCharacteristics
bits and dropped the rest without a trace. The title executable of
Series 1.0.2.1 carries 0x8160, so its line read
"0x8160 (high-entropy-va, dynamic-base, nx)": the terminal-server-aware
bit (0x8000) was missing from the names while present in the number.
Name the remaining documented bits (no-isolation, no-seh, no-bind,
wdm-driver, terminal-server-aware) and show any bit still without a name
(the reserved ones) in hex instead of dropping it. The new constants sit
with the others in victory-pe's layout::dll_flags.
* GPU: view addresses for tables made afresh (dynamic slots)
A table reaching past a host view heap smaller than the title's (NVIDIA: 1,000,000 slots) is made afresh in dynamic slots, and the shader gets that table's offset. A shader reading a view's address as data (e.g. the BVH builder's base) indexes the view addresses at the table's slots: past the buffer, which had an entry per title slot only, through a root view without bounds, and with no address entered there. The view addresses now have an entry per title and dynamic slot, entered whenever a dynamic slot is made: a view's address, zeros for a null view and for the raw views of ours that root views and host copies' view pairs put in dynamic slots, so no entry of an earlier table stays.
* GPU tests: a table made afresh has its view addresses at its dynamic slots
The test reads an entry only inside the view addresses' buffer (none past it, where the buffer had an entry per title slot only), checks the slot's entry before it is made, after, once it is given back (it stays until the slot is made again: every table made afresh makes all its slots) and once it is made null, checks that a root view and a host copy's view pair made in dynamic slots clear the entries an earlier table left there, and puts a mark past the last entry that a view address noted for a slot past the dynamic ones leaves as it is. It takes any heap size the host gives: a title heap of 4 slots has dynamic slots past it either way.
Decode R32_UINT and R32_SINT numerically and scale their full integer span. Render constant nonzero targets white so they remain distinguishable from all-zero targets.
Co-authored-by: andrewpozdnakov7-jpg <andrewpozdnakov7-jpg@users.noreply.github.com>
The stub that answers a slot a table does not fill reported only the
object kind, the slot and the caller's offset. Two reporters (#829 and
the #417 thread) had to patch it locally, logging rcx/rdx/r8/r9, to tell
what the call carried; one of them asked for it upstream.
The stub now takes the receiver and the next three registers and logs
them as `args=` alongside the rest, once per slot as before. On win64 all
four are registers, so reading them never touches the caller's stack,
and a call made with fewer real arguments only shows whatever its
registers held. That is enough to tell a call passing an interface GUID
or a module address from one passing flags, a count or an out pointer
without rebuilding with a local patch.
Co-authored-by: pablogonz12 <pablogonz12@users.noreply.github.com>
members() tested all 385 register slots to return the few that are live,
twice for every block of a program: 1.27 M tests for a 1,651-block
shader. Walk the seven set words by their lowest set bit instead, in the
same register order. The IR build is 4.5% faster on a synthetic GFX10
program of 12k and 24k instructions, and range::build 4.1% faster.
Co-authored-by: slatefield <slatefield@users.noreply.github.com>
The RX 5700's driver zero-extends the bytes of a dot4 multiplicand it
sees as a constant, so fspx_programs_run_with_the_hardwares_dot_products
failed on RDNA1 although the DXIL asks for signed bytes. Each operand is
now a literal plus a word loaded from the zeroed UAV.
Fixes#1782
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Every root signature we make declares SAMPLER_HEAP_DIRECTLY_INDEXED, and a
list must have a sampler heap bound before such a signature is set (the
debug layer's id 1419, and NVIDIA removes the device with INVALID_CALL for
it: #1754). bind_heaps only ever bound the heaps the title bound, plus our
view-heap fallback for the case the title binds none, so a compute list that
reads views and no samplers -- the list in that report -- set the signature
with no sampler heap bound at all.
There is now a sampler heap of ours, made on first use with a point sampler
in slot 0, bound whenever the title binds no sampler heap; the decision is a
small function with a test, so which heaps a list must have can be read
without a device.
v_cubeid/sc/tc/ma_f32 pick a coordinate (or its negation) as the
result, so a denormal coordinate came out as the host's: kept on AMD,
flushed to -0 on WARP, where the console's float mode reads it as a zero
of its sign. The coordinates now go through ftz first, as min and max's
operands do (77053a0).
A semantics probe runs the four over signed zeros, denormals,
infinities and NaN in each coordinate (14,440 inputs) against the RDNA2
model. Without the change: 2,193 model mismatches on an RX 9070, 1,276
on WARP, and the two disagree on 917.
Found by the cross-device fuzzer (#1614).
Co-authored-by: alexdeliu <240865807+alexdeliu@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* Shaders: 64-bit integer compares on their dwords
v_cmp_{lt,le,gt,ge}_{i64,u64} lowered to one i64 icmp give the wrong
answer on AMD's D3D12 driver when the operands share a dword: `v_cmp_lt_i64
s20, v[1:2], v[2:3]` with v1 = v2 = 0, v3 = 1 (0 < 0x1_00000000) is false
on an RX 9070 (32.0.32029.2010) and on a Ryzen 7700 iGPU, gfx1036
(32.0.21045.29003), as if the dwords were swapped; WARP gets it right.
Disjoint pairs are fine there, and so is equality.
The compare now runs on the dwords: the high ones decide (signed for
i64), equal ones leave it to the low ones (unsigned). It needs no INT64.
The GPU test runs all twelve compares over values whose dword orders
disagree, on disjoint and on shared registers; without the change it fails
on the AMD hardware.
Found by a cross-device fuzzer that compares single VALU instructions on
every adapter and WARP.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Shaders: a signed 64-bit compare's literal sign-extends in the dword split too
main's src64 now sign-extends the 32-bit literal of an _i64 operand
(signed_64_bit_operands_sign_extend_their_literal). The dword compare
read the literal's high dword as zero, so v_cmp_lt_i64 v[1:2], -100
compared against 0x00000000_FFFFFF9C. It now takes the same high dword
src64 would.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: alexdeliu <240865807+alexdeliu@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
A wireless receiver with its controller switched off still answers
XInputGetState with an all-zero state, which connected the empty slot
and disconnected the keyboard stand-in pad.
Keep each host slot disconnected until its current connection reports
non-rest input, reset that flag on disconnect, and keep scripted
diagnostic keys on the stand-in while no host pad has reported input.
Fixes#845.
Co-authored-by: andrewpozdnakov7-jpg <andrewpozdnakov7-jpg@users.noreply.github.com>
* Pipeline: accept existing entry when concurrent cache publication races on Windows
* Pipeline: exercise the blocked Windows cache publication path
Keep the published entry open without delete sharing and assert that replacement is blocked. The regression fails with the pre-fix publication code and passes with the current implementation.
Validation: 5 pipeline tests passed on x86_64-pc-windows-msvc; pipeline Clippy with warnings denied and formatting checks passed.
* Pipeline: adapt concurrent publication test to new tempfile_in signature
* Shaders: v_med3 orders -0 below +0, as RDNA2 does
The ISA defines v_med3_f32/v_med3_f16 over v_min_f32/v_max_f32, which order
-0 below +0 (#448 settled those), so of three zeros the median is the sign
two of them share; DXIL's plain FMin/FMax chain gives either zero. The zero
the chain leaves now takes that majority's sign (11 instructions). A NaN
still gives the minimum of the three.
Noticed while porting the idea of ivall/xcl#1348 (DavidM1911).
Tests: hardware execution tests in valu_tests for both operand orders and
the halves.
Written with an AI assistant.
* Shaders: keep main's med3 lowering, leave only the signed-zero test
main's max_min_flushed chain (77053a0c) already orders -0 below +0, so the
majority-sign select this branch added gives the same result.
---------
Co-authored-by: pgm1207 <104554896+pgm1207@users.noreply.github.com>
Co-authored-by: pablogonz12 <pablogonz12@users.noreply.github.com>
The console ignores blending on integer render targets and the title
leaves it on (the world has a mesh pipeline blending into an R8_UINT
target). D3D12 does not allow it: vkd3d-proton refuses such a pipeline
with E_INVALIDARG and its draws are lost. The host pipeline now turns
blending off on integer targets; with one description for all targets,
each target gets its own copy so the others keep theirs.
(cherry picked from commit 169efcb84eb5d9d83c0af7fe525a54ada86f3a0d)
Co-authored-by: pgm1207 <104554896+pgm1207@users.noreply.github.com>
Co-authored-by: pablogonz12 <pablogonz12@users.noreply.github.com>
ir::build fills every instruction's register lists twice. `effects()`
collects `Vec<Reg>` (two allocations), and the caller immediately maps
each one into `Vec<(Reg, Value)>` (two more), freeing the first pair. For
lists that are almost always two to four entries, that is four
allocations and two copies per instruction, on every instruction of every
program.
Have `effects()` and its helpers collect the `(Reg, Value)` pairs
directly, with the placeholder the SSA pass fills in. Two allocations per
instruction instead of four; `Inst` and everything downstream are
unchanged.
Measured with the synthetic bench in #1002 (no game data), ten
interleaved rounds per arm, nanoseconds per instruction, at 256/1k/4k/16k
instructions:
ir::build 308 -> 269, 375 -> 324, 407 -> 340, 402 -> 353 (0.835-0.878)
translation 898 -> 872, 898 -> 825, 951 -> 875, 956 -> 912 (0.919-0.971)
gfx10::decode, structure, lower and the rest are unchanged. The emitted
DXIL is byte-identical at all four sizes.
cargo test --workspace --locked: 342 passed, 0 failed, 7 ignored.
Both clippy configurations clean; cargo xtask policy ok.
Co-authored-by: pes7 <pes7@users.noreply.github.com>
* xmem: keep the space below 4 GiB for the title's 32-bit memory
XMemVirtualAlloc with the 32-bit address flag has to fit below 4 GiB, where
Windows also puts the host's own memory first (it allocates bottom up). With
a large pipeline cache read at startup, the driver's, heap and cache memory
left 22 MB there, in pieces of at most 14 MB, when Grand Theft Auto VI asked
for a 185 MB 32-bit placeholder; the request was refused
(ERROR_NOT_ENOUGH_MEMORY) and the title stopped at an assertion
(+0x19f4f58). The D3D12 debug layer's memory did the same.
`low_guards::install`, at the start of `run`, reserves the free space below
4 GiB but the lowest 256 MB (left to the host). A 32-bit request that finds
no room releases the smallest guard that fits it (else the largest) and
tries again, then guards what is still free of it.
Tested: the new test releases a guard, takes part of the hole and checks the
rest is guarded again. In the title (RTX 2080, a build with a large cache):
without this the startup failed 2 of 3 times; with it, 5 of 5 starts passed,
3.7 GB below 4 GiB kept for the title.
* Bound low-address allocation retries to existing guards
* xmem: safety comments and formatting for the bounded guard retry
---------
Co-authored-by: swarm <swarm@swarm.swarm>
Co-authored-by: NuraadGit <NuraadGit@users.noreply.github.com>
The early list keeps this run's keys first, then earlier runs' others,
but those came from a HashSet, so once the list was full the keys that
made room were any earlier ones, not the oldest.
Earlier keys now keep their place in the list as loaded. The list is
saved most recent run first, so sorting by that place drops the oldest
runs' keys and keeps the order across saves. A list saved by an earlier
build (in no order) still reads.
`save` also reads the list through `used()`, so a save before anything
read it in this run keeps the saved list instead of writing an empty one.
RDNA2 flushes denormal operands of the legacy multiplies to zero, so
0 x anything = 0 also holds for them. The lowering only tested for an exact
float zero, whose result also depends on the host's denormal mode. Test the
exponent bits instead. Follow-up to #2.
* GPU: mirror placed unordered texture views (#921)
Resolve `View::Placed(true, ...)` texture descriptors through
`placed_texture` to `View::Unordered` on the shared host texture for
that memory so placed unordered texture views bind real D3D12 UAVs and
transition to `UNORDERED_ACCESS` instead of falling back to null UAVs.
Refresh an already-mirrored placed texture slot when a later unordered
or renderable view upgrades that memory's `HostTexture`, and apply
`alias_source` copies to explicit SRVs superseded in `MEMORY` as well
as placed SRVs so compute writes at one guest address stay visible
regardless of view creation order.
Also resolve `DXGI_FORMAT_UNKNOWN` (`0`) view descriptions from
`resource::view_format` when the host copy is typeless or castable, and
check `typed_store` as well as typed-depth/typeless view exclusions in
`fits` before creating host SRVs/UAVs.
* GPU tests: dispatch a guest shader through a placed texture UAV
* GPU tests: declare the placed UAV tests beside the other pipeline modules
---------
Co-authored-by: andrewpozdnakov7-jpg <andrewpozdnakov7-jpg@users.noreply.github.com>
Fixes#181.
Concurrent WARP (d3d10warp.dll) usage across threads crashes with
0xC0000005 on Windows 11, both when creating/tearing down separate
WARP devices and when compiling pipelines or executing work concurrently
on a single shared WARP device.
Keep one process-wide WARP ID3D12Device in Host::new (for explicit
warp = true, VICTORY_WARP=1, and systems whose default DXGI adapter
has DXGI_ADAPTER_FLAG_SOFTWARE) and serialize WARP root signature
creation, pipeline compilation, draws, and dispatches behind a
process-wide mutex. Hardware D3D12 devices remain unserialized.
Route diff_tests's direct CreateRootSignature calls through
Host::root_signature_bytes so they share the same serialization, and
add a multi-threaded WARP regression test (parallel_warp_pipelines_and_draws).
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* Shaders: reuse SSA sums when tracing memory addresses
Co-Authored-By: GPT 6.2 Sol <noreply@openai.com>
* Shader tests: an address from no root parameter is title memory
Main reads such an address as title memory instead of refusing it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: GPT 6.2 Sol <noreply@openai.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
XAsyncComplete held the call's `done` lock while the title's provider
ran OP_CLEANUP. A cleanup that waits for a worker thread which is itself
completing the same call (it took the call before the cleanup removed
it) deadlocked: the worker blocks on `done`. The first completion now
claims the call with an atomic flag and runs unlocked; the status is
still published after the cleanup, while the block is valid, and `done`
is set only for the waiters.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
A new committed resource is not always zeroed: on the CI's WARP the
512 KiB mark buffer of heap_direct_texture_reads_mark_their_heap_index
came back holding the page table an earlier test had uploaded and
freed, so the test saw 16,389 bits besides the one the shader set.
Buffers, root UAVs and UAV textures are now made as copy destinations
and get zeros from an upload buffer before the dispatch.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
What was wrong: buffer and typed-buffer loads of normalized formats
(UNORM, SNORM) converted a code by dividing it on the host. The host's
division is not exact. On the RX 6700 XT, 125 of the 256 8-bit codes
loaded one ulp high, and 16-bit codes such as 257, 261, ..., 32896
loaded one ulp low; WARP was exact. The console's buffer unit gives the
float nearest the exact quotient, and titles rely on it in decisions:
Grand Theft Auto VI's mesh programs read a material index from a vertex
colour's alpha as `v_mul_legacy_f32 255.0` then `v_cvt_u32_f32`. A
quotient one ulp low truncates to the code below (the 16-bit codes above
did), so another material is picked.
What changed: for formats up to 16 bits per channel the quotient
a / (2^n - 1) is worked out from integers: Q = floor(a * 2^32 / d) as
a * K plus a correction (none when n divides 32), rounded to 24 bits up
exactly when its highest dropped bit is set (the quotient is never
exact, so never a tie), and that integer, at most 2^24 and so exact as a
float on any host, scaled by a power of two. The reference is the exact
quotient rounded to the nearest float, which removes the dependence on
how the host rounds a division or converts a large integer (WARP rounds
integers above 2^31 otherwise). Signed formats convert their magnitude
the same way; their two lowest codes stay -1.0. The 11- and 12-bit
widths, whose smallest codes need more bits, are rounded fully in
integers.
Cost: about 18-21 DXIL operations a channel where the division was 2 (a
division by a constant more where n does not divide 32), so a 4-channel
8-bit fetch is about 80 operations instead of about 12. The car body's
mesh program grows from 4,616 to 5,103 instructions (+487 for about 23
normalized channels). In the title it is not measurable: in a run of
the intro cutscene with this commit (cost2, on the previous main
4015a182), on world windows with no pipelines being made, the frame
median was 881 ms and the GPU 349 ms a frame (median 335), against
1,013 and 389 (365) for the same tree without it (s1a). Two runs of one
tree have differed by 132 ms of GPU a frame, so the difference is
within run-to-run noise.
Evidence: tests `normalized_buffer_formats_load_correctly_rounded_quotients`
(every 8- and 10-bit code and a 16-bit sample, unsigned and signed,
bit-exact on hardware and WARP; it failed on the RX 6700 XT before, at
8-bit code 3) and `normalized_codes_truncate_back_to_themselves` (the
title's truncation gives every code back; 16-bit code 257 came back as
256 before). Offline, the integer arithmetic as emitted matches the exact
quotient for every code of every width 2 to 16.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings back PR #1012's recursive heap index (taken back by fbac5bb6): a
descriptor every lane shares, chosen by an if/else nested in another,
reaches the outer join with an edge that is itself a join; its heap index is
a phi at each join of what each predecessor computes at its end. It lets
`indirect_diffuse_lighting:CS_ScreenProbes_ActivateRays` (39f0e9aeb156a61c,
issued every cutscene frame) through, whose host pipeline the AMD driver
could not make before the two commits ahead of this one.
The program itself is large: 74,700 GFX10 instructions, 11,896 branches
(488 backward), 1,889 typed buffer loads, each after a reload of the same
descriptor. Its DXIL, and what the AMD driver (RX 6700 XT, 32.0.21045)
does with it:
| | #1012 alone | now |
|---|---|---|
| lines (dxc -dumpbin) | 151,610 | 24,896 |
| branches (conditional) | 22,382 (10,040) | 3,070 (1,295) |
| blocks | 22,384 | 3,072 |
| heap handles | 2,608 | 65 |
| size queries | 2,477 | 0 |
| phis | 2,883 | 1,124 |
| DXIL bytes | 864 K | 144 K |
| validator | passes | passes |
| host pipeline | over 6 GB at 64 s, never finished (26.7 GB unwatched) | 2.36-2.45 GB, 78-107 s (with other work on the machine) |
What remains costly is the program's shape: one loop of 2,941 blocks
holding 1,239 of its 1,295 conditional branches, an inner one of
1,440 (the largest loop of the largest program by DXIL bytes,
RTShadowTrace32TemporalHQ_OneOver4RPP_Tiled, has 110 blocks; it compiles in
14 s, 353 MB). Making every branch uniform (an experiment) took the compile
to 1.9 GB and 54 s, so divergence is not most of it. The pipeline library
keeps it after the first make.
WARP refuses the pipeline at once (E_INVALIDARG): the program declares the
console's wave size (32), which WARP's 4-lane waves cannot run, as for every
compute program that declares one.
Whole list, translate --list --validate: 0 newly failing, 1 newly emitted
and validated (this program). Test: the nested-join lowering test is back
(`descriptors_joined_by_nested_control_flow_lower_to_one_uniform_handle`).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The debug layer reported ~16 resource-state errors a second in the world
on main (run light21) and with the queue order (light19), four kinds:
Depth twins, and 16-bit depth textures with twins (COPY_SOURCE, UNORDERED_
ACCESS and COMMON against DEPTH_WRITE): a list's prelude swapped each
texture's real state for the one the list leaves before recording the
twin copies it owed, so those copies moved the textures from the wrong
states. The prelude now records the copies from the real states, then the
list's moves from them, and only then stores the states the list leaves.
The title's 174 MB GPU heap, bound as a vertex buffer while in UNORDERED_
ACCESS, and barriers on it disagreeing with the state an earlier vertex
binding promoted it to: our only transitions on a title buffer's copy were
the indirect clamp's, UAV to INDIRECT_ARGUMENT and back to UAV. The clamp
now reads the title's records through a root view and writes the clamped
ones into an argument buffer of the list's own, which the execution reads;
only that buffer is transitioned (common, unordered access, indirect
argument, common). Title buffers' copies are never transitioned: common
between submissions, promoted by every use, ordered by unordered-access
barriers (the shortcut is in indirect.rs). The clamp no longer writes the
copy of the title's memory; the capture's read-back reads the clamped
records from the list's buffer.
Tests: a transition log (every barrier built on the test thread) replayed
in GPU order by the debug layer's rule: twin::tests::prelude_copies_start_
from_the_real_states (fails on the old order: "before COPY_SOURCE, the
resource is in COMMON", run light21's message) and indirect::tests::
argument_buffers_move_from_their_current_states (two lists in either
order; the title's copy untouched); the clamp tests now also check the
whole title copy is as written.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The console runs pixel programs in whole-quad mode: in every quad a
triangle edge crosses, the pixels outside the triangle run as helpers, and
the compiler takes derivatives of computed values (and quad reads) by
reading the neighbour's register with DPP `quad_perm` or `ds_swizzle`. We
lowered those reads to `WaveReadLaneAt` unless the program discards. Wave
operations leave helper lanes out on the host, and on AMD a read of one
gives 0: every pixel whose quad neighbour lies outside the triangle took a
wrong derivative, along every triangle edge. WARP includes helpers in wave
reads, so the tests passed there.
Quad-local reads in pixel programs now always go through quad reads
(`QuadReadLaneAt`), as they already did after a discard. What the host
guarantees there: helper lanes execute the program so that derivatives
can be taken, and quad operations include them (wave operations do not),
so a quad read of a helper gives the value that helper computed, as the
console's DPP read of a whole-quad-mode lane does. A discarded pixel stays
a helper in the same way.
Tests: two control-flow cases draw a triangle whose diagonal crosses
quads (`ddx_fine`, `ddy_fine`, `QuadReadAcrossDiagonal`, `QuadReadLaneAt`
of a computed value, console compiler against PC DXC). "derivatives and
quad reads across a triangle edge": before, RX 6700 XT 24 of 256 texels
differ (texel (0, 0): ddx -1 instead of 15, the helper read as 0), WARP 0;
now 0 and 0. "discard, then derivatives and quad reads across a triangle
edge" discards some neighbours before the reads (the path that used quad
reads already): 0 and 0.
Whole list (translate --list --validate): 3,005 pixel programs change,
84,589 read sites (median 15 per program, at most 732); no program changes
outcome. DXIL 1,197,299,944 -> 1,203,716,752 bytes (+0.54 %) on top of
the writer folding (on main without it: 1,423,424,800 -> 1,429,871,224),
blocks unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since the read marks, every vertex, geometry and mesh program that reads a
texture from the resource heap writes the marks' UAV (the write marks do
the same for programs writing through views), and its shader flags did not
declare "UAVs at every stage" (ShaderFlags bit 16, SFI0 0x4): the validator
refused 5,046 programs of the title's list with "Flags must match usage"
(VS_OctaWindFire_e6901d4b: declared 0x40000010, actual 0x40010010). The
runtime does not validate, so their pipelines were made, but a driver may
trust the flags.
The validator counts UAV ranges the module declares, not UAVs indexed from
the heap: `finish` sets the flag (and the SFI0 bit) when a program that is
neither a pixel nor a compute program declares any (root UAVs, the memory
bitmap, the marks). Counting every handle annotated as a UAV instead set it
wrongly for 26 mesh and vertex programs whose only UAVs come from the heap
(`MST_DS_TerrainTransform` and others: declared 0x40092000, actual
0x40082000).
Whole list (translate --list --validate), validated: vertex and pixel
13,313 -> 14,254 of 14,254, mesh 4,625 -> 8,694 of 8,765 (the other 71
have outputs over 32 KB), compute 1,984 of 2,732 unchanged (748 sample
with implicit LOD); no program newly fails.
Test: `emit::shader::tests::uavs_outside_pixel_and_compute_programs_are_declared`
(a marked vertex, pixel and compute program and a vertex program writing a
heap-indexed UAV each pass the validator; the marked vertex program fails
as the list's did without the flag, the heap one with it).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since 4243a96a ("16-bit typed buffer accesses pass bits through integer
views") a 16-bit typed buffer access reads its view's format kind from the
host's view-stride table, root SRV `t255` (`VIEW_STRIDES`), also for views
in tables. The differential harness asserted that a translated program's
root views are only the case's own (slots 4 and 5), so the case "16-bit and
64-bit arithmetic" (`RWBuffer<half4>` stores through
`buffer_store_format_d16`) failed on its root SRV 255 before anything ran,
in every run with the console compiler since that commit (eed16700 passes,
4243a96a fails).
`host::view_strides` builds the table as `victory_gpu` fills it for the
harness's view heap (element sizes, the integer and signed bits of typed
views of integer formats), and the harness binds it where a program asks.
The case now runs and matches the console compiler's program on the RX 6700
XT.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The console compiler reloads a descriptor before each use rather than keep
it (`indirect_diffuse_lighting:CS_ScreenProbes_ActivateRays` loads table
offset 0x640 2,399 times, once before each of its typed buffer loads), and
lowering made a heap handle at each load: index arithmetic, for heap
buffers the host-view guard, `createHandleFromHeap`, `annotateHandle`.
A descriptor resource tracking finds at a fixed address (a table or heap
entry, no dynamic term, not a waterfall loop's per-lane load) now gets one
handle for the program, made in the entry block from the root parameter's
user data. A descriptor chosen by control flow (a phi of heap indices at a
join) gets one handle made in its join block, shared by every access the
join dominates, instead of one per access. Read marks still go with each
access, at the handle's index.
ActivateRays (with nested joins allowed, the commit after this one):
2,608 heap handles before the DXIL writer's folding, 674 after it, 65 with
this. Whole list, translate --list --validate: 0 newly failing; DXIL
bitcode 1,246,729,828 -> 1,197,299,944 (-4.0 %) bytes.
Tests: `descriptors_reloaded_from_a_root_table_share_one_handle` (a
descriptor loaded in a branch and again after it: one handle), written heap
handles counted from the module (`Module::written_calls`).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Lowering leaves much in the DXIL that never runs or counts: branches on
constants (lane conditions structurisation already knows, edges no lane
takes) and the code only their other edge reaches, empty blocks that only
forward to the next, size queries for descriptor words no path reads. The
host driver compiles all of it. `indirect_diffuse_lighting:CS_ScreenProbes_
ActivateRays` (with nested descriptor joins, PR #1012) is where it showed:
8,745 of its 10,040 conditional branches were on constants, 10,061 of its
22,384 blocks empty forwarders, about 70 % of its instructions reachable only
through constant branches' dead edges, and 556 of the 587 size queries in
the rest unread; the AMD driver never finished it (over 6 GB at 64 s).
The writer (`Module::plan`, `Module::kept`) now:
* takes a branch on a constant as a branch to its one target: blocks only
the other edge reaches are not written, and phis lose the entries of edges
that are gone (their other entries stay);
* folds an empty block with one predecessor into it (the predecessor
branches to its target), unless it splits a critical edge (lowering keeps
loops' exits and preheaders dedicated, as DXC emits them) or its
predecessor would then reach the target twice (one phi entry per
predecessor); empty latches fold as before;
* writes only instructions with effects (stores, atomics, calls neither
read-none nor read-only: barriers, discard, wave operations, the write and
read marks) and what they read, transitively (it dropped only unread phis
before);
* declares only the functions it calls and the constant globals it reads
(the validator refuses the others);
* and the shader flags of heap handles, wave operations and 64-bit integers
follow what is written (`Module::uses`; the validator refuses a flag
whose use is gone, "Flags must match usage").
Whole list (shaders.rpf, the exe, XboxBvhBuilder, the upscaler;
translate --list --validate, against 8ff79135): 0 programs change outcome
(14,254 VS/PS, 2,732 compute, 8,765 mesh emitted; 13,313 / 1,984 / 4,625
validated, as before); DXIL bitcode 1,423,424,800 -> 1,246,729,828 bytes
(-12.4 %), blocks 3,624,448 -> 3,554,816 (-1.9 %).
ActivateRays itself is still refused here (nested joins); its table is in
the commit that lets it through.
Tests (`emit::bitcode`): a constant branch drops its other side and that
side's phi entry only; a loop whose back edge is never taken; empty blocks
before a phi fold only where the entry can move; only values with effects or
readers are written (read-none and read-only calls, stores, atomics,
barriers); constant globals nothing reads are left out; uses count only
what is written. The writer's pinned
bytes are pinned anew (its test module's last call became one with effects).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What was wrong: each refresh of a tracked texture read the changed
title memory into a buffer allocated for it, the texture's whole size
(5.6 MB for a BC7 2048), zero-filled and touched page by page: a
zero-fill and a page fault per 4 KiB for every texture brought up
(129,071 page faults while preparing in one frame of run placed1). The
detile itself is not the cost: a BC7 2048 64KB_D texture detiles at
0.04 ms per MB on this machine, as fast as a plain copy of its bytes,
against ~2.2 ms per MB for a whole refresh.
What changed: the read goes into a buffer the worker thread keeps for
its next refresh (up to 32 MiB; larger ones are not kept). Only the
touched spans are written, and only they are hashed and detiled, as
before. In diagnostics builds, the scan of each texture read for all
zeros runs only when its debug message is wanted.
Evidence: the texture upload tests, which refresh several textures and
single mips on the same threads, pass (victory-gpu 193 passed, twice).
Run scratch1 (240 s of the intro cutscene, quiet, on the same main as
run placed1): texture refreshes 177 ms of worker time for 98 MB a frame
(1.8 ms per MB) against 235 ms for 105 MB (2.2 ms per MB). Its whole
frame was slower (median 1,010 ms against 894) through GPU time (mean
450 ms against 318) and after-work, which this change does not touch:
one run each, run-to-run variance not separated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>