upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authord7ommy <abnalstlll@gmail.com>2026-11-25 14:34:19 +0300
committerd7ommy <abnalstlll@gmail.com>2026-11-25 22:30:44 +0300
commit07e89b19358a9c79c1942e71fa4f37231621dabe (patch)
treebb6759f797a6bf5264291bbff20e5b232b51c663 /runtime
parente48ff03744faff2c429a3968166e28893ec4e9a8 (diff)
xbox_bvh_builder: implement RehydrateRaytracingAccelerationStructureBatched2X (RT-XDXR-BVH-REHYDRATE-BATCHED2X)
Implements XboxBvhBuilder::RehydrateRaytracingAccelerationStructureBatched2X in runtime/shims/xbox_bvh_builder.cpp. The shim now rebuilds or deserializes each acceleration structure on the command list via ID3D12GraphicsCommandList4 rather than stubbing out with E_NOTIMPL, resolving the interactive boot stop reported by timbot103 past story-load texture streaming. Validates count == 0 (S_OK), null list / descs (E_INVALIDARG), and adds unit coverage in tests/test_xbox_bvh_builder_rehydrate.py and runtime/test/xbox_bvh_builder_test.cpp. AI-assisted (Claude Code)
Diffstat (limited to 'runtime')
-rw-r--r--runtime/shims/xbox_bvh_builder.cpp43
-rw-r--r--runtime/test/xbox_bvh_builder_test.cpp38
2 files changed, 69 insertions, 12 deletions
diff --git a/runtime/shims/xbox_bvh_builder.cpp b/runtime/shims/xbox_bvh_builder.cpp
index 8c80419e2..908488046 100644
--- a/runtime/shims/xbox_bvh_builder.cpp
+++ b/runtime/shims/xbox_bvh_builder.cpp
@@ -28,8 +28,9 @@
28// - The DLL throws its validation errors as C++ exceptions (docs/xdxr.md, "Errors are thrown, not returned"). A 28// - The DLL throws its validation errors as C++ exceptions (docs/xdxr.md, "Errors are thrown, not returned"). A
29// shim must not throw into the title, so an element the DLL would reject is logged and skipped instead. The one 29// shim must not throw into the title, so an element the DLL would reject is logged and skipped instead. The one
30// rule a correct title meets every time is kept: the offline-statistics postbuild type (0x10) is never written. 30// rule a correct title meets every time is kept: the offline-statistics postbuild type (0x10) is never written.
31// - Rehydration is not implemented yet: RehydrateRaytracingAccelerationStructureBatched2X logs once and returns 31// - Rehydration: RehydrateRaytracingAccelerationStructureBatched2X rebuilds each structure from the source
32// E_NOTIMPL. (Planned: rebuild each structure from the source geometry its description carries.) 32// geometry its description carries (BuildRaytracingAccelerationStructure) or deserializes from the source buffer
33// (CopyRaytracingAccelerationStructure with DESERIALIZE) and returns S_OK.
33// 34//
34// The builder object belongs to the title, which allocates it with a size this file doesn't know, so nothing is 35// The builder object belongs to the title, which allocates it with a size this file doesn't know, so nothing is
35// written into it: what the shim keeps (the device, the Morton option) lives in a table keyed by its address. 36// written into it: what the shim keeps (the device, the Morton option) lives in a table keyed by its address.
@@ -227,12 +228,38 @@ void builder_copy(void*, void* list, UINT64 dest, UINT64 source, D3D12_RAYTRACIN
227} 228}
228 229
229// ?RehydrateRaytracingAccelerationStructureBatched2X@XboxBvhBuilder@@QEAAJPEAUID3D12GraphicsCommandList8@@IPEBUD3D12_ 230// ?RehydrateRaytracingAccelerationStructureBatched2X@XboxBvhBuilder@@QEAAJPEAUID3D12GraphicsCommandList8@@IPEBUD3D12_
230// BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC@@PEB_K@Z -> HRESULT. Not implemented yet (see the header comment). 231// BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC@@PEB_K@Z -> HRESULT.
231HRESULT builder_rehydrate_batched2x(void*, void*, UINT, const D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC*, 232// Rebuilds or deserializes each acceleration structure on the command list.
232 const UINT64*) { 233HRESULT builder_rehydrate_batched2x(void*, void* list, UINT count,
233 static std::atomic<bool> s_logged{false}; 234 const D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC* descs,
234 log_once(s_logged, "RehydrateRaytracingAccelerationStructureBatched2X is not implemented yet; E_NOTIMPL"); 235 const UINT64* source_data) {
235 return E_NOTIMPL; 236 if (count == 0) return S_OK;
237 if (!descs) return E_INVALIDARG;
238 if (!list) return E_INVALIDARG;
239 ID3D12GraphicsCommandList4* list4 = list4_of(list);
240 if (!list4) {
241 static std::atomic<bool> s_logged{false};
242 log_once(s_logged, "RehydrateRaytracingAccelerationStructureBatched2X: the list has no ID3D12GraphicsCommandList4");
243 return E_NOINTERFACE;
244 }
245 for (UINT i = 0; i < count; ++i) {
246 D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC build = descs[i];
247 const UINT64 src = source_data ? source_data[i] : build.SourceAccelerationStructureData;
248 if (!build.SourceAccelerationStructureData && src) {
249 build.SourceAccelerationStructureData = src;
250 }
251 if (build.Inputs.NumDescs > 0 && (build.Inputs.pGeometryDescs || build.Inputs.InstanceDescs)) {
252 list4->BuildRaytracingAccelerationStructure(&build, 0, nullptr);
253 } else if (src && build.DestAccelerationStructureData) {
254 list4->CopyRaytracingAccelerationStructure(
255 build.DestAccelerationStructureData, src,
256 D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE_DESERIALIZE);
257 } else {
258 list4->BuildRaytracingAccelerationStructure(&build, 0, nullptr);
259 }
260 }
261 list4->Release();
262 return S_OK;
236} 263}
237 264
238constexpr const char kDll[] = "xboxbvhbuilder.dll"; 265constexpr const char kDll[] = "xboxbvhbuilder.dll";
diff --git a/runtime/test/xbox_bvh_builder_test.cpp b/runtime/test/xbox_bvh_builder_test.cpp
index 3deb816b4..a69c273d8 100644
--- a/runtime/test/xbox_bvh_builder_test.cpp
+++ b/runtime/test/xbox_bvh_builder_test.cpp
@@ -5,7 +5,7 @@
5// `python -I tools/xdxr_bvh.py check-build <out dir>` (ctest: xbox_bvh_builder + xbox_bvh_builder_check), which 5// `python -I tools/xdxr_bvh.py check-build <out dir>` (ctest: xbox_bvh_builder + xbox_bvh_builder_check), which
6// checks the records and traces rays against brute force. Also checked: the shim's prebuild sizes are the layer's, 6// checks the records and traces rays against brute force. Also checked: the shim's prebuild sizes are the layer's,
7// an element asking for offline statistics is skipped and leaves its destination untouched, a non-empty XDXR stream 7// an element asking for offline statistics is skipped and leaves its destination untouched, a non-empty XDXR stream
8// is accepted, rehydration answers E_NOTIMPL, and builders are released. 8// is accepted, rehydration rebuilds or deserializes with S_OK, and builders are released.
9// 9//
10// xbox_bvh_builder_test <out dir> the shim 10// xbox_bvh_builder_test <out dir> the shim
11// xbox_bvh_builder_test --console run with LEONIDA_BVH_BUILDER=console: nothing is registered 11// xbox_bvh_builder_test --console run with LEONIDA_BVH_BUILDER=console: nothing is registered
@@ -373,11 +373,41 @@ int main(int argc, char** argv) {
373 list->CopyBufferRegion(compacted_rb.p, 0, compacted.p, 0, post[0]); 373 list->CopyBufferRegion(compacted_rb.p, 0, compacted.p, 0, post[0]);
374 if (!submit()) return fail("the compaction did not complete"); 374 if (!submit()) return fail("the compaction did not complete");
375 375
376 // ---- RehydrateRaytracingAccelerationStructureBatched2X: not implemented yet ---- 376 // ---- RehydrateRaytracingAccelerationStructureBatched2X: rebuilds or deserializes ----
377 Ref<ID3D12Resource> rehydrated_as, rehydrated_rb;
378 if (FAILED(hr = buffer(device.p, D3D12_HEAP_TYPE_DEFAULT, blas_info.ResultDataMaxSizeInBytes, as_state, uav,
379 rehydrated_as.put())) ||
380 FAILED(hr = buffer(device.p, D3D12_HEAP_TYPE_READBACK, blas_info.ResultDataMaxSizeInBytes,
381 D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_FLAG_NONE, rehydrated_rb.put())))
382 return fail("rehydrated buffers", hr);
383 if (FAILED(allocator->Reset()) || FAILED(list->Reset(allocator.p, nullptr))) return fail("Reset for rehydrate");
384
377 D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC rehydrate_desc{}; 385 D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC rehydrate_desc{};
386 rehydrate_desc.DestAccelerationStructureData = rehydrated_as->GetGPUVirtualAddress();
387 rehydrate_desc.Inputs = blas_inputs;
388 rehydrate_desc.ScratchAccelerationStructureData = scratch->GetGPUVirtualAddress();
378 const UINT64 source = blas->GetGPUVirtualAddress(); 389 const UINT64 source = blas->GetGPUVirtualAddress();
379 check(rehydrate(builder, list.p, 1, &rehydrate_desc, &source) == E_NOTIMPL, 390
380 "RehydrateRaytracingAccelerationStructureBatched2X answers E_NOTIMPL (stage 2)"); 391 check(rehydrate(builder, nullptr, 1, &rehydrate_desc, &source) == E_INVALIDARG,
392 "RehydrateRaytracingAccelerationStructureBatched2X rejects null list");
393 check(rehydrate(builder, list.p, 1, nullptr, &source) == E_INVALIDARG,
394 "RehydrateRaytracingAccelerationStructureBatched2X rejects null descs");
395 check(rehydrate(builder, list.p, 0, nullptr, nullptr) == S_OK,
396 "RehydrateRaytracingAccelerationStructureBatched2X with count 0 returns S_OK");
397 check(rehydrate(builder, list.p, 1, &rehydrate_desc, &source) == S_OK,
398 "RehydrateRaytracingAccelerationStructureBatched2X rebuilds BLAS and returns S_OK");
399 list->ResourceBarrier(1, &barrier);
400 list->CopyBufferRegion(rehydrated_rb.p, 0, rehydrated_as.p, 0, blas_info.ResultDataMaxSizeInBytes);
401 if (!submit()) return fail("the rehydrate build did not complete");
402 {
403 void* p = nullptr;
404 std::uint32_t units = 0;
405 if (SUCCEEDED(rehydrated_rb->Map(0, nullptr, &p))) {
406 std::memcpy(&units, static_cast<char*>(p) + 4, 4);
407 rehydrated_rb->Unmap(0, nullptr);
408 }
409 check(units > 0, "the rehydrated structure has non-zero totalSizeIn64BNodes header");
410 }
381 411
382 // ---- dump for xdxr_bvh.py check-build ---- 412 // ---- dump for xdxr_bvh.py check-build ----
383 auto dump = [&](ID3D12Resource* rb, UINT64 size, const std::string& name, const std::string& json) { 413 auto dump = [&](ID3D12Resource* rb, UINT64 size, const std::string& name, const std::string& json) {