xref: /aosp_15_r20/external/deqp/external/vulkancts/modules/vulkan/mesh_shader/vktMeshShaderUtil.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _VKTMESHSHADERUTIL_HPP
2 #define _VKTMESHSHADERUTIL_HPP
3 /*------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2021 The Khronos Group Inc.
8  * Copyright (c) 2021 Valve Corporation.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  *//*!
23  * \file
24  * \brief Mesh Shader Utility Code
25  *//*--------------------------------------------------------------------*/
26 
27 #include "vktTestCase.hpp"
28 
29 #include "vkDefs.hpp"
30 
31 #include "deSTLUtil.hpp"
32 
33 #include <vector>
34 
35 namespace vkt
36 {
37 namespace MeshShader
38 {
39 
40 // Primitive shading rate cases.
41 enum class FragmentSize
42 {
43     SIZE_2X2   = 0,
44     SIZE_2X1   = 1,
45     SIZE_1X1   = 2,
46     SIZE_COUNT = 3,
47 };
48 
49 using FragmentSizeVector = std::vector<FragmentSize>;
50 
51 // Get the block extent according to the fragment size.
52 vk::VkExtent2D getShadingRateSize(FragmentSize fragmentSize);
53 
54 // Returns a shading rate size that does not match the given fragment sizes.
55 template <typename Iterator>
getBadShadingRateSize(Iterator itBegin,Iterator itEnd)56 FragmentSize getBadShadingRateSize(Iterator itBegin, Iterator itEnd)
57 {
58     const auto fsCount = static_cast<int>(FragmentSize::SIZE_COUNT);
59 
60     for (int i = 0; i < fsCount; ++i)
61     {
62         const auto fs = static_cast<FragmentSize>(i);
63         if (!de::contains(itBegin, itEnd, fs))
64             return fs;
65     }
66 
67     DE_ASSERT(false);
68     return FragmentSize::SIZE_COUNT;
69 }
70 
71 // GLSL representation of the given fragment size.
72 std::string getGLSLShadingRateMask(FragmentSize fragmentSize);
73 
74 // GLSL/SPV value of the given mask.
75 int getSPVShadingRateValue(FragmentSize fragmentSize);
76 
77 // Basic feature check (NV version)
78 void checkTaskMeshShaderSupportNV(Context &context, bool requireTask, bool requireMesh);
79 
80 // Basic feature check (EXT version)
81 void checkTaskMeshShaderSupportEXT(Context &context, bool requireTask, bool requireMesh);
82 
83 // Get the right SPIR-V build options for the EXT.
84 vk::ShaderBuildOptions getMinMeshEXTBuildOptions(uint32_t vulkanVersion, uint32_t flags = 0u);
85 vk::SpirVAsmBuildOptions getMinMeshEXTSpvBuildOptions(uint32_t vulkanVersion, bool allowMaintenance4 = false);
86 
87 } // namespace MeshShader
88 } // namespace vkt
89 
90 #endif // _VKTMESHSHADERUTIL_HPP
91