dawn: Refactor device creation and add shader-f16 feature

This CL modifies the way adapter creating devices, adds `shader-f16`
feature, and deprecates the `dawn-shader-float16` feature which is no
longer used.
Details:
1. Parse the toggles chained with device descriptor in
`adapter::CreateDeviceInternal`, which are then used to validate
features requirement within `CreateDeviceInternal` and passed to device
constructor as initializer.
2. When creating device, validate features requirement in
`CreateDeviceInternal` with toggles known, make sure to fail the device
creation if a required feature is not supported by adapter or is guarded
by certain toggles which were not enabled/disabled. Feature ShaderF16
and ChromiumExperimentalDp4a are validated in this way. Unittest is
added to check creating devices with toggles-guarded features required.
3. Add `shader-f16` feature, which allow `using f16;` in WGSL code.
End-to-end tests are added to test a trival f16 WGSL shader could be
used if and only if the device has `shader-f16` feature.
4. Deprecate the `dawn-shader-float16` feature, which will be completely
removed after cleaning up Blink code.

Bug: dawn:1510
Change-Id: I6cb2dcbe1ee584fdd6131c62df1ee850b881dbd2
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/100802
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Zhaoming Jiang
2022-09-08 00:11:04 +00:00
committed by Dawn LUCI CQ
parent f9eeed6106
commit 7ca82ac4d0
44 changed files with 605 additions and 333 deletions

View File

@@ -141,6 +141,11 @@ MaybeError Adapter::InitializeSupportedFeaturesImpl() {
mSupportedFeatures.EnableFeature(Feature::IndirectFirstInstance);
}
// ShaderF16
if (mFunctions.IsGLExtensionSupported("GL_AMD_gpu_shader_half_float")) {
mSupportedFeatures.EnableFeature(Feature::ShaderF16);
}
return {};
}
@@ -149,12 +154,20 @@ MaybeError Adapter::InitializeSupportedLimitsImpl(CombinedLimits* limits) {
return {};
}
ResultOrError<Ref<DeviceBase>> Adapter::CreateDeviceImpl(const DeviceDescriptor* descriptor) {
ResultOrError<Ref<DeviceBase>> Adapter::CreateDeviceImpl(
const DeviceDescriptor* descriptor,
const TripleStateTogglesSet& userProvidedToggles) {
EGLenum api =
GetBackendType() == wgpu::BackendType::OpenGL ? EGL_OPENGL_API : EGL_OPENGL_ES_API;
std::unique_ptr<Device::Context> context;
DAWN_TRY_ASSIGN(context, ContextEGL::Create(mEGLFunctions, api));
return Device::Create(this, descriptor, mFunctions, std::move(context));
return Device::Create(this, descriptor, mFunctions, std::move(context), userProvidedToggles);
}
MaybeError Adapter::ValidateFeatureSupportedWithTogglesImpl(
wgpu::FeatureName feature,
const TripleStateTogglesSet& userProvidedToggles) {
return {};
}
} // namespace dawn::native::opengl

View File

@@ -36,7 +36,13 @@ class Adapter : public AdapterBase {
MaybeError InitializeImpl() override;
MaybeError InitializeSupportedFeaturesImpl() override;
MaybeError InitializeSupportedLimitsImpl(CombinedLimits* limits) override;
ResultOrError<Ref<DeviceBase>> CreateDeviceImpl(const DeviceDescriptor* descriptor) override;
ResultOrError<Ref<DeviceBase>> CreateDeviceImpl(
const DeviceDescriptor* descriptor,
const TripleStateTogglesSet& userProvidedToggles) override;
MaybeError ValidateFeatureSupportedWithTogglesImpl(
wgpu::FeatureName feature,
const TripleStateTogglesSet& userProvidedToggles) override;
OpenGLFunctions mFunctions;
EGLFunctions mEGLFunctions;

View File

@@ -108,8 +108,10 @@ namespace dawn::native::opengl {
ResultOrError<Ref<Device>> Device::Create(AdapterBase* adapter,
const DeviceDescriptor* descriptor,
const OpenGLFunctions& functions,
std::unique_ptr<Context> context) {
Ref<Device> device = AcquireRef(new Device(adapter, descriptor, functions, std::move(context)));
std::unique_ptr<Context> context,
const TripleStateTogglesSet& userProvidedToggles) {
Ref<Device> device = AcquireRef(
new Device(adapter, descriptor, functions, std::move(context), userProvidedToggles));
DAWN_TRY(device->Initialize(descriptor));
return device;
}
@@ -117,8 +119,11 @@ ResultOrError<Ref<Device>> Device::Create(AdapterBase* adapter,
Device::Device(AdapterBase* adapter,
const DeviceDescriptor* descriptor,
const OpenGLFunctions& functions,
std::unique_ptr<Context> context)
: DeviceBase(adapter, descriptor), mGL(functions), mContext(std::move(context)) {}
std::unique_ptr<Context> context,
const TripleStateTogglesSet& userProvidedToggles)
: DeviceBase(adapter, descriptor, userProvidedToggles),
mGL(functions),
mContext(std::move(context)) {}
Device::~Device() {
Destroy();

View File

@@ -43,7 +43,8 @@ class Device final : public DeviceBase {
static ResultOrError<Ref<Device>> Create(AdapterBase* adapter,
const DeviceDescriptor* descriptor,
const OpenGLFunctions& functions,
std::unique_ptr<Context> context);
std::unique_ptr<Context> context,
const TripleStateTogglesSet& userProvidedToggles);
~Device() override;
MaybeError Initialize(const DeviceDescriptor* descriptor);
@@ -93,7 +94,8 @@ class Device final : public DeviceBase {
Device(AdapterBase* adapter,
const DeviceDescriptor* descriptor,
const OpenGLFunctions& functions,
std::unique_ptr<Context> context);
std::unique_ptr<Context> context,
const TripleStateTogglesSet& userProvidedToggles);
ResultOrError<Ref<BindGroupBase>> CreateBindGroupImpl(
const BindGroupDescriptor* descriptor) override;