Add WGPUAdapterProperties and expose it in DawnNative
The dawn_native::Adapter::GetPCIInfo/GetBackendType/GetDeviceType
methods are now deprecated in favor of a method returning a webgpu.h
AdapterProperties structure. Deprecated function are still available to
avoid breaking Chromium or Skia compilation.
This reduces the difference between dawn.json and webgpu.h
BUG=dawn:160
Change-Id: Ib68fe1c4d1d87676c01c212c91f80fdd26056c56
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/14541
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
diff --git a/dawn.json b/dawn.json
index 3e3fdd9..15e17b6 100644
--- a/dawn.json
+++ b/dawn.json
@@ -14,6 +14,26 @@
"See the License for the specific language governing permissions and",
"limitations under the License."
],
+ "adapter properties": {
+ "category": "structure",
+ "extensible": true,
+ "members": [
+ {"name": "device ID", "type": "uint32_t"},
+ {"name": "vendor ID", "type": "uint32_t"},
+ {"name": "name", "type": "char", "annotation": "const*"},
+ {"name": "adapter type", "type": "adapter type"},
+ {"name": "backend type", "type": "backend type"}
+ ]
+ },
+ "adapter type": {
+ "category": "enum",
+ "values": [
+ {"value": 0, "name": "discrete GPU"},
+ {"value": 1, "name": "integrated GPU"},
+ {"value": 2, "name": "CPU"},
+ {"value": 3, "name": "Unknown"}
+ ]
+ },
"address mode": {
"category": "enum",
"values": [
@@ -22,6 +42,18 @@
{"value": 2, "name": "clamp to edge"}
]
},
+ "backend type": {
+ "category": "enum",
+ "values": [
+ {"value": 0, "name": "D3D11"},
+ {"value": 1, "name": "D3D12"},
+ {"value": 2, "name": "metal"},
+ {"value": 3, "name": "vulkan"},
+ {"value": 4, "name": "openGL"},
+ {"value": 5, "name": "openGLES"},
+ {"value": 6, "name": "null"}
+ ]
+ },
"bind group": {
"category": "object"
},
diff --git a/examples/SampleUtils.cpp b/examples/SampleUtils.cpp
index b2bf1e58..b3d87a1 100644
--- a/examples/SampleUtils.cpp
+++ b/examples/SampleUtils.cpp
@@ -65,13 +65,13 @@
// Default to D3D12, Metal, Vulkan, OpenGL in that order as D3D12 and Metal are the preferred on
// their respective platforms, and Vulkan is preferred to OpenGL
#if defined(DAWN_ENABLE_BACKEND_D3D12)
- static dawn_native::BackendType backendType = dawn_native::BackendType::D3D12;
+static wgpu::BackendType backendType = wgpu::BackendType::D3D12;
#elif defined(DAWN_ENABLE_BACKEND_METAL)
- static dawn_native::BackendType backendType = dawn_native::BackendType::Metal;
-#elif defined(DAWN_ENABLE_BACKEND_OPENGL)
- static dawn_native::BackendType backendType = dawn_native::BackendType::OpenGL;
+static wgpu::BackendType backendType = wgpu::BackendType::Metal;
#elif defined(DAWN_ENABLE_BACKEND_VULKAN)
- static dawn_native::BackendType backendType = dawn_native::BackendType::Vulkan;
+static wgpu::BackendType backendType = wgpu::BackendType::Vulkan;
+#elif defined(DAWN_ENABLE_BACKEND_OPENGL)
+static wgpu::BackendType backendType = wgpu::BackendType::OpenGL;
#else
#error
#endif
@@ -109,8 +109,10 @@
std::vector<dawn_native::Adapter> adapters = instance->GetAdapters();
auto adapterIt = std::find_if(adapters.begin(), adapters.end(),
[](const dawn_native::Adapter adapter) -> bool {
- return adapter.GetBackendType() == backendType;
- });
+ wgpu::AdapterProperties properties;
+ adapter.GetProperties(&properties);
+ return properties.backendType == backendType;
+ });
ASSERT(adapterIt != adapters.end());
backendAdapter = *adapterIt;
}
@@ -200,23 +202,23 @@
if (std::string("-b") == argv[i] || std::string("--backend") == argv[i]) {
i++;
if (i < argc && std::string("d3d12") == argv[i]) {
- backendType = dawn_native::BackendType::D3D12;
+ backendType = wgpu::BackendType::D3D12;
continue;
}
if (i < argc && std::string("metal") == argv[i]) {
- backendType = dawn_native::BackendType::Metal;
+ backendType = wgpu::BackendType::Metal;
continue;
}
if (i < argc && std::string("null") == argv[i]) {
- backendType = dawn_native::BackendType::Null;
+ backendType = wgpu::BackendType::Null;
continue;
}
if (i < argc && std::string("opengl") == argv[i]) {
- backendType = dawn_native::BackendType::OpenGL;
+ backendType = wgpu::BackendType::OpenGL;
continue;
}
if (i < argc && std::string("vulkan") == argv[i]) {
- backendType = dawn_native::BackendType::Vulkan;
+ backendType = wgpu::BackendType::Vulkan;
continue;
}
fprintf(stderr, "--backend expects a backend name (opengl, metal, d3d12, null, vulkan)\n");
diff --git a/src/dawn_native/Adapter.cpp b/src/dawn_native/Adapter.cpp
index 02f0966..aa3ede7 100644
--- a/src/dawn_native/Adapter.cpp
+++ b/src/dawn_native/Adapter.cpp
@@ -18,16 +18,16 @@
namespace dawn_native {
- AdapterBase::AdapterBase(InstanceBase* instance, BackendType backend)
+ AdapterBase::AdapterBase(InstanceBase* instance, wgpu::BackendType backend)
: mInstance(instance), mBackend(backend) {
}
- BackendType AdapterBase::GetBackendType() const {
+ wgpu::BackendType AdapterBase::GetBackendType() const {
return mBackend;
}
- DeviceType AdapterBase::GetDeviceType() const {
- return mDeviceType;
+ wgpu::AdapterType AdapterBase::GetAdapterType() const {
+ return mAdapterType;
}
const PCIInfo& AdapterBase::GetPCIInfo() const {
diff --git a/src/dawn_native/Adapter.h b/src/dawn_native/Adapter.h
index 410a9a3..d008934 100644
--- a/src/dawn_native/Adapter.h
+++ b/src/dawn_native/Adapter.h
@@ -19,6 +19,9 @@
#include "dawn_native/Error.h"
#include "dawn_native/Extensions.h"
+#include "dawn_native/dawn_platform.h"
+
+#include <string>
namespace dawn_native {
@@ -26,11 +29,11 @@
class AdapterBase {
public:
- AdapterBase(InstanceBase* instance, BackendType backend);
+ AdapterBase(InstanceBase* instance, wgpu::BackendType backend);
virtual ~AdapterBase() = default;
- BackendType GetBackendType() const;
- DeviceType GetDeviceType() const;
+ wgpu::BackendType GetBackendType() const;
+ wgpu::AdapterType GetAdapterType() const;
const PCIInfo& GetPCIInfo() const;
InstanceBase* GetInstance() const;
@@ -43,7 +46,7 @@
protected:
PCIInfo mPCIInfo = {};
- DeviceType mDeviceType = DeviceType::Unknown;
+ wgpu::AdapterType mAdapterType = wgpu::AdapterType::Unknown;
ExtensionsSet mSupportedExtensions;
private:
@@ -52,7 +55,7 @@
MaybeError CreateDeviceInternal(DeviceBase** result, const DeviceDescriptor* descriptor);
InstanceBase* mInstance = nullptr;
- BackendType mBackend;
+ wgpu::BackendType mBackend;
};
} // namespace dawn_native
diff --git a/src/dawn_native/BackendConnection.cpp b/src/dawn_native/BackendConnection.cpp
index 5a9d4b1..09ef4ef 100644
--- a/src/dawn_native/BackendConnection.cpp
+++ b/src/dawn_native/BackendConnection.cpp
@@ -16,11 +16,11 @@
namespace dawn_native {
- BackendConnection::BackendConnection(InstanceBase* instance, BackendType type)
+ BackendConnection::BackendConnection(InstanceBase* instance, wgpu::BackendType type)
: mInstance(instance), mType(type) {
}
- BackendType BackendConnection::GetType() const {
+ wgpu::BackendType BackendConnection::GetType() const {
return mType;
}
diff --git a/src/dawn_native/BackendConnection.h b/src/dawn_native/BackendConnection.h
index e0e5699..f17108e 100644
--- a/src/dawn_native/BackendConnection.h
+++ b/src/dawn_native/BackendConnection.h
@@ -26,10 +26,10 @@
// backend.
class BackendConnection {
public:
- BackendConnection(InstanceBase* instance, BackendType type);
+ BackendConnection(InstanceBase* instance, wgpu::BackendType type);
virtual ~BackendConnection() = default;
- BackendType GetType() const;
+ wgpu::BackendType GetType() const;
InstanceBase* GetInstance() const;
// Returns all the adapters for the system that can be created by the backend, without extra
@@ -42,7 +42,7 @@
private:
InstanceBase* mInstance = nullptr;
- BackendType mType;
+ wgpu::BackendType mType;
};
} // namespace dawn_native
diff --git a/src/dawn_native/DawnNative.cpp b/src/dawn_native/DawnNative.cpp
index 857d0d2..dc95bc1 100644
--- a/src/dawn_native/DawnNative.cpp
+++ b/src/dawn_native/DawnNative.cpp
@@ -44,12 +44,44 @@
mImpl = nullptr;
}
+ void Adapter::GetProperties(wgpu::AdapterProperties* properties) const {
+ properties->backendType = mImpl->GetBackendType();
+ properties->adapterType = mImpl->GetAdapterType();
+ properties->deviceID = mImpl->GetPCIInfo().deviceId;
+ properties->vendorID = mImpl->GetPCIInfo().vendorId;
+ properties->name = mImpl->GetPCIInfo().name.c_str();
+ }
+
BackendType Adapter::GetBackendType() const {
- return mImpl->GetBackendType();
+ switch (mImpl->GetBackendType()) {
+ case wgpu::BackendType::D3D12:
+ return BackendType::D3D12;
+ case wgpu::BackendType::Metal:
+ return BackendType::Metal;
+ case wgpu::BackendType::Null:
+ return BackendType::Null;
+ case wgpu::BackendType::OpenGL:
+ return BackendType::OpenGL;
+ case wgpu::BackendType::Vulkan:
+ return BackendType::Vulkan;
+
+ default:
+ UNREACHABLE();
+ return BackendType::Null;
+ }
}
DeviceType Adapter::GetDeviceType() const {
- return mImpl->GetDeviceType();
+ switch (mImpl->GetAdapterType()) {
+ case wgpu::AdapterType::DiscreteGPU:
+ return DeviceType::DiscreteGPU;
+ case wgpu::AdapterType::IntegratedGPU:
+ return DeviceType::IntegratedGPU;
+ case wgpu::AdapterType::CPU:
+ return DeviceType::CPU;
+ case wgpu::AdapterType::Unknown:
+ return DeviceType::Unknown;
+ }
}
const PCIInfo& Adapter::GetPCIInfo() const {
@@ -75,7 +107,8 @@
// AdapterDiscoverOptionsBase
- AdapterDiscoveryOptionsBase::AdapterDiscoveryOptionsBase(BackendType type) : backendType(type) {
+ AdapterDiscoveryOptionsBase::AdapterDiscoveryOptionsBase(WGPUBackendType type)
+ : backendType(type) {
}
// Instance
diff --git a/src/dawn_native/Instance.cpp b/src/dawn_native/Instance.cpp
index c26d597..7219ab6 100644
--- a/src/dawn_native/Instance.cpp
+++ b/src/dawn_native/Instance.cpp
@@ -120,7 +120,7 @@
return;
}
- auto Register = [this](BackendConnection* connection, BackendType expectedType) {
+ auto Register = [this](BackendConnection* connection, wgpu::BackendType expectedType) {
if (connection != nullptr) {
ASSERT(connection->GetType() == expectedType);
ASSERT(connection->GetInstance() == this);
@@ -129,25 +129,25 @@
};
#if defined(DAWN_ENABLE_BACKEND_D3D12)
- Register(d3d12::Connect(this), BackendType::D3D12);
+ Register(d3d12::Connect(this), wgpu::BackendType::D3D12);
#endif // defined(DAWN_ENABLE_BACKEND_D3D12)
#if defined(DAWN_ENABLE_BACKEND_METAL)
- Register(metal::Connect(this), BackendType::Metal);
+ Register(metal::Connect(this), wgpu::BackendType::Metal);
#endif // defined(DAWN_ENABLE_BACKEND_METAL)
#if defined(DAWN_ENABLE_BACKEND_VULKAN)
- Register(vulkan::Connect(this), BackendType::Vulkan);
+ Register(vulkan::Connect(this), wgpu::BackendType::Vulkan);
#endif // defined(DAWN_ENABLE_BACKEND_VULKAN)
#if defined(DAWN_ENABLE_BACKEND_OPENGL)
- Register(opengl::Connect(this), BackendType::OpenGL);
+ Register(opengl::Connect(this), wgpu::BackendType::OpenGL);
#endif // defined(DAWN_ENABLE_BACKEND_OPENGL)
#if defined(DAWN_ENABLE_BACKEND_NULL)
- Register(null::Connect(this), BackendType::Null);
+ Register(null::Connect(this), wgpu::BackendType::Null);
#endif // defined(DAWN_ENABLE_BACKEND_NULL)
mBackendsConnected = true;
}
- ResultOrError<BackendConnection*> InstanceBase::FindBackend(BackendType type) {
+ ResultOrError<BackendConnection*> InstanceBase::FindBackend(wgpu::BackendType type) {
for (std::unique_ptr<BackendConnection>& backend : mBackends) {
if (backend->GetType() == type) {
return backend.get();
@@ -161,7 +161,7 @@
EnsureBackendConnections();
BackendConnection* backend;
- DAWN_TRY_ASSIGN(backend, FindBackend(options->backendType));
+ DAWN_TRY_ASSIGN(backend, FindBackend(static_cast<wgpu::BackendType>(options->backendType)));
std::vector<std::unique_ptr<AdapterBase>> newAdapters;
DAWN_TRY_ASSIGN(newAdapters, backend->DiscoverAdapters(options));
diff --git a/src/dawn_native/Instance.h b/src/dawn_native/Instance.h
index 0881d01..5095664 100644
--- a/src/dawn_native/Instance.h
+++ b/src/dawn_native/Instance.h
@@ -77,7 +77,7 @@
void EnsureBackendConnections();
// Finds the BackendConnection for `type` or returns an error.
- ResultOrError<BackendConnection*> FindBackend(BackendType type);
+ ResultOrError<BackendConnection*> FindBackend(wgpu::BackendType type);
MaybeError DiscoverAdaptersInternal(const AdapterDiscoveryOptionsBase* options);
diff --git a/src/dawn_native/d3d12/AdapterD3D12.cpp b/src/dawn_native/d3d12/AdapterD3D12.cpp
index c26399b..d9a07c6 100644
--- a/src/dawn_native/d3d12/AdapterD3D12.cpp
+++ b/src/dawn_native/d3d12/AdapterD3D12.cpp
@@ -35,7 +35,7 @@
};
Adapter::Adapter(Backend* backend, ComPtr<IDXGIAdapter1> hardwareAdapter)
- : AdapterBase(backend->GetInstance(), BackendType::D3D12),
+ : AdapterBase(backend->GetInstance(), wgpu::BackendType::D3D12),
mHardwareAdapter(hardwareAdapter),
mBackend(backend) {
}
@@ -75,9 +75,10 @@
DAWN_TRY_ASSIGN(mDeviceInfo, GatherDeviceInfo(*this));
if (adapterDesc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) {
- mDeviceType = DeviceType::CPU;
+ mAdapterType = wgpu::AdapterType::CPU;
} else {
- mDeviceType = (mDeviceInfo.isUMA) ? DeviceType::IntegratedGPU : DeviceType::DiscreteGPU;
+ mAdapterType = (mDeviceInfo.isUMA) ? wgpu::AdapterType::IntegratedGPU
+ : wgpu::AdapterType::DiscreteGPU;
}
std::wstring_convert<DeletableFacet<std::codecvt<wchar_t, char, std::mbstate_t>>> converter(
diff --git a/src/dawn_native/d3d12/BackendD3D12.cpp b/src/dawn_native/d3d12/BackendD3D12.cpp
index 71beb6c..81dfdb2 100644
--- a/src/dawn_native/d3d12/BackendD3D12.cpp
+++ b/src/dawn_native/d3d12/BackendD3D12.cpp
@@ -70,7 +70,8 @@
} // anonymous namespace
- Backend::Backend(InstanceBase* instance) : BackendConnection(instance, BackendType::D3D12) {
+ Backend::Backend(InstanceBase* instance)
+ : BackendConnection(instance, wgpu::BackendType::D3D12) {
}
MaybeError Backend::Initialize() {
diff --git a/src/dawn_native/d3d12/DeviceD3D12.h b/src/dawn_native/d3d12/DeviceD3D12.h
index a29adc9..35e5bd8 100644
--- a/src/dawn_native/d3d12/DeviceD3D12.h
+++ b/src/dawn_native/d3d12/DeviceD3D12.h
@@ -154,8 +154,6 @@
std::unique_ptr<DescriptorHeapAllocator> mDescriptorHeapAllocator;
std::unique_ptr<MapRequestTracker> mMapRequestTracker;
std::unique_ptr<ResourceAllocatorManager> mResourceAllocatorManager;
-
- dawn_native::PCIInfo mPCIInfo;
};
}} // namespace dawn_native::d3d12
diff --git a/src/dawn_native/metal/BackendMTL.mm b/src/dawn_native/metal/BackendMTL.mm
index f2ef973..7c626987 100644
--- a/src/dawn_native/metal/BackendMTL.mm
+++ b/src/dawn_native/metal/BackendMTL.mm
@@ -176,7 +176,7 @@
class Adapter : public AdapterBase {
public:
Adapter(InstanceBase* instance, id<MTLDevice> device)
- : AdapterBase(instance, BackendType::Metal), mDevice([device retain]) {
+ : AdapterBase(instance, wgpu::BackendType::Metal), mDevice([device retain]) {
mPCIInfo.name = std::string([mDevice.name UTF8String]);
PCIIDs ids;
@@ -186,12 +186,12 @@
};
#if defined(DAWN_PLATFORM_IOS)
- mDeviceType = DeviceType::IntegratedGPU;
+ mAdapterType = wgpu::AdapterType::IntegratedGPU;
#elif defined(DAWN_PLATFORM_MACOS)
if ([device isLowPower]) {
- mDeviceType = DeviceType::IntegratedGPU;
+ mAdapterType = wgpu::AdapterType::IntegratedGPU;
} else {
- mDeviceType = DeviceType::DiscreteGPU;
+ mAdapterType = wgpu::AdapterType::DiscreteGPU;
}
#else
# error "Unsupported Apple platform."
@@ -221,7 +221,8 @@
// Implementation of the Metal backend's BackendConnection
- Backend::Backend(InstanceBase* instance) : BackendConnection(instance, BackendType::Metal) {
+ Backend::Backend(InstanceBase* instance)
+ : BackendConnection(instance, wgpu::BackendType::Metal) {
if (GetInstance()->IsBackendValidationEnabled()) {
setenv("METAL_DEVICE_WRAPPER_TYPE", "1", 1);
}
diff --git a/src/dawn_native/null/DeviceNull.cpp b/src/dawn_native/null/DeviceNull.cpp
index d721751..fd7ef2e 100644
--- a/src/dawn_native/null/DeviceNull.cpp
+++ b/src/dawn_native/null/DeviceNull.cpp
@@ -26,9 +26,9 @@
// Implementation of pre-Device objects: the null adapter, null backend connection and Connect()
- Adapter::Adapter(InstanceBase* instance) : AdapterBase(instance, BackendType::Null) {
+ Adapter::Adapter(InstanceBase* instance) : AdapterBase(instance, wgpu::BackendType::Null) {
mPCIInfo.name = "Null backend";
- mDeviceType = DeviceType::CPU;
+ mAdapterType = wgpu::AdapterType::CPU;
// Enable all extensions by default for the convenience of tests.
mSupportedExtensions.extensionsBitSet.flip();
@@ -47,7 +47,7 @@
class Backend : public BackendConnection {
public:
- Backend(InstanceBase* instance) : BackendConnection(instance, BackendType::Null) {
+ Backend(InstanceBase* instance) : BackendConnection(instance, wgpu::BackendType::Null) {
}
std::vector<std::unique_ptr<AdapterBase>> DiscoverDefaultAdapters() override {
diff --git a/src/dawn_native/opengl/BackendGL.cpp b/src/dawn_native/opengl/BackendGL.cpp
index cfdfb46..7116d8e 100644
--- a/src/dawn_native/opengl/BackendGL.cpp
+++ b/src/dawn_native/opengl/BackendGL.cpp
@@ -119,7 +119,7 @@
class Adapter : public AdapterBase {
public:
- Adapter(InstanceBase* instance) : AdapterBase(instance, BackendType::OpenGL) {
+ Adapter(InstanceBase* instance) : AdapterBase(instance, wgpu::BackendType::OpenGL) {
}
MaybeError Initialize(const AdapterDiscoveryOptions* options) {
@@ -225,7 +225,8 @@
// Implementation of the OpenGL backend's BackendConnection
- Backend::Backend(InstanceBase* instance) : BackendConnection(instance, BackendType::OpenGL) {
+ Backend::Backend(InstanceBase* instance)
+ : BackendConnection(instance, wgpu::BackendType::OpenGL) {
}
std::vector<std::unique_ptr<AdapterBase>> Backend::DiscoverDefaultAdapters() {
@@ -241,7 +242,7 @@
return DAWN_VALIDATION_ERROR("The OpenGL backend can only create a single adapter");
}
- ASSERT(optionsBase->backendType == BackendType::OpenGL);
+ ASSERT(optionsBase->backendType == WGPUBackendType_OpenGL);
const AdapterDiscoveryOptions* options =
static_cast<const AdapterDiscoveryOptions*>(optionsBase);
diff --git a/src/dawn_native/opengl/OpenGLBackend.cpp b/src/dawn_native/opengl/OpenGLBackend.cpp
index fbab415..34513f5 100644
--- a/src/dawn_native/opengl/OpenGLBackend.cpp
+++ b/src/dawn_native/opengl/OpenGLBackend.cpp
@@ -24,7 +24,7 @@
namespace dawn_native { namespace opengl {
AdapterDiscoveryOptions::AdapterDiscoveryOptions()
- : AdapterDiscoveryOptionsBase(BackendType::OpenGL) {
+ : AdapterDiscoveryOptionsBase(WGPUBackendType_OpenGL) {
}
DawnSwapChainImplementation CreateNativeSwapChainImpl(WGPUDevice device,
diff --git a/src/dawn_native/vulkan/AdapterVk.cpp b/src/dawn_native/vulkan/AdapterVk.cpp
index dd9341f..004ba23 100644
--- a/src/dawn_native/vulkan/AdapterVk.cpp
+++ b/src/dawn_native/vulkan/AdapterVk.cpp
@@ -20,7 +20,7 @@
namespace dawn_native { namespace vulkan {
Adapter::Adapter(Backend* backend, VkPhysicalDevice physicalDevice)
- : AdapterBase(backend->GetInstance(), BackendType::Vulkan),
+ : AdapterBase(backend->GetInstance(), wgpu::BackendType::Vulkan),
mPhysicalDevice(physicalDevice),
mBackend(backend) {
}
@@ -54,16 +54,16 @@
switch (mDeviceInfo.properties.deviceType) {
case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU:
- mDeviceType = DeviceType::IntegratedGPU;
+ mAdapterType = wgpu::AdapterType::IntegratedGPU;
break;
case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
- mDeviceType = DeviceType::DiscreteGPU;
+ mAdapterType = wgpu::AdapterType::DiscreteGPU;
break;
case VK_PHYSICAL_DEVICE_TYPE_CPU:
- mDeviceType = DeviceType::CPU;
+ mAdapterType = wgpu::AdapterType::CPU;
break;
default:
- mDeviceType = DeviceType::Unknown;
+ mAdapterType = wgpu::AdapterType::Unknown;
break;
}
diff --git a/src/dawn_native/vulkan/BackendVk.cpp b/src/dawn_native/vulkan/BackendVk.cpp
index 924753c..e1ef3d2 100644
--- a/src/dawn_native/vulkan/BackendVk.cpp
+++ b/src/dawn_native/vulkan/BackendVk.cpp
@@ -37,7 +37,8 @@
namespace dawn_native { namespace vulkan {
- Backend::Backend(InstanceBase* instance) : BackendConnection(instance, BackendType::Vulkan) {
+ Backend::Backend(InstanceBase* instance)
+ : BackendConnection(instance, wgpu::BackendType::Vulkan) {
}
Backend::~Backend() {
diff --git a/src/fuzzers/DawnWireServerAndFrontendFuzzer.cpp b/src/fuzzers/DawnWireServerAndFrontendFuzzer.cpp
index 0126028..fe73675 100644
--- a/src/fuzzers/DawnWireServerAndFrontendFuzzer.cpp
+++ b/src/fuzzers/DawnWireServerAndFrontendFuzzer.cpp
@@ -29,7 +29,10 @@
wgpu::Device nullDevice;
for (dawn_native::Adapter adapter : adapters) {
- if (adapter.GetBackendType() == dawn_native::BackendType::Null) {
+ wgpu::AdapterProperties properties;
+ adapter.GetProperties(&properties);
+
+ if (properties.backendType == wgpu::BackendType::Null) {
nullDevice = wgpu::Device::Acquire(adapter.CreateDevice());
break;
}
diff --git a/src/fuzzers/DawnWireServerAndVulkanBackendFuzzer.cpp b/src/fuzzers/DawnWireServerAndVulkanBackendFuzzer.cpp
index 784a8ce..54fc8cd 100644
--- a/src/fuzzers/DawnWireServerAndVulkanBackendFuzzer.cpp
+++ b/src/fuzzers/DawnWireServerAndVulkanBackendFuzzer.cpp
@@ -28,8 +28,11 @@
wgpu::Device device;
for (dawn_native::Adapter adapter : adapters) {
- if (adapter.GetBackendType() == dawn_native::BackendType::Vulkan &&
- adapter.GetDeviceType() == dawn_native::DeviceType::CPU) {
+ wgpu::AdapterProperties properties;
+ adapter.GetProperties(&properties);
+
+ if (properties.backendType == wgpu::BackendType::Vulkan &&
+ properties.adapterType == wgpu::AdapterType::CPU) {
device = wgpu::Device::Acquire(adapter.CreateDevice());
break;
}
diff --git a/src/include/dawn_native/DawnNative.h b/src/include/dawn_native/DawnNative.h
index 17ed5e3..0230cca 100644
--- a/src/include/dawn_native/DawnNative.h
+++ b/src/include/dawn_native/DawnNative.h
@@ -26,14 +26,20 @@
class Platform;
} // namespace dawn_platform
+namespace wgpu {
+ struct AdapterProperties;
+}
+
namespace dawn_native {
+ // DEPRECATED: use WGPUAdapterProperties instead.
struct PCIInfo {
uint32_t deviceId = 0;
uint32_t vendorId = 0;
std::string name;
};
+ // DEPRECATED: use WGPUBackendType instead.
enum class BackendType {
D3D12,
Metal,
@@ -42,6 +48,7 @@
Vulkan,
};
+ // DEPRECATED: use WGPUAdapterType instead.
enum class DeviceType {
DiscreteGPU,
IntegratedGPU,
@@ -86,9 +93,15 @@
Adapter(AdapterBase* impl);
~Adapter();
+ // DEPRECATED: use GetProperties instead.
BackendType GetBackendType() const;
DeviceType GetDeviceType() const;
const PCIInfo& GetPCIInfo() const;
+
+ // Essentially webgpu.h's wgpuAdapterGetProperties while we don't have WGPUAdapter in
+ // dawn.json
+ void GetProperties(wgpu::AdapterProperties* properties) const;
+
std::vector<const char*> GetSupportedExtensions() const;
WGPUDeviceProperties GetAdapterProperties() const;
@@ -106,10 +119,10 @@
// Base class for options passed to Instance::DiscoverAdapters.
struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptionsBase {
public:
- const BackendType backendType;
+ const WGPUBackendType backendType;
protected:
- AdapterDiscoveryOptionsBase(BackendType type);
+ AdapterDiscoveryOptionsBase(WGPUBackendType type);
};
// Represents a connection to dawn_native and is used for dependency injection, discovering
diff --git a/src/tests/DawnTest.cpp b/src/tests/DawnTest.cpp
index ba7285d..da7e575 100644
--- a/src/tests/DawnTest.cpp
+++ b/src/tests/DawnTest.cpp
@@ -41,32 +41,32 @@
namespace {
- std::string ParamName(dawn_native::BackendType type) {
+ std::string ParamName(wgpu::BackendType type) {
switch (type) {
- case dawn_native::BackendType::D3D12:
+ case wgpu::BackendType::D3D12:
return "D3D12";
- case dawn_native::BackendType::Metal:
+ case wgpu::BackendType::Metal:
return "Metal";
- case dawn_native::BackendType::Null:
+ case wgpu::BackendType::Null:
return "Null";
- case dawn_native::BackendType::OpenGL:
+ case wgpu::BackendType::OpenGL:
return "OpenGL";
- case dawn_native::BackendType::Vulkan:
+ case wgpu::BackendType::Vulkan:
return "Vulkan";
default:
UNREACHABLE();
}
}
- const char* DeviceTypeName(dawn_native::DeviceType type) {
+ const char* AdapterTypeName(wgpu::AdapterType type) {
switch (type) {
- case dawn_native::DeviceType::DiscreteGPU:
+ case wgpu::AdapterType::DiscreteGPU:
return "Discrete GPU";
- case dawn_native::DeviceType::IntegratedGPU:
+ case wgpu::AdapterType::IntegratedGPU:
return "Integrated GPU";
- case dawn_native::DeviceType::CPU:
+ case wgpu::AdapterType::CPU:
return "CPU";
- case dawn_native::DeviceType::Unknown:
+ case wgpu::AdapterType::Unknown:
return "Unknown";
default:
UNREACHABLE();
@@ -90,10 +90,10 @@
const RGBA8 RGBA8::kYellow = RGBA8(255, 255, 0, 255);
const RGBA8 RGBA8::kWhite = RGBA8(255, 255, 255, 255);
-const DawnTestParam D3D12Backend(dawn_native::BackendType::D3D12);
-const DawnTestParam MetalBackend(dawn_native::BackendType::Metal);
-const DawnTestParam OpenGLBackend(dawn_native::BackendType::OpenGL);
-const DawnTestParam VulkanBackend(dawn_native::BackendType::Vulkan);
+const DawnTestParam D3D12Backend(wgpu::BackendType::D3D12);
+const DawnTestParam MetalBackend(wgpu::BackendType::Metal);
+const DawnTestParam OpenGLBackend(wgpu::BackendType::OpenGL);
+const DawnTestParam VulkanBackend(wgpu::BackendType::Vulkan);
DawnTestParam ForceToggles(const DawnTestParam& originParam,
std::initializer_list<const char*> forceEnabledWorkarounds,
@@ -224,24 +224,26 @@
"\n"
<< "System adapters: \n";
for (const dawn_native::Adapter& adapter : mInstance->GetAdapters()) {
- const dawn_native::PCIInfo& pci = adapter.GetPCIInfo();
+ wgpu::AdapterProperties properties;
+ adapter.GetProperties(&properties);
std::ostringstream vendorId;
std::ostringstream deviceId;
vendorId << std::setfill('0') << std::uppercase << std::internal << std::hex << std::setw(4)
- << pci.vendorId;
+ << properties.vendorID;
deviceId << std::setfill('0') << std::uppercase << std::internal << std::hex << std::setw(4)
- << pci.deviceId;
+ << properties.deviceID;
// Preparing for outputting hex numbers
dawn::InfoLog() << std::showbase << std::hex << std::setfill('0') << std::setw(4)
- << " - \"" << pci.name << "\"\n"
- << " type: " << DeviceTypeName(adapter.GetDeviceType())
- << ", backend: " << ParamName(adapter.GetBackendType()) << "\n"
+ << " - \"" << properties.name << "\"\n"
+ << " type: " << AdapterTypeName(properties.adapterType)
+ << ", backend: " << ParamName(properties.backendType) << "\n"
<< " vendorId: 0x" << vendorId.str() << ", deviceId: 0x" << deviceId.str()
- << (mHasVendorIdFilter && mVendorIdFilter == pci.vendorId ? " [Selected]"
- : "")
+ << (mHasVendorIdFilter && mVendorIdFilter == properties.vendorID
+ ? " [Selected]"
+ : "")
<< "\n";
}
}
@@ -346,43 +348,43 @@
}
bool DawnTestBase::IsD3D12() const {
- return mParam.backendType == dawn_native::BackendType::D3D12;
+ return mParam.backendType == wgpu::BackendType::D3D12;
}
bool DawnTestBase::IsMetal() const {
- return mParam.backendType == dawn_native::BackendType::Metal;
+ return mParam.backendType == wgpu::BackendType::Metal;
}
bool DawnTestBase::IsOpenGL() const {
- return mParam.backendType == dawn_native::BackendType::OpenGL;
+ return mParam.backendType == wgpu::BackendType::OpenGL;
}
bool DawnTestBase::IsVulkan() const {
- return mParam.backendType == dawn_native::BackendType::Vulkan;
+ return mParam.backendType == wgpu::BackendType::Vulkan;
}
bool DawnTestBase::IsAMD() const {
- return gpu_info::IsAMD(mPCIInfo.vendorId);
+ return gpu_info::IsAMD(mAdapterProperties.vendorID);
}
bool DawnTestBase::IsARM() const {
- return gpu_info::IsARM(mPCIInfo.vendorId);
+ return gpu_info::IsARM(mAdapterProperties.vendorID);
}
bool DawnTestBase::IsImgTec() const {
- return gpu_info::IsImgTec(mPCIInfo.vendorId);
+ return gpu_info::IsImgTec(mAdapterProperties.vendorID);
}
bool DawnTestBase::IsIntel() const {
- return gpu_info::IsIntel(mPCIInfo.vendorId);
+ return gpu_info::IsIntel(mAdapterProperties.vendorID);
}
bool DawnTestBase::IsNvidia() const {
- return gpu_info::IsNvidia(mPCIInfo.vendorId);
+ return gpu_info::IsNvidia(mAdapterProperties.vendorID);
}
bool DawnTestBase::IsQualcomm() const {
- return gpu_info::IsQualcomm(mPCIInfo.vendorId);
+ return gpu_info::IsQualcomm(mAdapterProperties.vendorID);
}
bool DawnTestBase::IsWindows() const {
@@ -437,6 +439,10 @@
return {};
}
+const wgpu::AdapterProperties& DawnTestBase::GetAdapterProperties() const {
+ return mAdapterProperties;
+}
+
// This function can only be called after SetUp() because it requires mBackendAdapter to be
// initialized.
bool DawnTestBase::SupportsExtensions(const std::vector<const char*>& extensions) {
@@ -458,20 +464,23 @@
void DawnTestBase::SetUp() {
// Initialize mBackendAdapter, and create the device.
- const dawn_native::BackendType backendType = mParam.backendType;
+ const wgpu::BackendType backendType = mParam.backendType;
{
dawn_native::Instance* instance = gTestEnv->GetInstance();
std::vector<dawn_native::Adapter> adapters = instance->GetAdapters();
for (const dawn_native::Adapter& adapter : adapters) {
- if (adapter.GetBackendType() == backendType) {
- if (adapter.GetDeviceType() == dawn_native::DeviceType::CPU) {
+ wgpu::AdapterProperties properties;
+ adapter.GetProperties(&properties);
+
+ if (properties.backendType == backendType) {
+ if (properties.adapterType == wgpu::AdapterType::CPU) {
continue;
}
// Filter adapter by vendor id
if (HasVendorIdFilter()) {
- if (adapter.GetPCIInfo().vendorId == GetVendorIdFilter()) {
+ if (properties.vendorID == GetVendorIdFilter()) {
mBackendAdapter = adapter;
break;
}
@@ -480,7 +489,8 @@
// Prefer discrete GPU on multi-GPU systems, otherwise get integrated GPU.
mBackendAdapter = adapter;
- if (mBackendAdapter.GetDeviceType() == dawn_native::DeviceType::DiscreteGPU) {
+ mAdapterProperties = properties;
+ if (properties.adapterType == wgpu::AdapterType::DiscreteGPU) {
break;
}
}
@@ -491,8 +501,6 @@
}
}
- mPCIInfo = mBackendAdapter.GetPCIInfo();
-
for (const char* forceEnabledWorkaround : mParam.forceEnabledWorkarounds) {
ASSERT(gTestEnv->GetInstance()->GetToggleInfo(forceEnabledWorkaround) != nullptr);
}
@@ -600,10 +608,6 @@
return mError;
}
-dawn_native::PCIInfo DawnTestBase::GetPCIInfo() const {
- return mPCIInfo;
-}
-
// static
void DawnTestBase::OnDeviceError(WGPUErrorType type, const char* message, void* userdata) {
ASSERT(type != WGPUErrorType_NoError);
@@ -813,19 +817,19 @@
}
namespace detail {
- bool IsBackendAvailable(dawn_native::BackendType type) {
+ bool IsBackendAvailable(wgpu::BackendType type) {
switch (type) {
#if defined(DAWN_ENABLE_BACKEND_D3D12)
- case dawn_native::BackendType::D3D12:
+ case wgpu::BackendType::D3D12:
#endif
#if defined(DAWN_ENABLE_BACKEND_METAL)
- case dawn_native::BackendType::Metal:
+ case wgpu::BackendType::Metal:
#endif
#if defined(DAWN_ENABLE_BACKEND_OPENGL)
- case dawn_native::BackendType::OpenGL:
+ case wgpu::BackendType::OpenGL:
#endif
#if defined(DAWN_ENABLE_BACKEND_VULKAN)
- case dawn_native::BackendType::Vulkan:
+ case wgpu::BackendType::Vulkan:
#endif
return true;
diff --git a/src/tests/DawnTest.h b/src/tests/DawnTest.h
index d7e88a6..fb8825d 100644
--- a/src/tests/DawnTest.h
+++ b/src/tests/DawnTest.h
@@ -87,10 +87,10 @@
std::ostream& operator<<(std::ostream& stream, const RGBA8& color);
struct DawnTestParam {
- explicit DawnTestParam(dawn_native::BackendType backendType) : backendType(backendType) {
+ explicit DawnTestParam(wgpu::BackendType backendType) : backendType(backendType) {
}
- dawn_native::BackendType backendType;
+ wgpu::BackendType backendType;
std::vector<const char*> forceEnabledWorkarounds;
std::vector<const char*> forceDisabledWorkarounds;
@@ -196,8 +196,6 @@
bool HasVendorIdFilter() const;
uint32_t GetVendorIdFilter() const;
- dawn_native::PCIInfo GetPCIInfo() const;
-
protected:
wgpu::Device device;
wgpu::Queue queue;
@@ -236,6 +234,8 @@
// code path to handle the situation when not all extensions are supported.
virtual std::vector<const char*> GetRequiredExtensions();
+ const wgpu::AdapterProperties& GetAdapterProperties() const;
+
private:
DawnTestParam mParam;
@@ -294,9 +294,8 @@
// Assuming the data is mapped, checks all expectations
void ResolveExpectations();
- dawn_native::PCIInfo mPCIInfo;
-
dawn_native::Adapter mBackendAdapter;
+ wgpu::AdapterProperties mAdapterProperties;
};
// Skip a test when the given condition is satisfied.
@@ -350,7 +349,7 @@
namespace detail {
// Helper functions used for DAWN_INSTANTIATE_TEST
- bool IsBackendAvailable(dawn_native::BackendType type);
+ bool IsBackendAvailable(wgpu::BackendType type);
std::vector<DawnTestParam> FilterBackends(const DawnTestParam* params, size_t numParams);
// All classes used to implement the deferred expectations should inherit from this.
diff --git a/src/tests/end2end/BasicTests.cpp b/src/tests/end2end/BasicTests.cpp
index 77861c3..ec223ea 100644
--- a/src/tests/end2end/BasicTests.cpp
+++ b/src/tests/end2end/BasicTests.cpp
@@ -23,7 +23,7 @@
TEST_P(BasicTests, VendorIdFilter) {
DAWN_SKIP_TEST_IF(!HasVendorIdFilter());
- ASSERT_EQ(GetPCIInfo().vendorId, GetVendorIdFilter());
+ ASSERT_EQ(GetAdapterProperties().vendorID, GetVendorIdFilter());
}
// Test Buffer::SetSubData changes the content of the buffer, but really this is the most
diff --git a/src/tests/unittests/validation/ValidationTest.cpp b/src/tests/unittests/validation/ValidationTest.cpp
index 957a859..40aec15 100644
--- a/src/tests/unittests/validation/ValidationTest.cpp
+++ b/src/tests/unittests/validation/ValidationTest.cpp
@@ -28,7 +28,10 @@
// Validation tests run against the null backend, find the corresponding adapter
bool foundNullAdapter = false;
for (auto ¤tAdapter : adapters) {
- if (currentAdapter.GetBackendType() == dawn_native::BackendType::Null) {
+ wgpu::AdapterProperties adapterProperties;
+ currentAdapter.GetProperties(&adapterProperties);
+
+ if (adapterProperties.backendType == wgpu::BackendType::Null) {
adapter = currentAdapter;
foundNullAdapter = true;
break;
diff --git a/src/utils/BackendBinding.cpp b/src/utils/BackendBinding.cpp
index 54aa607..0e4fff3 100644
--- a/src/utils/BackendBinding.cpp
+++ b/src/utils/BackendBinding.cpp
@@ -44,8 +44,8 @@
: mWindow(window), mDevice(device) {
}
- void SetupGLFWWindowHintsForBackend(dawn_native::BackendType type) {
- if (type == dawn_native::BackendType::OpenGL) {
+ void SetupGLFWWindowHintsForBackend(wgpu::BackendType type) {
+ if (type == wgpu::BackendType::OpenGL) {
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 4);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
@@ -57,11 +57,11 @@
void DiscoverAdapter(dawn_native::Instance* instance,
GLFWwindow* window,
- dawn_native::BackendType type) {
+ wgpu::BackendType type) {
DAWN_UNUSED(type);
DAWN_UNUSED(window);
- if (type == dawn_native::BackendType::OpenGL) {
+ if (type == wgpu::BackendType::OpenGL) {
#if defined(DAWN_ENABLE_BACKEND_OPENGL)
glfwMakeContextCurrent(window);
dawn_native::opengl::AdapterDiscoveryOptions adapterOptions;
@@ -73,32 +73,30 @@
}
}
- BackendBinding* CreateBinding(dawn_native::BackendType type,
- GLFWwindow* window,
- WGPUDevice device) {
+ BackendBinding* CreateBinding(wgpu::BackendType type, GLFWwindow* window, WGPUDevice device) {
switch (type) {
#if defined(DAWN_ENABLE_BACKEND_D3D12)
- case dawn_native::BackendType::D3D12:
+ case wgpu::BackendType::D3D12:
return CreateD3D12Binding(window, device);
#endif
#if defined(DAWN_ENABLE_BACKEND_METAL)
- case dawn_native::BackendType::Metal:
+ case wgpu::BackendType::Metal:
return CreateMetalBinding(window, device);
#endif
#if defined(DAWN_ENABLE_BACKEND_NULL)
- case dawn_native::BackendType::Null:
+ case wgpu::BackendType::Null:
return CreateNullBinding(window, device);
#endif
#if defined(DAWN_ENABLE_BACKEND_OPENGL)
- case dawn_native::BackendType::OpenGL:
+ case wgpu::BackendType::OpenGL:
return CreateOpenGLBinding(window, device);
#endif
#if defined(DAWN_ENABLE_BACKEND_VULKAN)
- case dawn_native::BackendType::Vulkan:
+ case wgpu::BackendType::Vulkan:
return CreateVulkanBinding(window, device);
#endif
diff --git a/src/utils/BackendBinding.h b/src/utils/BackendBinding.h
index f8d35b0..26d749a 100644
--- a/src/utils/BackendBinding.h
+++ b/src/utils/BackendBinding.h
@@ -15,7 +15,7 @@
#ifndef UTILS_BACKENDBINDING_H_
#define UTILS_BACKENDBINDING_H_
-#include "dawn/webgpu.h"
+#include "dawn/webgpu_cpp.h"
#include "dawn_native/DawnNative.h"
struct GLFWwindow;
@@ -36,13 +36,11 @@
WGPUDevice mDevice = nullptr;
};
- void SetupGLFWWindowHintsForBackend(dawn_native::BackendType type);
+ void SetupGLFWWindowHintsForBackend(wgpu::BackendType type);
void DiscoverAdapter(dawn_native::Instance* instance,
GLFWwindow* window,
- dawn_native::BackendType type);
- BackendBinding* CreateBinding(dawn_native::BackendType type,
- GLFWwindow* window,
- WGPUDevice device);
+ wgpu::BackendType type);
+ BackendBinding* CreateBinding(wgpu::BackendType type, GLFWwindow* window, WGPUDevice device);
} // namespace utils