Handle Device Lost for SwapChain

Bug: dawn:68
Change-Id: I16e00bb2e203e71fd0840b71bc027e6fbea4e52c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/15723
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Natasha Lee <natlee@microsoft.com>
This commit is contained in:
Natasha Lee 2020-02-11 21:30:25 +00:00 committed by Commit Bot service account
parent 713d9cbf93
commit 2fd6181929
3 changed files with 36 additions and 1 deletions

View File

@ -220,6 +220,7 @@ namespace dawn_native {
wgpu::TextureUsage allowedUsage,
uint32_t width,
uint32_t height) const {
DAWN_TRY(GetDevice()->ValidateIsAlive());
DAWN_TRY(GetDevice()->ValidateObject(this));
DAWN_TRY(ValidateTextureUsage(allowedUsage));
@ -233,6 +234,7 @@ namespace dawn_native {
}
MaybeError OldSwapChainBase::ValidateGetCurrentTextureView() const {
DAWN_TRY(GetDevice()->ValidateIsAlive());
DAWN_TRY(GetDevice()->ValidateObject(this));
if (mWidth == 0) {
@ -244,6 +246,7 @@ namespace dawn_native {
}
MaybeError OldSwapChainBase::ValidatePresent() const {
DAWN_TRY(GetDevice()->ValidateIsAlive());
DAWN_TRY(GetDevice()->ValidateObject(this));
if (mCurrentTextureView.Get() == nullptr) {

View File

@ -503,7 +503,6 @@ namespace dawn_native {
}
MaybeError TextureBase::ValidateDestroy() const {
DAWN_TRY(GetDevice()->ValidateIsAlive());
DAWN_TRY(GetDevice()->ValidateObject(this));
return {};
}

View File

@ -290,3 +290,36 @@ TEST_F(SwapChainValidationTests, SwapChainIsInvalidAfterSurfaceDestruction_After
CheckTextureViewIsDestroyed(view);
ASSERT_DEVICE_ERROR(replacedSwapChain.Present());
}
// Test that after Device is Lost, all swap chain operations fail
static void ToMockDeviceLostCallback(const char* message, void* userdata) {
ValidationTest* self = static_cast<ValidationTest*>(userdata);
self->StartExpectDeviceError();
}
// Test that new swap chain present fails after device is lost
TEST_F(SwapChainValidationTests, NewSwapChainPresentFailsAfterDeviceLost) {
device.SetDeviceLostCallback(ToMockDeviceLostCallback, this);
wgpu::SwapChain swapchain = device.CreateSwapChain(surface, &goodDescriptor);
wgpu::TextureView view = swapchain.GetCurrentTextureView();
device.LoseForTesting();
ASSERT_DEVICE_ERROR(swapchain.Present());
}
// Test that new swap chain get current texture view fails after device is lost
TEST_F(SwapChainValidationTests, NewSwapChainGetCurrentTextureViewFailsAfterDevLost) {
device.SetDeviceLostCallback(ToMockDeviceLostCallback, this);
wgpu::SwapChain swapchain = device.CreateSwapChain(surface, &goodDescriptor);
device.LoseForTesting();
ASSERT_DEVICE_ERROR(swapchain.GetCurrentTextureView());
}
// Test that creation of a new swapchain fails
TEST_F(SwapChainValidationTests, CreateNewSwapChainFailsAfterDevLost) {
device.SetDeviceLostCallback(ToMockDeviceLostCallback, this);
device.LoseForTesting();
ASSERT_DEVICE_ERROR(device.CreateSwapChain(surface, &goodDescriptor));
}