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:
parent
713d9cbf93
commit
2fd6181929
|
@ -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) {
|
||||
|
|
|
@ -503,7 +503,6 @@ namespace dawn_native {
|
|||
}
|
||||
|
||||
MaybeError TextureBase::ValidateDestroy() const {
|
||||
DAWN_TRY(GetDevice()->ValidateIsAlive());
|
||||
DAWN_TRY(GetDevice()->ValidateObject(this));
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue