1 // Copyright 2020 The Dawn Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // This file contains utilities to convert from-to spirv.hpp datatypes without polluting other 16 // headers with spirv.hpp 17 18 #ifndef DAWNNATIVE_OPENGL_SPIRV_UTILS_H_ 19 #define DAWNNATIVE_OPENGL_SPIRV_UTILS_H_ 20 21 #include "dawn_native/Format.h" 22 #include "dawn_native/PerStage.h" 23 #include "dawn_native/VertexFormat.h" 24 #include "dawn_native/dawn_platform.h" 25 26 #include <spirv_cross.hpp> 27 28 namespace dawn_native { 29 30 // Returns the spirv_cross equivalent for this shader stage and vice-versa. 31 spv::ExecutionModel ShaderStageToExecutionModel(SingleShaderStage stage); 32 SingleShaderStage ExecutionModelToShaderStage(spv::ExecutionModel model); 33 34 // Returns the texture view dimension for corresponding to (dim, arrayed). 35 wgpu::TextureViewDimension SpirvDimToTextureViewDimension(spv::Dim dim, bool arrayed); 36 37 // Returns the texture format corresponding to format. 38 wgpu::TextureFormat SpirvImageFormatToTextureFormat(spv::ImageFormat format); 39 40 // Returns the format "component type" corresponding to the SPIRV base type. 41 wgpu::TextureComponentType SpirvBaseTypeToTextureComponentType( 42 spirv_cross::SPIRType::BaseType spirvBaseType); 43 SampleTypeBit SpirvBaseTypeToSampleTypeBit(spirv_cross::SPIRType::BaseType spirvBaseType); 44 45 // Returns the VertexFormatBaseType corresponding to the SPIRV base type. 46 VertexFormatBaseType SpirvBaseTypeToVertexFormatBaseType( 47 spirv_cross::SPIRType::BaseType spirvBaseType); 48 49 } // namespace dawn_native 50 51 #endif // DAWNNATIVE_OPENGL_SPIRV_UTILS_H_ 52