Commit Graph

1118 Commits

Author SHA1 Message Date
173ce07977 d3d12: residency calls answer as the host runtime does
d3d12_residency_test runs the same 110 MakeResident / Evict /
SetResidencyPriority / EnqueueMakeResident steps on the Vulkan-backed device
and on the host runtime, with a committed buffer, a heap, a placed buffer, a
descriptor heap, a query heap and a fence of each. It compares every HRESULT,
the device-removed reason after each step, and the value EnqueueMakeResident
leaves the fence at. Steps that leave the host runtime unusable run there in a
child process with a fresh device (--host-step). On main 7 steps differed (RTX
3060, driver 610.88); now none do:

- SetResidencyPriority takes a priority only for objects that own their
  memory, committed resources and heaps. A placed resource (a reserved one too,
  by the same rule; not measured), a descriptor heap, a query heap or a fence is E_INVALIDARG, also inside a
  longer list (the layer accepted all of them). The host also removes its
  device then (DXGI_ERROR_INVALID_CALL); the layer doesn't, since a title that
  sets priorities on placed resources would lose its device over a hint.
- EnqueueMakeResident accepts a null fence and signals nothing (the layer
  answered E_INVALIDARG).

Not compared: a nonzero count with a null array and a null entry in an array,
which the host dereferences; and a value below the fence's current one, which
moves the host's fence back but not the layer's (Vulkan timelines only go up,
already documented).

d3d12_vulkan_device_test's residency checks expected the old answers for a
fence and an allocator's priority and for a null fence, and now expect the
host's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 22:04:47 +01:00
61d8911cee d3d12: build against every Windows SDK 10.0.26100 d3d12.h (BUILD-970)
The README asks for "Windows SDK 10.0.26100 or newer", but the SDK's
d3d12.h changed within 10.0.26100: 10.0.26100.6584 ships
D3D12_SDK_VERSION 612, later builds 616. main used names from newer
headers, so it stopped compiling on the older 10.0.26100 builds:

- D3D12_FEATURE_D3D12_OPTIONS21 and its payload, with
  D3D12_WORK_GRAPHS_TIER_NOT_SUPPORTED and
  D3D12_EXECUTE_INDIRECT_TIER_1_0 (header 613);
- D3D12_INDIRECT_ARGUMENT_TYPE_INCREMENTING_CONSTANT (613);
- D3D12_FEATURE_D3D12_OPTIONS20 with D3D12_RECREATE_AT_TIER_NOT_SUPPORTED,
  and D3D12_FEATURE_PREDICATION (611).

They join the two feature values d3d12_feature_compat.h already declares
for the same reason: ABI values and payload structs in rt::d3d12::compat,
used by the device and its test. Where the header has the real
declarations, static_asserts check that the values, sizes and offsets
agree.

The runtime and every test now build against DirectX-Headers v1.610.2,
v1.611.0 and v1.613.0's d3d12.h (put ahead of the SDK's) and against the
SDK's own 616 header. Before this change, 611 failed with 18 errors and
610 with more.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GN11jcpJWD4phrXJyDgED6
2026-11-22 21:02:24 +00:00
00a04419de Validate depth-stencil views in CreateDepthStencilView
The TEXTURE2D/TEXTURE2DARRAY/TEXTURE2DMS/TEXTURE2DMSARRAY and default
paths wrote a TargetView with the caller's mip and slice range without
any of the checks the render-target-view path makes: no mip or layer
bounds, no dimension or sample-count match, no ALLOW_DEPTH_STENCIL
requirement and no view-format legality. An invalid view was silently
recorded as valid.

Give every depth view the same checks: the resource must be a
depth-capable texture, the view dimension must match the texture's
dimension and sample count, the mip and layer range must fit inside it
and the view format must be a concrete depth format of the resource's
own family (D16/D32/D24S8/D32S8X24, or that depth format for the
matching typeless resource). A refused view writes a null TargetView.

Adds runtime/test/d3d12_dsv_test.cpp covering valid TEXTURE2D,
TEXTURE2DARRAY, TEXTURE2DMS, typeless and default views plus refused
out-of-bounds mip/slice, MSAA/non-MSAA mismatch, non-depth resource and
wrong-family format views.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-11-22 20:51:16 +00:00
2edd806f5c d3d12: typeless depth-stencil textures without ALLOW_DEPTH_STENCIL 2026-11-22 15:51:15 -05:00
1b3a0d80f3 d3d12_xs: the device proxy answers IDXGIDevice1 (GetAdapter), step 3 of the GDKX boot sequence
A GDKX title asks its device for IDXGIDevice1, then GetAdapter and
EnumOutputs(0), to find the output it gives SetFrameIntervalX. The proxy
refused the QueryInterface, and a PC ID3D12Device has no IDXGIDevice to
forward to.

