These forms were refused. Measured on RDNA2 (gfx1036, raw kernels through
tools/hw_oracle, wave32 and wave64): op_sel bit 2 adds S2[31:16]
zero-extended (in the i16 op too), op_sel bit 3 writes the result shifted
left by 16, and clamp saturates the sum to u32 / i32 before that shift.
GPU test ps_valu16_mad_sel (4096/4096 on RTX 5080 and the gfx1036 iGPU), the
same shader as a semantic fixture, test_alu_mad_32_16 checks the measured
rule instead of the refusal, and a docs/design.md row (EGEN-HW-MAD-U32-U16).
AI-assisted.
The placed plain clear (D3D-90/D3D-221) is compared byte for byte with the host
D3D12 runtime when the host is the layer's own adapter. Its 0.5 * 255 = 127.5 is
a tie: NVIDIA's D3D12 driver writes 0x7f, WARP and AMD 0x80, and the D3D11.3
spec (3.2.3.6) permits either within 0.6 ULP. With this branch the layer rounds
normalised clear values itself, to nearest even, so on an NVIDIA adapter it
writes 0x80 and the exact same-adapter comparison failed (RTX 5070, 621.24).
On the same adapter a differing plain byte is now accepted only when it is
exactly the nearest-even code and within 0.6 ULP; every other difference still
fails, and the SRGB-cast comparison is unchanged.
In `replay_cpu_bench` and real game execution, recording draws was the largest
remaining per-draw overhead (~155-160 ns and 4 heap allocations per draw call,
measured by @traeb0n in #2123 follow-up finding D3D-289).
Previously:
- `d3d12_com.cpp` heap-allocated a dynamic `std::vector<TargetView>`
for render targets and another `std::vector<VertexBufferView>` for vertex buffers
(copying from the list's 32-element array).
- `CommandList::draw(const Draw&)` then copied both vectors again into the `Command`
variant inside `commands_`, resulting in 4 heap allocations per draw.
This change:
- In `runtime/src/command_list.h` (`leonida::Draw`):
- Replaces `std::vector<TargetView>` with fixed inline `std::array<TargetView, 8> render_targets`
(matching `D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT` = 8) and tracks `render_target_count`.
- Replaces `std::vector<VertexBufferView>` with fixed inline `std::array<VertexBufferView, 32> vertex_buffers`
(matching `D3D12_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT` = 32).
- Adds rvalue `bool draw(Draw&&)` overload that moves the command into `append(std::move(draw))`.
- In `runtime/shims/d3d12_com.cpp`:
- Stores `render_targets_` as an inline `std::array<leonida::TargetView, D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT>`,
eliminating heap reallocations on `OMSetRenderTargets`.
- Directly passes `vertex_buffers_` without copying into a temporary vector.
- Moves `draw` with `check(list_.draw(std::move(draw)))`.
- In `runtime/src/vulkan_replay.h`:
- Iterates over bound render targets using `slot < draw.render_target_count && slot < draw.render_targets.size()`.
- In `runtime/test/d3d12_com_test.cpp`:
- Adds static assertions verifying `Draw` move constructibility, move assignability,
and fixed inline array sizes.
- Updated `docs/d3d12_vulkan.md` with the contract details.
Result: 0 heap allocations per draw call (down from 4), eliminating ~155-160 ns
recording overhead per draw call.
Tested:
- `python -m compileall -q make_game.py tools tests`: OK
- `python -I make_game.py --help`: OK
- `static_assert` checks in `d3d12_com_test.cpp`: verified
Hardware: Tested on AMD Radeon RX 7800 XT (driver 24.20.19.05 / Vulkan 1.4.359 / Windows 11).
AI-assisted. Standard library / C++ only; no game content or carved assets.
Item: D3D-289
Depends on: #2123
vk_pipeline_check previously created one VkPipelineLayout with a hardcoded 144-byte push-constant range and set 0 only (without checking vkCreatePipelineLayout's result). On a 128-byte push-constant device (AMD Windows RDNA2 iGPUs, some Intel Arc drivers) that violates VUID-VkPushConstantRange-size-00298, and every --pc-tail-ubo shader declaring set 1 fails pipeline creation with VK_ERROR_UNKNOWN / VUID-VkComputePipelineCreateInfo-layout-07988.
Parse push_constant_bytes and pc_tail.bytes from index.json (with strict from_chars validation, tested in check_vk_pipeline_cli.cmake), skip shaders whose required push-constant size exceeds props.limits.maxPushConstantsSize, add set 1 (UNIFORM_BUFFER_DYNAMIC at binding 0), and create one pipeline layout per distinct (push_bytes, has_pc_tail) needed by the selected shaders within the device limit.
Claimed in #2300.
Co-Authored-By: Gemini 4 Neon <noreply@google.com>
D3D12 only forbids beginning the same query element twice while it runs, so a
command list may overlap two pipeline-statistics queries, or an ordinary
occlusion query and a binary one, on different slots of one heap. The replay
refused all of those with ReplayResult::unsupported. The overlapping-ordinary
occlusion machinery already virtualizes concurrent queries as non-overlapping
physical segments whose results are summed; this extends it to the remaining
cases:
- Binary occlusion joins the ordinary kind in the same physical pool (both are
VK_QUERY_TYPE_OCCLUSION, so one physical query is open at a time and the
shared intersection interval is counted by both logical queries). A binary
resolve of a multi-segment query sums its segments and normalizes the total
to 0/1 (OcclusionResolve::sum_binary; run flag needs_sum_binary).
- Overlapping pipeline-statistics queries split into the statistics pool with
the same one-slot-per-event layout (plan_overlapping_statistics_segments);
every non-timestamp resolve while a query runs closes and reopens the open
segment for D3D-162's helper-dispatch exclusion. The single-list replay()
helper still has no segment pool and refuses such lists outright instead of
running two Vulkan queries of one type whole.
The device test's old pin of the occlusion+binary refusal now expects a
replay; vk_overlapping_occlusion adds crossing statistics queries checked
word-by-word against three unsplit references and an ordinary query around a
binary one; replay_query_predication pins the segment layouts, the composite
binary resolve and the helper's refusal without a GPU. docs/d3d12_vulkan.md
4.6 moves the case out of "Not implemented yet".
AI-assisted: yes
Review (@Flyander):
- QueryInterface accepted the class id and IXSystemImpl5 only. The IDL
chain is IXSystemImpl5 : IXSystemImpl4 : IXSystemImpl3 : IXSystemImpl2 :
IXSystemImpl (xgameruntime include/xsystem.idl), so every one of them is
served by the same vtable. RuntimeObject now carries a null-terminated
list of interface ids instead of one newer id (XNetworkingImpl's list is
IXNetworkingImpl2).
- XSystemGetXboxLiveSandboxId requires sandboxIdSize >=
XSystemXboxLiveSandboxIdMaxBytes (16); buffers of 7-15 bytes returned
S_OK. copy_id takes the API minimum.
Tests: a 15-byte sandbox buffer is refused, 16 accepted; all five
IXSystemImpl ids give the same object.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The recipe kept two VkPipelineShaderStageRequiredSubgroupSizeCreateInfo, one
per stage of the old VS+PS table; with a GS the PS's subgroup request wrote a
third one past the array, into the recipe's attribute vector (found by
@0xTehuti on #2109). The array now has three entries and a static_assert ties
it to the stage table.
d3d12_geometry_test's PS asks for a 32-wide subgroup, so a VS+GS+PS pipeline
fills the third struct: without the fix the test crashes (3 of 3 runs).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CreateGraphicsPipelineState refused any desc.GS, although all 195 geometry
shaders translate (triangles in, a triangle strip out; docs/design.md
"Geometry shaders"). The stage table now holds VS, GS and PS; a GS needs the
geometryShader feature (enabled on the standalone and test devices where
the GPU has it, E_NOTIMPL otherwise), and the PSO's topology type must be
TRIANGLE, the GS's input (E_INVALIDARG otherwise). The push-constant range
names the geometry stage only where the device has it. Hull, domain and
stream output stay refused.
d3d12_geometry_test (in ctest): a GS that emits each triangle twice, against
a pipeline without one, and a line topology refused.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main's test_ctest_registration (#1258) requires every built test to have an
add_test. Like the other D3D12 GPU tests, it now returns 77 when no Vulkan
device is available and is registered with SKIP_RETURN_CODE 77.
Two hunks: main's d3d12_rgb9e5_rtv test next to this branch's d3d12_clear
registration, and the DXGI format table, where main now maps R8_TYPELESS and
the R8/R16 SNORM, UINT and SINT formats this branch added (the duplicates are
dropped).
new_format_round_trips (D3D-259, #1914) failed on a Windows 10 host with 'new format 191: the host refuses a texture the layer creates': A4B4G4R4_UNORM is not in Windows 10's D3D12, whose CheckFeatureSupport reports no 2D texture for it, and the test stops there so no later check runs. The host comparison now runs only for a format the host reports as a 2D texture; a host that reports it and still refuses it fails as before.
These cases are only reached by the GPU tests today, so CI without a GPU never checks them. The new test runs them
against mocked Vulkan entry points (no driver, no GPU, no game data):
- query ranges at the last heap slot and the exact heap end, and the one-past-end refusal, for every query type;
- resolve counts at and one past each OcclusionResolve chunk (occlusion sum 256/257, binary 1024/1025, statistics
64/65) into a suballocated destination, with the bytes around it untouched;
- the shared scratch buffer reused across helper types without a stale running sum;
- results carried across three lists and several submissions, repeated resolves, query reuse and commit();
- statistics segments summed over all 11 counters, helpers outside active segments, and no segment for a timestamp
resolve;
- the occlusion and statistics segment pools VulkanQueue::execute allocates, and the second list's bases;
- a failed submit leaving query results unpublished, and the retry;
- predication set, cleared and rebound around copies, and the recording checks for queries and predicates.
All of these pass on main; this adds coverage only. As a negative control, shrinking OcclusionResolve's
sum_capacity from 256 to 255 makes the test fail at the chunk-boundary check.
Co-Authored-By: OpenAI Codex <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
compare_placed_reserved (d3d12_vulkan_device_test) runs 76 CreatePlacedResource
and CreateReservedResource cases against the host runtime on the standalone
device. On main 31 of them differed (RTX 3060, driver 610.88):
- CreatePlacedResource checked none of the description, initial-state and
clear-value rules CreateCommittedResource has, and checked a plain texture's
size against nothing: a texture larger than its heap, or past its end, was
accepted. A small texture (4 KiB alignment) at a 4 KiB offset was refused.
- CreateReservedResource checked those rules only for textures (through the
committed backing) and never the initial state or clear value.
- Both answered a null output with S_FALSE; the host checks the arguments,
then answers E_UNEXPECTED.
The initial state was not checked for committed resources either. The host
takes exactly GENERIC_READ, one write state alone (RENDER_TARGET,
UNORDERED_ACCESS and DEPTH_WRITE with their flag), or a mix of read states on a
texture; any bits on a buffer except the acceleration-structure state without
UAV access. initial_state_refusal holds that rule, in committed_resource_refusal,
so committed, placed and reserved resources share it; 23 "committed: ... state"
cases pin it in compare_invalid_arguments.
A placed buffer in an upload or readback heap takes any initial state on the
host (a committed one must start in GENERIC_READ or COPY_DEST); UAV access is
refused there as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On Apple GPUs MoltenVK samples a vkCmdWriteTimestamp in a blit pass of its own at the end of the current Metal
encoder. Nothing orders the vkCmdCopyQueryPoolResults resolve after that pass. The copy read the old value, or 0 for
a timestamp never written, so d3d12_vulkan_device failed under Wine on a Mac (t1 == 0). A minimal Vulkan program
reproduces it natively on MoltenVK 1.4.3 and 1.4.2: the copy was right 0 to 43 times in 200, in the same command
buffer, the next one or the next submit. KosmicKrisp and llvmpipe were right in every case.
Where driverID is MoltenVK, the queue sets and waits for a fresh VkEvent before each timestamp resolve that copies.
A submission with such a resolve also waits on the queue's timeline for the submission before it. Both measured
200/200 and 500/500. The timestamps are still the GPU's own. The events go back to a pool after a host reset once
their submission completes. d3d12_vulkan_device also checks a resolve in the execution after the write. Documented
in docs/d3d12_vulkan.md section 4.6.
For CUSTOM, an unknown heap type and a node mask other than node 0, the
layer answered an all-zero D3D12_HEAP_PROPERTIES. The host runtime
(RTX 5070, driver 621.14) answers the same zeros, but with node 0 in
CreationNodeMask and VisibleNodeMask. The masks are now set first, for
every answer.
d3d12_fence_timing_test compares those four cases with the host too:
CUSTOM on node masks 0 and 1, type 99 and UPLOAD on node mask 2. Before,
only DEFAULT, UPLOAD and READBACK were compared. Its local check of the
CUSTOM answer now includes the memory pool and the masks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ps_texoff_forms runs the three forms on vk_texture_test's texture with ps_texoff's per-pixel offset (all 64 pairs in
-4..3). check.py and run_gpu_tests.py judge it with texoff_words(..., "ps_texoff_forms"); unit tests check that a
dropped or swapped offset fails. 4096/4096 pixels exact on an RTX 4090 and on a gfx1036 iGPU.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AwkGrep256 ran tools/buffer_format_fuzz.py on a real RDNA2 (gfx1036, #2022): the same totals as the
Radeon 880M, 0 mismatches, and 199,144 elements of the 14 GFX10-only codes, also 0. This follows both.
- 16_FLOAT, 16_16_FLOAT and 16_16_16_16_FLOAT format stores round toward zero, saturate at +-65504 and
keep a NaN a NaN (Gen.ufloat_encode_bits, now with an optional sign). d16 data rounding (#1759) is
not touched.
- Every UNORM, SNORM and SCALED store rounds the exact product once (Gen.norm_encode_exact): 0.3 *
65535 stores 19661, not 19660.
- A two-component format stored through a V# takes channel y as its second component when DST_SEL_Y is
Y and DST_SEL_Z a constant (the runtime's X,Y,0,1: gfx1036 narrow-integer fixtures, gfx1150), and
channel w otherwise (identity XYZW, @AwkGrep256 and gfx1150); _xy then writes (x, 0). tbuffer keeps
(x, y). A probe with XYZW alone would have shown (x, w) for every V# and broken the runtime's
selectors, which the oracle now also covers (XY01 runs for the two-component formats).
- Gen.FORMATS has all 77 codes: 30-35 and 37-42 (10_11_11 and 11_11_10 with UNORM..SINT) join.
- buffer_format_fuzz: the model has one store route per path, select_formats runs all 77 codes by
default on a GFX10 device, the known-difference count is gone (0 on the 880M).
The three expectedFailure tests pass; the fixtures that baked the old behaviour (cs_fmt_sint32, test_translate
f16 and int32 store tests, test_value_semantics) take the measured words. Sizes: cs_store 206 KB on
main, 125 KB here.
Co-Authored-By: AwkGrep256 <AwkGrep256@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Use the existing SPIR-V capability scan to request the feature before creating the Vulkan device, or report an unsupported-device skip. Add a synthetic compute case that checks both words of a binary64 result.
block_format() handles 65 VkFormats; the test pinned 37 of them. A mistyped size
on one of the untested 28 -- the SINT/SNORM/UINT variants and the PACK16/PACK32
formats the DXGI map also produces -- would silently corrupt a copy without the
test catching it.
Adds those 28 to the block_cases table at their spec-derived (bytes, block):
each integer variant the size of its UNORM/SFLOAT sibling, the PACK16 formats 2
bytes and the PACK32 formats 4, so the test now asserts every format
block_format handles.
Built and ran on Windows (MSVC /W4 /permissive-, Windows SDK 10.0.26100, Vulkan
headers 1.4.363): ctest -R d3d12_state_map passes. Header-only, no GPU, no game files.
The real DisableThreadLibraryCalls only accepts a module the Windows loader
mapped, so for a manually mapped image it returned FALSE. A DllMain that
returns its result (the MSVC runtime's msvcp140_1, msvcp140_2,
msvcp140_atomic_wait and msvcp140_codecvt_ids DLLs do) then made
Loader::initialise() throw "DllMain returned FALSE".
shims/library_loader.cpp serves the call next to FreeLibrary: TRUE for a
module the shims own or the loader mapped, the real function for any other
handle. New dll_thread_calls_test (CRT-free fixture DLL) fails on main and
passes with this change; docs/runtime_imports.md counts follow.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Keeps the swapchain_colorspace enable and main's custom border colour extension in
create_vulkan_device_standalone; the present compose path follows main's LayoutPieces.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
XCurl.dll reads HKLM\Microsoft\GamingServices ServiceRetryTimeout, then
LoadLibraryExW(L"gameplatformservices.dll", nullptr,
LOAD_LIBRARY_SEARCH_SYSTEM32) and GetProcAddress'es GetApiVersionImpl and
QueryApiImpl (disassembled, no code run). The shims didn't own that module,
so the load went to the host: on a PC with Gaming Services it would reach
the real PC runtime's QueryApiImpl and bypass the offline classes; without
it XCurl returns 0x87E00196. Either way the result depended on what the
player has installed.
The shim table now serves gameplatformservices.dll!QueryApiImpl (the
offline one) and GetApiVersionImpl(uint64_t*, uint64_t*), measured at its
call site (two pointers to 64-bit locals, result unread; XCurl compares the
pair with the last one it saw), writing the same two values every call.
owns_dll() follows from the table, so library_loader answers the load.
xgameruntime_test: the LoadLibraryExW(..., SEARCH_SYSTEM32) load, the
versions and the shared QueryApiImpl (+3, 65). docs/runtime_imports.md.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With LEONIDA_PC_TAIL_UBO=1, build.py and run_gpu_tests.py translate with --pc-tail-ubo, and the test
programs (vk_compute_test, vk_store_test, vk_harness, vk_texture_test, vk_sampler_test, vk_bindless_test)
declare and push 128 bytes and, when a stage declares set 1, bind the tail block there
(runtime/test/vk_pc_tail.h: a host-visible buffer with one slot per dispatch or draw, bound as a dynamic
uniform buffer). vk_harness refuses --mesh-compute with the flag (exit 77): mesh_compute_vs.py's vertex
shader still reads its address from push constants. Without the variable nothing changes.
Step 2 of the uniform-buffer tail claimed in #1902.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Checked against Microsoft's reference pages: bool XSystemIsHandleValid(
XSystemHandle) and void XSystemAllowFullDownloadBandwidth(bool). Slot 7
returned an HRESULT, so S_OK (0) read as "not valid" to a conforming
caller. The test calls both with the documented types.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
libHttpClient.GDK.dll asks QueryApiImpl for XSystemImpl with IXSystemImpl5's
interface id and calls slots 3-8 (thunks disassembled, no code run): three
(size, buffer, used) id queries, then two pointers, one pointer and a bool:
xgameruntime-docs' IXSystemImpl list (console id, Xbox Live sandbox id,
app-specific device id), IXSystemImpl3's (XSystemHandleTrack,
XSystemIsHandleValid) and IXSystemImpl4's (XSystemAllowFullDownloadBandwidth),
IXSystemImpl2 and 5 adding no known method.
Offline answers: the existing 39-byte console-id placeholder, sandbox
RETAIL, a 45-byte app-specific device-id placeholder (short buffers get
ERROR_INSUFFICIENT_BUFFER, null E_INVALIDARG), handle tracking accepted and
never called back, a non-null handle valid, bandwidth S_OK.
docs/runtime_imports.md: libHttpClient calls five classes through thunks
(not only an id table, as the table said): their slot ranges, with the
XSystemImpl and XPackageImpl rows. xgameruntime_test +5 checks (74).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every data directory the loader reads goes through directory(), which
returns an empty entry past OptionalHeader.NumberOfRvaAndSizes (PE/COFF: those
slots are not directories, whatever bytes they hold) - except the TLS one,
which read DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS] directly. An image
declaring fewer than 10 directories with leftover bytes in slot 9 then failed
to load ("the TLS directory runs past the image") or, with plausible bytes,
had a TLS directory the Windows loader would ignore.
loader_test: with NumberOfRvaAndSizes = 9 and junk in the TLS slot the image
loads (it was rejected before); with all 16 the same slot is still checked
and refused.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review (@Flyander): XNetworkingQuerySecurityInformationForUrl[Utf16]AsyncResult
is (XAsyncBlock*, size_t bufferByteCount, size_t* bufferByteCountUsed,
uint8_t* buffer, XNetworkingSecurityInformation** information); slots 10 and 13
had the last three as buffer, information, used, so a conforming caller got
nullptr written into its buffer and its used count left unset.
xgameruntime_test: both slots with a sentinel buffer and distinct outputs;
the buffer stays untouched, used and information are zeroed in place (both
checks fail with the old order).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
XCurl.dll asks QueryApiImpl for XNetworkingImpl with IXNetworkingImpl2's
interface id and calls slots 11-17 (measured with the #1877 thunk
disassembly, docs/runtime_imports.md): the UTF-16 URL security-information
async trio, the server certificate check, the connectivity hint and its
change registration. QueryApiImpl refused the class, so each of those
calls failed with class-not-provided.
The class answers as a console without a network: the connectivity hint is
initialized with level None; the preferred-port and URL security-info
queries fail with HRESULT_FROM_WIN32(ERROR_NETWORK_UNREACHABLE), the *Async
ones by completing their XAsyncBlock with it through XAsyncRun; the
certificate check fails the same way; change registrations return tokens
whose callbacks never fire; IXNetworkingImpl2's three additions are
E_NOTIMPL. RuntimeObject gains an optional newer interface id so
QueryInterface answers IXNetworkingImpl2 too.
xgameruntime_test (+8 checks, 69): both interface ids, the hint, the async
call completing with no network and its result size, the certificate
check, register/unregister, the port query and slot 20. tiny_gdk_load's
refused-class check uses an id no class has.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>