xref: /aosp_15_r20/external/deqp/external/vulkancts/framework/vulkan/vkSpirVProgram.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _VKSPIRVPROGRAM_HPP
2 #define _VKSPIRVPROGRAM_HPP
3 /*-------------------------------------------------------------------------
4  * Vulkan CTS Framework
5  * --------------------
6  *
7  * Copyright (c) 2015 Google 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
23  * \brief SPIR-V program and binary info.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "vkDefs.hpp"
27 #include "deStringUtil.hpp"
28 #include "vkValidatorOptions.hpp"
29 
30 #include <string>
31 
32 namespace tcu
33 {
34 class TestLog;
35 } // namespace tcu
36 
37 namespace vk
38 {
39 
40 struct SpirVAsmBuildOptions
41 {
42     uint32_t vulkanVersion;
43     SpirvVersion targetVersion;
44     bool supports_VK_KHR_spirv_1_4;
45     bool supports_VK_KHR_maintenance4;
46 
SpirVAsmBuildOptionsvk::SpirVAsmBuildOptions47     SpirVAsmBuildOptions(uint32_t vulkanVersion_, SpirvVersion targetVersion_, bool allowSpirv14 = false,
48                          bool allowMaintenance4 = false)
49         : vulkanVersion(vulkanVersion_)
50         , targetVersion(targetVersion_)
51         , supports_VK_KHR_spirv_1_4(allowSpirv14)
52         , supports_VK_KHR_maintenance4(allowMaintenance4)
53     {
54     }
55 
SpirVAsmBuildOptionsvk::SpirVAsmBuildOptions56     SpirVAsmBuildOptions(void)
57         : vulkanVersion(VK_MAKE_API_VERSION(0, 1, 0, 0))
58         , targetVersion(SPIRV_VERSION_1_0)
59         , supports_VK_KHR_spirv_1_4(false)
60         , supports_VK_KHR_maintenance4(false)
61     {
62     }
63 
getSpirvValidatorOptionsvk::SpirVAsmBuildOptions64     SpirvValidatorOptions getSpirvValidatorOptions() const
65     {
66         SpirvValidatorOptions result(vulkanVersion);
67         result.supports_VK_KHR_spirv_1_4 = supports_VK_KHR_spirv_1_4;
68         if (supports_VK_KHR_maintenance4)
69             result.flags = result.flags | SpirvValidatorOptions::FLAG_SPIRV_VALIDATOR_ALLOW_LOCALSIZEID;
70         return result;
71     }
72 };
73 
74 struct SpirVAsmSource
75 {
SpirVAsmSourcevk::SpirVAsmSource76     SpirVAsmSource(void)
77     {
78     }
79 
SpirVAsmSourcevk::SpirVAsmSource80     SpirVAsmSource(const std::string &source_) : source(source_)
81     {
82     }
83 
operator <<vk::SpirVAsmSource84     SpirVAsmSource &operator<<(const SpirVAsmBuildOptions &buildOptions_)
85     {
86         buildOptions = buildOptions_;
87         return *this;
88     }
89 
90     SpirVAsmBuildOptions buildOptions;
91     std::string source;
92 };
93 
94 struct SpirVProgramInfo
95 {
SpirVProgramInfovk::SpirVProgramInfo96     SpirVProgramInfo(void) : compileTimeUs(0), compileOk(false)
97     {
98     }
99 
100     std::string source;
101     std::string infoLog;
102     uint64_t compileTimeUs;
103     bool compileOk;
104 };
105 
106 tcu::TestLog &operator<<(tcu::TestLog &log, const SpirVProgramInfo &shaderInfo);
107 tcu::TestLog &operator<<(tcu::TestLog &log, const SpirVAsmSource &program);
108 
109 // Helper for constructing SpirVAsmSource
110 template <typename T>
operator <<(SpirVAsmSource & src,const T & val)111 SpirVAsmSource &operator<<(SpirVAsmSource &src, const T &val)
112 {
113     src.source += de::toString(val);
114     return src;
115 }
116 
117 } // namespace vk
118 
119 #endif // _VKSPIRVPROGRAM_HPP
120