Repository navigation
vulkan: harden IndirectDispatchCounter validation, cleanup, and emit guards - #6191
emirhan-karaca wants to merge 1 commit into
Conversation
SirKingg
left a comment
There was a problem hiding this comment.
Independent Windows/MSVC/Vulkan review, AI-assisted. I found the test skip issue inline, so I am not approving yet.
Windows, MSVC 19.44.35230, Vulkan SDK/validation 1.4.363, RTX 4070 Ti driver 610.88; synthetic inputs only, no game files.
cmake -S runtime -B runtime\build-review-6191 -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTING=ONandcmake --build runtime\build-review-6191 --target vk_indirect_dispatch_count_test vk_sync_validation_selftest: passed under vcvars64.- With
LEONIDA_VK_VALIDATION=1,ctest --test-dir runtime\build-review-6191 -C RelWithDebInfo -R '^vk_(indirect_dispatch_count|sync_validation)$' --repeat until-fail:3 --output-on-failure: both passed 3/3. The synchronization self-test independently detected one expected hazard without a barrier and zero with one; the PR test reported zero validation errors. - MSVC-compiled PR test against base header 561b65a: failed at the expected stride-4 rejection (line 254), exit 1. An isolated modified synthetic fixture exercised 300 records with a two-workgroup chunk limit and GPU counts 129, 0, and 999: passed with zero validation errors. It reuses the compute helper for readback, not actual vkCmdDispatchIndirect execution.
- With
LEONIDA_VK_VALIDATION=1andVK_LOADER_LAYERS_DISABLE=VK_LAYER_KHRONOS_validation,ctest --test-dir runtime\build-review-6191 -C RelWithDebInfo -R '^vk_indirect_dispatch_count$' -Vreports SKIP and exits 0 despite the requested layer being unavailable (see inline).
These focused tests do not establish behavior on other drivers, out-of-memory conditions on a real driver, or game workloads.
|
|
||
| vktest::Device d; | ||
| d.request_buffer_device_address = true; | ||
| if (!d.create(false) || !d.buffer_device_address) { |
There was a problem hiding this comment.
create() collapses DeviceStatus::failed and unavailable, so this returns 77 even when validation was explicitly requested but its layer or initialization fails. Reproduced with LEONIDA_VK_VALIDATION=1 and VK_LOADER_LAYERS_DISABLE=VK_LAYER_KHRONOS_validation: it prints that the layer is missing, then CTest marks the test skipped and exits 0, despite a working GPU. Could this use initialize(false), fail on DeviceStatus::failed, and reserve 77 for unavailable or missing BDA? A negative case would protect the validated run from silently skipping.
Summary
Hardens
IndirectDispatchCounter(runtime/src/vulkan_indirect_dispatch_count.h) with the same defensive validation, partial-initialization cleanup, and dispatch guards already applied to other GPU helpers (Depth24Converter,PresentComposer,PredicatedBufferCopier,PredicateReducer), and adds a standalone MockVk + real-GPU BDA count-gating regression test (runtime/test/vk_indirect_dispatch_count_test.cpp).Claim: #6089 (comment)
Changes
runtime/src/vulkan_indirect_dispatch_count.h:get_/device_and null destroy function pointers in~IndirectDispatchCounter(),~Batch(),make_pipeline(), andemit().Batch::prepare():stride < 12(a D3D12 dispatch argument record is 3 dwords = 12 bytes) and unalignedargument_offset % 4/count_offset % 4(the BDA compute shader loads 32-bit words).args_span,args_va + argument_offset,count_va + count_offset + sizeof(uint32_t), andoutput_va + bytes.memory_.memoryTypeCounttoVK_MAX_MEMORY_TYPESbefore indexingmemoryTypes[]/ shifting1u << i.bufferandmemoryin local handles until all creation, allocation, bind, and BDA checks succeed, and clearmemoryon failedvkAllocateMemoryso neither partial entries remain inallocationsnor garbage output handles are passed tovkDestroyBuffer/vkFreeMemory.make_pipeline(): verifyVK_SUCCESS && handle != VK_NULL_HANDLEat every creation step and destroy only handles created by successful calls (avoiding destroying garbage handles if a failed Vulkan call writes to the output pointer).emit(): guard nullcb/get_/device_/pipeline_/layout_/ zero BDA / invalidstrideormax_count/ zeromaxComputeWorkGroupCount[0], and compute workgroup count via(count - 1u) / 64u + 1uso the ceil-division cannot overflowuint32_tregardless of chunk size.runtime/test/vk_indirect_dispatch_count_test.cpp&runtime/CMakeLists.txt:vk_indirect_dispatch_count(vk_indirect_dispatch_count_test,SKIP_RETURN_CODE 77, MSVC/W4 /permissive- /utf-8).1a–1e: stride/offset rejection, null handles, missing entry points, garbage-on-failure cleanup,memoryTypeCount > VK_MAX_MEMORY_TYPESclamping, address-range overflows,emit()guards & chunked dispatch math) plus real-GPU Vulkan 1.3 BDA count-gating (count = 3, 0, 99,stride = 16,argument_offset = 16,count_offset = 4), reusingIndirectDispatchCounterfor readback so the private indirect buffer never requiresVK_BUFFER_USAGE_TRANSFER_SRC_BIT.Verification
origin/main561b65a83):vk_indirect_dispatch_count_testfails deterministically (exit 1) on both Intel UHD and NVIDIA RTX 5050 atline 254: !b->prepare(args_buf, 0, count_buf, 0, 4, 2, out)(stride = 4 < 12was wrongly accepted).vk_indirect_dispatch_count_test.cppunderg++ 16.2.0 -std=c++20 -O2 -Wall -Wextra -Wconversion -Wsign-conversion, Vulkan-Headers 369):101.7092):vk_indirect_dispatch_count_test3/3 consecutive PASS,vk_queue_testPASS.621.24):vk_indirect_dispatch_count_test3/3 consecutive PASS,vk_queue_testPASS.g++ 16.2.0without MSVC orVK_LAYER_KHRONOS_validationinstalled, so CI validation-layer and MSVC runs are appreciated.