Commit Graph

1118 Commits

Author SHA1 Message Date
c9ea508420 local: descriptor write-through and table mirror for title-backed heaps; diagnostics 2026-11-23 16:10:47 -06:00
93b2551f8d Merge PR #9576 2026-11-23 17:08:14 -05:00
3d1387b3b9 Merge PR #9531 2026-11-23 17:06:48 -05:00
721526af3d d3d12: FORMAT_SUPPORT answers the depth-plane view formats and comparison sampling as the host does
CheckFeatureSupport(FORMAT_SUPPORT) answered DXGI_ERROR_UNSUPPORTED for
R24_UNORM_X8_TYPELESS, X24_TYPELESS_G8_UINT, R32_FLOAT_X8X24_TYPELESS and
X32_TYPELESS_G8X24_UINT: they have no image of their own, so the Vulkan
lookups found nothing, although CreateShaderResourceView takes them on
depth-stencil textures. The host (RTX 5070 Ti and WARP) reports them as
sampled 2D and cube textures with mips, the depth plane also filtered.
SHADER_SAMPLE_COMPARISON and SHADER_GATHER_COMPARISON were never set, while
the host sets them on R32_FLOAT, R16_UNORM and the two depth-plane formats,
the formats an engine checks before using a comparison sampler on a shadow
map. 1D and multisample loads stay out, as for the depth formats.

d3d12_depth_view_format_support_test compares the HRESULT and the view bits
of 19 formats with the default adapter (PROBE_WARP=1: WARP): 6 differ on
main, 0 with this change, on both.

