diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index 8318757027d..dbc092b54c6 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp @@ -7162,7 +7162,10 @@ class Device final // (vkCreateShaderModule refuses the module without them, VUID-...-pCode-08740). opts->VPAndRTArrayIndexFromAnyShaderFeedingRasterizerSupportedWithoutGSEmulation = state_.info.shader_output_layer && state_.info.shader_output_viewport_index; - opts->ResourceHeapTier = D3D12_RESOURCE_HEAP_TIER_1; + // Tier 2: a heap may hold buffers and both kinds of texture together. CreateHeap accepts such heaps + // (heap_desc_refusal refuses only a heap that denies every kind) and placement checks only the heap's DENY + // flags, as on the console's RDNA2. A Tier 1 host (NVIDIA Pascal) refuses them (D3D-504, #4420). + opts->ResourceHeapTier = D3D12_RESOURCE_HEAP_TIER_2; return d3d12_trace::result(method, S_OK); } case D3D12_FEATURE_D3D12_OPTIONS1: { diff --git a/runtime/test/d3d12_vulkan_device_test.cpp b/runtime/test/d3d12_vulkan_device_test.cpp index 1aa9e2d46ce..851d2f77956 100644 --- a/runtime/test/d3d12_vulkan_device_test.cpp +++ b/runtime/test/d3d12_vulkan_device_test.cpp @@ -3143,6 +3143,25 @@ bool windows10_refusal(const char* name, ID3D12Device* host, HRESULT ours, HRESU return true; } +// The layer reports resource heap tier 2 and accepts a heap that holds buffers and both kinds of texture together. A +// tier 1 host (NVIDIA Pascal: GTX 1060 / 582.78, @ray3242 on #4420) refuses such a heap, so on that host only the +// layer's acceptance against the host's refusal is excused: `theirs` is the host's answer when the call is the +// CreateHeap itself, or E_UNEXPECTED when a placed-resource helper could not create its heap (D3D-504). +bool host_heap_tier1(ID3D12Device* host) { + D3D12_FEATURE_DATA_D3D12_OPTIONS o{}; + return SUCCEEDED(host->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &o, sizeof(o))) && + o.ResourceHeapTier == D3D12_RESOURCE_HEAP_TIER_1; +} + +bool tier1_mixed_heap_refusal(const char* name, ID3D12Device* host, HRESULT ours, HRESULT theirs, + HRESULT host_refusal) { + if (theirs != host_refusal || ours == theirs || (host_refusal == E_INVALIDARG && ours != S_OK)) return false; + if (!host_heap_tier1(host)) return false; + std::printf("invalid arguments %s: the tier 1 host refuses a heap of mixed resources (ours 0x%08lx, host " + "0x%08lx)\n", name, ours, theirs); + return true; +} + int compare_invalid_arguments(ID3D12Device* ours) { Ref host; if (!create_host_device(host)) return -1; @@ -4380,6 +4399,7 @@ int compare_heap_neighbours(ID3D12Device* ours) { const char* name; InvalidCase call; bool windows10_refuses = false; + bool mixed = true; // allows buffers and textures together: a tier 1 host refuses it (D3D-504) }; static const Case cases[] = { {"heap: alignment 0", [](ID3D12Device* d) { return heap_create(d, heap_desc_of(0)); }}, @@ -4404,7 +4424,7 @@ int compare_heap_neighbours(ID3D12Device* ours) { }}, {"heap: ALLOW_ONLY_BUFFERS (two DENY flags)", [](ID3D12Device* d) { return heap_create(d, heap_desc_of(0, {D3D12_HEAP_TYPE_DEFAULT}, D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS)); - }}, + }, false, false}, // The D3D12_HEAP_FLAGS documentation calls it unsupported, but the host accepts it (RTX 4070 SUPER and // UHD 770, @CowBoYdu76). Windows 10's and Windows 11 23H2's runtimes refuse it, as they refuse the committed // case above. @@ -4412,11 +4432,13 @@ int compare_heap_neighbours(ID3D12Device* ours) { return heap_create(d, heap_desc_of(0, {D3D12_HEAP_TYPE_DEFAULT}, D3D12_HEAP_FLAG_HARDWARE_PROTECTED)); }, true}, }; + std::printf("CreateHeap valid neighbours: host resource heap tier %d\n", host_heap_tier1(host.p) ? 1 : 2); int mismatches = 0; for (const Case& c : cases) { const HRESULT a = call_guarded(c.call, ours), b = call_guarded(c.call, host.p); if (a == b) continue; if (c.windows10_refuses && windows10_refusal(c.name, host.p, a, b)) continue; + if (c.mixed && tier1_mixed_heap_refusal(c.name, host.p, a, b, E_INVALIDARG)) continue; ++mismatches; std::fprintf(stderr, "invalid arguments %s: ours 0x%08lx, host 0x%08lx\n", c.name, a, b); } @@ -4915,6 +4937,8 @@ int compare_placed_reserved(ID3D12Device* ours) { if (verbose) std::printf(" ours 0x%08lx host 0x%08lx\n", a, b); if (a == b) continue; if (c.windows10_refuses && windows10_refusal(c.name, host.p, a, b)) continue; + // placed() answers E_UNEXPECTED when the device refuses the heap; PlacedArgs' heap allows every kind. + if (tier1_mixed_heap_refusal(c.name, host.p, a, b, E_UNEXPECTED)) continue; if (c.comparable && !c.comparable(host.p)) { std::printf("invalid arguments %s: not comparable on this host (ours 0x%08lx, host 0x%08lx)\n", c.name, a, b); @@ -7296,6 +7320,11 @@ int main() { heap_desc_of(0, {D3D12_HEAP_TYPE_DEFAULT}, D3D12_HEAP_FLAG_HARDWARE_PROTECTED), }; for (const D3D12_HEAP_DESC& hd : accepted_heaps) EXPECT(heap_create(standalone.p, hd) == S_OK); + // The heaps above that allow every resource kind are tier 2 heaps, so the layer reports tier 2 (D3D-504). + D3D12_FEATURE_DATA_D3D12_OPTIONS heap_opts{}; + EXPECT(SUCCEEDED(standalone->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &heap_opts, + sizeof(heap_opts)))); + EXPECT(heap_opts.ResourceHeapTier == D3D12_RESOURCE_HEAP_TIER_2); const int heap_mismatches = compare_heap_neighbours(standalone.p); if (heap_mismatches < 0) std::printf("CreateHeap valid neighbours: no host D3D12 device to compare with, skipped\n"); @@ -7754,11 +7783,13 @@ int main() { do { \ if (!(condition)) { std::fprintf(stderr, "line %d: %s\n", __LINE__, #condition); return false; } \ } while (0) + // Each heap holds one resource kind, so a resource heap tier 1 host (NVIDIA Pascal) creates it too (D3D-504). const auto placed_cast_scenario = [](ID3D12Device10* device10, bool layer, std::uint8_t* out) -> bool { D3D12_HEAP_DESC heap_desc{}; heap_desc.Properties.Type = D3D12_HEAP_TYPE_DEFAULT; heap_desc.SizeInBytes = 256 * 1024; heap_desc.Alignment = D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT; + heap_desc.Flags = D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES; Ref heap; CAST_CHECK(SUCCEEDED(device10->CreateHeap(&heap_desc, IID_PPV_ARGS(&heap.p)))); D3D12_RESOURCE_DESC1 texture{}; @@ -7850,8 +7881,11 @@ int main() { heap_desc.Properties.Type = D3D12_HEAP_TYPE_DEFAULT; heap_desc.SizeInBytes = 256 * 1024; heap_desc.Alignment = D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT; - Ref heap; + heap_desc.Flags = D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES; + Ref heap, buffer_heap; if (FAILED(device10->CreateHeap(&heap_desc, IID_PPV_ARGS(&heap.p)))) return false; + heap_desc.Flags = D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS; + if (FAILED(device10->CreateHeap(&heap_desc, IID_PPV_ARGS(&buffer_heap.p)))) return false; D3D12_RESOURCE_DESC1 texture{}; texture.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; texture.Width = 4; @@ -7873,7 +7907,7 @@ int main() { const DXGI_FORMAT unknown_list[] = {DXGI_FORMAT_UNKNOWN}; const DXGI_FORMAT wide_list[] = {DXGI_FORMAT_R16G16B16A16_FLOAT}; Ref refused; - out[0] = device10->CreatePlacedResource2(heap.p, 0, &buffer, D3D12_BARRIER_LAYOUT_UNDEFINED, nullptr, 1, + out[0] = device10->CreatePlacedResource2(buffer_heap.p, 0, &buffer, D3D12_BARRIER_LAYOUT_UNDEFINED, nullptr, 1, srgb_list, IID_PPV_ARGS(&refused.p)); out[1] = device10->CreatePlacedResource2(heap.p, 0, &texture, D3D12_BARRIER_LAYOUT_COMMON, nullptr, 1, unknown_list, IID_PPV_ARGS(&refused.p));