upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test
diff options
context:
space:
mode:
authortedin7 <tommasoderosa94@gmail.com>2026-11-23 16:49:34 +0100
committerMumogg <104529023+Mumogg@users.noreply.github.com>2026-11-23 22:14:29 -0600
commit81e8a6f2a42e72e49f0338a584cd651d5d3e9db7 (patch)
tree4bc69613699f4907bb961a3cf341ff9127d8f507 /runtime/test
parent992b19bd44c80eea1ad81bf737b9057d002b9aff (diff)
d3d12_xs: device slot 127 creates the committed resource (CreateCommittedResource3 with Xbox descriptors, RT-5 stop 15)
Slot 127 is past the PC device vtable and was refused with E_NOTIMPL. It has the argument list of ID3D12Device10::CreateCommittedResource3; the proxy now calls the PC device's with the Xbox layout word and flag bits cleaned as slot 76 does. Measured in #6982. (cherry picked from commit 8d622049ae79b7123ae4661ab3feaab27849575e)
Diffstat (limited to 'runtime/test')
-rw-r--r--runtime/test/xs_proxy_mock_test.cpp138
1 files changed, 137 insertions, 1 deletions
diff --git a/runtime/test/xs_proxy_mock_test.cpp b/runtime/test/xs_proxy_mock_test.cpp
index 1ad50a6b8..224030247 100644
--- a/runtime/test/xs_proxy_mock_test.cpp
+++ b/runtime/test/xs_proxy_mock_test.cpp
@@ -285,6 +285,35 @@ HRESULT WINAPI mock_create_command_list(Mock* self, std::uint64_t node_mask, std
285 return mock_query(child, riid, out); 285 return mock_query(child, riid, out);
286} 286}
287 287
288#ifdef __ID3D12Device10_INTERFACE_DEFINED__
289// PC ID3D12Device10::CreateCommittedResource3 takes ten words after `this`, so it has its own entry (PC slot 76) that
290// keeps all of them: the resource description is copied because the caller's copy is a local of the proxy.
291struct CommittedResource3Call {
292 unsigned calls;
293 const D3D12_HEAP_PROPERTIES* heap;
294 D3D12_HEAP_FLAGS heap_flags;
295 D3D12_RESOURCE_DESC1 desc;
296 std::uint32_t layout;
297 const D3D12_CLEAR_VALUE* clear;
298 const void* session;
299 std::uint32_t castable_count;
300 const DXGI_FORMAT* castable_formats;
301 const IID* riid;
302 void** out;
303};
304CommittedResource3Call g_committed3;
305
306HRESULT WINAPI mock_create_committed_resource3(Mock* self, const D3D12_HEAP_PROPERTIES* heap, D3D12_HEAP_FLAGS flags,
307 const D3D12_RESOURCE_DESC1* desc, std::uint32_t layout,
308 const D3D12_CLEAR_VALUE* clear, const void* session,
309 std::uint32_t castable_count, const DXGI_FORMAT* castable_formats,
310 const IID* riid, void** out) {
311 g_committed3 = {g_committed3.calls + 1, heap, flags, *desc, layout, clear, session, castable_count,
312 castable_formats, riid, out};
313 return mock_create(self, Kind::resource, reinterpret_cast<std::uint64_t>(riid), reinterpret_cast<std::uint64_t>(out));
314}
315#endif
316
288template <std::size_t... I> 317template <std::size_t... I>
289void fill_mock_vtable(void** vtable, std::index_sequence<I...>) { 318void fill_mock_vtable(void** vtable, std::index_sequence<I...>) {
290 ((vtable[I] = reinterpret_cast<void*>(&mock_slot<static_cast<unsigned>(I)>)), ...); 319 ((vtable[I] = reinterpret_cast<void*>(&mock_slot<static_cast<unsigned>(I)>)), ...);
@@ -295,6 +324,9 @@ void** mock_vtable() {
295 static const bool filled = [] { 324 static const bool filled = [] {
296 fill_mock_vtable(table, std::make_index_sequence<kMockSlots>{}); 325 fill_mock_vtable(table, std::make_index_sequence<kMockSlots>{});
297 table[12] = reinterpret_cast<void*>(&mock_create_command_list); 326 table[12] = reinterpret_cast<void*>(&mock_create_command_list);
327#ifdef __ID3D12Device10_INTERFACE_DEFINED__
328 table[76] = reinterpret_cast<void*>(&mock_create_committed_resource3);
329#endif
298 return true; 330 return true;
299 }(); 331 }();
300 (void)filled; 332 (void)filled;
@@ -314,6 +346,13 @@ std::uint64_t raw(const void* object, unsigned slot, std::uint64_t a1 = 0, std::
314 0, 0, 0); 346 0, 0, 0);
315} 347}
316 348
349// A call with the ten words of device slot 127 (and any other slot that takes up to ten).
350std::uint64_t raw10(const void* object, unsigned slot, const std::uint64_t (&w)[10]) {
351 void* const* vtable = *reinterpret_cast<void* const* const*>(object);
352 return reinterpret_cast<SlotFn>(vtable[slot])(const_cast<void*>(object), w[0], w[1], w[2], w[3], w[4], w[5], w[6],
353 w[7], w[8], w[9], 0, 0, 0, 0);
354}
355
317HRESULT hr_of(std::uint64_t value) { 356HRESULT hr_of(std::uint64_t value) {
318 return static_cast<HRESULT>(static_cast<std::uint32_t>(value)); 357 return static_cast<HRESULT>(static_cast<std::uint32_t>(value));
319} 358}
@@ -1206,6 +1245,103 @@ int run_fault_mode(const char* mode) {
1206 return 2; 1245 return 2;
1207} 1246}
1208 1247
1248// Device slot 127 is ID3D12Device10::CreateCommittedResource3 with Xbox descriptors (RT-5 stop 15). Past the PC
1249// vtable it used to be refused with E_NOTIMPL; the PC device must now get the resource with the Xbox layout word and
1250// flag bits gone and every other word as the title passed it.
1251int check_committed_resource3_x() {
1252#ifdef __ID3D12Device10_INTERFACE_DEFINED__
1253 constexpr std::uint32_t kXboxLayoutTiled = 0x101, kXboxFlagBit = 0x40000, kBarrierLayoutUndefined = 0xFFFFFFFFu;
1254 D3D12_HEAP_PROPERTIES heap{};
1255 heap.Type = D3D12_HEAP_TYPE_DEFAULT;
1256 D3D12_CLEAR_VALUE clear{};
1257 clear.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1258 const DXGI_FORMAT castable[2] = {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB};
1259 D3D12_RESOURCE_DESC1 texture{};
1260 texture.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
1261 texture.Width = 1920;
1262 texture.Height = 1080;
1263 texture.DepthOrArraySize = 1;
1264 texture.MipLevels = 1;
1265 texture.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
1266 texture.SampleDesc.Count = 1;
1267 texture.Layout = static_cast<D3D12_TEXTURE_LAYOUT>(kXboxLayoutTiled);
1268 texture.Flags = static_cast<D3D12_RESOURCE_FLAGS>(D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET |
1269 D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS | kXboxFlagBit);
1270
1271 // A PC device with ID3D12Device10: the render target comes back, as the console's call returns it.
1272 Mock* mock = nullptr;
1273 void* device = make_device(mock, 10, true);
1274 EXPECT(device && xs::device_proxy_slot_count(device) == 79);
1275 xs::reset_device_proxy_stats();
1276 g_committed3 = {};
1277 void* resource = nullptr;
1278 std::uint64_t words[10] = {word(&heap), D3D12_HEAP_FLAG_NONE, word(&texture), kBarrierLayoutUndefined,
1279 word(&clear), 0, 2, word(castable), word(&kResourceIid), word(&resource)};
1280 EXPECT(hr_of(raw10(device, 127, words)) == S_OK);
1281 EXPECT(resource && reinterpret_cast<Mock*>(resource)->kind == Kind::resource);
1282 EXPECT(g_committed3.calls == 1 && xs::device_slot_hits(127) == 1);
1283 EXPECT(g_committed3.heap == &heap && g_committed3.clear == &clear && !g_committed3.session);
1284 EXPECT(g_committed3.layout == kBarrierLayoutUndefined);
1285 EXPECT(g_committed3.castable_count == 2 && g_committed3.castable_formats == castable);
1286 EXPECT(g_committed3.riid == &kResourceIid);
1287 EXPECT(g_committed3.desc.Layout == D3D12_TEXTURE_LAYOUT_UNKNOWN);
1288 EXPECT(g_committed3.desc.Flags ==
1289 (D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS));
1290 EXPECT(g_committed3.desc.Width == 1920 && g_committed3.desc.Height == 1080 &&
1291 g_committed3.desc.Format == DXGI_FORMAT_R8G8B8A8_TYPELESS && g_committed3.desc.SampleDesc.Count == 1);
1292 EXPECT(texture.Layout == static_cast<D3D12_TEXTURE_LAYOUT>(kXboxLayoutTiled)); // the title's description is read only
1293 static_cast<void>(release(resource));
1294
1295 // A buffer takes the row-major layout.
1296 D3D12_RESOURCE_DESC1 buffer = texture;
1297 buffer.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
1298 buffer.Height = 1;
1299 buffer.Format = DXGI_FORMAT_UNKNOWN;
1300 words[2] = word(&buffer);
1301 words[6] = 0;
1302 words[7] = 0;
1303 resource = nullptr;
1304 EXPECT(hr_of(raw10(device, 127, words)) == S_OK && resource);
1305 EXPECT(g_committed3.calls == 2 && g_committed3.desc.Layout == D3D12_TEXTURE_LAYOUT_ROW_MAJOR);
1306
1307 // The PC device's own refusal reaches the title with a null object.
1308 mock->create_result = E_OUTOFMEMORY;
1309 resource = reinterpret_cast<void*>(1);
1310 words[9] = word(&resource);
1311 EXPECT(hr_of(raw10(device, 127, words)) == E_OUTOFMEMORY && !resource);
1312 mock->create_result = S_OK;
1313
1314 // A null description, IID or output is refused before the PC device is called.
1315 const unsigned before = g_committed3.calls;
1316 std::uint64_t bad[10];
1317 std::memcpy(bad, words, sizeof(bad));
1318 bad[2] = 0;
1319 EXPECT(hr_of(raw10(device, 127, bad)) == E_POINTER);
1320 std::memcpy(bad, words, sizeof(bad));
1321 bad[8] = 0;
1322 EXPECT(hr_of(raw10(device, 127, bad)) == E_POINTER);
1323 std::memcpy(bad, words, sizeof(bad));
1324 bad[9] = 0;
1325 EXPECT(hr_of(raw10(device, 127, bad)) == E_POINTER);
1326 EXPECT(g_committed3.calls == before);
1327 EXPECT(xs::device_slot_overridden(127));
1328 EXPECT(release(device) == 0);
1329
1330 // A PC device that stops at ID3D12Device9 has no CreateCommittedResource3: E_NOTIMPL, a null object, no PC call.
1331 Mock* old_mock = nullptr;
1332 void* old_device = make_device(old_mock, 9, true);
1333 EXPECT(old_device && xs::device_proxy_slot_count(old_device) == 76);
1334 resource = reinterpret_cast<void*>(1);
1335 words[9] = word(&resource);
1336 const unsigned old_before = g_committed3.calls;
1337 EXPECT(hr_of(raw10(old_device, 127, words)) == E_NOTIMPL && !resource);
1338 EXPECT(g_committed3.calls == old_before && old_mock->calls[76] == 0);
1339 EXPECT(release(old_device) == 0);
1340 std::printf("%s: device slot 127 creates the committed resource with the PC flags and layout\n", g_label);
1341#endif
1342 return 0;
1343}
1344
1209} // namespace 1345} // namespace
1210 1346
1211// A failure ends the process with a message on stderr, never in a dialog a test run would wait on: abort() (an 1347// A failure ends the process with a message on stderr, never in a dialog a test run would wait on: abort() (an
@@ -1410,7 +1546,7 @@ int main(int argc, char** argv) {
1410 if (check_tail(true) || check_levels() || check_slot48() || check_fence1() || check_create_failures() || check_open_shared() || 1546 if (check_tail(true) || check_levels() || check_slot48() || check_fence1() || check_create_failures() || check_open_shared() ||
1411 check_alloc_failures() || check_allocators() || check_xbox_slots() || check_console_command_list() || 1547 check_alloc_failures() || check_allocators() || check_xbox_slots() || check_console_command_list() ||
1412 check_custom_heap_properties() || 1548 check_custom_heap_properties() ||
1413 check_resource_allocation_info() || check_slot70()) 1549 check_resource_allocation_info() || check_slot70() || check_committed_resource3_x())
1414 return 1; 1550 return 1;
1415 std::printf("xs_proxy_mock_test: PASS (%d allocations refused on purpose)\n", g_failed_news); 1551 std::printf("xs_proxy_mock_test: PASS (%d allocations refused on purpose)\n", g_failed_news);
1416 return 0; 1552 return 0;