xref: /aosp_15_r20/external/deqp/external/openglcts/modules/common/glcSpirvUtils.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _GLCSPIRVUTILS_HPP
2 #define _GLCSPIRVUTILS_HPP
3 /*-------------------------------------------------------------------------
4  * OpenGL Conformance Test Suite
5  * -----------------------------
6  *
7  * Copyright (c) 2017-2019 The Khronos Group Inc.
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */ /*!
22  * \file  glcSpirvUtils.hpp
23  * \brief Utility functions for using Glslang and Spirv-tools to work with
24  *  SPIR-V shaders.
25  */ /*-------------------------------------------------------------------*/
26 #include "glcContext.hpp"
27 #include "gluShaderProgram.hpp"
28 #include <map>
29 #include <vector>
30 
31 namespace glc
32 {
33 typedef std::map<std::string, std::vector<std::string>> SpirVMapping;
34 
35 namespace spirvUtils
36 {
37 
38 enum SpirvVersion
39 {
40     SPIRV_VERSION_1_0 = 0, //!< SPIR-V 1.0
41     SPIRV_VERSION_1_1 = 1, //!< SPIR-V 1.1
42     SPIRV_VERSION_1_2 = 2, //!< SPIR-V 1.2
43     SPIRV_VERSION_1_3 = 3, //!< SPIR-V 1.3
44 
45     SPIRV_VERSION_LAST
46 };
47 
48 void checkGlSpirvSupported(deqp::Context &m_context);
49 
50 glu::ShaderBinary makeSpirV(tcu::TestLog &log, glu::ShaderSource source, SpirvVersion version = SPIRV_VERSION_1_0);
51 
52 void spirvAssemble(glu::ShaderBinaryDataType &dst, const std::string &src);
53 void spirvDisassemble(std::string &dst, const glu::ShaderBinaryDataType &src);
54 bool spirvValidate(glu::ShaderBinaryDataType &dst, bool throwOnError);
55 
56 bool verifyMappings(std::string glslSource, std::string spirVSource, SpirVMapping &mappings, bool anyOf);
57 } // namespace spirvUtils
58 } // namespace glc
59 
60 #endif // _GLCSPIRVUTILS_HPP