Skip to content

startup: implement ResolveSubresource command-list slot (Part of #870) - #2049

Closed
tedin7 wants to merge 1 commit into
R0Y00:mainfrom
tedin7:x2w-870-resolve-subresource
Closed

tedin7 wants to merge 1 commit into
R0Y00:mainfrom
tedin7:x2w-870-resolve-subresource

Conversation

@tedin7

@tedin7 tedin7 commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Part of #870

What this unblocks: MSAA render targets can be resolved into a single-sample texture, so a title's resolve step no longer falls to the no-op stub.

Forwards command list slot 19 (ResolveSubresource, desktop order) to the desktop list. Both textures must use COMMON state tracking. The list moves them to RESOLVE_DEST / RESOLVE_SOURCE for the call. Calls that do not fit (buffer, multisampled destination, single-sample source, size mismatch, subresource out of range, unknown format) are refused and logged instead of reaching the driver. The rules live in src/startup_stubs/resolve_subresource.h (no Windows types) with a unit test.

Verification:

  • g++ -std=c++17 -Wall -o /tmp/rs_test tests/startup_resolve_subresource.cpp && /tmp/rs_test (Linux host) -> startup_resolve_subresource: ok
  • git diff --check -> clean
  • Win2025: NOT run. The d3d12_xs_device.cpp change is not compiled yet, and slot 19 has no call-site confirmation (it is the desktop slot, bracketed by confirmed slots 13 and 20). Needs a Win2025 build and ctest -R startup_resolve_subresource before merge.

Slot 19 validates both textures (single-sample destination, multisampled source, matching size, subresource range) and moves them to the resolve states before the desktop call. Part of R0Y00#870.
@tedin7
tedin7 marked this pull request as ready for review November 24, 2026 23:40
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T23:47:56.814324Z b3ac4ae Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b3ac4aec3a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if (verdict != x2w_resolve::Verdict::ok) return refuse("arguments do not describe a valid resolve");
require_state(self, target, D3D12_RESOURCE_STATE_RESOLVE_DEST);
require_state(self, origin, D3D12_RESOURCE_STATE_RESOLVE_SOURCE);
list->ResolveSubresource(target, destination_subresource, origin, source_subresource, static_cast<DXGI_FORMAT>(format));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve resolved data when uploading sampled textures

For a resolve destination with Flags == D3D12_RESOURCE_FLAG_NONE and readable title-memory backing, such as a texture created through slot 133, this updates only the desktop texture. The next translated SRV bind unconditionally calls upload_texture (src/startup_stubs/d3d12_draw.inl:999), which excludes only render-target, depth-stencil and UAV resources. On its first bind, it therefore uploads the untouched CPU backing over the resolved pixels. A valid resolve-then-sample sequence reads stale CPU data instead of the resolve result. Record the destination's GPU-written contents and make the upload path preserve them.

Useful? React with 👍 / 👎.

if (verdict != x2w_resolve::Verdict::ok) return refuse("arguments do not describe a valid resolve");
require_state(self, target, D3D12_RESOURCE_STATE_RESOLVE_DEST);
require_state(self, origin, D3D12_RESOURCE_STATE_RESOLVE_SOURCE);
list->ResolveSubresource(target, destination_subresource, origin, source_subresource, static_cast<DXGI_FORMAT>(format));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Normalize console formats before submitting the resolve

When the caller supplies console colour format 116 or 117, sanitized() creates both desktop resources as DXGI_FORMAT_R10G10B10A2_UNORM through desktop_format(), but this call forwards the original console value. Both values pass x2w_resolve::check because its format check rejects only zero. Consequently, successfully created stand-ins receive a resolve with an unsupported desktop format that also differs from their actual format, potentially invalidating the command list or removing the device. Apply the existing desktop-format conversion before validating and forwarding the call.

Useful? React with 👍 / 👎.

Comment on lines +2331 to +2333
require_state(self, target, D3D12_RESOURCE_STATE_RESOLVE_DEST);
require_state(self, origin, D3D12_RESOURCE_STATE_RESOLVE_SOURCE);
list->ResolveSubresource(target, destination_subresource, origin, source_subresource, static_cast<DXGI_FORMAT>(format));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restore attachment states before subsequent draws

If the single-sample destination is already bound as a render target, resolving into it and then drawing again without rebinding leaves it in RESOLVE_DEST. list_targets() establishes render-target state only at bind time, while list_draw() and draw_translated() do not re-establish it; the title's barrier calls are still no-ops. Since targets_bound remains true, the next draw is recorded against an attachment in the wrong state, producing validation errors and possible device removal. Restore the previous tracked states after resolving, or ensure subsequent draws transition their bound attachments back to the required states.

Useful? React with 👍 / 👎.

Comment thread CMakeLists.txt
# Rules that gate a title's ResolveSubresource (src/startup_stubs/resolve_subresource.h, #870).
add_executable(startup_resolve_subresource tests/startup_resolve_subresource.cpp)
target_compile_features(startup_resolve_subresource PRIVATE cxx_std_17)
add_test(NAME startup_resolve_subresource COMMAND startup_resolve_subresource)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Document the new resolve capability and reproduction command

This adds an externally usable startup operation and a new CTest command, but a repository-wide search for ResolveSubresource and resolve_subresource finds no corresponding README or experiment-documentation entry. AGENTS.md requires updating the relevant README row or docs/experiments.md when a public capability or reproduction command changes. Add the supported resource constraints, the fixture's reproduction command and result, and the distinction between the tested argument predicates and the still-unverified Windows forwarding path.

AGENTS.md reference: AGENTS.md:L211-L212

Useful? React with 👍 / 👎.

@ChazY11

ChazY11 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Ran your host test under MSVC, broke the rules seven ways: six caught, and the seventh is a real gap

Your command works on Windows too, with cl instead of g++:

cl /nologo /std:c++17 /EHsc tests/startup_resolve_subresource.cpp /I src/startup_stubs
startup_resolve_subresource: ok      exit 0
mutation in resolve_subresource.h result
destination.sample_count != 1 removed caught
source.sample_count <= 1 → < 1 caught
the is_texture2d requirement removed caught
if (!format) removed caught
destination_subresource >= subresource_count → > caught
mip_extent floor 1 → 0 caught
the height comparison replaced with false not caught

The height check is unpinned, and it is the one that matters most

Only the width is compared by the fixture. A probe that varies only the height proves it both ways:

// 256x128 destination, 256x256 source: equal width and mip, different height
const Verdict v = check(dst, 0, src, 0, 28);
unmutated header:      height-only mismatch -> size_mismatch     exit 0
height check removed:  height-only mismatch -> NOT rejected      exit 1   <- the probe notices
your fixture:          exit 0                                    <- it does not

So today the header is correct and the height clause is untested. That is the clause whose failure mode the file's own comment describes: the call reaches
the driver and the desktop runtime treats it as a device-removing error. A one-line case closes it:

const Side dst_h = side(256, 128, 1, 1, 1, true);
const Side src_h = side(256, 256, 1, 1, 4, true);
expect(check(dst_h, 0, src_h, 0, 28) == Verdict::size_mismatch, "height mismatch is refused");

Two things the fixture does well

  • mip_extent's floor at 1 is caught: without it, a mip chain that shifts a small base to zero would compare 0 != 1 for identical textures and refuse
    valid resolves. That is a real one and it is pinned.
  • The subresource bounds are pinned in the strict direction (>=, not >), which is the boundary that off-by-one always lands on.

What I did not check

d3d12_xs_device.cpp's use of these verdicts — the state transitions to RESOLVE_DEST/RESOLVE_SOURCE and the logging path are Windows-only and I have no
device here. The header is genuinely "no Windows types" as claimed, which is what made this review possible without a build tree.

Notes

  • AI-assisted review.

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Closing as duplicate of our broader open PR #1944 (which already covers slot 19 alongside slots 15/17 and hardware tests).

@tedin7 tedin7 closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants