Commit Graph

1118 Commits

Author SHA1 Message Date
6ae02af006 Merge main into d3d-25-uav-clears
Conflicts: main moved texture create info into texture_create_info (the UAV
attachment usage now goes there, so placed-resource sizing agrees) and edited
the same docs paragraphs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 23:33:19 +00:00
467b1d1ff9 runtime: ClearUnorderedAccessViewUint/Float on the Vulkan device (D3D-25)
The CPU handle's slot is read while recording as the GFX10 T#/V# a shader
would load (docs section 3.4), so the clear works with whichever view
creation lands (#157, #328, #334) and with game-built descriptors.

- Buffers: vkCmdFillBuffer for elements up to 4 bytes, with the unaligned
  ends copied from the filled middle; 8/16-byte elements are written with
  vkCmdUpdateBuffer and doubled with copies. Rects are element ranges.
- Textures: vkCmdClearColorImage for whole views, vkCmdClearAttachments
  for rects (UAV textures also get COLOR_ATTACHMENT usage when the format
  supports it), in place in GENERAL; mip and layer range from the T#.
- Values follow D3D's Uint (raw low bits) and Float (converting) rules,
  encoded in the view's format and cleared into the image as the value
  that decodes those bytes in the image's own format (typeless resources).
- d3d12_uav_clear_test: hand-computed conversion checks, then raw,
  structured and typed buffers and 2D, array and volume textures cleared
  and read back through D3D12; refusals at record and replay.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 23:29:32 +00:00
438e144270 Runtime: build with MSVC; the descriptor test shows a missed sampler lookup
Two findings from the review of #328, on MSVC 19.44 and an RTX 5080.

- bind_image did not compile with MSVC (C2397): the view's aspect, picked
  between two VkImageAspectFlagBits values, went into a VkImageAspectFlags
  field in braces. MSVC's enums are ints, so that is a narrowing
  conversion there; GCC and clang give the enum an unsigned type and accept
  it. The value is cast now.
- d3d12_descriptor_test passed with the sampler index forced to 0, because
  its point, clamping sampler and the fallback sampler read the same
  texels. The test's sampler now wraps in U and the shader samples one
  tile to the right: the right sampler gives the texture, the fallback its
  right edge. With the index forced to 0 the test fails (texel 0 reads
  224, 0, 135, 255 instead of 0, 0, 128, 255).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 18:28:13 -05:00
bc14565c45 Runtime: texture views and samplers go into the bindless set (M2, the device's part)
The device now keeps set 0 of the translated shaders and puts into it what
views and samplers name. No pipeline binds the set yet: that comes with
the compute path. Until then rt::d3d12::bindless_set / bindless_set_layout
hand it out.

- Device: CreateShaderResourceView and CreateUnorderedAccessView of
  textures write a T# into the slot, CreateSampler an S#
  (gfx10_descriptors.h); each makes sure set 0 has the view or sampler and
  the hash table has the key. The key is the descriptor's bytes, so a
  copied descriptor needs nothing more. A view that cannot be shown (a
  volume, a multisampled texture, the stencil plane, a range past the
  texture) leaves a null descriptor, which finds the fallback. A texture
  is named by an address of its own above 4 GiB that nothing dereferences;
  its keys are erased and its indices freed when it is destroyed.
- VulkanDeviceInfo::bindless says the Vulkan device has the features; the
  standalone device and the test helper enable them where the GPU has
  them, with samplerAnisotropy and samplerMirrorClampToEdge.
- Every ExecuteCommandLists flushes the set before its commands are
  written (VulkanContext::set_bindless_prepare).
- Layouts: a bindless descriptor has one image layout, but D3D12 samples a
  texture both in a shader-resource state and while promoted from COMMON
  (GENERAL here). With the set, a texture's shader-resource states use
  GENERAL too (ResourceBinding::sampled_in_general). This follows from the
  Vulkan rule for descriptor layouts; no test can see it broken, since the
  validation layer does not follow dynamic indices into runtime arrays.

Not done, and listed in docs/d3d12_vulkan.md: buffer and constant-buffer
views, 1D/3D/multisampled and stencil views, descriptors the game writes
itself, static samplers and shaders' literal S#s, and holding back a flush
that moves table entries while earlier command lists still run.

Test: d3d12_descriptor_test, through the Xbox-ABI proxy. It decodes what
the slots hold (a view of an uploaded 8x8 texture, a sampler, a BGRA cube
view with a component mapping, an unordered-access view, null
descriptors). Then a compute shader (test/glsl/cs_sample.comp, compiled
with glslangValidator where it is found) is handed a slot's T# and the
sampler's S#, looks them up in the hash table as a translated shader does
and samples; the test creates that pipeline in Vulkan and binds the
device's set. It reads the texture through the view's own slot and
through a copy of it, and gets the fallback from a slot of bytes no view
was made for and, once the texture is destroyed, from the view's own
bytes. Without the table insert, or without the removal at destruction,
the test fails. The test no longer compiles d3d12_xs_device.cpp itself:
the COM library has it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 18:28:13 -05:00
fbffbce383 Runtime: preserve explicit RGBA8 typeless RTV formats for clears 2026-11-21 19:26:08 -04:00
03ff5f4bd8 Merge pull request #338 from mrb-eel 2026-11-21 18:08:03 -05:00
489258fda5 Resolve colour MSAA regions into destination offsets 2026-11-22 00:05:17 +01:00
257e3856cc Runtime: GetResourceAllocationInfo on the Vulkan device (D3D-23)
GetResourceAllocationInfo, GetResourceAllocationInfo1 and
GetResourceAllocationInfo2 were generated stubs. Buffers take their width
rounded up to 64 KiB. A texture's size is what its VkImage needs
(vkGetDeviceImageMemoryRequirements, or a throwaway image without it),
rounded up to its D3D12 alignment: 64 KiB, 4 MiB with MSAA, or the small
alignment the description asks for. A 4 KiB request that doesn't qualify
is invalid, as on the PC runtime; the MSAA 64 KiB one has no size limit
there. Texture creation and these queries share one VkImageCreateInfo.

d3d12_vulkan_device_test compares buffer sizes, alignments and invalid
descriptions with the host PC runtime, and checks the per-resource layout
of the Device4/Device8 variants.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 09:55:11 +11:00
cc1f4d3597 Merge pull request #230 from Jan Trencansky
# Conflicts:
#	docs/d3d12_vulkan.md
2026-11-21 17:09:46 -05:00
5773165b67 Merge pull request #241 from 0xTehuti 2026-11-21 17:07:42 -05:00
b80e3baddf Merge pull request #228 from Jan Trencansky 2026-11-21 17:07:41 -05:00
d5eabdad6a Runtime: CopyDescriptors and CopyDescriptorsSimple on the Vulkan device
A descriptor is the bytes of its heap slot (a TargetView in RTV and DSV
heaps, otherwise what the shader loads), so both are byte copies.
CopyDescriptors walks the destination and source range lists together,
one descriptor at a time; null size arrays mean one descriptor per range,
and whichever side runs out first ends the copy.

Test: d3d12_descriptor_test, through the Xbox-ABI proxy, checks the slots'
bytes for one run, range lists of different shapes on each side, null
size arrays, a destination longer than its source, and null arguments.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 16:56:56 -05:00
c33c216cbd Runtime: implement CheckFeatureSupport for format support, VA limits, and options (D3D-11) 2026-11-21 22:52:10 +01:00
4c2f143d83 Runtime: check maxPushConstantsSize at device creation and flag uniform-buffer fallback (D3D-14) 2026-11-21 22:38:22 +01: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
52e1ac3cd7 Support mipmapped 3D texture transfers on the Vulkan device 2026-11-21 21:24:04 +01: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
40f6399088 Runtime: Vulkan-backed ID3D12Device behind the Xbox-ABI proxy
- d3d12_vulkan_device.cpp: an ID3D12Device11 (PC ABI) the device proxy
  forwards to. Creates queues, allocators, command lists (incl.
  CreateCommandList1), fences, descriptor heaps (32-byte slots; RTV/DSV hold
  TargetViews), render-target and depth-stencil views, committed buffers
  (upload/readback mapped and zeroed) and 2D textures in the common formats,
  and answers feature-level and architecture queries. Everything else is a
  generated stub that logs once.
- First use of a new texture zero-fills it and moves it to the layout the
  command expects (vulkan_replay.h initialize), as D3D12 committed resources
  start zeroed; no submission at creation. CREATE_NOT_ZEROED skips the fill.
- Children hold the proxy, so GetDevice returns the Xbox-ABI object; COM base
  classes moved to d3d12_com_object.h. D3D12 queues share one VkQueue behind a
  submit lock.
- D3D12XboxCreateDevice: LEONIDA_D3D12=vulkan creates the Vulkan device on its
  own instance and wraps it in the same proxy (gta6rt built with the Vulkan
  SDK and Python 3); the host PC device stays the default.

Tests: d3d12_vulkan_device_test calls everything through the proxy (heaps via
slot 14 with RAX start handles, a render target via slot 76 with the Xbox
layout word) and reads colour, depth, stencil and a never-written texture
back; it also runs the standalone device. Clean under the Khronos validation
layer with the other GPU tests; all 6 ctest tests pass.
2026-11-21 20:22:20 +01:00