Make Toggles overriden automatically and device creation

Bug: dawn:373
Change-Id: I9aac64d1b800caad123161f4b48e70d39c1e0085
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/18761
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez 2020-04-06 16:55:22 +00:00 committed by Commit Bot service account
parent be73a51136
commit 022d074c06
7 changed files with 53 additions and 52 deletions

View File

@ -14,6 +14,7 @@
#include "dawn_native/Device.h"
#include "common/Log.h"
#include "dawn_native/Adapter.h"
#include "dawn_native/AttachmentState.h"
#include "dawn_native/BindGroup.h"
@ -72,13 +73,14 @@ namespace dawn_native {
mErrorScopeTracker = std::make_unique<ErrorScopeTracker>(this);
mFenceSignalTracker = std::make_unique<FenceSignalTracker>(this);
mDynamicUploader = std::make_unique<DynamicUploader>(this);
SetDefaultToggles();
if (descriptor != nullptr) {
ApplyToggleOverrides(descriptor);
ApplyExtensions(descriptor);
}
mFormatTable = BuildFormatTable(this);
SetDefaultToggles();
}
DeviceBase::~DeviceBase() {
@ -655,23 +657,6 @@ namespace dawn_native {
}
}
void DeviceBase::ApplyToggleOverrides(const DeviceDescriptor* deviceDescriptor) {
ASSERT(deviceDescriptor);
for (const char* toggleName : deviceDescriptor->forceEnabledToggles) {
Toggle toggle = GetAdapter()->GetInstance()->ToggleNameToEnum(toggleName);
if (toggle != Toggle::InvalidEnum) {
mEnabledToggles.Set(toggle, true);
}
}
for (const char* toggleName : deviceDescriptor->forceDisabledToggles) {
Toggle toggle = GetAdapter()->GetInstance()->ToggleNameToEnum(toggleName);
if (toggle != Toggle::InvalidEnum) {
mEnabledToggles.Set(toggle, false);
}
}
}
void DeviceBase::ApplyExtensions(const DeviceDescriptor* deviceDescriptor) {
ASSERT(deviceDescriptor);
ASSERT(GetAdapter()->SupportsAllRequestedExtensions(deviceDescriptor->requiredExtensions));
@ -684,18 +669,10 @@ namespace dawn_native {
return mEnabledExtensions.GetEnabledExtensionNames();
}
std::vector<const char*> DeviceBase::GetTogglesUsed() const {
return mEnabledToggles.GetContainedToggleNames();
}
bool DeviceBase::IsExtensionEnabled(Extension extension) const {
return mEnabledExtensions.IsEnabled(extension);
}
bool DeviceBase::IsToggleEnabled(Toggle toggle) const {
return mEnabledToggles.Has(toggle);
}
bool DeviceBase::IsValidationEnabled() const {
return !IsToggleEnabled(Toggle::SkipValidation);
}
@ -708,12 +685,6 @@ namespace dawn_native {
++mLazyClearCountForTesting;
}
void DeviceBase::SetDefaultToggles() {
// Sets the default-enabled toggles
mEnabledToggles.Set(Toggle::LazyClearResourceOnFirstUse, true);
mEnabledToggles.Set(Toggle::UseSpvc, false);
}
// Implementation details of object creation
MaybeError DeviceBase::CreateBindGroupInternal(BindGroupBase** result,
@ -912,8 +883,52 @@ namespace dawn_native {
return mDynamicUploader.get();
}
// The Toggle device facility
std::vector<const char*> DeviceBase::GetTogglesUsed() const {
return mEnabledToggles.GetContainedToggleNames();
}
bool DeviceBase::IsToggleEnabled(Toggle toggle) const {
return mEnabledToggles.Has(toggle);
}
void DeviceBase::SetToggle(Toggle toggle, bool isEnabled) {
if (!mOverridenToggles.Has(toggle)) {
mEnabledToggles.Set(toggle, isEnabled);
}
}
void DeviceBase::ForceSetToggle(Toggle toggle, bool isEnabled) {
if (!mOverridenToggles.Has(toggle) && mEnabledToggles.Has(toggle) != isEnabled) {
dawn::WarningLog() << "Forcing toggle \"" << ToggleEnumToName(toggle) << "\" to "
<< isEnabled << "when it was overriden to be " << !isEnabled;
}
mEnabledToggles.Set(toggle, isEnabled);
}
void DeviceBase::SetDefaultToggles() {
SetToggle(Toggle::LazyClearResourceOnFirstUse, true);
SetToggle(Toggle::UseSpvc, false);
}
void DeviceBase::ApplyToggleOverrides(const DeviceDescriptor* deviceDescriptor) {
ASSERT(deviceDescriptor);
for (const char* toggleName : deviceDescriptor->forceEnabledToggles) {
Toggle toggle = GetAdapter()->GetInstance()->ToggleNameToEnum(toggleName);
if (toggle != Toggle::InvalidEnum) {
mEnabledToggles.Set(toggle, true);
mOverridenToggles.Set(toggle, true);
}
}
for (const char* toggleName : deviceDescriptor->forceDisabledToggles) {
Toggle toggle = GetAdapter()->GetInstance()->ToggleNameToEnum(toggleName);
if (toggle != Toggle::InvalidEnum) {
mEnabledToggles.Set(toggle, false);
mOverridenToggles.Set(toggle, true);
}
}
}
} // namespace dawn_native

View File

@ -195,7 +195,7 @@ namespace dawn_native {
protected:
void SetToggle(Toggle toggle, bool isEnabled);
void ApplyToggleOverrides(const DeviceDescriptor* deviceDescriptor);
void ForceSetToggle(Toggle toggle, bool isEnabled);
void BaseDestructor();
std::unique_ptr<DynamicUploader> mDynamicUploader;
@ -263,6 +263,7 @@ namespace dawn_native {
TextureBase* texture,
const TextureViewDescriptor* descriptor);
void ApplyToggleOverrides(const DeviceDescriptor* deviceDescriptor);
void ApplyExtensions(const DeviceDescriptor* deviceDescriptor);
void SetDefaultToggles();
@ -309,6 +310,7 @@ namespace dawn_native {
FormatTable mFormatTable;
TogglesSet mEnabledToggles;
TogglesSet mOverridenToggles;
size_t mLazyClearCountForTesting = 0;
ExtensionsSet mEnabledExtensions;

View File

@ -46,9 +46,6 @@ namespace dawn_native { namespace d3d12 {
Device::Device(Adapter* adapter, const DeviceDescriptor* descriptor)
: DeviceBase(adapter, descriptor) {
InitTogglesFromDriver();
if (descriptor != nullptr) {
ApplyToggleOverrides(descriptor);
}
}
MaybeError Device::Initialize() {

View File

@ -49,9 +49,6 @@ namespace dawn_native { namespace metal {
mCommandQueue = [mMtlDevice newCommandQueue];
InitTogglesFromDriver();
if (descriptor != nil) {
ApplyToggleOverrides(descriptor);
}
}
Device::~Device() {

View File

@ -80,10 +80,6 @@ namespace dawn_native { namespace null {
Device::Device(Adapter* adapter, const DeviceDescriptor* descriptor)
: DeviceBase(adapter, descriptor) {
// Apply toggle overrides if necessary for test
if (descriptor != nullptr) {
ApplyToggleOverrides(descriptor);
}
}
Device::~Device() {

View File

@ -38,9 +38,6 @@ namespace dawn_native { namespace opengl {
const OpenGLFunctions& functions)
: DeviceBase(adapter, descriptor), gl(functions) {
InitTogglesFromDriver();
if (descriptor != nullptr) {
ApplyToggleOverrides(descriptor);
}
mFormatTable = BuildGLFormatTable();
}

View File

@ -47,9 +47,6 @@ namespace dawn_native { namespace vulkan {
Device::Device(Adapter* adapter, const DeviceDescriptor* descriptor)
: DeviceBase(adapter, descriptor) {
InitTogglesFromDriver();
if (descriptor != nullptr) {
ApplyToggleOverrides(descriptor);
}
// Set the device as lost until successfully created.
mLossStatus = LossStatus::AlreadyLost;
@ -460,10 +457,10 @@ namespace dawn_native { namespace vulkan {
ASSERT(supportsD32s8 || supportsD24s8);
if (!supportsD24s8) {
SetToggle(Toggle::VulkanUseD32S8, true);
ForceSetToggle(Toggle::VulkanUseD32S8, true);
}
if (!supportsD32s8) {
SetToggle(Toggle::VulkanUseD32S8, false);
ForceSetToggle(Toggle::VulkanUseD32S8, false);
}
}