Commit Graph

4163 Commits

Author SHA1 Message Date
ef205eec98 xbox_bvh_builder: review fixes for batched rehydration (RT-XDXR-BVH-REHYDRATE-BATCHED2X)
Maintainer fixes on top of the author's rehydration, carried over from the
reviewed branch onto the rewritten head:

- Scratch: each element of a batch gets a region of its own in one buffer
  per call, at D3D12's acceleration-structure alignment, and the command list
  holds that buffer until its next Reset (rt::d3d12::hold_until_reset). Before,
  every element and every list shared one builder-wide buffer with no barrier
  between the builds, and growing it released a buffer that builds already
  recorded could still use.
- Fresh builds: a rehydrate always builds from geometry. PERFORM_UPDATE is
  cleared together with SourceAccelerationStructureData, so the layer never
  refits from the dehydrated stream's bytes.
- The leaf frame compressionParams gives is described as not applied yet,
  which is what the code does.
- The test reads back rehydrated builds made without scratch
  (ScratchAccelerationStructureData = 0), the shape the title uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 14:37:34 -05:00
721a3b85ae Merge main into wave64-partial-wave-zero
Conflict in scripts/run_gpu_tests.py: the dump-test name list gained
cs_w64x_cmp_sdst on main and cs_w64x_partial_swizzle here; both are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 14:37:20 -05:00
65235f36ad test: update rehydration test comment to specify geometry rebuild (RT-XDXR-BVH-REHYDRATE-BATCHED2X)
AI-assisted (Claude Code, Claude Opus 5.5)
2026-11-25 22:30:44 +03:00
b352aa9be9 xbox_bvh_builder: supply scratch buffer and address review feedback (RT-XDXR-BVH-REHYDRATE-BATCHED2X)
- Fix log_once call signature at line 268 (passes flag, text without format args).
- Do not copy source_data into SourceAccelerationStructureData to avoid unwanted refit
  on update paths (d3d12_vulkan_device.cpp:2639).
- Allocate and supply scratch buffer via builder_ensure_scratch when the title passes
  ScratchAccelerationStructureData = 0 (docs/xdxr.md §6), avoiding command list poisoning.
- Retain the leaf-frame note (compressionParams, docs/bvh.md §4a) in comments and docs.
- Remove stale deserialize references in test comments and update test coverage.

AI-assisted (Claude Code, Claude Opus 5.5).
2026-11-25 22:30:44 +03:00
cb1cb86e92 xbox_bvh_builder: rebuild from geometry and refuse source-only rehydration (RT-XDXR-BVH-REHYDRATE-BATCHED2X)
Addresses review feedback on #1759 from @aslan2142 and @Tyrannys:
- RehydrateRaytracingAccelerationStructureBatched2X now rebuilds structures
  exclusively from geometry (docs/bvh.md §4a).
- Offline console dehydrated streams cannot be directly deserialized by
  PC D3D12/Vulkan drivers (docs/bvh.md §4/§4a). When source_data is present
  without geometry descs, the shim logs once and refuses with E_NOTIMPL.
- Documented in docs/xdxr.md that the 4th parameter (const UINT64* source_data)
  is a hypothesis denoting offline console stream pointers.
- Empty structures (NumDescs == 0 without source) are logged once and skipped.
- Updated runtime/test/xbox_bvh_builder_test.cpp and tests/test_xbox_bvh_builder_rehydrate.py
  to verify refusal of source-only streams (E_NOTIMPL) and handling of empty structures.

AI-assisted (Claude Code, Claude Opus 5.5).
2026-11-25 22:30:44 +03:00
07e89b1935 xbox_bvh_builder: implement RehydrateRaytracingAccelerationStructureBatched2X (RT-XDXR-BVH-REHYDRATE-BATCHED2X)
Implements XboxBvhBuilder::RehydrateRaytracingAccelerationStructureBatched2X
in runtime/shims/xbox_bvh_builder.cpp. The shim now rebuilds or deserializes
each acceleration structure on the command list via ID3D12GraphicsCommandList4
rather than stubbing out with E_NOTIMPL, resolving the interactive boot stop
reported by timbot103 past story-load texture streaming.

Validates count == 0 (S_OK), null list / descs (E_INVALIDARG), and adds unit
coverage in tests/test_xbox_bvh_builder_rehydrate.py and runtime/test/xbox_bvh_builder_test.cpp.

