Skip to content

feat(runtime): add D3D12 1D texture views and test - #1916

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
cobalt-pebble-804:feat/d3d12-texture1d
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
cobalt-pebble-804:feat/d3d12-texture1d

Conversation

@cobalt-pebble-804

Copy link
Copy Markdown
Contributor

Description

Implements D3D12_RESOURCE_DIMENSION_TEXTURE1D (1D and 1DArray) view handling and adds a dedicated GPU round-trip test:

  • Adds 1D and 1DArray view support in CreateRenderTargetView, CreateDepthStencilView, CreateShaderResourceView, and CreateUnorderedAccessView (including desc == nullptr fallback).
  • Adds d3d12_texture1d_test covering TEXTURE1D/TEXTURE1DARRAY SRV/UAV views and a CopyTextureRegion upload/readback GPU round-trip.

Architecture / Subsystem Affected

  • runtime/shims/d3d12_vulkan_device.cpp (CreateRenderTargetView, CreateDepthStencilView, CreateShaderResourceView, CreateUnorderedAccessView)
  • runtime/test/d3d12_texture1d_test.cpp
  • runtime/CMakeLists.txt

Verification & Testing

  • Tested locally on: Windows 10/11 x64, NVIDIA GeForce RTX 2060, Vulkan SDK 1.4.363.0
  • d3d12_texture1d_test.exe (LEONIDA_VK_VALIDATION=1): PASS (1D/1DArray SRV, UAV + CopyTextureRegion round-trip)

Checklist

  • Code adheres to the repository's style guidelines.
  • Self-review performed.
  • New/existing tests pass locally with LEONIDA_VK_VALIDATION=1.

@Vonsek Vonsek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On 5ce3ad83, the new SRV/UAV branches still reach a rejection in image_descriptor (around line 2630). The fixture uses a 1D resource with four layers. For its explicit image_1d views, the predicate rejects DepthOrArraySize != 1. For the image_1d_array views it falls through to an expected resource dimension of TEXTURE2D, so it rejects those too. write_image_descriptor returns before encoding or writing the slot. In addition, the bindless image dimension switch/table currently has no 1D-array entry.

The upload/readback invokes CopyTextureRegion on the resource and never reads or binds any of those four slots. Its byte check can therefore pass while none of the new SRV/UAV cases produces a usable descriptor. Could the test assert the encoded T# and a nonzero bindless lookup, or use a shader to read or write a nonzero mip/layer through a view? This is a source review of the exact head, without a local GPU run.

There is also direct overlap with #1851 (explicit 1D SRV of array slice 0, including the missing descriptor guard) and #773 (1D/1D-array UAV binding and shader tests). Please coordinate those parts with the existing PRs.

AI-assisted.