AI-assisted: yes
2026-11-23 16:00:07 -06:00
3afcab2a8b d3d12: enforce cross-device ownership checks on queue, fence, and bundle paths 2026-11-23 23:00:06 +01:00
3630610ca8 feat(d3d12): report console descriptor heap address on Xbox slot 14
Handle the console-extended CreateDescriptorHeap layout observed in #313 by reading address/size only on the Xbox slot 14 proxy path after a readable-range check, and report that console VA as the heap CPU/GPU start via an explicit Leonida helper. Normal 16-byte PC CreateDescriptorHeap calls remain unchanged. Title-memory aliasing / section 3.3 backing is still unresolved.
2026-11-23 23:32:12 +02:00
3644c72a57 d3d12: slot-133 texture layouts are validated; an import reaching the arena's VA window takes the fallback
From review (@FRaccie):
- The texture fallback called create_committed, which takes the state without checking it (textures start
  undefined and take their first command's layout), so the barrier-layout state and its COMMON retry did
  nothing. It now goes through create_committed_validated, as CreateCommittedResource does: RENDER_TARGET on a
  texture without ALLOW_RENDER_TARGET is refused and the COMMON retry answers; a description the checks refuse
  outright is refused.
- An imported buffer's VA is its host address, in the same BufferVaIndex as default-heap buffers, whose VAs are
  offsets in [0, arena size). A host address inside that window (low addresses, as under Wine) would shadow arena
  buffers in the nearest-start lookup, so such a range is not imported and the fallback answers.

d3d12_existing_heap_test checks the two texture cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 22:29:53 +01:00
57d08d2fd6 d3d12: 8-bit sRGB UAV textures are mutable UNORM images where the sRGB format has no storage
The host runtime sizes and creates R8G8B8A8_UNORM_SRGB and B8G8R8A8_UNORM_SRGB textures with
ALLOW_UNORDERED_ACCESS (RTX 4090 617.42 and WARP). The layer created their image in the sRGB format with
STORAGE usage, which most GPUs lack, so it refused them: a retail title sizes a 2048x2048, 12-mip
R8G8B8A8_UNORM_SRGB render target with unordered access through device slot 25, got UINT64_MAX and
stopped on its 32-bit size check.

Such a texture is now a mutable image of the UNORM format of the same order (Format::uint_backed, from
#7604), where the GPU can make that image with both formats listed. Its storage view is UNORM, as every
D3D12 typed UAV of these textures is; RTVs and SRVs are sRGB, so clears and draws encode and sampling
decodes. Multisampled ones are still refused.

d3d12_srgb_uav_test compares with WARP: the retail shape's size alignment and creation, a clear
through the sRGB RTV and one through a UNORM UAV, byte for byte, for RGBA8 and BGRA8. Without the
change it fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 22:25:05 +01:00
f9896e0fe5 local: merge #9137 (slot 133 kept as on ladder-frame) 2026-11-23 15:21:22 -06:00
237f9e0ba8 local: diagnostics (draw/present/clear/rect state), rect experiments 2026-11-23 15:20:43 -06:00
e64653e585 Merge branch 'pr7448' into local/ladder-frame-wine 2026-11-23 14:35:25 -06:00
6d1f046da6 docs, comments: describe the title's VA by its range, not by a measured value
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 21:13:38 +01:00
dbab003b0e d3d12: quad lists draw as triangle-list indices (0 1 2) (0 2 3) so flat inputs use the first quad vertex, and the PSO topology type is read as raw bits
Taken from the follow-up patch of @matheuskshn (930e78a2, tested by them on an RTX 4070 Ti: replay_quad_list_test fails the two non-indexed cases on a6b31d51 and passes with it). Re-run here: replay_quad_list_test and d3d12_rect_list_test exit 0 on the pod (Wine, RTX 4090).
2026-11-23 21:11:37 +01:00
f9db5e6bb3 d3d12: a bound table's slots the title wrote in its own heap backing are pulled in before the scan
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 21:05:45 +01:00
6d7842a55e d3d12: read LEONIDA_TITLE_WINDOWS_MB with getenv_s, as the file's other variables
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 20:59:21 +01:00
14d54d0d76 d3d12: a placed buffer keeps its heap's arena range after the heap is released
A placed buffer is a range of its heap's arena memory, but only the heap
held that range: releasing the application's last ID3D12Heap pointer
freed it while placed buffers in it were still alive, so the next heap
or committed buffer got the same GPU address and the arena zeroed and
overwrote the live buffer. On D3D12 a placed resource holds a reference
on its heap, so releasing the heap first is legal.

The placed buffer now holds the heap's range (the shared allocation
whose deleter returns it to the arena). New d3d12_placed_heap_lifetime
test: red on main (the new heap's buffer lands on 0x10000, the live
buffer's address), green with the fix.

AI-assisted (Claude Code)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 13:55:13 -06:00
d2f328e560 d3d12: only the title's memory gets a copy; the table scan covers the declared slots and is timed
The xmem shims record what they hand the title (XMemAlloc, XMemAllocDefault,
XMemVirtualAlloc, the title's VirtualAlloc); an address outside those ranges
is left as it was and counted. The submit-time scan reads only the
CBV/SRV/UAV slots the bound table's root signature declares, and its cost
is accumulated per ExecuteCommandLists. Section 3.3 describes the three
places addresses are replaced and the two kinds of copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 20:51:08 +01:00
f57ed9da22 d3d12: a shader path that is not UTF-8 never throws, and LEONIDA_SHADERS is absolute
- A shader_path.txt that is not UTF-8 no longer throws out of Create*PipelineState: MSVC's STL reports the failed
  conversion as std::system_error, not filesystem_error. configured_shader_directory() returns the reason instead,
  and DeviceState::library() catches every std::exception, so the "invalid translated shader path" message prints
  and the pipeline fails. The reader of the file itself is unchanged.
- A relative LEONIDA_SHADERS no longer follows the current directory: gta6rt makes it absolute at startup, next to
  --game-dir and --overlay, and ShaderLibrary::load keeps an absolute folder for the modules it reads later.

Tests: d3d12_shader_path_test (new, Windows, no GPU) and a relative-folder check in shader_library_test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 14:50:00 -05:00
65668002e9 d3d12: buffer addresses in the title's own memory reach a shader through an arena window
A root view or buffer V# may name the title's own memory outside any
slot-133 buffer (a per-frame constant ring, #8862 section 3.5). The
layer now makes a 64 KiB-aligned window of those pages in the GPU
address arena, copies it before every submission like a slot-133
shadow, and names that copy instead: for root views when set, for V#s
the layer writes, and for buffer V#s the title writes into a bound
CBV/SRV/UAV table itself, rewritten in place before each submission.
Counters per kind, LEONIDA_TITLE_WINDOWS_MB caps the windows (64 MiB).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 20:47:45 +01:00
7a8ae20ca0 docs: section 3.3 says how shaders reach title-placed buffers
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 20:39:59 +01:00
ab1fbff95d d3d12: shaders reach a title-placed buffer through the root views and buffer V#s the layer writes
Xbox device slot 133 places a buffer at the title's own VA, about 1.5 TiB on
Windows, while a translated shader computes heap_base + console VA with
heap_base the arena's device address. A root view or V# naming that VA
missed the buffer. The layer now translates an address inside a
title-placed buffer where it writes it (root CBV/SRV/UAV, CBV and buffer
SRV/UAV V#s): to the arena offset of the slot-133 shadow, which now lives
in the GPU address arena when it fits, or to an import's device address
minus heap_base. New tests: title_va_alias_test, d3d12_title_va_test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 20:38:42 +01:00
c4dc7e2ac4 Merge branch 'pr7535' into local/ladder-frame-wine 2026-11-23 13:36:23 -06:00
bdab731996 Merge branch 'pr7384' into local/ladder-frame-wine 2026-11-23 13:36:23 -06:00
ced3615124 local: merge #7584 (docs conflict: ours) 2026-11-23 13:34:47 -06:00
ec502356c7 d3d12: a static sampler with the UINT flag on transparent black is registered
register_static_samplers took D3D12_SAMPLER_FLAG_UINT_BORDER_COLOR on
any border colour without a _UINT enum value for a pair D3D12 does not
define, and skipped the sampler: CreateRootSignature succeeded, the S#
was never registered and the shader sampled through the fallback
sampler.

The static enum has no transparent _UINT value, so the 1.2 flag on
TRANSPARENT_BLACK is how a root signature writes the integer border
(0,0,0,0). D3D12 serializes and creates it; the pairs it refuses are the
flag with the float OPAQUE_BLACK and OPAQUE_WHITE, which stay refused.

d3d12_descriptor_test gets a fifth static sampler row for it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-23 20:19:07 +01:00
ba5e9a39c9 local: merge #7604 2026-11-23 13:08:38 -06:00
a86d7f9508 d3d12: an integrated GPU reports UMA and refuses MEMORY_POOL_L1 heaps, as the host does (#6569)
Squash-merged after diff review of PR #6569
2026-11-23 12:42:09 -06:00
5caef48a19 Merge branch 'pr7111' into ladder-frame
# Conflicts:
#	docs/runtime_imports.md
#	runtime/CMakeLists.txt
2026-11-23 19:38:48 +01:00
dfe4e4ad3a d3d12: guard null pInputElementDescs and validate graphics/compute PSO descriptors (#6689)
Squash-merged after diff review of PR #6689
2026-11-23 12:36:37 -06:00
14dc9af525 d3d12: enable SSE4.1 for Clang's slot-133 streaming copy
Clang's baseline x64 target cannot inline _mm_stream_load_si128 into copy_guarded. Give only that function the target feature the existing intrinsic requires; keep the MSVC path and global build flags unchanged.

Depends on: #8225. Claimed in #8186, comment7110252121. AI-assisted: yes (Codex).
2026-11-23 19:35:31 +01:00
a5c96e0dd5 Merge branch 'pr7755' into ladder-frame
# Conflicts:
#	runtime/shims/d3d12_vulkan_device.cpp
2026-11-23 19:32:11 +01:00
b036470cea D3D12_FEATURE_D3D12_OPTIONS: answer the five booleans from the enabled Vulkan features (#6578)
Squash-merged after diff review of PR #6578
2026-11-23 12:25:31 -06:00
fb23d93c13 Merge branch 'pr7403' into ladder-frame 2026-11-23 19:23:14 +01:00
6b1db4b3ae Merge branch 'pr7330' into ladder-frame 2026-11-23 19:23:08 +01:00
49410a52fc d3d12: a slot-133 buffer whose pages are not imported is a shadow at the title's VA
When VK_EXT_external_memory_host refuses the title's pages (write-combined or uncached pages, pages not committed yet, no extension, or the driver's import budget: about 64 MiB on an RTX 3070 Ti), the fallback was an ordinary DEFAULT buffer with neither the title's VA nor its data, so the title's descriptors resolved to nothing (slot 70 wrote a null SRV) and UI draws sampled nothing.

The fallback is now a host-visible buffer (VRAM through Resizable BAR where upload buffers use it) whose console VA is the title's address, filled from the title's pages at creation and again before every submission of command lists (VulkanContext::set_before_execute, called from VulkanQueue::execute_now). Only committed, readable pages are read; the rest is zero. GPU writes to the shadow are not copied back.

The first per-submission copy of each buffer size is timed and logged. Write-combined pages are read with MOVNTDQA: memcpy read 64 MiB of them in 253 ms on a Core i9-13900K, MOVNTDQA in 13 to 17 ms.

Tests: write-combined, uncached, 64 MiB write-combined and half-committed ranges in d3d12_existing_heap_test, two patterns over two submissions each, 0 validation errors on an RTX 4090.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 19:14:33 +01:00
a3eae955dc d3d12: slot 133's third argument is a barrier layout; a placed texture starts in the matching state
The title's third word at slot 133 is a D3D12_BARRIER_LAYOUT, not a resource state (measured by
@dracbat on a retail boot: 0x6 SHADER_RESOURCE for its RT/DS textures, 0x3 UNORDERED_ACCESS for its
RT+UAV ones, 0xFFFFFFFF UNDEFINED for the 182 MiB buffer), as PC CreatePlacedResource2 takes it. The
proxy passes it to the handler, and a texture's ordinary committed fallback starts in the equivalent
legacy state (UNDEFINED and unlisted values give COMMON; a state the description refuses retries with
COMMON, so the title always gets its resource). Buffers are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 19:10:29 +01:00
3eba4c9c9a Merge branch 'pr7066' into ladder
# Conflicts:
#	runtime/shims/d3d12_xs_device.cpp
#	runtime/shims/d3d12_xs_device.h
#	runtime/test/xs_proxy_mock_test.cpp
2026-11-23 18:54:06 +01:00
4336b7a2a0 Merge remote-tracking branch 'origin/main' into slot133-host-va 2026-11-23 18:50:06 +01:00
4fb24d2faa d3d12: a texture at slot 133 gets an ordinary committed texture instead of E_NOTIMPL
The retail title places textures at slot 133 too, and asserted on the E_NOTIMPL (found in review). A
texture now gets an ordinary committed DEFAULT texture of the same description, as slot 76 gives one,
logged once; it is not on the title's pages. The proxy rewrites a texture's Xbox layout word to
UNKNOWN (a buffer's to ROW_MAJOR), as slot 76 does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 18:37:44 +01:00
228cb9ec6c d3d12: slot 133 imports from the page that holds the address and binds at the offset; uncommitted pages fall back
The title places small buffers inside a page too: a 16-byte UAV at a 64-byte-aligned address on an
RTX 5090 (found in review), which the import refused with E_INVALIDARG, halting the boot. The import now
starts at the page holding the address and the buffer is bound at the offset; an offset off the
buffer's alignment takes the ordinary-buffer fallback. A range not fully committed (xmem commits on
first touch) also falls back instead of failing. Only a null address or a zero width are E_INVALIDARG.

d3d12_existing_heap_test: a buffer 64 bytes into a page reads back the CPU's writes at its own VA; a
1-byte offset and a partly committed range fall back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 18:33:50 +01:00
18b0bfbaf1 d3d12: an A8 render target's castable list takes its own format and refuses the others
castable_view_formats() mapped every castable format through vulkan_format(), which has no
A8_UNORM case, so CreateCommittedResource3/CreatePlacedResource2 with castable={A8_UNORM}
failed with E_INVALIDARG ("castable format not supported yet: 65"). The resource's own format
is always viewable (create_texture adds the image's format), so naming A8_UNORM on an A8
texture is now a no-op.

An A8 render target's VK_FORMAT_A8_UNORM_KHR image is in a compatibility class of its own,
so an R8_UNORM castable entry (same texel size) would have reached its
VkImageFormatListCreateInfo. Any format other than A8_UNORM is now refused with E_INVALIDARG
before Vulkan.

The A8 gate (runtime and vk_test_device.h) also requires TRANSFER_SRC/DST, since every
texture is created with transfer usage.

d3d12_draw_test runs the A8 clear/draw/blend cases on a second target made through
CreateCommittedResource3 with castable={A8_UNORM}, and checks castable={R8_UNORM} returns
E_INVALIDARG. Without the shim change it fails with the reported message.

Reported by tupacfan04 on #7403.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 18:32:40 +01:00
952be9b046 d3d12: A8_UNORM textures in 1D and 3D, as the host makes them
texture_format refused every A8_UNORM texture that was not 2D, so GetResourceAllocationInfo answered
UINT64_MAX for a 1D one (a title's boot sizes a 128-texel 1D A8_UNORM texture and asserts on that size).
The host accepts A8_UNORM in 1D, 2D and 3D (the gap is listed by #4533's host sweep). They are R8_UNORM
images like the 2D ones; the SRV's alpha-only swizzle does not depend on the dimension. Format support
now names TEXTURE1D and TEXTURE3D too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 18:30:31 +01:00
4da716493f d3d12: reject null arrays and invalid lists in ExecuteCommandLists (#6610)
Squash-merged after diff review of PR #6610
2026-11-23 11:16:29 -06:00
0dc7f58e5e d3d12: B5G5R5A1 UAV textures are mutable R16_UINT images where A1R5G5B5 has no storage
A B5G5R5A1_UNORM texture with ALLOW_UNORDERED_ACCESS was refused on a GPU whose
VK_FORMAT_A1R5G5B5_UNORM_PACK16 has no STORAGE_IMAGE (NVIDIA): GetResourceAllocationInfo answered
UINT64_MAX and creation failed. A title's boot creates a 2560x1440 render-target + UAV one and
asserts on that size.

The R9G9B9E5 route generalizes: Format::r9g9b9e5_as_r32_uint becomes Format::uint_backed, the format
a UAV texture stored as a mutable unsigned image is viewed in (E5B9G9R9 for R32_UINT, A1R5G5B5 for
R16_UINT). For B5G5R5A1 the image is R16_UINT with {R16_UINT, A1R5G5B5} listed; its storage view is
R16_UINT in the uint class, SRVs are A1R5G5B5 sampled views, and RTVs and clears go through an
A1R5G5B5 attachment view (ResourceBinding::uint_backed lets replay's color_view_format take it). The
SRV and UAV T#s keep the 1_5_5_5_UNORM format. A shader store still needs the translator to pack
the bits for that view, so CheckFeatureSupport does not advertise the typed UAV yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 18:06:24 +01:00
17cc9a7a92 d3d12: validate and track SetDescriptorHeaps and directly-indexed root flags (#6674)
Squash-merged after diff review of PR #6674
2026-11-23 11:00:10 -06:00
a3da5122fd d3d12: checkpoint slow compute pipeline compiles
Depends on: #7384
AI-assisted: yes (Codex)
2026-11-23 17:59:05 +01:00
59e4bb81ec d3d12: the A8 render-target code compiles and enables maintenance5 with older Vulkan headers
KarolKurzyna found two header gaps on #7403. VK_KHR_maintenance5 was added to the
device extensions inside the maintenance8 #ifdef, so headers with maintenance5
but not maintenance8 (1.3.262 to 1.4.305) chained its feature without enabling
the extension; the two #ifdefs are now separate. texture_format and the PSO named
VK_FORMAT_A8_UNORM_KHR unguarded; they now use kA8UnormFormat, which is
UNDEFINED (and never used, since a8_render_target stays false) without it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 17:56:50 +01:00
310773a01c d3d12: slot 133 review fixes: no write-combined import, committed-range check, immediate free, proxy test
- A write-combined (or uncached) page in the range is not imported: an RTX 5090 imported such a range
  and read wrong bytes back (found in review). It takes the ordinary-buffer fallback.
- The whole range must be committed, walked with VirtualQuery across allocations (the retail buffer
  spans three mapped windows); otherwise E_INVALIDARG instead of undefined behaviour in Vulkan.
- The imported memory is freed as soon as the submitted work has retired (wait_retire_ticket), not
  after the next submission: VK_EXT_external_memory_host needs the caller's pages to outlive it, and a
  title may free them right after releasing the resource.
- The PC flag mask is 0x5ff: 0x200, which the host refuses, is dropped. Slot 133 is listed in
  device_slot_overridden.
- xs_proxy_mock_test registers a handler and checks slot 133's argument positions, the flag mask
  (0x20204 -> 0x4), the ROW_MAJOR rewrite and the iid; d3d12_existing_heap_test checks the
  write-combined fallback and the partly committed refusal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 17:49:03 +01:00
1d8d1d355d d3d12_xs: slot 70 takes its buffer reference under the registry lock and asks for a buffer that holds the whole width (review of the raw view)
AI-assisted.
2026-11-23 17:46:16 +01:00
86cd0c5f2a d3d12: draw the console's rectangle lists (17, PSO type 19) and quad lists (19) as triangles
A rectangle list is three corners; the fourth is v2 + v3 - v1 for the position and every interpolant, after the vertex stage. A quad list is four vertices per quad. Vulkan has neither. A PSO with topology type 19 was refused (E_INVALIDARG) and the two list topologies drew as a plain triangle list.

Rectangle list: the PSO becomes a triangle-list pipeline with a generated geometry stage (src/rect_list_geometry.h), built from the vertex shader's own SPIR-V outputs, that emits the strip v1 v2 v3 v4. Quad list: one triangle fan per quad (0 1 2, 0 2 3), drawn with the index values 4q..4q+3 so the translated vertex id (VertexIndex - BaseVertex) is right; non-indexed draws read a shared 0, 1, 2, ... buffer reserved in the arena.

Facts from xvalkyrie (GPL-3.0, commit 53af7df77c10); no code copied.
2026-11-23 17:45:10 +01:00