AI-assisted (Claude Code)
2026-11-25 22:30:44 +03:00
e18b59a5b7 Merge pull request #1612 from Tyrannys/first-run-pad-focus
runtime: the first-run UI keyboard pad reads keys only with focus (RT-FIRST-RUN-PAD-FOCUS)
2026-11-25 20:30:08 +01:00
804f97479f runtime: guard null and invalid sizes in value_write_sink and add unit tests (RT-VALUE-WRITE-SINK-GUARDS-AND-TESTS)
Harden runtime/src/value_write_sink.h:
- Guard arena() against null buffer pointers and non-4/8-byte sizes by immediately returning Landing::refused, preventing null dereference and invalid writes.
- Guard title_pages() against null addresses, null bytes, and zero size by returning false immediately.
- Guard clear_arena() to reject null device pointers.
- Add clear_title_pages() and reset_for_test() to allow clean state resets across tests and teardown.
- Add portable CPU-only CTest unit test runtime/test/value_write_sink_test.cpp verifying initial state, guards, arena and title_pages dispatch, device-matched clearing, and multi-threaded concurrency.

AI-assisted (Claude Code)
2026-11-25 22:29:11 +03:00
cee965560c Merge pull request #1814 from timbot103/d3d-clear-uav-3d-slice
D3D-CLEAR-UAV-3D-SLICE: clear selected 3D UAV slices and rectangles
2026-11-25 20:29:08 +01:00
2355e60885 Decode generated shader fixture paths as UTF-8 2026-11-25 13:28:58 -06:00
75a41f5dc2 Merge pull request #1896 from IlyassRS3/fix/rt-indirect-topologies-and-stats
runtime: support dynamic topologies in indirect draws and report per-reason skip counts (RT-INDIRECT-TOPOLOGIES-AND-STATS)
2026-11-25 20:28:13 +01:00
b904919ab4 Merge pull request #1832 from IlyassRS3/fix/rt-indirect-clamp-sharing-and-safety
runtime: share indirect clamp buffers across queue families and fix safety bugs
2026-11-25 20:27:08 +01:00
369bb1c753 d3d12: gate SO_STATISTICS pools and refuse per-stream overlap (D3D-302)
The three review points on #1630:

- prepare() refuses two overlapping SO_STATISTICS queries on one stream: two
  active indexed queries in one pool break
  VUID-vkCmdBeginQueryIndexedEXT-queryPool-04753. Queries on different streams
  are fine.
- The transform-feedback pool now also needs the transformFeedbackQueries
  property, and a stream at or above maxTransformFeedbackStreams runs nothing
  and resolves zero instead of issuing an invalid indexed begin.
- replay_query_predication case 18 fails without both: the overlapping-stream
  list is invalid_query and a stream past the pool's stream count fills zeros.

Tested: d3d12_vulkan_device, d3d12_state_map and replay_query_predication pass
plain and with LEONIDA_VK_VALIDATION=1 (RTX 3080 Ti, driver 616.64). AI-assisted.
2026-11-25 14:24:41 -05:00
ff2e459123 vk_sampler_test --cube/--3d/--dref; ps_ssharp_cube, ps_ssharp_3d, ps_ssharp_c: the S# mip fields on cube, 3D and depth-compare samples (SHADER-EXPLICIT-LOD-BIAS-MVK)
GPU coverage for the rest of --explicit-lod-bias's forms. vk_sampler_test gains
a mode for a 6-layer cube (images_arr), a 128x128x2 volume (images_3d) and a
D32 texture (0.25 / 0.75 per level) with the S#'s compare function; the 2D
default is unchanged. check.py's SAMPLER_FIXTURES names each shader's mode and
judges ps_ssharp_c as compare results.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 20:21:58 +01:00
205bda4a4a Merge pull request #1941 from abnalstlll-byte/feat/rt-texture-tiles-host-adapter
test: respect LEONIDA_HOST_ADAPTER and layer LUID in d3d12_texture_tiles (RT-TEXTURE-TILES-HOST-ADAPTER)
2026-11-25 20:20:30 +01:00
e380a69a60 Merge pull request #1950 from kurrutako/rt/session-cache-at-exit
d3d12: write the session pipeline cache when the run ends with the device alive (RT-SESSION-CACHE-AT-EXIT)
2026-11-25 20:15:15 +01:00
ca0c72f810 runtime: guard empty destination and null data in write_pipeline_cache_file and add tests (RT-PIPELINE-CACHE-FILE-GUARDS-AND-TESTS)
Claimed in Issue #1608 as RT-PIPELINE-CACHE-FILE-GUARDS-AND-TESTS.

