Fix DawnWireServerFuzzer
dawn::native::Instance needs to be constructed from WGPUInstance,
instead of cast from it.
Bug: 341875571
Change-Id: I23fd317ef8c126516da4d940caecf37da529d644
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/189140
Reviewed-by: Loko Kung <lokokung@google.com>
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Shrek Shao <shrekshao@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
diff --git a/include/dawn/native/DawnNative.h b/include/dawn/native/DawnNative.h
index 1ff8d9b..915f3c6 100644
--- a/include/dawn/native/DawnNative.h
+++ b/include/dawn/native/DawnNative.h
@@ -157,6 +157,7 @@
class DAWN_NATIVE_EXPORT Instance {
public:
explicit Instance(const WGPUInstanceDescriptor* desc = nullptr);
+ explicit Instance(InstanceBase* impl);
~Instance();
Instance(const Instance& other) = delete;
diff --git a/src/dawn/fuzzers/DawnWireServerFuzzer.cpp b/src/dawn/fuzzers/DawnWireServerFuzzer.cpp
index ff50066..7ddc02c 100644
--- a/src/dawn/fuzzers/DawnWireServerFuzzer.cpp
+++ b/src/dawn/fuzzers/DawnWireServerFuzzer.cpp
@@ -115,7 +115,8 @@
const WGPURequestAdapterOptions* options,
WGPURequestAdapterCallback callback, void* userdata) {
std::vector<dawn::native::Adapter> adapters =
- reinterpret_cast<dawn::native::Instance*>(cInstance)->EnumerateAdapters();
+ dawn::native::Instance(reinterpret_cast<dawn::native::InstanceBase*>(cInstance))
+ .EnumerateAdapters();
for (dawn::native::Adapter adapter : adapters) {
if (sAdapterSupported(adapter)) {
WGPUAdapter cAdapter = adapter.Get();
@@ -137,14 +138,5 @@
std::unique_ptr<dawn::wire::WireServer> wireServer(new dawn::wire::WireServer(serverDesc));
wireServer->InjectInstance(instance->Get(), {1, 0});
wireServer->HandleCommands(reinterpret_cast<const char*>(data), size);
-
- // Flush remaining callbacks to avoid memory leaks.
- // TODO(crbug.com/dawn/1712): DeviceNull's APITick() will always return true so cannot
- // do a polling loop here.
- dawn::native::InstanceProcessEvents(instance->Get());
-
- // Note: Deleting the server will release all created objects.
- // Deleted devices will wait for idle on destruction.
- wireServer = nullptr;
return 0;
}
diff --git a/src/dawn/fuzzers/lpmfuzz/DawnLPMFuzzer.cpp b/src/dawn/fuzzers/lpmfuzz/DawnLPMFuzzer.cpp
index ed0f107..b30c205 100644
--- a/src/dawn/fuzzers/lpmfuzz/DawnLPMFuzzer.cpp
+++ b/src/dawn/fuzzers/lpmfuzz/DawnLPMFuzzer.cpp
@@ -89,7 +89,8 @@
const WGPURequestAdapterOptions* options,
WGPURequestAdapterCallback callback, void* userdata) {
std::vector<dawn::native::Adapter> adapters =
- reinterpret_cast<dawn::native::Instance*>(cInstance)->EnumerateAdapters();
+ dawn::native::Instance(reinterpret_cast<dawn::native::InstanceBase*>(cInstance))
+ .EnumerateAdapters();
for (dawn::native::Adapter adapter : adapters) {
if (sAdapterSupported(adapter)) {
WGPUAdapter cAdapter = adapter.Get();
@@ -124,7 +125,6 @@
// Note: Deleting the server will release all created objects.
// Deleted devices will wait for idle on destruction.
mCommandBuffer->SetHandler(nullptr);
- wireServer = nullptr;
return result == dawn::wire::WireResult::FatalError;
}
diff --git a/src/dawn/native/DawnNative.cpp b/src/dawn/native/DawnNative.cpp
index 71374e6..71a5e0c 100644
--- a/src/dawn/native/DawnNative.cpp
+++ b/src/dawn/native/DawnNative.cpp
@@ -170,6 +170,13 @@
tint::Initialize();
}
+Instance::Instance(InstanceBase* impl) : mImpl(impl) {
+ if (mImpl != nullptr) {
+ mImpl->APIAddRef();
+ }
+ tint::Initialize();
+}
+
Instance::~Instance() {
if (mImpl != nullptr) {
mImpl->APIRelease();