| // Copyright 2020 The Tint 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 SRC_READER_SPIRV_ENUM_CONVERTER_H_ | |
| #define SRC_READER_SPIRV_ENUM_CONVERTER_H_ | |
| #include "spirv/unified1/spirv.h" | |
| #include "src/ast/builtin.h" | |
| #include "src/ast/pipeline_stage.h" | |
| #include "src/ast/storage_class.h" | |
| #include "src/reader/spirv/fail_stream.h" | |
| #include "src/sem/storage_texture_type.h" | |
| namespace tint { | |
| namespace reader { | |
| namespace spirv { | |
| /// A converter from SPIR-V enums to Tint AST enums. | |
| class EnumConverter { | |
| public: | |
| /// Creates a new enum converter. | |
| /// @param fail_stream the error reporting stream. | |
| explicit EnumConverter(const FailStream& fail_stream); | |
| /// Destructor | |
| ~EnumConverter(); | |
| /// Converts a SPIR-V execution model to a Tint pipeline stage. | |
| /// On failure, logs an error and returns kNone | |
| /// @param model the SPIR-V entry point execution model | |
| /// @returns a Tint AST pipeline stage | |
| ast::PipelineStage ToPipelineStage(SpvExecutionModel model); | |
| /// Converts a SPIR-V storage class to a Tint storage class. | |
| /// On failure, logs an error and returns kNone | |
| /// @param sc the SPIR-V storage class | |
| /// @returns a Tint AST storage class | |
| ast::StorageClass ToStorageClass(const SpvStorageClass sc); | |
| /// Converts a SPIR-V Builtin value a Tint Builtin. | |
| /// On failure, logs an error and returns kNone | |
| /// @param b the SPIR-V builtin | |
| /// @returns a Tint AST builtin | |
| ast::Builtin ToBuiltin(SpvBuiltIn b); | |
| /// Converts a possibly arrayed SPIR-V Dim to a Tint texture dimension. | |
| /// On failure, logs an error and returns kNone | |
| /// @param dim the SPIR-V Dim value | |
| /// @param arrayed true if the texture is arrayed | |
| /// @returns a Tint AST texture dimension | |
| ast::TextureDimension ToDim(SpvDim dim, bool arrayed); | |
| /// Converts a SPIR-V Image Format to a Tint ImageFormat | |
| /// On failure, logs an error and returns kNone | |
| /// @param fmt the SPIR-V format | |
| /// @returns a Tint AST format | |
| ast::ImageFormat ToImageFormat(SpvImageFormat fmt); | |
| private: | |
| /// Registers a failure and returns a stream for log diagnostics. | |
| /// @returns a failure stream | |
| FailStream Fail() { return fail_stream_.Fail(); } | |
| FailStream fail_stream_; | |
| }; | |
| } // namespace spirv | |
| } // namespace reader | |
| } // namespace tint | |
| #endif // SRC_READER_SPIRV_ENUM_CONVERTER_H_ |