mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-19 01:46:35 +00:00
Fix crash when device is removed before CreateReady*Pipeline callback
This patch fixes a crash issue when the device is destroyed before
the callback of CreateReady{Render, Compute}Pipeline is called. Now
when the callback is called in DeviceBase::ShutDown(), the cached
pipeline object will also be destroyed before the callback returns.
BUG=dawn:529
TEST=dawn_end2end_tests
Change-Id: I91ec2608b53591d265c0648f5c02daf7fadac85e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/30744
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
committed by
Commit Bot service account
parent
ebdbc03b77
commit
42103bc2e9
@@ -30,20 +30,34 @@ namespace dawn_wire { namespace server {
|
||||
WGPUComputePipeline pipeline,
|
||||
const char* message,
|
||||
void* userdata) {
|
||||
CreateReadyPipelineUserData* createReadyPipelineUserData =
|
||||
static_cast<CreateReadyPipelineUserData*>(userdata);
|
||||
std::unique_ptr<CreateReadyPipelineUserData> createReadyPipelineUserData(
|
||||
static_cast<CreateReadyPipelineUserData*>(userdata));
|
||||
|
||||
// We need to ensure createReadyPipelineUserData->server is still pointing to a valid
|
||||
// object before doing any operations on it.
|
||||
if (createReadyPipelineUserData->isServerAlive.expired()) {
|
||||
return;
|
||||
}
|
||||
|
||||
createReadyPipelineUserData->server->OnCreateReadyComputePipelineCallback(
|
||||
status, pipeline, message, createReadyPipelineUserData);
|
||||
status, pipeline, message, createReadyPipelineUserData.release());
|
||||
}
|
||||
|
||||
void Server::ForwardCreateReadyRenderPipeline(WGPUCreateReadyPipelineStatus status,
|
||||
WGPURenderPipeline pipeline,
|
||||
const char* message,
|
||||
void* userdata) {
|
||||
CreateReadyPipelineUserData* createReadyPipelineUserData =
|
||||
static_cast<CreateReadyPipelineUserData*>(userdata);
|
||||
std::unique_ptr<CreateReadyPipelineUserData> createReadyPipelineUserData(
|
||||
static_cast<CreateReadyPipelineUserData*>(userdata));
|
||||
|
||||
// We need to ensure createReadyPipelineUserData->server is still pointing to a valid
|
||||
// object before doing any operations on it.
|
||||
if (createReadyPipelineUserData->isServerAlive.expired()) {
|
||||
return;
|
||||
}
|
||||
|
||||
createReadyPipelineUserData->server->OnCreateReadyRenderPipelineCallback(
|
||||
status, pipeline, message, createReadyPipelineUserData);
|
||||
status, pipeline, message, createReadyPipelineUserData.release());
|
||||
}
|
||||
|
||||
void Server::OnUncapturedError(WGPUErrorType type, const char* message) {
|
||||
@@ -87,6 +101,7 @@ namespace dawn_wire { namespace server {
|
||||
|
||||
std::unique_ptr<CreateReadyPipelineUserData> userdata =
|
||||
std::make_unique<CreateReadyPipelineUserData>();
|
||||
userdata->isServerAlive = mIsAlive;
|
||||
userdata->server = this;
|
||||
userdata->requestSerial = requestSerial;
|
||||
userdata->pipelineObjectID = pipelineObjectHandle.id;
|
||||
@@ -101,10 +116,27 @@ namespace dawn_wire { namespace server {
|
||||
const char* message,
|
||||
CreateReadyPipelineUserData* userdata) {
|
||||
std::unique_ptr<CreateReadyPipelineUserData> data(userdata);
|
||||
if (status != WGPUCreateReadyPipelineStatus_Success) {
|
||||
ComputePipelineObjects().Free(data->pipelineObjectID);
|
||||
} else {
|
||||
ComputePipelineObjects().Get(data->pipelineObjectID)->handle = pipeline;
|
||||
|
||||
auto* computePipelineObject = ComputePipelineObjects().Get(data->pipelineObjectID);
|
||||
ASSERT(computePipelineObject != nullptr);
|
||||
|
||||
switch (status) {
|
||||
case WGPUCreateReadyPipelineStatus_Success:
|
||||
computePipelineObject->handle = pipeline;
|
||||
break;
|
||||
|
||||
case WGPUCreateReadyPipelineStatus_Error:
|
||||
ComputePipelineObjects().Free(data->pipelineObjectID);
|
||||
break;
|
||||
|
||||
// Currently this code is unreachable because WireServer is always deleted before the
|
||||
// removal of the device. In the future this logic may be changed when we decide to
|
||||
// support sharing one pair of WireServer/WireClient to multiple devices.
|
||||
case WGPUCreateReadyPipelineStatus_DeviceLost:
|
||||
case WGPUCreateReadyPipelineStatus_DeviceDestroyed:
|
||||
case WGPUCreateReadyPipelineStatus_Unknown:
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
ReturnDeviceCreateReadyComputePipelineCallbackCmd cmd;
|
||||
@@ -128,6 +160,7 @@ namespace dawn_wire { namespace server {
|
||||
|
||||
std::unique_ptr<CreateReadyPipelineUserData> userdata =
|
||||
std::make_unique<CreateReadyPipelineUserData>();
|
||||
userdata->isServerAlive = mIsAlive;
|
||||
userdata->server = this;
|
||||
userdata->requestSerial = requestSerial;
|
||||
userdata->pipelineObjectID = pipelineObjectHandle.id;
|
||||
@@ -142,10 +175,27 @@ namespace dawn_wire { namespace server {
|
||||
const char* message,
|
||||
CreateReadyPipelineUserData* userdata) {
|
||||
std::unique_ptr<CreateReadyPipelineUserData> data(userdata);
|
||||
if (status != WGPUCreateReadyPipelineStatus_Success) {
|
||||
RenderPipelineObjects().Free(data->pipelineObjectID);
|
||||
} else {
|
||||
RenderPipelineObjects().Get(data->pipelineObjectID)->handle = pipeline;
|
||||
|
||||
auto* renderPipelineObject = RenderPipelineObjects().Get(data->pipelineObjectID);
|
||||
ASSERT(renderPipelineObject != nullptr);
|
||||
|
||||
switch (status) {
|
||||
case WGPUCreateReadyPipelineStatus_Success:
|
||||
renderPipelineObject->handle = pipeline;
|
||||
break;
|
||||
|
||||
case WGPUCreateReadyPipelineStatus_Error:
|
||||
RenderPipelineObjects().Free(data->pipelineObjectID);
|
||||
break;
|
||||
|
||||
// Currently this code is unreachable because WireServer is always deleted before the
|
||||
// removal of the device. In the future this logic may be changed when we decide to
|
||||
// support sharing one pair of WireServer/WireClient to multiple devices.
|
||||
case WGPUCreateReadyPipelineStatus_DeviceLost:
|
||||
case WGPUCreateReadyPipelineStatus_DeviceDestroyed:
|
||||
case WGPUCreateReadyPipelineStatus_Unknown:
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
ReturnDeviceCreateReadyRenderPipelineCallbackCmd cmd;
|
||||
|
||||
Reference in New Issue
Block a user