upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/test/d3d12_method_variants_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/test/d3d12_method_variants_test.cpp')
-rw-r--r--runtime/test/d3d12_method_variants_test.cpp311
1 files changed, 284 insertions, 27 deletions
diff --git a/runtime/test/d3d12_method_variants_test.cpp b/runtime/test/d3d12_method_variants_test.cpp
index 943577fff..d1b8edf4a 100644
--- a/runtime/test/d3d12_method_variants_test.cpp
+++ b/runtime/test/d3d12_method_variants_test.cpp
@@ -1,5 +1,6 @@
1// The 1/2/3 method variants of the Vulkan-backed ID3D12Device (D3D-28), each compared with the method it wraps: 1// The 1/2/3 method variants of the Vulkan-backed ID3D12Device (D3D-28), each compared with the method it wraps:
2// CreateCommittedResource1/2/3 with CreateCommittedResource, CreateCommandQueue1 with CreateCommandQueue and 2// CreateCommittedResource1/2/3 with CreateCommittedResource, CreatePlacedResource2 with CreatePlacedResource,
3// CreateReservedResource1/2 with CreateReservedResource, CreateCommandQueue1 with CreateCommandQueue and
3// GetCopyableFootprints1 with GetCopyableFootprints. The device is called directly, not through the Xbox-ABI proxy, 4// GetCopyableFootprints1 with GetCopyableFootprints. The device is called directly, not through the Xbox-ABI proxy,
4// because the proxy's slot 76 is the Xbox texture method, not CreateCommittedResource3 (docs/d3d12_vulkan.md 5// because the proxy's slot 76 is the Xbox texture method, not CreateCommittedResource3 (docs/d3d12_vulkan.md
5// section 7). The newer arguments' edge cases are checked against the PC runtime's answers, live when the host has 6// section 7). The newer arguments' edge cases are checked against the PC runtime's answers, live when the host has
@@ -215,22 +216,65 @@ struct Edge {
215// The edge cases of the newer arguments, run on any ID3D12Device10: ours, or the host's PC runtime to compare 216// The edge cases of the newer arguments, run on any ID3D12Device10: ours, or the host's PC runtime to compare
216// with. A GetCopyableFootprints1 answer is S_FALSE when every output is all ones (the failure answer), S_OK when 217// with. A GetCopyableFootprints1 answer is S_FALSE when every output is all ones (the failure answer), S_OK when
217// the footprint is the ordinary one, E_FAIL otherwise. 218// the footprint is the ordinary one, E_FAIL otherwise.
218std::vector<Edge> edge_answers(ID3D12Device10* device) { 219std::vector<Edge> edge_answers(ID3D12Device10* device, ID3D12Device10* placed_device,
219 const D3D12_HEAP_PROPERTIES default_heap{D3D12_HEAP_TYPE_DEFAULT}, upload_heap{D3D12_HEAP_TYPE_UPLOAD}; 220 ID3D12Device* size_host = nullptr) {
221 const D3D12_HEAP_PROPERTIES default_heap{D3D12_HEAP_TYPE_DEFAULT}, upload_heap{D3D12_HEAP_TYPE_UPLOAD},
222 readback_heap{D3D12_HEAP_TYPE_READBACK}, bad_heap{D3D12_HEAP_TYPE(99)};
220 D3D12_RESOURCE_DESC1 texture = desc1(texture_desc(8, 8, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE)); 223 D3D12_RESOURCE_DESC1 texture = desc1(texture_desc(8, 8, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE));
224 D3D12_RESOURCE_DESC1 rt_tex =
225 desc1(texture_desc(8, 8, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET));
226 D3D12_RESOURCE_DESC1 ds_tex =
227 desc1(texture_desc(8, 8, DXGI_FORMAT_D32_FLOAT, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL));
228 D3D12_RESOURCE_DESC1 ds_deny_tex = desc1(texture_desc(
229 8, 8, DXGI_FORMAT_D32_FLOAT, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL | D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE));
230 D3D12_RESOURCE_DESC1 uav_tex =
231 desc1(texture_desc(8, 8, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS));
232 D3D12_RESOURCE_DESC1 rt_ds_tex = desc1(texture_desc(
233 8, 8, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL));
234 D3D12_RESOURCE_DESC1 ds_uav_tex = desc1(texture_desc(
235 8, 8, DXGI_FORMAT_D32_FLOAT, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS));
236 D3D12_RESOURCE_DESC1 deny_only_tex =
237 desc1(texture_desc(8, 8, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE));
238 D3D12_RESOURCE_DESC1 zero_width_tex = desc1(texture_desc(0, 8, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE));
239 D3D12_RESOURCE_DESC1 big_tex =
240 desc1(texture_desc(1024, 1024, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE));
241 D3D12_RESOURCE_DESC1 tex_256x256 =
242 desc1(texture_desc(256, 256, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE));
243 D3D12_RESOURCE_DESC base_1000x600_10m =
244 texture_desc(1000, 600, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE, 10);
245 D3D12_RESOURCE_DESC base_300x200_f16 =
246 texture_desc(300, 200, DXGI_FORMAT_R16G16B16A16_FLOAT, D3D12_RESOURCE_FLAG_NONE);
247 D3D12_RESOURCE_DESC base_1x1024 =
248 texture_desc(1, 1024, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE);
249
221 D3D12_RESOURCE_DESC1 buffer = desc1(buffer_desc(300)); 250 D3D12_RESOURCE_DESC1 buffer = desc1(buffer_desc(300));
251 D3D12_RESOURCE_DESC1 uav_buffer = desc1(buffer_desc(256));
252 uav_buffer.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
253 D3D12_RESOURCE_DESC1 tall_buffer = desc1(buffer_desc(256));
254 tall_buffer.Height = 2;
255
222 D3D12_RESOURCE_DESC1 texture_region = texture, buffer_region = buffer; 256 D3D12_RESOURCE_DESC1 texture_region = texture, buffer_region = buffer;
223 texture_region.SamplerFeedbackMipRegion = buffer_region.SamplerFeedbackMipRegion = {4, 4, 1}; 257 texture_region.SamplerFeedbackMipRegion = buffer_region.SamplerFeedbackMipRegion = {4, 4, 1};
258
259 D3D12_CLEAR_VALUE cv_rt{DXGI_FORMAT_R8G8B8A8_UNORM, {0.f, 0.f, 0.f, 1.f}};
260 D3D12_CLEAR_VALUE cv_ds{DXGI_FORMAT_D32_FLOAT, {1.f, 0}};
261 D3D12_CLEAR_VALUE cv_bad{DXGI_FORMAT_R32_FLOAT, {0.f, 0.f, 0.f, 1.f}};
262
263 const DXGI_FORMAT srgb_cast[] = {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB};
264 const DXGI_FORMAT unknown_cast[] = {DXGI_FORMAT_UNKNOWN};
265 const DXGI_FORMAT wide_cast[] = {DXGI_FORMAT_R16G16B16A16_FLOAT};
266
224 const auto v2 = [&](const D3D12_HEAP_PROPERTIES& heap, const D3D12_RESOURCE_DESC1& desc) { 267 const auto v2 = [&](const D3D12_HEAP_PROPERTIES& heap, const D3D12_RESOURCE_DESC1& desc) {
225 Ref<ID3D12Resource> r; 268 Ref<ID3D12Resource> r;
226 return device->CreateCommittedResource2(&heap, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_COMMON, 269 return device->CreateCommittedResource2(&heap, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_COMMON,
227 nullptr, nullptr, IID_PPV_ARGS(&r.p)); 270 nullptr, nullptr, IID_PPV_ARGS(&r.p));
228 }; 271 };
229 const auto v3 = [&](const D3D12_HEAP_PROPERTIES& heap, const D3D12_RESOURCE_DESC1& desc, D3D12_BARRIER_LAYOUT layout, 272 const auto v3 = [&](const D3D12_HEAP_PROPERTIES& heap, const D3D12_RESOURCE_DESC1& desc, D3D12_BARRIER_LAYOUT layout,
230 UINT32 castable_count = 0, bool output = true) { 273 UINT32 castable_count = 0, bool output = true, D3D12_HEAP_FLAGS heap_flags = D3D12_HEAP_FLAG_NONE,
274 const D3D12_CLEAR_VALUE* clear = nullptr, const DXGI_FORMAT* castable = nullptr) {
231 Ref<ID3D12Resource> r; 275 Ref<ID3D12Resource> r;
232 return device->CreateCommittedResource3(&heap, D3D12_HEAP_FLAG_NONE, &desc, layout, nullptr, nullptr, 276 return device->CreateCommittedResource3(&heap, heap_flags, &desc, layout, clear, nullptr, castable_count,
233 castable_count, nullptr, __uuidof(ID3D12Resource), 277 castable, __uuidof(ID3D12Resource),
234 output ? reinterpret_cast<void**>(&r.p) : nullptr); 278 output ? reinterpret_cast<void**>(&r.p) : nullptr);
235 }; 279 };
236 const auto footprint = [&](const D3D12_RESOURCE_DESC1& desc) { 280 const auto footprint = [&](const D3D12_RESOURCE_DESC1& desc) {
@@ -245,6 +289,53 @@ std::vector<Edge> edge_answers(ID3D12Device10* device) {
245 void* queue = nullptr; 289 void* queue = nullptr;
246 const HRESULT null_queue = device->CreateCommandQueue1(nullptr, creator, __uuidof(ID3D12CommandQueue), &queue); 290 const HRESULT null_queue = device->CreateCommandQueue1(nullptr, creator, __uuidof(ID3D12CommandQueue), &queue);
247 if (queue) static_cast<IUnknown*>(queue)->Release(); 291 if (queue) static_cast<IUnknown*>(queue)->Release();
292
293 // Placed v2 setup.
294 D3D12_HEAP_DESC placed_heap_desc{256 * 1024, default_heap, D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT,
295 D3D12_HEAP_FLAG_NONE};
296 D3D12_HEAP_DESC upload_heap_desc{256 * 1024, upload_heap, D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT,
297 D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS};
298 Ref<ID3D12Heap> placed_heap, upload_placed_heap;
299 placed_device->CreateHeap(&placed_heap_desc, IID_PPV_ARGS(&placed_heap.p));
300 placed_device->CreateHeap(&upload_heap_desc, IID_PPV_ARGS(&upload_placed_heap.p));
301 const auto p2 = [&](ID3D12Heap* heap, UINT64 offset, const D3D12_RESOURCE_DESC1& desc, D3D12_BARRIER_LAYOUT layout,
302 const D3D12_CLEAR_VALUE* clear = nullptr, UINT32 cast_count = 0,
303 const DXGI_FORMAT* cast = nullptr) {
304 Ref<ID3D12Resource> r;
305 return placed_device->CreatePlacedResource2(heap, offset, &desc, layout, clear, cast_count, cast,
306 IID_PPV_ARGS(&r.p));
307 };
308 const auto p2_host_sized = [&](const D3D12_RESOURCE_DESC& base, UINT64 fallback_bytes) {
309 const UINT64 bytes = size_host ? size_host->GetResourceAllocationInfo(0, 1, &base).SizeInBytes
310 : fallback_bytes;
311 D3D12_HEAP_DESC hd{bytes, default_heap, D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT, D3D12_HEAP_FLAG_NONE};
312 Ref<ID3D12Heap> h;
313 if (FAILED(placed_device->CreateHeap(&hd, IID_PPV_ARGS(&h.p)))) return E_FAIL;
314 return p2(h.p, 0, desc1(base), D3D12_BARRIER_LAYOUT_COMMON);
315 };
316
317 // Reserved v1/v2 setup.
318 D3D12_RESOURCE_DESC res_tex = texture_desc(64, 64, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE);
319 res_tex.Layout = D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE;
320 D3D12_RESOURCE_DESC res_rt = res_tex;
321 res_rt.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
322 D3D12_RESOURCE_DESC res_uav = res_tex;
323 res_uav.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
324 D3D12_RESOURCE_DESC res_ds_deny = texture_desc(
325 64, 64, DXGI_FORMAT_D32_FLOAT, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL | D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE);
326 res_ds_deny.Layout = D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE;
327 D3D12_RESOURCE_DESC res_buf = buffer_desc(65536);
328 const auto r1 = [&](const D3D12_RESOURCE_DESC& desc, D3D12_RESOURCE_STATES state, const D3D12_CLEAR_VALUE* clear) {
329 Ref<ID3D12Resource> r;
330 return device->CreateReservedResource1(&desc, state, clear, nullptr, IID_PPV_ARGS(&r.p));
331 };
332 const auto r2 = [&](const D3D12_RESOURCE_DESC& desc, D3D12_BARRIER_LAYOUT layout,
333 const D3D12_CLEAR_VALUE* clear = nullptr, UINT32 cast_count = 0,
334 const DXGI_FORMAT* cast = nullptr) {
335 Ref<ID3D12Resource> r;
336 return device->CreateReservedResource2(&desc, layout, clear, nullptr, cast_count, cast, IID_PPV_ARGS(&r.p));
337 };
338
248 return { 339 return {
249 {"CreateCommittedResource2, texture with a mip region", v2(default_heap, texture_region), E_INVALIDARG}, 340 {"CreateCommittedResource2, texture with a mip region", v2(default_heap, texture_region), E_INVALIDARG},
250 {"CreateCommittedResource2, buffer with a mip region", v2(upload_heap, buffer_region), S_OK}, 341 {"CreateCommittedResource2, buffer with a mip region", v2(upload_heap, buffer_region), S_OK},
@@ -254,12 +345,138 @@ std::vector<Edge> edge_answers(ID3D12Device10* device) {
254 v3(upload_heap, buffer_region, D3D12_BARRIER_LAYOUT_UNDEFINED), S_OK}, 345 v3(upload_heap, buffer_region, D3D12_BARRIER_LAYOUT_UNDEFINED), S_OK},
255 {"CreateCommittedResource3, buffer in layout COMMON", v3(upload_heap, buffer, D3D12_BARRIER_LAYOUT_COMMON), 346 {"CreateCommittedResource3, buffer in layout COMMON", v3(upload_heap, buffer, D3D12_BARRIER_LAYOUT_COMMON),
256 E_INVALIDARG}, 347 E_INVALIDARG},
348 {"CreateCommittedResource3, upload buffer in UNDEFINED",
349 v3(upload_heap, buffer, D3D12_BARRIER_LAYOUT_UNDEFINED), S_OK},
350 {"CreateCommittedResource3, readback buffer in COMMON",
351 v3(readback_heap, buffer, D3D12_BARRIER_LAYOUT_COMMON), E_INVALIDARG},
352 {"CreateCommittedResource3, readback buffer in UNDEFINED",
353 v3(readback_heap, buffer, D3D12_BARRIER_LAYOUT_UNDEFINED), S_OK},
354 {"CreateCommittedResource3, upload buffer with ALLOW_UAV",
355 v3(upload_heap, uav_buffer, D3D12_BARRIER_LAYOUT_UNDEFINED), E_INVALIDARG},
356 {"CreateCommittedResource3, buffer with Height=2",
357 v3(default_heap, tall_buffer, D3D12_BARRIER_LAYOUT_UNDEFINED), E_INVALIDARG},
257 {"CreateCommittedResource3, texture in layout UNDEFINED", 358 {"CreateCommittedResource3, texture in layout UNDEFINED",
258 v3(default_heap, texture, D3D12_BARRIER_LAYOUT_UNDEFINED), S_OK}, 359 v3(default_heap, texture, D3D12_BARRIER_LAYOUT_UNDEFINED), S_OK},
259 {"CreateCommittedResource3, castable count with a null list", 360 {"CreateCommittedResource3, castable count with a null list",
260 v3(default_heap, texture, D3D12_BARRIER_LAYOUT_COMMON, 2), S_OK}, 361 v3(default_heap, texture, D3D12_BARRIER_LAYOUT_COMMON, 2), S_OK},
261 {"CreateCommittedResource3, null output", 362 {"CreateCommittedResource3, null output",
262 v3(default_heap, texture, D3D12_BARRIER_LAYOUT_COMMON, 0, false), S_FALSE}, 363 v3(default_heap, texture, D3D12_BARRIER_LAYOUT_COMMON, 0, false), S_FALSE},
364 {"CreateCommittedResource3, bad heap type",
365 v3(bad_heap, texture, D3D12_BARRIER_LAYOUT_COMMON), E_INVALIDARG},
366 {"CreateCommittedResource3, DENY_BUFFERS heap flag",
367 v3(default_heap, texture, D3D12_BARRIER_LAYOUT_COMMON, 0, true, D3D12_HEAP_FLAG_DENY_BUFFERS), E_INVALIDARG},
368 {"CreateCommittedResource3, ALLOW_DISPLAY on buffer",
369 v3(default_heap, buffer, D3D12_BARRIER_LAYOUT_UNDEFINED, 0, true, D3D12_HEAP_FLAG_ALLOW_DISPLAY),
370 E_INVALIDARG},
371 {"CreateCommittedResource3, clear value on buffer",
372 v3(upload_heap, buffer, D3D12_BARRIER_LAYOUT_UNDEFINED, 0, true, D3D12_HEAP_FLAG_NONE, &cv_rt), E_INVALIDARG},
373 {"CreateCommittedResource3, clear value on plain texture",
374 v3(default_heap, texture, D3D12_BARRIER_LAYOUT_COMMON, 0, true, D3D12_HEAP_FLAG_NONE, &cv_rt), E_INVALIDARG},
375 {"CreateCommittedResource3, mismatched clear value on RT",
376 v3(default_heap, rt_tex, D3D12_BARRIER_LAYOUT_COMMON, 0, true, D3D12_HEAP_FLAG_NONE, &cv_bad), E_INVALIDARG},
377 {"CreateCommittedResource3, valid clear value on RT",
378 v3(default_heap, rt_tex, D3D12_BARRIER_LAYOUT_RENDER_TARGET, 0, true, D3D12_HEAP_FLAG_NONE, &cv_rt), S_OK},
379 {"CreateCommittedResource3, valid clear value on DS",
380 v3(default_heap, ds_tex, D3D12_BARRIER_LAYOUT_DEPTH_STENCIL_WRITE, 0, true, D3D12_HEAP_FLAG_NONE, &cv_ds),
381 S_OK},
382 {"CreateCommittedResource3, RT | DS flags",
383 v3(default_heap, rt_ds_tex, D3D12_BARRIER_LAYOUT_COMMON), E_INVALIDARG},
384 {"CreateCommittedResource3, DS | UAV flags",
385 v3(default_heap, ds_uav_tex, D3D12_BARRIER_LAYOUT_COMMON), E_INVALIDARG},
386 {"CreateCommittedResource3, DENY_SHADER_RESOURCE without DS",
387 v3(default_heap, deny_only_tex, D3D12_BARRIER_LAYOUT_COMMON), E_INVALIDARG},
388 {"CreateCommittedResource3, texture Width=0",
389 v3(default_heap, zero_width_tex, D3D12_BARRIER_LAYOUT_COMMON), E_INVALIDARG},
390 {"CreateCommittedResource3, non-RT texture in RENDER_TARGET",
391 v3(default_heap, texture, D3D12_BARRIER_LAYOUT_RENDER_TARGET), E_INVALIDARG},
392 {"CreateCommittedResource3, non-UAV texture in UNORDERED_ACCESS",
393 v3(default_heap, texture, D3D12_BARRIER_LAYOUT_UNORDERED_ACCESS), E_INVALIDARG},
394 {"CreateCommittedResource3, non-UAV texture in DIRECT_QUEUE_UAV",
395 v3(default_heap, texture, D3D12_BARRIER_LAYOUT_DIRECT_QUEUE_UNORDERED_ACCESS), E_INVALIDARG},
396 {"CreateCommittedResource3, non-UAV texture in COMPUTE_QUEUE_UAV",
397 v3(default_heap, texture, D3D12_BARRIER_LAYOUT_COMPUTE_QUEUE_UNORDERED_ACCESS), E_INVALIDARG},
398 {"CreateCommittedResource3, UAV texture in DIRECT_QUEUE_UAV",
399 v3(default_heap, uav_tex, D3D12_BARRIER_LAYOUT_DIRECT_QUEUE_UNORDERED_ACCESS), S_OK},
400 {"CreateCommittedResource3, non-DS texture in DEPTH_STENCIL_WRITE",
401 v3(default_heap, texture, D3D12_BARRIER_LAYOUT_DEPTH_STENCIL_WRITE), E_INVALIDARG},
402 {"CreateCommittedResource3, non-DS texture in DEPTH_STENCIL_READ",
403 v3(default_heap, texture, D3D12_BARRIER_LAYOUT_DEPTH_STENCIL_READ), E_INVALIDARG},
404 {"CreateCommittedResource3, DS texture in DEPTH_STENCIL_READ",
405 v3(default_heap, ds_tex, D3D12_BARRIER_LAYOUT_DEPTH_STENCIL_READ), S_OK},
406 {"CreateCommittedResource3, DS+DENY_SR in SHADER_RESOURCE",
407 v3(default_heap, ds_deny_tex, D3D12_BARRIER_LAYOUT_SHADER_RESOURCE), E_INVALIDARG},
408 {"CreateCommittedResource3, DS+DENY_SR in DIRECT_QUEUE_SHADER_RESOURCE",
409 v3(default_heap, ds_deny_tex, D3D12_BARRIER_LAYOUT_DIRECT_QUEUE_SHADER_RESOURCE), E_INVALIDARG},
410 {"CreateCommittedResource3, DS+DENY_SR in COMPUTE_QUEUE_SHADER_RESOURCE",
411 v3(default_heap, ds_deny_tex, D3D12_BARRIER_LAYOUT_COMPUTE_QUEUE_SHADER_RESOURCE), E_INVALIDARG},
412 {"CreateCommittedResource3, DS+DENY_SR in GENERIC_READ",
413 v3(default_heap, ds_deny_tex, D3D12_BARRIER_LAYOUT_GENERIC_READ), S_OK},
414 {"CreatePlacedResource2, buffer in COMMON",
415 p2(upload_placed_heap.p, 0, buffer, D3D12_BARRIER_LAYOUT_COMMON), E_INVALIDARG},
416 {"CreatePlacedResource2, buffer with Height=2",
417 p2(placed_heap.p, 0, tall_buffer, D3D12_BARRIER_LAYOUT_UNDEFINED), E_INVALIDARG},
418 {"CreatePlacedResource2, upload buffer with ALLOW_UAV",
419 p2(upload_placed_heap.p, 0, uav_buffer, D3D12_BARRIER_LAYOUT_UNDEFINED), E_INVALIDARG},
420 {"CreatePlacedResource2, clear value on buffer",
421 p2(placed_heap.p, 0, buffer, D3D12_BARRIER_LAYOUT_UNDEFINED, &cv_rt), E_INVALIDARG},
422 {"CreatePlacedResource2, clear value on plain texture",
423 p2(placed_heap.p, 0, texture, D3D12_BARRIER_LAYOUT_COMMON, &cv_rt), E_INVALIDARG},
424 {"CreatePlacedResource2, valid clear value on RT",
425 p2(placed_heap.p, 0, rt_tex, D3D12_BARRIER_LAYOUT_RENDER_TARGET, &cv_rt), S_OK},
426 {"CreatePlacedResource2, oversized 1024x1024 texture in 256 KiB heap",
427 p2(placed_heap.p, 0, big_tex, D3D12_BARRIER_LAYOUT_COMMON), E_INVALIDARG},
428 {"CreatePlacedResource2, 256x256 at 64 KiB in 256 KiB heap",
429 p2(placed_heap.p, 65536, tex_256x256, D3D12_BARRIER_LAYOUT_COMMON), E_INVALIDARG},
430 {"CreatePlacedResource2, 1000x600 RGBA8 10 mips in host-sized heap",
431 p2_host_sized(base_1000x600_10m, 3538944), S_OK},
432 {"CreatePlacedResource2, 300x200 RGBA16F in host-sized heap",
433 p2_host_sized(base_300x200_f16, 589824), S_OK},
434 {"CreatePlacedResource2, 1x1024 RGBA8 in 64 KiB heap",
435 p2_host_sized(base_1x1024, 65536), S_OK},
436 {"CreatePlacedResource2, 8x8 texture at 192 KiB in 256 KiB heap",
437 p2(placed_heap.p, 3 * 65536, texture, D3D12_BARRIER_LAYOUT_COMMON), S_OK},
438 {"CreatePlacedResource2, non-RT texture in RENDER_TARGET",
439 p2(placed_heap.p, 0, texture, D3D12_BARRIER_LAYOUT_RENDER_TARGET), E_INVALIDARG},
440 {"CreatePlacedResource2, non-UAV texture in UNORDERED_ACCESS",
441 p2(placed_heap.p, 0, texture, D3D12_BARRIER_LAYOUT_UNORDERED_ACCESS), E_INVALIDARG},
442 {"CreatePlacedResource2, non-DS texture in DEPTH_STENCIL_WRITE",
443 p2(placed_heap.p, 0, texture, D3D12_BARRIER_LAYOUT_DEPTH_STENCIL_WRITE), E_INVALIDARG},
444 {"CreatePlacedResource2, DS+DENY_SR in DIRECT_QUEUE_SHADER_RESOURCE",
445 p2(placed_heap.p, 0, ds_deny_tex, D3D12_BARRIER_LAYOUT_DIRECT_QUEUE_SHADER_RESOURCE), E_INVALIDARG},
446 {"CreateReservedResource1, clear value on plain texture",
447 r1(res_tex, D3D12_RESOURCE_STATE_COMMON, &cv_rt), E_INVALIDARG},
448 {"CreateReservedResource2, buffer in COMMON",
449 r2(res_buf, D3D12_BARRIER_LAYOUT_COMMON), E_INVALIDARG},
450 {"CreateReservedResource2, buffer in UNDEFINED",
451 r2(res_buf, D3D12_BARRIER_LAYOUT_UNDEFINED), S_OK},
452 {"CreateReservedResource2, clear value on buffer",
453 r2(res_buf, D3D12_BARRIER_LAYOUT_UNDEFINED, &cv_rt), E_INVALIDARG},
454 {"CreateReservedResource2, clear value on plain texture",
455 r2(res_tex, D3D12_BARRIER_LAYOUT_COMMON, &cv_rt), E_INVALIDARG},
456 {"CreateReservedResource2, mismatched clear value on RT",
457 r2(res_rt, D3D12_BARRIER_LAYOUT_COMMON, &cv_bad), E_INVALIDARG},
458 {"CreateReservedResource2, valid clear value on RT",
459 r2(res_rt, D3D12_BARRIER_LAYOUT_RENDER_TARGET, &cv_rt), S_OK},
460 {"CreateReservedResource2, non-RT texture in RENDER_TARGET",
461 r2(res_tex, D3D12_BARRIER_LAYOUT_RENDER_TARGET), E_INVALIDARG},
462 {"CreateReservedResource2, non-UAV texture in UNORDERED_ACCESS",
463 r2(res_tex, D3D12_BARRIER_LAYOUT_UNORDERED_ACCESS), E_INVALIDARG},
464 {"CreateReservedResource2, UAV texture in COMPUTE_QUEUE_UAV",
465 r2(res_uav, D3D12_BARRIER_LAYOUT_COMPUTE_QUEUE_UNORDERED_ACCESS), S_OK},
466 {"CreateReservedResource2, non-DS texture in DEPTH_STENCIL_WRITE",
467 r2(res_tex, D3D12_BARRIER_LAYOUT_DEPTH_STENCIL_WRITE), E_INVALIDARG},
468 {"CreateReservedResource2, DS+DENY_SR in SHADER_RESOURCE",
469 r2(res_ds_deny, D3D12_BARRIER_LAYOUT_SHADER_RESOURCE), E_INVALIDARG},
470 {"CreateReservedResource2, castable format on buffer",
471 r2(res_buf, D3D12_BARRIER_LAYOUT_UNDEFINED, nullptr, 1, srgb_cast), E_INVALIDARG},
472 {"CreateReservedResource2, unknown castable format on texture",
473 r2(res_tex, D3D12_BARRIER_LAYOUT_COMMON, nullptr, 1, unknown_cast), E_INVALIDARG},
474 {"CreateReservedResource2, mismatched texel-size castable format",
475 r2(res_tex, D3D12_BARRIER_LAYOUT_COMMON, nullptr, 1, wide_cast), E_INVALIDARG},
476 {"CreateReservedResource2, valid castable format on texture",
477 r2(res_tex, D3D12_BARRIER_LAYOUT_COMMON, nullptr, 1, srgb_cast), S_OK},
478 {"CreateReservedResource2, castable count with null list",
479 r2(res_tex, D3D12_BARRIER_LAYOUT_COMMON, nullptr, 2, nullptr), S_OK},
263 {"CreateCommandQueue1, null description", null_queue, E_INVALIDARG}, 480 {"CreateCommandQueue1, null description", null_queue, E_INVALIDARG},
264 {"GetCopyableFootprints1, texture with a mip region", footprint(texture_region), S_FALSE}, 481 {"GetCopyableFootprints1, texture with a mip region", footprint(texture_region), S_FALSE},
265 {"GetCopyableFootprints1, buffer with a mip region", footprint(buffer_region), S_OK}, 482 {"GetCopyableFootprints1, buffer with a mip region", footprint(buffer_region), S_OK},
@@ -297,32 +514,47 @@ int main() {
297 EXPECT(create(device.p, via, upload_heap, buffer_desc(256), &out, fake_session()) == E_INVALIDARG); 514 EXPECT(create(device.p, via, upload_heap, buffer_desc(256), &out, fake_session()) == E_INVALIDARG);
298 EXPECT(out == nullptr); 515 EXPECT(out == nullptr);
299 } 516 }
517 {
518 D3D12_RESOURCE_DESC tiled_buf = buffer_desc(65536);
519 void* out = reinterpret_cast<void*>(1);
520 EXPECT(device->CreateReservedResource1(&tiled_buf, D3D12_RESOURCE_STATE_COMMON, nullptr, fake_session(),
521 __uuidof(ID3D12Resource), &out) == E_INVALIDARG);
522 EXPECT(out == nullptr);
523 out = reinterpret_cast<void*>(1);
524 EXPECT(device->CreateReservedResource2(&tiled_buf, D3D12_BARRIER_LAYOUT_UNDEFINED, nullptr, fake_session(),
525 0, nullptr, __uuidof(ID3D12Resource), &out) == E_INVALIDARG);
526 EXPECT(out == nullptr);
527 }
300 528
301 // The newer arguments' edge cases, each with the answer the PC runtime gives (and, when the host has a 529 // The newer arguments' edge cases, each with the answer the PC runtime gives (and, when the host has a
302 // D3D12 device, compared with it live). 530 // D3D12 device, compared with it live). Placed cases use standalone_device so the heap arena is present.
303 const std::vector<Edge> ours = edge_answers(device.p); 531 const HMODULE d3d12 = LoadLibraryExA("d3d12.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
532 const auto create_host = d3d12 ? reinterpret_cast<PFN_D3D12_CREATE_DEVICE>(
533 reinterpret_cast<void*>(GetProcAddress(d3d12, "D3D12CreateDevice")))
534 : nullptr;
535 Ref<ID3D12Device10> host;
536 const bool have_host =
537 create_host && SUCCEEDED(create_host(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&host.p)));
538 Ref<ID3D12Device> standalone_base;
539 Ref<ID3D12Device10> standalone_device;
540 EXPECT(SUCCEEDED(rt::d3d12::create_vulkan_device_standalone(IID_PPV_ARGS(&standalone_base.p))));
541 EXPECT(SUCCEEDED(standalone_base->QueryInterface(IID_PPV_ARGS(&standalone_device.p))));
542 const std::vector<Edge> ours = edge_answers(device.p, standalone_device.p, host.p);
304 for (const Edge& e : ours) { 543 for (const Edge& e : ours) {
305 if (e.got == e.want) continue; 544 if (e.got == e.want) continue;
306 std::fprintf(stderr, "%s: got %08lx, want %08lx\n", e.name, e.got, e.want); 545 std::fprintf(stderr, "%s: got %08lx, want %08lx\n", e.name, e.got, e.want);
307 return 1; 546 return 1;
308 } 547 }
309 { 548 if (have_host) {
310 const HMODULE d3d12 = LoadLibraryExA("d3d12.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); 549 const std::vector<Edge> theirs = edge_answers(host.p, host.p, host.p);
311 const auto create_host = d3d12 ? reinterpret_cast<PFN_D3D12_CREATE_DEVICE>( 550 for (std::size_t i = 0; i < ours.size(); ++i) {
312 reinterpret_cast<void*>(GetProcAddress(d3d12, "D3D12CreateDevice"))) 551 if (ours[i].got == theirs[i].got) continue;
313 : nullptr; 552 std::fprintf(stderr, "%s: ours %08lx, host runtime %08lx\n", ours[i].name, ours[i].got,
314 Ref<ID3D12Device10> host; 553 theirs[i].got);
315 if (create_host && SUCCEEDED(create_host(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&host.p)))) { 554 return 1;
316 const std::vector<Edge> theirs = edge_answers(host.p);
317 for (std::size_t i = 0; i < ours.size(); ++i) {
318 if (ours[i].got == theirs[i].got) continue;
319 std::fprintf(stderr, "%s: ours %08lx, host runtime %08lx\n", ours[i].name, ours[i].got,
320 theirs[i].got);
321 return 1;
322 }
323 } else {
324 std::printf("no host D3D12 device: edge cases checked against their recorded answers only\n");
325 } 555 }
556 } else {
557 std::printf("no host D3D12 device: edge cases checked against their recorded answers only\n");
326 } 558 }
327 559
328 // Castable formats: the layer reports relaxed format casting and passes a real list to 560 // Castable formats: the layer reports relaxed format casting and passes a real list to
@@ -359,7 +591,7 @@ int main() {
359 Ref<ID3D12DescriptorHeap> heap; 591 Ref<ID3D12DescriptorHeap> heap;
360 D3D12_DESCRIPTOR_HEAP_DESC heap_desc{}; 592 D3D12_DESCRIPTOR_HEAP_DESC heap_desc{};
361 heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; 593 heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
362 heap_desc.NumDescriptors = 3; 594 heap_desc.NumDescriptors = 4;
363 heap_desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE; 595 heap_desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
364 EXPECT(SUCCEEDED(device->CreateDescriptorHeap(&heap_desc, IID_PPV_ARGS(&heap.p)))); 596 EXPECT(SUCCEEDED(device->CreateDescriptorHeap(&heap_desc, IID_PPV_ARGS(&heap.p))));
365 D3D12_CPU_DESCRIPTOR_HANDLE slot = heap->GetCPUDescriptorHandleForHeapStart(); 597 D3D12_CPU_DESCRIPTOR_HANDLE slot = heap->GetCPUDescriptorHandleForHeapStart();
@@ -413,6 +645,30 @@ int main() {
413 nonzero = false; 645 nonzero = false;
414 for (std::uint32_t word : words) nonzero = nonzero || word != 0; 646 for (std::uint32_t word : words) nonzero = nonzero || word != 0;
415 EXPECT(nonzero); 647 EXPECT(nonzero);
648
649 // CreateReservedResource2 forwards its castable list to the backing Vulkan image too.
650 const auto slot_is_zero = [](D3D12_CPU_DESCRIPTOR_HANDLE handle) {
651 std::uint32_t descriptor_words[8]{};
652 std::memcpy(descriptor_words, reinterpret_cast<void*>(handle.ptr), sizeof(descriptor_words));
653 for (std::uint32_t word : descriptor_words)
654 if (word != 0) return false;
655 return true;
656 };
657 D3D12_RESOURCE_DESC res_tex = texture_desc(64, 64, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE);
658 res_tex.Layout = D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE;
659 Ref<ID3D12Resource> reserved_srgb;
660 EXPECT(SUCCEEDED(device->CreateReservedResource2(&res_tex, D3D12_BARRIER_LAYOUT_COMMON, nullptr, nullptr, 1,
661 srgb_only, IID_PPV_ARGS(&reserved_srgb.p))));
662 slot.ptr += stride;
663 srv.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
664 device->CreateShaderResourceView(reserved_srgb.p, &srv, slot);
665 EXPECT(!slot_is_zero(slot));
666 srv.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
667 device->CreateShaderResourceView(reserved_srgb.p, &srv, slot);
668 EXPECT(!slot_is_zero(slot));
669 srv.Format = DXGI_FORMAT_R8G8B8A8_UINT;
670 device->CreateShaderResourceView(reserved_srgb.p, &srv, slot);
671 EXPECT(slot_is_zero(slot));
416 } 672 }
417 673
418 // A texture from CreateCommittedResource3 (a castable count with a null list, which is no list) is 674 // A texture from CreateCommittedResource3 (a castable count with a null list, which is no list) is
@@ -523,7 +779,8 @@ int main() {
523 std::fprintf(stderr, "%u validation errors\n", d.validation_errors()); 779 std::fprintf(stderr, "%u validation errors\n", d.validation_errors());
524 return 1; 780 return 1;
525 } 781 }
526 std::printf("D3D12 method variants: CreateCommittedResource1/2/3, CreateCommandQueue1 and GetCopyableFootprints1 " 782 std::printf("D3D12 method variants: CreateCommittedResource1/2/3, CreatePlacedResource2, "
527 "matched their base methods and the PC runtime's edge-case answers; a texture round-tripped\n"); 783 "CreateReservedResource1/2, CreateCommandQueue1 and GetCopyableFootprints1 matched their base methods "
784 "and the PC runtime's edge-case answers; a texture round-tripped\n");
528 return 0; 785 return 0;
529} 786}