Commit Graph

26 Commits

Author SHA1 Message Date
d1539971a9 runtime: programmable sample positions only for multisampled targets (RT-SAMPLE-LOCATIONS-MSAA-ONLY)
#778 filled the sample-locations grids from 1 sample upwards, so every 1x depth-stencil image was created
sample-locations compatible and carried sample locations through its transitions. D3D12 only has programmable
sample positions for multisampled targets; since #778 the world phase loses the device on an RTX 5080. Keep 1 sample
out (SamplePositions::programmable_count): 1x depth images are plain again, MSAA keeps the feature.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwPPpwX5RYWwXCnj43U
2026-11-29 22:43:46 +01:00
a3e2088fd6 Merge main into d3d-sample-positions
Conflicts, all kept from both sides:
- GraphicsPipeline: main's rectangle_stage took bit 9, so custom_samples
  moves to bit 10; sample grids sit next to main's async_build.
- The pipeline variant appends VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT to
  main's dyn_list (8 entries at most) and keeps main's lazy shader modules.
- initialize() takes main's per-aspect zeroing and depth-UAV paths and still
  passes the active sample positions to every barrier.
- prepare_draw keeps main's skip/quad-index handling and the sample
  positions argument; emit_commands keeps active_samples, including main's
  clear-pattern round trip and the release (into UNDEFINED) barriers.
- Texture creation keeps main's 1D/3D UAV limits and the sample grid.
- Both new replay_texture_barrier_test cases are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 13:56:55 +05:00
37c5af12a4 d3d12: an enhanced texture barrier into LAYOUT_UNDEFINED closes and keeps the layout (D3D-BARRIER-INTO-UNDEFINED)
CommandList::barrier(TextureBarrier) refused LayoutAfter = UNDEFINED from a
defined layout, so the list's Close failed. D3D12 allows it: the contents are
no longer needed, as before the memory is aliased. WARP closes such a list
(measured on Windows 11 26340 in #984), and #984 reports that the retail title
ends a depth buffer's use this way and takes the failed Close as fatal.

The rule goes. Vulkan has no transition into UNDEFINED
(VUID-VkImageMemoryBarrier2-newLayout-01198), so replay gives each piece a
barrier with oldLayout = newLayout, the layout the tracker has for it, which
orders the accesses and changes nothing in the image; the tracker keeps the
layouts. A piece that was never used gets no barrier and is not zero-filled
for it. The next barrier starts from UNDEFINED and discards, as before.

UNDEFINED -> UNDEFINED is not touched here: that is #600.

The barrier half of item 2 of the split proposed in #984, carried onto main
from Moriz82's integration branch (command_list.h, the emit change and the
command_list_test, replay_texture_barrier_test and d3d12_close_parity_test
cases), restricted to a defined LayoutBefore, with more cases and two GPU
tests added.

Tests:
- command_list_test, replay_texture_barrier_test (CPU): the recorded barrier;
  kept layouts over mips in two layouts, with the discard flag and without a
  tracker; an unused image released without a barrier or a zero-fill; the
  barrier from UNDEFINED that follows.
- d3d12_close_parity_test: three enhanced-barrier rows (116 cases, 85 match).
- vk_command_replay_test part K (GPU): a colour target, a depth buffer whose
  planes are in two layouts and an unused image released; the target used
  again and read back.
- d3d12_com_test (GPU, D3D12 list and queue): a depth buffer cleared,
  released, taken from UNDEFINED again, cleared and read back.

Co-authored-by: Moriz82 <72836413+Moriz82@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-24 11:20:21 -06:00
27781f7f9b d3d12: replay programmable sample positions (D3D-SAMPLE-POSITIONS) 2026-11-24 18:41:32 +05:00
3ce953ae80 d3d12: a depth clear outside [0, 1], NaN, or with no clear flag no longer fails the list
`CommandList::clear_depth_stencil` (`runtime/src/command_list.h`) refused a `ClearDepthStencilView` whose depth was
outside [0, 1] or NaN, and one whose `D3D12_CLEAR_FLAGS` were 0, so `Close` answered `E_INVALIDARG` and the whole
`ExecuteCommandLists` submission was dropped. Windows' D3D12 closes those lists: on WARP a `D32_FLOAT` target keeps
1.5, -0.5 and NaN exactly as given, and a clear that names no plane clears nothing. `d3d12_clear_test` now reads those
back on WARP and on the layer, and `d3d12_close_parity_test` measures the four `Close` verdicts.