AI-assisted (Claude Code)
2026-11-25 22:14:24 +03:00
0bba07bf12 runtime: guard stack region wrap/underflow and null inputs in thread_stacks 2026-11-25 20:12:08 +01:00
4cfbdfc0b2 Merge remote-tracking branch 'origin/main' into rt-xapu-opus-on-1144 2026-11-25 14:12:01 -05:00
a5dd540bcc xapu: decode Opus packets through runtime/opus_decoder (RT-XAPU-OPUS-DECODE)
Builds on #1144 (RT-XAPU-CONNECT-LAYOUTS): the queue and layouts stay there;
fill() decodes each process packet through a Rust C-ABI crate over BSD-3
opus-pure when cargo builds it, and keeps the table-of-contents silence path
otherwise. Adds xapu_opus_test (a generated 440 Hz stereo packet decoded to
960 frames) and the CMake wiring; xapu_chad_test keeps covering the layouts
and the silent path. No game data.
2026-11-25 14:11:53 -05:00
14e1a352c4 runtime: guard null bind callbacks, add owner accessor and unit test suite for DeferredImageBinding (RT-DEFERRED-IMAGE-BINDING-GUARDS-AND-TESTS)
Claimed in Issue #1608 as RT-DEFERRED-IMAGE-BINDING-GUARDS-AND-TESTS.

AI-assisted (Claude Code)
2026-11-25 22:09:19 +03:00
9fc1862fad runtime: free unused thunk on zero redirects and harden code_hooks bounds 2026-11-25 20:09:18 +01:00
c37374180b Merge pull request #1887 from IlyassRS3/rt-console-heap-vsharp-bitset
d3d12: track live console-heap V# slots in a host-RAM bitset (RT-CONSOLE-HEAP-VSHARP-BITSET)
2026-11-25 20:06:41 +01:00
892f627082 runtime: guard window-fit zero dimensions, signed overflow, and OOM in lifecycle shim 2026-11-25 20:06:10 +01:00
f2e3a77fea d3d12_title_va_test, d3d12_compute_test: serialize root signatures through the shared helper, so the heap-directly-indexed cases run on Windows 10
Both tests carried their own copy of serialize(), which calls the in-box
D3D12SerializeVersionedRootSignature directly. Windows 10's d3d12.dll
(10.0.19041) refuses CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED at root signature
1.0 and 1.1 (E_INVALIDARG, "Unsupported bit-flag set"), so the cases that
set it stopped at an empty blob before reaching the code they test.
d3d12test::serialize_root_signature (d3d12_test_shaders.h) already retries
without the flags and puts them back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 21:06:10 +02:00
e6f34ed080 d3d12: say when the driver's pipeline cache stops keeping new pipelines (RT-PIPELINE-CACHE-GROWTH-STALL)
A driver can stop adding to a large VkPipelineCache with no error. On NVIDIA 610.88 a 1.23 GB or 1.35 GB cache
came back the same size to the byte after a 2 s compile, so the next run compiles the same pipelines again and
nothing says why. The runtime now takes the cache's size at creation and at each session save, counts the title's
pipeline builds that took at least 200 ms, and logs once when 16 or more compiled while the cache grew less than
64 KiB. pipeline_cache_store_test covers the decision; docs/d3d12_vulkan.md records the measurements.
2026-11-25 13:04:29 -06:00
09014c5e6f Normalize file byte order in the SPIR-V reader 2026-11-25 13:02:25 -06:00
98b22aee0b ps_ssharp_ld, ps_ssharp_b: the S# mip fields on image_sample_l, _d and _b, judged by SAMPLER_CASES (SHADER-EXPLICIT-LOD-BIAS-MVK)
GPU coverage for the --explicit-lod-bias paths ps_ssharp doesn't run: the Lod
of image_sample_l, the 2^bias Grad scale of image_sample_d and the bias of
image_sample_b. check.py's SAMPLER_FIXTURES runs all three with the same cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 19:58:22 +01:00
0233a9ec73 runtime: guard null out pointers, add inspection helpers and unit tests for PlacedDepthTextures (RT-XS-PLACED-DEPTH-GUARDS-AND-TESTS)
Claimed in Issue #1608 as RT-XS-PLACED-DEPTH-GUARDS-AND-TESTS.

