Reject createPipelineAsync callback if unsafe APIs are disabled

Async functions should fail by rejecting the callback instead of
generating a device error. This fixes a leak in the wire where
the allocation for the callback was never delete since it was
never called.

Fixed: chromium:1181627
Change-Id: I840073c1d1b5f1401aa8ed29d3c8f0e1e4fefd35
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/42540
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
Austin Eng 2021-02-25 22:06:55 +00:00 committed by Commit Bot service account
parent 7564ae1def
commit 87649ff09d
2 changed files with 21 additions and 22 deletions

View File

@ -711,9 +711,10 @@ namespace dawn_native {
ComputePipelineBase* result = nullptr;
if (IsToggleEnabled(Toggle::DisallowUnsafeAPIs)) {
ConsumedError(
DAWN_VALIDATION_ERROR("CreateComputePipelineAsync is disallowed because it isn't "
"completely implemented yet."));
callback(WGPUCreatePipelineAsyncStatus_Error, nullptr,
"CreateComputePipelineAsync is disallowed because it isn't completely "
"implemented yet.",
userdata);
return;
}
@ -763,9 +764,10 @@ namespace dawn_native {
RenderPipelineBase* result = nullptr;
if (IsToggleEnabled(Toggle::DisallowUnsafeAPIs)) {
ConsumedError(
DAWN_VALIDATION_ERROR("CreateRenderPipelineAsync is disallowed because it isn't "
"completely implemented yet."));
callback(WGPUCreatePipelineAsyncStatus_Error, nullptr,
"CreateRenderPipelineAsync is disallowed because it isn't completely "
"implemented yet.",
userdata);
return;
}

View File

@ -14,6 +14,7 @@
#include "tests/unittests/validation/ValidationTest.h"
#include "tests/MockCallback.h"
#include "utils/ComboRenderBundleEncoderDescriptor.h"
#include "utils/ComboRenderPipelineDescriptor.h"
#include "utils/WGPUHelpers.h"
@ -223,15 +224,13 @@ TEST_F(UnsafeAPIValidationTest, CreateComputePipelineAsyncDisallowed) {
// Control case: CreateComputePipeline is allowed.
device.CreateComputePipeline(&desc);
testing::MockCallback<WGPUCreateComputePipelineAsyncCallback> callback;
EXPECT_CALL(callback,
Call(WGPUCreatePipelineAsyncStatus_Error, nullptr, testing::NotNull(), this));
// Error case: CreateComputePipelineAsync is disallowed.
ASSERT_DEVICE_ERROR(device.CreateComputePipelineAsync(
&desc,
[](WGPUCreatePipelineAsyncStatus status, WGPUComputePipeline returnPipeline,
const char* message, void* userdata) {
// Status can be Error or Unkown (when using the wire).
EXPECT_NE(WGPUCreatePipelineAsyncStatus::WGPUCreatePipelineAsyncStatus_Success, status);
},
nullptr));
device.CreateComputePipelineAsync(&desc, callback.Callback(), callback.MakeUserdata(this));
WaitForAllOperations(device);
}
// Check that CreateRenderPipelineAsync is disallowed as part of unsafe APIs
@ -252,13 +251,11 @@ TEST_F(UnsafeAPIValidationTest, CreateRenderPipelineAsyncDisallowed) {
// Control case: CreateRenderPipeline is allowed.
device.CreateRenderPipeline(&desc);
testing::MockCallback<WGPUCreateRenderPipelineAsyncCallback> callback;
EXPECT_CALL(callback,
Call(WGPUCreatePipelineAsyncStatus_Error, nullptr, testing::NotNull(), this));
// Error case: CreateRenderPipelineAsync is disallowed.
ASSERT_DEVICE_ERROR(device.CreateRenderPipelineAsync(
&desc,
[](WGPUCreatePipelineAsyncStatus status, WGPURenderPipeline returnPipeline,
const char* message, void* userdata) {
// Status can be Error or Unkown (when using the wire).
EXPECT_NE(WGPUCreatePipelineAsyncStatus::WGPUCreatePipelineAsyncStatus_Success, status);
},
nullptr));
device.CreateRenderPipelineAsync(&desc, callback.Callback(), callback.MakeUserdata(this));
WaitForAllOperations(device);
}