GPU: deferred CopyBufferRegion can read stale CPU memory before preceding GPU writes complete #2781

Open
opened 2026-11-26 05:14:01 +00:00 by github-bot · 4 comments
Owner

@⁠FunWithFlagsDev on GitHub · 2026-11-25 20:21 UTC · original

<html>

Summary

While investigating the remaining blockers in upstream BVH construction following #2750, I identified a potential command-ordering defect in the implementation of CopyBufferRegion.

A buffer copy recorded after GPU work that writes its source can execute against stale CPU-side title memory before the preceding GPU work has even been submitted.

The same ordering hazard appears possible across different command lists prepared within one host submission.

This report includes source-level evidence, an asset-free differential model, and a proposed native regression test.

1. Source-level evidence

Upstream revision inspected:

13f91caee25f2fdf2c062be5f7a27f058e51cbca

CopyBufferRegion is deferred to CPU execution

crates/victory-gpu/src/list.rs:626–640

if let Some(list) = host_list(this)
    && let Some(to) = buffer_range(dst, dst_offset, len)
    && let Some(from) = buffer_range(src, src_offset, len)
{
    list.defer_copy(to, from, len as usize);
}

The operation becomes a deferred CPU copy rather than an ordered GPU copy.

host.rs:2024

deferred.copies.push(
    Step::Copy(dst as usize, src as usize, len)
);

Deferred copies execute before GPU submission

host.rs:2271–2300

&Step::Copy(dst, src, len) => {
    // ...
    batch.title_written();
    copy_mapped(
        dst as *mut u8,
        src as *const u8,
        len,
        true
    );
    len
}

All participating lists have their deferred steps processed before the host executes the GPU command lists.

See host.rs:1207–1255.

GPU-produced results are subsequently copied back into title memory after GPU completion.

See host.rs:1304–1390.

2. Ordering mismatch

Consider the following synthetic command sequence:

Initial source = OLD
Initial destination = SENTINEL

Dispatch: source = NEW
CopyBufferRegion: destination = source

Expected execution:

GPU produces NEW
Copy consumes NEW
Destination contains NEW

Potential current execution:

CPU deferred copy consumes OLD
GPU produces NEW
GPU results are copied back
Destination still contains OLD

The producer and consumer can therefore observe an ordering different from the recorded command sequence.

This is not limited to a single command list:

List A: GPU writes source
List B: CopyBufferRegion reads source

ExecuteCommandLists([A, B])

Because the deferred preparation of both lists precedes GPU execution, list B may consume stale CPU-side bytes.

3. Relevance to BVH construction

Fxceless's ray-tracing work independently identifies this mechanism:

https://github.com/fxceless/victory-fork/pull/994

That PR describes the title copying acceleration-structure compacted sizes from buffers written by preceding builder dispatches.

When those copies execute on the CPU during submission preparation, they may consume previous-frame values or zeros instead of the newly generated sizes.

The fork implements selected copies directly on the GPU behind the producing shaders.

Relevant implementation:

This may represent an additional upstream BVH blocker independent of the DispatchX thread-count investigation in #2750.

Its actual contribution to incomplete BVH construction in upstream has not yet been measured.

4. Asset-free differential model

The attached archive contains a Python ordering model covering 24 synthetic scenarios evaluated under four policies.

The scenarios include:

  • GPU producer and CPU copy within the same list.

  • Producer and consumer in separate lists within the same submission.

  • Separate submissions.

  • CPU-produced source data.

  • Reversed producer/consumer ordering.

  • Disjoint source ranges.

Results:

Policy Matching reference Divergent
Reference command order 24 0
Current deferred preparation model 22 2
Ordered GPU copy 24 0
Split before dependent CPU copy 24 0

The test checks the GPU-produced value, CPU-side source after completion, destination value, and surrounding sentinel words.

All producer and sentinel controls must pass before the ordering invariant is evaluated.

Important scope limitations:

  • The producer is a real GPU buffer copy, not a translated shader.

  • The consumer exercises HostList::defer_copy, not the public COM CopyBufferRegion entry point.

  • The Rust test has not yet been compiled or executed.

  • The test intentionally requires a working D3D12 host rather than silently skipping.

A failed compilation, unavailable adapter, device removal, or failed producer control must not be interpreted as reproduction of the ordering defect.

6. Suggested reproduction

Use a dedicated checkout at the pinned upstream revision.

The included preparation script checks the exact commit and normalized Git blob hash of host.rs, then stages the test-only source modification without editing the checkout.

python prepare_probe.py C:/src/victory-audit C:/src/staged-probe

Review the staged host.rs before copying it into the dedicated checkout.

Run on WARP:

$env:VICTORY_D3D12_WARP = '1'

cargo test -p victory-gpu gpu_producer_must_precede_deferred_title_copy -- --nocapture --test-threads=1

An independent hardware run would also be useful.

Please report the adapter, driver, revision, debug-layer errors, and all three copy-order diagnostic lines.

The preparation script's source anchors and pinned blob were checked against public source. Full-checkout staging remains untested.

7. Existing related upstream work

Two existing PRs are particularly relevant:

  • #2608 — splits and flushes command-list segments after texture readbacks, addressing related same-list and same-batch ordering hazards.

  • #2240 — refreshes page-table-backed title memory after intervening CPU writes.

The mechanism investigated here concerns the opposite dependency direction: a CPU copy consuming a result produced by GPU work that has not completed.

Coordination with #2608 may allow reuse of its dependency-aware segmentation infrastructure instead of introducing another independent mechanism.

8. Possible correction strategies

A. Dependency-aware GPU copies

When a copy's source overlaps an earlier GPU-written range, record the copy on the GPU behind its producer.

This requires:

  • Correct resource barriers.

  • Source and destination lifetime retention.

  • Destination write tracking and copy-back.

  • Correct handling of overlapping resource regions and memory aliases.

B. Dependency-aware submission segmentation