@Serrambi Serrambi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static review of 5ce3ad83: request changes — all four 1D views tested in the new test silently fail into null descriptors, RTV/DSV 1D paths are untested, and this overlaps with #1851.

  1. image_descriptor() (runtime/shims/d3d12_vulkan_device.cpp) was not updated:
    • line still only checks ImageType::image_1d, so image_1d_array takes the TEXTURE2D branch and fails desc.Dimension != dimension.
    • It also still checks (line && desc.DepthOrArraySize != 1) (instead of view.layer_count != 1, as addressed in #1851), so an explicit TEXTURE1D SRV/UAV on a 1D array fails too.
  2. False pass in runtime/test/d3d12_texture1d_test.cpp:
    • The test creates tex1d with DepthOrArraySize = 4, so srv1d, srv1d_arr, uav1d, and uav1d_arr all fail validation in image_descriptor() and write zeroed/null descriptors — yet the test never inspects descriptor words or bindless_hash_lookup, only CopyTextureRegion.
    • rtv_heap/dsv_heap and rtv_inc/dsv_inc/rtv_cpu/dsv_cpu are created and never used (CreateRenderTargetView and CreateDepthStencilView are never called, leaving unused locals under /W4), and CreateRenderTargetView / CreateDepthStencilView 1D branches lack dimension/array bounds validation and replay coverage.
  3. runtime/CMakeLists.txt placement and test properties:
    • d3d12_texture1d_test is inserted unindented between add_test(NAME d3d12_vulkan_device ...) and set_tests_properties(d3d12_vulkan_device ...), and lacks SKIP_RETURN_CODE 77.
  4. Overlap with #1851: touches the same CreateShaderResourceView TEXTURE1D block as #1851; please rebase onto #1851 (or coordinate scope) once #1851 lands.

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional gap beyond the existing 1D-array findings: a compatible typed RTV for a R8G8B8A8_TYPELESS 1D resource is nulled by the typeless-RGBA8 special case. That branch accepts only TEXTURE2D/TEXTURE2DARRAY and requires rd.Dimension == TEXTURE2D, even though D3D12 defines TEXTURE1D and TEXTURE1DARRAY RTV dimensions and allows a typed member of a typeless format family when the resource has ALLOW_RENDER_TARGET.

Please include the 1D/1D-array dimensions in this path (with the same mip/slice bounds checks) and cover at least one valid typeless-to-typed 1D RTV. References: https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_rtv_dimension and https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_resource_flags

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

In 348a0f9f, the dimension check now lets array views through to T# encoding. The remaining gap is that bind_image still returns false for image_1d_array at the set-0 dimension switch. For a non-MSAA view, write_image_descriptor still copies the T# into the slot after that registration failure. The new first-four-words check therefore cannot distinguish this from a usable binding.

I confirmed the distinction with a CPU-only probe on Windows/MSVC: encoding a four-layer, two-mip 1D-array T# passes the new nonzero condition and decodes as a four-layer 1D array, independently of any bindless registration. Adding the full T# lookup through rt::d3d12::bindless_hash_lookup or an actual shader access would catch the remaining failure. The fixture also now uses a separate single-layer resource for its non-array views, so it leaves the slice-0 behavior to #1851.

AI-assisted.

@Serrambi Serrambi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked the updated diff (348a0f9f):

  • image_descriptor() now recognizes image_1d_array, and d3d12_texture1d_test.cpp separates the single-layer resource and checks that the 4 descriptor slots are non-zero.
  • However, a few items from the earlier reviews still remain open:
    1. (view.type == g::ImageType::image_1d && desc.DepthOrArraySize != 1) in image_descriptor() still conflicts with #1851 (explicit D3D12_SRV_DIMENSION_TEXTURE1D on a 1D array).
    2. As @Vonsek noted, bind_image() still lacks an image_1d_array case in the bindless set-0 switch, so bindless_hash_lookup isn't exercised yet.
    3. rtv_heap/dsv_heap and rtv_inc/dsv_inc/rtv_cpu/dsv_cpu in d3d12_texture1d_test.cpp are still unused (so the new 1D RTV/DSV branches — and typeless 1D RTVs noted by @Flyander — remain untested).
    4. runtime/CMakeLists.txt still splits add_test(NAME d3d12_vulkan_device ...) from its set_tests_properties(d3d12_vulkan_device ...) and omits SKIP_RETURN_CODE 77 on d3d12_texture1d.

@Serrambi Serrambi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed 71a93120 and tested on NVIDIA GeForce RTX 5070 Ti (driver 610.88, Windows 11 Pro, MSVC 19.50.35719.0, Windows SDK 10.0.26100.0, Vulkan SDK 1.4.363.0): approve (all items from my earlier review are addressed).

Code review (runtime/shims/d3d12_vulkan_device.cpp, runtime/test/d3d12_texture1d_test.cpp, runtime/CMakeLists.txt)

  • Rebased cleanly onto main (#1851), keeping explicit TEXTURE1D SRVs on 1D arrays working while scoping CreateUnorderedAccessView to TEXTURE1D (layer_count = 1) and leaving default (nullptr) 1D-array SRV/UAV calls as null descriptors.
  • line_target_view() validates Dimension == TEXTURE1D, mip, first_layer, and remaining layer count safely without overflow, and the typeless/castable RGBA8 RTV path now allows D3D12_RTV_DIMENSION_TEXTURE1D and TEXTURE1DARRAY (plain_1d || array_1d).
  • d3d12_texture1d_test.cpp compiles cleanly under /W4, verifies g::decode() and rt::d3d12::bindless_hash_lookup != 0 on all 6 valid 1D SRV/UAV descriptors plus null-descriptor writes (0x77 pre-fill) on 1D arrays, and checks out-of-bounds 1D RTV/DSV nulling (CMakeLists.txt placement and SKIP_RETURN_CODE 77 are fixed too).
  • Two minor non-blocking notes:
    1. The test checks out-of-bounds RTV/DSV rejection (without pre-filling the target slots), rather than exercising a valid/typeless 1D CreateRenderTargetView/CreateDepthStencilView draw/clear end-to-end.
    2. The final PASS: log still says 1D/1DArray SRV, UAV even though TEXTURE1DARRAY SRV/UAV cases were removed in this revision.

Checks on 71a93120

  • d3d12_texture1d_test.exe (LEONIDA_VK_VALIDATION=1): passed (EXIT=0, 0 Vulkan validation errors)
  • d3d12_descriptor_test.exe (LEONIDA_VK_VALIDATION=1): passed (EXIT=0, 0 validation errors)
  • d3d12_typeless_rtv_test.exe (LEONIDA_VK_VALIDATION=1): passed (EXIT=0, 1730 WARP readbacks matched, 0 validation errors)
  • ctest --test-dir runtime/build --output-on-failure -R "^(d3d12_texture1d|d3d12_descriptor|d3d12_typeless_rtv)$": 3/3 passed

@Bj0rnis

Bj0rnis commented Nov 22, 2026

Copy link
Copy Markdown

Tested 71a93120 on NVIDIA GeForce RTX 5070 Ti (Blackwell), NVIDIA 621.24 (Vulkan 1.4.357) and AMD Radeon(TM) Graphics (iGPU, AMD 2026.04.17, Vulkan 1.4.315), Windows 11: pass

Built with MSVC 19.44 / Ninja / Windows SDK 10.0.26100.0 / Vulkan SDK 1.4.363.0 (scripts\build_runtime.ps1), run with Khronos Vulkan validation enabled (LEONIDA_VK_VALIDATION=1, DISABLE_VULKAN_OBS_CAPTURE=1):

  • RTX 5070 Ti: ctest -R "^(d3d12_texture1d|d3d12_descriptor|d3d12_vulkan_device)$" — 3/3 passed, 0 Vulkan validation errors (d3d12_texture1d verified all 6 1D SRV/UAV T# encodings + bindless_hash_lookup, the null-descriptor 1DArray defaults, out-of-bounds RTV/DSV rejection, and the CopyTextureRegion round-trip).
  • AMD Radeon iGPU (LEONIDA_VK_DEVICE=AMD): ctest -R "^(d3d12_texture1d|d3d12_descriptor)$" — 2/2 passed, 0 Vulkan validation errors.

AI-assisted (Antigravity / Gemini); no game files used.

@ItsNotRexed
ItsNotRexed merged commit 72b6218 into ItsNotRexed:main Nov 22, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants