Commit Graph

413 Commits

Author SHA1 Message Date
a5fdc8bbf9 Cache GFX10 tile X offsets and per-row Y contributions
Avoid per-element bit interleaving in tile/detile copies; retain element_offset as the independent reference and validate decoded output against it.

AI-assisted.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-11-22 17:56:49 +00:00
c43291cbe1 Add standalone GFX10 RbPlus 2D tile and detile primitive
D3D-316: copy the validated Python 4KB_S and 64KB_D bit patterns into a bounded, portable helper. Cover padded bijections, round trips, Python known offsets and invalid inputs without a GPU.

AI-assisted.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-11-22 17:49:56 +00:00
81c6cfe4fd Merge pull request #2021 from jaybeebabageyus 2026-11-22 10:40:29 -05:00
7e49e1b2e4 Merge pull request #1980 from totonii 2026-11-22 10:40:05 -05:00
4bc2fd2870 Merge pull request #1973 from Dominik 2026-11-22 10:39:59 -05:00
58cc88f5dd Merge pull request #1971 from Jolymmiles 2026-11-22 10:39:58 -05:00
6a4eff5816 Merge pull request #1942 from Felix Croasdale 2026-11-22 10:39:37 -05:00
68cee18fe2 Merge pull request #1939 from totonii 2026-11-22 10:39:35 -05:00
8b61d266bb Merge pull request #1933 from Emirhan Karaca 2026-11-22 10:39:32 -05:00
9887cc773a Merge pull request #1924 from Ash Hopkins 2026-11-22 10:39:28 -05:00
8dc359b892 Merge pull request #1914 from zneel 2026-11-22 10:39:25 -05:00
96dcddb6fb Merge pull request #1911 from Jan Trencansky 2026-11-22 10:39:21 -05:00
001981b743 Merge pull request #1910 from Dominik 2026-11-22 10:39:20 -05:00
12bad64c53 Merge pull request #1899 from Hadagalberto Junior 2026-11-22 10:39:15 -05:00
de8278f673 Merge pull request #1882 from Tomgamer 2026-11-22 10:39:08 -05:00
0093aa9097 Merge pull request #1799 from Dominik 2026-11-22 10:38:54 -05:00
86e6848f7b Merge pull request #1756 from Leonardo Guimaraes 2026-11-22 10:38:52 -05:00
56ae397800 Merge pull request #1740 from Ryderadzeee 2026-11-22 10:38:51 -05:00
ae2a4a1705 Merge pull request #987 from gabrielsteglich 2026-11-22 10:38:46 -05:00
729bee7bb2 Merge pull request #901 from traeb0n 2026-11-22 10:38:45 -05:00
944f26d7d1 Merge pull request #893 from traeb0n 2026-11-22 10:38:44 -05:00
03d81593b5 Merge pull request #831 from TheHoracio 2026-11-22 10:38:43 -05:00
1e48c3f463 Merge pull request #760 from 0xTehuti 2026-11-22 10:38:41 -05:00
eb35aed2e7 Merge origin/main into shader-309-wave64-lds-limit
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 16:32:05 +01:00
d9f7ec4162 Merge upstream main
# Conflicts:
#	tools/fspx_unpack.py
2026-11-22 10:28:36 -05:00
6a16ac1436 FSPX lookup: a kind-0 state key next to the code key; ambiguous programs are refused (RT-99 review)
Review on #1911: two containers with the same kind-6 program and different kind-0 entries (32x1x1 and 64x1x1)
translate to different modules but got the same fspx_code_sha256, so both resolved to the same pipeline.

- tools/fspx_unpack.py writes the kind-0 entry as fspx/<name>.state; tools/shader_meta.py records its SHA-256 as
  fspx_state_sha256 next to fspx_code_sha256.
- make_game.py: entries with the same code and state keys must have identical modules, otherwise the FSPX step fails
  naming both programs and drops the index. The same code key with other state keys is allowed.
