1 #ifndef _VKTPIPELINEMULTISAMPLEBASE_HPP
2 #define _VKTPIPELINEMULTISAMPLEBASE_HPP
3 /*------------------------------------------------------------------------
4 * Vulkan Conformance Tests
5 * ------------------------
6 *
7 * Copyright (c) 2016 The Khronos Group Inc.
8 * Copyright (c) 2023 LunarG, Inc.
9 * Copyright (c) 2023 Nintendo
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 *
23 *//*!
24 * \file vktPipelineMultisampleBase.hpp
25 * \brief Multisample Tests Base Classes
26 *//*--------------------------------------------------------------------*/
27
28 #include "vktPipelineMultisampleTestsUtil.hpp"
29 #include "vkPipelineConstructionUtil.hpp"
30 #include "vktTestCase.hpp"
31 #include "tcuVector.hpp"
32
33 namespace vkt
34 {
35 namespace pipeline
36 {
37 namespace multisample
38 {
39
40 enum class ComponentSource
41 {
42 NONE = 0,
43 CONSTANT = 1,
44 PUSH_CONSTANT = 2,
45 };
46
47 struct ComponentData
48 {
ComponentDatavkt::pipeline::multisample::ComponentData49 ComponentData ()
50 : source {ComponentSource::NONE}
51 , index {0u}
52 {}
53
ComponentDatavkt::pipeline::multisample::ComponentData54 ComponentData (ComponentSource source_, deUint32 index_)
55 : source {source_}
56 , index {index_}
57 {}
58
ComponentDatavkt::pipeline::multisample::ComponentData59 ComponentData (const ComponentData& other)
60 : source {other.source}
61 , index {other.index}
62 {}
63
64 ComponentSource source;
65 deUint32 index;
66 };
67
68 struct ImageMSParams
69 {
ImageMSParamsvkt::pipeline::multisample::ImageMSParams70 ImageMSParams (
71 const vk::PipelineConstructionType pipelineConstructionType_,
72 const vk::VkSampleCountFlagBits numSamples_,
73 const tcu::UVec3 imageSize_,
74 const ComponentData componentData_,
75 const float shadingRate_)
76 : pipelineConstructionType (pipelineConstructionType_)
77 , numSamples (numSamples_)
78 , imageSize (imageSize_)
79 , componentData (componentData_)
80 , shadingRate (shadingRate_)
81 {}
82
83 vk::PipelineConstructionType pipelineConstructionType;
84 vk::VkSampleCountFlagBits numSamples;
85 tcu::UVec3 imageSize;
86 ComponentData componentData;
87 const float shadingRate;
88 };
89
90 class MultisampleCaseBase : public TestCase
91 {
92 public:
MultisampleCaseBase(tcu::TestContext& testCtx, const std::string& name, const ImageMSParams& imageMSParams)93 MultisampleCaseBase (tcu::TestContext& testCtx,
94 const std::string& name,
95 const ImageMSParams& imageMSParams)
96 : TestCase(testCtx, name)
97 , m_imageMSParams(imageMSParams)
98 {}
checkSupport(Context& context) const99 virtual void checkSupport (Context& context) const
100 {
101 checkGraphicsPipelineLibrarySupport(context);
102 }
103
104 protected:
105
checkGraphicsPipelineLibrarySupport(Context& context) const106 void checkGraphicsPipelineLibrarySupport(Context& context) const
107 {
108 checkPipelineConstructionRequirements(context.getInstanceInterface(), context.getPhysicalDevice(), m_imageMSParams.pipelineConstructionType);
109 }
110
111 protected:
112 const ImageMSParams m_imageMSParams;
113 };
114
115 typedef MultisampleCaseBase* (*MultisampleCaseFuncPtr)(tcu::TestContext& testCtx, const std::string& name, const ImageMSParams& imageMSParams);
116
117 class MultisampleInstanceBase : public TestInstance
118 {
119 public:
MultisampleInstanceBase(Context& context, const ImageMSParams& imageMSParams)120 MultisampleInstanceBase (Context& context,
121 const ImageMSParams& imageMSParams)
122 : TestInstance (context)
123 , m_imageMSParams (imageMSParams)
124 , m_imageType (IMAGE_TYPE_2D)
125 , m_imageFormat (tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8))
126 {}
127
128 typedef std::vector<vk::VkVertexInputAttributeDescription> VertexAttribDescVec;
129
130 struct VertexDataDesc
131 {
132 vk::VkPrimitiveTopology primitiveTopology;
133 deUint32 verticesCount;
134 deUint32 dataStride;
135 vk::VkDeviceSize dataSize;
136 VertexAttribDescVec vertexAttribDescVec;
137 };
138
139 protected:
140
141 void validateImageSize (const vk::InstanceInterface& instance,
142 const vk::VkPhysicalDevice physicalDevice,
143 const ImageType imageType,
144 const tcu::UVec3& imageSize) const;
145
146 void validateImageFeatureFlags (const vk::InstanceInterface& instance,
147 const vk::VkPhysicalDevice physicalDevice,
148 const vk::VkFormat format,
149 const vk::VkFormatFeatureFlags featureFlags) const;
150
151 void validateImageInfo (const vk::InstanceInterface& instance,
152 const vk::VkPhysicalDevice physicalDevice,
153 const vk::VkImageCreateInfo& imageInfo) const;
154
155 virtual VertexDataDesc getVertexDataDescripton (void) const = 0;
156
157 virtual void uploadVertexData (const vk::Allocation& vertexBufferAllocation,
158 const VertexDataDesc& vertexDataDescripton) const = 0;
159 protected:
160 const ImageMSParams m_imageMSParams;
161 const ImageType m_imageType;
162 const tcu::TextureFormat m_imageFormat;
163 };
164
165 } // multisample
166
167 template <class CaseClass>
makeMSGroup(tcu::TestContext& testCtx, const std::string groupName, const vk::PipelineConstructionType pipelineConstructionType, const tcu::UVec3 imageSizes[], const deUint32 imageSizesElemCount, const vk::VkSampleCountFlagBits imageSamples[], const deUint32 imageSamplesElemCount, const multisample::ComponentData& componentData = multisample::ComponentData{}, const float shadingRate = 1.0f)168 tcu::TestCaseGroup* makeMSGroup (tcu::TestContext& testCtx,
169 const std::string groupName,
170 const vk::PipelineConstructionType pipelineConstructionType,
171 const tcu::UVec3 imageSizes[],
172 const deUint32 imageSizesElemCount,
173 const vk::VkSampleCountFlagBits imageSamples[],
174 const deUint32 imageSamplesElemCount,
175 const multisample::ComponentData& componentData = multisample::ComponentData{},
176 const float shadingRate = 1.0f)
177 {
178 de::MovePtr<tcu::TestCaseGroup> caseGroup(new tcu::TestCaseGroup(testCtx, groupName.c_str()));
179
180 for (deUint32 imageSizeNdx = 0u; imageSizeNdx < imageSizesElemCount; ++imageSizeNdx)
181 {
182 const tcu::UVec3 imageSize = imageSizes[imageSizeNdx];
183 std::ostringstream imageSizeStream;
184
185 imageSizeStream << imageSize.x() << "_" << imageSize.y() << "_" << imageSize.z();
186
187 de::MovePtr<tcu::TestCaseGroup> sizeGroup(new tcu::TestCaseGroup(testCtx, imageSizeStream.str().c_str()));
188
189 for (deUint32 imageSamplesNdx = 0u; imageSamplesNdx < imageSamplesElemCount; ++imageSamplesNdx)
190 {
191 const vk::VkSampleCountFlagBits samples = imageSamples[imageSamplesNdx];
192 const multisample::ImageMSParams imageMSParams
193 {
194 pipelineConstructionType,
195 samples,
196 imageSize,
197 componentData,
198 shadingRate,
199 };
200
201 sizeGroup->addChild(CaseClass::createCase(testCtx, "samples_" + de::toString(samples), imageMSParams));
202 }
203
204 caseGroup->addChild(sizeGroup.release());
205 }
206 return caseGroup.release();
207 }
208
209 } // pipeline
210 } // vkt
211
212 #endif // _VKTPIPELINEMULTISAMPLEBASE_HPP
213