mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 14:08:38 +00:00
dxgi: a failed ResizeBuffers leaves the swap chain without buffers until the next one succeeds, as on the host
Measured against the host runtime (RTX 3060 Ti, NVIDIA 610.88, and WARP): once ResizeBuffers accepts its arguments the old buffers are gone. If the new ones can't be made it fails, and the swap chain stays without buffers. GetDesc1 already reports the requested size and count, GetBuffer and Present are DXGI_ERROR_INVALID_CALL, and the next successful ResizeBuffers restores everything. A side above 16384 is E_INVALIDARG on the hardware device. A call refused for its arguments (a back buffer still held) changes nothing. The layer answered E_FAIL and kept describing the old buffers. It now answers E_INVALIDARG for a side above 16384 before calling Vulkan (it used to pass the extent to vkCreateImage, past the device's limits) and E_OUTOFMEMORY when Vulkan fails. It reports the requested description, refuses Present, and recovers on the next ResizeBuffers. dxgi_swapchain_test compares 15 steps of that with the host's default adapter. dxgi_swapchain_count_test gets failure injection on its fake Vulkan table: whether the offscreen ring or vkCreateSwapchainKHR fails (the latter retires the old swapchain anyway), on the offscreen and on the direct path, the next resize builds a working swapchain. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -305,6 +305,7 @@ public:
|
||||
if ((flags & DXGI_PRESENT_ALLOW_TEARING) &&
|
||||
(sync != 0 || !(flags_ & DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING)))
|
||||
return DXGI_ERROR_INVALID_CALL;
|
||||
if (lost_) return DXGI_ERROR_INVALID_CALL; // host-measured: no buffers after a failed ResizeBuffers
|
||||
if (flags & DXGI_PRESENT_TEST) return S_OK; // only asks whether a present would succeed
|
||||
const std::uint32_t cur = swapchain_.current_back_buffer_index();
|
||||
if (!swapchain_.present(cur)) return E_FAIL;
|
||||
@ -334,12 +335,12 @@ public:
|
||||
HRESULT STDMETHODCALLTYPE GetDesc(DXGI_SWAP_CHAIN_DESC* desc) override {
|
||||
if (!desc) return E_INVALIDARG;
|
||||
std::memset(desc, 0, sizeof(*desc));
|
||||
desc->BufferDesc.Width = swapchain_.extent().width;
|
||||
desc->BufferDesc.Height = swapchain_.extent().height;
|
||||
desc->BufferDesc.Format = vk_to_dxgi_format(swapchain_.format());
|
||||
desc->BufferDesc.Width = lost_ ? lost_width_ : swapchain_.extent().width;
|
||||
desc->BufferDesc.Height = lost_ ? lost_height_ : swapchain_.extent().height;
|
||||
desc->BufferDesc.Format = current_format();
|
||||
desc->SampleDesc.Count = 1;
|
||||
desc->BufferUsage = buffer_usage_;
|
||||
desc->BufferCount = swapchain_.image_count();
|
||||
desc->BufferCount = lost_ ? lost_count_ : swapchain_.image_count();
|
||||
desc->OutputWindow = hwnd_;
|
||||
desc->Windowed = TRUE;
|
||||
desc->SwapEffect = swap_effect_;
|
||||
@ -347,6 +348,19 @@ public:
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// The swap chain's format as GetDesc reports it.
|
||||
DXGI_FORMAT current_format() const { return lost_ ? lost_format_ : vk_to_dxgi_format(swapchain_.format()); }
|
||||
|
||||
// A failed ResizeBuffers (see resize_buffers): no buffers until the next successful one, and the description
|
||||
// reports what was asked for.
|
||||
void lose_buffers(std::uint32_t width, std::uint32_t height, UINT count, DXGI_FORMAT format) {
|
||||
lost_ = true;
|
||||
lost_width_ = width;
|
||||
lost_height_ = height;
|
||||
lost_count_ = count;
|
||||
lost_format_ = format;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE ResizeBuffers(UINT count, UINT width, UINT height, DXGI_FORMAT fmt, UINT flags) override {
|
||||
return resize_buffers(count, width, height, fmt, flags, nullptr, nullptr);
|
||||
}
|
||||
@ -374,18 +388,37 @@ public:
|
||||
// DXGI refuses to resize while the app still holds a back buffer reference.
|
||||
for (auto* bb : buffers_)
|
||||
if (bb->held_by_app()) return DXGI_ERROR_INVALID_CALL;
|
||||
const std::size_t target_count = count ? count : buffers_.size();
|
||||
const std::size_t target_count = count ? count : (lost_ ? lost_count_ : buffers_.size());
|
||||
if (node_masks && !std::all_of(node_masks, node_masks + target_count, [](UINT mask) { return mask <= 1; }))
|
||||
return DXGI_ERROR_INVALID_CALL;
|
||||
if (present_queues && !std::all_of(present_queues, present_queues + target_count, is_direct_present_queue))
|
||||
return DXGI_ERROR_INVALID_CALL;
|
||||
unregister_buffers();
|
||||
const VkExtent2D size = size_or_client(width, height, swapchain_.extent());
|
||||
const VkExtent2D size = size_or_client(width, height, lost_ ? VkExtent2D{lost_width_, lost_height_}
|
||||
: swapchain_.extent());
|
||||
const std::uint32_t w = size.width;
|
||||
const std::uint32_t h = size.height;
|
||||
const UINT next_flags = flags ? flags : flags_;
|
||||
const bool allow_tearing = (next_flags & DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) != 0;
|
||||
if (!swapchain_.resize(w, h, vk_fmt, count, allow_tearing)) return E_FAIL;
|
||||
// Host-measured (RTX 3060 Ti / NVIDIA 610.88 and WARP): once the arguments are accepted, the old buffers are
|
||||
// gone. When the new ones can't be made, ResizeBuffers fails and the swap chain stays without buffers: its
|
||||
// description already has the new size and count, GetBuffer and Present are DXGI_ERROR_INVALID_CALL, and the
|
||||
// next successful ResizeBuffers brings it back. A side above 16384 is E_INVALIDARG on the hardware device
|
||||
// (WARP takes 16385 and answers E_OUTOFMEMORY at 32768); a Vulkan failure here is E_OUTOFMEMORY.
|
||||
// The size check also keeps vkCreateImage from an extent past the device's limits.
|
||||
const DXGI_FORMAT next_format = fmt != DXGI_FORMAT_UNKNOWN ? fmt : current_format();
|
||||
if (w > D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION || h > D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION) {
|
||||
lose_buffers(w, h, static_cast<UINT>(target_count), next_format);
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
// Format UNKNOWN keeps the swap chain's format, which after a failed ResizeBuffers is the one it asked for.
|
||||
const VkFormat resize_format = vk_fmt != VK_FORMAT_UNDEFINED ? vk_fmt
|
||||
: lost_ ? dxgi_to_vk_format(lost_format_) : VK_FORMAT_UNDEFINED;
|
||||
if (!swapchain_.resize(w, h, resize_format, static_cast<std::uint32_t>(target_count), allow_tearing)) {
|
||||
lose_buffers(w, h, static_cast<UINT>(target_count), next_format);
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
lost_ = false;
|
||||
source_size_ = {w, h}; // host-measured: ResizeBuffers resets the source region to the new back buffers
|
||||
statistics_disjoint_.store(true, std::memory_order_relaxed);
|
||||
flags_ = next_flags;
|
||||
@ -462,12 +495,12 @@ public:
|
||||
HRESULT STDMETHODCALLTYPE GetDesc1(DXGI_SWAP_CHAIN_DESC1* desc) override {
|
||||
if (!desc) return E_INVALIDARG;
|
||||
std::memset(desc, 0, sizeof(*desc));
|
||||
desc->Width = swapchain_.extent().width;
|
||||
desc->Height = swapchain_.extent().height;
|
||||
desc->Format = vk_to_dxgi_format(swapchain_.format());
|
||||
desc->Width = lost_ ? lost_width_ : swapchain_.extent().width;
|
||||
desc->Height = lost_ ? lost_height_ : swapchain_.extent().height;
|
||||
desc->Format = current_format();
|
||||
desc->SampleDesc.Count = 1;
|
||||
desc->BufferUsage = buffer_usage_;
|
||||
desc->BufferCount = swapchain_.image_count();
|
||||
desc->BufferCount = lost_ ? lost_count_ : swapchain_.image_count();
|
||||
desc->Scaling = DXGI_SCALING_STRETCH;
|
||||
desc->SwapEffect = swap_effect_;
|
||||
desc->AlphaMode = DXGI_ALPHA_MODE_IGNORE;
|
||||
@ -642,6 +675,11 @@ private:
|
||||
DXGI_USAGE buffer_usage_ = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
HANDLE waitable_ = nullptr;
|
||||
std::vector<BackBufferResource*> buffers_;
|
||||
bool lost_ = false; // after a failed ResizeBuffers: no buffers, the description below
|
||||
std::uint32_t lost_width_ = 0;
|
||||
std::uint32_t lost_height_ = 0;
|
||||
UINT lost_count_ = 0;
|
||||
DXGI_FORMAT lost_format_ = DXGI_FORMAT_UNKNOWN;
|
||||
std::atomic<UINT> present_count_{0};
|
||||
std::atomic<bool> statistics_disjoint_{true};
|
||||
std::atomic<LONGLONG> last_present_qpc_{0};
|
||||
|
||||
@ -36,6 +36,13 @@ struct Fake {
|
||||
VkImage blit_dst = VK_NULL_HANDLE;
|
||||
unsigned presents = 0;
|
||||
unsigned created_offscreen = 0;
|
||||
// Failure injection for the failed-ResizeBuffers cases: the next N swapchain or image creations fail.
|
||||
unsigned fail_swapchain_creates = 0;
|
||||
unsigned fail_image_creates = 0;
|
||||
unsigned swapchains_made = 0;
|
||||
unsigned destroyed_images = 0;
|
||||
VkSwapchainKHR live = VK_NULL_HANDLE; // the swapchain that can acquire
|
||||
VkSwapchainKHR retired = VK_NULL_HANDLE; // retired by a vkCreateSwapchainKHR, failed or not
|
||||
};
|
||||
Fake g;
|
||||
|
||||
@ -99,8 +106,16 @@ VKAPI_ATTR void VKAPI_CALL memory_properties(VkPhysicalDevice, VkPhysicalDeviceM
|
||||
VKAPI_ATTR VkResult VKAPI_CALL create_swapchain(VkDevice, const VkSwapchainCreateInfoKHR* info,
|
||||
const VkAllocationCallbacks*, VkSwapchainKHR* out) {
|
||||
if (!info || !out) return VK_ERROR_INITIALIZATION_FAILED;
|
||||
// The Vulkan rule this test leans on: oldSwapchain is retired even when creation fails.
|
||||
if (info->oldSwapchain) g.retired = info->oldSwapchain;
|
||||
if (g.fail_swapchain_creates) {
|
||||
--g.fail_swapchain_creates;
|
||||
if (g.live == info->oldSwapchain) g.live = VK_NULL_HANDLE;
|
||||
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
|
||||
}
|
||||
g.create_min_image_count = info->minImageCount;
|
||||
*out = reinterpret_cast<VkSwapchainKHR>(kSwapchain);
|
||||
*out = reinterpret_cast<VkSwapchainKHR>(kSwapchain + 0x10 * g.swapchains_made++);
|
||||
g.live = *out;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
VKAPI_ATTR void VKAPI_CALL destroy_swapchain(VkDevice, VkSwapchainKHR, const VkAllocationCallbacks*) {}
|
||||
@ -112,9 +127,10 @@ VKAPI_ATTR VkResult VKAPI_CALL get_images(VkDevice, VkSwapchainKHR, std::uint32_
|
||||
*count = g.returned_images;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
VKAPI_ATTR VkResult VKAPI_CALL acquire_next_image(VkDevice, VkSwapchainKHR, std::uint64_t, VkSemaphore, VkFence,
|
||||
std::uint32_t* out) {
|
||||
VKAPI_ATTR VkResult VKAPI_CALL acquire_next_image(VkDevice, VkSwapchainKHR swapchain, std::uint64_t, VkSemaphore,
|
||||
VkFence, std::uint32_t* out) {
|
||||
if (!out || g.returned_images == 0) return VK_ERROR_INITIALIZATION_FAILED;
|
||||
if (swapchain != g.live) return VK_ERROR_OUT_OF_DATE_KHR; // a retired swapchain cannot acquire
|
||||
g.last_acquired = g.acquire_cursor % g.returned_images;
|
||||
++g.acquire_cursor;
|
||||
*out = g.last_acquired;
|
||||
@ -122,6 +138,7 @@ VKAPI_ATTR VkResult VKAPI_CALL acquire_next_image(VkDevice, VkSwapchainKHR, std:
|
||||
}
|
||||
VKAPI_ATTR VkResult VKAPI_CALL queue_present(VkQueue, const VkPresentInfoKHR* info) {
|
||||
if (!info || info->swapchainCount != 1 || !info->pImageIndices) return VK_ERROR_INITIALIZATION_FAILED;
|
||||
if (!info->pSwapchains || info->pSwapchains[0] != g.live) return VK_ERROR_OUT_OF_DATE_KHR;
|
||||
g.presented_image = info->pImageIndices[0];
|
||||
++g.presents;
|
||||
return VK_SUCCESS;
|
||||
@ -140,10 +157,14 @@ VKAPI_ATTR VkResult VKAPI_CALL device_wait_idle(VkDevice) { return VK_SUCCESS; }
|
||||
VKAPI_ATTR VkResult VKAPI_CALL create_image(VkDevice, const VkImageCreateInfo*, const VkAllocationCallbacks*,
|
||||
VkImage* out) {
|
||||
if (!out) return VK_ERROR_INITIALIZATION_FAILED;
|
||||
if (g.fail_image_creates) {
|
||||
--g.fail_image_creates;
|
||||
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
|
||||
}
|
||||
*out = reinterpret_cast<VkImage>(static_cast<std::uintptr_t>(kOffscreenBase + g.created_offscreen++));
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
VKAPI_ATTR void VKAPI_CALL destroy_image(VkDevice, VkImage, const VkAllocationCallbacks*) {}
|
||||
VKAPI_ATTR void VKAPI_CALL destroy_image(VkDevice, VkImage, const VkAllocationCallbacks*) { ++g.destroyed_images; }
|
||||
VKAPI_ATTR void VKAPI_CALL image_mem_req(VkDevice, VkImage, VkMemoryRequirements* req) {
|
||||
std::memset(req, 0, sizeof(*req));
|
||||
req->size = 4096;
|
||||
@ -326,6 +347,63 @@ int run_case(const char* label, std::uint32_t requested, std::uint32_t native, s
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Acquires and presents one frame on `swapchain`, which must still reach the live native swapchain.
|
||||
int present_one(const char* label, leonida::VulkanSwapchain& swapchain) {
|
||||
std::uint32_t index = 0;
|
||||
if (!swapchain.acquire_next_image(index)) {
|
||||
std::fprintf(stderr, "FAIL: %s: acquire after the failed resize\n", label);
|
||||
return 1;
|
||||
}
|
||||
const std::uint32_t current = swapchain.current_back_buffer_index();
|
||||
if (current >= swapchain.image_count()) return fail("current index out of range after the failed resize");
|
||||
g.presented_image = UINT32_MAX;
|
||||
if (!swapchain.present(current) || g.presented_image == UINT32_MAX) {
|
||||
std::fprintf(stderr, "FAIL: %s: present after the failed resize\n", label);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// After a failed ResizeBuffers the host's swap chain has no buffers (GetBuffer and Present are
|
||||
// DXGI_ERROR_INVALID_CALL; dxgi_swapchain_test compares that with the host), and the next successful
|
||||
// ResizeBuffers brings it back. This is the Vulkan side of that: whichever step fails (the offscreen ring, or
|
||||
// vkCreateSwapchainKHR, which retires the old swapchain even when it fails), a later resize still builds a
|
||||
// working swapchain, on the offscreen and on the direct path.
|
||||
int run_failed_resize(const char* label, std::uint32_t requested, std::uint32_t native, bool offscreen,
|
||||
bool fail_swapchain) {
|
||||
g = Fake{};
|
||||
g.min_image_count = 2;
|
||||
g.returned_images = native;
|
||||
std::mutex mutex;
|
||||
leonida::VulkanSwapchain swapchain(get_instance_proc, reinterpret_cast<VkInstance>(1),
|
||||
reinterpret_cast<VkPhysicalDevice>(2), get_device_proc,
|
||||
reinterpret_cast<VkDevice>(3), reinterpret_cast<VkQueue>(4), 0, mutex);
|
||||
if (!swapchain.create(reinterpret_cast<HWND>(static_cast<std::uintptr_t>(1)), 64, 64,
|
||||
VK_FORMAT_B8G8R8A8_UNORM, requested))
|
||||
return fail("VulkanSwapchain::create");
|
||||
if (swapchain.is_offscreen() != offscreen) return fail("unexpected path before the failed resize");
|
||||
const VkSwapchainKHR before = g.live;
|
||||
|
||||
if (fail_swapchain) {
|
||||
g.fail_swapchain_creates = 1;
|
||||
if (swapchain.resize(64, 64)) return fail("resize succeeded although vkCreateSwapchainKHR failed");
|
||||
if (g.retired != before || g.live) return fail("the failed create did not retire the old swapchain");
|
||||
} else {
|
||||
// 32x32 on a 64x64 surface needs an offscreen ring; its first image can't be made.
|
||||
g.fail_image_creates = 1;
|
||||
if (swapchain.resize(32, 32)) return fail("resize succeeded although the offscreen ring failed");
|
||||
}
|
||||
if (!swapchain.resize(64, 64)) {
|
||||
std::fprintf(stderr, "FAIL: %s: the next resize did not recover\n", label);
|
||||
return 1;
|
||||
}
|
||||
if (swapchain.image_count() != requested) return fail("the recovered swap chain changed the BufferCount");
|
||||
if (swapchain.is_offscreen() != offscreen) return fail("the recovered swap chain took another path");
|
||||
for (int frame = 0; frame < 3; ++frame)
|
||||
if (const int r = present_one(label, swapchain)) return r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct Case {
|
||||
const char* label;
|
||||
std::uint32_t requested;
|
||||
@ -349,7 +427,24 @@ int main() {
|
||||
for (const Case& c : cases) {
|
||||
if (const int result = run_case(c.label, c.requested, c.native, c.minimum, c.offscreen)) return result;
|
||||
}
|
||||
struct FailCase {
|
||||
const char* label;
|
||||
std::uint32_t requested;
|
||||
std::uint32_t native;
|
||||
bool offscreen;
|
||||
bool fail_swapchain;
|
||||
};
|
||||
const FailCase fail_cases[] = {
|
||||
{"offscreen ring, vkCreateSwapchainKHR fails", 2, 4, true, true},
|
||||
{"offscreen ring, the new ring fails", 2, 4, true, false},
|
||||
{"direct images, vkCreateSwapchainKHR fails", 3, 3, false, true},
|
||||
{"direct images, the new ring fails", 3, 3, false, false},
|
||||
};
|
||||
for (const FailCase& c : fail_cases) {
|
||||
if (const int result = run_failed_resize(c.label, c.requested, c.native, c.offscreen, c.fail_swapchain))
|
||||
return result;
|
||||
}
|
||||
std::printf("dxgi_swapchain_count_test: PASS (3 cases: extra native images, min above request, "
|
||||
"request above min)\n");
|
||||
"request above min; 4 failed-resize cases)\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -307,6 +307,128 @@ int compare_swap_chain_arguments(IDXGIFactory4* ours, ID3D12Device* our_device,
|
||||
return mismatches;
|
||||
}
|
||||
|
||||
// A failed ResizeBuffers, against the host runtime's DXGI. Measured on an RTX 3060 Ti (NVIDIA 610.88): a side
|
||||
// above 16384 is E_INVALIDARG, and then the swap chain has no buffers. GetDesc1 reports the size that was asked for,
|
||||
// GetBuffer and Present are DXGI_ERROR_INVALID_CALL, and the next ResizeBuffers to a valid size brings it all back.
|
||||
// A refused call (a back buffer still held) changes nothing. WARP differs (it takes 16385 and fails at 32768 with
|
||||
// E_OUTOFMEMORY), so this compares with the host's default adapter. Returns the number of mismatches, or -1 without
|
||||
// a host D3D12 device.
|
||||
int compare_failed_resize(IDXGIFactory4* ours, ID3D12CommandQueue* our_queue) {
|
||||
using CreateDevice = HRESULT(WINAPI*)(IUnknown*, D3D_FEATURE_LEVEL, REFIID, void**);
|
||||
using CreateFactory2 = HRESULT(WINAPI*)(UINT, REFIID, void**);
|
||||
const HMODULE d3d12 = LoadLibraryExA("d3d12.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
|
||||
const HMODULE dxgi = LoadLibraryExA("dxgi.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
|
||||
const auto create_device = d3d12 ? reinterpret_cast<CreateDevice>(
|
||||
reinterpret_cast<void*>(GetProcAddress(d3d12, "D3D12CreateDevice")))
|
||||
: nullptr;
|
||||
const auto create_factory = dxgi ? reinterpret_cast<CreateFactory2>(
|
||||
reinterpret_cast<void*>(GetProcAddress(dxgi, "CreateDXGIFactory2")))
|
||||
: nullptr;
|
||||
ID3D12Device* host_device = nullptr;
|
||||
IDXGIFactory4* host_factory = nullptr;
|
||||
ID3D12CommandQueue* host_queue = nullptr;
|
||||
const D3D12_COMMAND_QUEUE_DESC queue_desc{D3D12_COMMAND_LIST_TYPE_DIRECT, 0, D3D12_COMMAND_QUEUE_FLAG_NONE, 0};
|
||||
if (!create_device || !create_factory ||
|
||||
FAILED(create_device(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&host_device))) ||
|
||||
FAILED(create_factory(0, IID_PPV_ARGS(&host_factory))) ||
|
||||
FAILED(host_device->CreateCommandQueue(&queue_desc, IID_PPV_ARGS(&host_queue)))) {
|
||||
if (host_factory) host_factory->Release();
|
||||
if (host_device) host_device->Release();
|
||||
return -1;
|
||||
}
|
||||
DXGI_SWAP_CHAIN_DESC1 base{};
|
||||
base.Width = 64;
|
||||
base.Height = 64;
|
||||
base.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
base.SampleDesc.Count = 1;
|
||||
base.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
base.BufferCount = 2;
|
||||
base.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
|
||||
static const char* const kSteps[] = {
|
||||
"ResizeBuffers(2, 16385, 16)",
|
||||
"GetDesc1 width",
|
||||
"GetDesc1 height",
|
||||
"GetDesc1 BufferCount",
|
||||
"GetBuffer(0) after it",
|
||||
"Present after it",
|
||||
"ResizeBuffers(2, 16, 16385)",
|
||||
"ResizeBuffers(0, 64, 64) after both",
|
||||
"GetDesc1 width after",
|
||||
"GetDesc1 BufferCount after",
|
||||
"GetBuffer(0) after recovering",
|
||||
"Present after recovering",
|
||||
"ResizeBuffers with buffer 0 held",
|
||||
"GetDesc1 width after the refused call",
|
||||
"Present after the refused call",
|
||||
};
|
||||
std::vector<long> results[2];
|
||||
for (int side = 0; side < 2; ++side) {
|
||||
IDXGIFactory4* factory = side ? host_factory : ours;
|
||||
IUnknown* queue = side ? static_cast<IUnknown*>(host_queue) : static_cast<IUnknown*>(our_queue);
|
||||
HWND hwnd = create_test_window(64, 64);
|
||||
IDXGISwapChain1* chain1 = nullptr;
|
||||
IDXGISwapChain3* chain = nullptr;
|
||||
if (FAILED(factory->CreateSwapChainForHwnd(queue, hwnd, &base, nullptr, nullptr, &chain1)) ||
|
||||
FAILED(chain1->QueryInterface(IID_PPV_ARGS(&chain)))) {
|
||||
if (chain1) chain1->Release();
|
||||
DestroyWindow(hwnd);
|
||||
continue;
|
||||
}
|
||||
std::vector<long>& r = results[side];
|
||||
const auto desc = [&](int field) {
|
||||
DXGI_SWAP_CHAIN_DESC1 d{};
|
||||
chain->GetDesc1(&d);
|
||||
return static_cast<long>(field == 0 ? d.Width : field == 1 ? d.Height : d.BufferCount);
|
||||
};
|
||||
const auto get_buffer = [&] {
|
||||
ID3D12Resource* buffer = nullptr;
|
||||
const HRESULT hr = chain->GetBuffer(0, IID_PPV_ARGS(&buffer));
|
||||
if (buffer) buffer->Release();
|
||||
return static_cast<long>(hr);
|
||||
};
|
||||
r.push_back(chain->ResizeBuffers(2, 16385, 16, DXGI_FORMAT_UNKNOWN, 0));
|
||||
r.push_back(desc(0));
|
||||
r.push_back(desc(1));
|
||||
r.push_back(desc(2));
|
||||
r.push_back(get_buffer());
|
||||
r.push_back(chain->Present(0, 0));
|
||||
r.push_back(chain->ResizeBuffers(2, 16, 16385, DXGI_FORMAT_UNKNOWN, 0));
|
||||
r.push_back(chain->ResizeBuffers(0, 64, 64, DXGI_FORMAT_UNKNOWN, 0));
|
||||
r.push_back(desc(0));
|
||||
r.push_back(desc(2));
|
||||
r.push_back(get_buffer());
|
||||
r.push_back(chain->Present(0, 0));
|
||||
ID3D12Resource* held = nullptr;
|
||||
chain->GetBuffer(0, IID_PPV_ARGS(&held));
|
||||
r.push_back(chain->ResizeBuffers(2, 32, 32, DXGI_FORMAT_UNKNOWN, 0));
|
||||
if (held) held->Release();
|
||||
r.push_back(desc(0));
|
||||
r.push_back(chain->Present(0, 0));
|
||||
chain->Release();
|
||||
chain1->Release();
|
||||
DestroyWindow(hwnd);
|
||||
}
|
||||
host_queue->Release();
|
||||
host_factory->Release();
|
||||
host_device->Release();
|
||||
if (results[0].size() != std::size(kSteps) || results[1].size() != std::size(kSteps)) {
|
||||
std::fprintf(stderr, "failed ResizeBuffers: a swap chain could not be created (ours %zu, host %zu steps)\n",
|
||||
results[0].size(), results[1].size());
|
||||
return 1;
|
||||
}
|
||||
int mismatches = 0;
|
||||
for (std::size_t i = 0; i < std::size(kSteps); ++i) {
|
||||
if (results[0][i] != results[1][i]) {
|
||||
++mismatches;
|
||||
std::fprintf(stderr, "failed ResizeBuffers, %s: ours 0x%08lx, host 0x%08lx\n", kSteps[i],
|
||||
static_cast<unsigned long>(results[0][i]), static_cast<unsigned long>(results[1][i]));
|
||||
}
|
||||
}
|
||||
std::printf("failed ResizeBuffers: %zu steps compared with the host runtime, %d mismatches\n", std::size(kSteps),
|
||||
mismatches);
|
||||
return mismatches;
|
||||
}
|
||||
|
||||
int main() {
|
||||
if (!has_interactive_window_station()) {
|
||||
// The host answers DXGI_ERROR_NOT_CURRENTLY_AVAILABLE to every CreateSwapChainForHwnd there: nothing to compare.
|
||||
@ -509,6 +631,9 @@ int main() {
|
||||
const int argument_mismatches = compare_swap_chain_arguments(factory, dev, queue);
|
||||
if (argument_mismatches < 0) std::printf("CreateSwapChainForHwnd: no host D3D12 device to compare with, skipped\n");
|
||||
if (argument_mismatches > 0) return fail("CreateSwapChainForHwnd answers differ from the host runtime");
|
||||
const int resize_mismatches = compare_failed_resize(factory, queue);
|
||||
if (resize_mismatches < 0) std::printf("failed ResizeBuffers: no host D3D12 device to compare with, skipped\n");
|
||||
if (resize_mismatches > 0) return fail("a failed ResizeBuffers differs from the host runtime");
|
||||
|
||||
DXGI_SWAP_CHAIN_DESC1 scd{};
|
||||
scd.Width = 128;
|
||||
|
||||
Reference in New Issue
Block a user