Skip to content

tests(runtime): add CPU-only unit tests for vulkan_indirect_dispatch_count.h - #7910

Open
HDFreitas wants to merge 2 commits into
ProjectLeonida:mainfrom
HDFreitas:test/vulkan-indirect-dispatch-count
Open

HDFreitas wants to merge 2 commits into
ProjectLeonida:mainfrom
HDFreitas:test/vulkan-indirect-dispatch-count

Conversation

@HDFreitas

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #7804 (comment)

What and why

Adds CPU-only unit tests for runtime/src/vulkan_indirect_dispatch_count.h (IndirectDispatchCounter, IndirectDispatchCounter::Batch, and CountedDispatch) in runtime/test/vulkan_indirect_dispatch_count_test.cpp and registers vulkan_indirect_dispatch_count_test / CTest vulkan_indirect_dispatch_count in runtime/CMakeLists.txt.

Using a mock PFN_vkGetDeviceProcAddr dispatch table, the tests cover:

  • Batch::prepare argument validation (null buffers, zero/unaligned stride, zero max_count, zero maxComputeWorkGroupCount[0]) and missing entry-point guards
  • Partial pipeline creation rollback (vkCreateShaderModule, vkCreatePipelineLayout, vkCreateComputePipelines)
  • Buffer/memory allocation failure cleanup (vkCreateBuffer, vkAllocateMemory, vkBindBufferMemory), VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT preference and fallback, and BDA zero/overflow guards
  • Multi-chunk emit() bounded by both maxComputeWorkGroupCount[0] * 64 and 32-bit stride indexing (index_limit + 1), push constants, barrier placement, and destructor cleanup

Tested

  • OS / Compiler: Arch Linux, g++ 16.2.1, cmake + ninja (RelWithDebInfo)
  • Host GPU / Driver: NVIDIA GeForce RTX 3060 12 GB, nvidia-open 615.71.09 (CPU-only test; no GPU or game files used)
  • g++ -std=c++20 -Wall -Wextra -Wno-missing-field-initializers -Werror -Iruntime/src runtime/test/vulkan_indirect_dispatch_count_test.cpp -o /tmp/vulkan_indirect_dispatch_count_test && /tmp/vulkan_indirect_dispatch_count_test: vulkan_indirect_dispatch_count_test: ok
  • cmake -S runtime -B runtime/build/linux -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo && cmake --build runtime/build/linux --target vulkan_indirect_dispatch_count_test && ctest --test-dir runtime/build/linux --output-on-failure -R "^vulkan_indirect_dispatch_count$": 1/1 passed (0.00 sec)
  • python3 -I scripts/check_no_game_data.py runtime/test/vulkan_indirect_dispatch_count_test.cpp runtime/CMakeLists.txt: exit 0

AI-assisted: yes

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

@CourtyardGames

Copy link
Copy Markdown

Independent Windows x64 check at 5835549: I compiled the test directly with MSVC 19.44.35230, C++20, /O2 /W4 /permissive- /utf-8 and Khronos Vulkan-Headers v1.3.296. The executable printed vulkan_indirect_dispatch_count_test: ok and exited 0.

As a negative control, I changed only the argument address in the chunk push constants to reuse the first chunk's address. The rebuilt test exited 1 at line 302, where it checks that the second chunk advances by 64 records of 24 bytes. This exercised the mock dispatch path on CPU. AI-assisted.

@RAINighty

Copy link
Copy Markdown

Tested 5835549e2 merged with main dde82f27e (clean merge) on native Windows 11 (10.0.26300), MSVC 19.44.35228, Windows SDK 10.0.26100, Ninja, RelWithDebInfo: pass. The description reports a Linux g++ build, so this is the MSVC one through the project's CMake.

  • The runtime/CMakeLists.txt change reconfigures and the whole runtime builds (exit 0). The new vulkan_indirect_dispatch_count ctest is registered and passes (0.20 s).
  • I did not check the compiler warnings of the new test, and did not review the code beyond running it. CPU only, no game files.

AI-assisted (Claude Code).

@jebaczydow

Copy link
Copy Markdown

Read the diff and traced the expected values against vulkan_indirect_dispatch_count.h (not run). The ones I traced are right. Three gaps that would let a wrong implementation pass:

  1. The push constants stride_words and count are never asserted. Only first_record, records, and arguments/output of pushes[1] are checked, so job.stride in place of job.stride / 4 would pass.
  2. mock.dispatches == {1, 1, 1} only ever sees x = 1 (chunks of at most 64 records), so a hard-coded 1 passes. A chunk with 65 or more records per dispatch would pin the (count + 63) / 64 rounding.
  3. The wide-stride case (0x80000000) asserts records and first_record but not pushes[1].arguments, which should be args + 8 * 0x80000000 and is the value that exceeds 32 bits, the point of that case.

AI-assisted (Claude); code read only, nothing run.

@MartinIndra02

Copy link
Copy Markdown
Contributor

Independent build + test: PASS

AI-assisted (Claude Code). Windows 11 x64, MSVC 19.44.35220, Ninja RelWithDebInfo. CPU-only test; machine GPU NVIDIA GeForce RTX 3080 driver 621.24 / 32.0.16.2124 (not used).

Head 5835549e2, based on current main (dde82f27e). Reconfigured and built vulkan_indirect_dispatch_count_test, with no warnings.

Run Result
vulkan_indirect_dispatch_count_test.exe exit 0, vulkan_indirect_dispatch_count_test: ok

To check that the test catches real changes, I made four single-line local edits to runtime/src/vulkan_indirect_dispatch_count.h (Batch::prepare) and reran the test after each:

Mutation Test result
never prefer DEVICE_LOCAL memory caught: line 287: mock.last_alloc_type == 1
drop stride % 4 caught: line 203: !b->prepare(args, 0, cnt, 0, 10, 1, out)
drop the address + offset overflow guard caught: line 271: !counter.batch()->prepare(args, 16, cnt, 0, 12, 2, out)
drop max_count > max / record_bytes not caught

The one that survives can't be tested: max_count is a uint32_t, so max_count * 12 always fits in VkDeviceSize, and that guard in the header is dead code. That's not a gap in this test. No issues found.

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.

5 participants