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_
|
|
|
|
|
|
|
|
#include "dawn_native/Adapter.h"
|
|
|
|
#include "dawn_native/BackendConnection.h"
|
2019-04-26 07:52:57 +00:00
|
|
|
#include "dawn_native/Toggles.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 {
|
|
|
|
|
|
|
|
// This is called InstanceBase for consistency across the frontend, even if the backends don't
|
|
|
|
// specialize this class.
|
|
|
|
class InstanceBase final {
|
|
|
|
public:
|
|
|
|
InstanceBase() = default;
|
|
|
|
~InstanceBase() = default;
|
|
|
|
|
|
|
|
InstanceBase(const InstanceBase& other) = delete;
|
|
|
|
InstanceBase& operator=(const InstanceBase& other) = delete;
|
|
|
|
|
|
|
|
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);
|
|
|
|
const char* ToggleEnumToName(Toggle toggle);
|
|
|
|
|
2019-01-04 10:30:40 +00:00
|
|
|
private:
|
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
|
|
|
// Finds the BackendConnection for `type` or returns an error.
|
|
|
|
ResultOrError<BackendConnection*> FindBackend(BackendType type);
|
|
|
|
|
|
|
|
MaybeError DiscoverAdaptersInternal(const AdapterDiscoveryOptionsBase* options);
|
|
|
|
|
2019-04-26 07:52:57 +00:00
|
|
|
void EnsureToggleNameToEnumMapInitialized();
|
|
|
|
|
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-04-26 07:52:57 +00:00
|
|
|
bool mToggleNameToEnumMapInitialized = false;
|
|
|
|
|
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
|
|
|
|
|
|
|
std::unordered_map<std::string, Toggle> mToggleNameToEnumMap;
|
2019-01-04 10:30:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dawn_native
|
|
|
|
|
|
|
|
#endif // DAWNNATIVE_INSTANCE_H_
|