A title that clears depth with a computed value (or wraps the clear in a flag mask that can be 0) lost that frame's
depth clear and, with it, the whole submission's work. The call is now recorded with the depth as given (a D16 target
still quantizes at replay) or, with no plane named, recorded as nothing.

d3d12_clear_test adds three read-back comparisons (1.5/-0.5, NaN, flags 0), command_list_test asserts the accepted
calls and the stored values, and the four close-parity rows move from the known-difference table to `match`.
2026-11-23 22:31:56 +01:00
1599683caf d3d12: reset predication in ClearState and align SetPredication / AtomicCopyBuffer validation (#6815)
Squash-merged after diff review of PR #6815
2026-11-23 12:32:05 -06:00
2c72b0d281 d3d12: validate DXR acceleration-structure prebuild and recording inputs (#6825)
Squash-merged after diff review of PR #6825 - d3d12: validate DXR acceleration-structure prebuild and recording inputs
2026-11-23 09:49:28 -06:00
0539527a1f Merge pull request #4038 from pmilewsskiedu-gif
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:10:40 -05:00
24e3b9683e test: assert legal no-op copies emit no recorded commands 2026-11-22 18:45:33 -05:00
af83574378 test: align command-list no-op copy expectations 2026-11-22 18:39:53 -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
b76c78acdb Runtime: a bundle's draws run with the parent's state, and what the bundle set stays on the parent
A draw recorded in a bundle took the bundle's own viewport, targets, root
arguments and buffers. A bundle cannot set a viewport, so every bundle draw
was dropped without an error, and nothing of the parent's state reached it.
Only the stencil reference and the blend factor were handed back.

Inside a bundle, state calls, draws and Dispatch are now kept as deferred
calls, and ExecuteBundle plays them on the parent through the members a
direct call uses, between the bundle's state-free commands, in order. A
draw sees the parent's state plus what the bundle set, and what the bundle
set stays on the parent, as measured on the PC runtime. This replaces the
stencil-reference and blend-factor carry-back fields. Trace lines are
written once, when the bundle records the call.

ClearUnorderedAccessView is refused in a bundle, like the other clears.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-22 23:06:44 +07:00
d7e1857c5d Merge origin/main into d3d90-castable-placed (resolve #1083 conflicts)
Both sides extended the same spots: the PR's castable-format flag and main's
R9G9B9E5-as-R32_UINT view emulation meet in bind_image (two extra defaulted
parameters), image_descriptor's view format (resource_format + castable list),
create_texture (TextureCreateInfo carries the VkImageFormatListCreateInfo the
castable list fills) and the device init (arena creation plus main's predication
configuration). Main's hardened CopyBuffer preparation and predicate capture
keep the PR's arena-buffer offsets; the PR's old emit-side offset math is
superseded by main's prepare-side buffer_offset handling.
2026-11-22 03:00:14 -08:00
9360ec9ec0 Runtime: predicate byte-granular CopyBufferRegion on the GPU
Build on the full 64-bit predicate snapshots from #856. Replay predicated buffer copies through a storage8 compute helper, retain descriptor batches through timeline completion, and reject missing capabilities or active statistics queries before submitting work.

Validate byte offsets, high predicate words, bounds, skipped destinations and pending descriptor lifetimes with CPU checks, 180 native WARP comparisons and 64 gated/reused GPU submissions. The existing OPTIONS19 host-capability mismatch also reproduces on base 4a36bb1; no tests are disabled.
2026-11-22 05:28:28 -04:00
Ryx
998368adbf Runtime: compute groundwork (FSSM shader lookup, Dispatch in the IR)
First pieces of D3D-3 (compute path), no pipelines wired up yet:
- shader_library.h: FSSM extraction from the DXBC container (DXIL, XDAT
  0x0D, XBCH, zlib), SHA-256, a minimal JSON reader and the
  spirv/index.json lookup by fssm_sha256. Self-contained inflate, no
  dependencies.
- IR Dispatch with user data captured at record time; replay binds the
  pipeline, pushes the 144-byte block (s0..s31, heap base, code base) and
  dispatches. Arena buffers get a buffer_offset that copies honour.
- Root signatures use main's model (runtime/src/root_signature.h); the docs
  say so.

Tests: shader_library_test (FIPS 180-4 vectors; stored, fixed and dynamic
deflate blocks; corrupt and truncated streams; FSSM from a synthetic
container) joins ctest; command_list_test covers dispatch recording.
2026-11-22 04:58:00 +01:00
7079108182 Runtime: query heaps on Vulkan (D3D-15)
CreateQueryHeap makes one VkQueryPool per heap: occlusion (OCCLUSION and
BINARY_OCCLUSION queries), timestamp and copy-queue timestamp, and pipeline
statistics (all eleven Vulkan counters, whose order is the field order of
D3D12_QUERY_DATA_PIPELINE_STATISTICS). Other heap types are logged and
refused with E_NOTIMPL.

BeginQuery, EndQuery and ResolveQueryData are recorded in the command-list
IR with D3D12's rules for the calls, and replayed as vkCmdResetQueryPool +
vkCmdBeginQuery/vkCmdEndQuery, vkCmdWriteTimestamp at BOTTOM_OF_PIPE and
vkCmdCopyQueryPoolResults (64-bit, WAIT). Heap types, index ranges and the
destination buffer are checked before anything is written. A query that was
never ended resolves to zeros instead of stalling the GPU on WAIT_BIT.
GetTimestampFrequency is 1e9 / timestampPeriod. The devices enable
occlusionQueryPrecise and pipelineStatisticsQuery where the GPU has them.

Overlapping queries of one kind (valid D3D12, one active query per type in
Vulkan) are refused as unsupported, and binary occlusion is not clamped to
0/1 yet; both are written down in docs/d3d12_vulkan.md section 4.6.

Tested on an RTX 5070 (driver 621.01) under VK_LAYER_KHRONOS_validation.
AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 21:30:47 -06:00
c7e450fc69 D3D-26: keep a null discard region apart from an explicit UINT_MAX count
A region with NumSubresources = UINT_MAX was recorded like a null region and
skipped the FirstSubresource check. DiscardResource now has a whole flag;
explicit ranges are checked in 64-bit at recording and replay. Tests at the
UINT_MAX boundary in command_list_test, part F and the COM device test.
Found by matheuskshn in review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 02:55:44 +00:00
e40bd6563e Merge main into D3D-26: predication and reserved resources on main
main added SetPredication (D3D-18) and reserved resources; both sides are
kept. The predication replay test took part E, so the D3D-26 test is now
part F. An atomic copy recorded under a predicate is counted with the
other copies that Vulkan's conditional rendering cannot skip, and
SetPredication, DiscardResource and the atomic copies are all refused in
a bundle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 01:29:19 +00:00
1eaca53672 Merge main into D3D-26: bundles and samplers on main; D3D-26 calls follow the bundle rules
main added ExecuteBundle (command_list.h, d3d12_com.cpp) and samplers
(vulkan_backend.h); both sides are kept. DiscardResource and the atomic
copies are now refused in a bundle, as D3D12 documents, and
WriteBufferImmediate is allowed there (d3d12_com_test covers all four).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 00:13:23 +00:00
be91840c07 Runtime: SetPredication on VK_EXT_conditional_rendering (D3D-18)
- command_list.h: a Predication command (offset 8-byte aligned, EQUAL_ZERO or
  NOT_EQUAL_ZERO; a null buffer turns it off), recorded by
  GraphicsCommandList::SetPredication.
- vulkan_replay.h: begin/end conditional rendering (INVERTED for NOT_EQUAL_ZERO),
  ended before a new predicate and at the end of the list. While predicated,
  whole-view clears go through vkCmdClearAttachments, which conditional rendering
  covers. New ReplayResult::invalid_predication; PreparedList::unpredicated_copies
  counts copies Vulkan cannot predicate.
- Device: VK_EXT_conditional_rendering and its feature enabled when present, and
  buffers created with VK_BUFFER_USAGE_CONDITIONAL_RENDERING_BIT_EXT; without it a
  predicated list is unsupported.
- Tests: command_list_test (recording rules), vk_command_replay_test part C (GPU).
- docs/d3d12_vulkan.md 4.7: what is done; copies and the 64-bit value are open.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 10:59:11 +11:00
fe12da7edd D3D-35: implement ExecuteBundle IR inlining and validation 2026-11-22 00:32:28 +01:00
19742b531a Runtime: DiscardResource, WriteBufferImmediate and atomic copies on Vulkan (D3D-26)
Three command-list IR commands, recorded through COM and replayed by
vulkan_replay.h:

- DiscardResource: an oldLayout = UNDEFINED barrier to the layout the
  tracker already has for each subresource. Buffers, rectangle discards,
  parts never used yet, untracked replays and one plane of a combined
  depth-stencil without separate layouts are no-ops.
- WriteBufferImmediate: a 4-byte vkCmdUpdateBuffer at the address,
  resolved at execution through ResourceBinding::va / buffer_offset and
  ReplayFunctions::buffer_at (the same fields and lookup as #291).
  MARKER_OUT waits for and sees every earlier write; MARKER_IN gets an
  execution-only ALL_COMMANDS dependency (Vulkan cannot say "started");
  DEFAULT is ordered by the application's barriers.
- AtomicCopyBufferUINT/UINT64: one vkCmdCopyBuffer region after a
  barrier that covers every earlier write, the dependent resources'
  included. Recording follows the debug layer's ATOMICCOPYBUFFER_* and
  WRITEBUFFERIMMEDIATE_* rules.

Tests: command_list_test (recording rules), vk_command_replay_test part D
(GPU readback of writes in all three modes, ordered atomic copies,
discards, and the lists that must be refused), and the COM path in
d3d12_vulkan_device_test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 23:16:54 +00:00
d27e4c5765 Runtime: ResolveSubresource and multisampled textures on Vulkan
There was no resolve, and a multisampled committed texture was refused.

- IR: ResolveSubresource (two different resources).
- Replay: ResolveSubresource is vkCmdResolveImage in the layouts copies
  use: a multisampled colour subresource into a single-sampled 2D one of
  the same size and format. Depth-stencil resolves and resolves between
  two formats of a typeless family stay unsupported. ResourceBinding gains
  samples: a multisampled texture copies only to its own sample count and
  has no footprint.
- Device: committed multisampled 2D textures (single-mip render targets or
  depth-stencils, when the GPU has the sample count for the format; the
  other shapes are E_INVALIDARG as in D3D12), and TEXTURE2DMS
  render-target and depth-stencil views.
- COM: ID3D12GraphicsCommandList::ResolveSubresource.

Tests: command_list_test (recording rules, and a copy with a z range);
vk_command_replay_test part C (a 4x resolve and the refused resolves and
multisampled copies; it also runs the volume copies that are already on
main at the Vulkan level, on Linux too: a 4x4x4 volume uploaded, copied as
a block and whole, read back, and the z ranges that must be refused);
d3d12_vulkan_device_test (a resolve through the Xbox-ABI proxy and the
refused shapes).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 16:34:22 -05:00
Ryx
99336386d1 Runtime: D3D12 copies on Vulkan (buffers, textures, uploads, BC) and GetCopyableFootprints
- IR: CopyBufferRegion, CopyTextureRegion (subresource or placed footprint,
  optional box) and CopyResource, with D3D12's call rules (512-byte footprint
  offsets, 256-byte pitches, non-empty boxes).
- Replay: vkCmdCopyBuffer / CopyBufferToImage / CopyImageToBuffer / CopyImage.
  Footprint pitch becomes bufferRowLength; BC extents stop at the mip edge;
  every range and buffer bound is checked before anything is written. Copies
  run in TRANSFER_SRC/DST, or in place in GENERAL for a COMMON texture
  (implicit promotion). 2D only.
- Device: buffers expose their VkBuffer; BC1-7 formats; textureCompressionBC
  enabled when present; GetCopyableFootprints for buffers and 2D textures.
  Compared with the PC runtime over 13 descriptions, which showed planar
  depth-stencil rows are padded to 512 bytes.
- Each submission ends with a barrier to the host so readback buffers hold the
  GPU's writes after the fence wait. BC textures are not zero-filled on first
  use (Vulkan cannot clear them; the validation layer caught the first try).

Tests: d3d12_vulkan_device_test now reads results back through D3D12
(CopyTextureRegion into a readback heap, Map) and adds an upload list: a
pattern into a texture, CopyResource into a COMMON texture, a boxed copy, a BC1
round trip and CopyBufferRegion. command_list_test covers the copy rules. All
GPU tests are clean under the Khronos validation layer; 6/6 ctest.
2026-11-21 20:33:34 +01:00
Ryx
6052bf0bd5 Runtime: rectangle clears, layout tracking, enhanced barriers, COM list/queue/fence
Closes the gaps left by the barrier/clear slice:

- Rectangle clears: ClearRenderTargetView/ClearDepthStencilView rects are
  recorded and replayed with vkCmdClearAttachments in a dynamic-rendering
  scope, clipped to the mip.
- LayoutTracker: the current Vulkan layout per image subresource, so barriers
  start from the real layout. This honours implicit promotion and decay
  (COMMON is GENERAL; simultaneous-access textures stay GENERAL) and, with
  separateDepthStencilLayouts, lets one depth/stencil plane be cleared or
  transitioned while the other stays in another state.
- Enhanced barriers (global, buffer, texture, split, discard) mapped to
  vkCmdPipelineBarrier2.
- vulkan_backend.h: VulkanContext, VulkanQueue (ExecuteCommandLists checks
  every list before writing any; Wait is attached to the next submission),
  VulkanFence on timeline semaphores.
- d3d12_com.cpp: ID3D12GraphicsCommandList7, ID3D12CommandQueue,
  ID3D12CommandAllocator and ID3D12Fence1. Unimplemented methods are stubs
  generated at build time from the SDK's d3d12.h (tools/gen_d3d12_stubs.py),
  so vtables follow the SDK order and nothing SDK-derived is checked in.

Tests: command_list_test and d3d12_state_map_test (every copied D3D12
constant checked against d3d12.h) in ctest; vk_command_replay_test and the new
d3d12_com_test on the GPU, clean under the Khronos validation layer.
2026-11-21 19:19:31 +01:00
Ryx
7f6e8f059d Runtime: D3D12 barriers and depth-stencil clears in the command-list IR
The IR (command_list.h, was clear_commands.h) now records transition, UAV and
aliasing barriers (split barriers record their end half) and full-view
ClearDepthStencilView next to ClearRenderTargetView.

vulkan_replay.h (was vulkan_clear.h) maps D3D12 resource states to Vulkan
layout/access/stage (section 4.3 table), decodes subresource indices including
depth/stencil planes, validates the whole list before emitting anything, and
wraps clears in a layout round trip so images stay in their D3D12 state. The
caller no longer manages layouts by hand.

Tests: command_list_test (recording rules), d3d12_state_map_test (state table,
subresource decoding, constants checked against d3d12.h; needs Vulkan headers
only) and vk_command_replay_test (GPU readback of colour, depth and stencil;
LEONIDA_VK_VALIDATION=1 runs it under the Khronos validation layer).
2026-11-21 18:58:48 +01:00