Promote LoseForTesting to ForceLoss device so that user agents can use.
Bug: chromium:1356738
Change-Id: I348837ad4224124d9adba1ecf69a05b2060760c9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/100566
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Loko Kung <lokokung@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
diff --git a/dawn.json b/dawn.json
index e07bb57..8dedc59 100644
--- a/dawn.json
+++ b/dawn.json
@@ -1159,7 +1159,11 @@
"tags": ["dawn"]
},
{
- "name": "lose for testing",
+ "name": "force loss",
+ "args": [
+ {"name": "type", "type": "device lost reason"},
+ {"name": "message", "type": "char", "annotation": "const*", "length": "strlen"}
+ ],
"tags": ["dawn"]
},
{
diff --git a/src/dawn/native/Device.cpp b/src/dawn/native/Device.cpp
index 2093a0a..65e79c1 100644
--- a/src/dawn/native/Device.cpp
+++ b/src/dawn/native/Device.cpp
@@ -479,7 +479,9 @@
Destroy();
}
-void DeviceBase::HandleError(InternalErrorType type, const char* message) {
+void DeviceBase::HandleError(InternalErrorType type,
+ const char* message,
+ WGPUDeviceLostReason lost_reason) {
if (type == InternalErrorType::DeviceLost) {
mState = State::Disconnected;
@@ -519,7 +521,7 @@
if (type == InternalErrorType::DeviceLost) {
// The device was lost, call the application callback.
if (mDeviceLostCallback != nullptr) {
- mDeviceLostCallback(WGPUDeviceLostReason_Undefined, message, mDeviceLostUserdata);
+ mDeviceLostCallback(lost_reason, message, mDeviceLostUserdata);
mDeviceLostCallback = nullptr;
}
@@ -668,12 +670,11 @@
return {};
}
-void DeviceBase::APILoseForTesting() {
+void DeviceBase::APIForceLoss(wgpu::DeviceLostReason reason, const char* message) {
if (mState != State::Alive) {
return;
}
-
- HandleError(InternalErrorType::Internal, "Device lost for testing");
+ HandleError(InternalErrorType::Internal, message, ToAPI(reason));
}
DeviceBase::State DeviceBase::GetState() const {
diff --git a/src/dawn/native/Device.h b/src/dawn/native/Device.h
index 9e4fe03..42bc77b 100644
--- a/src/dawn/native/Device.h
+++ b/src/dawn/native/Device.h
@@ -65,7 +65,13 @@
DeviceBase(AdapterBase* adapter, const DeviceDescriptor* descriptor);
~DeviceBase() override;
- void HandleError(InternalErrorType type, const char* message);
+ // Handles the error, causing a device loss if applicable. Almost always when a device loss
+ // occurs because of an error, we want to call the device loss callback with an undefined
+ // reason, but the ForceLoss API allows for an injection of the reason, hence the default
+ // argument.
+ void HandleError(InternalErrorType type,
+ const char* message,
+ WGPUDeviceLostReason lost_reason = WGPUDeviceLostReason_Undefined);
bool ConsumedError(MaybeError maybeError) {
if (DAWN_UNLIKELY(maybeError.IsError())) {
@@ -343,7 +349,7 @@
void EmitDeprecationWarning(const char* warning);
void EmitLog(const char* message);
void EmitLog(WGPULoggingType loggingType, const char* message);
- void APILoseForTesting();
+ void APIForceLoss(wgpu::DeviceLostReason reason, const char* message);
QueueBase* GetQueue() const;
// AddFutureSerial is used to update the mFutureSerial with the max serial needed to be
diff --git a/src/dawn/tests/DawnTest.cpp b/src/dawn/tests/DawnTest.cpp
index 4cd35fd..44efc94 100644
--- a/src/dawn/tests/DawnTest.cpp
+++ b/src/dawn/tests/DawnTest.cpp
@@ -996,7 +996,7 @@
EXPECT_CALL(mDeviceLostCallback,
Call(WGPUDeviceLostReason_Undefined, testing::_, resolvedDevice.Get()))
.Times(1);
- resolvedDevice.LoseForTesting();
+ resolvedDevice.ForceLoss(wgpu::DeviceLostReason::Undefined, "Device lost for testing");
}
std::ostringstream& DawnTestBase::AddBufferExpectation(const char* file,
diff --git a/src/dawn/tests/end2end/DeviceLostTests.cpp b/src/dawn/tests/end2end/DeviceLostTests.cpp
index 4a906cd..d9aa3d0 100644
--- a/src/dawn/tests/end2end/DeviceLostTests.cpp
+++ b/src/dawn/tests/end2end/DeviceLostTests.cpp
@@ -408,7 +408,7 @@
mDeviceLostCallback.MakeUserdata(device.Get()));
EXPECT_CALL(mDeviceLostCallback, Call(WGPUDeviceLostReason_Undefined, testing::_, device.Get()))
.Times(0);
- device.LoseForTesting();
+ device.ForceLoss(wgpu::DeviceLostReason::Undefined, "Device lost for testing");
FlushWire();
testing::Mock::VerifyAndClearExpectations(&mDeviceLostCallback);
}