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
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2087,6 +2087,17 @@ endforeach()
add_test(NAME startup_committed_heap_state_upload_texture_control COMMAND startup_committed_heap_state_check warp --mutate upload-texture)
set_tests_properties(startup_committed_heap_state_hardware PROPERTIES SKIP_RETURN_CODE 77)
set_tests_properties(startup_committed_heap_state_upload_texture_control PROPERTIES WILL_FAIL TRUE)
# Device slot 76 (desktop CreateCommittedResource argument order) through the device wrapper: a render
# target with a clear value and buffers on the default, upload and readback heaps. The control asks for a
# 2D texture on an upload heap, which no runtime creates, and must FAIL.
add_executable(startup_committed_slot76_check tests/startup_committed_slot76_check.cpp)
target_compile_features(startup_committed_slot76_check PRIVATE cxx_std_17)
target_link_libraries(startup_committed_slot76_check PRIVATE d3d12_xs_shim d3d12 dxgi)
foreach(adapter IN ITEMS warp hardware)
add_test(NAME startup_committed_slot76_${adapter} COMMAND startup_committed_slot76_check ${adapter})
endforeach()
set_tests_properties(startup_committed_slot76_hardware PROPERTIES SKIP_RETURN_CODE 77)
add_test(NAME startup_committed_slot76_control COMMAND startup_committed_slot76_check warp --control)
# Opt-in BC7 4 KiB standard surfaces (src/startup_stubs/bc7_4k_s.h): accepted descriptions, padded
# sizes, block order and detile; the mutated run (x-first bit order) is the negative control.
add_executable(startup_bc7_4k_s_check tests/startup_bc7_4k_s_check.cpp)
Expand Down
14 changes: 14 additions & 0 deletions docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -2866,6 +2866,20 @@ freed slots are reused in address order so that pages reused together share a vi
bytes from the queried page to the end of the view, not one page. A placed buffer on such memory
is not affected: section-backed pages already took the committed, not-aliased path.

## Committed resources (device slot 76)

Device slot 76 (Xbox order, +0x260) takes the seven arguments of desktop `CreateCommittedResource`:
heap properties, heap flags, desc, initial state, clear value, riid and ppv. Measured: a console
package module (an upscaler) creates its resources through it. The stand-in shares the
committed-resource path of slot 127 (the `CreateCommittedResource3` order, with protected session and
castable formats, which slot 76 does not pass): the same initial-state choice per heap, the same
clear-value retry and title memory, and a log line naming the slot. Run
`ctest --preset dev --no-tests=error -R '^startup_committed_slot76_(warp|control)$'`
(`tests/startup_committed_slot76_check.cpp`): a render target with a clear value and buffers on the
default, upload and readback heaps, passed with initial state 0xffffffff as a title passes them, must
be created and leave the device alive. The control asks for a 2D texture on an upload heap and must
return `E_INVALIDARG` with no resource and leave the device alive. The control also requires all four valid creations to pass. `startup_committed_slot76_hardware` runs the creation checks on a physical GPU.

- `ctest --preset release --no-tests=error -R '^xmem_shim_(mapped_pages|page_runs)$' -V` runs the
earlier contract check and `tests/xmem_page_runs_check.py`: a batch across two sections with
holes, moved and reused pages; `VirtualQuery` before and after a view is split; two views of
Expand Down
35 changes: 28 additions & 7 deletions src/startup_stubs/d3d12_xs_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5718,10 +5718,10 @@ HRESULT __stdcall device_create_derived_pipeline(Wrapper*, void* base, UINT coun
// COMMON, GENERIC_READ on an upload heap and COPY_DEST on a readback heap (the initial states D3D12
// requires there; the Windows 10 runtime refuses COMMON with E_INVALIDARG). When desktop rejects the
// clear value it is retried without one.
HRESULT __stdcall device_create_committed_x(Wrapper* self, const D3D12_HEAP_PROPERTIES* props, UINT heap_flags,
const D3D12_RESOURCE_DESC* desc, UINT state, const D3D12_CLEAR_VALUE* clear,
void* session, UINT castable_count, const void* castable, const GUID* iid,
void** out)
// Slot 76 shares the work with the slot number in the log line.
HRESULT create_committed(int slot, Wrapper* self, const D3D12_HEAP_PROPERTIES* props, UINT heap_flags,
const D3D12_RESOURCE_DESC* desc, UINT state, const D3D12_CLEAR_VALUE* clear, void* session,
UINT castable_count, const void* castable, const GUID* iid, void** out)
{
char text[48];
guid_text(iid, text, sizeof(text));
Expand All @@ -5730,7 +5730,7 @@ HRESULT __stdcall device_create_committed_x(Wrapper* self, const D3D12_HEAP_PROP
const D3D12_RESOURCE_DESC copy = sanitized(*desc);
const auto flags = static_cast<D3D12_HEAP_FLAGS>(heap_flags);
const D3D12_RESOURCE_ALLOCATION_INFO info = device_of(self)->GetResourceAllocationInfo(0, 1, &copy);
check_device("Device before slot", 127);
check_device("Device before slot", slot);
void* const title_memory = info.SizeInBytes != ~0ull ? title_resource_memory(info.SizeInBytes, info.Alignment) : nullptr;
ID3D12Resource* resource = nullptr;
const D3D12_RESOURCE_STATES initial = props->Type == D3D12_HEAP_TYPE_UPLOAD ? D3D12_RESOURCE_STATE_GENERIC_READ
Expand All @@ -5748,8 +5748,9 @@ HRESULT __stdcall device_create_committed_x(Wrapper* self, const D3D12_HEAP_PROP
}
static LONG calls;
if (first_calls(calls, 12))
log("x2w-d3d12 Device::slot127(CreateCommittedResource3?) heap=%d flags=0x%x dim=%d %llux%u fmt=%d rflags=0x%x "
"state=0x%x clear=%p%s session=%p castable=%u/%p riid=%s -> 0x%08lx", props->Type, heap_flags, desc->Dimension,
log("x2w-d3d12 Device::slot%d(%s) heap=%d flags=0x%x dim=%d %llux%u fmt=%d rflags=0x%x "
"state=0x%x clear=%p%s session=%p castable=%u/%p riid=%s -> 0x%08lx", slot,
slot == 76 ? "CreateCommittedResource" : "CreateCommittedResource3?", props->Type, heap_flags, desc->Dimension,
desc->Width, desc->Height, desc->Format, desc->Flags, state, static_cast<const void*>(clear),
clear && !cleared ? "(dropped)" : "", session, castable_count, castable, text, static_cast<unsigned long>(hr));
if (FAILED(hr)) return hr;
Expand All @@ -5763,6 +5764,25 @@ HRESULT __stdcall device_create_committed_x(Wrapper* self, const D3D12_HEAP_PROP
return S_OK;
}

HRESULT __stdcall device_create_committed_x(Wrapper* self, const D3D12_HEAP_PROPERTIES* props, UINT heap_flags,
const D3D12_RESOURCE_DESC* desc, UINT state, const D3D12_CLEAR_VALUE* clear,
void* session, UINT castable_count, const void* castable, const GUID* iid,
void** out)
{
return create_committed(127, self, props, heap_flags, desc, state, clear, session, castable_count, castable, iid, out);
}

// Device slot 76 (Xbox order, +0x260): the seven arguments of desktop CreateCommittedResource
// (heap properties, heap flags, desc, initial state, clear value, riid, ppv). Seen from a console
// package module (an upscaler) that a title loaded only on the Series S profile. Same desktop
// creation as slot 127 (tests/startup_committed_slot76_check.cpp).
HRESULT __stdcall device_create_committed(Wrapper* self, const D3D12_HEAP_PROPERTIES* props, UINT heap_flags,
const D3D12_RESOURCE_DESC* desc, UINT state, const D3D12_CLEAR_VALUE* clear,
const GUID* iid, void** out)
{
return create_committed(76, self, props, heap_flags, desc, state, clear, nullptr, 0, nullptr, iid, out);
}

// Device slot 80 (Xbox order): (type, timeout, 0, flags, &token) -> HRESULT, the frame-event wait
// that hands out a frame token (called with type 2 / timeout -1 and type 0 / timeout 0, flags 0/2).
// Paces to the interval from slot 78 (33.3 ms by default) and returns increasing tokens.
Expand Down Expand Up @@ -6217,6 +6237,7 @@ void build_tables()
tables[device_kind][48] = reinterpret_cast<void*>(&device_create_command_queue_x);
tables[device_kind][70] = reinterpret_cast<void*>(&device_memory_srv);
tables[device_kind][73] = reinterpret_cast<void*>(&device_create_command_list_x);
tables[device_kind][76] = reinterpret_cast<void*>(&device_create_committed);
tables[device_kind][78] = reinterpret_cast<void*>(&device_frame_interval);
tables[device_kind][79] = reinterpret_cast<void*>(&device_frame_event);
tables[device_kind][80] = reinterpret_cast<void*>(&device_wait_frame_event);
Expand Down
116 changes: 116 additions & 0 deletions tests/startup_committed_slot76_check.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// Device check for committed resources made through the startup device wrapper's slot 76 (Xbox
// order, +0x260): the seven arguments of desktop CreateCommittedResource (heap properties, heap
// flags, desc, initial state, clear value, riid, ppv). It shares the desktop creation of slot 127
// (tests/startup_committed_heap_state_check.cpp). A 2D render target with a clear value and buffers on
// the default, upload and readback heaps, passed as a title passes them (initial state 0xffffffff),
// must all be created and the device must stay alive.
// usage: startup_committed_slot76_check warp|hardware [--control]
// --control also requires a 2D upload-heap texture to return E_INVALIDARG with no output resource.
#include "xmem_test_device.h"

#include <cstdio>
#include <cstring>

extern "C" __declspec(dllimport) HRESULT WINAPI D3D12XboxCreateDevice(IUnknown*, const void*, REFIID, void**);

namespace {
HRESULT create_wrapper(IUnknown* adapter, REFIID iid, void** out)
{
unsigned char parameters[64]{};
return D3D12XboxCreateDevice(adapter, parameters, iid, out);
}

using Committed76 = HRESULT (*)(void*, const D3D12_HEAP_PROPERTIES*, UINT, const D3D12_RESOURCE_DESC*, UINT,
const D3D12_CLEAR_VALUE*, const GUID*, void**);
constexpr UINT state_undefined = 0xffffffff;

Committed76 slot76(ID3D12Device* device)
{
return reinterpret_cast<Committed76>((*reinterpret_cast<void***>(device))[76]);
}

D3D12_RESOURCE_DESC buffer(UINT64 bytes)
{
D3D12_RESOURCE_DESC desc{};
desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
desc.Width = bytes;
desc.Height = 1;
desc.DepthOrArraySize = 1;
desc.MipLevels = 1;
desc.SampleDesc.Count = 1;
desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
return desc;
}

D3D12_RESOURCE_DESC texture(UINT width, UINT height, D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE)
{
D3D12_RESOURCE_DESC desc{};
desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
desc.Width = width;
desc.Height = height;
desc.DepthOrArraySize = 1;
desc.MipLevels = 1;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.SampleDesc.Count = 1;
desc.Flags = flags;
return desc;
}

const char* heap_name(D3D12_HEAP_TYPE type)
{
return type == D3D12_HEAP_TYPE_DEFAULT ? "default" : type == D3D12_HEAP_TYPE_UPLOAD ? "upload" : "readback";
}

// Returns 0 only when the requested creation or rejection is observed and the device stays alive.
int check(ID3D12Device* wrapper, D3D12_HEAP_TYPE type, const D3D12_RESOURCE_DESC& desc,
const D3D12_CLEAR_VALUE* clear = nullptr, bool reject = false)
{
const D3D12_HEAP_PROPERTIES props{type};
const GUID iid = __uuidof(ID3D12Resource);
void* created = nullptr;
const HRESULT hr = slot76(wrapper)(wrapper, &props, 0, &desc, state_undefined, clear, &iid, &created);
const HRESULT removed = wrapper->GetDeviceRemovedReason();
const char* what = desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER ? "buffer" : "2D texture";
std::printf("%s heap, %s of 0x%llx%s: slot 76 -> 0x%08lx\n", heap_name(type), what,
static_cast<unsigned long long>(desc.Width), clear ? " with clear value" : "", static_cast<unsigned long>(hr));
const bool expected = reject ? hr == E_INVALIDARG && !created : SUCCEEDED(hr) && created;
const int result = expected && SUCCEEDED(removed) ? 0 : 1;
if (reject && !result) std::puts("slot 76 rejected the upload-heap texture with E_INVALIDARG and no resource");
if (result)
std::printf("FAIL: %s heap %s: hr 0x%08lx object %p device 0x%08lx\n", heap_name(type), what, static_cast<unsigned long>(hr),
created, static_cast<unsigned long>(removed));
if (created) static_cast<IUnknown*>(created)->Release();
return result;
}
} // namespace

int main(int argc, char** argv)
{
if (argc != 2 && !(argc == 3 && std::strcmp(argv[2], "--control") == 0)) return 1;
const bool warp = std::strcmp(argv[1], "warp") == 0;
const bool control = argc == 3;
bool unmatched = false;
SetEnvironmentVariableW(L"X2W_D3D12_PERMISSIVE", L"1");
auto wrapper = create_device(warp, unmatched, create_wrapper);
if (!wrapper) {
if (warp || unmatched) {
std::puts("FAIL: no wrapped device");
return 1;
}
return 77;
}
int failures = 0;
D3D12_CLEAR_VALUE clear{};
clear.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
failures += check(wrapper.Get(), D3D12_HEAP_TYPE_DEFAULT, texture(128, 64, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET), &clear);
failures += check(wrapper.Get(), D3D12_HEAP_TYPE_DEFAULT, buffer(0x10000));
failures += check(wrapper.Get(), D3D12_HEAP_TYPE_UPLOAD, buffer(0x10000));
failures += check(wrapper.Get(), D3D12_HEAP_TYPE_READBACK, buffer(768));
if (control) failures += check(wrapper.Get(), D3D12_HEAP_TYPE_UPLOAD, texture(64, 64), nullptr, true);
if (failures) {
std::printf("startup_committed_slot76: FAIL (%d)\n", failures);
return 1;
}
std::puts("startup_committed_slot76: PASS (render target, default, upload and readback resources created through slot 76)");
return 0;
}
Loading