- runtime: a container or bare payload (kinds 0 and 6 present) matches the code key and then the state key; no match
  is E_INVALIDARG. A bare kind-6 program (slot 67, no kind 0) takes the code key's entries when their modules are
  identical, and is refused with E_INVALIDARG and an "ambiguous" log line when they differ.
- Tests: the review case in tests/test_fspx_shaders_stage.py, shader_library_test and d3d12_fspx_compute_test.
- docs/fspx.md: the two keys and the ambiguous case.

On 1.0.2.1 the 29 kind-6 programs are distinct, so nothing resolved wrongly before: 17 translated entries, 17
distinct code keys, 17 distinct (code, state) pairs, all 17 found from the container and from the bare program.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 10:28:07 -05:00
28ef599619 Runtime: pick the Vulkan GPU by the harnesses' rank (native over Dozen)
The runtime's standalone device (d3d12_vulkan_device.cpp) still took
"the first usable device, replaced by every later discrete GPU". #915
fixed that rule in the test harnesses because Mesa's Dozen (Microsoft
vendor 0x1414, "Microsoft Direct3D12 (<gpu>)") reports a discrete GPU, so
on a PC with the OpenCL/OpenGL/Vulkan Compatibility Pack the runtime
could run on the Vulkan-on-D3D12 wrapper while the tests used the native
driver. Even without Dozen, on a two-dGPU PC the runtime took the last
GPU and vk_test_device.h the first.

