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>
This commit is contained in:
Corentin Wallez 2019-01-10 10:07:04 +00:00 committed by Commit Bot service account
parent bd48385d50
commit 0d03b09623
5 changed files with 37 additions and 10 deletions

View File

@ -22,10 +22,6 @@
namespace dawn_native { namespace null { namespace dawn_native { namespace null {
dawnDevice CreateDevice() {
return reinterpret_cast<dawnDevice>(new Device);
}
dawnSwapChainImplementation CreateNativeSwapChainImpl() { dawnSwapChainImplementation CreateNativeSwapChainImpl() {
dawnSwapChainImplementation impl; dawnSwapChainImplementation impl;
impl = CreateSwapChainImplementation(new NativeSwapChainImpl()); impl = CreateSwapChainImplementation(new NativeSwapChainImpl());

View File

@ -164,8 +164,13 @@ dawn_fuzzer_test("dawn_wire_server_and_frontend_fuzzer") {
] ]
deps = [ deps = [
"${dawn_top_level}:dawn_common",
"${dawn_top_level}:libdawn_static", "${dawn_top_level}:libdawn_static",
"${dawn_top_level}:libdawn_native_static", "${dawn_top_level}:libdawn_native_static",
"${dawn_top_level}:libdawn_wire_static", "${dawn_top_level}:libdawn_wire_static",
] ]
additional_configs = [
"${dawn_top_level}:dawn_internal",
]
} }

View File

@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "common/Assert.h"
#include "dawn/dawncpp.h" #include "dawn/dawncpp.h"
#include "dawn_native/DawnNative.h" #include "dawn_native/DawnNative.h"
#include "dawn_native/NullBackend.h"
#include "dawn_wire/Wire.h" #include "dawn_wire/Wire.h"
#include <vector> #include <vector>
@ -45,7 +45,20 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
procs.swapChainBuilderSetImplementation = SkipSwapChainBuilderSetImplementation; procs.swapChainBuilderSetImplementation = SkipSwapChainBuilderSetImplementation;
dawnSetProcs(&procs); 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; DevNull devNull;
std::unique_ptr<dawn_wire::CommandHandler> wireServer( std::unique_ptr<dawn_wire::CommandHandler> wireServer(
@ -59,6 +72,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
// Destroy the server before the device because it needs to free all objects. // Destroy the server before the device because it needs to free all objects.
wireServer = nullptr; wireServer = nullptr;
nullDevice = nullptr; nullDevice = nullptr;
instance = nullptr;
return 0; return 0;
} }

View File

@ -15,12 +15,10 @@
#ifndef DAWNNATIVE_NULLBACKEND_H_ #ifndef DAWNNATIVE_NULLBACKEND_H_
#define DAWNNATIVE_NULLBACKEND_H_ #define DAWNNATIVE_NULLBACKEND_H_
#include <dawn/dawn.h>
#include <dawn/dawn_wsi.h> #include <dawn/dawn_wsi.h>
#include <dawn_native/dawn_native_export.h> #include <dawn_native/DawnNative.h>
namespace dawn_native { namespace null { namespace dawn_native { namespace null {
DAWN_NATIVE_EXPORT dawnDevice CreateDevice();
DAWN_NATIVE_EXPORT dawnSwapChainImplementation CreateNativeSwapChainImpl(); DAWN_NATIVE_EXPORT dawnSwapChainImplementation CreateNativeSwapChainImpl();
}} // namespace dawn_native::null }} // namespace dawn_native::null

View File

@ -14,6 +14,7 @@
#include "utils/BackendBinding.h" #include "utils/BackendBinding.h"
#include "common/Assert.h"
#include "dawn_native/NullBackend.h" #include "dawn_native/NullBackend.h"
namespace utils { namespace utils {
@ -23,7 +24,19 @@ namespace utils {
void SetupGLFWWindowHints() override { void SetupGLFWWindowHints() override {
} }
dawnDevice CreateDevice() 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 { uint64_t GetSwapChainImplementation() override {
if (mSwapchainImpl.userData == nullptr) { if (mSwapchainImpl.userData == nullptr) {
@ -36,6 +49,7 @@ namespace utils {
} }
private: private:
std::unique_ptr<dawn_native::Instance> mInstance;
dawnSwapChainImplementation mSwapchainImpl = {}; dawnSwapChainImplementation mSwapchainImpl = {};
}; };