// Copyright 2017 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 BACKEND_TOBACKEND_H_ #define BACKEND_TOBACKEND_H_ #include "dawn_native/Forward.h" namespace backend { // ToBackendTraits implements the mapping from base type to member type of BackendTraits template struct ToBackendTraits; template struct ToBackendTraits { using BackendType = typename BackendTraits::BindGroupType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::BindGroupLayoutType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::BlendStateType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::BufferType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::BufferViewType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::CommandBufferType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::ComputePipelineType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::DepthStencilStateType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::DeviceType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::InputStateType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::PipelineLayoutType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::QueueType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::RenderPassDescriptorType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::RenderPipelineType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::SamplerType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::ShaderModuleType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::TextureType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::SwapChainType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::TextureViewType; }; // ToBackendBase implements conversion to the given BackendTraits // To use it in a backend, use the following: // template // auto ToBackend(T&& common) -> decltype(ToBackendBase(common)) { // return ToBackendBase(common); // } template Ref::BackendType>& ToBackendBase(Ref& common) { return reinterpret_cast::BackendType>&>( common); } template const Ref::BackendType>& ToBackendBase( const Ref& common) { return reinterpret_cast< const Ref::BackendType>&>(common); } template typename ToBackendTraits::BackendType* ToBackendBase(T* common) { return reinterpret_cast::BackendType*>(common); } template const typename ToBackendTraits::BackendType* ToBackendBase(const T* common) { return reinterpret_cast::BackendType*>( common); } } // namespace backend #endif // BACKEND_TOBACKEND_H_