Skip to content
Merged
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
21 changes: 18 additions & 3 deletions docs/xdxr.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,31 @@ static reference, reached through a table (#7516), so 2 of them are calls of ano
| `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 |
| `RehydrateRaytracingAccelerationStructureBatched2X(GCL8*, UINT, BUILD_DESC*, UINT64*)` | 4 | rebuilds each structure from source geometry; refuses source-only stream without geometry |

**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.
- **Rehydration (`RehydrateRaytracingAccelerationStructureBatched2X`):** Rebuilds each structure on the GPU from
the source geometry its description carries ([bvh.md](bvh.md) §4a). The leaf frame `compressionParams` gives is
**not applied yet**: the leaves are built from the geometry as the description has it.
What the 4th parameter (`const UINT64* source_data`, mangling `PEB_K`) conveys is a **hypothesis**: it points to
the array of source buffer addresses for offline dehydrated console streams (e.g. rehydration inputs).
When geometry is provided (`NumDescs > 0`), the shim issues `BuildRaytracingAccelerationStructure` to construct
traversable GPU BVH nodes. That is a fresh build: the title sets `SourceAccelerationStructureData` to the
dehydrated stream, so the shim clears it and the `PERFORM_UPDATE` flag (logged once), which would otherwise make
the layer refit from the stream's bytes. The title passes `ScratchAccelerationStructureData = 0` (measured on the retail
title), so the shim supplies scratch, or the layer would reject the build: one new buffer per call, in which each
element has its own 256-byte-aligned region sized via `GetRaytracingAccelerationStructurePrebuildInfo`. The
layer's XDXR builder leaves the dependency between builds to the caller's barrier and the title puts none between
the elements of a batch, so no two builds, in a batch, on one list or on lists recorded in parallel, share scratch
bytes. The layer's command list holds the buffer until it is Reset or released, and the layer destroys it after
the submission that used it has retired. When `source_data` is supplied without geometry, the shim logs once and
refuses with `E_NOTIMPL`: offline console dehydrated streams cannot be directly deserialized by PC Vulkan/D3D12
drivers ([bvh.md](bvh.md) §4/§4a). Empty structures (`NumDescs == 0` without source) are logged and skipped.

`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`).
Expand Down
3 changes: 2 additions & 1 deletion runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2457,7 +2457,8 @@ if(TARGET Vulkan::Headers)
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)
# LEONIDA_VULKAN_DEVICE: the shim hands its rehydration scratch to the layer's list, as in gta6rt.
target_compile_definitions(xbox_bvh_builder_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX LEONIDA_VULKAN_DEVICE)
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}")
Expand Down
15 changes: 13 additions & 2 deletions runtime/shims/d3d12_com.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,11 @@ class GraphicsCommandList final
const leonida::CommandList& commands() const { return list_; }
// The descriptor tables this recording binds (console VAs), for the scan before a submission.
const std::vector<std::pair<std::uint64_t, std::uint32_t>>& tables() const { return tables_; }
// The pipeline states and root signatures the recording names (it holds a reference to each until Reset).
// The pipeline states and root signatures the recording names (it holds a reference to each until Reset), and
// the objects a shim handed it with hold_until_reset.
const std::vector<IUnknown*>& pinned() const { return held_; }
// rt::d3d12::hold_until_reset: an object the recording uses that its caller does not keep (a shim's own scratch).
void hold_for_recording(IUnknown* object) { hold(object); }
bool needs_all_sampled_views() const {
if (directly_indexed_) return true;
for (const auto& command : list_.commands()) {
Expand Down Expand Up @@ -2178,7 +2181,8 @@ class CommandQueue final

// What a held batch (queue_holds.h) keeps alive until it has run: the pipeline states and root signatures its
// lists name, which the application may release and Reset away as soon as ExecuteCommandLists returns. Resources
// are not held (a D3D12 application keeps them until the fence it signals; the docs, section 4.4, list this).
// are not held (a D3D12 application keeps them until the fence it signals; the docs, section 4.4, list this),
// except a shim's own the recording uses (hold_until_reset), which are pinned with them.
static std::shared_ptr<void> pin_lists(const std::vector<const GraphicsCommandList*>& lists) {
auto objects = std::shared_ptr<std::vector<IUnknown*>>(new std::vector<IUnknown*>, [](auto* held) {
for (IUnknown* object : *held) object->Release();
Expand Down Expand Up @@ -2807,6 +2811,13 @@ bool front_back_stencil_ref(ID3D12GraphicsCommandList8* list, UINT& front, UINT&
return true;
}

bool hold_until_reset(ID3D12GraphicsCommandList* list, IUnknown* object) {
GraphicsCommandList* l = GraphicsCommandList::from(list);
if (!l || !object) return false;
l->hold_for_recording(object);
return true;
}

bool recorded_commands(ID3D12GraphicsCommandList* list, std::vector<leonida::Command>& commands) {
const GraphicsCommandList* l = GraphicsCommandList::from(list);
if (!l) return false;
Expand Down
8 changes: 8 additions & 0 deletions runtime/shims/d3d12_com.h
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,14 @@ void set_global_realtime_privilege_override_for_test(int state);
// not one of this module's command lists.
bool front_back_stencil_ref(ID3D12GraphicsCommandList8* list, UINT& front, UINT& back);

// Makes `list` hold a reference to `object` until its next Reset or its release, as it holds the pipeline states it
// names: for an object only the recording uses, such as a shim's own scratch buffer. A list is Reset once it has
// been executed (or a held batch, src/queue_holds.h, keeps it pinned until it has run), and a resource released
// after its submission is destroyed through the device's deferred queue once that submission has retired, so the
// object outlives every GPU use the recording makes of it. False when `list` is not one of this module's command
// lists or `object` is null.
bool hold_until_reset(ID3D12GraphicsCommandList* list, IUnknown* object);

// A copy of the commands `list` has recorded so far, for tests of what a bundle puts into its parent. False when
// `list` is not one of this module's command lists.
bool recorded_commands(ID3D12GraphicsCommandList* list, std::vector<leonida::Command>& commands);
Expand Down
Loading
Loading