AI-assisted (Claude Code)
2026-11-25 21:56:23 +03:00
c09ee75c0e d3d12: geometry views drain on the submit thread, bound the release queue, keep one empty block
- Drain released geometry ranges only in the submit-thread before_execute callback, removing recording-thread drain calls and GeometryViews::should_reclaim().
- Filter geometry_writes::note_released() against monotonic watched_lo/watched_hi bounds and collapse the queue on 65536-entry overflow instead of dropping ranges.
- Bound GeometryViews::retire_range() walks using max_view_bytes_ and an ordered refused_ map with max_refused_bytes_.
- Keep one empty 4 MiB spare block in TitleBufferWindows (dropping it when needed under a cap), remove failed_ reset in free(), and cover all four points in geometry_views_test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 20:54:56 +02:00
6198879899 Use UTF-8 for shader library module filenames 2026-11-25 12:54:09 -06:00
2e8a92d72a runtime: guard base_reservation parsing and VirtualQuery loop overflow 2026-11-25 19:47:42 +01:00
b65ec46b7c runtime tests: vk_null_descriptor_test builds without glslangValidator
ba626820 added the test with a guard in main only: without glslangValidator
CMake leaves LEONIDA_TEST_NULL_DESCRIPTORS_SPV undefined, but run() still
names it, so the file does not compile and the Linux runtime build, which
installs no glslang (runtime.yml linux-gpu-tools), stops there. Compile the
helpers only with the shader, as main already assumes, so the test reports
itself unsupported (77) like the other GLSL-based tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 19:46:48 +01:00
61c3421875 Keep queued flips when reapplying the frame period 2026-11-25 12:46:44 -06:00
e54c69175a d3d12: evict geometry views on range release and retry refused ranges
RT-GEOMETRY-VIEW-EVICTION: free GeometryViews entries when their backing
title range is released or unmapped, deferring Vulkan storage reclamation
until in-flight GPU work completes, and retry cap-refused ranges once
budget is freed.

- Queue released title ranges from xmem (XMemFree/Default, VirtualFree
  MEM_RELEASE/MEM_DECOMMIT, XMemMapPhysicalPages unmap, CopyPageMappingsBatchX
  unmap range) via leonida::geometry_writes::note_released.
- Add coalesced sub-range freeing and empty-block Vulkan destruction to
  TitleBufferWindows.
- Retire overlapping views immediately from lookup/find/refresh/watch and
  title_va_aliases, and reap their backing storage once
  completed_retire_ticket() reaches the view's retire ticket.
- Track free_generation_ per refused key so resolve() short-circuits while
  nothing changed and retries once budget is reclaimed.
- Extend geometry_views_test.cpp with small-cap eviction, deferred GPU
  retirement, retry, and full block reclamation checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 20:46:30 +02:00
52d768a0dc runtime: respect IndependentBlendEnable=FALSE in B4G4R4A4 stand-in blend fallback 2026-11-25 19:44:56 +01:00
a013410f8e runtime: guard rel32 range, stub_page arithmetic, and VirtualProtect failure in clzero_patch 2026-11-25 19:42:17 +01:00
7f56e6a50b runtime: step try_clzero_loop by VirtualQuery regions and guard wraparound in cpu_emulation 2026-11-25 19:39:50 +01:00
a03715c46a vk_subgroup_info --lod-bias: measure mipLodBias with one compute dispatch, no test programs needed (SHADER-EXPLICIT-LOD-BIAS-MVK)
tools/vk_lod_bias.py clears a two-level R32_SFLOAT image to 0.0 / 1.0 and
samples it at explicit LOD 0 through samplers with mipLodBias 0 and +1, from
Python through ctypes. vk_subgroup_info.py --lod-bias reports the answer as
explicit_lod_bias; lod_bias_probe.py uses it first and draws ps_ssharp only as
a fallback, with the Homebrew llvm-mc hint when llvm-mc is missing (#1774
review). build.py and make_game.py can now measure too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 19:38:34 +01:00
ed34b996ce runtime: harden submit_phases period parsing and skip Scope overhead when disabled 2026-11-25 19:35:17 +01:00
0c4bdde51c runtime: guard overflow/div-by-zero and remove duplicate passes in d3d12_xs_alloc_size 2026-11-25 19:32:28 +01:00
065df3d8b2 runtime: guard align_up_saturating against zero alignment and add unit tests (RT-XS-ALLOC-SIZE-GUARDS-AND-TESTS)
Guard align_up_saturating against zero alignment (to == 0) in runtime/shims/d3d12_xs_alloc_size.h, avoiding division by zero and underflow.