- runtime/src/vulkan_device_filter.h: vulkan_device_rank() (native over
  Microsoft's layers, then discrete > integrated > virtual > CPU), with
  the device type as an int so the header stays Vulkan-free.
- d3d12_vulkan_device.cpp: the first usable device of the highest rank.
- vk_device_pick.h: device_rank forwards to it (static_assert on the
  VkPhysicalDeviceType values).
- d3d12_indirect_rt_test, dxgi_swapchain_test, vk_image_fuzz,
  vk_sampler_test had the old loop and ignored LEONIDA_VK_DEVICE: they
  now filter and rank like the rest, and an unmatched filter fails
  instead of skipping.
- vulkan_device_filter_test: the rank order; docs/testing.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 15:27:09 +00:00
56fd84b274 pe_loader: a forwarded CRT export binds the host copy, as a direct import does
resolve_forwarder checked prefer_host_copy() on the bare forwarder module
name, but forwarder strings normally leave out ".dll" ("MSVCP140.?foo")
and the host-copy list is named with it. So a bundled module forwarding to
one of the CRT DLLs the package ships (vcruntime140, msvcp140, concrt140,
...) mapped the Xbox build of that DLL from the game folder instead of the
host's, unlike a direct import of the same symbol. It now uses shim_key,
the name with ".dll" the function already builds for the shim lookup.

loader_test: a fake bundled vcruntime140.dll plus a provider forwarding
"vcruntime140.memset" binds to the host memset and never maps the fake
(fails before the change: the import ends unimplemented).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 15:26:25 +00:00
b805f191da pe_loader: refuse an export whose address is outside the image
parse_exports range-checks the export directory, its three tables and every
name, but stored each code export as base + rva without checking rva. An
address-table entry at or past SizeOfImage (and outside the export
directory, so not a forwarder) became a pointer past the mapping, which an
import or GetProcAddress through the shims would hand out and a caller would
jump to. The load now fails with the export's name, like every other RVA the
loader follows.

loader_test: an export at SizeOfImage is rejected (it loaded before this
change); one at the image's last byte still loads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 15:26:21 +00:00
b17531d021 Support sparse tile mappings for reserved D3D12 buffers
Depends on D3D-16 (PR #286).
2026-11-22 12:24:19 -03:00
ea32ba2f8e d3d12: review fixes for the new formats
- UAV clears of A4B4G4R4: an R4G4B4A4_PACK16 layout row (red in bits
  12-15, alpha in 0-3), unit-checked in conversion_checks and cleared end
  to end where the layer reports a typed UAV (the driver's call: WARP has
  one, AMD's D3D12 driver doesn't).
- FORMAT_SUPPORT reports IA_VERTEX_BUFFER only for formats input layouts
  accept (vertex_format), not every format Vulkan can fetch: R8/R16
  SNORM/SINT (and R8G8 SNORM/SINT) have no input-layout mapping yet.
- new_format_round_trips: each render-target format is cleared to
  (-3, -0.4, 0.25, 7) on the layer and on the host and the bytes compared,
  which catches a mapping of the right size but the wrong numeric type
  (R16_SNORM as UNORM, R8_SINT as UINT); no value is an exact half step.
  The host is the Vulkan device's own adapter, as in
  compare_format_support, not the default one.
- A4B4G4R4 is skipped where the Vulkan driver can't sample
  R4G4B4A4_UNORM_PACK16 (Vulkan doesn't require it), by the driver's
  format properties rather than the layer's answers; B4G4R4A4 and
  B5G5R5A1 are never skipped.
- d3d12_copy_xfmt: D16_UNORM <-> R16_UINT and R16_SNORM copies, the new
  members of depth_colour_pair, against the host and WARP.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 16:23:58 +01:00
e517b75fb2 fix(resource_tiling): guard integer overflows, shape divide-by-zero, and mip shift UB 2026-11-22 12:21:37 -03:00
47f4cdc643 runtime: route LoadLibrary/GetProcAddress of bundled package DLLs through rt::Loader 2026-11-22 16:21:16 +01:00
9d47be3dec Runtime: no heap allocation per barrier, clear or copy in replay
Three allocations replay_cpu_bench (#878) found on the hot path:

- detail::current returned a std::vector<LayoutPiece> for every
  transition, clear and copy in emit, though the answer is nearly always
  one piece (two with separate depth/stencil). LayoutPieces keeps two
  inline and spills to the heap beyond that, with the same interface
  (begin/end, size, push_back, clear), so `auto pieces = current(...)`
  callers compile as is. LayoutTracker::pieces takes either container.
- detail::clip built a new vector with push_back (two allocations for two
  rectangles); it now writes into the kept entry's p.rects.
- CommandList::append took const Command& and copied the temporary the
  recording calls build, so a rectangle clear's vector was allocated
  twice; an rvalue overload moves it.

replay_cpu_bench, i7-14700K, on top of #893: the frame goes from 194 to
173 ns per command, emit from 48 to 33 ns; emit makes no allocation per
command in the frame (0.43 before) and prepare 0.07 (0.26), and
recording makes one only for a rectangle clear's own rectangles.
d3d12_state_map_test checks LayoutPieces against the vector path,
including the spill at four pieces.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 09:19:29 -06:00
9df4eda200 Runtime: VulkanQueue keeps its PreparedList storage between executions
execute built a new std::vector<PreparedList> on every call, so every
command's detail::Prepared entry (1288 bytes on main now) was made in
fresh memory and freed again: replay_cpu_bench measures that at 274-292
ns per command on an i7-14700K, against 85 ns refilled in kept storage,
over half of the layer's whole CPU cost per command. The queue now keeps
the vector as a member (per queue, like its command buffers: one execute
at a time on a queue, as acquire() and submit() already assume) and
resizes it to the list count; prepare refills each list's entries in
place, where the per-entry vectors also keep their capacity.

replay_cpu_bench mirrors the change and reports both floors (entries in
kept storage and made fresh). Its frame goes from 425 to 194 ns per
command (a 21,504-command frame from 9.1 ms to 4.2 ms).

d3d12_vulkan_device_test executes {B, A}, then {B} alone, and checks
that only B ran the second time: with storage that only grows, a stale A
is replayed after B and the test fails (checked).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 09:19:29 -06:00
ef4d3053b1 Depth/stencil region resolves keep the texels around the rectangle
A ResolveSubresourceRegion of a depth or stencil plane runs in a rendering scope whose render area is the source
rectangle, and Vulkan resolves only inside it. MoltenVK (1.4.2 and 1.4.3) resolves the whole destination
subresource: it resolves through Metal's store action, which has no render area. d3d12_depth_resolve failed its
eight MIN/MAX rectangle cases under Wine on an M3 Max for that reason.

The texels around the rectangle now go into copy_scratch before the scope and back after it, in up to four bands, on
every GPU: no device property reports the behaviour. vk_command_replay_test part I resolves a D32 rectangle natively
and checks the texels around it; it failed on MoltenVK before this change (all 28 overwritten) and passes on
MoltenVK and KosmicKrisp, with no validation errors on KosmicKrisp.

AI-assisted.
2026-11-22 19:18:06 +04:00
efeef30822 d3d12: select integer transparent black for UINT custom border fallback
- For samplers with custom border colours (BorderColor::table), retain is_int in the fallback path when VK_EXT_custom_border_color is unavailable.
- Select VK_BORDER_COLOR_INT_TRANSPARENT_BLACK for UINT custom borders and VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK for float custom borders, satisfying Vulkan input validation rules on integer views (reported by Vonsek, #760).
- In vulkan_sampler(), default to VK_BORDER_COLOR_INT_TRANSPARENT_BLACK when sampler.integer_border is set for table colours.
- Update d3d12_sampler2_test with a fallback device and vkCreateSampler interception to verify that VK_BORDER_COLOR_INT_TRANSPARENT_BLACK and VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK are requested as expected.

Tested on Windows 11, MSVC 2022 x64 (Ninja, RelWithDebInfo), NVIDIA GeForce RTX 2070 SUPER.
Clean-room verification suite passed with exit code 0.
Co-Authored-By: Antigravity <antigravity@google.com>
2026-11-22 16:14:57 +01:00
74941a2411 base_reservation: read LEONIDA_BASE_RESERVED with swscanf_s (MSVC C4996)
swscanf at base_reservation.h:44 was the runtime build's only warning on
main 6a6704d, printed for five targets. swscanf_s takes no buffer sizes
for integer conversions, so the %llx:%llx parse is the same.

pe_loader_test now checks inherited(): a valid value, size 0, no size,
a non-hex base and no variable. Only arm64 Wine relaunches gta6rt, so a
Windows run never reached this parser before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 09:09:13 -06:00
74ab61efaa fix(subgroup_size): guard 64-bit invocation product overflow and zero local_size_x 2026-11-22 12:08:32 -03:00
d6443b1524 Startup trace: never replace an existing file; write UTF-8 only
Review on #1756 (Vonsek):
- The trace is opened before the loader reads the image, so `wb` could
  truncate an input named by mistake (the image itself). open() now
  uses "x" mode and fails with EEXIST on an existing path; gta6rt says
  so and exits with 2.
- OutputDebugStringA text is in the ANSI code page. It is converted
  to UTF-8 before quoting, so a byte such as 0xE9 no longer breaks the
  JSON lines. Host module names now come from GetModuleFileNameW,
  converted to UTF-8, for the same reason.

startup_trace_test: an existing file is refused with EEXIST and its
bytes survive, the trace stays off; an ANSI debug string with 0xE9
appears as its UTF-8 form and the whole file is valid UTF-8.
2026-11-22 12:06:49 -03:00
b01bed6efd Runtime: dispatch FenceWaitDispatcher callbacks outside mutex and wake blocked waits on device lost 2026-11-22 18:06:35 +03:00
2dca597bd9 Runtime: opt-in startup trace (gta6rt --trace FILE)
Writes one JSON object per line, flushed per event: module maps, TLS
callbacks, DllMain results, the first call of each unimplemented import
with its caller as module+RVA, OutputDebugString text, exceptions with
module+RVA and a short unwind, and the exit code. A vectored handler
records and returns EXCEPTION_CONTINUE_SEARCH, so behaviour is unchanged.
Off by default.

startup_trace_test builds a synthetic DLL image (no game data) and
checks each event kind.
2026-11-22 12:03:22 -03:00
7b48c194c0 Use Vulkan swapchain maintenance aliases supported by older headers 2026-11-22 19:00:41 +04:00
8cbf2c2f6c Runtime: MSAA PSOs take the standard sample pattern; draws check attachment sample counts
CreateGraphicsPipelineState refused every SampleDesc.Quality but 0. Native
D3D12 (RX 7800 XT, a Radeon iGPU and WARP) accepts 0,
D3D12_STANDARD_MULTISAMPLE_PATTERN and D3D12_CENTER_MULTISAMPLE_PATTERN and
refuses 1 (past NumQualityLevels). The standard pattern is Vulkan's standard
positions, so it is accepted; the centre pattern needs custom sample
locations and is refused with a log until those exist.

At replay every bound render target and depth target must have the PSO's
sample count (D3D12 leaves a mismatch undefined, Vulkan's dynamic rendering
forbids it), so a mismatched draw fails the list with invalid_subresource
instead of reaching the driver.

d3d12_msaa_draw_test (in ctest): 4x draws with a depth target, SampleMask 0x1
and ResolveSubresource; the quality rules; a 4x PSO into a 1x target.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 15:54:48 +01:00
0bde4c82d7 Runtime: split pipeline statistics around predication and footprint helpers (D3D-162)
Replay refused SetPredication, predicated buffer copies and D24/RGB96 footprint conversions while a
pipeline-statistics query was active (#1624 added the last), because their compute dispatches would count in the
application's CSInvocations. They now get the segment split #1519 gave resolves: the statistics query ends its
current physical segment right before the helper dispatch and begins the next right after it, and its result is
the per-counter sum of the segments. Query resolves and these helpers share one segment numbering. The markers for
non-query commands live on detail::Prepared, and emit() places them around capture_predicate,
emit_predicated_copy and the depth24 conversion parts, outside any rendering scope.

Without a statistics segment pool (the single-list replay(), or a queue without the summation helper), the three
commands are still refused while statistics are active, before any helper scratch is allocated (prepare() takes
statistics_helpers, false by default) and again in QueryReplay::plan.

Tests (Khronos validation on): vk_predicated_copy and depth24_convert run their helpers inside an otherwise empty
statistics query. Their results stay byte-exact and all 11 counters are 0. d3d12_predicated_copy compares with
WARP the same way. replay_query_predication checks the emitted order for a capture, a predicated copy, a footprint
copy and a resolve in one query, and the refusal without a pool. predicated_copy and typeless_rtv check both
preparation modes.

Co-Authored-By: OpenAI Codex <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 11:52:23 -03:00
4de870250e SHADER-309: keep compute workgroup memory under the limit
--wave64-emulate adds %x_buf (2L + 6W + 7 dwords) on top of the LDS
array, so a 64 KiB LDS made modules over maxComputeSharedMemorySize,
which spirv-val accepts and RADV dies on (#1721).

Translator: a 64 KiB hard cap (MAX_SHARED_BYTES, --max-shared-memory).
Over it, the pow2-rounded LDS array shrinks to the room left when the
program's need fits (indices wrap with OpUMod); otherwise the shader is
refused (Unsupported, with the byte counts). lds_bytes in index.json is
now the whole Workgroup total.

Runtime: the D3D12 shim's create_compute compares lds_bytes with the
device's maxComputeSharedMemorySize (32768 on AMD Windows and Intel)
and refuses the pipeline with a log line instead of creating it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 15:49:23 +01:00
98dc77c4eb Merge pull request #1874 from Serrambi 2026-11-22 09:49:00 -05:00
33507d493d Merge pull request #1863 from jsthope 2026-11-22 09:48:52 -05:00
7886972a6b Merge upstream main
# Conflicts:
#	docs/d3d12_command_objects.md
2026-11-22 09:48:41 -05:00
b566a8652f Merge pull request #1844 from romainveurrier 2026-11-22 09:48:41 -05:00