Repository navigation
Runtime: zero-initialize committed block-compressed textures on first use (D3D-220) - #1765
Conversation
|
Independently verified commit
AI Assisted. |
dcastell1
left a comment
There was a problem hiding this comment.
Built the runtime from this tree and ran it on the RTX 5090 (621.24, Windows 11):
1/1 Test #46: vk_bc_zero_init ... Passed 0.22 sec
Zero-initialising committed block-compressed textures is the kind of thing that only shows up as garbage in the first frames, so having a dedicated test that fails without it is worth more than the fix itself. No concerns.
|
Tested
No game files. AI-assisted (Claude Code). |
|
Tested f43ced5 on Intel UHD 770 (101.7092) and RTX 4070 SUPER (NVIDIA 616.64), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363.0: pass This is the GPU from #1725. The PR's own runs used MinGW and
|
|
Tested on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51): no regression from this PR. RTX 4080 SUPER: 101/102 pass. |
Claimed on #1548 (comment) (fixes D3D-220 / the
d3d12_copy_xfmtBC1 failure in #1725).Root cause
detail::initialize()(runtime/src/vulkan_replay.h) skipped zero-filling block-compressed (BC*) images (if (resource.not_zeroed || compressed)), because Vulkan forbidsvkCmdClearColorImageon compressed formats.In D3D12, committed resources created without
D3D12_HEAP_FLAG_CREATE_NOT_ZEROEDmust start zeroed. Ind3d12_copy_xfmt, two partial uncompressed →BC1copies leave blocks untouched:CopyTextureRegion R32G32_UINT 2x2 -> BC1 16x16 at (8, 4)leaves 12 of the 16 blocks (including block(0,0)at byte0) untouched.CopyResource R32G32_UINT 3x2 -> BC1 12x8, 2 mipswrites1x1into mip 1 (6x4, 2 blocks), leaving block1(bytes56..63) untouched.On drivers that recycle non-zero VRAM pages (such as Intel UHD 770 /
101.7092in #1725, failing 4 of 5 runs at byte0and byte56), those untouched blocks read back stale garbage instead of0x00.Fix (
runtime/src/vulkan_replay.h)detail::zero_compressed_image()and called it fromdetail::initialize()for committed block-compressed textures (!resource.not_zeroed && fmt.block > 1):vkCmdCopyBufferToImagedirectly from the device's read-onlyvk.zero_buffer(the 64 KiB reserved zero page in the GPU address arena), tiling across mips/layers/depth slices/block rows/block columns to stay withinvk.zero_sizewhile honoring Vulkan's compressedimageOffset/imageExtent/bufferOffsetalignment rules.vk.zero_bufferis unset, e.g.d3d12_copy_xfmtwithoutbuffer_device_address): Requests a device-local transfer scratch chunk (up to 64 KiB) fromvk.copy_scratch, zeros it viavkCmdFillBuffer, inserts aTRANSFER_WRITE -> TRANSFER_READbarrier, and copies it into the BC image viavkCmdCopyBufferToImage.resource.not_zeroed(D3D12_HEAP_FLAG_CREATE_NOT_ZEROED), and falls back to layout-only transition if neitherzero_buffernorcopy_scratchis wired (preserving synthetic CPU unit tests).Tests added
runtime/test/vk_bc_zero_init_test.cpp(registered as cross-platform CTestvk_bc_zero_initinruntime/CMakeLists.txtwithSKIP_RETURN_CODE 77):0x5Abefore registering them asUNDEFINEDinLayoutTracker(reproducing recycled VRAM deterministically on both integrated and discrete GPUs).CopyTextureRegion 2x2 -> BC1 16x16 at (8,4)andCopyResource 3x2 -> BC1 12x8, 2 mips) on bothvk.zero_buffer(Path A) andvk.copy_scratch(Path B).vk.zero_bufferon a32x32BC7image.not_zeroed = trueskips zero-fill (0x5Apreserved).d.validation_errors() == 0.Verification
main89b047cd): Failed deterministically on both Intel UHD (101.7092) and NVIDIA RTX 5050 (621.24) atline 200: got[k] == 0x00(untouched BC1 block(0,0)read back0x5A).-std=c++20 -O2 -Wall -Wextra -Wpedantic -Wno-missing-field-initializers, 0 warnings in touched lines):replay_clear_gate_testpassed.0x8086:0xa7a8, driver101.7092, Vulkan1.4.323):vk_bc_zero_init_test3/3 passed.0x10de:0x2d98, driver621.24, Vulkan1.4.357):vk_bc_zero_init_test3/3 passed.84built,89registered,0missing beyondd3d12_clear_test.AI-assisted: written and verified with an AI coding assistant; all code, negative controls, and multi-GPU runs reviewed and executed locally. No game data.