Alternatively, split at a GPU-to-CPU dependency, execute the producer segment, complete its write-back, and only then perform the CPU copy.

This would need to preserve command-list state and ordering across multiple lists in one submission.

Neither strategy should force every buffer copy onto the GPU or introduce unnecessary fences.

Additional correctness requirement

Upstream already withholds selected GPU writes when programs using computed title addresses encounter missing memory.

A dependent copy must not bypass that protection by committing results whose validity has been withheld.

Similarly, falling back to a stale CPU copy after detecting a known GPU dependency would reintroduce the original ordering hazard.

9. Requested verification

Could an independent tester run the proposed synthetic regression on the pinned revision?

If the ordering mismatch is reproduced, I suggest:

  1. Adding a shader-backed producer regression.

  2. Extending coverage to the actual CopyBufferRegion entry point.

  3. Testing same-list and same-submission dependencies.

  4. Reviewing integration with #2608.

  5. Evaluating the effect on BVH compacted-size readbacks after the remaining builder prerequisites are available.

Attachment

bvh_copy_order_audit.zip

Contents:

  • README.md

  • model.py

  • test_model.py

  • matrix.csv

  • results.txt

  • native_probe.rs

  • prepare_probe.py

Python reproduction:

python model.py
python -m unittest -v test_model

Credits and limitations

Credit to the Fxceless contributors for identifying the compacted-size copy hazard and implementing the ordered GPU-copy approach in #994.

This comparative investigation and its synthetic regression proposal were developed with AI assistance using ChatGPT.

No proprietary game assets, executable files, console SDK headers, shader dumps, or game captures were used or included.

Only public source inspection and Python-based synthetic validation were performed by this investigation. Native D3D12 reproduction remains pending.

This report does not claim that the identified ordering hazard is the sole cause of incomplete upstream BVH construction.

</html>## Summary

While investigating the remaining blockers in upstream BVH construction following #2750, I identified a potential command-ordering defect in the implementation of CopyBufferRegion.

A buffer copy recorded after GPU work that writes its source can execute against stale CPU-side title memory before the preceding GPU work has even been submitted.

The same ordering hazard appears possible across different command lists prepared within one host submission.

This report includes source-level evidence, an asset-free differential model, and a proposed native regression test.

1. Source-level evidence

Upstream revision inspected:

13f91caee25f2fdf2c062be5f7a27f058e51cbca

CopyBufferRegion is deferred to CPU execution