Add standalone CPU-only unit test runtime/test/d3d12_xs_alloc_size_test.cpp covering align_up_saturating, render_target_element_bytes, console_depth_planes, console_render_target_size, console_depth_stencil_size, and console_placement.

Register test executable and CTest in runtime/CMakeLists.txt.

AI-assisted (Claude Code)
2026-11-25 21:29:28 +03:00
cf5127e811 runtime: early-exit pending_through and cache semaphore completions in RetireTickets 2026-11-25 19:28:17 +01:00
2cca47b5c8 loader: compat run-time loads honour LoadLibraryEx flags and Windows-loaded dependencies
Review follow-up for #1565:
- LoadLibraryEx with DONT_RESOLVE_DLL_REFERENCES on a LEONIDA_COMPAT_DIR module fails with ERROR_NOT_SUPPORTED, before loading or returning a loaded handle, as for bundled DLLs.
- A compat DLL that Windows loaded as another compat DLL's dependency is recognised: compat_handle() finds it by its full path, and owns_compat_handle() by its folder (read outside mutex_, since GetModuleFileNameW can take the loader lock), so GetModuleHandle and LoadLibrary return it and GetProcAddress never fills in a missing export from the shim.
- A name with a directory gets the compat DLL only when it is that file; any other path goes on as without the folder.
- Names outside ASCII reach the compat lookup (it runs before the ASCII / wide split).
- The folder's file names are listed once per Loader, so lookups no longer touch the disk.

loader_test: test_compat_runtime_edges adds six cases for the first four points, through LoadLibraryExA/W, LoadLibraryW, GetModuleHandleW and GetProcAddress; all six fail on 582e14d. The listing has no functional test.
2026-11-25 15:15:43 -03:00
e500e99494 d3d12: CPU-fillable placed BC images share a zero image without host copies too
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 19:14:30 +01:00
435d7541fe dstorage: harden staging_bytes overflow and StagingPool::Lease reuse 2026-11-25 19:11:10 +01:00
fba6ce2427 runtime: add O(1) envelope fast path and explicit wrap to title_texture_refresh 2026-11-25 19:06:48 +01:00
28fc0262d2 d3d12_xs, test: say which route slot 31 remaps through; cover the retail route
queue_copy_page_mappings logs once whether CopyPageMappingsBatchX goes to an
installed batch hook or to the default adapter over xmem's range callback
(copy_page_mappings_fn), so a boot's read-fault reports can be matched to the
implementation the tests cover. Nothing in the runtime installs a hook, so a
retail run takes the default adapter.

d3d12_xmem_placed_test gains queue_remap_default_route, for that route: no
hook, a legacy-paired GPU-only destination, and a GPU-only pool backed only
through its CPU alias. The title maps a page of its own at one CPU twin while
the remap waits behind queue work (deferred with list values, waited for with
LEONIDA_LIST_VALUES=0), so ownership is checked when the remap is applied.
After the copy the GPU-only pages hold the pool's bytes, the other twin follows
them and the title's page keeps its bytes; after an unmap the GPU-only pages
and the mirrored twin are reserved and the title's page still holds its bytes.
On the code before this pull request the title's page check fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 19:04:43 +01:00
f1332737d4 runtime: speed up uav_clear format lookup and channel pack/unpack with unit tests 2026-11-25 19:01:18 +01:00
6c462cc77a runtime: guard XdxrBuilder empty dispatches, layout failure reset, and pipeline cleanup 2026-11-25 18:55:29 +01:00