diff --git a/src/dawn_wire/client/ShaderModule.cpp b/src/dawn_wire/client/ShaderModule.cpp index 97e0204c92..fa7945aed0 100644 --- a/src/dawn_wire/client/ShaderModule.cpp +++ b/src/dawn_wire/client/ShaderModule.cpp @@ -63,4 +63,14 @@ namespace dawn_wire { namespace client { return true; } + void ShaderModule::CancelCallbacksForDisconnect() { + for (auto& it : mCompilationInfoRequests) { + if (it.second.callback) { + it.second.callback(WGPUCompilationInfoRequestStatus_DeviceLost, nullptr, + it.second.userdata); + } + } + mCompilationInfoRequests.clear(); + } + }} // namespace dawn_wire::client diff --git a/src/dawn_wire/client/ShaderModule.h b/src/dawn_wire/client/ShaderModule.h index add5b975ff..d7ac55d667 100644 --- a/src/dawn_wire/client/ShaderModule.h +++ b/src/dawn_wire/client/ShaderModule.h @@ -32,6 +32,8 @@ namespace dawn_wire { namespace client { WGPUCompilationInfoRequestStatus status, const WGPUCompilationInfo* info); + void CancelCallbacksForDisconnect() override; + private: struct CompilationInfoRequest { WGPUCompilationInfoCallback callback = nullptr; diff --git a/src/tests/unittests/wire/WireShaderModuleTests.cpp b/src/tests/unittests/wire/WireShaderModuleTests.cpp index f4a0425435..4b2db4dd2a 100644 --- a/src/tests/unittests/wire/WireShaderModuleTests.cpp +++ b/src/tests/unittests/wire/WireShaderModuleTests.cpp @@ -117,4 +117,35 @@ TEST_F(WireShaderModuleTests, GetCompilationInfo) { _)) .Times(1); FlushServer(); -} \ No newline at end of file +} + +// Test that calling GetCompilationInfo then disconnecting the wire calls the callback with a device +// loss. +TEST_F(WireShaderModuleTests, GetCompilationInfoBeforeDisconnect) { + wgpuShaderModuleGetCompilationInfo(shaderModule, ToMockGetCompilationInfoCallback, nullptr); + + WGPUCompilationMessage message = {"Test Message", WGPUCompilationMessageType_Info, 2, 4, 6, 8}; + WGPUCompilationInfo compilationInfo; + compilationInfo.messageCount = 1; + compilationInfo.messages = &message; + + EXPECT_CALL(api, OnShaderModuleGetCompilationInfo(apiShaderModule, _, _)) + .WillOnce(InvokeWithoutArgs([&]() { + api.CallShaderModuleGetCompilationInfoCallback( + apiShaderModule, WGPUCompilationInfoRequestStatus_Success, &compilationInfo); + })); + FlushClient(); + + EXPECT_CALL(*mockCompilationInfoCallback, + Call(WGPUCompilationInfoRequestStatus_DeviceLost, nullptr, _)); + GetWireClient()->Disconnect(); +} + +// Test that calling GetCompilationInfo after disconnecting the wire calls the callback with a +// device loss. +TEST_F(WireShaderModuleTests, GetCompilationInfoAfterDisconnect) { + GetWireClient()->Disconnect(); + EXPECT_CALL(*mockCompilationInfoCallback, + Call(WGPUCompilationInfoRequestStatus_DeviceLost, nullptr, _)); + wgpuShaderModuleGetCompilationInfo(shaderModule, ToMockGetCompilationInfoCallback, nullptr); +}