The proxy now answers IDXGIObject, IDXGIDevice and IDXGIDevice1 as one COM
object with the device (a second vtable pointer in the proxy, same reference
count and QueryInterface). GetAdapter and GetParent return the adapter of the
device behind it: the host DXGI adapter with the device's LUID on the host
backend, the layer's own rt::dxgi adapter on the Vulkan device
(set_device_outer installs that provider).

dxgi_device_test walks it on WARP, the first hardware adapter and the Vulkan
device.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-22 20:35:26 +00:00
c262fb7b3c Runtime: gate counted indirect compute dispatches on GPU 2026-11-22 15:34:34 -05:00
780a8770cf d3d12: log once when a texture or default-heap buffer spills out of device-local memory (D3D-299)
DeviceState::allocate takes the next memory type when device-local memory is
full, so on a 4 GB GPU a texture could land in system memory without a word.
leonida::spilled_to_host (vulkan_memory.h) says when that happened: the
allocation preferred DEVICE_LOCAL, needed no host access, and got a type
without it. The arena and upload heaps in system memory without Resizable BAR
are the memory type policy and are not reported. The first spill is logged
once, with its size, memory type and heap. Part of #2375.

# Conflicts:
#	runtime/shims/d3d12_vulkan_device.cpp
2026-11-22 21:28:35 +01:00
6f66c4b5aa d3d12: CreateRootSignature registers the root signature's static samplers
The Vulkan device parsed a root signature's static samplers and dropped them,
so a shader holding one's S# by value missed in the hash table and sampled
through the fallback sampler. Each one now gets a sampler in set 0 and a key in
the hash table at root-signature creation, encoded as CreateSampler2 encodes
the same description (1.0, 1.1 and 1.2 blobs, the static border-colour enum,
the 1.2 flags).

d3d12_descriptor_test checks the key before and after for four root
signatures and samples with three of them on the GPU. docs/d3d12_vulkan.md no
longer says both that they are registered and that they are not.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-22 20:27:04 +00:00
58226b459c Seed runtime Vulkan pipeline cache from offline builds 2026-11-22 21:24:02 +01:00
6de779367b Runtime: command allocators and lists answer invalid arguments as the host does
Measured against the host D3D12 runtime (RTX 5070, driver 621.14) with
d3d12_vulkan_device_test's compare_invalid_arguments:

- CreateCommandAllocator and CreateCommandList1 took any type (7, 99,
  -1); the host refuses types past VIDEO_ENCODE with E_INVALIDARG.
- CreateCommandList and CreateCommandList1 took a node mask with bits
  past node 0; the host answers E_INVALIDARG.
- A null output was E_POINTER in all three; the host answers
  E_UNEXPECTED, after the argument checks.

compare_invalid_arguments gets 35 "command allocator:", "command list:"
and "command list1:" cases. Video list types are not compared: the host
hands out a video list (E_NOINTERFACE for ID3D12GraphicsCommandList),
while this layer creates a graphics list for them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 21:21:25 +01:00
b5e9ca4ccc Runtime: expose conservative rasterization Tier 2 with capability gates 2026-11-22 16:20:44 -04:00
23c3ccebd9 Merge pull request #3274 from 73N1X 2026-11-22 15:16:24 -05:00
a09d690ca9 Merge pull request #3252 from Douglas Sposito 2026-11-22 15:16:12 -05:00
cd472ec101 D3D12 layer: stream-output statistics query heaps (D3D-302)
CreateQueryHeap(D3D12_QUERY_HEAP_TYPE_SO_STATISTICS) returned E_NOTIMPL, so
a title that makes one got nothing. The layer has no stream output (a PSO
with StreamOutput entries is refused, SOSetTargets is not implemented), so
every SO_STATISTICS_STREAM0..3 query counts 0 written and 0 needed.

Such a heap is now made without a VkQueryPool: Begin/EndQuery record nothing
in Vulkan (the D3D12 call rules and the ended tracking still apply), the
queries overlap no occlusion or statistics query, and ResolveQueryData fills
16 zero bytes per query (D3D12_QUERY_DATA_SO_STATISTICS) with no statistics
split. When stream output lands this becomes a
VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT pool.

Mesh-shader statistics (PIPELINE_STATISTICS1) are left to D3D-132.
2026-11-22 20:14:17 +00:00
f1c8e9370d d3d12: GetResourceAllocationInfo* answer the invalid allocation for a visible mask above 1
On a single-node adapter the host runtime and WARP return SizeInBytes UINT64_MAX with 64 KiB alignment
for a visible mask naming a node that does not exist, also for zero resources, and leave the
per-resource array untouched (GetResourceAllocationInfo, 1 and 2). The layer ignored the mask and
returned a real size. Compared with the host in d3d12_vulkan_device_test.
2026-11-22 15:13:58 -05:00
e459634208 Merge pull request #3003 from Kacper Serewis 2026-11-22 15:13:57 -05:00
f5ec088201 Merge pull request #2817 from IAmNotSiob 2026-11-22 15:12:17 -05:00
bf576586b3 d3d12: place 1D and 3D textures like 2D ones
CreatePlacedResource answered E_NOTIMPL for every non-tiled texture that
was not 2D, while the host places 1D and 3D textures. A placed texture
already gets its own image from create_texture, which handles 1D and 3D
for committed textures, so the 2D-only branch goes. The checks before it
(size and room in the heap, an invalid dimension, no output pointer)
stay as they are and now cover 1D and 3D too.

