Reland "Remove `ConvertibleStatus` from `api_cpp.h`" This is a reland of commit f76b196d24d5f7d3c4afce51a8a46414003cee66 Original change's description: > Remove `ConvertibleStatus` from `api_cpp.h` > > This patch removes `ConvertibleStatus` from `api_cpp.h` and all > the calls that treat the return value from Enum `Status` to boolean. > > Bug: 42241199 > Change-Id: If8d4f924a05733345db95211513b976b410a4f40 > Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/325755 > Commit-Queue: Loko Kung <lokokung@google.com> > Reviewed-by: Loko Kung <lokokung@google.com> > Reviewed-by: Corentin Wallez <cwallez@chromium.org> Bug: 42241199 Change-Id: I51cbb1ed740f537a9df8c93df4e70d5b98b9a37f Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/331215 Reviewed-by: Kai Ninomiya <kainino@chromium.org> Commit-Queue: Loko Kung <lokokung@google.com>
diff --git a/generator/templates/api_cpp.h b/generator/templates/api_cpp.h index a8da102..f46ca45 100644 --- a/generator/templates/api_cpp.h +++ b/generator/templates/api_cpp.h
@@ -208,22 +208,6 @@ inline const {{OptionalBoolCppType}} {{OptionalBoolCppType}}::{{as_cppEnum(value.name)}} = {{OptionalBoolCppType}}({{as_cEnum(OptionalBool.name, value.name)}}); {% endfor %} -// Helper class to wrap Status which allows implicit conversion to bool. -// Used while callers switch to checking the Status enum instead of booleans. -// TODO(crbug.com/42241199): Remove when all callers check the enum. -struct ConvertibleStatus { - explicit(false) constexpr ConvertibleStatus(Status status) : status(status) {} - // NOLINTNEXTLINE(google-explicit-constructor) - constexpr operator bool() const { - return status == Status::Success; - } - // NOLINTNEXTLINE(google-explicit-constructor) - constexpr operator Status() const { - return status; - } - Status status; -}; - template<typename Derived, typename CType> class ObjectBase { public: @@ -387,7 +371,7 @@ {% set CppType = as_cppType(type.name) %} {% set MethodName = method.name.CamelCase() %} {% set MethodName = CppType + "::" + MethodName if dfn else MethodName %} - {{"ConvertibleStatus" if method.returns and method.returns.type.name.get() == "status" else as_annotated_cppType(method.returns)}} {{MethodName}}( + {{"Status" if method.returns and method.returns.type.name.get() == "status" else as_annotated_cppType(method.returns)}} {{MethodName}}( {%- for arg in method.arguments -%} {%- if not loop.first %}, {% endif -%} {%- if arg.type.category == "object" and arg.annotation == "value" -%}
diff --git a/src/dawn/node/binding/GPUAdapter.cpp b/src/dawn/node/binding/GPUAdapter.cpp index f9dcdd4..bee0417 100644 --- a/src/dawn/node/binding/GPUAdapter.cpp +++ b/src/dawn/node/binding/GPUAdapter.cpp
@@ -101,7 +101,7 @@ interop::Interface<interop::GPUSupportedLimits> GPUAdapter::getLimits(Napi::Env env) { dawn::utils::ComboLimits limits; - if (!adapter_.GetLimits(limits.GetLinked())) { + if (adapter_.GetLimits(limits.GetLinked()) != wgpu::Status::Success) { Napi::Error::New(env, "failed to get adapter limits").ThrowAsJavaScriptException(); }
diff --git a/src/dawn/node/binding/GPUDevice.cpp b/src/dawn/node/binding/GPUDevice.cpp index 1ade530..6242f85 100644 --- a/src/dawn/node/binding/GPUDevice.cpp +++ b/src/dawn/node/binding/GPUDevice.cpp
@@ -281,7 +281,7 @@ interop::Interface<interop::GPUSupportedLimits> GPUDevice::getLimits(Napi::Env env) { dawn::utils::ComboLimits limits; - if (!device_.GetLimits(limits.GetLinked())) { + if (device_.GetLimits(limits.GetLinked()) != wgpu::Status::Success) { Napi::Error::New(env, "failed to get device limits").ThrowAsJavaScriptException(); }
diff --git a/src/dawn/samples/DawnInfo.cpp b/src/dawn/samples/DawnInfo.cpp index 5ccac96..ec423ec 100644 --- a/src/dawn/samples/DawnInfo.cpp +++ b/src/dawn/samples/DawnInfo.cpp
@@ -250,7 +250,7 @@ void DumpAdapterLimits(const wgpu::Adapter& adapter) { wgpu::Limits adapterLimits; - if (adapter.GetLimits(&adapterLimits)) { + if (adapter.GetLimits(&adapterLimits) == wgpu::Status::Success) { std::cout << "\n"; std::cout << " Adapter Limits\n"; std::cout << " ==============\n";
diff --git a/src/dawn/tests/end2end/VideoViewsTests_mac.cpp b/src/dawn/tests/end2end/VideoViewsTests_mac.cpp index ad3047e..9251f12 100644 --- a/src/dawn/tests/end2end/VideoViewsTests_mac.cpp +++ b/src/dawn/tests/end2end/VideoViewsTests_mac.cpp
@@ -121,11 +121,12 @@ beginAccessDesc.initialized = initialized; beginAccessDesc.fenceCount = 0; beginAccessDesc.signaledValueCount = 0; - bool success = sharedTextureMemory.BeginAccess(texture, &beginAccessDesc); + wgpu::Status status = sharedTextureMemory.BeginAccess(texture, &beginAccessDesc); - return success ? std::make_unique<PlatformTextureIOSurface>(std::move(texture), - std::move(sharedTextureMemory)) - : nullptr; + return status == wgpu::Status::Success + ? std::make_unique<PlatformTextureIOSurface>(std::move(texture), + std::move(sharedTextureMemory)) + : nullptr; } void DestroyVideoTextureForTest(
diff --git a/src/dawn/tests/end2end/VideoViewsTests_win.cpp b/src/dawn/tests/end2end/VideoViewsTests_win.cpp index 6d23e07..b03facb 100644 --- a/src/dawn/tests/end2end/VideoViewsTests_win.cpp +++ b/src/dawn/tests/end2end/VideoViewsTests_win.cpp
@@ -229,9 +229,11 @@ beginDesc.signaledValues = &signaled_value; auto wgpuTexture = sharedTextureMemory.CreateTexture(&textureDesc); - bool success = sharedTextureMemory.BeginAccess(wgpuTexture, &beginDesc); + wgpu::Status status = sharedTextureMemory.BeginAccess(wgpuTexture, &beginDesc); - return success ? std::make_unique<PlatformTextureWin>(std::move(wgpuTexture)) : nullptr; + return status == wgpu::Status::Success + ? std::make_unique<PlatformTextureWin>(std::move(wgpuTexture)) + : nullptr; } void DestroyVideoTextureForTest(
diff --git a/src/dawn/tests/white_box/SharedBufferMemoryTests.cpp b/src/dawn/tests/white_box/SharedBufferMemoryTests.cpp index b383915..27538e1 100644 --- a/src/dawn/tests/white_box/SharedBufferMemoryTests.cpp +++ b/src/dawn/tests/white_box/SharedBufferMemoryTests.cpp
@@ -252,11 +252,11 @@ // Error case, fenceCount != signaledValueCount beginDesc.signaledValueCount = 1; beginDesc.signaledValues = &signalValue; - ASSERT_DEVICE_ERROR(EXPECT_FALSE(memory.BeginAccess(buffer, &beginDesc))); + ASSERT_DEVICE_ERROR(EXPECT_NE(memory.BeginAccess(buffer, &beginDesc), wgpu::Status::Success)); // Success case, fenceCount == signaledValueCount beginDesc.signaledValueCount = 0; - EXPECT_TRUE(memory.BeginAccess(buffer, &beginDesc)); + EXPECT_EQ(memory.BeginAccess(buffer, &beginDesc), wgpu::Status::Success); } // Ensure that EndAccess cannot be called on a mapped or pending mapped buffer.
diff --git a/src/dawn/tests/white_box/SharedTextureMemoryTests.cpp b/src/dawn/tests/white_box/SharedTextureMemoryTests.cpp index 5d6a507..cb197b5 100644 --- a/src/dawn/tests/white_box/SharedTextureMemoryTests.cpp +++ b/src/dawn/tests/white_box/SharedTextureMemoryTests.cpp
@@ -1003,12 +1003,14 @@ beginDesc.concurrentRead = false; beginDesc.initialized = true; - ASSERT_DEVICE_ERROR_MSG(EXPECT_FALSE(memory.BeginAccess(texture, &beginDesc)), - HasSubstr("is invalid")); + ASSERT_DEVICE_ERROR_MSG( + EXPECT_NE(memory.BeginAccess(texture, &beginDesc), wgpu::Status::Success), + HasSubstr("is invalid")); wgpu::SharedTextureMemoryEndAccessState endState = {}; - ASSERT_DEVICE_ERROR_MSG(EXPECT_FALSE(memory.EndAccess(texture, &endState)), - HasSubstr("is invalid")); + ASSERT_DEVICE_ERROR_MSG( + EXPECT_NE(memory.EndAccess(texture, &endState), wgpu::Status::Success), + HasSubstr("is invalid")); } } @@ -1057,7 +1059,7 @@ beginDesc.concurrentRead = false; beginDesc.initialized = true; // That the begin access does not succeed since the device is destroyed. - EXPECT_FALSE(memory.BeginAccess(memory.CreateTexture(), &beginDesc)); + EXPECT_NE(memory.BeginAccess(memory.CreateTexture(), &beginDesc), wgpu::Status::Success); } // Test that SharedTextureMemory::IsDeviceLost() returns the expected value before and @@ -1094,7 +1096,7 @@ beginDesc.concurrentRead = false; beginDesc.initialized = true; auto backendBeginState = GetParam().mBackend->ChainInitialBeginState(&beginDesc); - EXPECT_TRUE(memory.BeginAccess(texture, &beginDesc)); + EXPECT_EQ(memory.BeginAccess(texture, &beginDesc), wgpu::Status::Success); // Use the texture so there is a fence to export on end access. wgpu::SharedTextureMemoryProperties properties; @@ -1117,7 +1119,7 @@ // End access to export a fence. wgpu::SharedTextureMemoryEndAccessState endState = {}; auto backendEndState = GetParam().mBackend->ChainEndState(&endState); - EXPECT_TRUE(memory.EndAccess(texture, &endState)); + EXPECT_EQ(memory.EndAccess(texture, &endState), wgpu::Status::Success); // Destroy the device. device.Destroy(); @@ -1136,7 +1138,7 @@ backendBeginState = GetParam().mBackend->ChainBeginState(&beginDesc, endState); // Begin access should fail. - EXPECT_FALSE(memory.BeginAccess(texture, &beginDesc)); + EXPECT_NE(memory.BeginAccess(texture, &beginDesc), wgpu::Status::Success); } // Test calling GetProperties with an error memory. The properties are filled with 0/None/Undefined. @@ -1446,9 +1448,10 @@ auto backendBeginState = GetParam().mBackend->ChainInitialBeginState(&beginDesc); // It should be an error to BeginAccess twice in a row. - EXPECT_TRUE(memory.BeginAccess(texture, &beginDesc)); - ASSERT_DEVICE_ERROR_MSG(EXPECT_FALSE(memory.BeginAccess(texture, &beginDesc)), - HasSubstr("is already used to access")); + EXPECT_EQ(memory.BeginAccess(texture, &beginDesc), wgpu::Status::Success); + ASSERT_DEVICE_ERROR_MSG( + EXPECT_NE(memory.BeginAccess(texture, &beginDesc), wgpu::Status::Success), + HasSubstr("is already used to access")); } // Test that it is an error to call BeginAccess with fenceCount != signaledValueCount @@ -1467,11 +1470,11 @@ // Error case, fenceCount != signaledValueCount beginDesc.signaledValueCount = 1; beginDesc.signaledValues = &signalValue; - ASSERT_DEVICE_ERROR(EXPECT_FALSE(memory.BeginAccess(texture, &beginDesc))); + ASSERT_DEVICE_ERROR(EXPECT_NE(memory.BeginAccess(texture, &beginDesc), wgpu::Status::Success)); // Success case, fenceCount == signaledValueCount beginDesc.signaledValueCount = 0; - EXPECT_TRUE(memory.BeginAccess(texture, &beginDesc)); + EXPECT_EQ(memory.BeginAccess(texture, &beginDesc), wgpu::Status::Success); } // Test that it is an error to call BeginAccess concurrently on a write texture @@ -1488,9 +1491,10 @@ beginDesc.initialized = true; auto backendBeginState = GetParam().mBackend->ChainInitialBeginState(&beginDesc); - EXPECT_TRUE(memory.BeginAccess(writeTexture, &beginDesc)); - ASSERT_DEVICE_ERROR_MSG(EXPECT_FALSE(memory.BeginAccess(readTexture, &beginDesc)), - HasSubstr("is currently accessed for writing")); + EXPECT_EQ(memory.BeginAccess(writeTexture, &beginDesc), wgpu::Status::Success); + ASSERT_DEVICE_ERROR_MSG( + EXPECT_NE(memory.BeginAccess(readTexture, &beginDesc), wgpu::Status::Success), + HasSubstr("is currently accessed for writing")); } // Test that it is an error to call BeginAccess concurrently on a write texture @@ -1510,10 +1514,11 @@ beginDesc.initialized = true; auto backendBeginState = GetParam().mBackend->ChainInitialBeginState(&beginDesc); - EXPECT_TRUE(memory.BeginAccess(writeTexture, &beginDesc)); + EXPECT_EQ(memory.BeginAccess(writeTexture, &beginDesc), wgpu::Status::Success); beginDesc.concurrentRead = true; - ASSERT_DEVICE_ERROR_MSG(EXPECT_FALSE(memory.BeginAccess(readTexture, &beginDesc)), - HasSubstr("is currently accessed for writing")); + ASSERT_DEVICE_ERROR_MSG( + EXPECT_NE(memory.BeginAccess(readTexture, &beginDesc), wgpu::Status::Success), + HasSubstr("is currently accessed for writing")); } // Test that it is an error to call BeginAccess concurrently on a read texture @@ -1530,9 +1535,10 @@ beginDesc.initialized = true; auto backendBeginState = GetParam().mBackend->ChainInitialBeginState(&beginDesc); - EXPECT_TRUE(memory.BeginAccess(readTexture, &beginDesc)); - ASSERT_DEVICE_ERROR_MSG(EXPECT_FALSE(memory.BeginAccess(writeTexture, &beginDesc)), - HasSubstr("is currently accessed for exclusive reading")); + EXPECT_EQ(memory.BeginAccess(readTexture, &beginDesc), wgpu::Status::Success); + ASSERT_DEVICE_ERROR_MSG( + EXPECT_NE(memory.BeginAccess(writeTexture, &beginDesc), wgpu::Status::Success), + HasSubstr("is currently accessed for exclusive reading")); } // Test that it is an error to call BeginAccess concurrently on a read texture @@ -1552,10 +1558,11 @@ beginDesc.initialized = true; auto backendBeginState = GetParam().mBackend->ChainInitialBeginState(&beginDesc); - EXPECT_TRUE(memory.BeginAccess(readTexture, &beginDesc)); + EXPECT_EQ(memory.BeginAccess(readTexture, &beginDesc), wgpu::Status::Success); beginDesc.concurrentRead = false; - ASSERT_DEVICE_ERROR_MSG(EXPECT_FALSE(memory.BeginAccess(writeTexture, &beginDesc)), - HasSubstr("is currently accessed for reading.")); + ASSERT_DEVICE_ERROR_MSG( + EXPECT_NE(memory.BeginAccess(writeTexture, &beginDesc), wgpu::Status::Success), + HasSubstr("is currently accessed for reading.")); } // Test that it is an error to call BeginAccess concurrently on two write textures on a single @@ -1572,9 +1579,10 @@ beginDesc.initialized = true; auto backendBeginState = GetParam().mBackend->ChainInitialBeginState(&beginDesc); - EXPECT_TRUE(memory.BeginAccess(writeTexture1, &beginDesc)); - ASSERT_DEVICE_ERROR_MSG(EXPECT_FALSE(memory.BeginAccess(writeTexture2, &beginDesc)), - HasSubstr("is currently accessed for writing")); + EXPECT_EQ(memory.BeginAccess(writeTexture1, &beginDesc), wgpu::Status::Success); + ASSERT_DEVICE_ERROR_MSG( + EXPECT_NE(memory.BeginAccess(writeTexture2, &beginDesc), wgpu::Status::Success), + HasSubstr("is currently accessed for writing")); } // Test that it is valid to call BeginAccess concurrently on two read textures on a single @@ -1591,9 +1599,10 @@ beginDesc.initialized = true; auto backendBeginState = GetParam().mBackend->ChainInitialBeginState(&beginDesc); - EXPECT_TRUE(memory.BeginAccess(readTexture1, &beginDesc)); - ASSERT_DEVICE_ERROR_MSG(EXPECT_FALSE(memory.BeginAccess(readTexture2, &beginDesc)), - HasSubstr("is currently accessed for exclusive reading")); + EXPECT_EQ(memory.BeginAccess(readTexture1, &beginDesc), wgpu::Status::Success); + ASSERT_DEVICE_ERROR_MSG( + EXPECT_NE(memory.BeginAccess(readTexture2, &beginDesc), wgpu::Status::Success), + HasSubstr("is currently accessed for exclusive reading")); } // Test that it is valid to call BeginAccess concurrently on two read textures on a single @@ -1613,13 +1622,13 @@ beginDesc.initialized = true; auto backendBeginState = GetParam().mBackend->ChainInitialBeginState(&beginDesc); - EXPECT_TRUE(memory.BeginAccess(readTexture1, &beginDesc)); - EXPECT_TRUE(memory.BeginAccess(readTexture2, &beginDesc)); + EXPECT_EQ(memory.BeginAccess(readTexture1, &beginDesc), wgpu::Status::Success); + EXPECT_EQ(memory.BeginAccess(readTexture2, &beginDesc), wgpu::Status::Success); wgpu::SharedTextureMemoryEndAccessState endState1 = {}; - EXPECT_TRUE(memory.EndAccess(readTexture1, &endState1)); + EXPECT_EQ(memory.EndAccess(readTexture1, &endState1), wgpu::Status::Success); wgpu::SharedTextureMemoryEndAccessState endState2 = {}; - EXPECT_TRUE(memory.EndAccess(readTexture2, &endState2)); + EXPECT_EQ(memory.EndAccess(readTexture2, &endState2), wgpu::Status::Success); } // Test that it is valid to call BeginAccess concurrently on read textures on a single @@ -1638,10 +1647,11 @@ auto backendBeginState = GetParam().mBackend->ChainInitialBeginState(&beginDesc); beginDesc.concurrentRead = true; - EXPECT_TRUE(memory.BeginAccess(readTexture1, &beginDesc)); + EXPECT_EQ(memory.BeginAccess(readTexture1, &beginDesc), wgpu::Status::Success); beginDesc.concurrentRead = false; - ASSERT_DEVICE_ERROR_MSG(EXPECT_FALSE(memory.BeginAccess(readTexture2, &beginDesc)), - HasSubstr("is currently accessed for reading.")); + ASSERT_DEVICE_ERROR_MSG( + EXPECT_NE(memory.BeginAccess(readTexture2, &beginDesc), wgpu::Status::Success), + HasSubstr("is currently accessed for reading.")); } // Test that it is valid to call BeginAccess concurrently on read textures on a single @@ -1660,10 +1670,11 @@ auto backendBeginState = GetParam().mBackend->ChainInitialBeginState(&beginDesc); beginDesc.concurrentRead = false; - EXPECT_TRUE(memory.BeginAccess(readTexture1, &beginDesc)); + EXPECT_EQ(memory.BeginAccess(readTexture1, &beginDesc), wgpu::Status::Success); beginDesc.concurrentRead = true; - ASSERT_DEVICE_ERROR_MSG(EXPECT_FALSE(memory.BeginAccess(readTexture2, &beginDesc)), - HasSubstr("is currently accessed for exclusive reading.")); + ASSERT_DEVICE_ERROR_MSG( + EXPECT_NE(memory.BeginAccess(readTexture2, &beginDesc), wgpu::Status::Success), + HasSubstr("is currently accessed for exclusive reading.")); } // Test that it is valid to call BeginAccess concurrently on write textures with concurrentRead is @@ -1682,8 +1693,9 @@ auto backendBeginState = GetParam().mBackend->ChainInitialBeginState(&beginDesc); beginDesc.concurrentRead = true; - ASSERT_DEVICE_ERROR_MSG(EXPECT_FALSE(memory.BeginAccess(writeTexture, &beginDesc)), - HasSubstr("Concurrent reading read-write")); + ASSERT_DEVICE_ERROR_MSG( + EXPECT_NE(memory.BeginAccess(writeTexture, &beginDesc), wgpu::Status::Success), + HasSubstr("Concurrent reading read-write")); } // Test that it is an error to call EndAccess twice in a row on the same memory. @@ -1697,14 +1709,14 @@ beginDesc.initialized = true; auto backendBeginState = GetParam().mBackend->ChainInitialBeginState(&beginDesc); - EXPECT_TRUE(memory.BeginAccess(texture, &beginDesc)); + EXPECT_EQ(memory.BeginAccess(texture, &beginDesc), wgpu::Status::Success); wgpu::SharedTextureMemoryEndAccessState endState = {}; auto backendEndState = GetParam().mBackend->ChainEndState(&endState); - EXPECT_TRUE(memory.EndAccess(texture, &endState)); + EXPECT_EQ(memory.EndAccess(texture, &endState), wgpu::Status::Success); // Invalid to end access a second time. - ASSERT_DEVICE_ERROR_MSG(EXPECT_FALSE(memory.EndAccess(texture, &endState)), + ASSERT_DEVICE_ERROR_MSG(EXPECT_NE(memory.EndAccess(texture, &endState), wgpu::Status::Success), HasSubstr("is not currently being accessed")); } @@ -1721,11 +1733,11 @@ beginDesc.initialized = true; auto backendBeginState = GetParam().mBackend->ChainInitialBeginState(&beginDesc); - EXPECT_TRUE(memory.BeginAccess(texture1, &beginDesc)); + EXPECT_EQ(memory.BeginAccess(texture1, &beginDesc), wgpu::Status::Success); wgpu::SharedTextureMemoryEndAccessState endState = {}; auto backendEndState = GetParam().mBackend->ChainEndState(&endState); - ASSERT_DEVICE_ERROR_MSG(EXPECT_FALSE(memory.EndAccess(texture2, &endState)), + ASSERT_DEVICE_ERROR_MSG(EXPECT_NE(memory.EndAccess(texture2, &endState), wgpu::Status::Success), HasSubstr("is not currently being accessed")); } @@ -1737,7 +1749,7 @@ wgpu::SharedTextureMemoryEndAccessState endState = {}; auto backendEndState = GetParam().mBackend->ChainEndState(&endState); - ASSERT_DEVICE_ERROR_MSG(EXPECT_FALSE(memory.EndAccess(texture, &endState)), + ASSERT_DEVICE_ERROR_MSG(EXPECT_NE(memory.EndAccess(texture, &endState), wgpu::Status::Success), HasSubstr("is not currently being accessed")); }