KHR BLAS: no triangles for an indexed geometry with fewer than 3 indices; prebuild sizes the build it gets (RT-KHR-BLAS-PRIMCOUNT-AND-PREBUILD) #2486
Closed
leonida/mandy
Tyrannys wants to merge 0 commits from
claude/khr-blas-primcount into main
pull from: claude/khr-blas-primcount
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!2486
Loading…
Reference in a new issue
No description provided.
Delete branch "claude/khr-blas-primcount"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request closed
This pull request cannot be reopened because the branch was deleted.
Claimed in the coordination issue as: RT-KHR-BLAS-PRIMCOUNT-AND-PREBUILD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7224579621), item 1 of @kevincommits' finding (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7224204750). Thanks to kevincommits for finding it and for the repro values.
What and why
On the KHR acceleration-structure path (
LEONIDA_RT_AS=khr), two places counted the triangles of an indexed BLAS geometry wrong when it had fewer than 3 indices:BuildAccelerationStructureemit inruntime/src/vulkan_replay.h;GetRaytracingAccelerationStructurePrebuildInfoinruntime/shims/d3d12_vulkan_device.cpp.Both used
(indexed && index_count >= 3) ? index_count / 3 : vertex_count / 3. So an indexed geometry withIndexCount0 or 2 was counted by its vertices. Its index type stayedUINT16/UINT32, and its index address could be null (no index buffer).vkCmdBuildAccelerationStructuresKHRwould then read3 * (vertex_count / 3)indices from address 0, or past the end of the buffer. With kevincommits' inputs, the build got 1000 and 100 triangles where it should get 0.The XDXR sites already count
(indexed ? index_count : vertex_count) / 3. That rule is nowleonida::rt_triangle_count(runtime/src/command_list.h), and both KHR places use it.The KHR size query also differed from the build it sizes in two more ways:
R32G32_FLOATas three floats. The build records the four 16-bit formats D3D12 allows (R16G16B16A16_FLOAT,R16G16_FLOAT,R16G16B16A16_SNORM,R16G16_SNORM) as themselves.ALLOW_COMPACTION, which the build does.Both now come from one header,
runtime/shims/d3d12_rt_khr_inputs.h:khr_vertex_formatandkhr_build_flagsare used by the recorded build (d3d12_com.cpp) and by the size query.khr_build_size_querybuilds the size query's inputs. It is a plain function, so it can be tested without a device.A vertex format the build refuses is still sized as three floats, since a size query must name a format. Nothing else changes for the XDXR path (the default).
The comment in
d3d12_indirect_rt_test.cppthat called theALLOW_COMPACTIONforwarding an open gap now says it is forwarded. The test still takes the driver's own sizes as a floor, as before.Tested
New
replay_khr_blas_build(runtime/test/replay_khr_blas_build_test.cpp): records a BLAS build and runsprepare/emitagainst a fakevkCmdBuildAccelerationStructuresKHR. No GPU. It checks:UINT16,index_count0,vertex_count3000,index_va0;UINT32,index_count2,vertex_count300,index_va0) get 0 triangles;New
d3d12_rt_khr_inputs(runtime/test/d3d12_rt_khr_inputs_test.cpp): checkskhr_build_size_querywithout a device:ALLOW_COMPACTIONincluded, andPERFORM_UPDATEis not a flag;Both tests fail with the old behaviour put back (old count rule, old format choice, compaction dropped):
replay_khr_blas_build: 2 failures;d3d12_rt_khr_inputs: 7 failures.With the fix, both pass.
replay_khr_as_copy_postbuild,vk_xdxr_postbuild_readback,d3d12_comandtests/test_ci_registration.pypass.GPU tests, all passing:
d3d12_dxr_validationandd3d12_dxr_validation_khr(LEONIDA_RT_AS=khr);d3d12_indirect_rt;d3d12_indirect_rt_testagain withLEONIDA_RT_AS=khr LEONIDA_VK_VALIDATION=1: KHR builds, compaction postbuild, CLONE/COMPACT and ray queries, 0 validation errors.Full runtime build (MSVC, Ninja): clean.
GPUs tested: NVIDIA GeForce RTX 4070 SUPER, driver 621.01, Windows 11 (profile M).
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (No translator change.)🤖 Generated with Claude Code
Reviewed the diff and tested locally on Windows 11 + NVIDIA GeForce RTX 5070 12 GB (MSVC 19.44, Ninja Release).
rt_triangle_count()incommand_list.hand sharedkhr_vertex_format()/khr_build_flags()/khr_index_type()/khr_build_size_query()ind3d12_rt_khr_inputs.hensuresBuildRaytracingAccelerationStructureandGetRaytracingAccelerationStructurePrebuildInfoagree on triangle counts (indexed geometries with< 3indices produce0triangles instead of falling back tovertex_count / 3), all six D3D12 BLAS vertex formats, andALLOW_COMPACTION.d3d12_rt_khr_inputs_test,replay_khr_blas_build_test, andd3d12_indirect_rt_testand ranctest --output-on-failure:d3d12_rt_khr_inputs: passed (0.03 s).replay_khr_blas_build: passed (0.03 s).d3d12_indirect_rt: passed (0.83 s).d3d12_indirect_rt_upload_sysmem: passed (0.62 s).python -I tests/test_ctest_registration.py -v: 6/6 passed.GPUs tested: NVIDIA GeForce RTX 5070 12 GB (Windows 11, driver 610.88, Vulkan 1.4.341;
VK_LAYER_KHRONOS_validationnot installed locally).AI-assisted (Antigravity, Gemini).
Reviewed at head
ede03426con Windows 11 (MSVC 202219.44) with dual-GPU Vulkan validation (LEONIDA_VK_VALIDATION=1, Vulkan SDK1.4.363.0).Verification
d3d12_rt_khr_inputs_test,replay_khr_blas_build_test, andd3d12_indirect_rt_test.d3d12_rt_khr_inputs_test: passed.replay_khr_blas_build_test: passed.d3d12_indirect_rt_test(LEONIDA_VK_VALIDATION=1): PASS (0 validation errors) on both NVIDIA GeForce RTX 5080 (616.64) and AMD Radeon(TM) Graphics (25.10.30.02).Findings (Request changes)
VK_INDEX_TYPE_UINT16/UINT32with a nullindexDatadevice address (d3d12_com.cpp:1098-1103;vulkan_replay.h:5460-5486;replay_khr_blas_build_test.cpp:84-108):When
index_va == 0andindex_count < 3, replay emitsprimitiveCount = 0while still settingtr.indexType = VK_INDEX_TYPE_UINT16/UINT32andtr.indexData.deviceAddress = 0. UnderVUID-vkCmdBuildAccelerationStructuresKHR-pInfos-03806, any triangle geometry withindexType != VK_INDEX_TYPE_NONE_KHRrequires a valid device address inindexData(the mock atreplay_khr_blas_build_test.cpp:84-108currently expects the invalidUINT16/zero-address combination). Either normalize null-address empty indexed geometry consistently (e.g.,VK_INDEX_TYPE_NONE_KHRin both prebuild and replay) or reject nullindex_vawhen an index format is declared.transformDatapresence (d3d12_rt_khr_inputs.h:82-97vs.d3d12_com.cpp:1104,vulkan_replay.h:5468):d3d12_rt_khr_inputs.hleavestr.transformDatazero for every geometry duringvkGetAccelerationStructureBuildSizesKHR, while replay forwardst.transform_vaintotr.transformData.deviceAddress. Vulkan requirestransformData.hostAddress(ordeviceAddress) to be non-null in the size query whenever the subsequent build uses a transform to guarantee the returned acceleration-structure/scratch sizes are sufficient. Setting a non-null sentinel ontr.transformDatawhent.Transform3x4 != 0closes this prebuild parity gap.AI-assisted review + local MSVC/dual-GPU verification.
#2486 | head ede03426c98bb3c4f7658f034ca0dfc5091ee5ef (merged cleanly with main adfb3821a23612263c1c5b195453ed01c4c114db) |
ctest --test-dir runtime/build -C RelWithDebInfo -R "^(d3d12_rt_khr_inputs|replay_khr_blas_build|replay_khr_as_copy_postbuild|d3d12_dxr_validation|d3d12_dxr_validation_khr|d3d12_indirect_rt)$" --output-on-failure+LEONIDA_RT_AS=khrond3d12_indirect_rt+ live KHR empty-indexed BLAS GPU probe (LEONIDA_VK_VALIDATION=1) | red on main's< 3index formula:replay_khr_blas_build_testfails its two< 3static_assertchecks (error C2607at lines56and57) andd3d12_rt_khr_inputsfails (FAIL: R16_UINT, IndexCount 0, VertexCount 3000: 0 triangles (not 1000)andFAIL: R32_UINT, IndexCount 2, VertexCount 300: 0 triangles (not 100)) | green on PR+main:6/6CTests (d3d12_rt_khr_inputs,replay_khr_blas_build,replay_khr_as_copy_postbuild,d3d12_dxr_validation,d3d12_dxr_validation_khr,d3d12_indirect_rt) plusd3d12_indirect_rtunderLEONIDA_RT_AS=khrandtest_ci_registration.py(18/18) pass on RTX 3090 with0Khronos validation errors (check_no_game_data.py0violations). Note on the earlier review comments: (1) a liveLEONIDA_RT_AS=khr+VK_LAYER_KHRONOS_validation1.4.363.1GPU submission of an empty indexed BLAS (DXGI_FORMAT_R16_UINT,IndexCount = 0,IndexBuffer = 0->indexType = VK_INDEX_TYPE_UINT16,indexData.deviceAddress = 0,primitiveCount = 0) completes with0validation errors, asVUID-vkCmdBuildAccelerationStructuresKHR-pInfos-03806applies only whenprimitiveCount != 0; (2) setting a non-nulltr.transformDatasentinel inkhr_build_size_querywhent.Transform3x4 != 0remains a worthwhile follow-up so prebuild sizes include transform overhead | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yesTested ede03426c merged (no commit) with main 8fb974878: MSVC 19.52, Windows 11 10.0.26300.
GPUs tested: NVIDIA GeForce RTX 3080, driver 621.40.
d3d12_rt_khr_inputs,d3d12_indirect_rt,d3d12_indirect_rt_upload_sysmemandreplay_khr_blas_buildpass. The 294 relinked CTests pass, exceptxbox_present, which fails on main too (its resize case).d3d12_rt_khr_inputs.his new, andreplay_khr_blas_build_test.cpp(56):C3861 'rt_triangle_count'). No runtime red was shown here.gta6rtlinks with nothing new over main: no new unresolved symbol, same imports.runtime/CMakeLists.txt. Whichever lands second needs a rebase.Transform3x4) have no commit yet.AI-assisted (Claude Code).
Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (
d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools,d3d12/, or general docs), please feel free to reopen it.