Skip to content

Runtime: honor minimum LOD on sampled 2D array views - #1015

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
Vonsek:codex/array-min-lod-current
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
Vonsek:codex/array-min-lod-current

Conversation

@Vonsek

@Vonsek Vonsek commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as sampled Texture2DArray SRV minimum LOD.

Replacement for #974, replayed directly on 43d4703 following the merge-round request.

What and why

A D3D12 Texture2DArray SRV encoded ResourceMinLODClamp in its T#, but the sampled Vulkan view ignored it. A draw or dispatch requesting LOD zero could see a more detailed mip than the application allowed. Single-sampled colour 2D-array views now use the resource-relative minimum LOD handling that #829 added for 2D. This keeps the array layer range, sampler and component mapping in place and uses the existing fallback when an effective in-range clamp needs an unavailable feature.

Fractional minima on Intel. The UHD 770 and Xe-LPG were observed to use the integer-floor alternative permitted by Vulkan for the existing 2D view. For the new Xe-LPG array case, 1.75 gave mip 1 on all 64 texels where native RTX/Radeon/WARP give mip 2. The test retains the fractional assertions and also checks an effective 2.0 minimum. See the Intel A/B and sampling specification.

Tested

Added distinct colours to a three-layer, three-mip RGBA8 array in d3d12_descriptor_test. The view starts at resource mip 1 and layer 1. Through set 0, one sampler requests LOD 0 from both exposed layers. On Windows 11 build 26200, the RTX 5080 (32.0.16.1692) and AMD Radeon Graphics (32.0.21045.16010) gave these RGBA8 results:

Resource clamp Layer 1 Layer 2
1.0 (100,100,64,255) (160,100,64,255)
1.75 (100,180,64,255) (160,180,64,255)
2.0 (100,180,64,255) (160,180,64,255)
2.25, above the view's last mip (0,0,0,0) (0,0,0,0)
  • Red on 43d4703 with the new test: both GPUs returned (100,100,64,255) for the first layer at 1.75. The independent native D3D12 reference returned (100,180,64,255).
  • After the change: 256/256 samples per GPU matched the CPU expectations with core and synchronization validation enabled. A separate HLSL Texture2DArray.SampleLevel readback gave the same 256/256 on native D3D12 RTX, Radeon and WARP.
  • With the wrapped device's minimum-LOD capability flag deliberately cleared, the in-range 1.75 and 2.0 views used the fallback. The 1.0 and empty 2.25 controls retained their expected results (256/256 on RTX).
  • d3d12_descriptor_test passed on both Vulkan adapters and ctest --no-tests=error -R '^d3d12_vulkan_device$' passed on RTX.

The combined descriptor test also checked 256 volume-view samples and 448 floating-point MSAA samples per GPU, plus the integer multisample views and their miss controls.

Checklist

  • No game data, keys or decryption, including in logs or reports.
  • Updated the runtime view contract in docs/d3d12_vulkan.md. This change uses the existing translator bindings.

AI-assisted contribution using OpenAI Codex.

A Texture2DArray SRV encodes the clamp in its image descriptor. Forward it to Vulkan so sampling keeps the requested mip and array layer.
@kapitche

kapitche commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Tested a69977e on Windows 11 with two GPUs on one machine (MSVC 14.51, full shader toolchain):

