mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-11 14:41:50 +00:00
Make Surface reference its attached SwapChain
This solves an issues where when switching swapchains the previous one was destroyed before the new one was created, doing so detached itself from the Surface, which in turn made the new swapchain not do a graceful transition via vkSwapchainCreateInfoKHR::oldSwapchain. Keeping the reference on the surface makes sure we always have knowledge of the previous swapchain when replacing it. It requires re-working the lifetime model of NewSwapChainBase to not require a call to DetachFromSurface in the destructor, and having the Device explicitly tell a swapchain it got attached on creation (otherwise there are ASSERTs firing when swapchain creation fails). In addition, backends are changed to use a SwapChain::Create method and fail with a validation error (for now) when the previous swapchain didn't use the same API. vulkan::SwapChain is updated to use the previous swapchain's device's fenced deleter to destroy it which is important in the device switching tests. The SwapChainValidationTests are updated because with the lifetime changes the texture view can be kept alive after the application has lost the last reference to the wgpu::SwapChain. TBRing since it was reviewed in a different CL (but for the wrong branch). TBR=enga@chromium.org TBR=senorblanco@chromium.org Bug: dawn:269 Change-Id: Ie4374b5685af990d68969ab9cd7767e53c287ace Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/31041 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
41c24933da
commit
25eeaa3d39
@@ -136,9 +136,9 @@ TEST_P(SwapChainTests, DestroySurfaceAfterGet) {
|
||||
|
||||
// Test switching between present modes.
|
||||
TEST_P(SwapChainTests, SwitchPresentMode) {
|
||||
// For unclear reasons recreating the swapchain produces a debug report warning on NVIDIA and
|
||||
// makes the test fail.
|
||||
DAWN_SKIP_TEST_IF(IsVulkan() && IsNvidia());
|
||||
// Fails with "internal drawable creation failed" on the Windows NVIDIA CQ builders but not
|
||||
// locally.
|
||||
DAWN_SKIP_TEST_IF(IsWindows() && IsVulkan() && IsNvidia());
|
||||
|
||||
constexpr wgpu::PresentMode kAllPresentModes[] = {
|
||||
wgpu::PresentMode::Immediate,
|
||||
@@ -165,10 +165,6 @@ TEST_P(SwapChainTests, SwitchPresentMode) {
|
||||
|
||||
// Test resizing the swapchain and without resizing the window.
|
||||
TEST_P(SwapChainTests, ResizingSwapChainOnly) {
|
||||
// For unclear reasons recreating the swapchain produces a debug report warning on NVIDIA and
|
||||
// makes the test fail.
|
||||
DAWN_SKIP_TEST_IF(IsVulkan() && IsNvidia());
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
wgpu::SwapChainDescriptor desc = baseDescriptor;
|
||||
desc.width += i * 10;
|
||||
@@ -195,10 +191,6 @@ TEST_P(SwapChainTests, ResizingWindowOnly) {
|
||||
|
||||
// Test resizing both the window and the swapchain at the same time.
|
||||
TEST_P(SwapChainTests, ResizingWindowAndSwapChain) {
|
||||
// For unclear reasons recreating the swapchain produces a debug report warning on NVIDIA and
|
||||
// makes the test fail.
|
||||
DAWN_SKIP_TEST_IF(IsVulkan() && IsNvidia());
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
glfwSetWindowSize(window, 400 - 10 * i, 400 + 10 * i);
|
||||
glfwPollEvents();
|
||||
@@ -219,9 +211,10 @@ TEST_P(SwapChainTests, ResizingWindowAndSwapChain) {
|
||||
|
||||
// Test switching devices on the same adapter.
|
||||
TEST_P(SwapChainTests, SwitchingDevice) {
|
||||
// For unclear reasons recreating the swapchain produces a debug report warning on NVIDIA and
|
||||
// makes the test fail.
|
||||
DAWN_SKIP_TEST_IF(IsVulkan() && IsNvidia());
|
||||
// The Vulkan Validation Layers incorrectly disallow gracefully passing a swapchain between two
|
||||
// VkDevices using "vkSwapchainCreateInfoKHR::oldSwapchain".
|
||||
// See https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/2256
|
||||
DAWN_SKIP_TEST_IF(IsVulkan() && IsBackendValidationEnabled());
|
||||
|
||||
wgpu::Device device2 = wgpu::Device::Acquire(GetAdapter().CreateDevice());
|
||||
|
||||
|
||||
@@ -71,24 +71,38 @@ class SwapChainValidationTests : public DawnTest {
|
||||
|
||||
// Checks that an OutputAttachment view is an error by trying to create a render pass on it.
|
||||
void CheckTextureViewIsError(wgpu::TextureView view) {
|
||||
utils::ComboRenderPassDescriptor renderPassDesc({view});
|
||||
|
||||
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
|
||||
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDesc);
|
||||
pass.EndPass();
|
||||
ASSERT_DEVICE_ERROR(encoder.Finish());
|
||||
CheckTextureView(view, true, false);
|
||||
}
|
||||
|
||||
// Checks that an OutputAttachment view is an error by trying to create a render pass on it.
|
||||
// Checks that an OutputAttachment view is an error by trying to submit a render pass on it.
|
||||
void CheckTextureViewIsDestroyed(wgpu::TextureView view) {
|
||||
CheckTextureView(view, false, true);
|
||||
}
|
||||
|
||||
// Checks that an OutputAttachment view is valid by submitting a render pass on it.
|
||||
void CheckTextureViewIsValid(wgpu::TextureView view) {
|
||||
CheckTextureView(view, false, false);
|
||||
}
|
||||
|
||||
private:
|
||||
void CheckTextureView(wgpu::TextureView view, bool errorAtFinish, bool errorAtSubmit) {
|
||||
utils::ComboRenderPassDescriptor renderPassDesc({view});
|
||||
|
||||
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
|
||||
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDesc);
|
||||
pass.EndPass();
|
||||
wgpu::CommandBuffer commands = encoder.Finish();
|
||||
|
||||
ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
|
||||
if (errorAtFinish) {
|
||||
ASSERT_DEVICE_ERROR(encoder.Finish());
|
||||
} else {
|
||||
wgpu::CommandBuffer commands = encoder.Finish();
|
||||
|
||||
if (errorAtSubmit) {
|
||||
ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
|
||||
} else {
|
||||
queue.Submit(1, &commands);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -181,12 +195,17 @@ TEST_P(SwapChainValidationTests, PresentWithoutCurrentView) {
|
||||
ASSERT_DEVICE_ERROR(swapchain.Present());
|
||||
}
|
||||
|
||||
// Check that the current view is in the destroyed state after the swapchain is destroyed.
|
||||
TEST_P(SwapChainValidationTests, ViewDestroyedAfterSwapChainDestruction) {
|
||||
// Check that the current view isn't destroyed when the ref to the swapchain is lost because the
|
||||
// swapchain is kept alive by the surface. Also check after we lose all refs to the surface, the
|
||||
// texture is destroyed.
|
||||
TEST_P(SwapChainValidationTests, ViewValidAfterSwapChainRefLost) {
|
||||
wgpu::SwapChain swapchain = device.CreateSwapChain(surface, &goodDescriptor);
|
||||
wgpu::TextureView view = swapchain.GetCurrentTextureView();
|
||||
swapchain = nullptr;
|
||||
|
||||
swapchain = nullptr;
|
||||
CheckTextureViewIsValid(view);
|
||||
|
||||
surface = nullptr;
|
||||
CheckTextureViewIsDestroyed(view);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user