Repository navigation
Runtime: variable rate shading on Vulkan, RSSetShadingRate and the shading-rate image (D3D-32) - #469
ezwinxdlmao wants to merge 3 commits into
Conversation
|
Tested c914558 on RTX 4090 (driver 621.14), Windows 11 26200, MSVC 19.44: pass
That includes the new No game files used. AI-assisted run (Claude Code). |
c914558 to
cfe02e4
Compare
|
Rebased onto #291's merge candidate, Ryx69#6 ( The candidate has the vertex-stride fix, so I dropped this PR's copy. One fix came out of the rebase: the standalone device used to replace With validation on, |
RSSetShadingRate and RSSetShadingRateImage (ID3D12GraphicsCommandList5) on VK_KHR_fragment_shading_rate: - Draws record the rate, the two combiners and the image. Reset and ClearState return them to 1x1, passthrough and no image. A rate outside D3D12_SHADING_RATE makes Close return E_INVALIDARG. - Replay sets the rate at every draw as dynamic state. - First combiner: the per-primitive rate is always 1x1, because SV_ShadingRate is not translated. The first combiner is folded on the CPU and Vulkan's primitive op is KEEP. - Second combiner: with an image it maps to KEEP/REPLACE/MIN/MAX/MUL. Without one it is folded against 1x1. - The R8_UINT shading-rate image becomes the rendering scope's fragment-shading-rate attachment, in GENERAL, with texels of the reported tile size. An image smaller than the render area is left out. - Pixel shaders that write depth or stencil shade at 1x1, as D3D12 requires. - D3D12_OPTIONS6 and OPTIONS10 are answered from the GPU's fragment-shading-rate properties. The standalone device enables the extension where the GPU has it. d3d12_vrs_test draws through the proxy with a pixel shader that writes the pixel it ran at, and checks the coarse-pixel size read back for every rate, both combiners, a four-quadrant shading-rate image, ClearState, and a depth-writing pixel shader. It also compares OPTIONS6/OPTIONS10 with the host D3D12 runtime on the same adapter, and checks that a device without the extension reports and applies no VRS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RSSetShadingRate now refuses a combiner outside D3D12_SHADING_RATE_COMBINER: Close returns E_INVALIDARG, where the combiner used to act as passthrough. Either VRS call on a compute or copy list makes Close return E_FAIL, and bundles take both. When a list has several invalid calls, the first one decides what Close returns. These are the host PC D3D12 runtime's results, measured on a Radeon 680M, an RTX 3050 and WARP. The stricter checks follow 0xTehuti's ItsNotRexed#519, which also refuses invalid combiners and these calls on compute lists (there with E_INVALIDARG). d3d12_vrs_test checks the Close result after 14 call sequences, plus 2 more at tier 2. They run before the test's PSO check, so they also run on a device that refuses PSOs. The draw case for out-of-range combiners is gone. The docs list where the shading-rate image is still checked at replay rather than at Close. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WARP, a tier-1 device, refuses RSSetShadingRateImage on every list type, so the sentence measured on all three adapters no longer says bundles take both calls. The tier-1 case is already listed under known gaps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cfe02e4 to
e4f06d1
Compare
|
Rebased onto Conflicts resolved against main:
Tested on Windows 11 with MSVC 19.4x (VS 2022 Build Tools) and Ninja, on an NVIDIA GeForce RTX 3050 Laptop GPU, driver 32.0.16.2101:
AI-assisted (Claude Code). |
0xTehuti
left a comment
There was a problem hiding this comment.
Tested e4f06d1 on NVIDIA GeForce RTX 2070 SUPER, driver 595.79, Windows 11: pass
Environment & Toolchain
- Host / OS: Windows 11
- GPU: NVIDIA GeForce RTX 2070 SUPER (Driver 595.79 / Vulkan 1.4.321)
- Compiler / Build System: MSVC 19.44 (Visual Studio 2022 Community), Ninja 1.13.2
- Vulkan Toolchain: Vulkan SDK 1.4.363 (Vulkan-Headers 1.4.363, glslangValidator 16.6.0, VK_LAYER_KHRONOS_validation 1.4.363)
- Python: Python 3.13 (
compileallandmake_game.py --helpverified clean)
Test Verification
d3d12_vrs_test.exeunderLEONIDA_VK_VALIDATION=1:- Validation: 0 Vulkan validation messages / errors.
- Feature Support / Query Parity:
OPTIONS6(Tier 2, Tile size 16, Additional rates supported: yes) andOPTIONS10(Sum combiner: yes) match the host PC D3D12 runtime on the same adapter LUID. Close()Status Contract: All 16 call sequences matched host D3D12 behavior (correct rejection withE_INVALIDARGfor out-of-enum rates and combiners,E_FAILon compute/copy command lists,S_OKfor direct lists and bundles; first invalid call precedence verified).- Dynamic Shading Rate & Image Attachment: All 24 draw cases with
VK_KHR_fragment_shading_ratematched on every pixel (default 1x1, dynamic rates 1x2 through 4x4, state resets, combiners, depth-writing pixel shader clamping to 1x1, and rate image attachment with 4-quadrant layout). - No-extension Fallback: All 3 draw cases without the extension verified to ignore VRS and shade at 1x1.
d3d12_vulkan_device_test.exe:- Clean pass with 0 mismatches across format info, allocation info, and command stream execution.
- CTest Suite:
- Core runtime, mock proxies, device filters, descriptors, state mapping all passing.
Endorsing #469's draw-hooked VRS implementation.
AI-assisted review.
|
Tested e4f06d1 on AMD Radeon RX 7600 (RDNA3, Navi 33), AMD proprietary driver 26.11.2 (Vulkan 1.4.359), Windows 11 26300, MSVC 19.44, Vulkan SDK 1.4.363.0: pass for VRS, no regressions. As far as I can see this is the first AMD run of this PR (the earlier ones were an RTX 4090 and an RTX 2070 SUPER). It also covers a different path than the NVIDIA runs: this device reports tile 8 with no additional rates, where the RTX 2070 SUPER reports tile 16 with additional rates. AI-assisted (Claude Code); synthetic tests only, no game files.
Full runtime ctest (RelWithDebInfo, VS 2022 generator, Two notes:
|
Claimed in #374 as: D3D-32 (claim). Listed in #313.
What and why
Until now,
RSSetShadingRateandRSSetShadingRateImage(ID3D12GraphicsCommandList5) were generated stubs that only logged the call, andD3D12_OPTIONS6was not answered. This PR implements variable rate shading onVK_KHR_fragment_shading_rate, on top of #291's draw path.Recording. The rate, both combiners and the image are recorded with each draw (
leonida::Draw).ResetandClearStatereturn them to 1x1, passthrough and no image.A null combiner array is
{passthrough, passthrough}.Closereturns what the host PC D3D12 runtime returns. I measured that with a standalone probe (not committed) on a Radeon 680M, an RTX 3050 and WARP:E_INVALIDARG;E_FAIL, while bundles take both calls, as direct lists do;The three agree on all of these, except that WARP, a tier-1 device, refuses
RSSetShadingRateImageon every list (see the deviations below).The combiner and list-type checks follow 0xTehuti's Runtime: Variable Rate Shading on VK_KHR_fragment_shading_rate (D3D-32) #519 and came in with
1c59ccc. Before that commit, a combiner outside the enum acted as passthrough.Replay. Replay calls
vkCmdSetFragmentShadingRateKHRat every draw, and the shading rate is dynamic state in every graphics pipeline.D3D12_SHADING_RATEand a Vulkan shading-rate texel share one encoding (log2 w << 2 | log2 h).SV_ShadingRate)KEEP, soprimitiveFragmentShadingRateis not neededKEEP,REPLACE,MIN,MAXandMUL. Multiplying sizes is adding log2 rates. Sum is reported only withfragmentShadingRateStrictMultiplyCombiner, because without it 1 x 1 may give 2R8_UINT, 2D, single-sampled)VkRenderingFragmentShadingRateAttachmentInfoKHR, inGENERAL(whatSHADING_RATE_SOURCEalready maps to), with texels of the reported tile size. On a tier-2 device,R8_UINTtextures get the attachment usage, and graphics pipelines get..._RENDERING_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR. Other formats, multisampled textures and volumes are refused at replaySV_DepthorSV_StencilRefshades per pixelfragmentShadingRateWithShaderDepthStencilWrites, which both test GPUs have. Such PSOs (FragDepthorFragStencilRefEXTin the SPIR-V) are forced to 1x1Feature answers.
pipelineFragmentShadingRate.fragmentShadingRateNonTrivialCombinerOps, and an 8x8 or 16x16 texel in the device's range. The smaller one becomesShadingRateImageTileSize.AdditionalShadingRatesSupported: 2x4, 4x2 and 4x4 are all listed for one sample.OPTIONS10sum combiner: as above.Without the extension,
OPTIONS6reports no VRS, and the rate and the image are recorded but ignored. The standalone device (LEONIDA_D3D12=vulkan) enables the extension where the GPU has it.Deviations. All four are listed under known gaps in
docs/d3d12_vulkan.md.Close. An image that is not anR8_UINTtexture, or is multisampled or 3D, failsExecuteCommandLists. One with several mips or array layers is used through mip 0 and layer 0. The host runtime failsClosefor each of these except a 3D image. Checking atClosewould mean reading the resource while recording, which the command list does not do today.RSSetShadingRateImageis accepted. The host runtime failsClosewithE_FAILthere (WARP).Vertex strides. Earlier heads of this PR also stopped pipelines without vertex input from declaring
VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE(VUID-vkCmdDraw-pStrides-04913). #291's merge candidate now has that fix, so this PR no longer carries it.Docs.
docs/d3d12_vulkan.mdis updated in several places:OPTIONS6/OPTIONS10answers;Depends on: #291. This branch is rebased onto #291's merge candidate, Ryx69#6 (
70178d3: #291 merged withmainat426023a), plus three commits:5190251,571a694andcfe02e4(a doc wording fix). Only those three are this PR's. Against today'smain(c0ac5fd), this branch conflicts only where the candidate itself does:d3d12_vulkan_device.cppandvulkan_replay.h. I'll rebase again once #291 lands.The rebase kept the candidate's structure and re-added only the VRS parts:
texture_create_info.enable13.pNext, which would have dropped the other extension features the candidate chains there.Closekeeps the candidate's tracing and its open-query check, which now goes through the same first-error rule.Tested
Windows 11 Pro 26300, MSVC 19.44, Vulkan SDK 1.4.363.0, CMake + Ninja.
After the rebase onto
70178d3(same GPUs and drivers as below):/W4, no warnings.ctest: 61 of 62 pass. The failure isd3d12_sampler2, which fails onmain(e7584c5) too, on both GPUs: the host runtime reports no non-normalized samplers, so its answers differ from the layer's.LEONIDA_VK_VALIDATION=1:d3d12_vrs_test: every case matches on every pixel.d3d12_draw_testandd3d12_state_map_testpass.d3d12_vrs_test: the feature answers and allCloseresults match. There are no draws, because PSOs are refused (Runtime: check maxPushConstantsSize at device creation and flag uniform-buffer fallback (D3D-14) #224).d3d12_state_map_testpasses.d3d12_draw_test, which comes with the candidate, fails at PSO creation for the same reason. This PR doesn't touch it.The results below are from the pre-rebase heads (
88d0672,1c59ccc):/W4, no warnings.ctest: 15/15 pass on both GPUs.d3d12_vrs_test:ResetandClearState; every rate; each first combiner; each second combiner over a four-quadrant image (1x1, 2x2, 2x1, 1x2); no image bound; and a depth-writing pixel shader.Closeresults: 14 call sequences, plus 2 more at tier 2, must give the host runtime's result. They cover a rate or combiners outside their enums, each call on direct, bundle, compute and copy lists, and an invalid barrier before and after a VRS call on a compute list. They need no PSO, so they also run on the 680M.LEONIDA_VK_VALIDATION=1, every draw case passes on every pixel, all 16Closeresults match, and there are 0 validation errors.d3d12_draw_test,d3d12_compute_test,d3d12_vulkan_device_test,d3d12_descriptor_test,d3d12_com_testandvk_command_replay_testalso pass under validation.VK_LOADER_DRIVERS_SELECT=amd-vulkan64.json):Closeresults and the no-extension run: pass in the committed test, with all 16Closeresults matching and 0 validation errors.88d0672, all 28 cases passed under validation, with 2x4, 4x2 and 4x4 clamped to 2x2 as D3D12 requires without the additional rates.1c59cccchanges only recording and drops the out-of-range-combiner draw case, so I did not repeat that run.d3d12_draw_testandd3d12_compute_testfail at PSO creation (Runtime: compute path and graphics draws on Vulkan (D3D-3, D3D-4, milestone M1) #291's push-constant refusal), andd3d12_vulkan_device_testfails at the D3D-14 check!device_push_constants_need_fallback(Tests: the D3D-14 push-constant check accepts GPUs with 128 bytes (Radeon 680M, Intel Arc) #516, since merged, fixes that check onmain). This PR changes neither.d3d12_descriptor_test,d3d12_com_test,vk_command_replay_testandctestpass.88d0672: I disabled the depth-writing rule and the first-combiner fold in a scratch build. The test then failed exactly the six cases those rules cover and passed the rest.1c59ccc: I made seven wrong versions, and the tests caught every one:RSSetShadingRateallowed on compute and copy listsRSSetShadingRateImageallowed on compute and copy listsE_INVALIDARGinstead ofE_FAILfor the list typed3d12_state_map_test)AI-assisted (Claude Code, Claude Opus 5.5).
Checklist
docs/design.md, with how it was confirmed. (Not applicable: no translator change.)🤖 Generated with Claude Code