RTX 4080 SUPER (32.0.16.1714) Intel UHD 770 (32.0.101.6129)
ctest 47/47 45/47
d3d12_descriptor pass FAIL: minimum LOD view 1 texel 0: got 0 0 128 255, expected 16 160 64 255
d3d12_vulkan_device pass fails on main too (OPTIONS1 host comparison, #962)

Correction to my first version of this comment: that minimum LOD view case is already on main (d3d12_descriptor_test.cpp, registered by #883), and #1017's unrelated branch fails it the same way on this iGPU. So it's a main problem on Intel, not something this PR introduced. Both drivers expose VK_EXT_image_view_min_lod with minLod = true, and the Intel run never logs 2D SRV requires VK_EXT_image_view_min_lod, so the extension path is taken and Intel still samples a different mip. I've filed it in #634. With that and #962 set aside, this PR passes on both GPUs.

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

On replacement head a69977e, the Windows check stops at “Verify the descriptor test shader.” The same step fails on parent main 43d4703. The workflow checks runtime/build/generated/cs_sample.spv; current CMake names the output generated/LEONIDA_TEST_CS_SAMPLE_SPV.spv. All six shader outputs were present in my fresh build, and the descriptor test ran on both GPUs including the array, volume and MSAA pixel checks. Wine is skipped downstream of the Windows job.

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

@kapitche, thanks for the exact colors. I traced minimum LOD view 1 texel 0 to the existing single-layer Texture2D case. It is view {firstMip=0, mipCount=3, clamp=0.75}; (0,0,128,255) is mip 0 at the first texel, and (16,160,64,255) is mip 1. The same assertion and expected color are present on parent 43d4703. This assertion returns before the new array dispatch, whose diagnostic starts with array LOD. Your result establishes the Intel 2D readback; the array result is still open.

Could you run d3d12_descriptor_test.exe on both 43d4703 and a69977e on the same Intel ICD, first with identical unmodified sampler/device settings? If both stop at that 2D pixel, one diagnostic build of a69977e can also report the array result: move the complete SampleKeys array_keys block through its array minimum LOD summary immediately before SampleKeys lod_keys. That preserves both groups’ assertions, descriptor contents and sampler. An array pass will print 192 matched samples before the original 2D check. An array failure reports the clamp, layer and both RGBA values. That comparison will tell us which path to investigate before adjusting any sampler state.

@Parakeet-Wheat

Copy link
Copy Markdown
Contributor

Tested a69977e on an NVIDIA GeForce RTX 3070, driver 610.88, Windows 11 (26300), MSVC 19.44 (VS generator, RelWithDebInfo), Vulkan SDK 1.4.363.0, with LEONIDA_VK_VALIDATION=1: pass

  • Build passes with 0 warnings (tests: rename the multisample levels in d3d12_descriptor_test (C4456) #909 and d3d12_vulkan_device_test: the predication block's query heap desc no longer hides heap_desc (C4456) #952 are in now). ctest (validation on): 41/41.
  • d3d12_descriptor_test: exit 0, 0 validation messages, array minimum LOD: 192 samples matched across two layers and three views. The 3070 has VK_EXT_image_view_min_lod, so the 1.75 view took the extension path rather than the fallback. Volume SRVs: 0 of 256 differ. For the Intel question above: the existing 2D minimum LOD view checks, which run before the array group, also pass here, so the 0.75 case kapitche hit on the UHD 770 samples mip 1 as expected on Ampere.
  • vk_command_replay_test A to F and d3d12_com_test: pass, no validation messages.
  • d3d12_vulkan_device_test: exit 0, with one validation error that doesn't come from this PR: VUID-vkCreateDevice-ppEnabledExtensionNames-01387, "Missing extension required to enable device extension VK_KHR_swapchain: VK_KHR_surface". That's main's device creation (since 9363490, the DXGI swapchain shim), which enables VK_KHR_swapchain whenever the GPU offers it without checking that the instance it runs on enabled VK_KHR_surface. This PR doesn't touch device creation.

Code read: the change is right. Widening the clamp condition to image_2d_array reuses #829's resource-relative handling, and the new cs_sample.comp branch picks out 2D-array T#s by type 13. Two small follow-ups, neither for this PR:

  • TextureCube and TextureCubeArray SRVs also read ResourceMinLODClamp into the view (around lines 1919 and 1927), but the Vulkan view still ignores it there, and without a log, unlike the volume case, which logs and falls back. VK_EXT_image_view_min_lod applies to cube views too, so adding cube to the same condition (with a test face) would close that gap.
  • The log_once message for a missing extension still says "2D SRV requires VK_EXT_image_view_min_lod", though it now covers arrays too.

AI-assisted (Claude Code).

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

There is a spec detail that changes how to interpret the Intel readback. Vulkan’s image-level selection explicitly allows either the floating-point image-view minimum (preferred) or its integer variant (alternative). The integer variant is floor(minLod). With explicit LOD 0 and nearest mip filtering, a 0.75 minimum therefore permits mip 0 on the integer path, while the floating-point path gives mip 1. Likewise an array view starting at mip 1 with minimum 1.75 can give mip 1 or mip 2. Exposing the extension alone does not distinguish these implementations. Vulkan image-level selection · Definition of the image-view minimum

The D3D12 compatibility question is still real. If available with the Intel A/B, a native D3D12 SampleLevel(0) at the same 0.75/1.75 minima can establish that adapter's D3D12 result. An integer minimum of 1.0 on the three-mip 2D view distinguishes integer-floor behavior from the view minimum being ignored entirely. I’ll keep the D3D12 reference and the Vulkan-only possibilities separate in interpreting the results.

@BACONMANXDGOD

Copy link
Copy Markdown
Contributor

Tested a69977e on an RTX 5070 Ti Laptop (617.42) and an Intel Arrow Lake Xe-LPG iGPU (Windows 32.0.101.8132). Windows 11 26200, MSVC 19.44, Vulkan SDK 1.4.363, LEONIDA_VK_VALIDATION=1.

  • RTX: pass. d3d12_descriptor_test exits 0, including array minimum LOD: 192 samples matched across two layers and three views.
  • Intel: the test stops before your new case, at the existing 2D minimum LOD view 1 check (Runtime: apply the minimum LOD of sampled 2D colour views #829). That check fails the same way on main 43d4703 (got 0 0 128 255, expected 16 160 64 255). It's @kapitche's finding: Intel applies only the integer part of the view's minLod (Coordinating who works on what (3) (moved to #1006) #634 (comment)).
  • With both checks patched locally to report instead of stopping, your array views on Intel:
    • clamps 1.0 and 2.25 match on both layers;
    • 1.75 returns mip 1 instead of mip 2 on all 64 samples: layer 1 100,100,64 (want 100,180,64), layer 2 160,100,64 (want 160,180,64).
    • The 2D views fail the same way, one mip lower, on exactly views 1 (0.75) and 2 (1.75), 64 texels each.

So on Intel the new 2D-array path behaves exactly like main's 2D path. It's the driver's fractional-minLod behaviour, not something this PR introduces. It also adds a second Intel generation and a newer driver (Xe-LPG, 101.8132) to the UHD 770 (101.6129) result: the same views fail with the same values.

No game files. AI-assisted (Claude Code).

An integer image-view minimum is permitted by Vulkan and was observed on Intel. Check an effective integer minimum separately and report both view groups before returning a mismatch.
@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for testing both revisions and running the two view groups independently. Commit 326e849 keeps both D3D12 fractional expectations, prints the mismatch count for each failing view, and lets all groups run before returning failure. It adds a 2.0 minimum on a view starting at mip 1. That integer case must actually advance to mip 2, distinguishing the extension’s integer-floor alternative from a completely ignored minimum. The previous 1.0 case is the control at the first exposed mip.

With the new fixture against unchanged 43d4703, both of my GPUs missed 64/64 samples for each of 1.75, 2.0 and the empty 2.25 view. On this PR's runtime all 256/256 matched on both RTX 5080 and Radeon, as did native D3D12 on both and WARP. Simulating a device without the feature gave the expected fallback on the two effective in-range clamps.

@BACONMANXDGOD or @kapitche, an unmodified run of this head on Intel would establish whether the 2.0 case advances on both layers. The previous Xe-LPG run already establishes 64/64 mismatches at 1.75. The documentation now records that limitation.

@quackottu quackottu 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.

Tested 326e849 on NVIDIA GeForce RTX 5070, driver 621.24, Windows 11 Pro (26300), VS 2022 Build Tools, Vulkan SDK 1.4.363.0, with LEONIDA_VK_VALIDATION=1 and LEONIDA_D3D12=vulkan: pass

  • ctest -C RelWithDebInfo: 100% tests passed, 0 tests failed out of 47
  • every test program in the build passes. d3d12_vulkan_device_test and d3d12_fence_timing_test each report 3 validation errors (VUID-vkCreateDevice-ppEnabledExtensionNames-01387), but main 43d4703 shows the same: the standalone instance drops VK_KHR_surface, which #1027 fixes. Not from this PR.
  • d3d12_clear_test differs from WARP exactly as on main (#521).

Implicit Vulkan layers (overlays) were off through an empty VK_IMPLICIT_LAYER_PATH.

ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
@ItsJaved

Copy link
Copy Markdown
Contributor

Tested 326e849 on Windows 11 (MSVC 19.51.36247.0, Vulkan SDK 1.4.363.0, VK_LOADER_LAYERS_DISABLE=~implicit~, LEONIDA_VK_VALIDATION=1) on two GPUs in one machine:

  • NVIDIA GeForce RTX 5090 (0x10de:0x2b85, NVIDIA 621.24 / 32.0.16.2124, Vulkan 1.4.357): pass — array minimum LOD: 256/256 samples matched across two layers and four views, 0 validation errors.
  • AMD Radeon(TM) Graphics (0x1002:0x164e, RDNA2 iGPU, AMD 23.20.44 / 31.0.22044.1, Vulkan 1.3.262): pass — array minimum LOD: 256/256 samples matched across two layers and four views, 0 validation errors.

No game files. AI-assisted.

@ItsNotRexed
ItsNotRexed merged commit d494e10 into ItsNotRexed:main Nov 22, 2026
9 of 10 checks passed
@BACONMANXDGOD

Copy link
Copy Markdown
Contributor

@Vonsek, here is the unmodified run you asked for. Current main c63773d (which has 326e849), Intel Arrow Lake Xe-LPG iGPU (Windows 32.0.101.8132), LEONIDA_VK_VALIDATION=1:

  • The 2.0 case advances. array minimum LOD: 192/256 samples matched across two layers and four views: 1.0, 2.0 and 2.25 match on both layers. 1.75 gives 64/64 mismatched (mip 1: 100,100,64 where 100,180,64 is expected).
  • The 2D views 0.75 and 1.75 fail as before (mip 0 and mip 1).
  • RTX 5070 Ti: 256/256.

So Intel takes the spec's integer alternative, minLod_imageView = minLodInteger_imageView = floor(minLod), listed as "alternative" to minLodFloat in Image Level(s) Selection (d' = max(level_base + clamp(λ, 0, q), minLod_imageView)). It is not ignoring the minimum.

Two facts for whether this can be worked around:

  • Intel reports shaderResourceMinLod = false (RTX: true). So the SPIR-V MinLod operand, which clamps λ itself and has no integer alternative, isn't available there.
  • What a flooring device can still do is take the view minimum rounded to the nearest integer instead of its fraction (0.75 → 1, 1.75 → 2, 0.25 → 0).
    • With nearest-mip filtering that's exact, apart from the .5 tie convention, since nearest(max(λ, c)) = max(nearest(λ), nearest(c)).
    • With linear-mip filtering it is off by at most half a mip, where the floor can be off by up to a whole one.
    • Telling which devices floor needs a one-time probe at device creation, or a vendor check. Both Intel parts so far floor (UHD 770 101.6129, Xe-LPG 101.8132).

Do you want that in the 2D/2D-array path? It's your code, so I'd rather ask first. If yes, I can write it and test it on this Xe-LPG. No game files. AI-assisted (Claude Code).

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.

7 participants