Implement upstream RequestDevice, add native-only CreateDevice

This CL implements RequestDevice and also has changes for
Dawn to internally use wgpu::FeatureName enums, instead of
strings. Some of the string handling is kept for now to
support the deprecated creation path. GetFeatureInfo is added
to the instance to get a name and description of the feature,
for reporting in about://gpu.

Dawn device toggles are now passed in an extension struct off
of the device descriptor. This is only supported in dawn_native,
and not dawn_wire, for now, since dawn_wire doesn't have a way
to serialize lists of null-terminated const char*.

To enable the client to check whether the toggle descriptor is
supported, a `dawn-native` feature is added which is supported
all the time with dawn_native, but not supported with dawn_wire.

Feature `dawn-native` also enables a synchronous version of
CreateDevice for convenience.

Bug: dawn:160
Change-Id: Ifc195e7ea808c6c319021528ef4b36bd65583bff
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/72020
Reviewed-by: Loko Kung <lokokung@google.com>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
Austin Eng
2021-12-22 19:02:23 +00:00
committed by Dawn LUCI CQ
parent 59c84575f7
commit 2f218e2b21
41 changed files with 472 additions and 223 deletions

View File

@@ -26,10 +26,10 @@ class FeatureTests : public testing::Test {
mAdapterBase(mInstanceBase.Get()) {
}
std::vector<const char*> GetAllFeatureNames() {
std::vector<const char*> allFeatureNames(kTotalFeaturesCount);
std::vector<wgpu::FeatureName> GetAllFeatureNames() {
std::vector<wgpu::FeatureName> allFeatureNames(kTotalFeaturesCount);
for (size_t i = 0; i < kTotalFeaturesCount; ++i) {
allFeatureNames[i] = FeatureEnumToName(static_cast<dawn_native::Feature>(i));
allFeatureNames[i] = FeatureEnumToAPIFeature(static_cast<dawn_native::Feature>(i));
}
return allFeatureNames;
}
@@ -45,20 +45,23 @@ class FeatureTests : public testing::Test {
// Test the creation of a device will fail if the requested feature is not supported on the
// Adapter.
TEST_F(FeatureTests, AdapterWithRequiredFeatureDisabled) {
const std::vector<const char*> kAllFeatureNames = GetAllFeatureNames();
const std::vector<wgpu::FeatureName> kAllFeatureNames = GetAllFeatureNames();
for (size_t i = 0; i < kTotalFeaturesCount; ++i) {
dawn_native::Feature notSupportedFeature = static_cast<dawn_native::Feature>(i);
std::vector<const char*> featureNamesWithoutOne = kAllFeatureNames;
std::vector<wgpu::FeatureName> featureNamesWithoutOne = kAllFeatureNames;
featureNamesWithoutOne.erase(featureNamesWithoutOne.begin() + i);
mAdapterBase.SetSupportedFeatures(featureNamesWithoutOne);
dawn_native::Adapter adapterWithoutFeature(&mAdapterBase);
dawn_native::DawnDeviceDescriptor deviceDescriptor;
const char* featureName = FeatureEnumToName(notSupportedFeature);
deviceDescriptor.requiredFeatures = std::vector<const char*>(1, featureName);
WGPUDevice deviceWithFeature = adapterWithoutFeature.CreateDevice(&deviceDescriptor);
wgpu::DeviceDescriptor deviceDescriptor;
wgpu::FeatureName featureName = FeatureEnumToAPIFeature(notSupportedFeature);
deviceDescriptor.requiredFeatures = &featureName;
deviceDescriptor.requiredFeaturesCount = 1;
WGPUDevice deviceWithFeature = adapterWithoutFeature.CreateDevice(
reinterpret_cast<const WGPUDeviceDescriptor*>(&deviceDescriptor));
ASSERT_EQ(nullptr, deviceWithFeature);
}
}
@@ -68,14 +71,18 @@ TEST_F(FeatureTests, GetEnabledFeatures) {
dawn_native::Adapter adapter(&mAdapterBase);
for (size_t i = 0; i < kTotalFeaturesCount; ++i) {
dawn_native::Feature feature = static_cast<dawn_native::Feature>(i);
const char* featureName = FeatureEnumToName(feature);
wgpu::FeatureName featureName = FeatureEnumToAPIFeature(feature);
dawn_native::DawnDeviceDescriptor deviceDescriptor;
deviceDescriptor.requiredFeatures = {featureName};
dawn_native::DeviceBase* deviceBase =
dawn_native::FromAPI(adapter.CreateDevice(&deviceDescriptor));
std::vector<const char*> enabledFeatures = deviceBase->GetEnabledFeatures();
ASSERT_EQ(1u, enabledFeatures.size());
ASSERT_EQ(0, std::strcmp(featureName, enabledFeatures[0]));
wgpu::DeviceDescriptor deviceDescriptor;
deviceDescriptor.requiredFeatures = &featureName;
deviceDescriptor.requiredFeaturesCount = 1;
dawn_native::DeviceBase* deviceBase = dawn_native::FromAPI(
adapter.CreateDevice(reinterpret_cast<const WGPUDeviceDescriptor*>(&deviceDescriptor)));
ASSERT_EQ(1u, deviceBase->APIEnumerateFeatures(nullptr));
wgpu::FeatureName enabledFeature;
deviceBase->APIEnumerateFeatures(&enabledFeature);
EXPECT_EQ(enabledFeature, featureName);
}
}