// 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 DAWNNATIVE_TOBACKEND_H_ #define DAWNNATIVE_TOBACKEND_H_ #include "dawn_native/Forward.h" namespace dawn_native { // ToBackendTraits implements the mapping from base type to member type of BackendTraits template struct ToBackendTraits; template struct ToBackendTraits { using BackendType = typename BackendTraits::AdapterType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::BindGroupType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::BindGroupLayoutType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::BufferType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::CommandBufferType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::ComputePipelineType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::DeviceType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::PipelineLayoutType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::QuerySetType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::QueueType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::RenderPipelineType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::ResourceHeapType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::SamplerType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::ShaderModuleType; }; template struct ToBackendTraits { using BackendType = typename BackendTraits::StagingBufferType; }; 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 dawn_native #endif // DAWNNATIVE_TOBACKEND_H_