Remove non-adapter way to create null devices
BUG=dawn:29
Change-Id: I2153aa30afd096a3f27c8b8b2ba23a10c0ade50a
Reviewed-on: https://dawn-review.googlesource.com/c/3841
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/dawn_native/null/NullBackend.cpp b/src/dawn_native/null/NullBackend.cpp
index bd55c54..7f66df0 100644
--- a/src/dawn_native/null/NullBackend.cpp
+++ b/src/dawn_native/null/NullBackend.cpp
@@ -22,10 +22,6 @@
namespace dawn_native { namespace null {
- dawnDevice CreateDevice() {
- return reinterpret_cast<dawnDevice>(new Device);
- }
-
dawnSwapChainImplementation CreateNativeSwapChainImpl() {
dawnSwapChainImplementation impl;
impl = CreateSwapChainImplementation(new NativeSwapChainImpl());
diff --git a/src/fuzzers/BUILD.gn b/src/fuzzers/BUILD.gn
index 128cf18..9df69eb 100644
--- a/src/fuzzers/BUILD.gn
+++ b/src/fuzzers/BUILD.gn
@@ -164,8 +164,13 @@
]
deps = [
+ "${dawn_top_level}:dawn_common",
"${dawn_top_level}:libdawn_static",
"${dawn_top_level}:libdawn_native_static",
"${dawn_top_level}:libdawn_wire_static",
]
+
+ additional_configs = [
+ "${dawn_top_level}:dawn_internal",
+ ]
}
diff --git a/src/fuzzers/DawnWireServerAndFrontendFuzzer.cpp b/src/fuzzers/DawnWireServerAndFrontendFuzzer.cpp
index 37f7765..9160b29 100644
--- a/src/fuzzers/DawnWireServerAndFrontendFuzzer.cpp
+++ b/src/fuzzers/DawnWireServerAndFrontendFuzzer.cpp
@@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#include "common/Assert.h"
#include "dawn/dawncpp.h"
#include "dawn_native/DawnNative.h"
-#include "dawn_native/NullBackend.h"
#include "dawn_wire/Wire.h"
#include <vector>
@@ -45,7 +45,20 @@
procs.swapChainBuilderSetImplementation = SkipSwapChainBuilderSetImplementation;
dawnSetProcs(&procs);
- dawn::Device nullDevice = dawn::Device::Acquire(dawn_native::null::CreateDevice());
+ // Create an instance and find the null adapter to create a device with.
+ std::unique_ptr<dawn_native::Instance> instance = std::make_unique<dawn_native::Instance>();
+ instance->DiscoverDefaultAdapters();
+
+ std::vector<dawn_native::Adapter> adapters = instance->GetAdapters();
+
+ dawn::Device nullDevice;
+ for (dawn_native::Adapter adapter : adapters) {
+ if (adapter.GetBackendType() == dawn_native::BackendType::Null) {
+ nullDevice = dawn::Device::Acquire(adapter.CreateDevice());
+ break;
+ }
+ }
+ ASSERT(nullDevice.Get() != nullptr);
DevNull devNull;
std::unique_ptr<dawn_wire::CommandHandler> wireServer(
@@ -59,6 +72,7 @@
// Destroy the server before the device because it needs to free all objects.
wireServer = nullptr;
nullDevice = nullptr;
+ instance = nullptr;
return 0;
}
diff --git a/src/include/dawn_native/NullBackend.h b/src/include/dawn_native/NullBackend.h
index 21fe1d0..7862c5f 100644
--- a/src/include/dawn_native/NullBackend.h
+++ b/src/include/dawn_native/NullBackend.h
@@ -15,12 +15,10 @@
#ifndef DAWNNATIVE_NULLBACKEND_H_
#define DAWNNATIVE_NULLBACKEND_H_
-#include <dawn/dawn.h>
#include <dawn/dawn_wsi.h>
-#include <dawn_native/dawn_native_export.h>
+#include <dawn_native/DawnNative.h>
namespace dawn_native { namespace null {
- DAWN_NATIVE_EXPORT dawnDevice CreateDevice();
DAWN_NATIVE_EXPORT dawnSwapChainImplementation CreateNativeSwapChainImpl();
}} // namespace dawn_native::null
diff --git a/src/utils/NullBinding.cpp b/src/utils/NullBinding.cpp
index 1620dd2..0bf6f3b 100644
--- a/src/utils/NullBinding.cpp
+++ b/src/utils/NullBinding.cpp
@@ -14,6 +14,7 @@
#include "utils/BackendBinding.h"
+#include "common/Assert.h"
#include "dawn_native/NullBackend.h"
namespace utils {
@@ -23,7 +24,19 @@
void SetupGLFWWindowHints() override {
}
dawnDevice CreateDevice() override {
- return dawn_native::null::CreateDevice();
+ // Make an instance and find the null adapter
+ mInstance = std::make_unique<dawn_native::Instance>();
+ mInstance->DiscoverDefaultAdapters();
+
+ std::vector<dawn_native::Adapter> adapters = mInstance->GetAdapters();
+ for (dawn_native::Adapter adapter : adapters) {
+ if (adapter.GetBackendType() == dawn_native::BackendType::Null) {
+ return adapter.CreateDevice();
+ }
+ }
+
+ UNREACHABLE();
+ return {};
}
uint64_t GetSwapChainImplementation() override {
if (mSwapchainImpl.userData == nullptr) {
@@ -36,6 +49,7 @@
}
private:
+ std::unique_ptr<dawn_native::Instance> mInstance;
dawnSwapChainImplementation mSwapchainImpl = {};
};