Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions docs/xdxr.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,40 @@ type is one of two checks, and neither reads past the `InfoType` field:

None of the 15 other DLLs in the package names the type or an offline builder.

## 4a. The runtime serves the DLL itself

`runtime/shims/xbox_bvh_builder.cpp` serves the seven exports the executable imports with the layer's own XDXR
builder (`runtime/src/xdxr_build.*`), so the bundled DLL is not loaded and its 52 console programs are never created.
Their pipeline compile (31.2 s for one of them on an RTX 4080, 59.5 s for all 52 on an RX 9070 XT, #7231/#7049) runs
on the title's thread, longer than its ~30 s startup watchdog, so a cold first boot ends at the builder (boot stop 18).
`LEONIDA_BVH_BUILDER=console` turns the shim off.

The executable's imports and call sites, measured statically on 1.0.2.1. The counts are `call [rip+disp32]`
through the import table. For `Batched2X`, IDA finds 8 direct calls: 4 in each of two sibling functions with no
static reference, reached through a table (#7516), so 2 of them are calls of another form.

| Export | Call sites | The shim |
|---|---:|---|
| `XboxBvhBuilder(ID3D12Device11*, bool)` | 1 | keeps the device in a table keyed by `this`; writes nothing into the title's object |
| `~XboxBvhBuilder()` | 1 | releases that entry |
| `Set64BitMortonCodes(bool)` | 8 | recorded; the layer's builder has no such option |
| `GetRaytracingAccelerationStructurePrebuildInfo(INPUTS*, XDXR_STREAM_DESC*, PREBUILD_INFO*)` | 3 | the layer's sizes |
| `BuildRaytracingAccelerationStructureBatched2X(GCL6*, UINT, BATCHED_DESC2*)` | 6 (8) | one layer build per element (§1), with its postbuild descriptions |
| `CopyRaytracingAccelerationStructure(GCL4*, dest, source, mode)` | 2 | the layer's copy |
| `RehydrateRaytracingAccelerationStructureBatched2X(GCL8*, UINT, BUILD_DESC*, UINT64*)` | 4 | `E_NOTIMPL` for now |

**Where it differs from the DLL:**
- **Stream records (§3):** they tune the console builder's heuristics, so they are ignored (logged once). The result
is still a valid BVH of the same geometry, in the node format the traversal shaders read.
- **Validation errors:** the DLL throws them as C++ exceptions. A shim must not throw into the title, so an element
the DLL would refuse is skipped with a log line. The offline-statistics postbuild type (`0x10`, §4) is one of
those.
- **Rehydration** is the next step: rebuild each structure on the GPU from the source geometry its description
carries ([bvh.md](bvh.md) §4a), in the leaf frame `compressionParams` gives.

`xbox_bvh_builder_test` calls every export through the shim registry, the way the title's imports bind, and
`xdxr_bvh.py check-build` checks the BLAS, TLAS and compacted BLAS it builds (ctest `xbox_bvh_builder_check`).

## 5. What is still open

- The names of the stream record types and of their values.
Expand Down
19 changes: 19 additions & 0 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ if(WIN32 AND LEONIDA_BUILD_WINDOWS_RUNTIME)
shims/xgameruntime_gamesave.cpp
shims/xgameruntime_store.cpp
shims/xgameruntime_offline.cpp
shims/xbox_bvh_builder.cpp
shims/library_loader.cpp
shims/process.cpp
)
Expand Down Expand Up @@ -1545,6 +1546,24 @@ if(TARGET Vulkan::Headers)
set_tests_properties(d3d12_xdxr_rt_check PROPERTIES FIXTURES_REQUIRED d3d12_xdxr_cases SKIP_RETURN_CODE 77)
endif()

# XboxBvhBuilder.dll served by the layer's builder (RT-5, boot stop 18): the seven exports the executable imports,
# through the shim registry as the title binds them; the structures are checked like d3d12_xdxr_rt's.
set(LEONIDA_XBOX_BVH_BUILDER_OUT "${CMAKE_CURRENT_BINARY_DIR}/xbox_bvh_builder_cases")
add_executable(xbox_bvh_builder_test test/xbox_bvh_builder_test.cpp shims/xbox_bvh_builder.cpp shims/registry.cpp)
target_link_libraries(xbox_bvh_builder_test PRIVATE gta6rt_d3d12_com)
target_compile_definitions(xbox_bvh_builder_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX)
target_compile_options(xbox_bvh_builder_test PRIVATE /W4 /permissive- /utf-8)
target_link_options(xbox_bvh_builder_test PRIVATE /OPT:NOREF)
add_test(NAME xbox_bvh_builder COMMAND xbox_bvh_builder_test "${LEONIDA_XBOX_BVH_BUILDER_OUT}")
set_tests_properties(xbox_bvh_builder PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60 FIXTURES_SETUP xbox_bvh_builder_cases)
add_test(NAME xbox_bvh_builder_console COMMAND xbox_bvh_builder_test --console)
set_tests_properties(xbox_bvh_builder_console PROPERTIES ENVIRONMENT "LEONIDA_BVH_BUILDER=console")
if(Python3_FOUND)
add_test(NAME xbox_bvh_builder_check COMMAND "${Python3_EXECUTABLE}" -I
"${CMAKE_CURRENT_SOURCE_DIR}/../tools/xdxr_bvh.py" check-build "${LEONIDA_XBOX_BVH_BUILDER_OUT}" --rays 1000)
set_tests_properties(xbox_bvh_builder_check PROPERTIES FIXTURES_REQUIRED xbox_bvh_builder_cases SKIP_RETURN_CODE 77)
endif()

# GCL8's QueryInterface and its one method need an allocator and a list, not a Vulkan device.
add_executable(d3d12_gcl8_test test/d3d12_gcl8_test.cpp)
target_link_libraries(d3d12_gcl8_test PRIVATE gta6rt_d3d12_com)
Expand Down
2 changes: 2 additions & 0 deletions runtime/shims/d3d12_xs_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,8 @@ unsigned detect_slot_count(ID3D12Device* real) {

} // namespace

IUnknown* real_object_behind_proxy(const void* object) { return proxy_real_object(object); }

HRESULT create_device_proxy(ID3D12Device* real, REFIID riid, void** out) {
if (!real) return E_POINTER;
if (!out) return E_POINTER;
Expand Down
5 changes: 5 additions & 0 deletions runtime/shims/d3d12_xs_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ unsigned device_proxy_slot_count(const void* device);
// The PC device behind a proxy. Null when `device` is not a proxy.
ID3D12Device* device_proxy_real_device(const void* device);

// The real object behind any of the child proxies (heap, queue, fence, allocator, and a kind added later, such as a
// console command-list proxy, which joins proxy_real_object), or null when `object` is none of them. For code outside
// this file that is handed a title's object, like the XboxBvhBuilder shim's command lists.
IUnknown* real_object_behind_proxy(const void* object);

// True for slots the proxy handles itself rather than forwarding verbatim: IUnknown (0-2), 8 and 75 (queue
// proxies), 9 (allocator proxies), 14, 31/34/35/45/46/50 (proxies unwrapped), 32 and 36 (fence proxies), 48/73 and
// 78/79/80 (the Xbox slots above, at their configured indices), 62, 67 and 76. Slot 10 is intentionally false: the
Expand Down
Loading
Loading