d3d12_placed_dimensions_test compares the answers and GetDesc with the
host (default adapter and WARP) for 1D, 1D arrays, 3D, BC1 3D, UAV and
render-target 1D/3D textures, and round-trips a pattern through every
subresource of a placed 3D texture and a placed 1D array.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 20:12:16 +00:00
e138630254 Merge pull request #2772 from Nicolas Abosch 2026-11-22 15:11:49 -05:00
63ab7be421 Runtime: zero-fill default-heap buffers outside the arena (D3D-71)
D3D12 committed resources start zeroed unless the heap has
CREATE_NOT_ZEROED. Arena buffers are zeroed through its mapping, but
device-local buffers outside it were not ("default-heap buffers are not
zero-filled yet"). They are now queued on the context and filled with
vkCmdFillBuffer by the next submission on any queue, ahead of its lists.

That submission publishes the same initialisation semaphore as the
storage-image setup, so a list on another queue that uses the buffer first
waits for the fill. A buffer destroyed before any submission leaves the
queue, and a failed submission puts its fills back.

A queue being destroyed now clears that shared semaphore if it published
it: the queue is idle, so the work is done, and a later submission on
another queue would otherwise wait on a destroyed semaphore. With buffer
fills publishing it often, d3d12_vulkan_device_test hit exactly that
(vkQueueSubmit: invalid pWaitSemaphores, then a crash).

d3d12_vulkan_device_test (a device without the arena) reads a fresh
default buffer back as zeros after dirtying recycled memory, and checks
that a CREATE_NOT_ZEROED buffer written in the same list keeps the copy.
2026-11-22 20:11:43 +00:00
92da70ad6b Merge remote-tracking branch 'origin/main' into bindless-per-queue-retire
# Conflicts:
#	runtime/src/vulkan_backend.h
2026-11-22 21:11:25 +01:00
5a41704181 Merge pull request #2167 from Alex Arenas 2026-11-22 15:10:18 -05:00
5063e9cd80 Merge pull request #2069 from AlxcBTW
# Conflicts:
#	docs/d3d12_vulkan.md
2026-11-22 15:10:09 -05:00
7fded18980 Merge pull request #1773 from Vonsek 2026-11-22 15:09:47 -05:00
803abc9176 Merge pull request #1611 from Vonsek 2026-11-22 15:09:45 -05:00
6c92d8e998 Merge pull request #612 from ismailchaka1 2026-11-22 15:09:35 -05:00
7be6847cf0 d3d12: a pipeline registers its shaders' literal S#s
A shader that builds its S# from immediates (literal_samplers in the
translator index) names no heap slot, so nothing gave that S# a sampler
and a hash-table key: register_samplers (#1169) had no caller outside its
test. The shader's lookup found the fallback sampler and sampled with
the wrong filter and address modes.

ShaderLibrary now keeps each entry's literal_samplers, and
CreateGraphicsPipelineState / CreateComputePipelineState register those
of every stage that uses the bindless set.

Test: ps_m2_literal.asm (ps_m2 with the S# from s_mov literals) in
d3d12_m2_textured_test: no key for the words before its PSO, a sampler
index after it. Fails on main, passes here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 17:05:25 -03:00
5418decf08 Runtime: GPU address arena high-water mark (D3D-55)
The device tracks the arena's peak end offset, its peak live bytes overall
and per use (buffers, shader-visible descriptor heaps, shader code and
D3D12 heaps), and its allocations and refusals, and prints one line at
release. LEONIDA_ARENA_LOG=1 also logs every VA handed out, every refused
request, and upload/readback VAs outside the arena. This answers open
question 5 (how large the arena must be) once the game runs.

Rebased onto main now that #291 is in: arena_allocate/arena_release take
the use, and every call site passes it, including the heap ranges #291
added since.
2026-11-22 20:04:14 +00:00
90f10662ac Merge upstream main into reserved texture tile mappings 2026-11-22 17:03:14 -03:00
b9cc5f9a32 Runtime: support conservative rasterization Tier 1 2026-11-22 16:02:50 -04:00
15b4154142 Runtime: support conservative rasterization Tier 1 2026-11-22 15:57:00 -04:00
dd86750fde Runtime: views across B8G8R8X8 and B8G8R8A8 through a castable-format list (BUILD-768)
A castable-format list may name the other family of a B8G8R8X8 or
B8G8R8A8 texture (relaxed casting). WARP and AMD's D3D12 driver accept
such lists both ways, typed and TYPELESS, and an SRV in a listed format
reads by its own format: alpha 1 for B8G8R8X8, the stored byte for
B8G8R8A8, and red and blue swapped when the list crosses channel orders
(an R8G8B8A8 texture read as B8G8R8A8 or B8G8R8X8). The layer kept the
list only as Vulkan formats, where both families are BGRA8, so it refused
a view across them, and its T# took the channel order from the image's
format, so a B8G8R8A8 view of an R8G8B8A8 texture read unswapped.

The resource now also keeps the list as the application gave it,
image_descriptor lets a view cross the families when the list names its
format, the alpha swizzle follows the view's format, and a colour view in
the other channel order takes its swizzle from that order (both orders
share one T# format code).

d3d12_descriptor_test adds a B8G8R8A8_UNORM texture listing
B8G8R8X8_UNORM, a B8G8R8X8_UNORM one listing B8G8R8A8_UNORM, and two
R8G8B8A8_UNORM ones listing B8G8R8X8_UNORM and B8G8R8A8_UNORM, each viewed
through the listed format: T# formats and swizzles, an unlisted format
refused, and the same bytes sampled through the bindless set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 16:53:06 -03:00
09c6cbe045 fix(runtime): support InstanceDataStepRate > 1 via vertex attribute divisor
CreateGraphicsPipelineState previously logged that instance step rates above 1 were not modelled and left per-instance slots stepping every instance.

Query and enable vertexAttributeInstanceRateDivisor via VK_KHR_vertex_attribute_divisor (falling back to VK_EXT_vertex_attribute_divisor) in create_vulkan_device() and vk_test_device.h, chain VkPipelineVertexInputDivisorStateCreateInfoEXT onto VkPipelineVertexInputStateCreateInfo::pNext when a per-instance slot has InstanceDataStepRate > 1 (refusing with E_NOTIMPL when the feature is unavailable), and add a synthetic GPU instanced draw test in d3d12_draw_test for step rate 2 with a step-rate 1 negative control.

Rebased onto upstream/main (16282101), chaining divisor feature structs via v13.next()/v13_.next() and moving step_fence to 60 after x8_fence.

AI-assisted.
2026-11-22 20:50:50 +01:00
81ec7f74c3 d3d12: link f16 halves between the VS and the PS, which is stages[2] since #2109
#2109 made the PSO stages {vs, gs, ps}; the --f16-interp-fallback link (SHADER-378, #2389) still read the PS from
stages[1], found the empty GS slot and never ran, so d3d12_f16_halves drew nothing. With a GS the PS reads the GS's
outputs, so the VS/PS link is skipped there (logged once). Also: xgameruntime_test re-reads the package id after
clearing the LEONIDA_PACKAGE_ID override.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 14:41:01 -05:00
07e2293ec0 feat(runtime): implement buffer CreateShaderResourceView (raw, structured, typed GFX10 V#)
Implement D3D12_SRV_DIMENSION_BUFFER in ID3D12Device::CreateShaderResourceView,
writing a 16-byte GFX10 V# descriptor into the 32-byte CBV_SRV_UAV slot:
- Raw (D3D12_BUFFER_SRV_FLAG_RAW, R32_TYPELESS, stride 0): OobSelect::raw,
  num_records = NumElements * 4, GFX10_FORMAT_32_UINT.
- Structured (StructureByteStride > 0, DXGI_FORMAT_UNKNOWN): OobSelect::structured,
  stride = StructureByteStride, num_records = NumElements, GFX10_FORMAT_32_UINT.
- Typed (stride 0, uncompressed color format incl. RGB96): OobSelect::structured,
  stride = element bytes, num_records = NumElements, format_from_vulkan(named),
  Shader4ComponentMapping applied to format_swizzle(named).
- Rejects DENY_SHADER_RESOURCE, null desc on buffer, invalid format/stride/flag
  combinations, and out-of-bounds ranges (leaving the 32-byte slot zeroed).

AI-assisted.
2026-11-22 20:37:10 +01:00
b34368e7a2 d3d12: exclude 8-bit sRGB formats from typed buffer support 2026-11-22 20:05:06 +01:00
a8fae90809 Order the bindless table upload across queues, bound retired generations, keep the in-use set on failure (review of #2740)
Other queues' next submission waits on the timeline value of the submission that carries a new generation's table upload; the submit result is committed under tracker_mutex_; at most 8 retired generations are kept before the flush waits for the oldest one's ticket (queue timelines, not the device); a failed new generation leaves the in-use set and the pending writes alone. The churn test gains an async-compute case (no D3D12 fence from compute to the direct queue), a check that a retired generation is pending right after its submit, and a --validated ctest. Docs: only public sources.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 19:46:53 +01:00
d3b774eed5 PresentX planes: tone map shoulder, SDR white query off the present path, review fixes
- Tone map: identity up to 0.8 of SDR white, extended Reinhard shoulder above it, continuous in value and slope, content
  peak maps to 1.0 (SDR-range content is no longer darkened).
- The Windows SDR white level is read by a background thread (about once a second, only while HDR10 is in use);
  PresentX reads an atomic. A failed query keeps the last good value; QueryDisplayConfig retries on
  ERROR_INSUFFICIENT_BUFFER.
- LEONIDA_SDR_EOTF is case-insensitive, unknown or too long values are logged; setters are atomics; <cwchar> for wcscmp.
- Tests: eight-step HDR10 ramp with hand-calculated bytes, curve properties (monotonic, identity below the knee, peak 1,
  slope continuity), HDR10 plane 1 over SDR plane 0 on HDR10 and SDR outputs, hand-calculated 50% overlay bytes, query cost.
- Docs 4.5: shoulder description, query cost, sources marked (KWin claim unverified, vkd3d-proton file partly read, the
  measured 80 nits only covers the SDR fallback path).
- present_compose.inc rebuilt with glslc 2026.4 (reproducible, spirv-val clean).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 19:45:00 +01:00
3a44e1926b Merge pull request #2736 from mrp1no 2026-11-22 13:17:27 -05:00
0963784063 PresentX planes: filter and blend in linear light, selectable SDR EOTF, Windows SDR white level, tone map
- Compose pass decodes every texel to linear (premultiplied) before filtering, converts the plane to the output's linear
  working space (Rec.2020 nits for HDR10, Rec.709 relative to SDR white for SDR), blends there and encodes once.
- SDR EOTF is piecewise sRGB by default (community-sourced Windows behaviour), gamma 2.2 by
  XboxPresentation::set_sdr_eotf or LEONIDA_SDR_EOTF=gamma22.
- SDR white: set_sdr_white_nits override, else DISPLAYCONFIG_SDR_WHITE_LEVEL of the window's output while HDR10 is
  active, else 203 nits (BT.2408).
- HDR10 on an SDR output: extended Reinhard on luminance (white point at the content peak, default 1000 nits) instead of a
  hard clip.
- HDR metadata stays unsent; docs section 4.5 documents the decisions and cites the sources.
- CPU reference model and xbox_present_test updated (linear model, EOTF option, 50% overlay, tone map, white level query).
- present_compose.inc rebuilt with glslc 2026.4 (byte-reproducible, spirv-val clean).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 19:17:24 +01:00
a44df460f3 Merge pull request #2662 from admin 2026-11-22 13:16:54 -05:00
1c3360367f Merge pull request #2591 from 0xTehuti 2026-11-22 13:16:24 -05:00
23f61f5724 Merge pull request #2563 from Ewann 2026-11-22 13:16:12 -05:00
da3861dd86 Merge pull request #2462 from mrp1no 2026-11-22 13:15:29 -05:00
84df39f34f Merge pull request #2453 from Flyander 2026-11-22 13:15:26 -05:00
0dff1b420b Merge pull request #2416 from Ewann 2026-11-22 13:15:09 -05:00
09cf8b65e3 rdna2spirv: s_memtime / s_memrealtime via OpReadClockKHR, enable VK_KHR_shader_clock 2026-11-22 19:14:59 +01:00
78688eab40 Merge pull request #2389 from Julio Facal
# Conflicts:
#	docs/design.md
2026-11-22 13:14:35 -05:00
e41720bac9 Merge pull request #2373 from Ewann 2026-11-22 13:14:21 -05:00
c7894a6fb7 Merge pull request #2242 from Ewann 2026-11-22 13:13:28 -05:00