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>
This commit is contained in:
Corentin Wallez 2020-01-10 13:28:18 +00:00 committed by Commit Bot service account
parent 5fc2c82c11
commit f12c9dba6d
27 changed files with 237 additions and 143 deletions

View File

@ -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"
},

View File

@ -65,13 +65,13 @@ enum class CmdBufType {
// 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 @@ wgpu::Device CreateCppDawnDevice() {
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 @@ bool InitSample(int argc, const char** argv) {
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");

View File

@ -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 {

View File

@ -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 @@ namespace dawn_native {
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 @@ namespace dawn_native {
protected:
PCIInfo mPCIInfo = {};
DeviceType mDeviceType = DeviceType::Unknown;
wgpu::AdapterType mAdapterType = wgpu::AdapterType::Unknown;
ExtensionsSet mSupportedExtensions;
private:
@ -52,7 +55,7 @@ namespace dawn_native {
MaybeError CreateDeviceInternal(DeviceBase** result, const DeviceDescriptor* descriptor);
InstanceBase* mInstance = nullptr;
BackendType mBackend;
wgpu::BackendType mBackend;
};
} // namespace dawn_native

View File

@ -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;
}

View File

@ -26,10 +26,10 @@ namespace dawn_native {
// 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 @@ namespace dawn_native {
private:
InstanceBase* mInstance = nullptr;
BackendType mType;
wgpu::BackendType mType;
};
} // namespace dawn_native

View File

@ -44,12 +44,44 @@ namespace dawn_native {
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 @@ namespace dawn_native {
// AdapterDiscoverOptionsBase
AdapterDiscoveryOptionsBase::AdapterDiscoveryOptionsBase(BackendType type) : backendType(type) {
AdapterDiscoveryOptionsBase::AdapterDiscoveryOptionsBase(WGPUBackendType type)
: backendType(type) {
}
// Instance

View File

@ -120,7 +120,7 @@ namespace dawn_native {
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 @@ namespace dawn_native {
};
#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 @@ namespace dawn_native {
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));

View File

@ -77,7 +77,7 @@ namespace dawn_native {
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);

View File

@ -35,7 +35,7 @@ namespace dawn_native { namespace d3d12 {
};
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 @@ namespace dawn_native { namespace d3d12 {
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(

View File

@ -70,7 +70,8 @@ namespace dawn_native { namespace d3d12 {
} // anonymous namespace
Backend::Backend(InstanceBase* instance) : BackendConnection(instance, BackendType::D3D12) {
Backend::Backend(InstanceBase* instance)
: BackendConnection(instance, wgpu::BackendType::D3D12) {
}
MaybeError Backend::Initialize() {

View File

@ -154,8 +154,6 @@ namespace dawn_native { namespace d3d12 {
std::unique_ptr<DescriptorHeapAllocator> mDescriptorHeapAllocator;
std::unique_ptr<MapRequestTracker> mMapRequestTracker;
std::unique_ptr<ResourceAllocatorManager> mResourceAllocatorManager;
dawn_native::PCIInfo mPCIInfo;
};
}} // namespace dawn_native::d3d12

View File

@ -176,7 +176,7 @@ namespace dawn_native { namespace metal {
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 @@ namespace dawn_native { namespace metal {
};
#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 @@ namespace dawn_native { namespace metal {
// 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);
}

View File

@ -26,9 +26,9 @@ namespace dawn_native { namespace null {
// 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 @@ namespace dawn_native { namespace null {
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 {

View File

@ -119,7 +119,7 @@ namespace dawn_native { namespace opengl {
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 @@ namespace dawn_native { namespace opengl {
// 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 @@ namespace dawn_native { namespace opengl {
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);

View File

@ -24,7 +24,7 @@
namespace dawn_native { namespace opengl {
AdapterDiscoveryOptions::AdapterDiscoveryOptions()
: AdapterDiscoveryOptionsBase(BackendType::OpenGL) {
: AdapterDiscoveryOptionsBase(WGPUBackendType_OpenGL) {
}
DawnSwapChainImplementation CreateNativeSwapChainImpl(WGPUDevice device,

View File

@ -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 @@ namespace dawn_native { namespace vulkan {
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;
}

View File

@ -37,7 +37,8 @@ const char kVulkanLibName[] = "libvulkan.so";
namespace dawn_native { namespace vulkan {
Backend::Backend(InstanceBase* instance) : BackendConnection(instance, BackendType::Vulkan) {
Backend::Backend(InstanceBase* instance)
: BackendConnection(instance, wgpu::BackendType::Vulkan) {
}
Backend::~Backend() {

View File

@ -29,7 +29,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
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;
}

View File

@ -28,8 +28,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
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;
}

View File

@ -26,14 +26,20 @@ namespace dawn_platform {
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 @@ namespace dawn_native {
Vulkan,
};
// DEPRECATED: use WGPUAdapterType instead.
enum class DeviceType {
DiscreteGPU,
IntegratedGPU,
@ -86,9 +93,15 @@ namespace dawn_native {
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 @@ namespace dawn_native {
// 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

View File

@ -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::kBlue = RGBA8(0, 0, 255, 255);
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 @@ void DawnTestEnvironment::SetUp() {
"\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 @@ DawnTestBase::~DawnTestBase() {
}
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 @@ std::vector<const char*> DawnTestBase::GetRequiredExtensions() {
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 @@ bool DawnTestBase::SupportsExtensions(const std::vector<const char*>& extensions
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 @@ void DawnTestBase::SetUp() {
// 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 @@ void DawnTestBase::SetUp() {
}
}
mPCIInfo = mBackendAdapter.GetPCIInfo();
for (const char* forceEnabledWorkaround : mParam.forceEnabledWorkarounds) {
ASSERT(gTestEnv->GetInstance()->GetToggleInfo(forceEnabledWorkaround) != nullptr);
}
@ -600,10 +608,6 @@ bool DawnTestBase::EndExpectDeviceError() {
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 @@ std::ostream& operator<<(std::ostream& stream, const RGBA8& color) {
}
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;

View File

@ -87,10 +87,10 @@ struct RGBA8 {
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 @@ class DawnTestBase {
bool HasVendorIdFilter() const;
uint32_t GetVendorIdFilter() const;
dawn_native::PCIInfo GetPCIInfo() const;
protected:
wgpu::Device device;
wgpu::Queue queue;
@ -236,6 +234,8 @@ class DawnTestBase {
// 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 @@ class DawnTestBase {
// 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 @@ using DawnTest = DawnTestWithParams<>;
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.

View File

@ -23,7 +23,7 @@ class BasicTests : public DawnTest {
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

View File

@ -28,7 +28,10 @@ ValidationTest::ValidationTest() {
// Validation tests run against the null backend, find the corresponding adapter
bool foundNullAdapter = false;
for (auto &currentAdapter : 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;

View File

@ -44,8 +44,8 @@ namespace utils {
: 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 @@ namespace utils {
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 @@ namespace utils {
}
}
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

View File

@ -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 @@ namespace utils {
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