[crates/victory-gpu/src/list.rs:626–640](https://github.com/Marvisak/VIctory/blob/13f91cae/crates/victory-gpu/src/list.rs#L626-L640)

if let Some(list) = host_list(this)
    && let Some(to) = buffer_range(dst, dst_offset, len)
    && let Some(from) = buffer_range(src, src_offset, len)
{
    list.defer_copy(to, from, len as usize);
}

The operation becomes a deferred CPU copy rather than an ordered GPU copy.

[host.rs:2024](https://github.com/Marvisak/VIctory/blob/13f91cae/crates/victory-gpu/src/host.rs#L2024)

deferred.copies.push(
    Step::Copy(dst as usize, src as usize, len)
);

Deferred copies execute before GPU submission

[host.rs:2271–2300](https://github.com/Marvisak/VIctory/blob/13f91cae/crates/victory-gpu/src/host.rs#L2271-L2300)

&Step::Copy(dst, src, len) => {
    // ...
    batch.title_written();
    copy_mapped(
        dst as *mut u8,
        src as *const u8,
        len,
        true
    );
    len
}

All participating lists have their deferred steps processed before the host executes the GPU command lists.

See [host.rs:1207–1255](https://github.com/Marvisak/VIctory/blob/13f91cae/crates/victory-gpu/src/host.rs#L1207-L1255).

GPU-produced results are subsequently copied back into title memory after GPU completion.

See [host.rs:1304–1390](https://github.com/Marvisak/VIctory/blob/13f91cae/crates/victory-gpu/src/host.rs#L1304-L1390).

2. Ordering mismatch

Consider the following synthetic command sequence:

Initial source = OLD
Initial destination = SENTINEL

Dispatch: source = NEW
CopyBufferRegion: destination = source

Expected execution:

GPU produces NEW
Copy consumes NEW
Destination contains NEW

Potential current execution:

CPU deferred copy consumes OLD
GPU produces NEW
GPU results are copied back
Destination still contains OLD

The producer and consumer can therefore observe an ordering different from the recorded command sequence.

This is not limited to a single command list:

List A: GPU writes source
List B: CopyBufferRegion reads source

ExecuteCommandLists([A, B])

Because the deferred preparation of both lists precedes GPU execution, list B may consume stale CPU-side bytes.

3. Relevance to BVH construction

Fxceless's ray-tracing work independently identifies this mechanism:

https://github.com/fxceless/victory-fork/pull/994

That PR describes the title copying acceleration-structure compacted sizes from buffers written by preceding builder dispatches.

When those copies execute on the CPU during submission preparation, they may consume previous-frame values or zeros instead of the newly generated sizes.

The fork implements selected copies directly on the GPU behind the producing shaders.

Relevant implementation:

This may represent an additional upstream BVH blocker independent of the DispatchX thread-count investigation in #2750.

Its actual contribution to incomplete BVH construction in upstream has not yet been measured.

4. Asset-free differential model

The attached archive contains a Python ordering model covering 24 synthetic scenarios evaluated under four policies.

The scenarios include:

  • GPU producer and CPU copy within the same list.
  • Producer and consumer in separate lists within the same submission.
  • Separate submissions.
  • CPU-produced source data.
  • Reversed producer/consumer ordering.
  • Disjoint source ranges.

Results:

Policy Matching reference Divergent
Reference command order 24 0
Current deferred preparation model 22 2
Ordered GPU copy 24 0
Split before dependent CPU copy 24 0

All nine Python unit tests passed.

Both divergences occur when a CPU copy consumes an overlapping result produced by preceding GPU work in the same submission.

These results validate the modeled ordering hazard. They are not measurements of its frequency in the title.

The alternative policies are idealized ordering strategies, not validated production implementations.

5. Proposed native regression

The archive also includes a proposed test-only addition to the existing host::batch test module.

Test name:

gpu_producer_must_precede_deferred_title_copy

The test initializes independent synthetic memory pools with:

OLD      = 0x11111111
NEW      = 0x22222222
SENTINEL = 0x5A5A5A5A

An actual D3D12 buffer copy produces NEW in the source shadow.

The consumer uses the production HostList::defer_copy path.

Three execution arrangements are compared:

Arrangement Expected destination Predicted on current main
Same list 22222222 11111111
Different lists, same submission 22222222 11111111
Separate submissions 22222222 22222222

The test checks the GPU-produced value, CPU-side source after completion, destination value, and surrounding sentinel words.

All producer and sentinel controls must pass before the ordering invariant is evaluated.

Important scope limitations:

  • The producer is a real GPU buffer copy, not a translated shader.
  • The consumer exercises HostList::defer_copy, not the public COM CopyBufferRegion entry point.
  • The Rust test has not yet been compiled or executed.
  • The test intentionally requires a working D3D12 host rather than silently skipping.

A failed compilation, unavailable adapter, device removal, or failed producer control must not be interpreted as reproduction of the ordering defect.

6. Suggested reproduction

Use a dedicated checkout at the pinned upstream revision.

The included preparation script checks the exact commit and normalized Git blob hash of host.rs, then stages the test-only source modification without editing the checkout.

python prepare_probe.py C:/src/victory-audit C:/src/staged-probe

Review the staged host.rs before copying it into the dedicated checkout.

Run on WARP:

$env:VICTORY_D3D12_WARP = '1'

cargo test -p victory-gpu gpu_producer_must_precede_deferred_title_copy -- --nocapture --test-threads=1

An independent hardware run would also be useful.

Please report the adapter, driver, revision, debug-layer errors, and all three copy-order diagnostic lines.

The preparation script's source anchors and pinned blob were checked against public source. Full-checkout staging remains untested.

Two existing PRs are particularly relevant:

  • #2608 — splits and flushes command-list segments after texture readbacks, addressing related same-list and same-batch ordering hazards.
  • #2240 — refreshes page-table-backed title memory after intervening CPU writes.

The mechanism investigated here concerns the opposite dependency direction: a CPU copy consuming a result produced by GPU work that has not completed.

Coordination with #2608 may allow reuse of its dependency-aware segmentation infrastructure instead of introducing another independent mechanism.

8. Possible correction strategies

A. Dependency-aware GPU copies

When a copy's source overlaps an earlier GPU-written range, record the copy on the GPU behind its producer.

This requires:

  • Correct resource barriers.
  • Source and destination lifetime retention.
  • Destination write tracking and copy-back.
  • Correct handling of overlapping resource regions and memory aliases.

B. Dependency-aware submission segmentation

Alternatively, split at a GPU-to-CPU dependency, execute the producer segment, complete its write-back, and only then perform the CPU copy.

This would need to preserve command-list state and ordering across multiple lists in one submission.

Neither strategy should force every buffer copy onto the GPU or introduce unnecessary fences.

Additional correctness requirement

Upstream already withholds selected GPU writes when programs using computed title addresses encounter missing memory.

A dependent copy must not bypass that protection by committing results whose validity has been withheld.

Similarly, falling back to a stale CPU copy after detecting a known GPU dependency would reintroduce the original ordering hazard.

9. Requested verification

Could an independent tester run the proposed synthetic regression on the pinned revision?

If the ordering mismatch is reproduced, I suggest:

  1. Adding a shader-backed producer regression.
  2. Extending coverage to the actual CopyBufferRegion entry point.
  3. Testing same-list and same-submission dependencies.
  4. Reviewing integration with #2608.
  5. Evaluating the effect on BVH compacted-size readbacks after the remaining builder prerequisites are available.

Attachment

bvh_copy_order_audit.zip

Contents:

  • README.md
  • model.py
  • test_model.py
  • matrix.csv
  • results.txt
  • native_probe.rs
  • prepare_probe.py

Python reproduction:

python model.py
python -m unittest -v test_model

Credits and limitations

Credit to the Fxceless contributors for identifying the compacted-size copy hazard and implementing the ordered GPU-copy approach in #994.

bvh_copy_order_audit.zip

No proprietary game assets, executable files, console SDK headers, shader dumps, or game captures were used or included.

Only public source inspection and Python-based synthetic validation were performed by this investigation. Native D3D12 reproduction remains pending.

This report does not claim that the identified ordering hazard is the sole cause of incomplete upstream BVH construction.

**@⁠FunWithFlagsDev** on GitHub · 2026-11-25 20:21 UTC · [original](https://github.com/Marvisak/VIctory/issues/2781) <html> <body> <!--StartFragment--><h2><span>Summary</span></h2><p><span>While investigating the remaining blockers in upstream BVH construction following #2750, I identified a potential command-ordering defect in the implementation of </span><code><span>CopyBufferRegion</span></code><span>.</span></p><p><span>A buffer copy recorded after GPU work that writes its source can execute against stale CPU-side title memory before the preceding GPU work has even been submitted.</span></p><p><span>The same ordering hazard appears possible across different command lists prepared within one host submission.</span></p><p><span>This report includes source-level evidence, an asset-free differential model, and a proposed native regression test.</span></p><h2><span>1. Source-level evidence</span></h2><p><span>Upstream revision inspected:</span></p><p><code><span>13f91caee25f2fdf2c062be5f7a27f058e51cbca</span></code></p><h3><span>CopyBufferRegion is deferred to CPU execution</span></h3><p><a href="https://github.com/Marvisak/VIctory/blob/13f91cae/crates/victory-gpu/src/list.rs#L626-L640"><code><span>crates/victory-gpu/src/list.rs:626–640</span></code></a></p><pre><code><span>if let Some(list) = host_list(this) &amp;&amp; let Some(to) = buffer_range(dst, dst_offset, len) &amp;&amp; let Some(from) = buffer_range(src, src_offset, len) { list.defer_copy(to, from, len as usize); }</span></code></pre><p><span>The operation becomes a deferred CPU copy rather than an ordered GPU copy.</span></p><p><a href="https://github.com/Marvisak/VIctory/blob/13f91cae/crates/victory-gpu/src/host.rs#L2024"><code><span>host.rs:2024</span></code></a></p><pre><code><span>deferred.copies.push( Step::Copy(dst as usize, src as usize, len) );</span></code></pre><h3><span>Deferred copies execute before GPU submission</span></h3><p><a href="https://github.com/Marvisak/VIctory/blob/13f91cae/crates/victory-gpu/src/host.rs#L2271-L2300"><code><span>host.rs:2271–2300</span></code></a></p><pre><code><span>&amp;Step::Copy(dst, src, len) =&gt; { // ... batch.title_written(); copy_mapped( dst as *mut u8, src as *const u8, len, true ); len }</span></code></pre><p><span>All participating lists have their deferred steps processed before the host executes the GPU command lists.</span></p><p><span>See </span><a href="https://github.com/Marvisak/VIctory/blob/13f91cae/crates/victory-gpu/src/host.rs#L1207-L1255"><code><span>host.rs:1207–1255</span></code></a><span>.</span></p><p><span>GPU-produced results are subsequently copied back into title memory after GPU completion.</span></p><p><span>See </span><a href="https://github.com/Marvisak/VIctory/blob/13f91cae/crates/victory-gpu/src/host.rs#L1304-L1390"><code><span>host.rs:1304–1390</span></code></a><span>.</span></p><h2><span>2. Ordering mismatch</span></h2><p><span>Consider the following synthetic command sequence:</span></p><pre><code><span>Initial source = OLD Initial destination = SENTINEL Dispatch: source = NEW CopyBufferRegion: destination = source</span></code></pre><p><span>Expected execution:</span></p><pre><code><span>GPU produces NEW Copy consumes NEW Destination contains NEW</span></code></pre><p><span>Potential current execution:</span></p><pre><code><span>CPU deferred copy consumes OLD GPU produces NEW GPU results are copied back Destination still contains OLD</span></code></pre><p><span>The producer and consumer can therefore observe an ordering different from the recorded command sequence.</span></p><p><span>This is not limited to a single command list:</span></p><pre><code><span>List A: GPU writes source List B: CopyBufferRegion reads source ExecuteCommandLists([A, B])</span></code></pre><p><span>Because the deferred preparation of both lists precedes GPU execution, list B may consume stale CPU-side bytes.</span></p><h2><span>3. Relevance to BVH construction</span></h2><p><span>Fxceless's ray-tracing work independently identifies this mechanism:</span></p><p><a href="https://github.com/fxceless/victory-fork/pull/994"><span>https://github.com/fxceless/victory-fork/pull/994</span></a></p><p><span>That PR describes the title copying acceleration-structure compacted sizes from buffers written by preceding builder dispatches.</span></p><p><span>When those copies execute on the CPU during submission preparation, they may consume previous-frame values or zeros instead of the newly generated sizes.</span></p><p><span>The fork implements selected copies directly on the GPU behind the producing shaders.</span></p><p><span>Relevant implementation:</span></p><ul><li><p><a href="https://github.com/fxceless/victory-fork/blob/c9ca6b26119beb0eb39c0687cf85cc3f4a0e1ee1/crates/victory-gpu/src/list.rs#L816-L850"><span>Copy routing in list.rs</span></a></p></li><li><p><a href="https://github.com/fxceless/victory-fork/blob/c9ca6b26119beb0eb39c0687cf85cc3f4a0e1ee1/crates/victory-gpu/src/host.rs#L6436-L6501"><span>HostList::copy_on_card and shaders_wrote</span></a></p></li></ul><p><span>This may represent an additional upstream BVH blocker independent of the </span><code><span>DispatchX</span></code><span> thread-count investigation in #2750.</span></p><p><span>Its actual contribution to incomplete BVH construction in upstream has not yet been measured.</span></p><h2><span>4. Asset-free differential model</span></h2><p><span>The attached archive contains a Python ordering model covering 24 synthetic scenarios evaluated under four policies.</span></p><p><span>The scenarios include:</span></p><ul><li><p><span>GPU producer and CPU copy within the same list.</span></p></li><li><p><span>Producer and consumer in separate lists within the same submission.</span></p></li><li><p><span>Separate submissions.</span></p></li><li><p><span>CPU-produced source data.</span></p></li><li><p><span>Reversed producer/consumer ordering.</span></p></li><li><p><span>Disjoint source ranges.</span></p></li></ul><p><span>Results:</span></p> Policy | Matching reference | Divergent -- | -- | -- Reference command order | 24 | 0 Current deferred preparation model | 22 | 2 Ordered GPU copy | 24 | 0 Split before dependent CPU copy | 24 | 0 <p><span>The test checks the GPU-produced value, CPU-side source after completion, destination value, and surrounding sentinel words.</span></p><p><span>All producer and sentinel controls must pass before the ordering invariant is evaluated.</span></p><p><span>Important scope limitations:</span></p><ul><li><p><span>The producer is a real GPU buffer copy, not a translated shader.</span></p></li><li><p><span>The consumer exercises </span><code><span>HostList::defer_copy</span></code><span>, not the public COM </span><code><span>CopyBufferRegion</span></code><span> entry point.</span></p></li><li><p><span>The Rust test has not yet been compiled or executed.</span></p></li><li><p><span>The test intentionally requires a working D3D12 host rather than silently skipping.</span></p></li></ul><p><span>A failed compilation, unavailable adapter, device removal, or failed producer control must not be interpreted as reproduction of the ordering defect.</span></p><h2><span>6. Suggested reproduction</span></h2><p><span>Use a dedicated checkout at the pinned upstream revision.</span></p><p><span>The included preparation script checks the exact commit and normalized Git blob hash of </span><code><span>host.rs</span></code><span>, then stages the test-only source modification without editing the checkout.</span></p><pre><code><span>python prepare_probe.py C:/src/victory-audit C:/src/staged-probe</span></code></pre><p><span>Review the staged </span><code><span>host.rs</span></code><span> before copying it into the dedicated checkout.</span></p><p><span>Run on WARP:</span></p><pre><code><span>$env:VICTORY_D3D12_WARP = '1' cargo test -p victory-gpu gpu_producer_must_precede_deferred_title_copy -- --nocapture --test-threads=1</span></code></pre><p><span>An independent hardware run would also be useful.</span></p><p><span>Please report the adapter, driver, revision, debug-layer errors, and all three </span><code><span>copy-order</span></code><span> diagnostic lines.</span></p><p><span>The preparation script's source anchors and pinned blob were checked against public source. Full-checkout staging remains untested.</span></p><h2><span>7. Existing related upstream work</span></h2><p><span>Two existing PRs are particularly relevant:</span></p><ul><li><p><span>#2608 — splits and flushes command-list segments after texture readbacks, addressing related same-list and same-batch ordering hazards.</span></p></li><li><p><span>#2240 — refreshes page-table-backed title memory after intervening CPU writes.</span></p></li></ul><p><span>The mechanism investigated here concerns the opposite dependency direction: a CPU copy consuming a result produced by GPU work that has not completed.</span></p><p><span>Coordination with #2608 may allow reuse of its dependency-aware segmentation infrastructure instead of introducing another independent mechanism.</span></p><h2><span>8. Possible correction strategies</span></h2><h3><span>A. Dependency-aware GPU copies</span></h3><p><span>When a copy's source overlaps an earlier GPU-written range, record the copy on the GPU behind its producer.</span></p><p><span>This requires:</span></p><ul><li><p><span>Correct resource barriers.</span></p></li><li><p><span>Source and destination lifetime retention.</span></p></li><li><p><span>Destination write tracking and copy-back.</span></p></li><li><p><span>Correct handling of overlapping resource regions and memory aliases.</span></p></li></ul><h3><span>B. Dependency-aware submission segmentation</span></h3><p><span>Alternatively, split at a GPU-to-CPU dependency, execute the producer segment, complete its write-back, and only then perform the CPU copy.</span></p><p><span>This would need to preserve command-list state and ordering across multiple lists in one submission.</span></p><p><span>Neither strategy should force every buffer copy onto the GPU or introduce unnecessary fences.</span></p><h3><span>Additional correctness requirement</span></h3><p><span>Upstream already withholds selected GPU writes when programs using computed title addresses encounter missing memory.</span></p><p><span>A dependent copy must not bypass that protection by committing results whose validity has been withheld.</span></p><p><span>Similarly, falling back to a stale CPU copy after detecting a known GPU dependency would reintroduce the original ordering hazard.</span></p><h2><span>9. Requested verification</span></h2><p><span>Could an independent tester run the proposed synthetic regression on the pinned revision?</span></p><p><span>If the ordering mismatch is reproduced, I suggest:</span></p><ol start="1"><li><p><span>Adding a shader-backed producer regression.</span></p></li><li><p><span>Extending coverage to the actual </span><code><span>CopyBufferRegion</span></code><span> entry point.</span></p></li><li><p><span>Testing same-list and same-submission dependencies.</span></p></li><li><p><span>Reviewing integration with #2608.</span></p></li><li><p><span>Evaluating the effect on BVH compacted-size readbacks after the remaining builder prerequisites are available.</span></p></li></ol><h2><span>Attachment</span></h2><p><code><span>bvh_copy_order_audit.zip</span></code></p><p><span>Contents:</span></p><ul><li><p><code><span>README.md</span></code></p></li><li><p><code><span>model.py</span></code></p></li><li><p><code><span>test_model.py</span></code></p></li><li><p><code><span>matrix.csv</span></code></p></li><li><p><code><span>results.txt</span></code></p></li><li><p><code><span>native_probe.rs</span></code></p></li><li><p><code><span>prepare_probe.py</span></code></p></li></ul><p><span>Python reproduction:</span></p><pre><code><span>python model.py python -m unittest -v test_model</span></code></pre><h2><span>Credits and limitations</span></h2><p><span>Credit to the Fxceless contributors for identifying the compacted-size copy hazard and implementing the ordered GPU-copy approach in #994.</span></p><p><span>This comparative investigation and its synthetic regression proposal were developed with AI assistance using ChatGPT.</span></p><p><span>No proprietary game assets, executable files, console SDK headers, shader dumps, or game captures were used or included.</span></p><p><span>Only public source inspection and Python-based synthetic validation were performed by this investigation. Native D3D12 reproduction remains pending.</span></p><p><span>This report does not claim that the identified ordering hazard is the sole cause of incomplete upstream BVH construction.</span></p><!--EndFragment--> </body> </html>## Summary While investigating the remaining blockers in upstream BVH construction following #2750, I identified a potential command-ordering defect in the implementation of `CopyBufferRegion`. A buffer copy recorded after GPU work that writes its source can execute against stale CPU-side title memory before the preceding GPU work has even been submitted. The same ordering hazard appears possible across different command lists prepared within one host submission. This report includes source-level evidence, an asset-free differential model, and a proposed native regression test. ## 1. Source-level evidence Upstream revision inspected: `13f91caee25f2fdf2c062be5f7a27f058e51cbca` ### CopyBufferRegion is deferred to CPU execution [`[crates/victory-gpu/src/list.rs:626–640](https://github.com/Marvisak/VIctory/blob/13f91cae/crates/victory-gpu/src/list.rs#L626-L640)`](https://github.com/Marvisak/VIctory/blob/13f91cae/crates/victory-gpu/src/list.rs#L626-L640) ```rust if let Some(list) = host_list(this) && let Some(to) = buffer_range(dst, dst_offset, len) && let Some(from) = buffer_range(src, src_offset, len) { list.defer_copy(to, from, len as usize); } ``` The operation becomes a deferred CPU copy rather than an ordered GPU copy. [`[host.rs:2024](https://github.com/Marvisak/VIctory/blob/13f91cae/crates/victory-gpu/src/host.rs#L2024)`](https://github.com/Marvisak/VIctory/blob/13f91cae/crates/victory-gpu/src/host.rs#L2024) ```rust deferred.copies.push( Step::Copy(dst as usize, src as usize, len) ); ``` ### Deferred copies execute before GPU submission [`[host.rs:2271–2300](https://github.com/Marvisak/VIctory/blob/13f91cae/crates/victory-gpu/src/host.rs#L2271-L2300)`](https://github.com/Marvisak/VIctory/blob/13f91cae/crates/victory-gpu/src/host.rs#L2271-L2300) ```rust &Step::Copy(dst, src, len) => { // ... batch.title_written(); copy_mapped( dst as *mut u8, src as *const u8, len, true ); len } ``` All participating lists have their deferred steps processed before the host executes the GPU command lists. See [`[host.rs:1207–1255](https://github.com/Marvisak/VIctory/blob/13f91cae/crates/victory-gpu/src/host.rs#L1207-L1255)`](https://github.com/Marvisak/VIctory/blob/13f91cae/crates/victory-gpu/src/host.rs#L1207-L1255). GPU-produced results are subsequently copied back into title memory after GPU completion. See [`[host.rs:1304–1390](https://github.com/Marvisak/VIctory/blob/13f91cae/crates/victory-gpu/src/host.rs#L1304-L1390)`](https://github.com/Marvisak/VIctory/blob/13f91cae/crates/victory-gpu/src/host.rs#L1304-L1390). ## 2. Ordering mismatch Consider the following synthetic command sequence: ```text Initial source = OLD Initial destination = SENTINEL Dispatch: source = NEW CopyBufferRegion: destination = source ``` Expected execution: ```text GPU produces NEW Copy consumes NEW Destination contains NEW ``` Potential current execution: ```text CPU deferred copy consumes OLD GPU produces NEW GPU results are copied back Destination still contains OLD ``` The producer and consumer can therefore observe an ordering different from the recorded command sequence. This is not limited to a single command list: ```text List A: GPU writes source List B: CopyBufferRegion reads source ExecuteCommandLists([A, B]) ``` Because the deferred preparation of both lists precedes GPU execution, list B may consume stale CPU-side bytes. ## 3. Relevance to BVH construction Fxceless's ray-tracing work independently identifies this mechanism: https://github.com/fxceless/victory-fork/pull/994 That PR describes the title copying acceleration-structure compacted sizes from buffers written by preceding builder dispatches. When those copies execute on the CPU during submission preparation, they may consume previous-frame values or zeros instead of the newly generated sizes. The fork implements selected copies directly on the GPU behind the producing shaders. Relevant implementation: - [[Copy routing in list.rs](https://github.com/fxceless/victory-fork/blob/c9ca6b26119beb0eb39c0687cf85cc3f4a0e1ee1/crates/victory-gpu/src/list.rs#L816-L850)](https://github.com/fxceless/victory-fork/blob/c9ca6b26119beb0eb39c0687cf85cc3f4a0e1ee1/crates/victory-gpu/src/list.rs#L816-L850) - [[HostList::copy_on_card and shaders_wrote](https://github.com/fxceless/victory-fork/blob/c9ca6b26119beb0eb39c0687cf85cc3f4a0e1ee1/crates/victory-gpu/src/host.rs#L6436-L6501)](https://github.com/fxceless/victory-fork/blob/c9ca6b26119beb0eb39c0687cf85cc3f4a0e1ee1/crates/victory-gpu/src/host.rs#L6436-L6501) This may represent an additional upstream BVH blocker independent of the `DispatchX` thread-count investigation in #2750. Its actual contribution to incomplete BVH construction in upstream has not yet been measured. ## 4. Asset-free differential model The attached archive contains a Python ordering model covering 24 synthetic scenarios evaluated under four policies. The scenarios include: - GPU producer and CPU copy within the same list. - Producer and consumer in separate lists within the same submission. - Separate submissions. - CPU-produced source data. - Reversed producer/consumer ordering. - Disjoint source ranges. Results: | Policy | Matching reference | Divergent | |---|---:|---:| | Reference command order | 24 | 0 | | Current deferred preparation model | 22 | 2 | | Ordered GPU copy | 24 | 0 | | Split before dependent CPU copy | 24 | 0 | All nine Python unit tests passed. Both divergences occur when a CPU copy consumes an overlapping result produced by preceding GPU work in the same submission. These results validate the modeled ordering hazard. They are not measurements of its frequency in the title. The alternative policies are idealized ordering strategies, not validated production implementations. ## 5. Proposed native regression The archive also includes a proposed test-only addition to the existing `host::batch` test module. Test name: `gpu_producer_must_precede_deferred_title_copy` The test initializes independent synthetic memory pools with: ```text OLD = 0x11111111 NEW = 0x22222222 SENTINEL = 0x5A5A5A5A ``` An actual D3D12 buffer copy produces `NEW` in the source shadow. The consumer uses the production `HostList::defer_copy` path. Three execution arrangements are compared: | Arrangement | Expected destination | Predicted on current main | |---|---|---| | Same list | `22222222` | `11111111` | | Different lists, same submission | `22222222` | `11111111` | | Separate submissions | `22222222` | `22222222` | The test checks the GPU-produced value, CPU-side source after completion, destination value, and surrounding sentinel words. All producer and sentinel controls must pass before the ordering invariant is evaluated. Important scope limitations: - The producer is a real GPU buffer copy, not a translated shader. - The consumer exercises `HostList::defer_copy`, not the public COM `CopyBufferRegion` entry point. - The Rust test has not yet been compiled or executed. - The test intentionally requires a working D3D12 host rather than silently skipping. A failed compilation, unavailable adapter, device removal, or failed producer control must not be interpreted as reproduction of the ordering defect. ## 6. Suggested reproduction Use a dedicated checkout at the pinned upstream revision. The included preparation script checks the exact commit and normalized Git blob hash of `host.rs`, then stages the test-only source modification without editing the checkout. ```powershell python prepare_probe.py C:/src/victory-audit C:/src/staged-probe ``` Review the staged `host.rs` before copying it into the dedicated checkout. Run on WARP: ```powershell $env:VICTORY_D3D12_WARP = '1' cargo test -p victory-gpu gpu_producer_must_precede_deferred_title_copy -- --nocapture --test-threads=1 ``` An independent hardware run would also be useful. Please report the adapter, driver, revision, debug-layer errors, and all three `copy-order` diagnostic lines. The preparation script's source anchors and pinned blob were checked against public source. Full-checkout staging remains untested. ## 7. Existing related upstream work Two existing PRs are particularly relevant: - #2608 — splits and flushes command-list segments after texture readbacks, addressing related same-list and same-batch ordering hazards. - #2240 — refreshes page-table-backed title memory after intervening CPU writes. The mechanism investigated here concerns the opposite dependency direction: a CPU copy consuming a result produced by GPU work that has not completed. Coordination with #2608 may allow reuse of its dependency-aware segmentation infrastructure instead of introducing another independent mechanism. ## 8. Possible correction strategies ### A. Dependency-aware GPU copies When a copy's source overlaps an earlier GPU-written range, record the copy on the GPU behind its producer. This requires: - Correct resource barriers. - Source and destination lifetime retention. - Destination write tracking and copy-back. - Correct handling of overlapping resource regions and memory aliases. ### B. Dependency-aware submission segmentation Alternatively, split at a GPU-to-CPU dependency, execute the producer segment, complete its write-back, and only then perform the CPU copy. This would need to preserve command-list state and ordering across multiple lists in one submission. Neither strategy should force every buffer copy onto the GPU or introduce unnecessary fences. ### Additional correctness requirement Upstream already withholds selected GPU writes when programs using computed title addresses encounter missing memory. A dependent copy must not bypass that protection by committing results whose validity has been withheld. Similarly, falling back to a stale CPU copy after detecting a known GPU dependency would reintroduce the original ordering hazard. ## 9. Requested verification Could an independent tester run the proposed synthetic regression on the pinned revision? If the ordering mismatch is reproduced, I suggest: 1. Adding a shader-backed producer regression. 2. Extending coverage to the actual `CopyBufferRegion` entry point. 3. Testing same-list and same-submission dependencies. 4. Reviewing integration with #2608. 5. Evaluating the effect on BVH compacted-size readbacks after the remaining builder prerequisites are available. ## Attachment `bvh_copy_order_audit.zip` Contents: - `README.md` - `model.py` - `test_model.py` - `matrix.csv` - `results.txt` - `native_probe.rs` - `prepare_probe.py` Python reproduction: ```bash python model.py python -m unittest -v test_model ``` ## Credits and limitations Credit to the Fxceless contributors for identifying the compacted-size copy hazard and implementing the ordered GPU-copy approach in #994. [bvh_copy_order_audit.zip](https://github.com/user-attachments/files/35432477/bvh_copy_order_audit.zip) No proprietary game assets, executable files, console SDK headers, shader dumps, or game captures were used or included. Only public source inspection and Python-based synthetic validation were performed by this investigation. Native D3D12 reproduction remains pending. This report does not claim that the identified ordering hazard is the sole cause of incomplete upstream BVH construction.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:14:01 +00:00
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 21:01 UTC · original

An asset-free WARP test now reproduces this through VIctory's guest CopyBufferRegion call. On 13f91ca the GPU writes 0x55667788 while the destination receives 0x11223344 in one list and in two lists of one submission. Separate submissions return 0x55667788.

I offered 34fc326 directly on #2608 head 5bf646428c48f4e2cd31a4063597e1c87d3a3d12. That head shows the same original results. The fix orders copies whose source overlaps a declared GPU write. The same test now returns 0x55667788 in all three layouts. Disjoint source ranges, a copy recorded before the write and surrounding sentinel words are unchanged. Six paired WARP runs and both full serial GPU suites passed on the fix, with 203 passed and one ignored per suite.

Please retain the Git author on cherry-pick or rebase. If folding the fix or test into another commit, please include the following trailer.

Co-authored-by: andrewpozdnakov7-jpg [email protected]

AI-assisted with Codex. Synthetic buffers on WARP.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 21:01 UTC · [original](https://github.com/Marvisak/VIctory/issues/2781#issuecomment-7174511971) An asset-free WARP test now reproduces this through VIctory's guest CopyBufferRegion call. On 13f91ca the GPU writes 0x55667788 while the destination receives 0x11223344 in one list and in two lists of one submission. Separate submissions return 0x55667788. I offered [34fc326](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/34fc326cdf19c7c286fc0413050640ff186c54f8) directly on #2608 head 5bf646428c48f4e2cd31a4063597e1c87d3a3d12. That head shows the same original results. The fix orders copies whose source overlaps a declared GPU write. The same test now returns 0x55667788 in all three layouts. Disjoint source ranges, a copy recorded before the write and surrounding sentinel words are unchanged. Six paired WARP runs and both full serial GPU suites passed on the fix, with 203 passed and one ignored per suite. Please retain the Git author on cherry-pick or rebase. If folding the fix or test into another commit, please include the following trailer. Co-authored-by: andrewpozdnakov7-jpg <[email protected]> AI-assisted with Codex. Synthetic buffers on WARP.
Author
Owner

@⁠Venom2054 on GitHub · 2026-11-25 21:09 UTC · original

I ran the proposed four-byte probe at upstream commit 13f91cae twice on each adapter. NVIDIA RTX 5070 Ti (621.01) and Microsoft WARP (10.0.26100.9818) returned the same three results. I built victory-gpu with the diagnostics feature and checked the selected adapter for each run.

Producer and copy GPU source CPU source after completion Destination
Same command list 0x22222222 0x22222222 0x11111111
Separate lists, same submission 0x22222222 0x22222222 0x11111111
Separate submissions 0x22222222 0x22222222 0x22222222

Both adjacent sentinels stayed at 0x5a5a5a5a and the device remained healthy. Only the final ordering assertion failed. On both adapters the debug queue already contained message #1419 about the sampler heap during host initialization, before creating the test buffers. After draining it, the three cases generated no further D3D12 error or corruption messages.

This verifies the proposed HostList::defer_copy probe on physical NVIDIA hardware as well as WARP, alongside the guest-entry WARP check above. My runs used the upstream revision before the proposed fix. For the public CopyBufferRegion entry point, #387 also has a real-queue test and fix results. I haven't measured the effect on in-game BVH construction.

**@⁠Venom2054** on GitHub · 2026-11-25 21:09 UTC · [original](https://github.com/Marvisak/VIctory/issues/2781#issuecomment-7174686167) I ran the proposed four-byte probe at upstream commit 13f91cae twice on each adapter. NVIDIA RTX 5070 Ti (621.01) and Microsoft WARP (10.0.26100.9818) returned the same three results. I built victory-gpu with the diagnostics feature and checked the selected adapter for each run. | Producer and copy | GPU source | CPU source after completion | Destination | |---|---|---|---| | Same command list | 0x22222222 | 0x22222222 | 0x11111111 | | Separate lists, same submission | 0x22222222 | 0x22222222 | 0x11111111 | | Separate submissions | 0x22222222 | 0x22222222 | 0x22222222 | Both adjacent sentinels stayed at 0x5a5a5a5a and the device remained healthy. Only the final ordering assertion failed. On both adapters the debug queue already contained message #1419 about the sampler heap during host initialization, before creating the test buffers. After draining it, the three cases generated no further D3D12 error or corruption messages. This verifies the proposed HostList::defer_copy probe on physical NVIDIA hardware as well as WARP, alongside the guest-entry WARP check above. My runs used the upstream revision before the proposed fix. For the public CopyBufferRegion entry point, #387 also has a [real-queue test and fix results](https://git.gtahub.st/github/Marvisak--VIctory/pulls/387). I haven't measured the effect on in-game BVH construction.
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 21:12 UTC · original

Root cause confirmed and fixed in #2810: HostList::run_deferred executes Step::Copy/Fill at submission preparation, before ExecuteCommandLists — a CopyBufferRegion reading a range the submission's shaders write carries stale bytes (they only reach title memory in the post-fence copy-back), and one writing such a range gets overwritten by it.

The fix queues any deferred copy/fill touching a range declared GPU-written (shared Batch state, so cross-list ordering works) on a late list that runs after the copy-backs, before the writes that signal completion to the title. Includes an end-to-end test through Host::execute.

**@⁠kotekompotek** on GitHub · 2026-11-25 21:12 UTC · [original](https://github.com/Marvisak/VIctory/issues/2781#issuecomment-7174755410) Root cause confirmed and fixed in #2810: `HostList::run_deferred` executes `Step::Copy`/`Fill` at submission preparation, before `ExecuteCommandLists` — a `CopyBufferRegion` reading a range the submission's shaders write carries stale bytes (they only reach title memory in the post-fence copy-back), and one writing such a range gets overwritten by it. The fix queues any deferred copy/fill touching a range declared GPU-written (shared `Batch` state, so cross-list ordering works) on a `late` list that runs after the copy-backs, before the writes that signal completion to the title. Includes an end-to-end test through `Host::execute`.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 21:46 UTC · original

Automated triage for the maintainers.

Confirmed on main 61bfc77. In crates/victory-gpu/src/host.rs, Host::execute calls HostList::run_deferred for every list of the submission before ExecuteCommandLists. run_deferred runs Step::Copy (queued by HostList::defer_copy from CopyBufferRegion in list.rs) as a CPU copy_mapped at that point. A copy whose source the same submission's shaders write therefore reads the bytes from before the copy-back. Two commenters reproduced it with synthetic buffers on WARP and on an RTX 5070 Ti.

Open PRs: #2810 runs such copies after the copy-backs and is the most direct fix. #387 (ordering of buffer copies) and #2608 (splitting after texture read-backs) are related. The fork commit offered in a comment above is not a PR. PRs are open to everyone, so please open one, or coordinate on #2810, if that change differs from it.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 21:46 UTC · [original](https://github.com/Marvisak/VIctory/issues/2781#issuecomment-7175512416) <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-25T21:12:25Z at=2026-11-25T21:50:00Z --> Automated triage for the maintainers. Confirmed on main 61bfc77. In `crates/victory-gpu/src/host.rs`, `Host::execute` calls `HostList::run_deferred` for every list of the submission before `ExecuteCommandLists`. `run_deferred` runs `Step::Copy` (queued by `HostList::defer_copy` from `CopyBufferRegion` in `list.rs`) as a CPU `copy_mapped` at that point. A copy whose source the same submission's shaders write therefore reads the bytes from before the copy-back. Two commenters reproduced it with synthetic buffers on WARP and on an RTX 5070 Ti. Open PRs: #2810 runs such copies after the copy-backs and is the most direct fix. #387 (ordering of buffer copies) and #2608 (splitting after texture read-backs) are related. The fork commit offered in a comment above is not a PR. PRs are open to everyone, so please open one, or coordinate on #2810, if that change differs from it. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory#2781
No description provided.