2019-01-04 10:30:40 +00:00
|
|
|
// Copyright 2018 The Dawn Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#ifndef DAWNNATIVE_INSTANCE_H_
|
|
|
|
#define DAWNNATIVE_INSTANCE_H_
|
|
|
|
|
2020-04-20 17:36:22 +00:00
|
|
|
#include "common/RefCounted.h"
|
2019-01-04 10:30:40 +00:00
|
|
|
#include "dawn_native/Adapter.h"
|
|
|
|
#include "dawn_native/BackendConnection.h"
|
2019-08-02 00:06:38 +00:00
|
|
|
#include "dawn_native/Extensions.h"
|
2019-04-26 07:52:57 +00:00
|
|
|
#include "dawn_native/Toggles.h"
|
2020-01-10 13:06:48 +00:00
|
|
|
#include "dawn_native/dawn_platform.h"
|
2019-01-04 10:30:40 +00:00
|
|
|
|
2019-04-26 07:52:57 +00:00
|
|
|
#include <array>
|
2019-01-04 10:30:40 +00:00
|
|
|
#include <memory>
|
2019-04-26 07:52:57 +00:00
|
|
|
#include <unordered_map>
|
2019-01-04 10:30:40 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace dawn_native {
|
|
|
|
|
2020-01-15 13:14:12 +00:00
|
|
|
class Surface;
|
|
|
|
|
2019-01-04 10:30:40 +00:00
|
|
|
// This is called InstanceBase for consistency across the frontend, even if the backends don't
|
|
|
|
// specialize this class.
|
2020-01-10 13:06:48 +00:00
|
|
|
class InstanceBase final : public RefCounted {
|
2019-01-04 10:30:40 +00:00
|
|
|
public:
|
2020-01-10 13:06:48 +00:00
|
|
|
static InstanceBase* Create(const InstanceDescriptor* descriptor = nullptr);
|
2019-01-04 10:30:40 +00:00
|
|
|
|
|
|
|
void DiscoverDefaultAdapters();
|
2019-01-07 09:48:03 +00:00
|
|
|
bool DiscoverAdapters(const AdapterDiscoveryOptionsBase* options);
|
2019-01-04 10:30:40 +00:00
|
|
|
|
|
|
|
const std::vector<std::unique_ptr<AdapterBase>>& GetAdapters() const;
|
|
|
|
|
|
|
|
// Used to handle error that happen up to device creation.
|
|
|
|
bool ConsumedError(MaybeError maybeError);
|
|
|
|
|
2019-04-26 07:52:57 +00:00
|
|
|
// Used to query the details of a toggle. Return nullptr if toggleName is not a valid name
|
|
|
|
// of a toggle supported in Dawn.
|
|
|
|
const ToggleInfo* GetToggleInfo(const char* toggleName);
|
|
|
|
Toggle ToggleNameToEnum(const char* toggleName);
|
|
|
|
|
2019-08-02 00:06:38 +00:00
|
|
|
// Used to query the details of an extension. Return nullptr if extensionName is not a valid
|
|
|
|
// name of an extension supported in Dawn.
|
|
|
|
const ExtensionInfo* GetExtensionInfo(const char* extensionName);
|
|
|
|
Extension ExtensionNameToEnum(const char* extensionName);
|
|
|
|
ExtensionsSet ExtensionNamesToExtensionsSet(
|
|
|
|
const std::vector<const char*>& requiredExtensions);
|
|
|
|
|
2019-05-15 06:06:26 +00:00
|
|
|
void EnableBackendValidation(bool enableBackendValidation);
|
2019-06-21 02:09:05 +00:00
|
|
|
bool IsBackendValidationEnabled() const;
|
|
|
|
|
2020-07-29 19:44:41 +00:00
|
|
|
void EnableGPUBasedBackendValidation(bool enableGPUBasedBackendValidation);
|
|
|
|
bool IsGPUBasedBackendValidationEnabled() const;
|
|
|
|
|
2019-06-21 02:09:05 +00:00
|
|
|
void EnableBeginCaptureOnStartup(bool beginCaptureOnStartup);
|
|
|
|
bool IsBeginCaptureOnStartupEnabled() const;
|
2019-05-15 06:06:26 +00:00
|
|
|
|
2019-08-13 19:00:34 +00:00
|
|
|
void SetPlatform(dawn_platform::Platform* platform);
|
|
|
|
dawn_platform::Platform* GetPlatform() const;
|
|
|
|
|
2020-01-15 13:14:12 +00:00
|
|
|
// Dawn API
|
|
|
|
Surface* CreateSurface(const SurfaceDescriptor* descriptor);
|
|
|
|
|
2019-01-04 10:30:40 +00:00
|
|
|
private:
|
2020-01-10 13:06:48 +00:00
|
|
|
InstanceBase() = default;
|
|
|
|
~InstanceBase() = default;
|
|
|
|
|
|
|
|
InstanceBase(const InstanceBase& other) = delete;
|
|
|
|
InstanceBase& operator=(const InstanceBase& other) = delete;
|
|
|
|
|
|
|
|
bool Initialize(const InstanceDescriptor* descriptor);
|
|
|
|
|
2019-01-07 09:48:03 +00:00
|
|
|
// Lazily creates connections to all backends that have been compiled.
|
2019-01-04 10:30:40 +00:00
|
|
|
void EnsureBackendConnections();
|
2019-04-26 07:52:57 +00:00
|
|
|
|
2019-01-07 09:48:03 +00:00
|
|
|
MaybeError DiscoverAdaptersInternal(const AdapterDiscoveryOptionsBase* options);
|
|
|
|
|
2019-01-04 10:30:40 +00:00
|
|
|
bool mBackendsConnected = false;
|
2019-02-25 17:42:56 +00:00
|
|
|
bool mDiscoveredDefaultAdapters = false;
|
2019-01-04 10:30:40 +00:00
|
|
|
|
2019-05-15 06:06:26 +00:00
|
|
|
bool mEnableBackendValidation = false;
|
2019-06-21 02:09:05 +00:00
|
|
|
bool mBeginCaptureOnStartup = false;
|
2020-07-29 19:44:41 +00:00
|
|
|
bool mEnableGPUValidation = false;
|
2019-04-26 07:52:57 +00:00
|
|
|
|
2019-08-13 19:00:34 +00:00
|
|
|
dawn_platform::Platform* mPlatform = nullptr;
|
|
|
|
|
2019-01-04 10:30:40 +00:00
|
|
|
std::vector<std::unique_ptr<BackendConnection>> mBackends;
|
|
|
|
std::vector<std::unique_ptr<AdapterBase>> mAdapters;
|
2019-04-26 07:52:57 +00:00
|
|
|
|
2019-08-02 00:06:38 +00:00
|
|
|
ExtensionsInfo mExtensionsInfo;
|
2019-07-30 23:58:52 +00:00
|
|
|
TogglesInfo mTogglesInfo;
|
2019-01-04 10:30:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dawn_native
|
|
|
|
|
|
|
|
#endif // DAWNNATIVE_INSTANCE_H_
|