Repository navigation
startup: implement ResolveSubresource command-list slot (Part of #870) #2049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ | |
| #include "console_plane_size.h" | ||
| #include "descriptor_heap_type.h" | ||
| #include "null_binding_cause.h" | ||
| #include "resolve_subresource.h" | ||
| #include "null_texture_view.h" | ||
| #include "packed_target_format.h" | ||
| #include "present_view_format.h" | ||
|
|
@@ -2297,6 +2298,40 @@ void __stdcall list_stencil_ref(Wrapper* self, UINT reference) | |
| { | ||
| if (auto* list = recording(self)) list->OMSetStencilRef(reference); | ||
| } | ||
| // List slot 19, ResolveSubresource(dest, dest subresource, source, source subresource, format). Both | ||
| // textures use COMMON state tracking; the list moves them to RESOLVE_DEST / RESOLVE_SOURCE for the call. | ||
| void __stdcall list_resolve_subresource(Wrapper* self, void* destination, UINT destination_subresource, void* source, | ||
| UINT source_subresource, UINT format) | ||
| { | ||
| const auto refuse = [](const char* reason) { | ||
| static LONG refusals; | ||
| if (first_calls(refusals, 16)) log("x2w-render ResolveSubresource refused: %s", reason); | ||
| }; | ||
| auto* list = recording(self); | ||
| if (!list) return refuse("list is closed"); | ||
| Wrapper* to = as_wrapper(destination); | ||
| Wrapper* from = as_wrapper(source); | ||
| if (!to || !from || to->own().kind != resource_kind || from->own().kind != resource_kind || !to->own().real || | ||
| !from->own().real || to == from) | ||
| return refuse("missing desktop resource"); | ||
| const auto* to_info = resource_info(to); | ||
| const auto* from_info = resource_info(from); | ||
| if (!to_info || !from_info || to_info->initial_state != D3D12_RESOURCE_STATE_COMMON || | ||
| from_info->initial_state != D3D12_RESOURCE_STATE_COMMON) | ||
| return refuse("resource does not use COMMON state tracking"); | ||
| auto* target = static_cast<ID3D12Resource*>(to->own().real); | ||
| auto* origin = static_cast<ID3D12Resource*>(from->own().real); | ||
| const auto side = [](ID3D12Resource* resource) { | ||
| const D3D12_RESOURCE_DESC desc = resource->GetDesc(); | ||
| return x2w_resolve::Side{desc.Width, desc.Height, desc.MipLevels, desc.DepthOrArraySize, desc.SampleDesc.Count, | ||
| desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE2D}; | ||
| }; | ||
| const auto verdict = x2w_resolve::check(side(target), destination_subresource, side(origin), source_subresource, format); | ||
| 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)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For a resolve destination with Useful? React with 👍 / 👎. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the caller supplies console colour format 116 or 117, Useful? React with 👍 / 👎.
Comment on lines
+2331
to
+2333
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If the single-sample destination is already bound as a render target, resolving into it and then drawing again without rebinding leaves it in Useful? React with 👍 / 👎. |
||
| } | ||
| // List slot 44 (desktop 40 + 4), SetGraphicsRootShaderResourceView(parameter, title GPU address). | ||
| void __stdcall list_root_srv(Wrapper* self, UINT parameter, u64 address) | ||
| { | ||
|
|
@@ -3755,6 +3790,7 @@ void build_tables() | |
| list_typed[52] = reinterpret_cast<ListTyped>(&list_clear_target); | ||
| list_typed[139] = reinterpret_cast<ListTyped>(&list_reset); | ||
| list_typed[12] = reinterpret_cast<ListTyped>(&list_draw); | ||
| list_typed[19] = reinterpret_cast<ListTyped>(&list_resolve_subresource); | ||
| list_typed[20] = reinterpret_cast<ListTyped>(&list_topology); | ||
| list_typed[21] = reinterpret_cast<ListTyped>(&list_viewports); | ||
| list_typed[22] = reinterpret_cast<ListTyped>(&list_scissors); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // Experimental (docs/startup-runtime.md, #870): the checks before a title's ResolveSubresource (command | ||
| // list slot 19, desktop order) is forwarded to the desktop list. Plain standard C++ with no Windows types, | ||
| // so the rules can be compiled and tested on their own. | ||
| // | ||
| // A resolve copies one subresource of a multisampled texture into one subresource of a single-sample | ||
| // texture of the same size. The desktop runtime treats any other call as a device-removing error, so a | ||
| // call that does not fit is refused here and logged instead of reaching the driver. | ||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| namespace x2w_resolve { | ||
|
|
||
| struct Side { | ||
| std::uint64_t width; | ||
| std::uint32_t height; | ||
| std::uint32_t mip_levels; | ||
| std::uint32_t array_size; | ||
| std::uint32_t sample_count; | ||
| bool is_texture2d; | ||
| }; | ||
|
|
||
| enum class Verdict { | ||
| ok, | ||
| not_texture, | ||
| destination_multisampled, | ||
| source_not_multisampled, | ||
| size_mismatch, | ||
| subresource_out_of_range, | ||
| format_unknown, | ||
| }; | ||
|
|
||
| inline std::uint64_t subresource_count(const Side& s) { return std::uint64_t{s.mip_levels} * s.array_size; } | ||
|
|
||
| // The size of a subresource at `mip`: each mip halves the base size and stops at 1. | ||
| inline std::uint64_t mip_extent(std::uint64_t base, std::uint32_t mip) | ||
| { | ||
| const std::uint64_t value = mip >= 63 ? 0 : base >> mip; | ||
| return value ? value : 1; | ||
| } | ||
|
|
||
| inline Verdict check(const Side& destination, std::uint32_t destination_subresource, const Side& source, | ||
| std::uint32_t source_subresource, std::uint32_t format) | ||
| { | ||
| if (!destination.is_texture2d || !source.is_texture2d) return Verdict::not_texture; | ||
| if (destination.sample_count != 1) return Verdict::destination_multisampled; | ||
| if (source.sample_count <= 1) return Verdict::source_not_multisampled; | ||
| if (!format) return Verdict::format_unknown; | ||
| if (!destination.mip_levels || !destination.array_size || !source.mip_levels || !source.array_size || | ||
| destination_subresource >= subresource_count(destination) || source_subresource >= subresource_count(source)) | ||
| return Verdict::subresource_out_of_range; | ||
| const std::uint32_t destination_mip = destination_subresource % destination.mip_levels; | ||
| const std::uint32_t source_mip = source_subresource % source.mip_levels; | ||
| if (mip_extent(destination.width, destination_mip) != mip_extent(source.width, source_mip) || | ||
| mip_extent(destination.height, destination_mip) != mip_extent(source.height, source_mip)) | ||
| return Verdict::size_mismatch; | ||
| return Verdict::ok; | ||
| } | ||
|
|
||
| } // namespace x2w_resolve |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // Checks the rules that gate a title's ResolveSubresource (src/startup_stubs/resolve_subresource.h, #870). | ||
| #include "../src/startup_stubs/resolve_subresource.h" | ||
|
|
||
| #include <cstdio> | ||
|
|
||
| using namespace x2w_resolve; | ||
|
|
||
| namespace { | ||
| int failures; | ||
| void expect(bool ok, const char* what) | ||
| { | ||
| if (!ok) { | ||
| std::printf("FAIL: %s\n", what); | ||
| ++failures; | ||
| } | ||
| } | ||
| constexpr std::uint32_t rgba8 = 28; | ||
| } // namespace | ||
|
|
||
| int main() | ||
| { | ||
| const Side single{1280, 720, 1, 1, 1, true}; | ||
| const Side msaa{1280, 720, 1, 1, 4, true}; | ||
|
|
||
| expect(check(single, 0, msaa, 0, rgba8) == Verdict::ok, "a 4x target resolves into a single-sample one"); | ||
| expect(check(msaa, 0, msaa, 0, rgba8) == Verdict::destination_multisampled, "destination must be single-sample"); | ||
| expect(check(single, 0, single, 0, rgba8) == Verdict::source_not_multisampled, "source must be multisampled"); | ||
| expect(check(single, 0, msaa, 0, 0) == Verdict::format_unknown, "format must be named"); | ||
|
|
||
| Side buffer = single; | ||
| buffer.is_texture2d = false; | ||
| expect(check(buffer, 0, msaa, 0, rgba8) == Verdict::not_texture, "buffers are refused"); | ||
|
|
||
| const Side smaller{640, 360, 1, 1, 1, true}; | ||
| expect(check(smaller, 0, msaa, 0, rgba8) == Verdict::size_mismatch, "sizes must match"); | ||
|
|
||
| const Side mips{1280, 720, 3, 2, 1, true}; | ||
| expect(check(mips, 5, msaa, 0, rgba8) == Verdict::size_mismatch, "mip 2 of the destination is 320x180"); | ||
| expect(check(mips, 6, msaa, 0, rgba8) == Verdict::subresource_out_of_range, "subresource 6 of 6 is out of range"); | ||
| expect(check(mips, 3, msaa, 0, rgba8) == Verdict::ok, "array slice 1, mip 0 matches the source"); | ||
| expect(check(single, 0, msaa, 1, rgba8) == Verdict::subresource_out_of_range, "source subresource 1 of 1"); | ||
|
|
||
| const Side tiny{1, 1, 1, 1, 1, true}; | ||
| const Side tiny_msaa{1, 1, 1, 1, 2, true}; | ||
| expect(check(tiny, 0, tiny_msaa, 0, rgba8) == Verdict::ok, "1x1 resolves"); | ||
| const Side deep{1, 1, 70, 1, 1, true}; | ||
| expect(check(deep, 69, tiny_msaa, 0, rgba8) == Verdict::ok, "a mip past the size floor stays 1x1"); | ||
|
|
||
| if (!failures) std::printf("startup_resolve_subresource: ok\n"); | ||
| return failures ? 1 : 0; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds an externally usable startup operation and a new CTest command, but a repository-wide search for
ResolveSubresourceandresolve_subresourcefinds no corresponding README or experiment-documentation entry.AGENTS.mdrequires updating the relevant README row ordocs/experiments.mdwhen 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 👍 / 👎.