2018-07-18 09:40:26 +00:00
|
|
|
// Copyright 2017 The Dawn Authors
|
2017-05-31 00:03:44 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2018-07-24 14:42:33 +00:00
|
|
|
#ifndef DAWNNATIVE_TOBACKEND_H_
|
|
|
|
#define DAWNNATIVE_TOBACKEND_H_
|
2017-05-31 00:03:44 +00:00
|
|
|
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/Forward.h"
|
2017-05-31 00:03:44 +00:00
|
|
|
|
2018-07-24 14:45:45 +00:00
|
|
|
namespace dawn_native {
|
2017-05-31 00:03:44 +00:00
|
|
|
|
|
|
|
// ToBackendTraits implements the mapping from base type to member type of BackendTraits
|
2017-11-24 18:59:42 +00:00
|
|
|
template <typename T, typename BackendTraits>
|
2017-05-31 00:03:44 +00:00
|
|
|
struct ToBackendTraits;
|
|
|
|
|
2019-01-10 10:12:24 +00:00
|
|
|
template <typename BackendTraits>
|
|
|
|
struct ToBackendTraits<AdapterBase, BackendTraits> {
|
|
|
|
using BackendType = typename BackendTraits::AdapterType;
|
|
|
|
};
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
template <typename BackendTraits>
|
2017-05-31 00:03:44 +00:00
|
|
|
struct ToBackendTraits<BindGroupBase, BackendTraits> {
|
|
|
|
using BackendType = typename BackendTraits::BindGroupType;
|
|
|
|
};
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
template <typename BackendTraits>
|
2017-05-31 00:03:44 +00:00
|
|
|
struct ToBackendTraits<BindGroupLayoutBase, BackendTraits> {
|
|
|
|
using BackendType = typename BackendTraits::BindGroupLayoutType;
|
|
|
|
};
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
template <typename BackendTraits>
|
2017-05-31 00:03:44 +00:00
|
|
|
struct ToBackendTraits<BufferBase, BackendTraits> {
|
|
|
|
using BackendType = typename BackendTraits::BufferType;
|
|
|
|
};
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
template <typename BackendTraits>
|
2017-05-31 00:03:44 +00:00
|
|
|
struct ToBackendTraits<CommandBufferBase, BackendTraits> {
|
|
|
|
using BackendType = typename BackendTraits::CommandBufferType;
|
|
|
|
};
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
template <typename BackendTraits>
|
2017-07-14 14:58:07 +00:00
|
|
|
struct ToBackendTraits<ComputePipelineBase, BackendTraits> {
|
|
|
|
using BackendType = typename BackendTraits::ComputePipelineType;
|
|
|
|
};
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
template <typename BackendTraits>
|
2017-06-12 14:23:22 +00:00
|
|
|
struct ToBackendTraits<DeviceBase, BackendTraits> {
|
|
|
|
using BackendType = typename BackendTraits::DeviceType;
|
|
|
|
};
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
template <typename BackendTraits>
|
2017-05-31 00:03:44 +00:00
|
|
|
struct ToBackendTraits<PipelineLayoutBase, BackendTraits> {
|
|
|
|
using BackendType = typename BackendTraits::PipelineLayoutType;
|
|
|
|
};
|
|
|
|
|
2020-06-11 00:34:14 +00:00
|
|
|
template <typename BackendTraits>
|
|
|
|
struct ToBackendTraits<QuerySetBase, BackendTraits> {
|
|
|
|
using BackendType = typename BackendTraits::QuerySetType;
|
|
|
|
};
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
template <typename BackendTraits>
|
2017-05-31 00:03:44 +00:00
|
|
|
struct ToBackendTraits<QueueBase, BackendTraits> {
|
|
|
|
using BackendType = typename BackendTraits::QueueType;
|
|
|
|
};
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
template <typename BackendTraits>
|
2017-07-14 14:58:07 +00:00
|
|
|
struct ToBackendTraits<RenderPipelineBase, BackendTraits> {
|
|
|
|
using BackendType = typename BackendTraits::RenderPipelineType;
|
|
|
|
};
|
|
|
|
|
2019-08-27 23:36:26 +00:00
|
|
|
template <typename BackendTraits>
|
|
|
|
struct ToBackendTraits<ResourceHeapBase, BackendTraits> {
|
|
|
|
using BackendType = typename BackendTraits::ResourceHeapType;
|
|
|
|
};
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
template <typename BackendTraits>
|
2017-05-31 00:03:44 +00:00
|
|
|
struct ToBackendTraits<SamplerBase, BackendTraits> {
|
|
|
|
using BackendType = typename BackendTraits::SamplerType;
|
|
|
|
};
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
template <typename BackendTraits>
|
2017-05-31 00:03:44 +00:00
|
|
|
struct ToBackendTraits<ShaderModuleBase, BackendTraits> {
|
|
|
|
using BackendType = typename BackendTraits::ShaderModuleType;
|
|
|
|
};
|
|
|
|
|
2019-01-29 00:10:07 +00:00
|
|
|
template <typename BackendTraits>
|
|
|
|
struct ToBackendTraits<StagingBufferBase, BackendTraits> {
|
|
|
|
using BackendType = typename BackendTraits::StagingBufferType;
|
|
|
|
};
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
template <typename BackendTraits>
|
2017-05-31 00:03:44 +00:00
|
|
|
struct ToBackendTraits<TextureBase, BackendTraits> {
|
|
|
|
using BackendType = typename BackendTraits::TextureType;
|
|
|
|
};
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
template <typename BackendTraits>
|
2017-07-19 22:41:17 +00:00
|
|
|
struct ToBackendTraits<SwapChainBase, BackendTraits> {
|
|
|
|
using BackendType = typename BackendTraits::SwapChainType;
|
|
|
|
};
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
template <typename BackendTraits>
|
2017-05-31 00:03:44 +00:00
|
|
|
struct ToBackendTraits<TextureViewBase, BackendTraits> {
|
|
|
|
using BackendType = typename BackendTraits::TextureViewType;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ToBackendBase implements conversion to the given BackendTraits
|
|
|
|
// To use it in a backend, use the following:
|
|
|
|
// template<typename T>
|
|
|
|
// auto ToBackend(T&& common) -> decltype(ToBackendBase<MyBackendTraits>(common)) {
|
|
|
|
// return ToBackendBase<MyBackendTraits>(common);
|
|
|
|
// }
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
template <typename BackendTraits, typename T>
|
2017-05-31 00:03:44 +00:00
|
|
|
Ref<typename ToBackendTraits<T, BackendTraits>::BackendType>& ToBackendBase(Ref<T>& common) {
|
2017-11-24 18:59:42 +00:00
|
|
|
return reinterpret_cast<Ref<typename ToBackendTraits<T, BackendTraits>::BackendType>&>(
|
|
|
|
common);
|
2017-05-31 00:03:44 +00:00
|
|
|
}
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
template <typename BackendTraits, typename T>
|
|
|
|
const Ref<typename ToBackendTraits<T, BackendTraits>::BackendType>& ToBackendBase(
|
|
|
|
const Ref<T>& common) {
|
|
|
|
return reinterpret_cast<
|
|
|
|
const Ref<typename ToBackendTraits<T, BackendTraits>::BackendType>&>(common);
|
2017-05-31 00:03:44 +00:00
|
|
|
}
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
template <typename BackendTraits, typename T>
|
2017-05-31 00:03:44 +00:00
|
|
|
typename ToBackendTraits<T, BackendTraits>::BackendType* ToBackendBase(T* common) {
|
|
|
|
return reinterpret_cast<typename ToBackendTraits<T, BackendTraits>::BackendType*>(common);
|
|
|
|
}
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
template <typename BackendTraits, typename T>
|
2017-05-31 00:03:44 +00:00
|
|
|
const typename ToBackendTraits<T, BackendTraits>::BackendType* ToBackendBase(const T* common) {
|
2017-11-24 18:59:42 +00:00
|
|
|
return reinterpret_cast<const typename ToBackendTraits<T, BackendTraits>::BackendType*>(
|
|
|
|
common);
|
2017-05-31 00:03:44 +00:00
|
|
|
}
|
|
|
|
|
2018-07-24 14:45:45 +00:00
|
|
|
} // namespace dawn_native
|
2017-05-31 00:03:44 +00:00
|
|
|
|
2018-07-24 14:42:33 +00:00
|
|
|
#endif // DAWNNATIVE_TOBACKEND_H_
|