1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2019 The Khronos Group Inc.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *//*!
20 * \file
21 * \brief Vulkan Imageless Framebuffer Tests
22 *//*--------------------------------------------------------------------*/
23
24 #include "vktImagelessFramebufferTests.hpp"
25 #include "vktTestGroupUtil.hpp"
26 #include "vktTestCase.hpp"
27
28 #include "deUniquePtr.hpp"
29 #include "deRandom.hpp"
30
31 #include "tcuTextureUtil.hpp"
32 #include "tcuVectorUtil.hpp"
33 #include "tcuImageCompare.hpp"
34 #include "tcuRGBA.hpp"
35
36 #include "vkCmdUtil.hpp"
37 #include "vkImageUtil.hpp"
38 #include "vkObjUtil.hpp"
39 #include "vkQueryUtil.hpp"
40 #include "vkRefUtil.hpp"
41 #include "vkTypeUtil.hpp"
42 #include "vkBuilderUtil.hpp"
43
44 #include <iostream>
45
46 namespace vkt
47 {
48 namespace imageless
49 {
50
51 namespace
52 {
53 using namespace vk;
54 using de::MovePtr;
55 using de::UniquePtr;
56 using de::SharedPtr;
57
58 typedef SharedPtr<Unique<VkPipeline> > SharedPtrVkPipeline;
59
60 enum TestType
61 {
62 TEST_TYPE_COLOR = 0,
63 TEST_TYPE_DEPTH_STENCIL,
64 TEST_TYPE_COLOR_RESOLVE,
65 TEST_TYPE_DEPTH_STENCIL_RESOLVE,
66 TEST_TYPE_MULTISUBPASS,
67 TEST_TYPE_DIFFERENT_ATTACHMENTS,
68 TEST_TYPE_LAST
69 };
70
71 enum AspectFlagBits
72 {
73 ASPECT_NONE = 0,
74 ASPECT_COLOR = (1<<0),
75 ASPECT_DEPTH = (1<<1),
76 ASPECT_STENCIL = (1<<2),
77 ASPECT_DEPTH_STENCIL = ASPECT_DEPTH | ASPECT_STENCIL,
78 };
79 typedef deUint32 AspectFlags;
80
81 const deUint32 NO_SAMPLE = static_cast<deUint32>(-1);
82 const deUint32 NO_SUBPASS = static_cast<deUint32>(-1);
83
84 struct TestParameters
85 {
86 TestType testType;
87 VkFormat colorFormat;
88 VkFormat dsFormat;
89 };
90
91 template<typename T>
makeSharedPtr(Move<T> move)92 inline SharedPtr<Unique<T> > makeSharedPtr (Move<T> move)
93 {
94 return SharedPtr<Unique<T> >(new Unique<T>(move));
95 }
96
sampleCountBitFromSampleCount(deUint32 count)97 VkSampleCountFlagBits sampleCountBitFromSampleCount (deUint32 count)
98 {
99 switch (count)
100 {
101 case 1: return VK_SAMPLE_COUNT_1_BIT;
102 case 2: return VK_SAMPLE_COUNT_2_BIT;
103 case 4: return VK_SAMPLE_COUNT_4_BIT;
104 case 8: return VK_SAMPLE_COUNT_8_BIT;
105 case 16: return VK_SAMPLE_COUNT_16_BIT;
106 case 32: return VK_SAMPLE_COUNT_32_BIT;
107 case 64: return VK_SAMPLE_COUNT_64_BIT;
108
109 default:
110 DE_FATAL("Invalid sample count");
111 return (VkSampleCountFlagBits)0x0;
112 }
113 }
114
convertAttachmentReference(const VkAttachmentReference & attachmentReference,const VkImageAspectFlags aspectMask)115 VkAttachmentReference2 convertAttachmentReference (const VkAttachmentReference& attachmentReference, const VkImageAspectFlags aspectMask)
116 {
117 const VkAttachmentReference2 attachmentReference2 =
118 {
119 VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2, // VkStructureType sType;
120 DE_NULL, // const void* pNext;
121 attachmentReference.attachment, // deUint32 attachment;
122 attachmentReference.layout, // VkImageLayout layout;
123 aspectMask // VkImageAspectFlags aspectMask;
124 };
125
126 return attachmentReference2;
127 }
128
convertAttachmentDescriptions(const std::vector<VkAttachmentDescription> & attachmentDescriptions)129 std::vector<VkAttachmentDescription2> convertAttachmentDescriptions (const std::vector<VkAttachmentDescription>& attachmentDescriptions)
130 {
131 std::vector<VkAttachmentDescription2> attachmentDescriptions2;
132
133 attachmentDescriptions2.reserve(attachmentDescriptions.size());
134
135 for (size_t adNdx = 0; adNdx < attachmentDescriptions.size(); ++adNdx)
136 {
137 const VkAttachmentDescription& attachmentDescription = attachmentDescriptions[adNdx];
138 const VkAttachmentDescription2 attachmentDescription2 =
139 {
140 VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2, // VkStructureType sType;
141 DE_NULL, // const void* pNext;
142 attachmentDescription.flags, // VkAttachmentDescriptionFlags flags;
143 attachmentDescription.format, // VkFormat format;
144 attachmentDescription.samples, // VkSampleCountFlagBits samples;
145 attachmentDescription.loadOp, // VkAttachmentLoadOp loadOp;
146 attachmentDescription.storeOp, // VkAttachmentStoreOp storeOp;
147 attachmentDescription.stencilLoadOp, // VkAttachmentLoadOp stencilLoadOp;
148 attachmentDescription.stencilStoreOp, // VkAttachmentStoreOp stencilStoreOp;
149 attachmentDescription.initialLayout, // VkImageLayout initialLayout;
150 attachmentDescription.finalLayout, // VkImageLayout finalLayout;
151 };
152
153 attachmentDescriptions2.push_back(attachmentDescription2);
154 }
155
156 return attachmentDescriptions2;
157 }
158
makeGraphicsPipeline(const DeviceInterface & vk,const VkDevice device,const VkPipelineLayout pipelineLayout,const VkRenderPass renderPass,const VkShaderModule vertexModule,const VkShaderModule fragmendModule,const VkExtent2D renderSize,const AspectFlags depthStencilAspects=ASPECT_NONE,const VkSampleCountFlagBits sampleCountBits=VK_SAMPLE_COUNT_1_BIT,const deUint32 subpass=0)159 Move<VkPipeline> makeGraphicsPipeline (const DeviceInterface& vk,
160 const VkDevice device,
161 const VkPipelineLayout pipelineLayout,
162 const VkRenderPass renderPass,
163 const VkShaderModule vertexModule,
164 const VkShaderModule fragmendModule,
165 const VkExtent2D renderSize,
166 const AspectFlags depthStencilAspects = ASPECT_NONE,
167 const VkSampleCountFlagBits sampleCountBits = VK_SAMPLE_COUNT_1_BIT,
168 const deUint32 subpass = 0)
169 {
170 const bool useDepth = (depthStencilAspects & ASPECT_DEPTH) != 0;
171 const bool useStencil = (depthStencilAspects & ASPECT_STENCIL) != 0;
172 const std::vector<VkViewport> viewports (1, makeViewport(renderSize));
173 const std::vector<VkRect2D> scissors (1, makeRect2D(renderSize));
174 const VkStencilOpState stencilOpState =
175 {
176 VK_STENCIL_OP_KEEP, // VkStencilOp failOp;
177 VK_STENCIL_OP_INCREMENT_AND_CLAMP, // VkStencilOp passOp;
178 VK_STENCIL_OP_KEEP, // VkStencilOp depthFailOp;
179 VK_COMPARE_OP_ALWAYS, // VkCompareOp compareOp;
180 ~0u, // deUint32 compareMask;
181 ~0u, // deUint32 writeMask;
182 0u // deUint32 reference;
183 };
184 const VkPipelineDepthStencilStateCreateInfo pipelineDepthStencilStateInfo =
185 {
186 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, // VkStructureType sType;
187 DE_NULL, // const void* pNext;
188 (VkPipelineDepthStencilStateCreateFlags)0, // VkPipelineDepthStencilStateCreateFlags flags;
189 useDepth ? VK_TRUE : VK_FALSE, // VkBool32 depthTestEnable;
190 useDepth ? VK_TRUE : VK_FALSE, // VkBool32 depthWriteEnable;
191 VK_COMPARE_OP_LESS, // VkCompareOp depthCompareOp;
192 VK_FALSE, // VkBool32 depthBoundsTestEnable;
193 useStencil ? VK_TRUE : VK_FALSE, // VkBool32 stencilTestEnable;
194 stencilOpState, // VkStencilOpState front;
195 stencilOpState, // VkStencilOpState back;
196 0.0f, // float minDepthBounds;
197 1.0f // float maxDepthBounds;
198 };
199 const VkPipelineMultisampleStateCreateInfo multisampleState =
200 {
201 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
202 DE_NULL, // const void* pNext;
203 (VkPipelineMultisampleStateCreateFlags)0u, // VkPipelineMultisampleStateCreateFlags flags;
204 sampleCountBits, // VkSampleCountFlagBits rasterizationSamples;
205 VK_FALSE, // VkBool32 sampleShadingEnable;
206 0.0f, // float minSampleShading;
207 DE_NULL, // const VkSampleMask* pSampleMask;
208 VK_FALSE, // VkBool32 alphaToCoverageEnable;
209 VK_FALSE, // VkBool32 alphaToOneEnable;
210 };
211
212 return makeGraphicsPipeline(vk, // const DeviceInterface& vk
213 device, // const VkDevice device
214 pipelineLayout, // const VkPipelineLayout pipelineLayout
215 vertexModule, // const VkShaderModule vertexShaderModule
216 DE_NULL, // const VkShaderModule tessellationControlModule
217 DE_NULL, // const VkShaderModule tessellationEvalModule
218 DE_NULL, // const VkShaderModule geometryShaderModule
219 fragmendModule, // const VkShaderModule fragmentShaderModule
220 renderPass, // const VkRenderPass renderPass
221 viewports, // const std::vector<VkViewport>& viewports
222 scissors, // const std::vector<VkRect2D>& scissors
223 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,// const VkPrimitiveTopology topology
224 subpass, // const deUint32 subpass
225 0u, // const deUint32 patchControlPoints
226 DE_NULL, // const VkPipelineVertexInputStateCreateInfo* vertexInputStateCreateInfo
227 DE_NULL, // const VkPipelineRasterizationStateCreateInfo* rasterizationStateCreateInfo
228 &multisampleState, // const VkPipelineMultisampleStateCreateInfo* multisampleStateCreateInfo
229 &pipelineDepthStencilStateInfo); // const VkPipelineDepthStencilStateCreateInfo* depthStencilStateCreateInfo
230 }
231
makeRenderPass(const DeviceInterface & vk,const VkDevice device,const VkFormat colorFormat,const VkFormat depthStencilFormat,const VkSampleCountFlagBits colorSamples,const VkSampleCountFlagBits depthStencilSamples=VK_SAMPLE_COUNT_1_BIT,const VkAttachmentLoadOp loadOperation=VK_ATTACHMENT_LOAD_OP_CLEAR,const VkImageLayout finalLayoutColor=VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,const VkImageLayout finalLayoutDepthStencil=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,const VkImageLayout subpassLayoutColor=VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,const VkImageLayout subpassLayoutDepthStencil=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,const VkAllocationCallbacks * const allocationCallbacks=DE_NULL)232 Move<VkRenderPass> makeRenderPass (const DeviceInterface& vk,
233 const VkDevice device,
234 const VkFormat colorFormat,
235 const VkFormat depthStencilFormat,
236 const VkSampleCountFlagBits colorSamples,
237 const VkSampleCountFlagBits depthStencilSamples = VK_SAMPLE_COUNT_1_BIT,
238 const VkAttachmentLoadOp loadOperation = VK_ATTACHMENT_LOAD_OP_CLEAR,
239 const VkImageLayout finalLayoutColor = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
240 const VkImageLayout finalLayoutDepthStencil = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
241 const VkImageLayout subpassLayoutColor = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
242 const VkImageLayout subpassLayoutDepthStencil = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
243 const VkAllocationCallbacks* const allocationCallbacks = DE_NULL)
244 {
245 const bool hasColor = colorFormat != VK_FORMAT_UNDEFINED;
246 const bool hasDepthStencil = depthStencilFormat != VK_FORMAT_UNDEFINED;
247 const bool hasColorResolve = hasColor && (colorSamples != VK_SAMPLE_COUNT_1_BIT);
248 const bool hasDepthStencilResolve = hasDepthStencil && (depthStencilSamples != VK_SAMPLE_COUNT_1_BIT);
249 const VkImageLayout initialLayoutColor = loadOperation == VK_ATTACHMENT_LOAD_OP_LOAD ? VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_UNDEFINED;
250 const VkImageLayout initialLayoutDepthStencil = loadOperation == VK_ATTACHMENT_LOAD_OP_LOAD ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_UNDEFINED;
251 const VkAttachmentDescription colorAttachmentDescription =
252 {
253 (VkAttachmentDescriptionFlags)0, // VkAttachmentDescriptionFlags flags;
254 colorFormat, // VkFormat format;
255 colorSamples, // VkSampleCountFlagBits samples;
256 loadOperation, // VkAttachmentLoadOp loadOp;
257 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
258 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
259 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
260 initialLayoutColor, // VkImageLayout initialLayout;
261 finalLayoutColor // VkImageLayout finalLayout;
262 };
263 const VkAttachmentDescription depthStencilAttachmentDescription =
264 {
265 (VkAttachmentDescriptionFlags)0, // VkAttachmentDescriptionFlags flags;
266 depthStencilFormat, // VkFormat format;
267 depthStencilSamples, // VkSampleCountFlagBits samples;
268 loadOperation, // VkAttachmentLoadOp loadOp;
269 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
270 loadOperation, // VkAttachmentLoadOp stencilLoadOp;
271 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp stencilStoreOp;
272 initialLayoutDepthStencil, // VkImageLayout initialLayout;
273 finalLayoutDepthStencil // VkImageLayout finalLayout;
274 };
275 const VkAttachmentDescription colorResolveAttachmentDescription =
276 {
277 (VkAttachmentDescriptionFlags)0, // VkAttachmentDescriptionFlags flags;
278 colorFormat, // VkFormat format;
279 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
280 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp loadOp;
281 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
282 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
283 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
284 initialLayoutColor, // VkImageLayout initialLayout;
285 finalLayoutColor // VkImageLayout finalLayout;
286 };
287 const VkAttachmentDescription depthStencilResolveAttachmentDescription =
288 {
289 (VkAttachmentDescriptionFlags)0, // VkAttachmentDescriptionFlags flags;
290 depthStencilFormat, // VkFormat format;
291 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
292 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp loadOp;
293 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
294 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
295 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp stencilStoreOp;
296 initialLayoutDepthStencil, // VkImageLayout initialLayout;
297 finalLayoutDepthStencil // VkImageLayout finalLayout;
298 };
299 std::vector<VkAttachmentDescription> attachmentDescriptions;
300
301 if (hasColor)
302 attachmentDescriptions.push_back(colorAttachmentDescription);
303 if (hasDepthStencil)
304 attachmentDescriptions.push_back(depthStencilAttachmentDescription);
305 if (hasColorResolve)
306 attachmentDescriptions.push_back(colorResolveAttachmentDescription);
307 if (hasDepthStencilResolve)
308 attachmentDescriptions.push_back(depthStencilResolveAttachmentDescription);
309
310 deUint32 attachmentCounter = 0;
311 const VkAttachmentReference colorAttachmentRef =
312 {
313 hasColor ? attachmentCounter++ : 0u, // deUint32 attachment;
314 subpassLayoutColor // VkImageLayout layout;
315 };
316 const VkAttachmentReference depthStencilAttachmentRef =
317 {
318 hasDepthStencil ? attachmentCounter++ : 0u, // deUint32 attachment;
319 subpassLayoutDepthStencil // VkImageLayout layout;
320 };
321 const VkAttachmentReference colorResolveAttachmentRef =
322 {
323 hasColorResolve ? attachmentCounter++ : 0u, // deUint32 attachment;
324 subpassLayoutColor // VkImageLayout layout;
325 };
326
327 if (hasDepthStencilResolve)
328 {
329 const VkImageAspectFlags colorAspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
330 const VkImageAspectFlags depthStencilAspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
331 const VkAttachmentReference2 colorAttachmentRef2 = convertAttachmentReference(colorAttachmentRef, colorAspectMask);
332 const VkAttachmentReference2 depthStencilAttachmentRef2 = convertAttachmentReference(depthStencilAttachmentRef, depthStencilAspectMask);
333 const VkAttachmentReference2 colorResolveAttachmentRef2 = convertAttachmentReference(colorResolveAttachmentRef, colorAspectMask);
334 const VkAttachmentReference2 depthStencilResolveAttachmentRef2 =
335 {
336 VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2, // VkStructureType sType;
337 DE_NULL, // const void* pNext;
338 hasDepthStencilResolve ? attachmentCounter++ : 0u, // deUint32 attachment;
339 subpassLayoutDepthStencil, // VkImageLayout layout;
340 depthStencilAspectMask // VkImageAspectFlags aspectMask;
341 };
342 const VkSubpassDescriptionDepthStencilResolve subpassDescriptionDepthStencilResolve =
343 {
344 VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE, // VkStructureType sType;
345 DE_NULL, // const void* pNext;
346 VK_RESOLVE_MODE_SAMPLE_ZERO_BIT, // VkResolveModeFlagBitsKHR depthResolveMode;
347 VK_RESOLVE_MODE_SAMPLE_ZERO_BIT, // VkResolveModeFlagBitsKHR stencilResolveMode;
348 &depthStencilResolveAttachmentRef2 // const VkAttachmentReference2KHR* pDepthStencilResolveAttachment;
349 };
350 const VkSubpassDescription2 subpassDescription2 =
351 {
352 VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2, // VkStructureType sType;
353 &subpassDescriptionDepthStencilResolve, // const void* pNext;
354 (VkSubpassDescriptionFlags)0, // VkSubpassDescriptionFlags flags;
355 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
356 0u, // deUint32 viewMask;
357 0u, // deUint32 inputAttachmentCount;
358 DE_NULL, // const VkAttachmentReference2* pInputAttachments;
359 hasColor ? 1u : 0u, // deUint32 colorAttachmentCount;
360 hasColor ? &colorAttachmentRef2 : DE_NULL, // const VkAttachmentReference2* pColorAttachments;
361 hasColorResolve ? &colorResolveAttachmentRef2 : DE_NULL, // const VkAttachmentReference2* pResolveAttachments;
362 hasDepthStencil ? &depthStencilAttachmentRef2 : DE_NULL, // const VkAttachmentReference2* pDepthStencilAttachment;
363 0u, // deUint32 preserveAttachmentCount;
364 DE_NULL // const deUint32* pPreserveAttachments;
365 };
366 const std::vector<VkAttachmentDescription2> attachmentDescriptions2 = convertAttachmentDescriptions(attachmentDescriptions);
367 const VkRenderPassCreateInfo2 renderPassInfo =
368 {
369 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2, // VkStructureType sType;
370 DE_NULL, // const void* pNext;
371 (VkRenderPassCreateFlags)0, // VkRenderPassCreateFlags flags;
372 (deUint32)attachmentDescriptions2.size(), // deUint32 attachmentCount;
373 &attachmentDescriptions2[0], // const VkAttachmentDescription2* pAttachments;
374 1u, // deUint32 subpassCount;
375 &subpassDescription2, // const VkSubpassDescription2* pSubpasses;
376 0u, // deUint32 dependencyCount;
377 DE_NULL, // const VkSubpassDependency2* pDependencies;
378 0u, // deUint32 correlatedViewMaskCount;
379 DE_NULL // const deUint32* pCorrelatedViewMasks;
380 };
381
382 return createRenderPass2(vk, device, &renderPassInfo, allocationCallbacks);
383 }
384 else
385 {
386 const VkSubpassDescription subpassDescription =
387 {
388 (VkSubpassDescriptionFlags)0, // VkSubpassDescriptionFlags flags;
389 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
390 0u, // deUint32 inputAttachmentCount;
391 DE_NULL, // const VkAttachmentReference* pInputAttachments;
392 hasColor ? 1u : 0u, // deUint32 colorAttachmentCount;
393 hasColor ? &colorAttachmentRef : DE_NULL, // const VkAttachmentReference* pColorAttachments;
394 hasColorResolve ? &colorResolveAttachmentRef : DE_NULL, // const VkAttachmentReference* pResolveAttachments;
395 hasDepthStencil ? &depthStencilAttachmentRef : DE_NULL, // const VkAttachmentReference* pDepthStencilAttachment;
396 0u, // deUint32 preserveAttachmentCount;
397 DE_NULL // const deUint32* pPreserveAttachments;
398 };
399 const VkRenderPassCreateInfo renderPassInfo =
400 {
401 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // VkStructureType sType;
402 DE_NULL, // const void* pNext;
403 (VkRenderPassCreateFlags)0, // VkRenderPassCreateFlags flags;
404 (deUint32)attachmentDescriptions.size(), // deUint32 attachmentCount;
405 &attachmentDescriptions[0], // const VkAttachmentDescription* pAttachments;
406 1u, // deUint32 subpassCount;
407 &subpassDescription, // const VkSubpassDescription* pSubpasses;
408 0u, // deUint32 dependencyCount;
409 DE_NULL // const VkSubpassDependency* pDependencies;
410 };
411
412 return createRenderPass(vk, device, &renderPassInfo, allocationCallbacks);
413 }
414 }
415
makeRenderPass(const DeviceInterface & vk,const VkDevice device,const VkFormat colorFormat,const VkAllocationCallbacks * const allocationCallbacks)416 Move<VkRenderPass> makeRenderPass (const DeviceInterface& vk,
417 const VkDevice device,
418 const VkFormat colorFormat,
419 const VkAllocationCallbacks* const allocationCallbacks)
420 {
421 const VkAttachmentDescription attachmentDescriptions[] =
422 {
423 {
424 (VkAttachmentDescriptionFlags)0, // VkAttachmentDescriptionFlags flags;
425 colorFormat, // VkFormat format;
426 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
427 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
428 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
429 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
430 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
431 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
432 VK_IMAGE_LAYOUT_GENERAL // VkImageLayout finalLayout;
433 },
434 {
435 (VkAttachmentDescriptionFlags)0, // VkAttachmentDescriptionFlags flags;
436 colorFormat, // VkFormat format;
437 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
438 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp loadOp;
439 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
440 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
441 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
442 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
443 VK_IMAGE_LAYOUT_GENERAL // VkImageLayout finalLayout;
444 },
445 };
446 const VkAttachmentReference colorAttachmentRef0 =
447 {
448 0u, // deUint32 attachment;
449 VK_IMAGE_LAYOUT_GENERAL // VkImageLayout layout;
450 };
451 const deUint32 preserveAttachment = 1u;
452 const VkAttachmentReference inputAttachmentRef1 =
453 {
454 0u, // deUint32 attachment;
455 VK_IMAGE_LAYOUT_GENERAL // VkImageLayout layout;
456 };
457 const VkAttachmentReference colorAttachmentRef1 =
458 {
459 1u, // deUint32 attachment;
460 VK_IMAGE_LAYOUT_GENERAL // VkImageLayout layout;
461 };
462 const VkSubpassDescription subpassDescriptions[] =
463 {
464 {
465 (VkSubpassDescriptionFlags)0, // VkSubpassDescriptionFlags flags;
466 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
467 0u, // deUint32 inputAttachmentCount;
468 DE_NULL, // const VkAttachmentReference* pInputAttachments;
469 1u, // deUint32 colorAttachmentCount;
470 &colorAttachmentRef0, // const VkAttachmentReference* pColorAttachments;
471 DE_NULL, // const VkAttachmentReference* pResolveAttachments;
472 DE_NULL, // const VkAttachmentReference* pDepthStencilAttachment;
473 1u, // deUint32 preserveAttachmentCount;
474 &preserveAttachment // const deUint32* pPreserveAttachments;
475 },
476 {
477 (VkSubpassDescriptionFlags)0, // VkSubpassDescriptionFlags flags;
478 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
479 1u, // deUint32 inputAttachmentCount;
480 &inputAttachmentRef1, // const VkAttachmentReference* pInputAttachments;
481 1u, // deUint32 colorAttachmentCount;
482 &colorAttachmentRef1, // const VkAttachmentReference* pColorAttachments;
483 DE_NULL, // const VkAttachmentReference* pResolveAttachments;
484 DE_NULL, // const VkAttachmentReference* pDepthStencilAttachment;
485 0u, // deUint32 preserveAttachmentCount;
486 DE_NULL // const deUint32* pPreserveAttachments;
487 },
488 };
489 const VkSubpassDependency subpassDependency =
490 {
491 0, // deUint32 srcSubpass;
492 1u, // deUint32 dstSubpass;
493 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, // VkPipelineStageFlags srcStageMask;
494 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, // VkPipelineStageFlags dstStageMask;
495 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkAccessFlags srcAccessMask;
496 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, // VkAccessFlags dstAccessMask;
497 VK_DEPENDENCY_VIEW_LOCAL_BIT, // VkDependencyFlags dependencyFlags;
498 };
499 const VkRenderPassCreateInfo renderPassInfo =
500 {
501 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // VkStructureType sType;
502 DE_NULL, // const void* pNext;
503 (VkRenderPassCreateFlags)0, // VkRenderPassCreateFlags flags;
504 DE_LENGTH_OF_ARRAY(attachmentDescriptions), // deUint32 attachmentCount;
505 &attachmentDescriptions[0], // const VkAttachmentDescription* pAttachments;
506 DE_LENGTH_OF_ARRAY(subpassDescriptions), // deUint32 subpassCount;
507 &subpassDescriptions[0], // const VkSubpassDescription* pSubpasses;
508 1u, // deUint32 dependencyCount;
509 &subpassDependency // const VkSubpassDependency* pDependencies;
510 };
511
512 return createRenderPass(vk, device, &renderPassInfo, allocationCallbacks);
513 }
514
makeSingleAttachmentRenderPass(const DeviceInterface & vk,const VkDevice device,const VkFormat colorFormat,const VkAllocationCallbacks * const allocationCallbacks)515 Move<VkRenderPass> makeSingleAttachmentRenderPass (const DeviceInterface& vk,
516 const VkDevice device,
517 const VkFormat colorFormat,
518 const VkAllocationCallbacks* const allocationCallbacks)
519 {
520 const VkAttachmentDescription attachmentDescriptions[] =
521 {
522 {
523 (VkAttachmentDescriptionFlags)0, // VkAttachmentDescriptionFlags flags;
524 colorFormat, // VkFormat format;
525 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
526 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
527 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
528 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
529 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
530 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
531 VK_IMAGE_LAYOUT_GENERAL // VkImageLayout finalLayout;
532 },
533 };
534 const VkAttachmentReference colorAttachmentRef0 =
535 {
536 0u, // deUint32 attachment;
537 VK_IMAGE_LAYOUT_GENERAL // VkImageLayout layout;
538 };
539 const VkSubpassDescription subpassDescriptions[] =
540 {
541 {
542 (VkSubpassDescriptionFlags)0, // VkSubpassDescriptionFlags flags;
543 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
544 0u, // deUint32 inputAttachmentCount;
545 DE_NULL, // const VkAttachmentReference* pInputAttachments;
546 1u, // deUint32 colorAttachmentCount;
547 &colorAttachmentRef0, // const VkAttachmentReference* pColorAttachments;
548 DE_NULL, // const VkAttachmentReference* pResolveAttachments;
549 DE_NULL, // const VkAttachmentReference* pDepthStencilAttachment;
550 0u, // deUint32 preserveAttachmentCount;
551 DE_NULL // const deUint32* pPreserveAttachments;
552 }
553 };
554 const VkRenderPassCreateInfo renderPassInfo =
555 {
556 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // VkStructureType sType;
557 DE_NULL, // const void* pNext;
558 (VkRenderPassCreateFlags)0, // VkRenderPassCreateFlags flags;
559 DE_LENGTH_OF_ARRAY(attachmentDescriptions), // deUint32 attachmentCount;
560 &attachmentDescriptions[0], // const VkAttachmentDescription* pAttachments;
561 DE_LENGTH_OF_ARRAY(subpassDescriptions), // deUint32 subpassCount;
562 &subpassDescriptions[0], // const VkSubpassDescription* pSubpasses;
563 0u, // deUint32 dependencyCount;
564 DE_NULL // const VkSubpassDependency* pDependencies;
565 };
566
567 return createRenderPass(vk, device, &renderPassInfo, allocationCallbacks);
568 }
569
makeImageCreateInfo(const VkFormat format,const VkExtent2D size,const VkImageUsageFlags usage,VkSampleCountFlagBits samples=VK_SAMPLE_COUNT_1_BIT)570 VkImageCreateInfo makeImageCreateInfo (const VkFormat format, const VkExtent2D size, const VkImageUsageFlags usage, VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT)
571 {
572 const VkExtent3D extent = { size.width, size.height, 1u };
573 const VkImageCreateInfo imageParams =
574 {
575 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
576 DE_NULL, // const void* pNext;
577 0u, // VkImageCreateFlags flags;
578 VK_IMAGE_TYPE_2D, // VkImageType imageType;
579 format, // VkFormat format;
580 extent, // VkExtent3D extent;
581 1u, // deUint32 mipLevels;
582 1u, // deUint32 arrayLayers;
583 samples, // VkSampleCountFlagBits samples;
584 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
585 usage, // VkImageUsageFlags usage;
586 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
587 0u, // deUint32 queueFamilyIndexCount;
588 DE_NULL, // const deUint32* pQueueFamilyIndices;
589 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
590 };
591 return imageParams;
592 }
593
makeFramebufferAttachmentImageInfos(const VkExtent2D & renderSize,const VkFormat * colorFormat,const VkImageUsageFlags colorUsage,const VkFormat * dsFormat,const VkImageUsageFlags dsUsage,const AspectFlags resolveAspects,const deUint32 inputAttachmentCount)594 std::vector<VkFramebufferAttachmentImageInfo> makeFramebufferAttachmentImageInfos (const VkExtent2D& renderSize,
595 const VkFormat* colorFormat,
596 const VkImageUsageFlags colorUsage,
597 const VkFormat* dsFormat,
598 const VkImageUsageFlags dsUsage,
599 const AspectFlags resolveAspects,
600 const deUint32 inputAttachmentCount)
601 {
602 const bool colorResolve = (resolveAspects & ASPECT_COLOR) != 0;
603 const bool depthStencilResolve = (resolveAspects & ASPECT_DEPTH_STENCIL) != 0;
604 std::vector<VkFramebufferAttachmentImageInfo> framebufferAttachmentImageInfos;
605
606 DE_ASSERT(colorFormat != DE_NULL);
607 DE_ASSERT(dsFormat != DE_NULL);
608
609 if (*colorFormat != VK_FORMAT_UNDEFINED)
610 {
611 const VkFramebufferAttachmentImageInfo framebufferAttachmentImageInfo =
612 {
613 VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO, // VkStructureType sType;
614 DE_NULL, // const void* pNext;
615 (VkImageCreateFlags)0u, // VkImageCreateFlags flags;
616 colorUsage, // VkImageUsageFlags usage;
617 renderSize.width, // deUint32 width;
618 renderSize.height, // deUint32 height;
619 1u, // deUint32 layerCount;
620 1u, // deUint32 viewFormatCount;
621 colorFormat // const VkFormat* pViewFormats;
622 };
623
624 framebufferAttachmentImageInfos.push_back(framebufferAttachmentImageInfo);
625 }
626
627 if (*dsFormat != VK_FORMAT_UNDEFINED)
628 {
629 const VkFramebufferAttachmentImageInfo framebufferAttachmentImageInfo =
630 {
631 VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO, // VkStructureType sType;
632 DE_NULL, // const void* pNext;
633 (VkImageCreateFlags)0u, // VkImageCreateFlags flags;
634 dsUsage, // VkImageUsageFlags usage;
635 renderSize.width, // deUint32 width;
636 renderSize.height, // deUint32 height;
637 1u, // deUint32 layerCount;
638 1u, // deUint32 viewFormatCount;
639 dsFormat // const VkFormat* pViewFormats;
640 };
641
642 framebufferAttachmentImageInfos.push_back(framebufferAttachmentImageInfo);
643 }
644
645 if (colorResolve)
646 {
647 const VkFramebufferAttachmentImageInfo framebufferAttachmentImageInfo =
648 {
649 VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO, // VkStructureType sType;
650 DE_NULL, // const void* pNext;
651 (VkImageCreateFlags)0u, // VkImageCreateFlags flags;
652 colorUsage, // VkImageUsageFlags usage;
653 renderSize.width, // deUint32 width;
654 renderSize.height, // deUint32 height;
655 1u, // deUint32 layerCount;
656 1u, // deUint32 viewFormatCount;
657 colorFormat // const VkFormat* pViewFormats;
658 };
659
660 DE_ASSERT(*colorFormat != VK_FORMAT_UNDEFINED);
661
662 framebufferAttachmentImageInfos.push_back(framebufferAttachmentImageInfo);
663 }
664
665 if (depthStencilResolve)
666 {
667 const VkFramebufferAttachmentImageInfo framebufferAttachmentImageInfo =
668 {
669 VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO, // VkStructureType sType;
670 DE_NULL, // const void* pNext;
671 (VkImageCreateFlags)0u, // VkImageCreateFlags flags;
672 dsUsage, // VkImageUsageFlags usage;
673 renderSize.width, // deUint32 width;
674 renderSize.height, // deUint32 height;
675 1u, // deUint32 layerCount;
676 1u, // deUint32 viewFormatCount;
677 dsFormat // const VkFormat* pViewFormats;
678 };
679
680 DE_ASSERT(*dsFormat != VK_FORMAT_UNDEFINED);
681
682 framebufferAttachmentImageInfos.push_back(framebufferAttachmentImageInfo);
683 }
684
685 for (deUint32 inputAttachmentNdx = 0; inputAttachmentNdx < inputAttachmentCount; ++inputAttachmentNdx)
686 {
687 const VkFramebufferAttachmentImageInfo framebufferAttachmentImageInfo =
688 {
689 VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO, // VkStructureType sType;
690 DE_NULL, // const void* pNext;
691 (VkImageCreateFlags)0u, // VkImageCreateFlags flags;
692 colorUsage | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, // VkImageUsageFlags usage;
693 renderSize.width, // deUint32 width;
694 renderSize.height, // deUint32 height;
695 1u, // deUint32 layerCount;
696 1u, // deUint32 viewFormatCount;
697 colorFormat // const VkFormat* pViewFormats;
698 };
699
700 framebufferAttachmentImageInfos.push_back(framebufferAttachmentImageInfo);
701 }
702
703 return framebufferAttachmentImageInfos;
704 }
705
makeFramebuffer(const DeviceInterface & vk,const VkDevice device,const VkRenderPass renderPass,const VkExtent2D & renderSize,const VkFormat * colorFormat,const VkImageUsageFlags colorUsage,const VkFormat * dsFormat,const VkImageUsageFlags dsUsage=static_cast<VkImageUsageFlags> (0),const AspectFlags resolveAspects=ASPECT_NONE,const deUint32 inputAttachmentCount=0)706 Move<VkFramebuffer> makeFramebuffer (const DeviceInterface& vk,
707 const VkDevice device,
708 const VkRenderPass renderPass,
709 const VkExtent2D& renderSize,
710 const VkFormat* colorFormat,
711 const VkImageUsageFlags colorUsage,
712 const VkFormat* dsFormat,
713 const VkImageUsageFlags dsUsage = static_cast<VkImageUsageFlags>(0),
714 const AspectFlags resolveAspects = ASPECT_NONE,
715 const deUint32 inputAttachmentCount = 0)
716 {
717 const std::vector<VkFramebufferAttachmentImageInfo> framebufferAttachmentImageInfos = makeFramebufferAttachmentImageInfos(renderSize, colorFormat, colorUsage, dsFormat, dsUsage, resolveAspects, inputAttachmentCount);
718 const deUint32 attachmentCount = static_cast<deUint32>(framebufferAttachmentImageInfos.size());
719 const VkFramebufferAttachmentsCreateInfo framebufferAttachmentsCreateInfo =
720 {
721 VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO, // VkStructureType sType;
722 DE_NULL, // const void* pNext;
723 attachmentCount, // deUint32 attachmentImageInfoCount;
724 &framebufferAttachmentImageInfos[0] // const VkFramebufferAttachmentImageInfo* pAttachmentImageInfos;
725 };
726 const VkFramebufferCreateInfo framebufferInfo =
727 {
728 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType;
729 &framebufferAttachmentsCreateInfo, // const void* pNext;
730 VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT, // VkFramebufferCreateFlags flags;
731 renderPass, // VkRenderPass renderPass;
732 attachmentCount, // deUint32 attachmentCount;
733 DE_NULL, // const VkImageView* pAttachments;
734 renderSize.width, // deUint32 width;
735 renderSize.height, // deUint32 height;
736 1u, // deUint32 layers;
737 };
738
739 return createFramebuffer(vk, device, &framebufferInfo);
740 }
741
makeVerifyFramebuffer(const DeviceInterface & vk,const VkDevice device,const VkRenderPass renderPass,const VkImageView colorAttachment,const VkExtent2D & renderSize,const deUint32 layers=1u)742 Move<VkFramebuffer> makeVerifyFramebuffer (const DeviceInterface& vk,
743 const VkDevice device,
744 const VkRenderPass renderPass,
745 const VkImageView colorAttachment,
746 const VkExtent2D& renderSize,
747 const deUint32 layers = 1u)
748 {
749 const VkFramebufferCreateInfo framebufferInfo = {
750 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType;
751 DE_NULL, // const void* pNext;
752 (VkFramebufferCreateFlags)0, // VkFramebufferCreateFlags flags;
753 renderPass, // VkRenderPass renderPass;
754 1u, // deUint32 attachmentCount;
755 &colorAttachment, // const VkImageView* pAttachments;
756 renderSize.width, // deUint32 width;
757 renderSize.height, // deUint32 height;
758 layers, // deUint32 layers;
759 };
760
761 return createFramebuffer(vk, device, &framebufferInfo);
762 }
763
makeVerifyPipelineLayout(const DeviceInterface & vk,const VkDevice device,const VkDescriptorSetLayout descriptorSetLayout)764 Move<VkPipelineLayout> makeVerifyPipelineLayout (const DeviceInterface& vk,
765 const VkDevice device,
766 const VkDescriptorSetLayout descriptorSetLayout)
767 {
768 const VkPushConstantRange pushConstantRanges =
769 {
770 VK_SHADER_STAGE_FRAGMENT_BIT, // VkShaderStageFlags stageFlags;
771 0u, // deUint32 offset;
772 sizeof(deUint32) // deUint32 size;
773 };
774 const VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo =
775 {
776 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
777 DE_NULL, // const void* pNext;
778 (VkPipelineLayoutCreateFlags)0, // VkPipelineLayoutCreateFlags flags;
779 1u, // deUint32 setLayoutCount;
780 &descriptorSetLayout, // const VkDescriptorSetLayout* pSetLayouts;
781 1u, // deUint32 pushConstantRangeCount;
782 &pushConstantRanges, // const VkPushConstantRange* pPushConstantRanges;
783 };
784 return createPipelineLayout(vk, device, &pipelineLayoutCreateInfo);
785 }
786
makeVerifyRenderPass(const DeviceInterface & vk,const VkDevice device,const VkFormat colorFormat)787 Move<VkRenderPass> makeVerifyRenderPass (const DeviceInterface& vk,
788 const VkDevice device,
789 const VkFormat colorFormat)
790 {
791 return makeRenderPass(vk, device, colorFormat);
792 }
793
makeImageMemoryBarrier(const VkAccessFlags srcAccessMask,const VkAccessFlags dstAccessMask,const VkImageLayout oldLayout,const VkImageLayout newLayout,const VkImage image,const VkImageSubresourceRange subresourceRange)794 VkImageMemoryBarrier makeImageMemoryBarrier (const VkAccessFlags srcAccessMask,
795 const VkAccessFlags dstAccessMask,
796 const VkImageLayout oldLayout,
797 const VkImageLayout newLayout,
798 const VkImage image,
799 const VkImageSubresourceRange subresourceRange)
800 {
801 const VkImageMemoryBarrier barrier =
802 {
803 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
804 DE_NULL, // const void* pNext;
805 srcAccessMask, // VkAccessFlags outputMask;
806 dstAccessMask, // VkAccessFlags inputMask;
807 oldLayout, // VkImageLayout oldLayout;
808 newLayout, // VkImageLayout newLayout;
809 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
810 VK_QUEUE_FAMILY_IGNORED, // deUint32 destQueueFamilyIndex;
811 image, // VkImage image;
812 subresourceRange, // VkImageSubresourceRange subresourceRange;
813 };
814 return barrier;
815 }
816
makeBufferMemoryBarrier(const VkAccessFlags srcAccessMask,const VkAccessFlags dstAccessMask,const VkBuffer buffer,const VkDeviceSize offset,const VkDeviceSize bufferSizeBytes)817 VkBufferMemoryBarrier makeBufferMemoryBarrier (const VkAccessFlags srcAccessMask,
818 const VkAccessFlags dstAccessMask,
819 const VkBuffer buffer,
820 const VkDeviceSize offset,
821 const VkDeviceSize bufferSizeBytes)
822 {
823 const VkBufferMemoryBarrier barrier =
824 {
825 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
826 DE_NULL, // const void* pNext;
827 srcAccessMask, // VkAccessFlags srcAccessMask;
828 dstAccessMask, // VkAccessFlags dstAccessMask;
829 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
830 VK_QUEUE_FAMILY_IGNORED, // deUint32 destQueueFamilyIndex;
831 buffer, // VkBuffer buffer;
832 offset, // VkDeviceSize offset;
833 bufferSizeBytes, // VkDeviceSize size;
834 };
835 return barrier;
836 }
837
makeSampler(const DeviceInterface & vk,const VkDevice & device)838 Move<VkSampler> makeSampler (const DeviceInterface& vk, const VkDevice& device)
839 {
840 const VkSamplerCreateInfo createInfo =
841 {
842 VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, // VkStructureType sType;
843 DE_NULL, // const void* pNext;
844 0u, // VkSamplerCreateFlags flags;
845 VK_FILTER_NEAREST, // VkFilter magFilter;
846 VK_FILTER_NEAREST, // VkFilter minFilter;
847 VK_SAMPLER_MIPMAP_MODE_LINEAR, // VkSamplerMipmapMode mipmapMode;
848 VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, // VkSamplerAddressMode addressModeU;
849 VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, // VkSamplerAddressMode addressModeV;
850 VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, // VkSamplerAddressMode addressModeW;
851 0.0f, // float mipLodBias;
852 VK_FALSE, // VkBool32 anisotropyEnable;
853 1.0f, // float maxAnisotropy;
854 VK_FALSE, // VkBool32 compareEnable;
855 VK_COMPARE_OP_ALWAYS, // VkCompareOp compareOp;
856 0.0f, // float minLod;
857 0.0f, // float maxLod;
858 VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK, // VkBorderColor borderColor;
859 VK_FALSE // VkBool32 unnormalizedCoordinates;
860 };
861
862 return createSampler(vk, device, &createInfo);
863 }
864
fillBuffer(const DeviceInterface & vk,const VkDevice device,Allocation & bufferAlloc,const void * data,const VkDeviceSize dataSize)865 void fillBuffer (const DeviceInterface& vk, const VkDevice device, Allocation& bufferAlloc, const void* data, const VkDeviceSize dataSize)
866 {
867 const VkMappedMemoryRange memRange =
868 {
869 VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, // VkStructureType sType;
870 DE_NULL, // const void* pNext;
871 bufferAlloc.getMemory(), // VkDeviceMemory memory;
872 bufferAlloc.getOffset(), // VkDeviceSize offset;
873 VK_WHOLE_SIZE // VkDeviceSize size;
874 };
875 const deUint32 dataSize32 = static_cast<deUint32>(dataSize);
876
877 deMemcpy(bufferAlloc.getHostPtr(), data, dataSize32);
878 VK_CHECK(vk.flushMappedMemoryRanges(device, 1u, &memRange));
879 }
880
getFullQuadVertices(void)881 std::vector<float> getFullQuadVertices (void)
882 {
883 const float verticesData[] =
884 {
885 -1.0f, -1.0f, 0.0f, 1.0f,
886 -1.0f, +1.0f, 0.0f, 1.0f,
887 +1.0f, -1.0f, 0.0f, 1.0f,
888 -1.0f, +1.0f, 0.0f, 1.0f,
889 +1.0f, -1.0f, 0.0f, 1.0f,
890 +1.0f, +1.0f, 0.0f, 1.0f,
891 };
892 const std::vector<float> vertices (verticesData, verticesData + DE_LENGTH_OF_ARRAY(verticesData));
893
894 return vertices;
895 }
896
checkImageFormatProperties(const InstanceInterface & vki,const VkPhysicalDevice & physDevice,const VkFormat format,const VkImageUsageFlags imageUsageFlags,const VkExtent2D & requiredSize2D)897 void checkImageFormatProperties (const InstanceInterface& vki,
898 const VkPhysicalDevice& physDevice,
899 const VkFormat format,
900 const VkImageUsageFlags imageUsageFlags,
901 const VkExtent2D& requiredSize2D)
902 {
903 const VkImageType imageType = VK_IMAGE_TYPE_2D;
904 const VkImageTiling imageTiling = VK_IMAGE_TILING_OPTIMAL;
905 const VkImageCreateFlags imageCreateFlags = static_cast<VkImageCreateFlags>(0u);
906 const deUint32 requiredLayers = 1u;
907 const VkExtent3D requiredSize = makeExtent3D(requiredSize2D.height, requiredSize2D.width, 1u);
908
909 VkImageFormatProperties imageFormatProperties;
910 VkResult result;
911
912 deMemset(&imageFormatProperties, 0, sizeof(imageFormatProperties));
913
914 result = vki.getPhysicalDeviceImageFormatProperties(physDevice, format, imageType, imageTiling, imageUsageFlags, imageCreateFlags, &imageFormatProperties);
915
916 if (result != VK_SUCCESS ||
917 imageFormatProperties.maxArrayLayers < requiredLayers ||
918 imageFormatProperties.maxExtent.height < requiredSize.height ||
919 imageFormatProperties.maxExtent.width < requiredSize.width ||
920 imageFormatProperties.maxExtent.depth < requiredSize.depth)
921 {
922 TCU_THROW(NotSupportedError, "Depth/stencil format is not supported");
923 }
924 }
925
getStencilBufferFormat(VkFormat depthStencilImageFormat)926 VkFormat getStencilBufferFormat(VkFormat depthStencilImageFormat)
927 {
928 const tcu::TextureFormat tcuFormat = mapVkFormat(depthStencilImageFormat);
929 const VkFormat result = (tcuFormat.order == tcu::TextureFormat::S || tcuFormat.order == tcu::TextureFormat::DS) ? VK_FORMAT_S8_UINT : VK_FORMAT_UNDEFINED;
930
931 DE_ASSERT(result != VK_FORMAT_UNDEFINED);
932
933 return result;
934 }
935
convertDepthToColor(const tcu::TextureFormat & dataFormat,const int width,const int height,const void * data,const tcu::TextureFormat & targetFormat)936 static MovePtr<tcu::TextureLevel> convertDepthToColor (const tcu::TextureFormat& dataFormat, const int width, const int height, const void* data, const tcu::TextureFormat& targetFormat)
937 {
938 const tcu::ConstPixelBufferAccess srcImage (dataFormat, width, height, 1u, data);
939 MovePtr<tcu::TextureLevel> dstImage (new tcu::TextureLevel(targetFormat, width, height, 1u));
940 tcu::PixelBufferAccess dstAccess (dstImage->getAccess());
941
942 for (int y = 0; y < height; y++)
943 for (int x = 0; x < width; x++)
944 {
945 const float depth = srcImage.getPixDepth(x, y);
946 const tcu::Vec4 color = tcu::Vec4(depth, depth, depth, 1.0f);
947
948 dstAccess.setPixel(color, x, y);
949 }
950
951 return dstImage;
952 }
953
convertStencilToColor(const tcu::TextureFormat & dataFormat,const int width,const int height,const void * data,const tcu::TextureFormat & targetFormat)954 static MovePtr<tcu::TextureLevel> convertStencilToColor (const tcu::TextureFormat& dataFormat, const int width, const int height, const void* data, const tcu::TextureFormat& targetFormat)
955 {
956 const int maxValue (4);
957 const tcu::ConstPixelBufferAccess srcImage (dataFormat, width, height, 1u, data);
958 MovePtr<tcu::TextureLevel> dstImage (new tcu::TextureLevel(targetFormat, width, height, 1u));
959 tcu::PixelBufferAccess dstAccess (dstImage->getAccess());
960
961 for (int y = 0; y < height; y++)
962 for (int x = 0; x < width; x++)
963 {
964 const int stencilInt = srcImage.getPixStencil(x, y);
965 const float stencil = (stencilInt < maxValue) ? float(stencilInt) / float(maxValue) : 1.0f;
966 const tcu::Vec4 color = tcu::Vec4(stencil, stencil, stencil, 1.0f);
967
968 dstAccess.setPixel(color, x, y);
969 }
970
971 return dstImage;
972 }
973
974 class ColorImagelessTestInstance : public TestInstance
975 {
976 public:
977 ColorImagelessTestInstance (Context& context, const TestParameters& parameters);
978 protected:
979 virtual tcu::TestStatus iterate (void);
980
981 virtual std::vector<float> getVertices (void);
982 void readOneSampleFromMultisampleImage (const VkFormat srcFormat,
983 const Unique<VkImage>& srcImage,
984 const deUint32 sampleID,
985 const VkFormat dstFormat,
986 const Unique<VkImage>& dstImage,
987 const Unique<VkBuffer>& dstBuffer,
988 const AspectFlags aspect);
989 virtual MovePtr<tcu::TextureLevel> generateReferenceImage (const tcu::TextureFormat& textureFormat,
990 const AspectFlags aspectFlags,
991 const deUint32 sample,
992 const deUint32 subpass);
993 virtual bool verifyBuffer (const UniquePtr<Allocation>& bufAlloc,
994 const VkFormat bufferFormat,
995 const std::string& name,
996 const AspectFlags aspectFlags,
997 const deUint32 sample = NO_SAMPLE,
998 const deUint32 subpass = NO_SUBPASS);
999 virtual bool verifyBufferInternal (const void* resultData,
1000 const tcu::TextureFormat& textureFormat,
1001 const tcu::TextureLevel& referenceImage,
1002 const std::string& name);
1003
1004 const bool m_extensions;
1005 const VkExtent2D m_imageExtent2D;
1006 const TestParameters m_parameters;
1007 VkImageUsageFlags m_colorImageUsage;
1008 };
1009
ColorImagelessTestInstance(Context & context,const TestParameters & parameters)1010 ColorImagelessTestInstance::ColorImagelessTestInstance (Context& context, const TestParameters& parameters)
1011 : TestInstance (context)
1012 , m_extensions (context.requireDeviceFunctionality("VK_KHR_imageless_framebuffer"))
1013 , m_imageExtent2D (makeExtent2D(32u, 32u))
1014 , m_parameters (parameters)
1015 , m_colorImageUsage (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)
1016 {
1017 const InstanceInterface& vki = m_context.getInstanceInterface();
1018 const VkPhysicalDevice physDevice = m_context.getPhysicalDevice();
1019 const VkPhysicalDeviceImagelessFramebufferFeatures& imagelessFramebufferFeatures (context.getImagelessFramebufferFeatures());
1020
1021 if (imagelessFramebufferFeatures.imagelessFramebuffer == DE_FALSE)
1022 TCU_THROW(NotSupportedError, "Imageless framebuffer is not supported");
1023
1024 checkImageFormatProperties(vki, physDevice, m_parameters.colorFormat, m_colorImageUsage, m_imageExtent2D);
1025 }
1026
readOneSampleFromMultisampleImage(const VkFormat srcFormat,const Unique<VkImage> & srcImage,const deUint32 sampleID,const VkFormat dstFormat,const Unique<VkImage> & dstImage,const Unique<VkBuffer> & dstBuffer,const AspectFlags aspect)1027 void ColorImagelessTestInstance::readOneSampleFromMultisampleImage (const VkFormat srcFormat,
1028 const Unique<VkImage>& srcImage,
1029 const deUint32 sampleID,
1030 const VkFormat dstFormat,
1031 const Unique<VkImage>& dstImage,
1032 const Unique<VkBuffer>& dstBuffer,
1033 const AspectFlags aspect)
1034 {
1035 const DeviceInterface& vk = m_context.getDeviceInterface();
1036 const VkDevice device = m_context.getDevice();
1037 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
1038 const VkQueue queue = m_context.getUniversalQueue();
1039 Allocator& allocator = m_context.getDefaultAllocator();
1040
1041 const tcu::Vec4 clearColor = tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f);
1042 const bool color = ((aspect & ASPECT_COLOR) != 0);
1043 const bool depth = ((aspect & ASPECT_DEPTH) != 0);
1044 const bool stencil = ((aspect & ASPECT_STENCIL) != 0);
1045 const VkImageAspectFlags srcAspect = color ? VK_IMAGE_ASPECT_COLOR_BIT
1046 : depth ? VK_IMAGE_ASPECT_DEPTH_BIT
1047 : VK_IMAGE_ASPECT_STENCIL_BIT;
1048 const VkImageSubresourceRange srcSubresRange = makeImageSubresourceRange(srcAspect, 0u, 1u, 0u, 1u);
1049 const Unique<VkImageView> srcImageView (makeImageView (vk, device, *srcImage, VK_IMAGE_VIEW_TYPE_2D, srcFormat, srcSubresRange));
1050
1051 const VkImageAspectFlags dstAspect = VK_IMAGE_ASPECT_COLOR_BIT;
1052 const VkImageSubresourceRange dstSubresRange = makeImageSubresourceRange(dstAspect, 0u, 1u, 0u, 1u);
1053 const Unique<VkImageView> dstAttachment (makeImageView (vk, device, *dstImage, VK_IMAGE_VIEW_TYPE_2D, dstFormat, dstSubresRange));
1054
1055 const std::string fragModuleInfix = color ? "-color"
1056 : depth ? "-depth"
1057 : stencil ? "-stencil"
1058 : "";
1059 const Unique<VkShaderModule> vertModule (createShaderModule (vk, device, m_context.getBinaryCollection().get("demultisample-vert"), 0u));
1060 const Unique<VkShaderModule> fragModule (createShaderModule (vk, device, m_context.getBinaryCollection().get("demultisample" + fragModuleInfix + "-frag"), 0u));
1061 const Unique<VkRenderPass> renderPass (makeVerifyRenderPass (vk, device, dstFormat));
1062 const Unique<VkFramebuffer> framebuffer (makeVerifyFramebuffer (vk, device, *renderPass, *dstAttachment, m_imageExtent2D));
1063
1064 const VkDescriptorType samplerDescType (VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER);
1065 const Unique<VkSampler> sampler (makeSampler(vk, device));
1066 const Unique<VkDescriptorSetLayout> descriptorSetLayout (DescriptorSetLayoutBuilder()
1067 .addSingleSamplerBinding(samplerDescType, VK_SHADER_STAGE_FRAGMENT_BIT, &sampler.get())
1068 .build(vk, device));
1069 const Unique<VkDescriptorPool> descriptorPool (DescriptorPoolBuilder()
1070 .addType(samplerDescType)
1071 .build(vk, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1u));
1072 const Unique<VkDescriptorSet> descriptorSet (makeDescriptorSet(vk, device, *descriptorPool, *descriptorSetLayout));
1073 const VkDescriptorImageInfo imageDescriptorInfo (makeDescriptorImageInfo(DE_NULL, *srcImageView, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL));
1074
1075 DescriptorSetUpdateBuilder()
1076 .writeSingle(*descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), samplerDescType, &imageDescriptorInfo)
1077 .update(vk, device);
1078
1079 const Unique<VkPipelineLayout> pipelineLayout (makeVerifyPipelineLayout (vk, device, *descriptorSetLayout));
1080 const Unique<VkPipeline> pipeline (makeGraphicsPipeline (vk, device, *pipelineLayout, *renderPass, *vertModule, *fragModule, m_imageExtent2D));
1081 const Unique<VkCommandPool> cmdPool (createCommandPool (vk, device, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, queueFamilyIndex));
1082 const Unique<VkCommandBuffer> cmdBuffer (allocateCommandBuffer (vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
1083
1084 const std::vector<float> vertexArray (getFullQuadVertices());
1085 const deUint32 vertexCount (static_cast<deUint32>(vertexArray.size() / 4u));
1086 const VkDeviceSize vertexArraySize (vertexArray.size() * sizeof(vertexArray[0]));
1087 const Unique<VkBuffer> vertexBuffer (makeBuffer (vk, device, vertexArraySize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT));
1088 const UniquePtr<Allocation> vertexBufferAlloc (bindBuffer (vk, device, allocator, *vertexBuffer, MemoryRequirement::HostVisible));
1089 const VkDeviceSize vertexBufferOffset (0u);
1090
1091 fillBuffer(vk, device, *vertexBufferAlloc, &vertexArray[0], vertexArraySize);
1092
1093 beginCommandBuffer(vk, *cmdBuffer);
1094 {
1095 if (sampleID == 0)
1096 {
1097 if (color)
1098 {
1099 const VkImageMemoryBarrier preCopyBarrier = makeImageMemoryBarrier (VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT,
1100 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
1101 *srcImage, srcSubresRange);
1102
1103 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &preCopyBarrier);
1104 }
1105 else if (depth)
1106 {
1107 const VkImageSubresourceRange preCopySubresRange = makeImageSubresourceRange (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, 0u, 1u, 0u, 1u);
1108 const VkImageMemoryBarrier preCopyBarrier = makeImageMemoryBarrier (VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT,
1109 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
1110 *srcImage, preCopySubresRange);
1111
1112 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &preCopyBarrier);
1113 }
1114 }
1115
1116 beginRenderPass(vk, *cmdBuffer, *renderPass, *framebuffer, makeRect2D(m_imageExtent2D), clearColor);
1117 {
1118 vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
1119
1120 vk.cmdBindDescriptorSets(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipelineLayout, 0u, 1u, &descriptorSet.get(), 0u, DE_NULL);
1121
1122 vk.cmdBindVertexBuffers(*cmdBuffer, 0u, 1u, &*vertexBuffer, &vertexBufferOffset);
1123
1124 vk.cmdPushConstants(*cmdBuffer, *pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 0u, sizeof(sampleID), &sampleID);
1125
1126 vk.cmdDraw(*cmdBuffer, vertexCount, 1u, 0u, 0u);
1127 }
1128 endRenderPass(vk, *cmdBuffer);
1129
1130 // Image copy
1131 {
1132 const VkImageMemoryBarrier preCopyBarrier = makeImageMemoryBarrier (VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
1133 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1134 *dstImage, dstSubresRange);
1135 const VkBufferImageCopy region = makeBufferImageCopy (makeExtent3D(m_imageExtent2D.width, m_imageExtent2D.height, 1u),
1136 makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u));
1137 const VkBufferMemoryBarrier postCopyBarrier = makeBufferMemoryBarrier (VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, *dstBuffer, 0ull, VK_WHOLE_SIZE);
1138
1139 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &preCopyBarrier);
1140 vk.cmdCopyImageToBuffer(*cmdBuffer, *dstImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *dstBuffer, 1u, ®ion);
1141 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, 1u, &postCopyBarrier, DE_NULL, 0u);
1142 }
1143 }
1144 endCommandBuffer(vk, *cmdBuffer);
1145 submitCommandsAndWait(vk, device, queue, *cmdBuffer);
1146 }
1147
verifyBufferInternal(const void * resultData,const tcu::TextureFormat & textureFormat,const tcu::TextureLevel & referenceImage,const std::string & name)1148 bool ColorImagelessTestInstance::verifyBufferInternal (const void* resultData, const tcu::TextureFormat& textureFormat, const tcu::TextureLevel& referenceImage, const std::string& name)
1149 {
1150 const int dataSize (m_imageExtent2D.width * m_imageExtent2D.height * textureFormat.getPixelSize());
1151 const tcu::ConstPixelBufferAccess referenceAccess (referenceImage.getAccess());
1152
1153 if (deMemCmp(resultData, referenceAccess.getDataPtr(), dataSize) != 0)
1154 {
1155 const tcu::ConstPixelBufferAccess resultImage (textureFormat, m_imageExtent2D.width, m_imageExtent2D.height, 1u, resultData);
1156 bool ok;
1157
1158 ok = tcu::intThresholdCompare(m_context.getTestContext().getLog(), name.c_str(), "", referenceAccess, resultImage, tcu::UVec4(1), tcu::COMPARE_LOG_RESULT);
1159
1160 return ok;
1161 }
1162
1163 return true;
1164 }
1165
verifyBuffer(const UniquePtr<Allocation> & bufAlloc,const VkFormat bufferFormat,const std::string & name,const AspectFlags aspectFlags,const deUint32 sample,const deUint32 subpass)1166 bool ColorImagelessTestInstance::verifyBuffer (const UniquePtr<Allocation>& bufAlloc, const VkFormat bufferFormat, const std::string& name, const AspectFlags aspectFlags, const deUint32 sample, const deUint32 subpass)
1167 {
1168 invalidateMappedMemoryRange(m_context.getDeviceInterface(), m_context.getDevice(), bufAlloc->getMemory(), bufAlloc->getOffset(), VK_WHOLE_SIZE);
1169
1170 const tcu::TextureFormat bufferTextureFormat (mapVkFormat(bufferFormat));
1171 const bool multisampled (sample != NO_SAMPLE);
1172 const bool depth ((aspectFlags & ASPECT_DEPTH) != 0);
1173 const bool stencil ((aspectFlags & ASPECT_STENCIL) != 0);
1174 const bool convertRequired ((depth || stencil) && !multisampled);
1175 const tcu::TextureFormat convertTextureFormat (tcu::TextureFormat(tcu::TextureFormat::R, tcu::TextureFormat::UNORM_INT8));
1176 const tcu::TextureFormat referenceTextureFormat (convertRequired ? convertTextureFormat : bufferTextureFormat);
1177 const MovePtr<tcu::TextureLevel> referenceImage (generateReferenceImage(referenceTextureFormat, aspectFlags, sample, subpass));
1178
1179 if (!multisampled && depth)
1180 {
1181 MovePtr<tcu::TextureLevel> convertedImage (convertDepthToColor(bufferTextureFormat, m_imageExtent2D.width, m_imageExtent2D.height, bufAlloc->getHostPtr(), convertTextureFormat));
1182 tcu::ConstPixelBufferAccess convertedAccess (convertedImage->getAccess());
1183
1184 return verifyBufferInternal(convertedAccess.getDataPtr(), convertTextureFormat, *referenceImage, name);
1185 }
1186 else if (!multisampled && stencil)
1187 {
1188 MovePtr<tcu::TextureLevel> convertedImage (convertStencilToColor(bufferTextureFormat, m_imageExtent2D.width, m_imageExtent2D.height, bufAlloc->getHostPtr(), convertTextureFormat));
1189 tcu::ConstPixelBufferAccess convertedAccess (convertedImage->getAccess());
1190
1191 return verifyBufferInternal(convertedAccess.getDataPtr(), convertTextureFormat, *referenceImage, name);
1192 }
1193 else
1194 {
1195 const void* resultData (bufAlloc->getHostPtr());
1196
1197 return verifyBufferInternal(resultData, bufferTextureFormat, *referenceImage, name);
1198 }
1199 }
1200
generateReferenceImage(const tcu::TextureFormat & textureFormat,const AspectFlags aspectFlags,const deUint32 sample,const deUint32 subpass)1201 MovePtr<tcu::TextureLevel> ColorImagelessTestInstance::generateReferenceImage (const tcu::TextureFormat& textureFormat,
1202 const AspectFlags aspectFlags,
1203 const deUint32 sample,
1204 const deUint32 subpass)
1205 {
1206 const int width = m_imageExtent2D.width;
1207 const int height = m_imageExtent2D.height;
1208 const int componentValue (static_cast<int>(0.75f * 0x100));
1209 const tcu::RGBA colorDrawRGBA (tcu::RGBA(componentValue, componentValue, componentValue, 0xFF));
1210 const tcu::Vec4 colorDraw (colorDrawRGBA.toVec());
1211 const tcu::Vec4 colorFill (tcu::RGBA::black().toVec());
1212 MovePtr<tcu::TextureLevel> image (new tcu::TextureLevel(textureFormat, width, height));
1213 tcu::PixelBufferAccess access (image->getAccess());
1214
1215 DE_UNREF(aspectFlags);
1216 DE_ASSERT(aspectFlags == ASPECT_COLOR);
1217 DE_UNREF(sample);
1218 DE_ASSERT(sample == NO_SAMPLE);
1219 DE_UNREF(subpass);
1220 DE_ASSERT(subpass == NO_SUBPASS);
1221
1222 for (int y = 0; y < height; ++y)
1223 {
1224 const tcu::Vec4& validColor = (y < height / 2) ? colorFill : colorDraw;
1225
1226 for (int x = 0; x < width; ++x)
1227 access.setPixel(validColor, x, y);
1228 }
1229
1230 return image;
1231 }
1232
getVertices(void)1233 std::vector<float> ColorImagelessTestInstance::getVertices (void)
1234 {
1235 const float verticesData[] =
1236 {
1237 -1.0f, 0.0f, 0.0f, 1.0f,
1238 -1.0f, +1.0f, 0.0f, 1.0f,
1239 +1.0f, 0.0f, 0.0f, 1.0f,
1240 -1.0f, +1.0f, 0.0f, 1.0f,
1241 +1.0f, 0.0f, 0.0f, 1.0f,
1242 +1.0f, +1.0f, 0.0f, 1.0f,
1243 };
1244 const std::vector<float> vertices (verticesData, verticesData + DE_LENGTH_OF_ARRAY(verticesData));
1245
1246 return vertices;
1247 }
1248
iterate(void)1249 tcu::TestStatus ColorImagelessTestInstance::iterate (void)
1250 {
1251 const DeviceInterface& vk = m_context.getDeviceInterface();
1252 const VkDevice device = m_context.getDevice();
1253 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
1254 const VkQueue queue = m_context.getUniversalQueue();
1255 Allocator& allocator = m_context.getDefaultAllocator();
1256
1257 const tcu::Vec4 clearColor = tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f);
1258 const VkFormat colorFormat = m_parameters.colorFormat;
1259 const VkDeviceSize colorBufferSize = m_imageExtent2D.width * m_imageExtent2D.height * tcu::getPixelSize(mapVkFormat(colorFormat));
1260 const VkImageSubresourceRange colorSubresRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u);
1261
1262 const Unique<VkImage> colorImage (makeImage (vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage)));
1263 const UniquePtr<Allocation> colorImageAlloc (bindImage (vk, device, allocator, *colorImage, MemoryRequirement::Any));
1264 const Unique<VkImageView> colorAttachment (makeImageView (vk, device, *colorImage, VK_IMAGE_VIEW_TYPE_2D, colorFormat, colorSubresRange));
1265 const Unique<VkBuffer> colorBuffer (makeBuffer (vk, device, colorBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT));
1266 const UniquePtr<Allocation> colorBufferAlloc (bindBuffer (vk, device, allocator, *colorBuffer, MemoryRequirement::HostVisible));
1267
1268 const Unique<VkShaderModule> vertModule (createShaderModule (vk, device, m_context.getBinaryCollection().get("vert"), 0u));
1269 const Unique<VkShaderModule> fragModule (createShaderModule (vk, device, m_context.getBinaryCollection().get("frag"), 0u));
1270 const Unique<VkRenderPass> renderPass (makeRenderPass (vk, device, colorFormat, m_parameters.dsFormat));
1271 const Unique<VkFramebuffer> framebuffer (makeFramebuffer (vk, device, *renderPass, m_imageExtent2D, &colorFormat, m_colorImageUsage, &m_parameters.dsFormat));
1272 const Unique<VkPipelineLayout> pipelineLayout (makePipelineLayout (vk, device));
1273 const Unique<VkPipeline> pipeline (makeGraphicsPipeline (vk, device, *pipelineLayout, *renderPass, *vertModule, *fragModule, m_imageExtent2D));
1274 const Unique<VkCommandPool> cmdPool (createCommandPool (vk, device, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, queueFamilyIndex));
1275 const Unique<VkCommandBuffer> cmdBuffer (allocateCommandBuffer (vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
1276
1277 const std::vector<float> vertexArray (getVertices());
1278 const deUint32 vertexCount (static_cast<deUint32>(vertexArray.size() / 4u));
1279 const VkDeviceSize vertexArraySize (vertexArray.size() * sizeof(vertexArray[0]));
1280 const Unique<VkBuffer> vertexBuffer (makeBuffer (vk, device, vertexArraySize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT));
1281 const UniquePtr<Allocation> vertexBufferAlloc (bindBuffer (vk, device, allocator, *vertexBuffer, MemoryRequirement::HostVisible));
1282 const VkDeviceSize vertexBufferOffset (0u);
1283
1284 fillBuffer(vk, device, *vertexBufferAlloc, &vertexArray[0], vertexArraySize);
1285
1286 beginCommandBuffer(vk, *cmdBuffer);
1287 {
1288 const VkRenderPassAttachmentBeginInfo renderPassAttachmentBeginInfo =
1289 {
1290 VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO, // VkStructureType sType;
1291 DE_NULL, // const void* pNext;
1292 1u, // deUint32 attachmentCount;
1293 &*colorAttachment // const VkImageView* pAttachments;
1294 };
1295
1296 beginRenderPass(vk, *cmdBuffer, *renderPass, *framebuffer, makeRect2D(m_imageExtent2D), clearColor, &renderPassAttachmentBeginInfo);
1297 {
1298 vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
1299
1300 vk.cmdBindVertexBuffers(*cmdBuffer, 0u, 1u, &*vertexBuffer, &vertexBufferOffset);
1301
1302 vk.cmdDraw(*cmdBuffer, vertexCount, 1u, 0u, 0u);
1303 }
1304 endRenderPass(vk, *cmdBuffer);
1305
1306 // Color image copy
1307 {
1308 const VkImageMemoryBarrier preCopyBarrier = makeImageMemoryBarrier (VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
1309 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1310 *colorImage, colorSubresRange);
1311 const VkBufferImageCopy region = makeBufferImageCopy (makeExtent3D(m_imageExtent2D.width, m_imageExtent2D.height, 1u),
1312 makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u));
1313 const VkBufferMemoryBarrier postCopyBarrier = makeBufferMemoryBarrier (VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, *colorBuffer, 0ull, VK_WHOLE_SIZE);
1314
1315 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &preCopyBarrier);
1316 vk.cmdCopyImageToBuffer(*cmdBuffer, *colorImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *colorBuffer, 1u, ®ion);
1317 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, 1u, &postCopyBarrier, DE_NULL, 0u);
1318 }
1319 }
1320 endCommandBuffer(vk, *cmdBuffer);
1321 submitCommandsAndWait(vk, device, queue, *cmdBuffer);
1322
1323 if (verifyBuffer(colorBufferAlloc, colorFormat, "Color", ASPECT_COLOR))
1324 return tcu::TestStatus::pass("Pass");
1325 else
1326 return tcu::TestStatus::fail("Fail");
1327 }
1328
1329 class DepthImagelessTestInstance : public ColorImagelessTestInstance
1330 {
1331 public:
1332 DepthImagelessTestInstance (Context& context, const TestParameters& parameters);
1333
1334 protected:
1335 virtual tcu::TestStatus iterate (void);
1336
1337 virtual std::vector<float> getVertices (void);
1338
1339 virtual MovePtr<tcu::TextureLevel> generateReferenceImage (const tcu::TextureFormat& textureFormat,
1340 const AspectFlags aspectFlags,
1341 const deUint32 sample,
1342 const deUint32 subpass);
1343
1344 VkImageUsageFlags m_dsImageUsage;
1345 };
1346
DepthImagelessTestInstance(Context & context,const TestParameters & parameters)1347 DepthImagelessTestInstance::DepthImagelessTestInstance (Context& context, const TestParameters& parameters)
1348 : ColorImagelessTestInstance (context, parameters)
1349 , m_dsImageUsage (VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT)
1350 {
1351 const InstanceInterface& vki = m_context.getInstanceInterface();
1352 const VkPhysicalDevice physDevice = m_context.getPhysicalDevice();
1353
1354 checkImageFormatProperties(vki, physDevice, m_parameters.dsFormat, m_dsImageUsage, m_imageExtent2D);
1355 }
1356
generateReferenceImage(const tcu::TextureFormat & textureFormat,const AspectFlags aspectFlags,const deUint32 sample,const deUint32 subpass)1357 MovePtr<tcu::TextureLevel> DepthImagelessTestInstance::generateReferenceImage (const tcu::TextureFormat& textureFormat,
1358 const AspectFlags aspectFlags,
1359 const deUint32 sample,
1360 const deUint32 subpass)
1361 {
1362 const bool color = ((aspectFlags & ASPECT_COLOR) != 0);
1363 const bool depth = ((aspectFlags & ASPECT_DEPTH) != 0);
1364 const bool stencil = ((aspectFlags & ASPECT_STENCIL) != 0);
1365 const int width = m_imageExtent2D.width;
1366 const int height = m_imageExtent2D.height;
1367 MovePtr<tcu::TextureLevel> image (new tcu::TextureLevel(textureFormat, width, height));
1368 tcu::PixelBufferAccess access (image->getAccess());
1369
1370 DE_ASSERT(dePop32(aspectFlags) == 1);
1371 DE_UNREF(sample);
1372 DE_ASSERT(sample == NO_SAMPLE);
1373 DE_UNREF(subpass);
1374 DE_ASSERT(subpass == NO_SUBPASS);
1375
1376 if (color)
1377 {
1378 const int componentValue (static_cast<int>(0.75f * 0x100));
1379 const tcu::RGBA colorDrawRGBA (tcu::RGBA(componentValue, componentValue, componentValue, 0xFF));
1380 const tcu::Vec4 colorDraw (colorDrawRGBA.toVec());
1381 const tcu::Vec4 colorDrawTop (tcu::RGBA::white().toVec());
1382 const tcu::Vec4 colorFill (tcu::RGBA::black().toVec());
1383
1384 for (int y = 0; y < height; ++y)
1385 for (int x = 0; x < width; ++x)
1386 {
1387 const tcu::Vec4& validColor = (y < height / 2) ? colorFill
1388 : (x < width / 2) ? colorDraw
1389 : colorDrawTop;
1390
1391 access.setPixel(validColor, x, y);
1392 }
1393 }
1394
1395 if (depth)
1396 {
1397 const int colorFillValue (static_cast<int>(1.00f * 0x100));
1398 const int colorDrawValue (static_cast<int>(0.50f * 0x100));
1399 const int colorTopValue (static_cast<int>(0.25f * 0x100));
1400 const tcu::IVec4 colorFill (colorFillValue, 0, 0, 0xFF);
1401 const tcu::IVec4 colorDraw (colorDrawValue, 0, 0, 0xFF);
1402 const tcu::IVec4 colorTop (colorTopValue, 0, 0, 0xFF);
1403
1404 for (int y = 0; y < height; ++y)
1405 for (int x = 0; x < width; ++x)
1406 {
1407 const tcu::IVec4& validColor = (y < height / 2) ? colorFill
1408 : (x < width / 2) ? colorDraw
1409 : colorTop;
1410
1411 access.setPixel(validColor, x, y);
1412 }
1413 }
1414
1415 if (stencil)
1416 {
1417 const int colorFillValue (static_cast<int>(0.00f * 0x100));
1418 const int colorDrawValue (static_cast<int>(0.25f * 0x100));
1419 const int colorTopValue (static_cast<int>(0.50f * 0x100));
1420 const tcu::IVec4 colorFill (colorFillValue, 0, 0, 0xFF);
1421 const tcu::IVec4 colorDraw (colorDrawValue, 0, 0, 0xFF);
1422 const tcu::IVec4 colorTop (colorTopValue, 0, 0, 0xFF);
1423
1424 for (int y = 0; y < height; ++y)
1425 for (int x = 0; x < width; ++x)
1426 {
1427 const tcu::IVec4& validColor = (y < height / 2) ? colorFill
1428 : (x < width / 2) ? colorDraw
1429 : colorTop;
1430
1431 access.setPixel(validColor, x, y);
1432 }
1433 }
1434
1435 return image;
1436 }
1437
getVertices(void)1438 std::vector<float> DepthImagelessTestInstance::getVertices (void)
1439 {
1440 const float verticesData[] =
1441 {
1442 -1.0f, 0.0f, 0.50f, 1.0f,
1443 -1.0f, +1.0f, 0.50f, 1.0f,
1444 +1.0f, 0.0f, 0.50f, 1.0f,
1445 -1.0f, +1.0f, 0.50f, 1.0f,
1446 +1.0f, 0.0f, 0.50f, 1.0f,
1447 +1.0f, +1.0f, 0.50f, 1.0f,
1448
1449 0.0f, 0.0f, 0.25f, 1.0f,
1450 0.0f, +1.0f, 0.25f, 1.0f,
1451 +1.0f, 0.0f, 0.25f, 1.0f,
1452 0.0f, +1.0f, 0.25f, 1.0f,
1453 +1.0f, 0.0f, 0.25f, 1.0f,
1454 +1.0f, +1.0f, 0.25f, 1.0f,
1455 };
1456 const std::vector<float> vertices (verticesData, verticesData + DE_LENGTH_OF_ARRAY(verticesData));
1457
1458 return vertices;
1459 }
1460
iterate(void)1461 tcu::TestStatus DepthImagelessTestInstance::iterate (void)
1462 {
1463 const DeviceInterface& vk = m_context.getDeviceInterface();
1464 const VkDevice device = m_context.getDevice();
1465 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
1466 const VkQueue queue = m_context.getUniversalQueue();
1467 Allocator& allocator = m_context.getDefaultAllocator();
1468
1469 const deUint32 sampleCount = 1u;
1470 const VkSampleCountFlagBits sampleCountFlag = sampleCountBitFromSampleCount(sampleCount);
1471 const tcu::Vec4 clearColor = tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f);
1472 const VkFormat colorFormat = m_parameters.colorFormat;
1473 const VkDeviceSize colorBufferSize = m_imageExtent2D.width * m_imageExtent2D.height * tcu::getPixelSize(mapVkFormat(colorFormat));
1474 const VkImageSubresourceRange colorSubresRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u);
1475
1476 const Unique<VkImage> colorImage (makeImage (vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage)));
1477 const UniquePtr<Allocation> colorImageAlloc (bindImage (vk, device, allocator, *colorImage, MemoryRequirement::Any));
1478 const Unique<VkImageView> colorAttachment (makeImageView (vk, device, *colorImage, VK_IMAGE_VIEW_TYPE_2D, colorFormat, colorSubresRange));
1479 const Unique<VkBuffer> colorBuffer (makeBuffer (vk, device, colorBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT));
1480 const UniquePtr<Allocation> colorBufferAlloc (bindBuffer (vk, device, allocator, *colorBuffer, MemoryRequirement::HostVisible));
1481
1482 const float clearDepth = 1.0f;
1483 const deUint32 clearStencil = 0u;
1484 const VkFormat dsFormat = m_parameters.dsFormat;
1485 const deUint32 dsImagePixelSize = static_cast<deUint32>(tcu::getPixelSize(mapVkFormat(dsFormat)));
1486 const VkImageAspectFlags dsAspectFlags = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
1487 const VkImageSubresourceRange dsSubresRange = makeImageSubresourceRange(dsAspectFlags, 0u, 1u, 0u, 1u);
1488
1489 const VkDeviceSize depthBufferSize = m_imageExtent2D.width * m_imageExtent2D.height * dsImagePixelSize;
1490 const VkFormat stencilBufferFormat = getStencilBufferFormat(dsFormat);
1491 const deUint32 stencilPixelSize = static_cast<deUint32>(tcu::getPixelSize(mapVkFormat(stencilBufferFormat)));
1492 const VkDeviceSize stencilBufferSize = m_imageExtent2D.width * m_imageExtent2D.height * stencilPixelSize;
1493
1494 const Unique<VkImage> dsImage (makeImage (vk, device, makeImageCreateInfo(dsFormat, m_imageExtent2D, m_dsImageUsage)));
1495 const UniquePtr<Allocation> dsImageAlloc (bindImage (vk, device, allocator, *dsImage, MemoryRequirement::Any));
1496 const Unique<VkImageView> dsAttachment (makeImageView (vk, device, *dsImage, VK_IMAGE_VIEW_TYPE_2D, dsFormat, dsSubresRange));
1497 const Unique<VkBuffer> depthBuffer (makeBuffer (vk, device, depthBufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT));
1498 const UniquePtr<Allocation> depthBufferAlloc (bindBuffer (vk, device, allocator, *depthBuffer, MemoryRequirement::HostVisible));
1499 const Unique<VkBuffer> stencilBuffer (makeBuffer (vk, device, stencilBufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT));
1500 const UniquePtr<Allocation> stencilBufferAlloc (bindBuffer (vk, device, allocator, *stencilBuffer, MemoryRequirement::HostVisible));
1501
1502 const Unique<VkShaderModule> vertModule (createShaderModule (vk, device, m_context.getBinaryCollection().get("vert"), 0u));
1503 const Unique<VkShaderModule> fragModule (createShaderModule (vk, device, m_context.getBinaryCollection().get("frag"), 0u));
1504 const Unique<VkRenderPass> renderPass (makeRenderPass (vk, device, colorFormat, dsFormat, sampleCountFlag));
1505 const Unique<VkFramebuffer> framebuffer (makeFramebuffer (vk, device, *renderPass, m_imageExtent2D, &colorFormat, m_colorImageUsage, &dsFormat, m_dsImageUsage));
1506 const Unique<VkPipelineLayout> pipelineLayout (makePipelineLayout (vk, device));
1507 const Unique<VkPipeline> pipeline (makeGraphicsPipeline (vk, device, *pipelineLayout, *renderPass, *vertModule, *fragModule, m_imageExtent2D, ASPECT_DEPTH_STENCIL));
1508 const Unique<VkCommandPool> cmdPool (createCommandPool (vk, device, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, queueFamilyIndex));
1509 const Unique<VkCommandBuffer> cmdBuffer (allocateCommandBuffer (vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
1510
1511 const std::vector<float> vertexArray (getVertices());
1512 const deUint32 vertexCount (static_cast<deUint32>(vertexArray.size() / 4u));
1513 const VkDeviceSize vertexArraySize (vertexArray.size() * sizeof(vertexArray[0]));
1514 const Unique<VkBuffer> vertexBuffer (makeBuffer (vk, device, vertexArraySize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT));
1515 const UniquePtr<Allocation> vertexBufferAlloc (bindBuffer (vk, device, allocator, *vertexBuffer, MemoryRequirement::HostVisible));
1516 const VkDeviceSize vertexBufferOffset (0u);
1517
1518 fillBuffer(vk, device, *vertexBufferAlloc, &vertexArray[0], vertexArraySize);
1519
1520 beginCommandBuffer(vk, *cmdBuffer);
1521 {
1522 const VkImageView attachments[] = { *colorAttachment, *dsAttachment };
1523 const VkRenderPassAttachmentBeginInfo renderPassAttachmentBeginInfo =
1524 {
1525 VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO, // VkStructureType sType;
1526 DE_NULL, // const void* pNext;
1527 DE_LENGTH_OF_ARRAY(attachments), // deUint32 attachmentCount;
1528 attachments // const VkImageView* pAttachments;
1529 };
1530
1531 beginRenderPass(vk, *cmdBuffer, *renderPass, *framebuffer, makeRect2D(m_imageExtent2D), clearColor, clearDepth, clearStencil, &renderPassAttachmentBeginInfo);
1532 {
1533 vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
1534
1535 vk.cmdBindVertexBuffers(*cmdBuffer, 0u, 1u, &*vertexBuffer, &vertexBufferOffset);
1536
1537 vk.cmdDraw(*cmdBuffer, vertexCount, 1u, 0u, 0u);
1538 }
1539 endRenderPass(vk, *cmdBuffer);
1540
1541 // Color image copy
1542 {
1543 const VkImageMemoryBarrier preCopyBarrier = makeImageMemoryBarrier (VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
1544 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1545 *colorImage, colorSubresRange);
1546 const VkBufferImageCopy region = makeBufferImageCopy (makeExtent3D(m_imageExtent2D.width, m_imageExtent2D.height, 1u),
1547 makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u));
1548 const VkBufferMemoryBarrier postCopyBarrier = makeBufferMemoryBarrier (VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, *colorBuffer, 0ull, VK_WHOLE_SIZE);
1549
1550 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &preCopyBarrier);
1551 vk.cmdCopyImageToBuffer(*cmdBuffer, *colorImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *colorBuffer, 1u, ®ion);
1552 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, 1u, &postCopyBarrier, DE_NULL, 0u);
1553 }
1554
1555 // Depth/Stencil image copy
1556 {
1557 const VkImageMemoryBarrier preCopyBarrier = makeImageMemoryBarrier(VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
1558 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *dsImage, dsSubresRange);
1559 const VkBufferImageCopy depthCopyRegion = makeBufferImageCopy(makeExtent3D(m_imageExtent2D.width, m_imageExtent2D.height, 1u),
1560 makeImageSubresourceLayers(VK_IMAGE_ASPECT_DEPTH_BIT, 0u, 0u, 1u));
1561 const VkBufferImageCopy stencilCopyRegion = makeBufferImageCopy(makeExtent3D(m_imageExtent2D.width, m_imageExtent2D.height, 1u),
1562 makeImageSubresourceLayers(VK_IMAGE_ASPECT_STENCIL_BIT, 0u, 0u, 1u));
1563 const VkBufferMemoryBarrier postCopyBarriers[] =
1564 {
1565 makeBufferMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, *depthBuffer, 0ull, VK_WHOLE_SIZE),
1566 makeBufferMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, *stencilBuffer, 0ull, VK_WHOLE_SIZE),
1567 };
1568
1569 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &preCopyBarrier);
1570 vk.cmdCopyImageToBuffer(*cmdBuffer, *dsImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *depthBuffer, 1u, &depthCopyRegion);
1571 vk.cmdCopyImageToBuffer(*cmdBuffer, *dsImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *stencilBuffer, 1u, &stencilCopyRegion);
1572 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, DE_LENGTH_OF_ARRAY(postCopyBarriers), postCopyBarriers, DE_NULL, 0u);
1573 }
1574 }
1575 endCommandBuffer(vk, *cmdBuffer);
1576 submitCommandsAndWait(vk, device, queue, *cmdBuffer);
1577
1578 {
1579 std::string result;
1580
1581 if (!verifyBuffer(colorBufferAlloc, colorFormat, "Color", ASPECT_COLOR))
1582 result += " Color";
1583
1584 if (!verifyBuffer(depthBufferAlloc, dsFormat, "Depth", ASPECT_DEPTH))
1585 result += " Depth";
1586
1587 if (!verifyBuffer(stencilBufferAlloc, stencilBufferFormat, "Stencil", ASPECT_STENCIL))
1588 result += " Stencil";
1589
1590 if (result.empty())
1591 return tcu::TestStatus::pass("Pass");
1592 else
1593 return tcu::TestStatus::fail("Following parts of image are incorrect:" + result);
1594 }
1595 }
1596
1597 class ColorResolveImagelessTestInstance : public ColorImagelessTestInstance
1598 {
1599 public:
1600 ColorResolveImagelessTestInstance (Context& context, const TestParameters& parameters);
1601 protected:
1602 virtual tcu::TestStatus iterate (void);
1603
1604 virtual MovePtr<tcu::TextureLevel> generateReferenceImage (const tcu::TextureFormat& textureFormat,
1605 const AspectFlags aspectFlags,
1606 const deUint32 sample,
1607 const deUint32 subpass);
1608
1609 virtual std::vector<float> getVertices (void);
1610 };
1611
ColorResolveImagelessTestInstance(Context & context,const TestParameters & parameters)1612 ColorResolveImagelessTestInstance::ColorResolveImagelessTestInstance (Context& context, const TestParameters& parameters)
1613 : ColorImagelessTestInstance (context, parameters)
1614 {
1615 const InstanceInterface& vki = m_context.getInstanceInterface();
1616 const VkPhysicalDevice physDevice = m_context.getPhysicalDevice();
1617
1618 // To validate per-sample image image must also be sampled
1619 m_colorImageUsage |= VK_IMAGE_USAGE_SAMPLED_BIT;
1620
1621 checkImageFormatProperties(vki, physDevice, m_parameters.colorFormat, m_colorImageUsage, m_imageExtent2D);
1622 }
1623
generateReferenceImage(const tcu::TextureFormat & textureFormat,const AspectFlags aspectFlags,const deUint32 sample,const deUint32 subpass)1624 MovePtr<tcu::TextureLevel> ColorResolveImagelessTestInstance::generateReferenceImage (const tcu::TextureFormat& textureFormat,
1625 const AspectFlags aspectFlags,
1626 const deUint32 sample,
1627 const deUint32 subpass)
1628 {
1629 const int width = m_imageExtent2D.width;
1630 const int height = m_imageExtent2D.height;
1631 MovePtr<tcu::TextureLevel> image (new tcu::TextureLevel(textureFormat, width, height));
1632 tcu::PixelBufferAccess access (image->getAccess());
1633 const int componentValue (static_cast<int>(0.75f * 0x100));
1634 const tcu::RGBA colorDrawRGBA (tcu::RGBA(componentValue, componentValue, componentValue, 0xFF));
1635 const tcu::Vec4 colorDraw (colorDrawRGBA.toVec());
1636 const tcu::Vec4 colorFill (tcu::RGBA::black().toVec());
1637 const tcu::Vec4 colorEdge0 (colorDraw);
1638 const tcu::Vec4 colorEdge1 (colorFill);
1639 const tcu::Vec4 colorEdge2 (colorDraw);
1640 const tcu::Vec4 colorEdge3 (colorFill);
1641 const tcu::Vec4 colorEdgeR ((colorDraw.x() + colorFill.x()) / 2, (colorDraw.y() + colorFill.y()) / 2, (colorDraw.z() + colorFill.z()) / 2, colorDraw.w()); // AVERAGE
1642 const tcu::Vec4& colorEdge = sample == 0 ? colorEdge0
1643 : sample == 1 ? colorEdge1
1644 : sample == 2 ? colorEdge2
1645 : sample == 3 ? colorEdge3
1646 : colorEdgeR;
1647
1648 DE_UNREF(aspectFlags);
1649 DE_ASSERT(dePop32(aspectFlags) == 1);
1650 DE_ASSERT(aspectFlags == ASPECT_COLOR);
1651 DE_UNREF(subpass);
1652 DE_ASSERT(subpass == NO_SUBPASS);
1653
1654 for (int y = 0; y < height; ++y)
1655 for (int x = 0; x < width; ++x)
1656 {
1657 const int mx = width - 1 - x;
1658 const tcu::Vec4& validColor = (y == mx) ? colorEdge
1659 : (y > mx) ? colorFill
1660 : colorDraw;
1661
1662 access.setPixel(validColor, x, y);
1663 }
1664
1665 return image;
1666 }
1667
getVertices(void)1668 std::vector<float> ColorResolveImagelessTestInstance::getVertices (void)
1669 {
1670 const float verticesData[] =
1671 {
1672 -1.0f, -1.0f, 0.0f, 1.0f,
1673 -1.0f, +1.0f, 0.0f, 1.0f,
1674 +1.0f, -1.0f, 0.0f, 1.0f,
1675 };
1676 const std::vector<float> vertices (verticesData, verticesData + DE_LENGTH_OF_ARRAY(verticesData));
1677
1678 return vertices;
1679 }
1680
iterate(void)1681 tcu::TestStatus ColorResolveImagelessTestInstance::iterate (void)
1682 {
1683 const DeviceInterface& vk = m_context.getDeviceInterface();
1684 const VkDevice device = m_context.getDevice();
1685 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
1686 const VkQueue queue = m_context.getUniversalQueue();
1687 Allocator& allocator = m_context.getDefaultAllocator();
1688
1689 const VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_4_BIT;
1690 const tcu::Vec4 clearColor = tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f);
1691 const VkFormat colorFormat = m_parameters.colorFormat;
1692 const VkDeviceSize colorBufferSize = m_imageExtent2D.width * m_imageExtent2D.height * tcu::getPixelSize(mapVkFormat(colorFormat));
1693 const VkImageSubresourceRange colorSubresRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u);
1694
1695 const Unique<VkImage> colorImage (makeImage (vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage, sampleCount)));
1696 const UniquePtr<Allocation> colorImageAlloc (bindImage (vk, device, allocator, *colorImage, MemoryRequirement::Any));
1697 const Unique<VkImageView> colorAttachment (makeImageView (vk, device, *colorImage, VK_IMAGE_VIEW_TYPE_2D, colorFormat, colorSubresRange));
1698
1699 const Unique<VkImage> colorResolveImage (makeImage (vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage)));
1700 const UniquePtr<Allocation> colorResolveImageAlloc (bindImage (vk, device, allocator, *colorResolveImage, MemoryRequirement::Any));
1701 const Unique<VkImageView> colorResolveAttachment (makeImageView (vk, device, *colorResolveImage, VK_IMAGE_VIEW_TYPE_2D, colorFormat, colorSubresRange));
1702 const Unique<VkBuffer> colorResolveBuffer (makeBuffer (vk, device, colorBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT));
1703 const UniquePtr<Allocation> colorResolveBufferAlloc (bindBuffer (vk, device, allocator, *colorResolveBuffer, MemoryRequirement::HostVisible));
1704
1705 const Unique<VkShaderModule> vertModule (createShaderModule (vk, device, m_context.getBinaryCollection().get("vert"), 0u));
1706 const Unique<VkShaderModule> fragModule (createShaderModule (vk, device, m_context.getBinaryCollection().get("frag"), 0u));
1707 const Unique<VkRenderPass> renderPass (makeRenderPass (vk, device, colorFormat, m_parameters.dsFormat, sampleCount));
1708 const Unique<VkFramebuffer> framebuffer (makeFramebuffer (vk, device, *renderPass, m_imageExtent2D, &colorFormat, m_colorImageUsage, &m_parameters.dsFormat, 0u, ASPECT_COLOR));
1709 const Unique<VkPipelineLayout> pipelineLayout (makePipelineLayout (vk, device));
1710 const Unique<VkPipeline> pipeline (makeGraphicsPipeline (vk, device, *pipelineLayout, *renderPass, *vertModule, *fragModule, m_imageExtent2D, ASPECT_NONE, sampleCount));
1711 const Unique<VkCommandPool> cmdPool (createCommandPool (vk, device, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, queueFamilyIndex));
1712 const Unique<VkCommandBuffer> cmdBuffer (allocateCommandBuffer (vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
1713
1714 const std::vector<float> vertexArray (getVertices());
1715 const deUint32 vertexCount (static_cast<deUint32>(vertexArray.size() / 4u));
1716 const VkDeviceSize vertexArraySize (vertexArray.size() * sizeof(vertexArray[0]));
1717 const Unique<VkBuffer> vertexBuffer (makeBuffer (vk, device, vertexArraySize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT));
1718 const UniquePtr<Allocation> vertexBufferAlloc (bindBuffer (vk, device, allocator, *vertexBuffer, MemoryRequirement::HostVisible));
1719 const VkDeviceSize vertexBufferOffset (0u);
1720
1721 fillBuffer(vk, device, *vertexBufferAlloc, &vertexArray[0], vertexArraySize);
1722
1723 beginCommandBuffer(vk, *cmdBuffer);
1724 {
1725 const VkImageView attachments[] = { *colorAttachment, *colorResolveAttachment };
1726 const VkRenderPassAttachmentBeginInfo renderPassAttachmentBeginInfo =
1727 {
1728 VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO, // VkStructureType sType;
1729 DE_NULL, // const void* pNext;
1730 DE_LENGTH_OF_ARRAY(attachments), // deUint32 attachmentCount;
1731 attachments // const VkImageView* pAttachments;
1732 };
1733
1734 beginRenderPass(vk, *cmdBuffer, *renderPass, *framebuffer, makeRect2D(m_imageExtent2D), clearColor, &renderPassAttachmentBeginInfo);
1735 {
1736 vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
1737
1738 vk.cmdBindVertexBuffers(*cmdBuffer, 0u, 1u, &*vertexBuffer, &vertexBufferOffset);
1739
1740 vk.cmdDraw(*cmdBuffer, vertexCount, 1u, 0u, 0u);
1741 }
1742 endRenderPass(vk, *cmdBuffer);
1743
1744 // Color image copy
1745 {
1746 const VkImageMemoryBarrier preCopyBarrier = makeImageMemoryBarrier (VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
1747 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1748 *colorResolveImage, colorSubresRange);
1749 const VkBufferImageCopy region = makeBufferImageCopy (makeExtent3D(m_imageExtent2D.width, m_imageExtent2D.height, 1u),
1750 makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u));
1751 const VkBufferMemoryBarrier postCopyBarrier = makeBufferMemoryBarrier (VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, *colorResolveBuffer, 0ull, VK_WHOLE_SIZE);
1752
1753 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &preCopyBarrier);
1754 vk.cmdCopyImageToBuffer(*cmdBuffer, *colorResolveImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *colorResolveBuffer, 1u, ®ion);
1755 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, 1u, &postCopyBarrier, DE_NULL, 0u);
1756 }
1757 }
1758 endCommandBuffer(vk, *cmdBuffer);
1759 submitCommandsAndWait(vk, device, queue, *cmdBuffer);
1760
1761 {
1762 std::string result;
1763
1764 if (!verifyBuffer(colorResolveBufferAlloc, colorFormat, "ResolveColor", ASPECT_COLOR))
1765 result += " ResolveColor";
1766
1767 // Parse color aspect of separate samples of multisample image
1768 for (deUint32 sampleNdx = 0; sampleNdx < sampleCount; ++sampleNdx)
1769 {
1770 const std::string name ("Color" + de::toString(sampleNdx));
1771 const Unique<VkImage> imageSample (makeImage (vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage)));
1772 const UniquePtr<Allocation> imageSampleAlloc (bindImage (vk, device, allocator, *imageSample, MemoryRequirement::Any));
1773 const Unique<VkBuffer> imageBuffer (makeBuffer (vk, device, colorBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT));
1774 const UniquePtr<Allocation> imageBufferAlloc (bindBuffer (vk, device, allocator, *imageBuffer, MemoryRequirement::HostVisible));
1775
1776 readOneSampleFromMultisampleImage(colorFormat, colorImage, sampleNdx, colorFormat, imageSample, imageBuffer, ASPECT_COLOR);
1777
1778 if (!verifyBuffer(imageBufferAlloc, colorFormat, name, ASPECT_COLOR, sampleNdx))
1779 result += " " + name;
1780 }
1781
1782
1783 if (result.empty())
1784 return tcu::TestStatus::pass("Pass");
1785 else
1786 return tcu::TestStatus::fail("Fail");
1787 }
1788 }
1789
1790 class DepthResolveImagelessTestInstance : public DepthImagelessTestInstance
1791 {
1792 public:
1793 DepthResolveImagelessTestInstance (Context& context, const TestParameters& parameters);
1794
1795 protected:
1796 virtual tcu::TestStatus iterate (void);
1797
1798 virtual MovePtr<tcu::TextureLevel> generateReferenceImage (const tcu::TextureFormat& textureFormat,
1799 const AspectFlags aspectFlags,
1800 const deUint32 sample,
1801 const deUint32 subpass);
1802
1803 virtual std::vector<float> getVertices (void);
1804 };
1805
DepthResolveImagelessTestInstance(Context & context,const TestParameters & parameters)1806 DepthResolveImagelessTestInstance::DepthResolveImagelessTestInstance (Context& context, const TestParameters& parameters)
1807 : DepthImagelessTestInstance (context, parameters)
1808 {
1809 context.requireDeviceFunctionality("VK_KHR_depth_stencil_resolve");
1810
1811 const InstanceInterface& vki = m_context.getInstanceInterface();
1812 const VkPhysicalDevice physDevice = m_context.getPhysicalDevice();
1813 VkPhysicalDeviceProperties2 deviceProperties;
1814 VkPhysicalDeviceDepthStencilResolveProperties dsResolveProperties;
1815
1816 deMemset(&deviceProperties, 0, sizeof(deviceProperties));
1817 deMemset(&dsResolveProperties, 0, sizeof(dsResolveProperties));
1818
1819 deviceProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
1820 deviceProperties.pNext = &dsResolveProperties;
1821
1822 dsResolveProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES;
1823 dsResolveProperties.pNext = DE_NULL;
1824
1825 vki.getPhysicalDeviceProperties2(physDevice, &deviceProperties);
1826
1827 m_colorImageUsage |= VK_IMAGE_USAGE_SAMPLED_BIT;
1828
1829 checkImageFormatProperties(vki, physDevice, m_parameters.colorFormat, m_colorImageUsage, m_imageExtent2D);
1830
1831 m_dsImageUsage |= VK_IMAGE_USAGE_SAMPLED_BIT;
1832
1833 checkImageFormatProperties(vki, physDevice, m_parameters.dsFormat, m_dsImageUsage, m_imageExtent2D);
1834 }
1835
generateReferenceImage(const tcu::TextureFormat & textureFormat,const AspectFlags aspectFlags,const deUint32 sample,const deUint32 subpass)1836 MovePtr<tcu::TextureLevel> DepthResolveImagelessTestInstance::generateReferenceImage (const tcu::TextureFormat& textureFormat,
1837 const AspectFlags aspectFlags,
1838 const deUint32 sample,
1839 const deUint32 subpass)
1840 {
1841 const bool color = ((aspectFlags & ASPECT_COLOR) != 0);
1842 const bool depth = ((aspectFlags & ASPECT_DEPTH) != 0);
1843 const bool stencil = ((aspectFlags & ASPECT_STENCIL) != 0);
1844 const int width = m_imageExtent2D.width;
1845 const int height = m_imageExtent2D.height;
1846 MovePtr<tcu::TextureLevel> image (new tcu::TextureLevel(textureFormat, width, height));
1847 tcu::PixelBufferAccess access (image->getAccess());
1848
1849 DE_ASSERT(dePop32(aspectFlags) == 1);
1850 DE_UNREF(subpass);
1851
1852 if (color)
1853 {
1854 const tcu::Vec4 colorDraw (tcu::RGBA::blue().toVec());
1855 const tcu::Vec4 colorFill (tcu::RGBA::black().toVec());
1856 const tcu::Vec4 colorEdge0 (colorDraw);
1857 const tcu::Vec4 colorEdge1 (colorFill);
1858 const tcu::Vec4 colorEdge2 (colorDraw);
1859 const tcu::Vec4 colorEdge3 (colorFill);
1860 const tcu::Vec4 colorEdgeR ((colorDraw.x() + colorFill.x()) / 2, (colorDraw.y() + colorFill.y()) / 2, (colorDraw.z() + colorFill.z()) / 2, colorDraw.w()); // AVERAGE
1861 const tcu::Vec4& colorEdge = sample == 0 ? colorEdge0
1862 : sample == 1 ? colorEdge1
1863 : sample == 2 ? colorEdge2
1864 : sample == 3 ? colorEdge3
1865 : colorEdgeR;
1866
1867 for (int y = 0; y < height; ++y)
1868 for (int x = 0; x < width; ++x)
1869 {
1870 const int mx = width - 1 - x;
1871 const tcu::Vec4& validColor = (y == mx) ? colorEdge
1872 : (y > mx) ? colorFill
1873 : colorDraw;
1874
1875 access.setPixel(validColor, x, y);
1876 }
1877 }
1878
1879 if (depth)
1880 {
1881 const int colorFillValue (static_cast<int>(1.00f * 0x100));
1882 const int colorDrawValue (static_cast<int>(0.00f * 0x100));
1883 const tcu::IVec4 colorFill (colorFillValue, colorFillValue, colorFillValue, 0xFF);
1884 const tcu::IVec4 colorDraw (colorDrawValue, colorDrawValue, colorDrawValue, 0xFF);
1885 const tcu::IVec4 colorEdge0 (colorDraw);
1886 const tcu::IVec4 colorEdge1 (colorFill);
1887 const tcu::IVec4 colorEdge2 (colorDraw);
1888 const tcu::IVec4 colorEdge3 (colorFill);
1889 const tcu::IVec4 colorEdgeR (colorEdge0); // SAMPLE_ZERO
1890 const tcu::IVec4& colorEdge = sample == 0 ? colorEdge0
1891 : sample == 1 ? colorEdge1
1892 : sample == 2 ? colorEdge2
1893 : sample == 3 ? colorEdge3
1894 : colorEdgeR;
1895
1896 for (int y = 0; y < height; ++y)
1897 for (int x = 0; x < width; ++x)
1898 {
1899 const int mx = width - 1 - x;
1900 const tcu::IVec4& validColor = (y == mx) ? colorEdge
1901 : (y > mx) ? colorFill
1902 : colorDraw;
1903
1904 access.setPixel(validColor, x, y);
1905 }
1906 }
1907
1908 if (stencil)
1909 {
1910 const int colorFillValue ((0 * 0x100) / 4);
1911 const int colorDrawValue ((1 * 0x100) / 4);
1912 const tcu::IVec4 colorFill (colorFillValue, colorFillValue, colorFillValue, 0xFF);
1913 const tcu::IVec4 colorDraw (colorDrawValue, colorDrawValue, colorDrawValue, 0xFF);
1914 const tcu::IVec4 colorEdge0 (colorDraw);
1915 const tcu::IVec4 colorEdge1 (colorFill);
1916 const tcu::IVec4 colorEdge2 (colorDraw);
1917 const tcu::IVec4 colorEdge3 (colorFill);
1918 const tcu::IVec4 colorEdgeR (colorEdge0); // SAMPLE_ZERO
1919 const tcu::IVec4& colorEdge = sample == 0 ? colorEdge0
1920 : sample == 1 ? colorEdge1
1921 : sample == 2 ? colorEdge2
1922 : sample == 3 ? colorEdge3
1923 : colorEdgeR;
1924
1925 for (int y = 0; y < height; ++y)
1926 for (int x = 0; x < width; ++x)
1927 {
1928 const int mx = width - 1 - x;
1929 const tcu::IVec4& validColor = (y == mx) ? colorEdge
1930 : (y > mx) ? colorFill
1931 : colorDraw;
1932
1933 access.setPixel(validColor, x, y);
1934 }
1935 }
1936
1937 return image;
1938 }
1939
getVertices(void)1940 std::vector<float> DepthResolveImagelessTestInstance::getVertices (void)
1941 {
1942 const float verticesData[] =
1943 {
1944 -1.0f, -1.0f, 0.0f, 1.0f,
1945 -1.0f, +1.0f, 0.0f, 1.0f,
1946 +1.0f, -1.0f, 0.0f, 1.0f,
1947 -1.0f, -1.0f, 0.5f, 1.0f,
1948 -1.0f, +1.0f, 0.5f, 1.0f,
1949 +1.0f, -1.0f, 0.5f, 1.0f,
1950 };
1951 const std::vector<float> vertices (verticesData, verticesData + DE_LENGTH_OF_ARRAY(verticesData));
1952
1953 return vertices;
1954 }
1955
iterate(void)1956 tcu::TestStatus DepthResolveImagelessTestInstance::iterate (void)
1957 {
1958 const DeviceInterface& vk = m_context.getDeviceInterface();
1959 const VkDevice device = m_context.getDevice();
1960 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
1961 const VkQueue queue = m_context.getUniversalQueue();
1962 Allocator& allocator = m_context.getDefaultAllocator();
1963
1964 const deUint32 sampleCount = 4u;
1965 const VkSampleCountFlagBits sampleCountFlag = sampleCountBitFromSampleCount(sampleCount);
1966 const tcu::Vec4 clearColor = tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f);
1967 const VkFormat colorFormat = m_parameters.colorFormat;
1968 const VkDeviceSize colorBufferSize = m_imageExtent2D.width * m_imageExtent2D.height * tcu::getPixelSize(mapVkFormat(colorFormat));
1969 const VkImageSubresourceRange colorSubresRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u);
1970
1971 const Unique<VkImage> colorImage (makeImage (vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage, sampleCountFlag)));
1972 const UniquePtr<Allocation> colorImageAlloc (bindImage (vk, device, allocator, *colorImage, MemoryRequirement::Any));
1973 const Unique<VkImageView> colorAttachment (makeImageView (vk, device, *colorImage, VK_IMAGE_VIEW_TYPE_2D, colorFormat, colorSubresRange));
1974
1975 const Unique<VkImage> colorResolveImage (makeImage (vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage)));
1976 const UniquePtr<Allocation> colorResolveImageAlloc (bindImage (vk, device, allocator, *colorResolveImage, MemoryRequirement::Any));
1977 const Unique<VkImageView> colorResolveAttachment (makeImageView (vk, device, *colorResolveImage, VK_IMAGE_VIEW_TYPE_2D, colorFormat, colorSubresRange));
1978 const Unique<VkBuffer> colorResolveBuffer (makeBuffer (vk, device, colorBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT));
1979 const UniquePtr<Allocation> colorResolveBufferAlloc (bindBuffer (vk, device, allocator, *colorResolveBuffer, MemoryRequirement::HostVisible));
1980
1981 const float clearDepth = 1.0f;
1982 const deUint32 clearStencil = 0u;
1983 const VkFormat dsFormat = m_parameters.dsFormat;
1984 const deUint32 dsImagePixelSize = static_cast<deUint32>(tcu::getPixelSize(mapVkFormat(dsFormat)));
1985 const VkImageAspectFlags dsAspectFlags = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
1986 const VkImageSubresourceRange dsSubresRange = makeImageSubresourceRange(dsAspectFlags, 0u, 1u, 0u, 1u);
1987
1988 const VkDeviceSize depthBufferSize = m_imageExtent2D.width * m_imageExtent2D.height * dsImagePixelSize;
1989 const VkFormat stencilBufferFormat = getStencilBufferFormat(dsFormat);
1990 const deUint32 stencilPixelSize = static_cast<deUint32>(tcu::getPixelSize(mapVkFormat(stencilBufferFormat)));
1991 const VkDeviceSize stencilBufferSize = m_imageExtent2D.width * m_imageExtent2D.height * stencilPixelSize;
1992
1993 const Unique<VkImage> dsImage (makeImage (vk, device, makeImageCreateInfo(dsFormat, m_imageExtent2D, m_dsImageUsage, sampleCountFlag)));
1994 const UniquePtr<Allocation> dsImageAlloc (bindImage (vk, device, allocator, *dsImage, MemoryRequirement::Any));
1995 const Unique<VkImageView> dsAttachment (makeImageView (vk, device, *dsImage, VK_IMAGE_VIEW_TYPE_2D, dsFormat, dsSubresRange));
1996
1997 const Unique<VkImage> dsResolveImage (makeImage (vk, device, makeImageCreateInfo(dsFormat, m_imageExtent2D, m_dsImageUsage)));
1998 const UniquePtr<Allocation> dsResolveImageAlloc (bindImage (vk, device, allocator, *dsResolveImage, MemoryRequirement::Any));
1999 const Unique<VkImageView> dsResolveAttachment (makeImageView (vk, device, *dsResolveImage, VK_IMAGE_VIEW_TYPE_2D, dsFormat, dsSubresRange));
2000 const Unique<VkBuffer> depthResolveBuffer (makeBuffer (vk, device, depthBufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT));
2001 const UniquePtr<Allocation> depthResolveBufferAlloc (bindBuffer (vk, device, allocator, *depthResolveBuffer, MemoryRequirement::HostVisible));
2002 const Unique<VkBuffer> stencilResolveBuffer (makeBuffer (vk, device, stencilBufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT));
2003 const UniquePtr<Allocation> stencilResolveBufferAlloc (bindBuffer (vk, device, allocator, *stencilResolveBuffer, MemoryRequirement::HostVisible));
2004
2005 const Unique<VkShaderModule> vertModule (createShaderModule (vk, device, m_context.getBinaryCollection().get("vert"), 0u));
2006 const Unique<VkShaderModule> fragModule (createShaderModule (vk, device, m_context.getBinaryCollection().get("frag"), 0u));
2007 const Unique<VkRenderPass> renderPass (makeRenderPass (vk, device, colorFormat, m_parameters.dsFormat, sampleCountFlag, sampleCountFlag));
2008 const Unique<VkFramebuffer> framebuffer (makeFramebuffer (vk, device, *renderPass, m_imageExtent2D, &colorFormat, m_colorImageUsage, &m_parameters.dsFormat, m_dsImageUsage, ASPECT_COLOR|ASPECT_DEPTH_STENCIL));
2009 const Unique<VkPipelineLayout> pipelineLayout (makePipelineLayout (vk, device));
2010 const Unique<VkPipeline> pipeline (makeGraphicsPipeline (vk, device, *pipelineLayout, *renderPass, *vertModule, *fragModule, m_imageExtent2D, ASPECT_DEPTH_STENCIL, sampleCountFlag));
2011 const Unique<VkCommandPool> cmdPool (createCommandPool (vk, device, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, queueFamilyIndex));
2012 const Unique<VkCommandBuffer> cmdBuffer (allocateCommandBuffer (vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
2013
2014 const std::vector<float> vertexArray (getVertices());
2015 const deUint32 vertexCount (static_cast<deUint32>(vertexArray.size() / 4u));
2016 const VkDeviceSize vertexArraySize (vertexArray.size() * sizeof(vertexArray[0]));
2017 const Unique<VkBuffer> vertexBuffer (makeBuffer (vk, device, vertexArraySize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT));
2018 const UniquePtr<Allocation> vertexBufferAlloc (bindBuffer (vk, device, allocator, *vertexBuffer, MemoryRequirement::HostVisible));
2019 const VkDeviceSize vertexBufferOffset (0u);
2020
2021 fillBuffer(vk, device, *vertexBufferAlloc, &vertexArray[0], vertexArraySize);
2022
2023 beginCommandBuffer(vk, *cmdBuffer);
2024 {
2025 const VkImageView attachments[] = { *colorAttachment, *dsAttachment, *colorResolveAttachment, *dsResolveAttachment };
2026 const VkRenderPassAttachmentBeginInfo renderPassAttachmentBeginInfo =
2027 {
2028 VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO, // VkStructureType sType;
2029 DE_NULL, // const void* pNext;
2030 DE_LENGTH_OF_ARRAY(attachments), // deUint32 attachmentCount;
2031 attachments // const VkImageView* pAttachments;
2032 };
2033
2034 beginRenderPass(vk, *cmdBuffer, *renderPass, *framebuffer, makeRect2D(m_imageExtent2D), clearColor, clearDepth, clearStencil, &renderPassAttachmentBeginInfo);
2035 {
2036 vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
2037
2038 vk.cmdBindVertexBuffers(*cmdBuffer, 0u, 1u, &*vertexBuffer, &vertexBufferOffset);
2039
2040 vk.cmdDraw(*cmdBuffer, vertexCount, 1u, 0u, 0u);
2041 }
2042 endRenderPass(vk, *cmdBuffer);
2043
2044 // Color resolve image copy
2045 {
2046 const VkImageMemoryBarrier preCopyBarrier = makeImageMemoryBarrier (VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
2047 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
2048 *colorResolveImage, colorSubresRange);
2049 const VkBufferImageCopy region = makeBufferImageCopy (makeExtent3D(m_imageExtent2D.width, m_imageExtent2D.height, 1u),
2050 makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u));
2051 const VkBufferMemoryBarrier postCopyBarrier = makeBufferMemoryBarrier (VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, *colorResolveBuffer, 0ull, VK_WHOLE_SIZE);
2052
2053 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &preCopyBarrier);
2054 vk.cmdCopyImageToBuffer(*cmdBuffer, *colorResolveImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *colorResolveBuffer, 1u, ®ion);
2055 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, 1u, &postCopyBarrier, DE_NULL, 0u);
2056 }
2057
2058 // Depth/Stencil resolve image copy
2059 {
2060 const VkImageMemoryBarrier preCopyBarrier = makeImageMemoryBarrier(0u, VK_ACCESS_TRANSFER_READ_BIT,
2061 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
2062 *dsResolveImage, dsSubresRange);
2063 const VkBufferImageCopy depthCopyRegion = makeBufferImageCopy(makeExtent3D(m_imageExtent2D.width, m_imageExtent2D.height, 1u),
2064 makeImageSubresourceLayers(VK_IMAGE_ASPECT_DEPTH_BIT, 0u, 0u, 1u));
2065 const VkBufferImageCopy stencilCopyRegion = makeBufferImageCopy(makeExtent3D(m_imageExtent2D.width, m_imageExtent2D.height, 1u),
2066 makeImageSubresourceLayers(VK_IMAGE_ASPECT_STENCIL_BIT, 0u, 0u, 1u));
2067 const VkBufferMemoryBarrier postCopyBarriers[] =
2068 {
2069 makeBufferMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, *depthResolveBuffer, 0ull, VK_WHOLE_SIZE),
2070 makeBufferMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, *stencilResolveBuffer, 0ull, VK_WHOLE_SIZE),
2071 };
2072
2073 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &preCopyBarrier);
2074 vk.cmdCopyImageToBuffer(*cmdBuffer, *dsResolveImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *depthResolveBuffer, 1u, &depthCopyRegion);
2075 vk.cmdCopyImageToBuffer(*cmdBuffer, *dsResolveImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *stencilResolveBuffer, 1u, &stencilCopyRegion);
2076 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, DE_LENGTH_OF_ARRAY(postCopyBarriers), postCopyBarriers, DE_NULL, 0u);
2077 }
2078 }
2079 endCommandBuffer(vk, *cmdBuffer);
2080 submitCommandsAndWait(vk, device, queue, *cmdBuffer);
2081
2082 {
2083 std::string result;
2084
2085 if (!verifyBuffer(colorResolveBufferAlloc, colorFormat, "ResolveColor", ASPECT_COLOR))
2086 result += " ResolveColor";
2087
2088 if (!verifyBuffer(depthResolveBufferAlloc, dsFormat, "ResolveDepth", ASPECT_DEPTH))
2089 result += " ResolveDepth";
2090
2091 if (!verifyBuffer(stencilResolveBufferAlloc, stencilBufferFormat, "ResolveStencil", ASPECT_STENCIL))
2092 result += " ResolveStencil";
2093
2094 // Parse color aspect of separate samples of multisample image
2095 for (deUint32 sampleNdx = 0; sampleNdx < sampleCount; ++sampleNdx)
2096 {
2097 const std::string name ("Color" + de::toString(sampleNdx));
2098 const Unique<VkImage> imageSample (makeImage (vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage)));
2099 const UniquePtr<Allocation> imageSampleAlloc (bindImage (vk, device, allocator, *imageSample, MemoryRequirement::Any));
2100 const Unique<VkBuffer> imageBuffer (makeBuffer (vk, device, colorBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT));
2101 const UniquePtr<Allocation> imageBufferAlloc (bindBuffer (vk, device, allocator, *imageBuffer, MemoryRequirement::HostVisible));
2102
2103 readOneSampleFromMultisampleImage(colorFormat, colorImage, sampleNdx, colorFormat, imageSample, imageBuffer, ASPECT_COLOR);
2104
2105 if (!verifyBuffer(imageBufferAlloc, colorFormat, name, ASPECT_COLOR, sampleNdx))
2106 result += " " + name;
2107 }
2108
2109 // Parse depth aspect of separate samples of multisample image
2110 for (deUint32 sampleNdx = 0; sampleNdx < sampleCount; ++sampleNdx)
2111 {
2112 const std::string name ("Depth" + de::toString(sampleNdx));
2113 const Unique<VkImage> imageSample (makeImage (vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage)));
2114 const UniquePtr<Allocation> imageSampleAlloc (bindImage (vk, device, allocator, *imageSample, MemoryRequirement::Any));
2115 const Unique<VkBuffer> imageBuffer (makeBuffer (vk, device, colorBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT));
2116 const UniquePtr<Allocation> imageBufferAlloc (bindBuffer (vk, device, allocator, *imageBuffer, MemoryRequirement::HostVisible));
2117
2118 readOneSampleFromMultisampleImage(dsFormat, dsImage, sampleNdx, colorFormat, imageSample, imageBuffer, ASPECT_DEPTH);
2119
2120 if (!verifyBuffer(imageBufferAlloc, colorFormat, name, ASPECT_DEPTH, sampleNdx))
2121 result += " " + name;
2122 }
2123
2124 // Parse stencil aspect of separate samples of multisample image
2125 for (deUint32 sampleNdx = 0; sampleNdx < sampleCount; ++sampleNdx)
2126 {
2127 const std::string name ("Stencil" + de::toString(sampleNdx));
2128 const Unique<VkImage> imageSample (makeImage (vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage)));
2129 const UniquePtr<Allocation> imageSampleAlloc (bindImage (vk, device, allocator, *imageSample, MemoryRequirement::Any));
2130 const Unique<VkBuffer> imageBuffer (makeBuffer (vk, device, colorBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT));
2131 const UniquePtr<Allocation> imageBufferAlloc (bindBuffer (vk, device, allocator, *imageBuffer, MemoryRequirement::HostVisible));
2132
2133 readOneSampleFromMultisampleImage(dsFormat, dsImage, sampleNdx, colorFormat, imageSample, imageBuffer, ASPECT_STENCIL);
2134
2135 if (!verifyBuffer(imageBufferAlloc, colorFormat, name, ASPECT_STENCIL, sampleNdx))
2136 result += " " + name;
2137 }
2138
2139 if (result.empty())
2140 return tcu::TestStatus::pass("Pass");
2141 else
2142 return tcu::TestStatus::fail("Following parts of image are incorrect:" + result);
2143 }
2144 }
2145
2146 class MultisubpassTestInstance : public ColorImagelessTestInstance
2147 {
2148 public:
2149 MultisubpassTestInstance (Context& context, const TestParameters& parameters);
2150
2151 protected:
2152 virtual tcu::TestStatus iterate (void);
2153
2154 virtual std::vector<float> getVertices (void);
2155
2156 virtual MovePtr<tcu::TextureLevel> generateReferenceImage (const tcu::TextureFormat& textureFormat,
2157 const AspectFlags aspectFlags,
2158 const deUint32 sample,
2159 const deUint32 subpass);
2160 };
2161
MultisubpassTestInstance(Context & context,const TestParameters & parameters)2162 MultisubpassTestInstance::MultisubpassTestInstance (Context& context, const TestParameters& parameters)
2163 : ColorImagelessTestInstance (context, parameters)
2164 {
2165 }
2166
getVertices(void)2167 std::vector<float> MultisubpassTestInstance::getVertices (void)
2168 {
2169 const float verticesData[] =
2170 {
2171 -1.0f, 0.0f, 0.0f, 1.0f,
2172 -1.0f, +1.0f, 0.0f, 1.0f,
2173 +1.0f, 0.0f, 0.0f, 1.0f,
2174 -1.0f, +1.0f, 0.0f, 1.0f,
2175 +1.0f, 0.0f, 0.0f, 1.0f,
2176 +1.0f, +1.0f, 0.0f, 1.0f,
2177 };
2178 const std::vector<float> vertices (verticesData, verticesData + DE_LENGTH_OF_ARRAY(verticesData));
2179
2180 return vertices;
2181 }
2182
generateReferenceImage(const tcu::TextureFormat & textureFormat,const AspectFlags aspectFlags,const deUint32 sample,const deUint32 subpass)2183 MovePtr<tcu::TextureLevel> MultisubpassTestInstance::generateReferenceImage (const tcu::TextureFormat& textureFormat,
2184 const AspectFlags aspectFlags,
2185 const deUint32 sample,
2186 const deUint32 subpass)
2187 {
2188 const int width = m_imageExtent2D.width;
2189 const int height = m_imageExtent2D.height;
2190 const tcu::Vec4 colorDraw0 (0.0f, 0.0f, 1.0f, 1.0f);
2191 const tcu::Vec4 colorFill0 (tcu::RGBA::black().toVec());
2192 const tcu::Vec4 colorDraw1 (colorDraw0.x(), 1.0f, colorDraw0.z(), 1.0f);
2193 const tcu::Vec4 colorFill1 (colorFill0.x(), 1.0f, colorFill0.z(), 1.0f);
2194 const tcu::Vec4& colorDraw ((subpass == 0) ? colorDraw0 : colorDraw1);
2195 const tcu::Vec4& colorFill ((subpass == 0) ? colorFill0 : colorFill1);
2196 MovePtr<tcu::TextureLevel> image (new tcu::TextureLevel(textureFormat, width, height));
2197 tcu::PixelBufferAccess access (image->getAccess());
2198
2199 DE_UNREF(aspectFlags);
2200 DE_ASSERT(aspectFlags == ASPECT_COLOR);
2201 DE_UNREF(sample);
2202 DE_ASSERT(sample == NO_SAMPLE);
2203 DE_ASSERT(subpass != NO_SUBPASS);
2204
2205 for (int y = 0; y < height; ++y)
2206 {
2207 const tcu::Vec4& validColor = (y < height / 2) ? colorFill : colorDraw;
2208
2209 for (int x = 0; x < width; ++x)
2210 access.setPixel(validColor, x, y);
2211 }
2212
2213 return image;
2214 }
2215
iterate(void)2216 tcu::TestStatus MultisubpassTestInstance::iterate (void)
2217 {
2218 const DeviceInterface& vk = m_context.getDeviceInterface();
2219 const VkDevice device = m_context.getDevice();
2220 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
2221 const VkQueue queue = m_context.getUniversalQueue();
2222 Allocator& allocator = m_context.getDefaultAllocator();
2223
2224 const tcu::Vec4 clearColor = tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f);
2225 const VkFormat colorFormat = m_parameters.colorFormat;
2226 const VkDeviceSize colorBufferSize = m_imageExtent2D.width * m_imageExtent2D.height * tcu::getPixelSize(mapVkFormat(colorFormat));
2227 const VkImageSubresourceRange colorSubresRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u);
2228
2229 const Unique<VkImage> color0Image (makeImage (vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)));
2230 const UniquePtr<Allocation> color0ImageAlloc (bindImage (vk, device, allocator, *color0Image, MemoryRequirement::Any));
2231 const Unique<VkImageView> color0Attachment (makeImageView (vk, device, *color0Image, VK_IMAGE_VIEW_TYPE_2D, colorFormat, colorSubresRange));
2232 const Unique<VkBuffer> color0Buffer (makeBuffer (vk, device, colorBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT));
2233 const UniquePtr<Allocation> color0BufferAlloc (bindBuffer (vk, device, allocator, *color0Buffer, MemoryRequirement::HostVisible));
2234
2235 const Unique<VkImage> color1Image (makeImage (vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)));
2236 const UniquePtr<Allocation> color1ImageAlloc (bindImage (vk, device, allocator, *color1Image, MemoryRequirement::Any));
2237 const Unique<VkImageView> color1Attachment (makeImageView (vk, device, *color1Image, VK_IMAGE_VIEW_TYPE_2D, colorFormat, colorSubresRange));
2238 const Unique<VkBuffer> color1Buffer (makeBuffer (vk, device, colorBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT));
2239 const UniquePtr<Allocation> color1BufferAlloc (bindBuffer (vk, device, allocator, *color1Buffer, MemoryRequirement::HostVisible));
2240
2241 const VkDescriptorType descriptorType (VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT);
2242 const Unique<VkDescriptorSetLayout> descriptorSetLayout (DescriptorSetLayoutBuilder()
2243 .addSingleBinding(descriptorType, VK_SHADER_STAGE_FRAGMENT_BIT)
2244 .build(vk, device));
2245 const Unique<VkDescriptorPool> descriptorPool (DescriptorPoolBuilder()
2246 .addType(descriptorType)
2247 .build(vk, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1u));
2248 const Unique<VkDescriptorSet> descriptorSet (makeDescriptorSet(vk, device, *descriptorPool, *descriptorSetLayout));
2249 const VkDescriptorImageInfo imageDescriptorInfo (makeDescriptorImageInfo(DE_NULL, *color0Attachment, VK_IMAGE_LAYOUT_GENERAL));
2250
2251 DescriptorSetUpdateBuilder()
2252 .writeSingle(*descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), descriptorType, &imageDescriptorInfo)
2253 .update(vk, device);
2254
2255 const Unique<VkRenderPass> renderPass (makeRenderPass (vk, device, colorFormat, DE_NULL));
2256 const Unique<VkFramebuffer> framebuffer (makeFramebuffer (vk, device, *renderPass, m_imageExtent2D, &colorFormat, m_colorImageUsage, &m_parameters.dsFormat, 0u, ASPECT_NONE, 1u));
2257 const Unique<VkCommandPool> cmdPool (createCommandPool (vk, device, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, queueFamilyIndex));
2258 const Unique<VkCommandBuffer> cmdBuffer (allocateCommandBuffer (vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
2259
2260 const Unique<VkShaderModule> vertModule0 (createShaderModule (vk, device, m_context.getBinaryCollection().get("vert"), 0u));
2261 const Unique<VkShaderModule> fragModule0 (createShaderModule (vk, device, m_context.getBinaryCollection().get("frag"), 0u));
2262 const Unique<VkPipelineLayout> pipelineLayout0 (makePipelineLayout (vk, device));
2263 const Unique<VkPipeline> pipeline0 (makeGraphicsPipeline (vk, device, *pipelineLayout0, *renderPass, *vertModule0, *fragModule0, m_imageExtent2D));
2264
2265 const Unique<VkShaderModule> vertModule1 (createShaderModule (vk, device, m_context.getBinaryCollection().get("vert1"), 0u));
2266 const Unique<VkShaderModule> fragModule1 (createShaderModule (vk, device, m_context.getBinaryCollection().get("frag1"), 0u));
2267 const Unique<VkPipelineLayout> pipelineLayout1 (makePipelineLayout (vk, device, 1u, &*descriptorSetLayout));
2268 const Unique<VkPipeline> pipeline1 (makeGraphicsPipeline (vk, device, *pipelineLayout1, *renderPass, *vertModule1, *fragModule1, m_imageExtent2D, 0u, VK_SAMPLE_COUNT_1_BIT, 1u));
2269
2270 const std::vector<float> vertex0Array (getVertices());
2271 const deUint32 vertex0Count (static_cast<deUint32>(vertex0Array.size() / 4u));
2272 const VkDeviceSize vertex0ArraySize (vertex0Array.size() * sizeof(vertex0Array[0]));
2273 const Unique<VkBuffer> vertex0Buffer (makeBuffer (vk, device, vertex0ArraySize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT));
2274 const UniquePtr<Allocation> vertex0BufferAlloc (bindBuffer (vk, device, allocator, *vertex0Buffer, MemoryRequirement::HostVisible));
2275 const VkDeviceSize vertex0BufferOffset (0u);
2276
2277 const std::vector<float> vertex1Array (getFullQuadVertices());
2278 const deUint32 vertex1Count (static_cast<deUint32>(vertex1Array.size() / 4u));
2279 const VkDeviceSize vertex1ArraySize (vertex1Array.size() * sizeof(vertex1Array[0]));
2280 const Unique<VkBuffer> vertex1Buffer (makeBuffer (vk, device, vertex1ArraySize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT));
2281 const UniquePtr<Allocation> vertex1BufferAlloc (bindBuffer (vk, device, allocator, *vertex1Buffer, MemoryRequirement::HostVisible));
2282 const VkDeviceSize vertex1BufferOffset (0u);
2283
2284 fillBuffer(vk, device, *vertex0BufferAlloc, &vertex0Array[0], vertex0ArraySize);
2285 fillBuffer(vk, device, *vertex1BufferAlloc, &vertex1Array[0], vertex1ArraySize);
2286
2287 beginCommandBuffer(vk, *cmdBuffer);
2288 {
2289 const VkImageView attachments[] = { *color0Attachment, *color1Attachment };
2290 const VkRenderPassAttachmentBeginInfo renderPassAttachmentBeginInfo =
2291 {
2292 VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO, // VkStructureType sType;
2293 DE_NULL, // const void* pNext;
2294 DE_LENGTH_OF_ARRAY(attachments), // deUint32 attachmentCount;
2295 &attachments[0] // const VkImageView* pAttachments;
2296 };
2297
2298 beginRenderPass(vk, *cmdBuffer, *renderPass, *framebuffer, makeRect2D(m_imageExtent2D), clearColor, &renderPassAttachmentBeginInfo);
2299 {
2300 {
2301 vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline0);
2302
2303 vk.cmdBindVertexBuffers(*cmdBuffer, 0u, 1u, &*vertex0Buffer, &vertex0BufferOffset);
2304
2305 vk.cmdDraw(*cmdBuffer, vertex0Count, 1u, 0u, 0u);
2306 }
2307
2308 vk.cmdNextSubpass(*cmdBuffer, VK_SUBPASS_CONTENTS_INLINE);
2309
2310 {
2311 vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline1);
2312
2313 vk.cmdBindVertexBuffers(*cmdBuffer, 0u, 1u, &*vertex1Buffer, &vertex1BufferOffset);
2314
2315 vk.cmdBindDescriptorSets(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipelineLayout1, 0u, 1u, &descriptorSet.get(), 0u, DE_NULL);
2316
2317 vk.cmdDraw(*cmdBuffer, vertex1Count, 1u, 0u, 0u);
2318 }
2319 }
2320 endRenderPass(vk, *cmdBuffer);
2321
2322 // Subpass0 color image copy
2323 {
2324 const VkImageMemoryBarrier preCopyBarrier = makeImageMemoryBarrier (VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
2325 VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
2326 *color0Image, colorSubresRange);
2327 const VkBufferImageCopy region = makeBufferImageCopy (makeExtent3D(m_imageExtent2D.width, m_imageExtent2D.height, 1u),
2328 makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u));
2329 const VkBufferMemoryBarrier postCopyBarrier = makeBufferMemoryBarrier (VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, *color0Buffer, 0ull, VK_WHOLE_SIZE);
2330
2331 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &preCopyBarrier);
2332 vk.cmdCopyImageToBuffer(*cmdBuffer, *color0Image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *color0Buffer, 1u, ®ion);
2333 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, 1u, &postCopyBarrier, DE_NULL, 0u);
2334 }
2335
2336 // Subpass1 color image copy
2337 {
2338 const VkImageMemoryBarrier preCopyBarrier = makeImageMemoryBarrier (VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
2339 VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
2340 *color1Image, colorSubresRange);
2341 const VkBufferImageCopy region = makeBufferImageCopy (makeExtent3D(m_imageExtent2D.width, m_imageExtent2D.height, 1u),
2342 makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u));
2343 const VkBufferMemoryBarrier postCopyBarrier = makeBufferMemoryBarrier (VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, *color1Buffer, 0ull, VK_WHOLE_SIZE);
2344
2345 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &preCopyBarrier);
2346 vk.cmdCopyImageToBuffer(*cmdBuffer, *color1Image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *color1Buffer, 1u, ®ion);
2347 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, 1u, &postCopyBarrier, DE_NULL, 0u);
2348 }
2349 }
2350 endCommandBuffer(vk, *cmdBuffer);
2351 submitCommandsAndWait(vk, device, queue, *cmdBuffer);
2352
2353 {
2354 std::string result;
2355
2356 if (!verifyBuffer(color0BufferAlloc, colorFormat, "ColorSubpass0", ASPECT_COLOR, NO_SAMPLE, 0u))
2357 result += " ColorSubpass0";
2358
2359 if (!verifyBuffer(color1BufferAlloc, colorFormat, "ColorSubpass1", ASPECT_COLOR, NO_SAMPLE, 1u))
2360 result += " ColorSubpass1";
2361
2362 if (result.empty())
2363 return tcu::TestStatus::pass("Pass");
2364 else
2365 return tcu::TestStatus::fail("Following parts of image are incorrect:" + result);
2366 }
2367 }
2368
2369
2370 class DifferentAttachmentsTestInstance : public ColorImagelessTestInstance
2371 {
2372 public:
2373 DifferentAttachmentsTestInstance(Context& context, const TestParameters& parameters);
2374
2375 protected:
2376 virtual tcu::TestStatus iterate(void);
2377
2378 virtual std::vector<float> getVertices(void);
2379
2380 virtual MovePtr<tcu::TextureLevel> generateReferenceImage(const tcu::TextureFormat& textureFormat,
2381 const AspectFlags aspectFlags,
2382 const deUint32 sample,
2383 const deUint32 subpass);
2384 };
2385
DifferentAttachmentsTestInstance(Context & context,const TestParameters & parameters)2386 DifferentAttachmentsTestInstance::DifferentAttachmentsTestInstance(Context& context, const TestParameters& parameters)
2387 : ColorImagelessTestInstance(context, parameters)
2388 {
2389 }
2390
getVertices(void)2391 std::vector<float> DifferentAttachmentsTestInstance::getVertices(void)
2392 {
2393 const float verticesData[] =
2394 {
2395 -1.0f, 0.0f, 0.0f, 1.0f,
2396 -1.0f, +1.0f, 0.0f, 1.0f,
2397 +1.0f, 0.0f, 0.0f, 1.0f,
2398 -1.0f, +1.0f, 0.0f, 1.0f,
2399 +1.0f, 0.0f, 0.0f, 1.0f,
2400 +1.0f, +1.0f, 0.0f, 1.0f,
2401 };
2402 const std::vector<float> vertices(verticesData, verticesData + DE_LENGTH_OF_ARRAY(verticesData));
2403
2404 return vertices;
2405 }
2406
generateReferenceImage(const tcu::TextureFormat & textureFormat,const AspectFlags aspectFlags,const deUint32 sample,const deUint32)2407 MovePtr<tcu::TextureLevel> DifferentAttachmentsTestInstance::generateReferenceImage(const tcu::TextureFormat& textureFormat,
2408 const AspectFlags aspectFlags,
2409 const deUint32 sample,
2410 const deUint32)
2411 {
2412 const int width = m_imageExtent2D.width;
2413 const int height = m_imageExtent2D.height;
2414 const tcu::Vec4 colorDraw (0.0f, 0.0f, 1.0f, 1.0f);
2415 const tcu::Vec4 colorFill (tcu::RGBA::black().toVec());
2416 MovePtr<tcu::TextureLevel> image (new tcu::TextureLevel(textureFormat, width, height));
2417 tcu::PixelBufferAccess access (image->getAccess());
2418
2419 DE_UNREF(aspectFlags);
2420 DE_ASSERT(aspectFlags == ASPECT_COLOR);
2421 DE_UNREF(sample);
2422 DE_ASSERT(sample == NO_SAMPLE);
2423
2424 for (int y = 0; y < height; ++y)
2425 {
2426 const tcu::Vec4& validColor = (y < height / 2) ? colorFill : colorDraw;
2427
2428 for (int x = 0; x < width; ++x)
2429 access.setPixel(validColor, x, y);
2430 }
2431
2432 return image;
2433 }
2434
iterate(void)2435 tcu::TestStatus DifferentAttachmentsTestInstance::iterate(void)
2436 {
2437 const DeviceInterface& vk = m_context.getDeviceInterface();
2438 const VkDevice device = m_context.getDevice();
2439 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
2440 const VkQueue queue = m_context.getUniversalQueue();
2441 Allocator& allocator = m_context.getDefaultAllocator();
2442
2443 const tcu::Vec4 clearColor = tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f);
2444 const VkFormat colorFormat = m_parameters.colorFormat;
2445 const VkDeviceSize colorBufferSize = m_imageExtent2D.width * m_imageExtent2D.height * tcu::getPixelSize(mapVkFormat(colorFormat));
2446 const VkImageSubresourceRange colorSubresRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u);
2447
2448 const Unique<VkImage> color0Image (makeImage (vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)));
2449 const UniquePtr<Allocation> color0ImageAlloc (bindImage (vk, device, allocator, *color0Image, MemoryRequirement::Any));
2450 const Unique<VkImageView> color0Attachment (makeImageView (vk, device, *color0Image, VK_IMAGE_VIEW_TYPE_2D, colorFormat, colorSubresRange));
2451 const Unique<VkBuffer> color0Buffer (makeBuffer (vk, device, colorBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT));
2452 const UniquePtr<Allocation> color0BufferAlloc (bindBuffer (vk, device, allocator, *color0Buffer, MemoryRequirement::HostVisible));
2453
2454 const Unique<VkImage> color1Image (makeImage (vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)));
2455 const UniquePtr<Allocation> color1ImageAlloc (bindImage (vk, device, allocator, *color1Image, MemoryRequirement::Any));
2456 const Unique<VkImageView> color1Attachment (makeImageView (vk, device, *color1Image, VK_IMAGE_VIEW_TYPE_2D, colorFormat, colorSubresRange));
2457 const Unique<VkBuffer> color1Buffer (makeBuffer (vk, device, colorBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT));
2458 const UniquePtr<Allocation> color1BufferAlloc (bindBuffer (vk, device, allocator, *color1Buffer, MemoryRequirement::HostVisible));
2459
2460 const Unique<VkRenderPass> renderPass (makeSingleAttachmentRenderPass (vk, device, colorFormat, DE_NULL));
2461 const Unique<VkFramebuffer> framebuffer (makeFramebuffer (vk, device, *renderPass, m_imageExtent2D, &colorFormat, m_colorImageUsage, &m_parameters.dsFormat));
2462 const Unique<VkCommandPool> cmdPool (createCommandPool (vk, device, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, queueFamilyIndex));
2463 const Unique<VkCommandBuffer> cmdBuffer (allocateCommandBuffer (vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
2464
2465 const Unique<VkShaderModule> vertModule (createShaderModule (vk, device, m_context.getBinaryCollection().get("vert"), 0u));
2466 const Unique<VkShaderModule> fragModule (createShaderModule (vk, device, m_context.getBinaryCollection().get("frag"), 0u));
2467 const Unique<VkPipelineLayout> pipelineLayout (makePipelineLayout (vk, device));
2468 const Unique<VkPipeline> pipeline (makeGraphicsPipeline (vk, device, *pipelineLayout, *renderPass, *vertModule, *fragModule, m_imageExtent2D));
2469
2470 const std::vector<float> vertexArray (getVertices());
2471 const deUint32 vertexCount (static_cast<deUint32>(vertexArray.size() / 4u));
2472 const VkDeviceSize vertexArraySize (vertexArray.size() * sizeof(vertexArray[0]));
2473 const Unique<VkBuffer> vertexBuffer (makeBuffer (vk, device, vertexArraySize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT));
2474 const UniquePtr<Allocation> vertexBufferAlloc (bindBuffer (vk, device, allocator, *vertexBuffer, MemoryRequirement::HostVisible));
2475 const VkDeviceSize vertexBufferOffset (0u);
2476
2477 fillBuffer(vk, device, *vertexBufferAlloc, &vertexArray[0], vertexArraySize);
2478
2479 beginCommandBuffer(vk, *cmdBuffer);
2480 {
2481 const VkRenderPassAttachmentBeginInfo renderPassAttachmentBeginInfo0 =
2482 {
2483 VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO, // VkStructureType sType;
2484 DE_NULL, // const void* pNext;
2485 1u, // deUint32 attachmentCount;
2486 &*color0Attachment // const VkImageView* pAttachments;
2487 };
2488
2489 beginRenderPass(vk, *cmdBuffer, *renderPass, *framebuffer, makeRect2D(m_imageExtent2D), clearColor, &renderPassAttachmentBeginInfo0);
2490 {
2491 vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
2492
2493 vk.cmdBindVertexBuffers(*cmdBuffer, 0u, 1u, &*vertexBuffer, &vertexBufferOffset);
2494
2495 vk.cmdDraw(*cmdBuffer, vertexCount, 1u, 0u, 0u);
2496 }
2497 endRenderPass(vk, *cmdBuffer);
2498
2499 const VkRenderPassAttachmentBeginInfo renderPassAttachmentBeginInfo1 =
2500 {
2501 VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO, // VkStructureType sType;
2502 DE_NULL, // const void* pNext;
2503 1u, // deUint32 attachmentCount;
2504 &*color1Attachment // const VkImageView* pAttachments;
2505 };
2506
2507 beginRenderPass(vk, *cmdBuffer, *renderPass, *framebuffer, makeRect2D(m_imageExtent2D), clearColor, &renderPassAttachmentBeginInfo1);
2508 {
2509 vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
2510
2511 vk.cmdBindVertexBuffers(*cmdBuffer, 0u, 1u, &*vertexBuffer, &vertexBufferOffset);
2512
2513 vk.cmdDraw(*cmdBuffer, vertexCount, 1u, 0u, 0u);
2514 }
2515 endRenderPass(vk, *cmdBuffer);
2516
2517 // Subpass0 color image copy
2518 {
2519 const VkImageMemoryBarrier preCopyBarrier = makeImageMemoryBarrier (VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
2520 VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
2521 *color0Image, colorSubresRange);
2522 const VkBufferImageCopy region = makeBufferImageCopy (makeExtent3D(m_imageExtent2D.width, m_imageExtent2D.height, 1u),
2523 makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u));
2524 const VkBufferMemoryBarrier postCopyBarrier = makeBufferMemoryBarrier (VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, *color0Buffer, 0ull, VK_WHOLE_SIZE);
2525
2526 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &preCopyBarrier);
2527 vk.cmdCopyImageToBuffer(*cmdBuffer, *color0Image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *color0Buffer, 1u, ®ion);
2528 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, 1u, &postCopyBarrier, DE_NULL, 0u);
2529 }
2530
2531 // Subpass1 color image copy
2532 {
2533 const VkImageMemoryBarrier preCopyBarrier = makeImageMemoryBarrier (VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
2534 VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
2535 *color1Image, colorSubresRange);
2536 const VkBufferImageCopy region = makeBufferImageCopy (makeExtent3D(m_imageExtent2D.width, m_imageExtent2D.height, 1u),
2537 makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u));
2538 const VkBufferMemoryBarrier postCopyBarrier = makeBufferMemoryBarrier (VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, *color1Buffer, 0ull, VK_WHOLE_SIZE);
2539
2540 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &preCopyBarrier);
2541 vk.cmdCopyImageToBuffer(*cmdBuffer, *color1Image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *color1Buffer, 1u, ®ion);
2542 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, 1u, &postCopyBarrier, DE_NULL, 0u);
2543 }
2544 }
2545 endCommandBuffer(vk, *cmdBuffer);
2546 submitCommandsAndWait(vk, device, queue, *cmdBuffer);
2547
2548 {
2549 std::string result;
2550
2551 if (!verifyBuffer(color0BufferAlloc, colorFormat, "ColorSubpass0", ASPECT_COLOR, NO_SAMPLE, 0u))
2552 result += " ColorSubpass0";
2553
2554 if (!verifyBuffer(color1BufferAlloc, colorFormat, "ColorSubpass1", ASPECT_COLOR, NO_SAMPLE, 1u))
2555 result += " ColorSubpass1";
2556
2557 if (result.empty())
2558 return tcu::TestStatus::pass("Pass");
2559 else
2560 return tcu::TestStatus::fail("Following parts of image are incorrect:" + result);
2561 }
2562 }
2563
2564 class BaseTestCase : public TestCase
2565 {
2566 public:
2567 BaseTestCase (tcu::TestContext& context, const std::string& name, const std::string& description, const TestParameters& parameters);
2568 virtual ~BaseTestCase (void);
2569
2570 protected:
2571 virtual void checkSupport (Context& context) const;
2572 virtual void initPrograms (SourceCollections& programCollection) const;
2573 virtual TestInstance* createInstance (Context& context) const;
2574
2575 const TestParameters m_parameters;
2576 };
2577
BaseTestCase(tcu::TestContext & context,const std::string & name,const std::string & description,const TestParameters & parameters)2578 BaseTestCase::BaseTestCase (tcu::TestContext& context, const std::string& name, const std::string& description, const TestParameters& parameters)
2579 : TestCase (context, name, description)
2580 , m_parameters (parameters)
2581 {
2582 }
2583
~BaseTestCase()2584 BaseTestCase::~BaseTestCase ()
2585 {
2586 }
2587
checkSupport(Context & context) const2588 void BaseTestCase::checkSupport (Context& context) const
2589 {
2590 if (m_parameters.testType == TEST_TYPE_COLOR_RESOLVE || m_parameters.testType == TEST_TYPE_DEPTH_STENCIL_RESOLVE)
2591 {
2592 if (!context.getDeviceProperties().limits.standardSampleLocations)
2593 TCU_THROW(NotSupportedError, "Non-standard sample locations are not supported");
2594 }
2595 }
2596
initPrograms(SourceCollections & programCollection) const2597 void BaseTestCase::initPrograms (SourceCollections& programCollection) const
2598 {
2599 // Vertex shader
2600 {
2601 std::ostringstream src;
2602
2603 if (m_parameters.testType == TEST_TYPE_COLOR || m_parameters.testType == TEST_TYPE_COLOR_RESOLVE || m_parameters.testType == TEST_TYPE_DEPTH_STENCIL)
2604 {
2605 src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
2606 << "\n"
2607 << "layout(location = 0) in highp vec4 a_position;\n"
2608 << "layout(location = 0) out highp vec4 a_color;\n"
2609 << "\n"
2610 << "void main (void)\n"
2611 << "{\n"
2612 << " gl_Position = a_position;\n"
2613 << " if (gl_VertexIndex < 6)\n"
2614 << " a_color = vec4(0.75f, 0.75f, 0.75f, 1.0f);\n"
2615 << " else\n"
2616 << " a_color = vec4(1.00f, 1.00f, 1.00f, 1.0f);\n"
2617 << "}\n";
2618 }
2619
2620 if (m_parameters.testType == TEST_TYPE_DEPTH_STENCIL_RESOLVE)
2621 {
2622 src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
2623 << "\n"
2624 << "layout(location = 0) in highp vec4 a_position;\n"
2625 << "layout(location = 0) out highp vec4 a_color;\n"
2626 << "\n"
2627 << "void main (void)\n"
2628 << "{\n"
2629 << " gl_Position = a_position;\n"
2630 << " if (gl_VertexIndex < 3)\n"
2631 << " a_color = vec4(0.00f, 0.00f, 1.00f, 1.0f);\n"
2632 << " else\n"
2633 << " a_color = vec4(0.00f, 1.00f, 0.00f, 1.0f);\n"
2634 << "}\n";
2635 }
2636
2637 if (m_parameters.testType == TEST_TYPE_MULTISUBPASS || m_parameters.testType == TEST_TYPE_DIFFERENT_ATTACHMENTS)
2638 {
2639 src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
2640 << "\n"
2641 << "layout(location = 0) in highp vec4 a_position;\n"
2642 << "layout(location = 0) out highp vec4 a_color;\n"
2643 << "\n"
2644 << "void main (void)\n"
2645 << "{\n"
2646 << " gl_Position = a_position;\n"
2647 << " a_color = vec4(0.0f, 0.0f, 1.0f, 1.0f);\n"
2648 << "}\n";
2649 }
2650
2651 programCollection.glslSources.add("vert") << glu::VertexSource(src.str());
2652 }
2653
2654 // Fragment shader
2655 {
2656 std::ostringstream src;
2657
2658 src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
2659 << "\n"
2660 << "layout(location = 0) in highp vec4 a_color;\n"
2661 << "layout(location = 0) out highp vec4 o_color;\n"
2662 << "\n"
2663 << "void main (void)\n"
2664 << "{\n"
2665 << " o_color = a_color;\n"
2666 << "}\n";
2667
2668 programCollection.glslSources.add("frag") << glu::FragmentSource(src.str());
2669 }
2670
2671 // Additional shaders
2672 if (m_parameters.testType == TEST_TYPE_COLOR_RESOLVE || m_parameters.testType == TEST_TYPE_DEPTH_STENCIL_RESOLVE)
2673 {
2674 // Vertex shader
2675 {
2676 std::ostringstream src;
2677
2678 src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
2679 << "\n"
2680 << "layout(location = 0) in highp vec4 a_position;\n"
2681 << "\n"
2682 << "void main (void)\n"
2683 << "{\n"
2684 << " gl_Position = a_position;\n"
2685 << "}\n";
2686
2687 programCollection.glslSources.add("demultisample-vert") << glu::VertexSource(src.str());
2688 }
2689
2690 // Fragment shader
2691 {
2692 // Color
2693 {
2694 std::ostringstream src;
2695
2696 src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
2697 << "\n"
2698 << "layout(set = 0, binding = 0) uniform sampler2DMS u_ms_image_sampler;\n"
2699 << "layout(push_constant) uniform PushConstantsBlock {\n"
2700 << " highp int sampleID;\n"
2701 << "} pushConstants;\n"
2702 << "layout(location = 0) out highp vec4 o_color;\n"
2703 << "\n"
2704 << "void main (void)\n"
2705 << "{\n"
2706 << " o_color = texelFetch(u_ms_image_sampler, ivec2(gl_FragCoord.xy), pushConstants.sampleID);\n"
2707 << "}\n";
2708
2709 programCollection.glslSources.add("demultisample-color-frag") << glu::FragmentSource(src.str());
2710 }
2711
2712 // Depth
2713 {
2714 std::ostringstream src;
2715
2716 // Depth-component textures are treated as one-component floating-point textures.
2717 src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
2718 << "\n"
2719 << "layout(binding = 0) uniform sampler2DMS u_ms_image_sampler;\n"
2720 << "layout(push_constant) uniform PushConstantsBlock {\n"
2721 << " highp int sampleID;\n"
2722 << "} pushConstants;\n"
2723 << "layout(location = 0) out highp vec4 o_color;\n"
2724 << "\n"
2725 << "void main (void)\n"
2726 << "{\n"
2727 << " vec4 val = texelFetch(u_ms_image_sampler, ivec2(gl_FragCoord.xy), pushConstants.sampleID);\n"
2728 << " o_color = vec4(val.x, val.x, val.x, 1.0);\n"
2729 << "}\n";
2730
2731 programCollection.glslSources.add("demultisample-depth-frag") << glu::FragmentSource(src.str());
2732 }
2733
2734 // Stencil
2735 {
2736 std::ostringstream src;
2737
2738 // Stencil-component textures are treated as one-component unsigned integer textures.
2739 src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
2740 << "\n"
2741 << "layout(binding = 0) uniform usampler2DMS u_ms_image_sampler;\n"
2742 << "layout(push_constant) uniform PushConstantsBlock {\n"
2743 << " highp int sampleID;\n"
2744 << "} pushConstants;\n"
2745 << "layout(location = 0) out highp vec4 o_color;\n"
2746 << "\n"
2747 << "void main (void)\n"
2748 << "{\n"
2749 << " uvec4 uVal = texelFetch(u_ms_image_sampler, ivec2(gl_FragCoord.xy), pushConstants.sampleID);\n"
2750 << " float val = float(uVal.x) / 4.0f;\n"
2751 << " o_color = vec4(val, val, val, 1.0);\n"
2752 << "}\n";
2753
2754 programCollection.glslSources.add("demultisample-stencil-frag") << glu::FragmentSource(src.str());
2755 }
2756 }
2757 }
2758
2759 if (m_parameters.testType == TEST_TYPE_MULTISUBPASS)
2760 {
2761 // Vertex shader
2762 {
2763 std::ostringstream src;
2764
2765 src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
2766 << "\n"
2767 << "layout(location = 0) in highp vec4 a_position;\n"
2768 << "\n"
2769 << "void main (void)\n"
2770 << "{\n"
2771 << " gl_Position = a_position;\n"
2772 << "}\n";
2773
2774 programCollection.glslSources.add("vert1") << glu::VertexSource(src.str());
2775 }
2776
2777 // Fragment shader
2778 {
2779 std::ostringstream src;
2780
2781 src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
2782 << "\n"
2783 << "layout(input_attachment_index = 0, set = 0, binding = 0) uniform subpassInput u_colors;\n"
2784 << "layout(location = 0) out highp vec4 o_color;\n"
2785 << "\n"
2786 << "void main (void)\n"
2787 << "{\n"
2788 << " o_color = subpassLoad(u_colors);\n"
2789 << " o_color.g = 1.0f;\n"
2790 << " o_color.a = 1.0f;\n"
2791 << "}\n";
2792
2793 programCollection.glslSources.add("frag1") << glu::FragmentSource(src.str());
2794 }
2795 }
2796
2797
2798 return;
2799 }
2800
createInstance(Context & context) const2801 TestInstance* BaseTestCase::createInstance (Context& context) const
2802 {
2803 if (m_parameters.testType == TEST_TYPE_COLOR)
2804 return new ColorImagelessTestInstance(context, m_parameters);
2805
2806 if (m_parameters.testType == TEST_TYPE_DEPTH_STENCIL)
2807 return new DepthImagelessTestInstance(context, m_parameters);
2808
2809 if (m_parameters.testType == TEST_TYPE_COLOR_RESOLVE)
2810 return new ColorResolveImagelessTestInstance(context, m_parameters);
2811
2812 if (m_parameters.testType == TEST_TYPE_DEPTH_STENCIL_RESOLVE)
2813 return new DepthResolveImagelessTestInstance(context, m_parameters);
2814
2815 if (m_parameters.testType == TEST_TYPE_MULTISUBPASS)
2816 return new MultisubpassTestInstance(context, m_parameters);
2817
2818 if (m_parameters.testType == TEST_TYPE_DIFFERENT_ATTACHMENTS)
2819 return new DifferentAttachmentsTestInstance(context, m_parameters);
2820
2821
2822 TCU_THROW(InternalError, "Unknown test type specified");
2823 }
2824
imagelessColorTests(tcu::TestContext & testCtx)2825 tcu::TestNode* imagelessColorTests (tcu::TestContext& testCtx)
2826 {
2827 TestParameters parameters =
2828 {
2829 TEST_TYPE_COLOR, // TestType testType;
2830 VK_FORMAT_R8G8B8A8_UNORM, // VkFormat colorFormat;
2831 VK_FORMAT_UNDEFINED, // VkFormat dsFormat;
2832 };
2833
2834 return new BaseTestCase(testCtx, "color", "Imageless color attachment test", parameters);
2835 }
2836
imagelessDepthStencilTests(tcu::TestContext & testCtx)2837 tcu::TestNode* imagelessDepthStencilTests (tcu::TestContext& testCtx)
2838 {
2839 TestParameters parameters =
2840 {
2841 TEST_TYPE_DEPTH_STENCIL, // TestType testType;
2842 VK_FORMAT_R8G8B8A8_UNORM, // VkFormat colorFormat;
2843 VK_FORMAT_D24_UNORM_S8_UINT, // VkFormat dsFormat;
2844 };
2845
2846 return new BaseTestCase(testCtx, "depth_stencil", "Imageless depth/stencil attachment test", parameters);
2847 }
2848
imagelessColorResolveTests(tcu::TestContext & testCtx)2849 tcu::TestNode* imagelessColorResolveTests (tcu::TestContext& testCtx)
2850 {
2851 TestParameters parameters =
2852 {
2853 TEST_TYPE_COLOR_RESOLVE, // TestType testType;
2854 VK_FORMAT_R8G8B8A8_UNORM, // VkFormat colorFormat;
2855 VK_FORMAT_UNDEFINED, // VkFormat dsFormat;
2856 };
2857
2858 return new BaseTestCase(testCtx, "color_resolve", "Imageless color attachment resolve test", parameters);
2859 }
2860
imagelessDepthStencilResolveTests(tcu::TestContext & testCtx)2861 tcu::TestNode* imagelessDepthStencilResolveTests (tcu::TestContext& testCtx)
2862 {
2863 TestParameters parameters =
2864 {
2865 TEST_TYPE_DEPTH_STENCIL_RESOLVE, // TestType testType;
2866 VK_FORMAT_R8G8B8A8_UNORM, // VkFormat colorFormat;
2867 VK_FORMAT_D24_UNORM_S8_UINT, // VkFormat dsFormat;
2868 };
2869
2870 return new BaseTestCase(testCtx, "depth_stencil_resolve", "Imageless color and depth/stencil attachment resolve test", parameters);
2871 }
2872
imagelessMultisubpass(tcu::TestContext & testCtx)2873 tcu::TestNode* imagelessMultisubpass(tcu::TestContext& testCtx)
2874 {
2875 TestParameters parameters =
2876 {
2877 TEST_TYPE_MULTISUBPASS, // TestType testType;
2878 VK_FORMAT_R8G8B8A8_UNORM, // VkFormat colorFormat;
2879 VK_FORMAT_UNDEFINED, // VkFormat dsFormat;
2880 };
2881
2882 return new BaseTestCase(testCtx, "multisubpass", "Multi-subpass test", parameters);
2883 }
2884
imagelessDifferentAttachments(tcu::TestContext & testCtx)2885 tcu::TestNode* imagelessDifferentAttachments(tcu::TestContext& testCtx)
2886 {
2887 TestParameters parameters =
2888 {
2889 TEST_TYPE_DIFFERENT_ATTACHMENTS, // TestType testType;
2890 VK_FORMAT_R8G8B8A8_UNORM, // VkFormat colorFormat;
2891 VK_FORMAT_UNDEFINED, // VkFormat dsFormat;
2892 };
2893
2894 return new BaseTestCase(testCtx, "different_attachments", "Different attachments in multiple render passes", parameters);
2895 }
2896
2897 } // anonymous
2898
createTests(tcu::TestContext & testCtx)2899 tcu::TestCaseGroup* createTests (tcu::TestContext& testCtx)
2900 {
2901 de::MovePtr<tcu::TestCaseGroup> imagelessFramebufferGroup (new tcu::TestCaseGroup(testCtx, "imageless_framebuffer", "Imageless Framebuffer tests"));
2902
2903 imagelessFramebufferGroup->addChild(imagelessColorTests(testCtx)); // Color only test
2904 imagelessFramebufferGroup->addChild(imagelessDepthStencilTests(testCtx)); // Color and depth/stencil test
2905 imagelessFramebufferGroup->addChild(imagelessColorResolveTests(testCtx)); // Color and color resolve test
2906 imagelessFramebufferGroup->addChild(imagelessDepthStencilResolveTests(testCtx)); // Color, depth and depth resolve test (interaction with VK_KHR_depth_stencil_resolve)
2907 imagelessFramebufferGroup->addChild(imagelessMultisubpass(testCtx)); // Multi-subpass test
2908 imagelessFramebufferGroup->addChild(imagelessDifferentAttachments(testCtx)); // Different attachments in multiple render passes
2909
2910 return imagelessFramebufferGroup.release();
2911 }
2912
2913 } // imageless
2914 } // vkt
2915