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.
|
|
|
|
|
2017-07-06 18:41:13 +00:00
|
|
|
#ifndef BACKEND_TOBACKEND_H_
|
|
|
|
#define BACKEND_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
|
|
|
|
|
|
|
namespace backend {
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
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-07-26 20:59:53 +00:00
|
|
|
struct ToBackendTraits<BlendStateBase, BackendTraits> {
|
|
|
|
using BackendType = typename BackendTraits::BlendStateType;
|
|
|
|
};
|
|
|
|
|
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<BufferViewBase, BackendTraits> {
|
|
|
|
using BackendType = typename BackendTraits::BufferViewType;
|
|
|
|
};
|
|
|
|
|
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-05-31 00:03:44 +00:00
|
|
|
struct ToBackendTraits<DepthStencilStateBase, BackendTraits> {
|
|
|
|
using BackendType = typename BackendTraits::DepthStencilStateType;
|
|
|
|
};
|
|
|
|
|
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<InputStateBase, BackendTraits> {
|
|
|
|
using BackendType = typename BackendTraits::InputStateType;
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
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>
|
2018-05-11 17:04:44 +00:00
|
|
|
struct ToBackendTraits<RenderPassDescriptorBase, BackendTraits> {
|
|
|
|
using BackendType = typename BackendTraits::RenderPassDescriptorType;
|
2017-05-31 00:03:44 +00:00
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
} // namespace backend
|
2017-05-31 00:03:44 +00:00
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
#endif // BACKEND_TOBACKEND_H_
|