d9edae60810ea04645e73904235ec4e577e104f6
[platform/upstream/VK-GL-CTS.git] / external / openglcts / modules / common / subgroups / glcSubgroupsTestsUtils.hpp
1 #ifndef _VKTSUBGROUPSTESTSUTILS_HPP
2 #define _VKTSUBGROUPSTESTSUTILS_HPP
3 /*------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2017 The Khronos Group Inc.
8  * Copyright (c) 2017 Codeplay Software Ltd.
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 Subgroups tests utility classes
25  */ /*--------------------------------------------------------------------*/
26
27 #include "vkBuilderUtil.hpp"
28 #include "vkDefs.hpp"
29 #include "vkDeviceUtil.hpp"
30 #include "vkMemUtil.hpp"
31 #include "vkPlatform.hpp"
32 #include "vkPrograms.hpp"
33 #include "vkQueryUtil.hpp"
34 #include "vkRef.hpp"
35 #include "vkRefUtil.hpp"
36 #include "vkStrUtil.hpp"
37 #include "vkTypeUtil.hpp"
38 #include "vktTestCase.hpp"
39 #include "vktTestCaseUtil.hpp"
40
41 #include "tcuFormatUtil.hpp"
42 #include "tcuTestLog.hpp"
43 #include "tcuVectorUtil.hpp"
44
45 #include "gluShaderUtil.hpp"
46
47 #include "deSharedPtr.hpp"
48 #include "deUniquePtr.hpp"
49
50 #include <string>
51
52 namespace vkt
53 {
54 namespace subgroups
55 {
56 // A struct to represent input data to a shader
57 struct SSBOData
58 {
59         SSBOData() :
60                 initializeType  (InitializeNone),
61                 format                  (vk::VK_FORMAT_UNDEFINED),
62                 numElements             (0),
63                 isImage                 (false),
64                 binding                 (0u),
65                 stages                  ((vk::VkShaderStageFlagBits)0u)
66         {}
67
68         enum InputDataInitializeType
69         {
70                 InitializeNone = 0,
71                 InitializeNonZero,
72                 InitializeZero,
73         } initializeType;
74
75         vk::VkFormat                            format;
76         vk::VkDeviceSize                        numElements;
77         bool                                            isImage;
78         deUint32                                        binding;
79         vk::VkShaderStageFlagBits       stages;
80 };
81
82 std::string getSharedMemoryBallotHelper();
83
84 deUint32 getSubgroupSize(Context& context);
85
86 vk::VkDeviceSize maxSupportedSubgroupSize();
87
88 std::string getShaderStageName(vk::VkShaderStageFlags stage);
89
90 std::string getSubgroupFeatureName(vk::VkSubgroupFeatureFlagBits bit);
91
92 void addNoSubgroupShader (vk::SourceCollections& programCollection);
93
94 std::string getVertShaderForStage(vk::VkShaderStageFlags stage);//TODO
95
96 bool isSubgroupSupported(Context& context);
97
98 bool areSubgroupOperationsSupportedForStage(
99         Context& context, vk::VkShaderStageFlags stage);
100
101 bool areSubgroupOperationsRequiredForStage(vk::VkShaderStageFlags stage);
102
103 bool isSubgroupFeatureSupportedForDevice(Context& context, vk::VkSubgroupFeatureFlagBits bit);
104
105 bool isFragmentSSBOSupportedForDevice(Context& context);
106
107 bool isVertexSSBOSupportedForDevice(Context& context);
108
109 bool isDoubleSupportedForDevice(Context& context);
110
111 bool isDoubleFormat(vk::VkFormat format);
112
113 std::string getFormatNameForGLSL(vk::VkFormat format);
114
115 void addGeometryShadersFromTemplate (const std::string& glslTemplate, const vk::ShaderBuildOptions& options, vk::GlslSourceCollection& collection);
116 void addGeometryShadersFromTemplate (const std::string& spirvTemplate, const vk::SpirVAsmBuildOptions& options, vk::SpirVAsmCollection& collection);
117
118 void setVertexShaderFrameBuffer (vk::SourceCollections& programCollection);
119
120 void setFragmentShaderFrameBuffer (vk::SourceCollections& programCollection);
121
122 void setFragmentShaderFrameBuffer (vk::SourceCollections& programCollection);
123
124 void setTesCtrlShaderFrameBuffer (vk::SourceCollections& programCollection);
125
126 void setTesEvalShaderFrameBuffer (vk::SourceCollections& programCollection);
127
128 bool check(std::vector<const void*> datas,
129         deUint32 width, deUint32 ref);
130
131 bool checkCompute(std::vector<const void*> datas,
132         const deUint32 numWorkgroups[3], const deUint32 localSize[3],
133         deUint32 ref);
134
135 tcu::TestStatus makeTessellationEvaluationFrameBufferTest(Context& context, vk::VkFormat format,
136         SSBOData* extraData, deUint32 extraDataCount,
137         bool (*checkResult)(std::vector<const void*> datas, deUint32 width, deUint32 subgroupSize),
138         const vk::VkShaderStageFlags shaderStage = vk::VK_SHADER_STAGE_ALL_GRAPHICS);
139
140 tcu::TestStatus makeGeometryFrameBufferTest(Context& context, vk::VkFormat format, SSBOData* extraData,
141         deUint32 extraDataCount,
142         bool (*checkResult)(std::vector<const void*> datas, deUint32 width, deUint32 subgroupSize));
143
144 tcu::TestStatus allStages(Context& context, vk::VkFormat format,
145         SSBOData* extraData, deUint32 extraDataCount,
146         bool (*checkResult)(std::vector<const void*> datas, deUint32 width, deUint32 subgroupSize),
147         const vk::VkShaderStageFlags shaderStage);
148
149 tcu::TestStatus makeVertexFrameBufferTest(Context& context, vk::VkFormat format,
150         SSBOData* extraData, deUint32 extraDataCount,
151         bool (*checkResult)(std::vector<const void*> datas, deUint32 width, deUint32 subgroupSize));
152
153 tcu::TestStatus makeFragmentFrameBufferTest(Context& context, vk::VkFormat format,
154         SSBOData* extraData, deUint32 extraDataCount,
155         bool (*checkResult)(std::vector<const void*> datas, deUint32 width,
156                                                                          deUint32 height, deUint32 subgroupSize));
157
158 tcu::TestStatus makeComputeTest(
159         Context& context, vk::VkFormat format, SSBOData* inputs,
160         deUint32 inputsCount,
161         bool (*checkResult)(std::vector<const void*> datas,
162                 const deUint32 numWorkgroups[3], const deUint32 localSize[3],
163                 deUint32 subgroupSize));
164 } // subgroups
165 } // vkt
166
167 #endif // _VKTSUBGROUPSTESTSUTILS_HPP