1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2016 The Khronos Group Inc.
6 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 *//*!
21 * \file
22 * \brief Vulkan Image Clearing Tests
23 *//*--------------------------------------------------------------------*/
24
25 #include "vktApiImageClearingTests.hpp"
26
27 #include "deRandom.hpp"
28 #include "deMath.h"
29 #include "deSTLUtil.hpp"
30 #include "deStringUtil.hpp"
31 #include "deUniquePtr.hpp"
32 #include "deArrayUtil.hpp"
33 #include "deInt32.h"
34 #include "vkImageUtil.hpp"
35 #include "vkMemUtil.hpp"
36 #include "vktTestCase.hpp"
37 #include "vktTestCaseUtil.hpp"
38 #include "vktTestGroupUtil.hpp"
39 #include "vkQueryUtil.hpp"
40 #include "vkRefUtil.hpp"
41 #include "vkTypeUtil.hpp"
42 #include "vkCmdUtil.hpp"
43 #include "tcuImageCompare.hpp"
44 #include "tcuTexture.hpp"
45 #include "tcuTextureUtil.hpp"
46 #include "tcuVectorType.hpp"
47 #include "tcuTexture.hpp"
48 #include "tcuFloat.hpp"
49 #include "tcuTestLog.hpp"
50 #include "tcuVectorUtil.hpp"
51 #include <sstream>
52 #include <numeric>
53
54 namespace vkt
55 {
56
57 namespace api
58 {
59
60 using namespace vk;
61 using namespace tcu;
62
63 namespace
64 {
65
66 enum AllocationKind
67 {
68 ALLOCATION_KIND_SUBALLOCATED = 0,
69 ALLOCATION_KIND_DEDICATED,
70
71 ALLOCATION_KIND_LAST,
72 };
73
74 union Threshold {
75 Vec4 vec4;
76 IVec4 ivec4;
77 UVec4 uvec4;
78 };
79
allocateBuffer(const InstanceInterface & vki,const DeviceInterface & vkd,const VkPhysicalDevice & physDevice,const VkDevice device,const VkBuffer & buffer,const MemoryRequirement requirement,Allocator & allocator,AllocationKind allocationKind)80 de::MovePtr<Allocation> allocateBuffer (const InstanceInterface& vki,
81 const DeviceInterface& vkd,
82 const VkPhysicalDevice& physDevice,
83 const VkDevice device,
84 const VkBuffer& buffer,
85 const MemoryRequirement requirement,
86 Allocator& allocator,
87 AllocationKind allocationKind)
88 {
89 switch (allocationKind)
90 {
91 case ALLOCATION_KIND_SUBALLOCATED:
92 {
93 const VkMemoryRequirements memoryRequirements = getBufferMemoryRequirements(vkd, device, buffer);
94
95 return allocator.allocate(memoryRequirements, requirement);
96 }
97
98 case ALLOCATION_KIND_DEDICATED:
99 {
100 return allocateDedicated(vki, vkd, physDevice, device, buffer, requirement);
101 }
102
103 default:
104 {
105 TCU_THROW(InternalError, "Invalid allocation kind");
106 }
107 }
108 }
109
allocateImage(const InstanceInterface & vki,const DeviceInterface & vkd,const VkPhysicalDevice & physDevice,const VkDevice device,const VkImage & image,const MemoryRequirement requirement,Allocator & allocator,AllocationKind allocationKind)110 de::MovePtr<Allocation> allocateImage (const InstanceInterface& vki,
111 const DeviceInterface& vkd,
112 const VkPhysicalDevice& physDevice,
113 const VkDevice device,
114 const VkImage& image,
115 const MemoryRequirement requirement,
116 Allocator& allocator,
117 AllocationKind allocationKind)
118 {
119 switch (allocationKind)
120 {
121 case ALLOCATION_KIND_SUBALLOCATED:
122 {
123 const VkMemoryRequirements memoryRequirements = getImageMemoryRequirements(vkd, device, image);
124
125 return allocator.allocate(memoryRequirements, requirement);
126 }
127
128 case ALLOCATION_KIND_DEDICATED:
129 {
130 return allocateDedicated(vki, vkd, physDevice, device, image, requirement);
131 }
132
133 default:
134 {
135 TCU_THROW(InternalError, "Invalid allocation kind");
136 }
137 }
138 }
139
getMipLevelExtent(VkExtent3D baseExtent,const deUint32 mipLevel)140 VkExtent3D getMipLevelExtent (VkExtent3D baseExtent, const deUint32 mipLevel)
141 {
142 baseExtent.width = std::max(baseExtent.width >> mipLevel, 1u);
143 baseExtent.height = std::max(baseExtent.height >> mipLevel, 1u);
144 baseExtent.depth = std::max(baseExtent.depth >> mipLevel, 1u);
145 return baseExtent;
146 }
147
getNumMipLevels(const VkExtent3D & baseExtent,const deUint32 maxMipLevels)148 deUint32 getNumMipLevels (const VkExtent3D& baseExtent, const deUint32 maxMipLevels)
149 {
150 const deUint32 widestEdge = std::max(std::max(baseExtent.width, baseExtent.height), baseExtent.depth);
151 return std::min(static_cast<deUint32>(deFloatLog2(static_cast<float>(widestEdge))) + 1u, maxMipLevels);
152 }
153
greatestCommonDivisor(const deUint32 a,const deUint32 b)154 deUint32 greatestCommonDivisor (const deUint32 a, const deUint32 b)
155 {
156 /* Find GCD */
157 deUint32 temp;
158 deUint32 x=a;
159 deUint32 y=b;
160
161 while (x%y != 0)
162 {
163 temp = y;
164 y = x%y;
165 x = temp;
166 }
167 return y;
168 }
169
lowestCommonMultiple(const deUint32 a,const deUint32 b)170 deUint32 lowestCommonMultiple (const deUint32 a, const deUint32 b)
171 {
172 return (a*b)/greatestCommonDivisor(a,b);
173 }
174
getImageMipLevelSizes(const deUint32 pixelSize,const VkExtent3D & baseExtent,const deUint32 numMipLevels,const deUint32 perLevelAlignment=1u)175 std::vector<deUint32> getImageMipLevelSizes (const deUint32 pixelSize, const VkExtent3D& baseExtent, const deUint32 numMipLevels, const deUint32 perLevelAlignment = 1u)
176 {
177 std::vector<deUint32> results(numMipLevels);
178
179 for (deUint32 mipLevel = 0; mipLevel < numMipLevels; ++mipLevel)
180 {
181 const VkExtent3D extent = getMipLevelExtent(baseExtent, mipLevel);
182 results[mipLevel] = static_cast<deUint32>(extent.width * extent.height * extent.depth * pixelSize);
183 results[mipLevel] = ((results[mipLevel] + perLevelAlignment-1) / perLevelAlignment) * perLevelAlignment;
184 }
185
186 return results;
187 }
188
189 struct LayerRange
190 {
191 deUint32 baseArrayLayer;
192 deUint32 layerCount;
193 };
194
isInClearRange(const UVec4 & clearCoords,const deUint32 x,const deUint32 y,deUint32 arrayLayer=0,tcu::Maybe<LayerRange> imageViewLayerRange=tcu::Maybe<LayerRange> (),tcu::Maybe<LayerRange> attachmentClearLayerRange=tcu::Maybe<LayerRange> ())195 inline bool isInClearRange (const UVec4& clearCoords, const deUint32 x, const deUint32 y, deUint32 arrayLayer = 0, tcu::Maybe<LayerRange> imageViewLayerRange = tcu::Maybe<LayerRange>(), tcu::Maybe<LayerRange> attachmentClearLayerRange = tcu::Maybe<LayerRange>())
196 {
197 if (attachmentClearLayerRange)
198 {
199 // Only layers in range passed to clear command are cleared
200
201 const deUint32 clearBaseLayer = (imageViewLayerRange ? imageViewLayerRange->baseArrayLayer : 0) + attachmentClearLayerRange->baseArrayLayer;
202 const deUint32 clearLayerCount = (attachmentClearLayerRange->layerCount == VK_REMAINING_ARRAY_LAYERS) ? imageViewLayerRange->layerCount : clearBaseLayer + attachmentClearLayerRange->layerCount;
203
204 if ((arrayLayer < clearBaseLayer) || (arrayLayer >= (clearLayerCount)))
205 {
206 return false;
207 }
208 }
209
210 if (clearCoords == UVec4())
211 {
212 return true;
213 }
214
215 //! Check if a point lies in a cross-like area.
216 return !((x < clearCoords[0] && y < clearCoords[1]) ||
217 (x < clearCoords[0] && y >= clearCoords[3]) ||
218 (x >= clearCoords[2] && y < clearCoords[1]) ||
219 (x >= clearCoords[2] && y >= clearCoords[3]));
220 }
221
isInInitialClearRange(deUint32 mipLevel,deUint32 arrayLayer,LayerRange imageViewLayerRange)222 inline bool isInInitialClearRange (deUint32 mipLevel, deUint32 arrayLayer, LayerRange imageViewLayerRange)
223 {
224 if (mipLevel > 0)
225 {
226 // intial clear is done using FB bound to level 0 only
227 return false;
228 }
229
230 // Only layers in range bound to framebuffer are cleared to initial color
231 if ((arrayLayer < imageViewLayerRange.baseArrayLayer) || (arrayLayer >= (imageViewLayerRange.baseArrayLayer + imageViewLayerRange.layerCount)))
232 {
233 return false;
234 }
235
236 return true;
237 }
238
239 // This method is copied from the vktRenderPassTests.cpp. It should be moved to a common place.
calcFloatDiff(float a,float b)240 int calcFloatDiff (float a, float b)
241 {
242 const int asign = Float32(a).sign();
243 const int bsign = Float32(a).sign();
244
245 const deUint32 avalue = (Float32(a).bits() & ((0x1u << 31u) - 1u));
246 const deUint32 bvalue = (Float32(b).bits() & ((0x1u << 31u) - 1u));
247
248 if (asign != bsign)
249 return avalue + bvalue + 1u;
250 else if (avalue < bvalue)
251 return bvalue - avalue;
252 else
253 return avalue - bvalue;
254 }
255
256 // This method is copied from the vktRenderPassTests.cpp and extended with the stringResult parameter.
comparePixelToDepthClearValue(const ConstPixelBufferAccess & access,int x,int y,float ref,std::string & stringResult)257 bool comparePixelToDepthClearValue (const ConstPixelBufferAccess& access,
258 int x,
259 int y,
260 float ref,
261 std::string& stringResult)
262 {
263 const TextureFormat format = getEffectiveDepthStencilTextureFormat(access.getFormat(), Sampler::MODE_DEPTH);
264 const TextureChannelClass channelClass = getTextureChannelClass(format.type);
265
266 switch (channelClass)
267 {
268 case TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
269 case TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
270 {
271 const int bitDepth = getTextureFormatBitDepth(format).x();
272 const float depth = access.getPixDepth(x, y);
273 const float threshold = 2.0f / (float)((1 << bitDepth) - 1);
274 const bool result = deFloatAbs(depth - ref) <= threshold;
275
276 if (!result)
277 {
278 std::stringstream s;
279 s << "Ref:" << ref << " Threshold:" << threshold << " Depth:" << depth;
280 stringResult = s.str();
281 }
282
283 return result;
284 }
285
286 case TEXTURECHANNELCLASS_FLOATING_POINT:
287 {
288 const float depth = access.getPixDepth(x, y);
289 const int mantissaBits = getTextureFormatMantissaBitDepth(format).x();
290 const int threshold = (10 * 1) << (23 - mantissaBits);
291
292 DE_ASSERT(mantissaBits <= 23);
293
294 const bool result = calcFloatDiff(depth, ref) <= threshold;
295
296 if (!result)
297 {
298 float floatThreshold = Float32((deUint32)threshold).asFloat();
299 std::stringstream s;
300
301 s << "Ref:" << ref << " Threshold:" << floatThreshold << " Depth:" << depth;
302 stringResult = s.str();
303 }
304
305 return result;
306 }
307
308 default:
309 DE_FATAL("Invalid channel class");
310 return false;
311 }
312 }
313
314 // This method is copied from the vktRenderPassTests.cpp and extended with the stringResult parameter.
comparePixelToStencilClearValue(const ConstPixelBufferAccess & access,int x,int y,deUint32 ref,std::string & stringResult)315 bool comparePixelToStencilClearValue (const ConstPixelBufferAccess& access,
316 int x,
317 int y,
318 deUint32 ref,
319 std::string& stringResult)
320 {
321 const deUint32 stencil = access.getPixStencil(x, y);
322 const bool result = stencil == ref;
323
324 if (!result)
325 {
326 std::stringstream s;
327 s << "Ref:" << ref << " Threshold:0" << " Stencil:" << stencil;
328 stringResult = s.str();
329 }
330
331 return result;
332 }
333
334 // This method is copied from the vktRenderPassTests.cpp and extended with the stringResult parameter.
comparePixelToColorClearValue(const ConstPixelBufferAccess & access,int x,int y,int z,const VkClearColorValue & ref,std::string & stringResult,const Threshold & threshold,const BVec4 & channelMask,const TextureChannelClass & channelClass)335 bool comparePixelToColorClearValue (const ConstPixelBufferAccess& access,
336 int x,
337 int y,
338 int z,
339 const VkClearColorValue& ref,
340 std::string& stringResult,
341 const Threshold& threshold,
342 const BVec4& channelMask,
343 const TextureChannelClass& channelClass)
344 {
345 switch (channelClass)
346 {
347 case TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
348 case TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
349 {
350 const Vec4 resColor (access.getPixel(x, y, z));
351 Vec4 refColor (ref.float32[0],
352 ref.float32[1],
353 ref.float32[2],
354 ref.float32[3]);
355
356 if (isSRGB(access.getFormat()))
357 refColor = linearToSRGB(refColor);
358
359 const bool result = !(anyNotEqual(logicalAnd(lessThanEqual(absDiff(resColor, refColor), threshold.vec4), channelMask), channelMask));
360
361 if (!result)
362 {
363 std::stringstream s;
364 s << "Ref:" << refColor << " Mask:" << channelMask << " Threshold:" << threshold.vec4 << " Color:" << resColor;
365 stringResult = s.str();
366 }
367
368 return result;
369 }
370
371 case TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
372 {
373 const UVec4 resColor (access.getPixelUint(x, y, z));
374 const UVec4 refColor (ref.uint32[0],
375 ref.uint32[1],
376 ref.uint32[2],
377 ref.uint32[3]);
378 const bool result = !(anyNotEqual(logicalAnd(lessThanEqual(absDiff(resColor, refColor), threshold.uvec4), channelMask), channelMask));
379
380 if (!result)
381 {
382 std::stringstream s;
383 s << "Ref:" << refColor << " Mask:" << channelMask << " Threshold:" << threshold.uvec4 << " Color:" << resColor;
384 stringResult = s.str();
385 }
386
387 return result;
388 }
389
390 case TEXTURECHANNELCLASS_SIGNED_INTEGER:
391 {
392 const IVec4 resColor (access.getPixelInt(x, y, z));
393 const IVec4 refColor (ref.int32[0],
394 ref.int32[1],
395 ref.int32[2],
396 ref.int32[3]);
397 const bool result = !(anyNotEqual(logicalAnd(lessThanEqual(absDiff(resColor, refColor), threshold.ivec4), channelMask), channelMask));
398
399 if (!result)
400 {
401 std::stringstream s;
402 s << "Ref:" << refColor << " Mask:" << channelMask << " Threshold:" << threshold.ivec4 << " Color:" << resColor;
403 stringResult = s.str();
404 }
405
406 return result;
407 }
408
409 case TEXTURECHANNELCLASS_FLOATING_POINT:
410 {
411 const Vec4 resColor (access.getPixel(x, y, z));
412 const Vec4 refColor (ref.float32[0],
413 ref.float32[1],
414 ref.float32[2],
415 ref.float32[3]);
416 DE_ASSERT(allEqual(greaterThanEqual(threshold.ivec4, IVec4(0)), BVec4(true)));
417
418 for (int ndx = 0; ndx < 4; ndx++)
419 {
420 const bool result = !(calcFloatDiff(resColor[ndx], refColor[ndx]) > threshold.ivec4[ndx] && channelMask[ndx]);
421
422 if (!result)
423 {
424 float floatThreshold = Float32((deUint32)(threshold).ivec4[0]).asFloat();
425 Vec4 thresholdVec4 (floatThreshold,
426 floatThreshold,
427 floatThreshold,
428 floatThreshold);
429 std::stringstream s;
430 s << "Ref:" << refColor << " Mask:" << channelMask << " Threshold:" << thresholdVec4 << " Color:" << resColor;
431 stringResult = s.str();
432
433 return false;
434 }
435 }
436
437 return true;
438 }
439
440 default:
441 DE_FATAL("Invalid channel class");
442 return false;
443 }
444 }
445
extentToString(VkExtent3D extent,VkImageType imageType)446 std::string extentToString (VkExtent3D extent, VkImageType imageType)
447 {
448 // Don't append image dimensions when using the dimensions found in original test cases. This avoids name clashing with the old versions.
449 if (imageType == VK_IMAGE_TYPE_1D && extent.width == 256u) return "";
450 if (imageType == VK_IMAGE_TYPE_2D && extent.width == 256u && extent.height == 256u) return "";
451 if (imageType == VK_IMAGE_TYPE_3D && extent.width == 256u && extent.height == 256u && extent.depth == 16u) return "";
452
453 return (std::string("_") + de::toString(extent.width) + std::string("x") + de::toString(extent.height) + (extent.depth != 1 ? (std::string("x") + de::toString(extent.depth)) : ""));
454 }
455
456 enum SeparateDepthStencilLayoutMode
457 {
458 SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_NONE = 0,
459 SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_DEPTH,
460 SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_STENCIL,
461 };
462
463 struct TestParams
464 {
465 bool useSingleMipLevel; //!< only mip level 0, otherwise up to maxMipLevels
466 VkImageType imageType;
467 VkFormat imageFormat;
468 VkImageTiling imageTiling;
469 VkExtent3D imageExtent;
470 deUint32 imageLayerCount;
471 LayerRange imageViewLayerRange;
472 VkClearValue initValue;
473 VkClearValue clearValue[2]; //!< the second value is used with more than one mip map
474 bool useSeparateExpectedClearValue;
475 VkClearValue expectedClearValue[2];
476 LayerRange clearLayerRange;
477 AllocationKind allocationKind;
478 bool isCube;
479 SeparateDepthStencilLayoutMode separateDepthStencilLayoutMode;
480 bool isColorMultipleSubresourceRangeTest;
481 };
482
483 class ImageClearingTestInstance : public vkt::TestInstance
484 {
485 public:
486 ImageClearingTestInstance (Context& context,
487 const TestParams& testParams);
488
489 Move<VkCommandPool> createCommandPool (VkCommandPoolCreateFlags commandPoolCreateFlags) const;
490 Move<VkCommandBuffer> allocatePrimaryCommandBuffer (VkCommandPool commandPool) const;
491 Move<VkImage> createImage (VkImageType imageType, VkFormat format, VkImageTiling tiling, VkExtent3D extent, deUint32 arrayLayerCount, VkImageUsageFlags usage) const;
492 Move<VkImageView> createImageView (VkImage image, VkImageViewType viewType, VkFormat format, VkImageAspectFlags aspectMask, LayerRange layerRange) const;
493 Move<VkRenderPass> createRenderPass (VkFormat format) const;
494 Move<VkFramebuffer> createFrameBuffer (VkImageView imageView, VkRenderPass renderPass, deUint32 imageWidth, deUint32 imageHeight, deUint32 imageLayersCount) const;
495
496 void beginCommandBuffer (VkCommandBufferUsageFlags usageFlags) const;
497 void endCommandBuffer (void) const;
498 void submitCommandBuffer (void) const;
499 void beginRenderPass (VkSubpassContents content, VkClearValue clearValue) const;
500 void preClearImage (const deUint32 imageMipLevels, VkExtent3D imageExtent, deUint32 imageLayerCount, Unique<VkCommandBuffer>& commandBuffer) const;
501 Move<VkBuffer> createImageClearingBuffer (const DeviceInterface& vkd, const VkDevice device, Unique<VkImage>& image);
502
503 void pipelineImageBarrier (VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask, VkImageLayout oldLayout, VkImageLayout newLayout, VkImageAspectFlags aspectMask = 0u) const;
504 de::MovePtr<TextureLevelPyramid> readImage (VkImageAspectFlags aspectMask, deUint32 baseLayer) const;
505 tcu::TestStatus verifyResultImage (const std::string& successMessage, const UVec4& clearCoords = UVec4()) const;
506
507 protected:
508 enum ViewType
509 {
510 VIEW_TYPE_SINGLE,
511 VIEW_TYPE_ARRAY,
512 VIEW_TYPE_CUBE
513 };
514 VkImageViewType getCorrespondingImageViewType (VkImageType imageType, ViewType viewType) const;
515 VkImageUsageFlags getImageUsageFlags (VkFormat format) const;
516 VkImageAspectFlags getImageAspectFlags (VkFormat format) const;
517 bool getIsAttachmentFormat (VkFormat format, VkImageTiling tiling) const;
518 bool getIs3DFormat (VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags) const;
519 bool getIsStencilFormat (VkFormat format) const;
520 bool getIsDepthFormat (VkFormat format) const;
521 VkImageFormatProperties getImageFormatProperties (void) const;
522 VkImageCreateFlags getImageCreateFlags (void) const;
523 ViewType getViewType (deUint32 imageLayerCount) const;
524 de::MovePtr<Allocation> allocateAndBindImageMemory (VkImage image) const;
525 de::MovePtr<Allocation> allocateAndBindBufferMemory (VkBuffer buffer) const;
526
527 const TestParams& m_params;
528 const VkDevice m_device;
529 const InstanceInterface& m_vki;
530 const DeviceInterface& m_vkd;
531 const VkQueue m_queue;
532 const deUint32 m_queueFamilyIndex;
533 Allocator& m_allocator;
534
535 const bool m_isAttachmentFormat;
536 const VkImageUsageFlags m_imageUsageFlags;
537 const VkImageAspectFlags m_imageAspectFlags;
538 const VkImageFormatProperties m_imageFormatProperties;
539 const deUint32 m_imageMipLevels;
540 const deUint32 m_thresholdMipLevel;
541
542 Unique<VkCommandPool> m_commandPool;
543 Unique<VkCommandBuffer> m_commandBuffer;
544
545 const bool m_is3DFormat;
546 Unique<VkImage> m_image;
547 Move<VkBuffer> m_stagingBuffer;
548 de::MovePtr<Allocation> m_stagingBufferMemory;
549 de::MovePtr<Allocation> m_imageMemory;
550 Unique<VkImageView> m_imageView;
551 Move<VkRenderPass> m_renderPass;
552 Move<VkFramebuffer> m_frameBuffer;
553 };
554
ImageClearingTestInstance(Context & context,const TestParams & params)555 ImageClearingTestInstance::ImageClearingTestInstance (Context& context, const TestParams& params)
556 : TestInstance (context)
557 , m_params (params)
558 , m_device (context.getDevice())
559 , m_vki (context.getInstanceInterface())
560 , m_vkd (context.getDeviceInterface())
561 , m_queue (context.getUniversalQueue())
562 , m_queueFamilyIndex (context.getUniversalQueueFamilyIndex())
563 , m_allocator (context.getDefaultAllocator())
564 , m_isAttachmentFormat (getIsAttachmentFormat(params.imageFormat, params.imageTiling))
565 , m_imageUsageFlags (getImageUsageFlags(params.imageFormat))
566 , m_imageAspectFlags (getImageAspectFlags(params.imageFormat))
567 , m_imageFormatProperties (getImageFormatProperties())
568 , m_imageMipLevels (params.useSingleMipLevel ? 1u : getNumMipLevels(params.imageExtent, m_imageFormatProperties.maxMipLevels))
569 , m_thresholdMipLevel (std::max(m_imageMipLevels / 2u, 1u))
570 , m_commandPool (createCommandPool(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT))
571 , m_commandBuffer (allocatePrimaryCommandBuffer(*m_commandPool))
572 , m_is3DFormat (getIs3DFormat(params.imageFormat, params.imageType, params.imageTiling, getImageUsageFlags(params.imageFormat), 0u))
573
574 , m_image (createImage(params.imageType,
575 params.imageFormat,
576 params.imageTiling,
577 params.imageExtent,
578 params.imageLayerCount,
579 m_imageUsageFlags))
580
581 , m_stagingBuffer (createImageClearingBuffer(m_vkd, m_device, m_image))
582 , m_stagingBufferMemory (allocateAndBindBufferMemory(*m_stagingBuffer))
583
584 , m_imageMemory (allocateAndBindImageMemory(*m_image))
585 , m_imageView (m_isAttachmentFormat ? createImageView(*m_image,
586 getCorrespondingImageViewType(params.imageType, getViewType(params.imageLayerCount)),
587 params.imageFormat,
588 m_imageAspectFlags,
589 params.imageViewLayerRange) : vk::Move<VkImageView>())
590
591 {
592 if (m_params.allocationKind == ALLOCATION_KIND_DEDICATED)
593 context.requireDeviceFunctionality("VK_KHR_dedicated_allocation");
594
595 if (m_params.separateDepthStencilLayoutMode != SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_NONE)
596 context.requireDeviceFunctionality("VK_KHR_separate_depth_stencil_layouts");
597
598 if (!m_is3DFormat)
599 {
600 if (m_isAttachmentFormat)
601 {
602 m_renderPass = createRenderPass(params.imageFormat);
603 m_frameBuffer = createFrameBuffer(*m_imageView, *m_renderPass, params.imageExtent.width, params.imageExtent.height, params.imageViewLayerRange.layerCount);
604 }
605 }
606
607 }
608
getViewType(deUint32 imageLayerCount) const609 ImageClearingTestInstance::ViewType ImageClearingTestInstance::getViewType (deUint32 imageLayerCount) const
610 {
611 if (imageLayerCount > 1u)
612 return m_params.isCube ? VIEW_TYPE_CUBE : VIEW_TYPE_ARRAY;
613 else
614 return VIEW_TYPE_SINGLE;
615 }
616
getCorrespondingImageViewType(VkImageType imageType,ViewType viewType) const617 VkImageViewType ImageClearingTestInstance::getCorrespondingImageViewType (VkImageType imageType, ViewType viewType) const
618 {
619 switch (imageType)
620 {
621 case VK_IMAGE_TYPE_1D:
622 return (viewType == VIEW_TYPE_ARRAY) ? VK_IMAGE_VIEW_TYPE_1D_ARRAY : VK_IMAGE_VIEW_TYPE_1D;
623 case VK_IMAGE_TYPE_2D:
624 if (viewType == VIEW_TYPE_ARRAY)
625 return VK_IMAGE_VIEW_TYPE_2D_ARRAY;
626 else if (viewType == VIEW_TYPE_CUBE)
627 return VK_IMAGE_VIEW_TYPE_CUBE;
628 else
629 return VK_IMAGE_VIEW_TYPE_2D;
630 case VK_IMAGE_TYPE_3D:
631 if (viewType != VIEW_TYPE_SINGLE)
632 {
633 DE_FATAL("Cannot have 3D image array");
634 }
635 return VK_IMAGE_VIEW_TYPE_3D;
636 default:
637 DE_FATAL("Unknown image type!");
638 }
639
640 return VK_IMAGE_VIEW_TYPE_2D;
641 }
642
getImageUsageFlags(VkFormat format) const643 VkImageUsageFlags ImageClearingTestInstance::getImageUsageFlags (VkFormat format) const
644 {
645 VkImageUsageFlags commonFlags = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
646
647 if (m_isAttachmentFormat)
648 {
649 if (isDepthStencilFormat(format))
650 return commonFlags | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
651
652 return commonFlags | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
653 }
654 return commonFlags;
655 }
656
getImageAspectFlags(VkFormat format) const657 VkImageAspectFlags ImageClearingTestInstance::getImageAspectFlags (VkFormat format) const
658 {
659 VkImageAspectFlags imageAspectFlags = 0;
660
661 if (getIsDepthFormat(format))
662 imageAspectFlags |= VK_IMAGE_ASPECT_DEPTH_BIT;
663
664 if (getIsStencilFormat(format))
665 imageAspectFlags |= VK_IMAGE_ASPECT_STENCIL_BIT;
666
667 if (imageAspectFlags == 0)
668 imageAspectFlags = VK_IMAGE_ASPECT_COLOR_BIT;
669
670 return imageAspectFlags;
671 }
672
getIs3DFormat(VkFormat format,VkImageType type,VkImageTiling tiling,VkImageUsageFlags usage,VkImageCreateFlags flags) const673 bool ImageClearingTestInstance::getIs3DFormat (VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags) const
674 {
675 const VkImageFormatProperties props = vk::getPhysicalDeviceImageFormatProperties(m_vki, m_context.getPhysicalDevice(), format, type, tiling, usage, flags);
676
677 return props.maxExtent.depth > 1u;
678 }
679
getIsAttachmentFormat(VkFormat format,VkImageTiling tiling) const680 bool ImageClearingTestInstance::getIsAttachmentFormat (VkFormat format, VkImageTiling tiling) const
681 {
682 const VkFormatProperties props = vk::getPhysicalDeviceFormatProperties(m_vki, m_context.getPhysicalDevice(), format);
683 const VkFormatFeatureFlags features = tiling == VK_IMAGE_TILING_OPTIMAL ? props.optimalTilingFeatures : props.linearTilingFeatures;
684
685 return (features & (vk::VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | vk::VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) != 0;
686 }
687
getIsStencilFormat(VkFormat format) const688 bool ImageClearingTestInstance::getIsStencilFormat (VkFormat format) const
689 {
690 const TextureFormat tcuFormat = mapVkFormat(format);
691
692 if (tcuFormat.order == TextureFormat::S || tcuFormat.order == TextureFormat::DS)
693 return true;
694
695 return false;
696 }
697
getIsDepthFormat(VkFormat format) const698 bool ImageClearingTestInstance::getIsDepthFormat (VkFormat format) const
699 {
700 const TextureFormat tcuFormat = mapVkFormat(format);
701
702 if (tcuFormat.order == TextureFormat::D || tcuFormat.order == TextureFormat::DS)
703 return true;
704
705 return false;
706 }
707
getImageCreateFlags(void) const708 VkImageCreateFlags ImageClearingTestInstance::getImageCreateFlags (void) const
709 {
710 return m_params.isCube ? (VkImageCreateFlags)VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT : (VkImageCreateFlags)0;
711 }
712
getImageFormatProperties(void) const713 VkImageFormatProperties ImageClearingTestInstance::getImageFormatProperties (void) const
714 {
715 VkImageFormatProperties properties;
716 const VkResult result = m_vki.getPhysicalDeviceImageFormatProperties(m_context.getPhysicalDevice(), m_params.imageFormat, m_params.imageType,
717 m_params.imageTiling, m_imageUsageFlags, getImageCreateFlags(), &properties);
718
719 if (result == VK_ERROR_FORMAT_NOT_SUPPORTED)
720 TCU_THROW(NotSupportedError, "Format not supported");
721 else
722 return properties;
723 }
724
allocateAndBindImageMemory(VkImage image) const725 de::MovePtr<Allocation> ImageClearingTestInstance::allocateAndBindImageMemory (VkImage image) const
726 {
727 de::MovePtr<Allocation> imageMemory (allocateImage(m_vki, m_vkd, m_context.getPhysicalDevice(), m_device, image, MemoryRequirement::Any, m_allocator, m_params.allocationKind));
728 VK_CHECK(m_vkd.bindImageMemory(m_device, image, imageMemory->getMemory(), imageMemory->getOffset()));
729 return imageMemory;
730 }
731
allocateAndBindBufferMemory(VkBuffer buffer) const732 de::MovePtr<Allocation> ImageClearingTestInstance::allocateAndBindBufferMemory (VkBuffer buffer) const
733 {
734 de::MovePtr<Allocation> stagingBufferMemory = allocateBuffer(m_vki, m_vkd, m_context.getPhysicalDevice(), m_device, buffer, MemoryRequirement::HostVisible, m_allocator, m_params.allocationKind);
735 VK_CHECK(m_vkd.bindBufferMemory(m_device, buffer, stagingBufferMemory->getMemory(), stagingBufferMemory->getOffset()));
736 return stagingBufferMemory;
737 }
738
createCommandPool(VkCommandPoolCreateFlags commandPoolCreateFlags) const739 Move<VkCommandPool> ImageClearingTestInstance::createCommandPool (VkCommandPoolCreateFlags commandPoolCreateFlags) const
740 {
741 return vk::createCommandPool(m_vkd, m_device, commandPoolCreateFlags, m_queueFamilyIndex);
742 }
743
allocatePrimaryCommandBuffer(VkCommandPool commandPool) const744 Move<VkCommandBuffer> ImageClearingTestInstance::allocatePrimaryCommandBuffer (VkCommandPool commandPool) const
745 {
746 return vk::allocateCommandBuffer(m_vkd, m_device, commandPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
747 }
748
createImage(VkImageType imageType,VkFormat format,VkImageTiling tiling,VkExtent3D extent,deUint32 arrayLayerCount,VkImageUsageFlags usage) const749 Move<VkImage> ImageClearingTestInstance::createImage (VkImageType imageType, VkFormat format, VkImageTiling tiling, VkExtent3D extent, deUint32 arrayLayerCount, VkImageUsageFlags usage) const
750 {
751 if (arrayLayerCount > m_imageFormatProperties.maxArrayLayers)
752 TCU_THROW(NotSupportedError, "Device does not support enough image array layers");
753
754 const VkImageCreateInfo imageCreateInfo =
755 {
756 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
757 DE_NULL, // const void* pNext;
758 getImageCreateFlags(), // VkImageCreateFlags flags;
759 imageType, // VkImageType imageType;
760 format, // VkFormat format;
761 extent, // VkExtent3D extent;
762 m_imageMipLevels, // deUint32 mipLevels;
763 arrayLayerCount, // deUint32 arrayLayers;
764 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
765 tiling, // VkImageTiling tiling;
766 usage, // VkImageUsageFlags usage;
767 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
768 1u, // deUint32 queueFamilyIndexCount;
769 &m_queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
770 VK_IMAGE_LAYOUT_UNDEFINED // VkImageLayout initialLayout;
771 };
772
773 return vk::createImage(m_vkd, m_device, &imageCreateInfo, DE_NULL);
774 }
775
createImageView(VkImage image,VkImageViewType viewType,VkFormat format,VkImageAspectFlags aspectMask,LayerRange layerRange) const776 Move<VkImageView> ImageClearingTestInstance::createImageView (VkImage image, VkImageViewType viewType, VkFormat format, VkImageAspectFlags aspectMask, LayerRange layerRange) const
777 {
778 const VkImageViewCreateInfo imageViewCreateInfo =
779 {
780 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
781 DE_NULL, // const void* pNext;
782 0u, // VkImageViewCreateFlags flags;
783 image, // VkImage image;
784 viewType, // VkImageViewType viewType;
785 format, // VkFormat format;
786 {
787 VK_COMPONENT_SWIZZLE_IDENTITY, // VkComponentSwizzle r;
788 VK_COMPONENT_SWIZZLE_IDENTITY, // VkComponentSwizzle g;
789 VK_COMPONENT_SWIZZLE_IDENTITY, // VkComponentSwizzle b;
790 VK_COMPONENT_SWIZZLE_IDENTITY, // VkComponentSwizzle a;
791 }, // VkComponentMapping components;
792 {
793 aspectMask, // VkImageAspectFlags aspectMask;
794 0u, // deUint32 baseMipLevel;
795 1u, // deUint32 mipLevels;
796 layerRange.baseArrayLayer, // deUint32 baseArrayLayer;
797 layerRange.layerCount, // deUint32 arraySize;
798 }, // VkImageSubresourceRange subresourceRange;
799 };
800
801 return vk::createImageView(m_vkd, m_device, &imageViewCreateInfo, DE_NULL);
802 }
803
createRenderPass(VkFormat format) const804 Move<VkRenderPass> ImageClearingTestInstance::createRenderPass (VkFormat format) const
805 {
806 if (m_params.separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_NONE)
807 {
808 VkImageLayout imageLayout;
809
810 if (isDepthStencilFormat(format))
811 imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
812 else
813 imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
814
815 const VkAttachmentDescription attachmentDesc =
816 {
817 0u, // VkAttachmentDescriptionFlags flags;
818 format, // VkFormat format;
819 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
820 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
821 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
822 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp stencilLoadOp;
823 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp stencilStoreOp;
824 imageLayout, // VkImageLayout initialLayout;
825 imageLayout, // VkImageLayout finalLayout;
826 };
827
828 const VkAttachmentDescription attachments[1] =
829 {
830 attachmentDesc
831 };
832
833 const VkAttachmentReference attachmentRef =
834 {
835 0u, // deUint32 attachment;
836 imageLayout, // VkImageLayout layout;
837 };
838
839 const VkAttachmentReference* pColorAttachments = DE_NULL;
840 const VkAttachmentReference* pDepthStencilAttachment = DE_NULL;
841 deUint32 colorAttachmentCount = 1;
842
843 if (isDepthStencilFormat(format))
844 {
845 colorAttachmentCount = 0;
846 pDepthStencilAttachment = &attachmentRef;
847 }
848 else
849 {
850 colorAttachmentCount = 1;
851 pColorAttachments = &attachmentRef;
852 }
853
854 const VkSubpassDescription subpassDesc[1] =
855 {
856 {
857 0u, // VkSubpassDescriptionFlags flags;
858 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
859 0u, // deUint32 inputAttachmentCount;
860 DE_NULL, // const VkAttachmentReference* pInputAttachments;
861 colorAttachmentCount, // deUint32 colorAttachmentCount;
862 pColorAttachments, // const VkAttachmentReference* pColorAttachments;
863 DE_NULL, // const VkAttachmentReference* pResolveAttachments;
864 pDepthStencilAttachment, // const VkAttachmentReference* pDepthStencilAttachment;
865 0u, // deUint32 preserveAttachmentCount;
866 DE_NULL, // const VkAttachmentReference* pPreserveAttachments;
867 }
868 };
869
870 const VkRenderPassCreateInfo renderPassCreateInfo =
871 {
872 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // VkStructureType sType;
873 DE_NULL, // const void* pNext;
874 0u, // VkRenderPassCreateFlags flags;
875 1u, // deUint32 attachmentCount;
876 attachments, // const VkAttachmentDescription* pAttachments;
877 1u, // deUint32 subpassCount;
878 subpassDesc, // const VkSubpassDescription* pSubpasses;
879 0u, // deUint32 dependencyCount;
880 DE_NULL, // const VkSubpassDependency* pDependencies;
881 };
882
883 return vk::createRenderPass(m_vkd, m_device, &renderPassCreateInfo, DE_NULL);
884 }
885 else
886 {
887 // Make sure VK_KHR_create_renderpass2 is supported. Due to InstanceFactory1 being used and the render pass being created in
888 // the instance constructor and not every time, this is the best moment to check.
889 m_context.requireDeviceFunctionality("VK_KHR_create_renderpass2");
890
891 VkImageLayout initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
892 VkImageLayout finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
893 VkAttachmentDescriptionStencilLayoutKHR stencilLayouts =
894 {
895 VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_STENCIL_LAYOUT_KHR,
896 DE_NULL,
897 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
898 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
899 };
900
901 VkImageLayout imageLayout;
902 VkAttachmentReferenceStencilLayoutKHR stencilLayoutRef =
903 {
904 VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_STENCIL_LAYOUT_KHR,
905 DE_NULL,
906 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
907 };
908
909 if (m_params.separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_DEPTH)
910 {
911 initialLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL_KHR;
912 finalLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL_KHR;
913 stencilLayouts.stencilInitialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
914 stencilLayouts.stencilFinalLayout = VK_IMAGE_LAYOUT_GENERAL;
915 imageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL_KHR;
916 stencilLayoutRef.stencilLayout = VK_IMAGE_LAYOUT_GENERAL;
917 }
918 else
919 {
920 initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
921 finalLayout = VK_IMAGE_LAYOUT_GENERAL;
922 stencilLayouts.stencilInitialLayout = VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL_KHR;
923 stencilLayouts.stencilFinalLayout = VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL_KHR;
924 imageLayout = VK_IMAGE_LAYOUT_GENERAL;
925 stencilLayoutRef.stencilLayout = VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL_KHR;
926 }
927
928 const VkAttachmentDescription2KHR attachmentDesc =
929 {
930 VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2_KHR, // VkStructureType sType;
931 &stencilLayouts, // const void* pNext;
932 0u, // VkAttachmentDescriptionFlags flags;
933 format, // VkFormat format;
934 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
935 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
936 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
937 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp stencilLoadOp;
938 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp stencilStoreOp;
939 initialLayout, // VkImageLayout initialLayout;
940 finalLayout, // VkImageLayout finalLayout;
941 };
942
943 const VkAttachmentReference2KHR attachmentRef =
944 {
945 VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2_KHR, // VkStructureType sType;
946 &stencilLayoutRef, // const void* pNext;
947 0u, // deUint32 attachment;
948 imageLayout, // VkImageLayout layout;
949 0u, // VkImageAspectFlags aspectMask;
950 };
951
952 const VkSubpassDescription2KHR subpassDesc =
953 {
954 VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2_KHR, // VkStructureType sType;
955 DE_NULL, // const void* pNext;
956 0u, // VkSubpassDescriptionFlags flags;
957 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
958 0u, // deUint32 viewMask;
959 0u, // deUint32 inputAttachmentCount;
960 DE_NULL, // const VkAttachmentReference2KHR* pInputAttachments;
961 0u, // deUint32 colorAttachmentCount;
962 DE_NULL, // const VkAttachmentReference2KHR* pColorAttachments;
963 DE_NULL, // const VkAttachmentReference2KHR* pResolveAttachments;
964 &attachmentRef, // const VkAttachmentReference2KHR* pDepthStencilAttachment;
965 0u, // deUint32 preserveAttachmentCount;
966 DE_NULL, // const VkAttachmentReference2KHR* pPreserveAttachments;
967 };
968
969 const VkRenderPassCreateInfo2KHR renderPassCreateInfo =
970 {
971 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2_KHR, // VkStructureType sType;
972 DE_NULL, // const void* pNext;
973 0u, // VkRenderPassCreateFlags flags;
974 1u, // deUint32 attachmentCount;
975 &attachmentDesc, // const VkAttachmentDescription* pAttachments;
976 1u, // deUint32 subpassCount;
977 &subpassDesc, // const VkSubpassDescription* pSubpasses;
978 0u, // deUint32 dependencyCount;
979 DE_NULL, // const VkSubpassDependency* pDependencies;
980 0u, // deUint32 correlatedViewMaskCount;
981 DE_NULL, // const deUint32* pCorrelatedViewMasks;
982 };
983
984 return vk::createRenderPass2(m_vkd, m_device, &renderPassCreateInfo, DE_NULL);
985 }
986 }
987
createFrameBuffer(VkImageView imageView,VkRenderPass renderPass,deUint32 imageWidth,deUint32 imageHeight,deUint32 imageLayersCount) const988 Move<VkFramebuffer> ImageClearingTestInstance::createFrameBuffer (VkImageView imageView, VkRenderPass renderPass, deUint32 imageWidth, deUint32 imageHeight, deUint32 imageLayersCount) const
989 {
990 const VkImageView attachmentViews[1] =
991 {
992 imageView
993 };
994
995 const VkFramebufferCreateInfo framebufferCreateInfo =
996 {
997 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType;
998 DE_NULL, // const void* pNext;
999 0u, // VkFramebufferCreateFlags flags;
1000 renderPass, // VkRenderPass renderPass;
1001 1, // deUint32 attachmentCount;
1002 attachmentViews, // const VkImageView* pAttachments;
1003 imageWidth, // deUint32 width;
1004 imageHeight, // deUint32 height;
1005 imageLayersCount, // deUint32 layers;
1006 };
1007
1008 return createFramebuffer(m_vkd, m_device, &framebufferCreateInfo, DE_NULL);
1009 }
1010
beginCommandBuffer(VkCommandBufferUsageFlags usageFlags) const1011 void ImageClearingTestInstance::beginCommandBuffer (VkCommandBufferUsageFlags usageFlags) const
1012 {
1013 vk::beginCommandBuffer(m_vkd, *m_commandBuffer, usageFlags);
1014 }
1015
endCommandBuffer(void) const1016 void ImageClearingTestInstance::endCommandBuffer (void) const
1017 {
1018 vk::endCommandBuffer(m_vkd, *m_commandBuffer);
1019 }
1020
submitCommandBuffer(void) const1021 void ImageClearingTestInstance::submitCommandBuffer (void) const
1022 {
1023 submitCommandsAndWait(m_vkd, m_device, m_queue, m_commandBuffer.get());
1024 }
1025
pipelineImageBarrier(VkPipelineStageFlags srcStageMask,VkPipelineStageFlags dstStageMask,VkAccessFlags srcAccessMask,VkAccessFlags dstAccessMask,VkImageLayout oldLayout,VkImageLayout newLayout,VkImageAspectFlags aspectMask) const1026 void ImageClearingTestInstance::pipelineImageBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask, VkImageLayout oldLayout, VkImageLayout newLayout, VkImageAspectFlags aspectMask) const
1027 {
1028 if (!aspectMask || m_params.separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_NONE)
1029 aspectMask = m_imageAspectFlags;
1030
1031 const VkImageMemoryBarrier imageBarrier =
1032 {
1033 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
1034 DE_NULL, // const void* pNext;
1035 srcAccessMask, // VkAccessFlags srcAccessMask;
1036 dstAccessMask, // VkAccessFlags dstAccessMask;
1037 oldLayout, // VkImageLayout oldLayout;
1038 newLayout, // VkImageLayout newLayout;
1039 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
1040 VK_QUEUE_FAMILY_IGNORED, // deUint32 destQueueFamilyIndex;
1041 *m_image, // VkImage image;
1042 {
1043 aspectMask, // VkImageAspectFlags aspectMask;
1044 0u, // deUint32 baseMipLevel;
1045 VK_REMAINING_MIP_LEVELS, // deUint32 levelCount;
1046 0u, // deUint32 baseArrayLayer;
1047 VK_REMAINING_ARRAY_LAYERS, // deUint32 layerCount;
1048 }, // VkImageSubresourceRange subresourceRange;
1049 };
1050
1051 m_vkd.cmdPipelineBarrier(*m_commandBuffer, srcStageMask, dstStageMask, 0, 0, DE_NULL, 0, DE_NULL, 1, &imageBarrier);
1052 }
1053
readImage(VkImageAspectFlags aspectMask,deUint32 arrayLayer) const1054 de::MovePtr<TextureLevelPyramid> ImageClearingTestInstance::readImage (VkImageAspectFlags aspectMask, deUint32 arrayLayer) const
1055 {
1056 const TextureFormat tcuFormat = aspectMask == VK_IMAGE_ASPECT_COLOR_BIT ? mapVkFormat(m_params.imageFormat) :
1057 aspectMask == VK_IMAGE_ASPECT_DEPTH_BIT ? getDepthCopyFormat(m_params.imageFormat) :
1058 aspectMask == VK_IMAGE_ASPECT_STENCIL_BIT ? getStencilCopyFormat(m_params.imageFormat) :
1059 TextureFormat();
1060 const deUint32 pixelSize = getPixelSize(tcuFormat);
1061 deUint32 alignment = 4; // subsequent mip levels aligned to 4 bytes
1062
1063 if (!getIsDepthFormat(m_params.imageFormat) && !getIsStencilFormat(m_params.imageFormat))
1064 alignment = lowestCommonMultiple(pixelSize, alignment); // alignment must be multiple of pixel size, if not D/S.
1065
1066 const std::vector<deUint32> mipLevelSizes = getImageMipLevelSizes(pixelSize, m_params.imageExtent, m_imageMipLevels, alignment);
1067 const VkDeviceSize imageTotalSize = std::accumulate(mipLevelSizes.begin(), mipLevelSizes.end(), 0u);
1068
1069 de::MovePtr<TextureLevelPyramid> result (new TextureLevelPyramid(tcuFormat, m_imageMipLevels));
1070 Move<VkBuffer> buffer;
1071 de::MovePtr<Allocation> bufferAlloc;
1072
1073 // Create destination buffer
1074 {
1075 const VkBufferCreateInfo bufferParams =
1076 {
1077 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
1078 DE_NULL, // const void* pNext;
1079 0u, // VkBufferCreateFlags flags;
1080 imageTotalSize, // VkDeviceSize size;
1081 VK_BUFFER_USAGE_TRANSFER_DST_BIT, // VkBufferUsageFlags usage;
1082 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1083 0u, // deUint32 queueFamilyIndexCount;
1084 DE_NULL // const deUint32* pQueueFamilyIndices;
1085 };
1086
1087 buffer = createBuffer(m_vkd, m_device, &bufferParams);
1088 bufferAlloc = allocateBuffer(m_vki, m_vkd, m_context.getPhysicalDevice(), m_device, *buffer, MemoryRequirement::HostVisible, m_allocator, m_params.allocationKind);
1089 VK_CHECK(m_vkd.bindBufferMemory(m_device, *buffer, bufferAlloc->getMemory(), bufferAlloc->getOffset()));
1090 }
1091
1092 // Barriers for copying image to buffer
1093
1094 const VkBufferMemoryBarrier bufferBarrier =
1095 {
1096 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
1097 DE_NULL, // const void* pNext;
1098 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
1099 VK_ACCESS_HOST_READ_BIT, // VkAccessFlags dstAccessMask;
1100 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
1101 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
1102 *buffer, // VkBuffer buffer;
1103 0u, // VkDeviceSize offset;
1104 imageTotalSize, // VkDeviceSize size;
1105 };
1106
1107 // Copy image to buffer
1108 std::vector<VkBufferImageCopy> copyRegions;
1109 {
1110 deUint32 offset = 0u;
1111 for (deUint32 mipLevel = 0; mipLevel < m_imageMipLevels; ++mipLevel)
1112 {
1113 const VkExtent3D extent = getMipLevelExtent(m_params.imageExtent, mipLevel);
1114 const VkBufferImageCopy region =
1115 {
1116 offset, // VkDeviceSize bufferOffset;
1117 0u, // deUint32 bufferRowLength;
1118 0u, // deUint32 bufferImageHeight;
1119 { aspectMask, mipLevel, arrayLayer, 1u }, // VkImageSubresourceLayers imageSubresource;
1120 { 0, 0, 0 }, // VkOffset3D imageOffset;
1121 extent // VkExtent3D imageExtent;
1122 };
1123 copyRegions.push_back(region);
1124 offset += mipLevelSizes[mipLevel];
1125 }
1126 }
1127
1128 beginCommandBuffer(0);
1129
1130 pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT,
1131 VK_PIPELINE_STAGE_TRANSFER_BIT,
1132 VK_ACCESS_TRANSFER_WRITE_BIT,
1133 VK_ACCESS_TRANSFER_READ_BIT,
1134 VK_IMAGE_LAYOUT_GENERAL,
1135 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1136 aspectMask);
1137
1138 m_vkd.cmdCopyImageToBuffer(*m_commandBuffer, *m_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *buffer, static_cast<deUint32>(copyRegions.size()), ©Regions[0]);
1139 m_vkd.cmdPipelineBarrier(*m_commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &bufferBarrier, 0, (const VkImageMemoryBarrier*)DE_NULL);
1140
1141 pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT,
1142 VK_PIPELINE_STAGE_TRANSFER_BIT,
1143 VK_ACCESS_TRANSFER_READ_BIT,
1144 VK_ACCESS_TRANSFER_READ_BIT,
1145 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1146 VK_IMAGE_LAYOUT_GENERAL,
1147 aspectMask);
1148
1149 endCommandBuffer();
1150 submitCommandBuffer();
1151
1152 invalidateAlloc(m_vkd, m_device, *bufferAlloc);
1153
1154 {
1155 deUint32 offset = 0u;
1156 for (deUint32 mipLevel = 0; mipLevel < m_imageMipLevels; ++mipLevel)
1157 {
1158 const VkExtent3D extent = getMipLevelExtent(m_params.imageExtent, mipLevel);
1159 const void* pLevelData = static_cast<const void*>(reinterpret_cast<deUint8*>(bufferAlloc->getHostPtr()) + offset);
1160
1161 result->allocLevel(mipLevel, extent.width, extent.height, extent.depth);
1162 copy(result->getLevel(mipLevel), ConstPixelBufferAccess(result->getFormat(), result->getLevel(mipLevel).getSize(), pLevelData));
1163
1164 offset += mipLevelSizes[mipLevel];
1165 }
1166 }
1167
1168 return result;
1169 }
1170
verifyResultImage(const std::string & successMessage,const UVec4 & clearCoords) const1171 tcu::TestStatus ImageClearingTestInstance::verifyResultImage (const std::string& successMessage, const UVec4& clearCoords) const
1172 {
1173 DE_ASSERT((clearCoords == UVec4()) || m_params.imageExtent.depth == 1u);
1174
1175 if (getIsDepthFormat(m_params.imageFormat) && m_params.separateDepthStencilLayoutMode != SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_STENCIL)
1176 {
1177 DE_ASSERT(m_imageMipLevels == 1u);
1178
1179 for (deUint32 arrayLayer = 0; arrayLayer < m_params.imageLayerCount; ++arrayLayer)
1180 {
1181 de::MovePtr<TextureLevelPyramid> image = readImage(VK_IMAGE_ASPECT_DEPTH_BIT, arrayLayer);
1182 std::string message;
1183 float depthValue;
1184
1185 for (deUint32 y = 0; y < m_params.imageExtent.height; ++y)
1186 for (deUint32 x = 0; x < m_params.imageExtent.width; ++x)
1187 {
1188 if (isInClearRange(clearCoords, x, y, arrayLayer, m_params.imageViewLayerRange, m_params.clearLayerRange))
1189 depthValue = m_params.clearValue[0].depthStencil.depth;
1190 else
1191 if (isInInitialClearRange(0u /* mipLevel */, arrayLayer, m_params.imageViewLayerRange))
1192 {
1193 depthValue = m_params.initValue.depthStencil.depth;
1194 }
1195 else
1196 continue;
1197
1198 if (!comparePixelToDepthClearValue(image->getLevel(0), x, y, depthValue, message))
1199 return TestStatus::fail("Depth value mismatch! " + message);
1200 }
1201 }
1202 }
1203
1204 if (getIsStencilFormat(m_params.imageFormat) && m_params.separateDepthStencilLayoutMode != SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_DEPTH)
1205 {
1206 DE_ASSERT(m_imageMipLevels == 1u);
1207
1208 for (deUint32 arrayLayer = 0; arrayLayer < m_params.imageLayerCount; ++arrayLayer)
1209 {
1210 de::MovePtr<TextureLevelPyramid> image = readImage(VK_IMAGE_ASPECT_STENCIL_BIT, arrayLayer);
1211 std::string message;
1212 deUint32 stencilValue;
1213
1214 for (deUint32 y = 0; y < m_params.imageExtent.height; ++y)
1215 for (deUint32 x = 0; x < m_params.imageExtent.width; ++x)
1216 {
1217 if (isInClearRange(clearCoords, x, y, arrayLayer, m_params.imageViewLayerRange, m_params.clearLayerRange))
1218 stencilValue = m_params.clearValue[0].depthStencil.stencil;
1219 else
1220 if (isInInitialClearRange(0u /* mipLevel */, arrayLayer, m_params.imageViewLayerRange))
1221 {
1222 stencilValue = m_params.initValue.depthStencil.stencil;
1223 }
1224 else
1225 continue;
1226
1227 if (!comparePixelToStencilClearValue(image->getLevel(0), x, y, stencilValue, message))
1228 return TestStatus::fail("Stencil value mismatch! " + message);
1229 }
1230 }
1231 }
1232
1233 if (!isDepthStencilFormat(m_params.imageFormat))
1234 {
1235 const TextureFormat format = mapVkFormat(m_params.imageFormat);
1236 const TextureChannelClass channelClass = getTextureChannelClass(format.type);
1237 const BVec4 channelMask = getTextureFormatChannelMask(format);
1238 Threshold threshold {Vec4 (0)};
1239 switch (channelClass)
1240 {
1241 case TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1242 case TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1243 {
1244 const IVec4 formatDepth = getTextureFormatBitDepth(format);
1245 const int modifier = (channelClass == TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT) ? 0 : 1;
1246 threshold.vec4 = {formatDepth[0] > 0 ? 1.0f / ((float)(1 << (formatDepth[0] - modifier)) - 1.0f) : 1.0f,
1247 formatDepth[1] > 0 ? 1.0f / ((float)(1 << (formatDepth[1] - modifier)) - 1.0f) : 1.0f,
1248 formatDepth[2] > 0 ? 1.0f / ((float)(1 << (formatDepth[2] - modifier)) - 1.0f) : 1.0f,
1249 formatDepth[3] > 0 ? 1.0f / ((float)(1 << (formatDepth[3] - modifier)) - 1.0f) : 1.0f};
1250 break;
1251 }
1252 case TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1253 {
1254 threshold.uvec4 = UVec4(1U);
1255 break;
1256 }
1257 case TEXTURECHANNELCLASS_SIGNED_INTEGER:
1258 {
1259 threshold.ivec4 = IVec4(1);
1260 break;
1261 }
1262 case TEXTURECHANNELCLASS_FLOATING_POINT:
1263 {
1264 const IVec4& mantissaBits = getTextureFormatMantissaBitDepth(format);
1265 threshold.ivec4 = IVec4(10 * IVec4(1) << (23 - mantissaBits));
1266 break;
1267 }
1268 default:
1269 DE_FATAL("Invalid channel class");
1270 }
1271
1272 for (deUint32 arrayLayer = 0; arrayLayer < m_params.imageLayerCount; ++arrayLayer)
1273 {
1274 de::MovePtr<TextureLevelPyramid> image = readImage(VK_IMAGE_ASPECT_COLOR_BIT, arrayLayer);
1275 std::string message;
1276 const VkClearColorValue* pColorValue;
1277
1278 for (deUint32 mipLevel = 0; mipLevel < m_imageMipLevels; ++mipLevel)
1279 {
1280 const int clearColorNdx = ((mipLevel < m_thresholdMipLevel || m_params.isColorMultipleSubresourceRangeTest) ? 0 : 1);
1281 const VkExtent3D extent = getMipLevelExtent(m_params.imageExtent, mipLevel);
1282 const VkClearColorValue* pExpectedColorValue = &(m_params.useSeparateExpectedClearValue ? m_params.expectedClearValue : m_params.clearValue)[clearColorNdx].color;
1283 const auto& pixelBufferAccess = image->getLevel(mipLevel);
1284
1285 for (deUint32 z = 0; z < extent.depth; ++z)
1286 for (deUint32 y = 0; y < extent.height; ++y)
1287 for (deUint32 x = 0; x < extent.width; ++x)
1288 {
1289 if (isInClearRange(clearCoords, x, y, arrayLayer, m_params.imageViewLayerRange, m_params.clearLayerRange))
1290 {
1291 pColorValue = pExpectedColorValue;
1292 }
1293 else
1294 {
1295 if (isInInitialClearRange(mipLevel, arrayLayer, m_params.imageViewLayerRange))
1296 {
1297 pColorValue = &m_params.initValue.color;
1298 }
1299 else
1300 {
1301 continue;
1302 }
1303 }
1304 if (!comparePixelToColorClearValue(pixelBufferAccess, x, y, z, *pColorValue, message, threshold, channelMask, channelClass))
1305 return TestStatus::fail("Color value mismatch! " + message);
1306 }
1307 }
1308 }
1309 }
1310
1311 return TestStatus::pass(successMessage);
1312 }
1313
createImageClearingBuffer(const DeviceInterface & vkd,const VkDevice device,Unique<VkImage> & image)1314 Move<VkBuffer> ImageClearingTestInstance::createImageClearingBuffer(const DeviceInterface& vkd, const VkDevice device, Unique<VkImage>& image)
1315 {
1316 Move<VkBuffer> stagingBuffer;
1317 de::MovePtr<Allocation> stagingBufferAlloc;
1318 const VkDeviceSize stagingBufferSize = getImageMemoryRequirements(vkd, device, *image).size;
1319 // Create image clearing buffer
1320 {
1321 const VkBufferCreateInfo bufferParams =
1322 {
1323 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
1324 DE_NULL, // const void* pNext;
1325 0u, // VkBufferCreateFlags flags;
1326 stagingBufferSize, // VkDeviceSize size;
1327 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, // VkBufferUsageFlags usage;
1328 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1329 0u, // deUint32 queueFamilyIndexCount;
1330 DE_NULL // const deUint32* pQueueFamilyIndices;
1331 };
1332 stagingBuffer = createBuffer(vkd, device, &bufferParams);
1333 }
1334 return stagingBuffer;
1335 }
1336
preClearImage(const deUint32 imageMipLevels,VkExtent3D imageExtent,deUint32 imageLayerCount,Unique<VkCommandBuffer> & commandBuffer) const1337 void ImageClearingTestInstance::preClearImage (const deUint32 imageMipLevels, VkExtent3D imageExtent, deUint32 imageLayerCount, Unique<VkCommandBuffer>& commandBuffer) const
1338 {
1339 std::vector<VkBufferImageCopy> copyRegions;
1340 std::vector<VkImageAspectFlags> aspectMasks;
1341
1342 if (getIsDepthFormat(m_params.imageFormat))
1343 aspectMasks.push_back(VK_IMAGE_ASPECT_DEPTH_BIT);
1344 if (getIsStencilFormat(m_params.imageFormat))
1345 aspectMasks.push_back(VK_IMAGE_ASPECT_STENCIL_BIT);
1346 if (aspectMasks.empty())
1347 aspectMasks.push_back(VK_IMAGE_ASPECT_COLOR_BIT);
1348
1349 for (deUint32 mipLevel = 0; mipLevel < imageMipLevels; ++mipLevel)
1350 {
1351 const VkExtent3D extent = getMipLevelExtent(imageExtent, mipLevel);
1352 for (auto mask : aspectMasks)
1353 {
1354 const VkImageSubresourceLayers imageSubResource =
1355 {
1356 mask, // VkImageAspectFlags aspectMask
1357 mipLevel, // uint32_t mipLevel
1358 0u, // uint32_t baseArrayLayer
1359 imageLayerCount // uint32_t layerCount
1360 };
1361 const VkBufferImageCopy region =
1362 {
1363 0u, // VkDeviceSize bufferOffset;
1364 0u, // deUint32 bufferRowLength;
1365 0u, // deUint32 bufferImageHeight;
1366 imageSubResource, // VkImageSubresourceLayers imageSubresource;
1367 {0, 0, 0}, // VkOffset3D imageOffset;
1368 extent // VkExtent3D imageExtent;
1369 };
1370 copyRegions.push_back(region);
1371 }
1372 }
1373
1374 m_vkd.cmdFillBuffer(*commandBuffer, *m_stagingBuffer, 0u, VK_WHOLE_SIZE, 0u);
1375
1376 pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, // VkPipelineStageFlags srcStageMask
1377 VK_PIPELINE_STAGE_TRANSFER_BIT, // VkPipelineStageFlags dstStageMask
1378 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask
1379 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask
1380 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
1381 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); // VkImageLayout newLayout;
1382
1383 m_vkd.cmdCopyBufferToImage(*commandBuffer, *m_stagingBuffer, *m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, static_cast<deUint32>(copyRegions.size()), ©Regions[0]);
1384 }
1385
beginRenderPass(VkSubpassContents content,VkClearValue clearValue) const1386 void ImageClearingTestInstance::beginRenderPass (VkSubpassContents content, VkClearValue clearValue) const
1387 {
1388 vk::beginRenderPass(m_vkd, *m_commandBuffer, *m_renderPass, *m_frameBuffer, makeRect2D(0, 0, m_params.imageExtent.width, m_params.imageExtent.height), clearValue, content);
1389 }
1390
1391 class ClearColorImageTestInstance : public ImageClearingTestInstance
1392 {
1393 public:
ClearColorImageTestInstance(Context & context,const TestParams & testParams,bool twoStep=false)1394 ClearColorImageTestInstance (Context& context, const TestParams& testParams, bool twoStep = false) : ImageClearingTestInstance (context, testParams), m_twoStep(twoStep) {}
1395 virtual TestStatus iterate (void);
1396 protected:
1397 bool m_twoStep;
1398 };
1399
1400 class TwoStepClearColorImageTestInstance : public ClearColorImageTestInstance
1401 {
1402 public:
TwoStepClearColorImageTestInstance(Context & context,const TestParams & testParams)1403 TwoStepClearColorImageTestInstance (Context& context, const TestParams& testParams) : ClearColorImageTestInstance(context, testParams, true) {}
1404 };
1405
1406 class ClearColorImageMultipleSubresourceRangeTestInstance : public ClearColorImageTestInstance
1407 {
1408 public:
ClearColorImageMultipleSubresourceRangeTestInstance(Context & context,const TestParams & testParams)1409 ClearColorImageMultipleSubresourceRangeTestInstance (Context& context, const TestParams& testParams) : ClearColorImageTestInstance(context, testParams, false) {}
1410 virtual TestStatus iterate (void);
1411 };
1412
iterate(void)1413 TestStatus ClearColorImageMultipleSubresourceRangeTestInstance::iterate(void)
1414 {
1415 std::vector<VkImageSubresourceRange> subresourceRanges;
1416
1417 DE_ASSERT(m_imageMipLevels > 1u);
1418
1419 deUint32 mipLevel = 0u;
1420 // Create a subresource range per mipmap level.
1421 do {
1422 subresourceRanges.push_back(makeImageSubresourceRange(m_imageAspectFlags, mipLevel++, 1u, m_params.clearLayerRange.baseArrayLayer, m_params.clearLayerRange.layerCount));
1423 } while (mipLevel < m_imageMipLevels);
1424
1425 beginCommandBuffer(0);
1426
1427 pipelineImageBarrier(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, // VkPipelineStageFlags srcStageMask
1428 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, // VkPipelineStageFlags dstStageMask
1429 0, // VkAccessFlags srcAccessMask
1430 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask
1431 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
1432 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); // VkImageLayout newLayout;
1433
1434 preClearImage(m_imageMipLevels, m_params.imageExtent, m_params.imageLayerCount, m_commandBuffer);
1435
1436 pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, // VkPipelineStageFlags srcStageMask
1437 VK_PIPELINE_STAGE_TRANSFER_BIT, // VkPipelineStageFlags dstStageMask
1438 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask
1439 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask
1440 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
1441 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); // VkImageLayout newLayout;
1442
1443 // Test clear color in all ranges
1444 m_vkd.cmdClearColorImage(*m_commandBuffer, *m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &m_params.clearValue[0].color, static_cast<deUint32>(subresourceRanges.size()), subresourceRanges.data());
1445
1446 pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, // VkPipelineStageFlags srcStageMask
1447 VK_PIPELINE_STAGE_TRANSFER_BIT, // VkPipelineStageFlags dstStageMask
1448 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask
1449 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask
1450 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
1451 VK_IMAGE_LAYOUT_GENERAL); // VkImageLayout newLayout;
1452
1453 endCommandBuffer();
1454 submitCommandBuffer();
1455
1456 return verifyResultImage("cmdClearColorImage passed");
1457 }
1458
iterate(void)1459 TestStatus ClearColorImageTestInstance::iterate (void)
1460 {
1461 std::vector<VkImageSubresourceRange> subresourceRanges;
1462 std::vector<VkImageSubresourceRange> steptwoRanges;
1463
1464 if (m_imageMipLevels == 1)
1465 {
1466 subresourceRanges.push_back(makeImageSubresourceRange(m_imageAspectFlags, 0u, 1u, m_params.clearLayerRange.baseArrayLayer, m_twoStep ? 1 : m_params.clearLayerRange.layerCount));
1467 steptwoRanges.push_back( makeImageSubresourceRange(m_imageAspectFlags, 0u, VK_REMAINING_MIP_LEVELS, m_params.clearLayerRange.baseArrayLayer, VK_REMAINING_ARRAY_LAYERS));
1468 }
1469 else
1470 {
1471 subresourceRanges.push_back(makeImageSubresourceRange(m_imageAspectFlags, 0u, m_thresholdMipLevel, m_params.clearLayerRange.baseArrayLayer, m_params.clearLayerRange.layerCount));
1472 subresourceRanges.push_back(makeImageSubresourceRange(m_imageAspectFlags, m_thresholdMipLevel, VK_REMAINING_MIP_LEVELS, m_params.clearLayerRange.baseArrayLayer, m_params.clearLayerRange.layerCount));
1473 steptwoRanges.push_back( makeImageSubresourceRange(m_imageAspectFlags, 0u, m_thresholdMipLevel, m_params.clearLayerRange.baseArrayLayer, VK_REMAINING_ARRAY_LAYERS));
1474 steptwoRanges.push_back( makeImageSubresourceRange(m_imageAspectFlags, m_thresholdMipLevel, VK_REMAINING_MIP_LEVELS, m_params.clearLayerRange.baseArrayLayer, VK_REMAINING_ARRAY_LAYERS));
1475 }
1476
1477 beginCommandBuffer(0);
1478
1479 pipelineImageBarrier(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, // VkPipelineStageFlags srcStageMask
1480 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, // VkPipelineStageFlags dstStageMask
1481 0, // VkAccessFlags srcAccessMask
1482 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask
1483 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
1484 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); // VkImageLayout newLayout;
1485
1486 preClearImage(m_imageMipLevels, m_params.imageExtent, m_params.imageLayerCount, m_commandBuffer);
1487
1488 pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, // VkPipelineStageFlags srcStageMask
1489 VK_PIPELINE_STAGE_TRANSFER_BIT, // VkPipelineStageFlags dstStageMask
1490 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask
1491 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask
1492 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
1493 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); // VkImageLayout newLayout;
1494
1495 // Different clear color per range
1496 for (std::size_t i = 0u; i < subresourceRanges.size(); ++i)
1497 {
1498 m_vkd.cmdClearColorImage(*m_commandBuffer, *m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &m_params.clearValue[i].color, 1, &subresourceRanges[i]);
1499
1500 if (m_twoStep)
1501 {
1502 pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, // VkPipelineStageFlags srcStageMask
1503 VK_PIPELINE_STAGE_TRANSFER_BIT, // VkPipelineStageFlags dstStageMask
1504 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask
1505 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask
1506 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
1507 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); // VkImageLayout newLayout;
1508
1509 m_vkd.cmdClearColorImage(*m_commandBuffer, *m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &m_params.clearValue[i].color, 1, &steptwoRanges[i]);
1510 }
1511 }
1512
1513 pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, // VkPipelineStageFlags srcStageMask
1514 VK_PIPELINE_STAGE_TRANSFER_BIT, // VkPipelineStageFlags dstStageMask
1515 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask
1516 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask
1517 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
1518 VK_IMAGE_LAYOUT_GENERAL); // VkImageLayout newLayout;
1519
1520 endCommandBuffer();
1521 submitCommandBuffer();
1522
1523 return verifyResultImage("cmdClearColorImage passed");
1524 }
1525
1526 class ClearDepthStencilImageTestInstance : public ImageClearingTestInstance
1527 {
1528 public:
ClearDepthStencilImageTestInstance(Context & context,const TestParams & testParams,bool twoStep=false)1529 ClearDepthStencilImageTestInstance (Context& context, const TestParams& testParams, bool twoStep = false) : ImageClearingTestInstance (context, testParams), m_twoStep(twoStep) {}
1530 virtual TestStatus iterate (void);
1531 protected:
1532 bool m_twoStep;
1533 };
1534
1535 class TwoStepClearDepthStencilImageTestInstance : public ClearDepthStencilImageTestInstance
1536 {
1537 public:
TwoStepClearDepthStencilImageTestInstance(Context & context,const TestParams & testParams)1538 TwoStepClearDepthStencilImageTestInstance (Context& context, const TestParams& testParams) : ClearDepthStencilImageTestInstance (context, testParams, true) { }
1539 };
1540
1541 class ClearDepthStencilImageMultipleSubresourceRangeTestInstance : public ClearDepthStencilImageTestInstance
1542 {
1543 public:
ClearDepthStencilImageMultipleSubresourceRangeTestInstance(Context & context,const TestParams & testParams)1544 ClearDepthStencilImageMultipleSubresourceRangeTestInstance (Context& context, const TestParams& testParams) : ClearDepthStencilImageTestInstance(context, testParams, false) { }
1545 virtual TestStatus iterate (void);
1546 };
1547
iterate(void)1548 TestStatus ClearDepthStencilImageMultipleSubresourceRangeTestInstance::iterate (void)
1549 {
1550 VkImageAspectFlags aspectMask = m_imageAspectFlags;
1551
1552 // Depth/Stencil formats only. No separate layout modes.
1553 DE_ASSERT(m_params.separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_NONE);
1554
1555 std::vector<VkImageSubresourceRange> subresourceRanges;
1556
1557 subresourceRanges.push_back(makeImageSubresourceRange(VK_IMAGE_ASPECT_STENCIL_BIT, 0u, 1u, m_params.clearLayerRange.baseArrayLayer, m_params.clearLayerRange.layerCount));
1558 subresourceRanges.push_back(makeImageSubresourceRange(VK_IMAGE_ASPECT_DEPTH_BIT, 0u, 1u, m_params.clearLayerRange.baseArrayLayer, m_params.clearLayerRange.layerCount));
1559
1560 beginCommandBuffer(0);
1561
1562 pipelineImageBarrier(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, // VkPipelineStageFlags srcStageMask
1563 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, // VkPipelineStageFlags dstStageMask
1564 0, // VkAccessFlags srcAccessMask
1565 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask
1566 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
1567 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); // VkImageLayout newLayout;
1568
1569 preClearImage(m_imageMipLevels, m_params.imageExtent, m_params.imageLayerCount, m_commandBuffer);
1570
1571 pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, // VkPipelineStageFlags srcStageMask
1572 VK_PIPELINE_STAGE_TRANSFER_BIT, // VkPipelineStageFlags dstStageMask
1573 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask
1574 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask
1575 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
1576 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); // VkImageLayout newLayout;
1577
1578 m_vkd.cmdClearDepthStencilImage(*m_commandBuffer, *m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &m_params.clearValue[0].depthStencil, static_cast<deUint32>(subresourceRanges.size()), subresourceRanges.data());
1579
1580 pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, // VkPipelineStageFlags srcStageMask
1581 VK_PIPELINE_STAGE_TRANSFER_BIT, // VkPipelineStageFlags dstStageMask
1582 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask
1583 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask
1584 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
1585 VK_IMAGE_LAYOUT_GENERAL, // VkImageLayout newLayout;
1586 aspectMask); // VkImageAspectFlags aspectMask;
1587
1588 endCommandBuffer();
1589 submitCommandBuffer();
1590
1591 return verifyResultImage("cmdClearDepthStencilImage passed");
1592 }
1593
iterate(void)1594 TestStatus ClearDepthStencilImageTestInstance::iterate (void)
1595 {
1596 VkImageAspectFlags aspectMask = m_imageAspectFlags;
1597 if (m_params.separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_DEPTH)
1598 {
1599 aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
1600 }
1601 else if (m_params.separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_STENCIL)
1602 {
1603 aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
1604 }
1605
1606 const VkImageSubresourceRange subresourceRange = makeImageSubresourceRange(aspectMask, 0u, 1u, m_params.clearLayerRange.baseArrayLayer, m_twoStep ? 1 : m_params.clearLayerRange.layerCount);
1607 const VkImageSubresourceRange steptwoRange = makeImageSubresourceRange(aspectMask, 0u, VK_REMAINING_MIP_LEVELS, m_params.clearLayerRange.baseArrayLayer, VK_REMAINING_ARRAY_LAYERS);
1608
1609 beginCommandBuffer(0);
1610
1611 pipelineImageBarrier(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, // VkPipelineStageFlags srcStageMask
1612 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, // VkPipelineStageFlags dstStageMask
1613 0, // VkAccessFlags srcAccessMask
1614 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask
1615 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
1616 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); // VkImageLayout newLayout;
1617
1618 preClearImage(m_imageMipLevels, m_params.imageExtent, m_params.imageLayerCount, m_commandBuffer);
1619
1620 pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, // VkPipelineStageFlags srcStageMask
1621 VK_PIPELINE_STAGE_TRANSFER_BIT, // VkPipelineStageFlags dstStageMask
1622 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask
1623 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask
1624 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
1625 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); // VkImageLayout newLayout;
1626
1627 m_vkd.cmdClearDepthStencilImage(*m_commandBuffer, *m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &m_params.clearValue[0].depthStencil, 1, &subresourceRange);
1628
1629 if (m_twoStep) {
1630 pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, // VkPipelineStageFlags srcStageMask
1631 VK_PIPELINE_STAGE_TRANSFER_BIT, // VkPipelineStageFlags dstStageMask
1632 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask
1633 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask
1634 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
1635 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); // VkImageLayout newLayout;
1636
1637 m_vkd.cmdClearDepthStencilImage(*m_commandBuffer, *m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &m_params.clearValue[0].depthStencil, 1, &steptwoRange);
1638 }
1639
1640 pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, // VkPipelineStageFlags srcStageMask
1641 VK_PIPELINE_STAGE_TRANSFER_BIT, // VkPipelineStageFlags dstStageMask
1642 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask
1643 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask
1644 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
1645 VK_IMAGE_LAYOUT_GENERAL, // VkImageLayout newLayout;
1646 aspectMask); // VkImageAspectFlags aspectMask;
1647
1648 endCommandBuffer();
1649 submitCommandBuffer();
1650
1651 return verifyResultImage("cmdClearDepthStencilImage passed");
1652 }
1653
1654 class ClearAttachmentTestInstance : public ImageClearingTestInstance
1655 {
1656 public:
1657 enum ClearType
1658 {
1659 FULL_CLEAR,
1660 PARTIAL_CLEAR,
1661 };
1662
ClearAttachmentTestInstance(Context & context,const TestParams & testParams,const ClearType clearType=FULL_CLEAR)1663 ClearAttachmentTestInstance (Context& context, const TestParams& testParams, const ClearType clearType = FULL_CLEAR)
1664 : ImageClearingTestInstance (context, testParams)
1665 , m_clearType (clearType)
1666 {
1667 if (!m_isAttachmentFormat)
1668 TCU_THROW(NotSupportedError, "Format not renderable");
1669 }
1670
iterate(void)1671 TestStatus iterate (void)
1672 {
1673 const bool isDepthStencil = isDepthStencilFormat(m_params.imageFormat);
1674 const VkAccessFlags accessMask = (isDepthStencil ? VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT : VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
1675 VkImageLayout attachmentLayout = (isDepthStencil ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
1676 VkImageAspectFlags aspectMask = m_imageAspectFlags;
1677
1678 if (m_params.separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_DEPTH)
1679 {
1680 attachmentLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL_KHR;
1681 aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
1682 }
1683 else if (m_params.separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_STENCIL)
1684 {
1685 attachmentLayout = VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL_KHR;
1686 aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
1687 }
1688
1689 const VkClearAttachment clearAttachment =
1690 {
1691 aspectMask, // VkImageAspectFlags aspectMask;
1692 0u, // deUint32 colorAttachment;
1693 m_params.clearValue[0] // VkClearValue clearValue;
1694 };
1695
1696 UVec4 clearCoords;
1697 std::vector<VkClearRect> clearRects;
1698
1699 if (m_clearType == FULL_CLEAR)
1700 {
1701 const VkClearRect rect =
1702 {
1703 {
1704 { 0, 0 }, // VkOffset2D offset;
1705 { m_params.imageExtent.width, m_params.imageExtent.height } // VkExtent2D extent;
1706 }, // VkRect2D rect;
1707 m_params.clearLayerRange.baseArrayLayer, // deUint32 baseArrayLayer;
1708 m_params.clearLayerRange.layerCount, // deUint32 layerCount;
1709 };
1710
1711 clearRects.push_back(rect);
1712 }
1713 else
1714 {
1715 const deUint32 clearX = m_params.imageExtent.width / 8u;
1716 const deUint32 clearY = m_params.imageExtent.height / 8u;
1717 const deUint32 clearWidth = m_params.imageExtent.width / 2u;
1718 const deUint32 clearHeight = m_params.imageExtent.height / 2u;
1719
1720 clearCoords = UVec4(clearX, clearY,
1721 clearX + clearWidth, clearY + clearHeight);
1722
1723 const VkClearRect rects[2] =
1724 {
1725 {
1726 {
1727 { 0, static_cast<deInt32>(clearY) }, // VkOffset2D offset;
1728 { m_params.imageExtent.width, clearHeight } // VkExtent2D extent;
1729 }, // VkRect2D rect;
1730 m_params.clearLayerRange.baseArrayLayer, // deUint32 baseArrayLayer;
1731 m_params.clearLayerRange.layerCount // deUint32 layerCount;
1732 },
1733 {
1734 {
1735 { static_cast<deInt32>(clearX), 0 }, // VkOffset2D offset;
1736 { clearWidth, m_params.imageExtent.height } // VkExtent2D extent;
1737 }, // VkRect2D rect;
1738 m_params.clearLayerRange.baseArrayLayer, // deUint32 baseArrayLayer;
1739 m_params.clearLayerRange.layerCount // deUint32 layerCount;
1740 }
1741 };
1742
1743 clearRects.push_back(rects[0]);
1744 clearRects.push_back(rects[1]);
1745 }
1746
1747 beginCommandBuffer(0);
1748
1749 pipelineImageBarrier(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, // VkPipelineStageFlags srcStageMask
1750 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, // VkPipelineStageFlags dstStageMask
1751 0, // VkAccessFlags srcAccessMask
1752 accessMask, // VkAccessFlags dstAccessMask
1753 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
1754 attachmentLayout, // VkImageLayout newLayout;
1755 aspectMask); // VkImageAspectFlags aspectMask;
1756
1757 beginRenderPass(VK_SUBPASS_CONTENTS_INLINE, m_params.initValue);
1758 m_vkd.cmdClearAttachments(*m_commandBuffer, 1, &clearAttachment, static_cast<deUint32>(clearRects.size()), &clearRects[0]);
1759 endRenderPass(m_vkd, *m_commandBuffer);
1760
1761 pipelineImageBarrier(VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, // VkPipelineStageFlags srcStageMask
1762 VK_PIPELINE_STAGE_TRANSFER_BIT, // VkPipelineStageFlags dstStageMask
1763 accessMask, // VkAccessFlags srcAccessMask
1764 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask
1765 attachmentLayout, // VkImageLayout oldLayout;
1766 VK_IMAGE_LAYOUT_GENERAL, // VkImageLayout newLayout;
1767 aspectMask); // VkImageAspectFlags aspectMask;
1768
1769 endCommandBuffer();
1770 submitCommandBuffer();
1771
1772 return verifyResultImage("cmdClearAttachments passed", clearCoords);
1773 }
1774
1775 private:
1776 const ClearType m_clearType;
1777 };
1778
1779 class PartialClearAttachmentTestInstance : public ClearAttachmentTestInstance
1780 {
1781 public:
PartialClearAttachmentTestInstance(Context & context,const TestParams & testParams)1782 PartialClearAttachmentTestInstance (Context& context, const TestParams& testParams) : ClearAttachmentTestInstance (context, testParams, PARTIAL_CLEAR) {}
1783 };
1784
makeClearColorValue(VkFormat format,float r,float g,float b,float a)1785 VkClearValue makeClearColorValue (VkFormat format, float r, float g, float b, float a)
1786 {
1787 const TextureFormat tcuFormat = mapVkFormat(format);
1788 VkClearValue clearValue;
1789
1790 if (getTextureChannelClass(tcuFormat.type) == TEXTURECHANNELCLASS_FLOATING_POINT
1791 || getTextureChannelClass(tcuFormat.type) == TEXTURECHANNELCLASS_SIGNED_FIXED_POINT
1792 || getTextureChannelClass(tcuFormat.type) == TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT)
1793 {
1794 clearValue.color.float32[0] = r;
1795 clearValue.color.float32[1] = g;
1796 clearValue.color.float32[2] = b;
1797 clearValue.color.float32[3] = a;
1798 }
1799 else if (getTextureChannelClass(tcuFormat.type) == TEXTURECHANNELCLASS_UNSIGNED_INTEGER)
1800 {
1801 UVec4 maxValues = getFormatMaxUintValue(tcuFormat);
1802
1803 clearValue.color.uint32[0] = (deUint32)((float)maxValues[0] * r);
1804 clearValue.color.uint32[1] = (deUint32)((float)maxValues[1] * g);
1805 clearValue.color.uint32[2] = (deUint32)((float)maxValues[2] * b);
1806 clearValue.color.uint32[3] = (deUint32)((float)maxValues[3] * a);
1807 }
1808 else if (getTextureChannelClass(tcuFormat.type) == TEXTURECHANNELCLASS_SIGNED_INTEGER)
1809 {
1810 IVec4 maxValues = getFormatMaxIntValue(tcuFormat);
1811
1812 clearValue.color.int32[0] = (deUint32)((float)maxValues[0] * r);
1813 clearValue.color.int32[1] = (deUint32)((float)maxValues[1] * g);
1814 clearValue.color.int32[2] = (deUint32)((float)maxValues[2] * b);
1815 clearValue.color.int32[3] = (deUint32)((float)maxValues[3] * a);
1816 }
1817 else
1818 DE_FATAL("Unknown channel class");
1819
1820 return clearValue;
1821 }
1822
getFormatCaseName(VkFormat format)1823 std::string getFormatCaseName (VkFormat format)
1824 {
1825 return de::toLower(de::toString(getFormatStr(format)).substr(10));
1826 }
1827
getImageTypeCaseName(VkImageType type)1828 const char* getImageTypeCaseName (VkImageType type)
1829 {
1830 const char* s_names[] =
1831 {
1832 "1d",
1833 "2d",
1834 "3d"
1835 };
1836 return de::getSizedArrayElement<VK_CORE_IMAGE_TYPE_LAST>(s_names, type);
1837 }
1838
getImageTilingCaseName(VkImageTiling tiling)1839 const char* getImageTilingCaseName (VkImageTiling tiling)
1840 {
1841 const char* s_names[] =
1842 {
1843 "optimal",
1844 "linear",
1845 };
1846 return de::getSizedArrayElement<VK_CORE_IMAGE_TILING_LAST>(s_names, tiling);
1847 }
1848
createImageClearingTestsCommon(TestContext & testCtx,tcu::TestCaseGroup * imageClearingTests,AllocationKind allocationKind)1849 TestCaseGroup* createImageClearingTestsCommon (TestContext& testCtx, tcu::TestCaseGroup* imageClearingTests, AllocationKind allocationKind)
1850 {
1851 de::MovePtr<TestCaseGroup> colorImageClearTests (new TestCaseGroup(testCtx, "clear_color_image", "Color Image Clear Tests"));
1852 de::MovePtr<TestCaseGroup> depthStencilImageClearTests (new TestCaseGroup(testCtx, "clear_depth_stencil_image", "Color Depth/Stencil Image Tests"));
1853 de::MovePtr<TestCaseGroup> colorAttachmentClearTests (new TestCaseGroup(testCtx, "clear_color_attachment", "Color Color Attachment Tests"));
1854 de::MovePtr<TestCaseGroup> depthStencilAttachmentClearTests (new TestCaseGroup(testCtx, "clear_depth_stencil_attachment", "Color Depth/Stencil Attachment Tests"));
1855 de::MovePtr<TestCaseGroup> partialColorAttachmentClearTests (new TestCaseGroup(testCtx, "partial_clear_color_attachment", "Clear Partial Color Attachment Tests"));
1856 de::MovePtr<TestCaseGroup> partialDepthStencilAttachmentClearTests (new TestCaseGroup(testCtx, "partial_clear_depth_stencil_attachment", "Clear Partial Depth/Stencil Attachment Tests"));
1857
1858 // Some formats are commented out due to the tcu::TextureFormat does not support them yet.
1859 const VkFormat colorImageFormatsToTest[] =
1860 {
1861 VK_FORMAT_R4G4_UNORM_PACK8,
1862 VK_FORMAT_R4G4B4A4_UNORM_PACK16,
1863 VK_FORMAT_B4G4R4A4_UNORM_PACK16,
1864 VK_FORMAT_R5G6B5_UNORM_PACK16,
1865 VK_FORMAT_B5G6R5_UNORM_PACK16,
1866 VK_FORMAT_R5G5B5A1_UNORM_PACK16,
1867 VK_FORMAT_B5G5R5A1_UNORM_PACK16,
1868 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
1869 VK_FORMAT_R8_UNORM,
1870 VK_FORMAT_R8_SNORM,
1871 VK_FORMAT_R8_USCALED,
1872 VK_FORMAT_R8_SSCALED,
1873 VK_FORMAT_R8_UINT,
1874 VK_FORMAT_R8_SINT,
1875 VK_FORMAT_R8_SRGB,
1876 VK_FORMAT_R8G8_UNORM,
1877 VK_FORMAT_R8G8_SNORM,
1878 VK_FORMAT_R8G8_USCALED,
1879 VK_FORMAT_R8G8_SSCALED,
1880 VK_FORMAT_R8G8_UINT,
1881 VK_FORMAT_R8G8_SINT,
1882 VK_FORMAT_R8G8_SRGB,
1883 VK_FORMAT_R8G8B8_UNORM,
1884 VK_FORMAT_R8G8B8_SNORM,
1885 VK_FORMAT_R8G8B8_USCALED,
1886 VK_FORMAT_R8G8B8_SSCALED,
1887 VK_FORMAT_R8G8B8_UINT,
1888 VK_FORMAT_R8G8B8_SINT,
1889 VK_FORMAT_R8G8B8_SRGB,
1890 VK_FORMAT_B8G8R8_UNORM,
1891 VK_FORMAT_B8G8R8_SNORM,
1892 VK_FORMAT_B8G8R8_USCALED,
1893 VK_FORMAT_B8G8R8_SSCALED,
1894 VK_FORMAT_B8G8R8_UINT,
1895 VK_FORMAT_B8G8R8_SINT,
1896 VK_FORMAT_B8G8R8_SRGB,
1897 VK_FORMAT_R8G8B8A8_UNORM,
1898 VK_FORMAT_R8G8B8A8_SNORM,
1899 VK_FORMAT_R8G8B8A8_USCALED,
1900 VK_FORMAT_R8G8B8A8_SSCALED,
1901 VK_FORMAT_R8G8B8A8_UINT,
1902 VK_FORMAT_R8G8B8A8_SINT,
1903 VK_FORMAT_R8G8B8A8_SRGB,
1904 VK_FORMAT_B8G8R8A8_UNORM,
1905 VK_FORMAT_B8G8R8A8_SNORM,
1906 VK_FORMAT_B8G8R8A8_USCALED,
1907 VK_FORMAT_B8G8R8A8_SSCALED,
1908 VK_FORMAT_B8G8R8A8_UINT,
1909 VK_FORMAT_B8G8R8A8_SINT,
1910 VK_FORMAT_B8G8R8A8_SRGB,
1911 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
1912 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
1913 VK_FORMAT_A8B8G8R8_USCALED_PACK32,
1914 VK_FORMAT_A8B8G8R8_SSCALED_PACK32,
1915 VK_FORMAT_A8B8G8R8_UINT_PACK32,
1916 VK_FORMAT_A8B8G8R8_SINT_PACK32,
1917 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
1918 VK_FORMAT_A2R10G10B10_UNORM_PACK32,
1919 VK_FORMAT_A2R10G10B10_SNORM_PACK32,
1920 VK_FORMAT_A2R10G10B10_USCALED_PACK32,
1921 VK_FORMAT_A2R10G10B10_SSCALED_PACK32,
1922 VK_FORMAT_A2R10G10B10_UINT_PACK32,
1923 VK_FORMAT_A2R10G10B10_SINT_PACK32,
1924 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
1925 VK_FORMAT_A2B10G10R10_SNORM_PACK32,
1926 VK_FORMAT_A2B10G10R10_USCALED_PACK32,
1927 VK_FORMAT_A2B10G10R10_SSCALED_PACK32,
1928 VK_FORMAT_A2B10G10R10_UINT_PACK32,
1929 VK_FORMAT_A2B10G10R10_SINT_PACK32,
1930 VK_FORMAT_R16_UNORM,
1931 VK_FORMAT_R16_SNORM,
1932 VK_FORMAT_R16_USCALED,
1933 VK_FORMAT_R16_SSCALED,
1934 VK_FORMAT_R16_UINT,
1935 VK_FORMAT_R16_SINT,
1936 VK_FORMAT_R16_SFLOAT,
1937 VK_FORMAT_R16G16_UNORM,
1938 VK_FORMAT_R16G16_SNORM,
1939 VK_FORMAT_R16G16_USCALED,
1940 VK_FORMAT_R16G16_SSCALED,
1941 VK_FORMAT_R16G16_UINT,
1942 VK_FORMAT_R16G16_SINT,
1943 VK_FORMAT_R16G16_SFLOAT,
1944 VK_FORMAT_R16G16B16_UNORM,
1945 VK_FORMAT_R16G16B16_SNORM,
1946 VK_FORMAT_R16G16B16_USCALED,
1947 VK_FORMAT_R16G16B16_SSCALED,
1948 VK_FORMAT_R16G16B16_UINT,
1949 VK_FORMAT_R16G16B16_SINT,
1950 VK_FORMAT_R16G16B16_SFLOAT,
1951 VK_FORMAT_R16G16B16A16_UNORM,
1952 VK_FORMAT_R16G16B16A16_SNORM,
1953 VK_FORMAT_R16G16B16A16_USCALED,
1954 VK_FORMAT_R16G16B16A16_SSCALED,
1955 VK_FORMAT_R16G16B16A16_UINT,
1956 VK_FORMAT_R16G16B16A16_SINT,
1957 VK_FORMAT_R16G16B16A16_SFLOAT,
1958 VK_FORMAT_R32_UINT,
1959 VK_FORMAT_R32_SINT,
1960 VK_FORMAT_R32_SFLOAT,
1961 VK_FORMAT_R32G32_UINT,
1962 VK_FORMAT_R32G32_SINT,
1963 VK_FORMAT_R32G32_SFLOAT,
1964 VK_FORMAT_R32G32B32_UINT,
1965 VK_FORMAT_R32G32B32_SINT,
1966 VK_FORMAT_R32G32B32_SFLOAT,
1967 VK_FORMAT_R32G32B32A32_UINT,
1968 VK_FORMAT_R32G32B32A32_SINT,
1969 VK_FORMAT_R32G32B32A32_SFLOAT,
1970 // VK_FORMAT_R64_UINT,
1971 // VK_FORMAT_R64_SINT,
1972 // VK_FORMAT_R64_SFLOAT,
1973 // VK_FORMAT_R64G64_UINT,
1974 // VK_FORMAT_R64G64_SINT,
1975 // VK_FORMAT_R64G64_SFLOAT,
1976 // VK_FORMAT_R64G64B64_UINT,
1977 // VK_FORMAT_R64G64B64_SINT,
1978 // VK_FORMAT_R64G64B64_SFLOAT,
1979 // VK_FORMAT_R64G64B64A64_UINT,
1980 // VK_FORMAT_R64G64B64A64_SINT,
1981 // VK_FORMAT_R64G64B64A64_SFLOAT,
1982 VK_FORMAT_B10G11R11_UFLOAT_PACK32,
1983 VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
1984 // VK_FORMAT_BC1_RGB_UNORM_BLOCK,
1985 // VK_FORMAT_BC1_RGB_SRGB_BLOCK,
1986 // VK_FORMAT_BC1_RGBA_UNORM_BLOCK,
1987 // VK_FORMAT_BC1_RGBA_SRGB_BLOCK,
1988 // VK_FORMAT_BC2_UNORM_BLOCK,
1989 // VK_FORMAT_BC2_SRGB_BLOCK,
1990 // VK_FORMAT_BC3_UNORM_BLOCK,
1991 // VK_FORMAT_BC3_SRGB_BLOCK,
1992 // VK_FORMAT_BC4_UNORM_BLOCK,
1993 // VK_FORMAT_BC4_SNORM_BLOCK,
1994 // VK_FORMAT_BC5_UNORM_BLOCK,
1995 // VK_FORMAT_BC5_SNORM_BLOCK,
1996 // VK_FORMAT_BC6H_UFLOAT_BLOCK,
1997 // VK_FORMAT_BC6H_SFLOAT_BLOCK,
1998 // VK_FORMAT_BC7_UNORM_BLOCK,
1999 // VK_FORMAT_BC7_SRGB_BLOCK,
2000 // VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK,
2001 // VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK,
2002 // VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK,
2003 // VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK,
2004 // VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK,
2005 // VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK,
2006 // VK_FORMAT_EAC_R11_UNORM_BLOCK,
2007 // VK_FORMAT_EAC_R11_SNORM_BLOCK,
2008 // VK_FORMAT_EAC_R11G11_UNORM_BLOCK,
2009 // VK_FORMAT_EAC_R11G11_SNORM_BLOCK,
2010 // VK_FORMAT_ASTC_4x4_UNORM_BLOCK,
2011 // VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
2012 // VK_FORMAT_ASTC_5x4_UNORM_BLOCK,
2013 // VK_FORMAT_ASTC_5x4_SRGB_BLOCK,
2014 // VK_FORMAT_ASTC_5x5_UNORM_BLOCK,
2015 // VK_FORMAT_ASTC_5x5_SRGB_BLOCK,
2016 // VK_FORMAT_ASTC_6x5_UNORM_BLOCK,
2017 // VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
2018 // VK_FORMAT_ASTC_6x6_UNORM_BLOCK,
2019 // VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
2020 // VK_FORMAT_ASTC_8x5_UNORM_BLOCK,
2021 // VK_FORMAT_ASTC_8x5_SRGB_BLOCK,
2022 // VK_FORMAT_ASTC_8x6_UNORM_BLOCK,
2023 // VK_FORMAT_ASTC_8x6_SRGB_BLOCK,
2024 // VK_FORMAT_ASTC_8x8_UNORM_BLOCK,
2025 // VK_FORMAT_ASTC_8x8_SRGB_BLOCK,
2026 // VK_FORMAT_ASTC_10x5_UNORM_BLOCK,
2027 // VK_FORMAT_ASTC_10x5_SRGB_BLOCK,
2028 // VK_FORMAT_ASTC_10x6_UNORM_BLOCK,
2029 // VK_FORMAT_ASTC_10x6_SRGB_BLOCK,
2030 // VK_FORMAT_ASTC_10x8_UNORM_BLOCK,
2031 // VK_FORMAT_ASTC_10x8_SRGB_BLOCK,
2032 // VK_FORMAT_ASTC_10x10_UNORM_BLOCK,
2033 // VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
2034 // VK_FORMAT_ASTC_12x10_UNORM_BLOCK,
2035 // VK_FORMAT_ASTC_12x10_SRGB_BLOCK,
2036 // VK_FORMAT_ASTC_12x12_UNORM_BLOCK,
2037 // VK_FORMAT_ASTC_12x12_SRGB_BLOCK,
2038
2039 VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT,
2040 VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT,
2041 };
2042 const size_t numOfColorImageFormatsToTest = DE_LENGTH_OF_ARRAY(colorImageFormatsToTest);
2043
2044 const VkFormat depthStencilImageFormatsToTest[] =
2045 {
2046 VK_FORMAT_D16_UNORM,
2047 VK_FORMAT_X8_D24_UNORM_PACK32,
2048 VK_FORMAT_D32_SFLOAT,
2049 VK_FORMAT_S8_UINT,
2050 VK_FORMAT_D16_UNORM_S8_UINT,
2051 VK_FORMAT_D24_UNORM_S8_UINT,
2052 VK_FORMAT_D32_SFLOAT_S8_UINT
2053 };
2054 const size_t numOfDepthStencilImageFormatsToTest = DE_LENGTH_OF_ARRAY(depthStencilImageFormatsToTest);
2055
2056 struct ClearTestColorParams
2057 {
2058 bool matchTextureChannelClass;
2059 TextureChannelClass textureChannelClass;
2060 const char* testNameSuffix;
2061 float clearColors[2][4];
2062 bool useSeparateExpectedColors;
2063 float expectedColors[2][4];
2064 };
2065 const ClearTestColorParams clearColorsToTest[] =
2066 {
2067 {
2068 false, // matchTextureChannelClass
2069 TEXTURECHANNELCLASS_LAST, // textureChannelClass
2070 "", // testNameSuffix
2071 {
2072 { 0.1f, 0.5f, 0.3f, 0.9f }, // clearColors[0]
2073 { 0.3f, 0.6f, 0.2f, 0.7f }, // clearColors[1]
2074 },
2075 false, // useSeparateExpectedColors
2076 { } // expectedColors
2077 },
2078 {
2079 true, // matchTextureChannelClass
2080 TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT, // textureChannelClass
2081 "_clamp_input", // testNameSuffix
2082 {
2083 { -0.1f, -1e6f, -0.3f, -1.5f }, // clearColors[0]
2084 { -1.5f, -0.6f, -1e6f, -0.7f }, // clearColors[1]
2085 },
2086 true, // useSeparateExpectedColors
2087 {
2088 { 0.0f, 0.0f, 0.0f, 0.0f }, // expectedColors[0]
2089 { 0.0f, 0.0f, 0.0f, 0.0f }, // expectedColors[1]
2090 }
2091 }
2092 };
2093 const size_t numOfClearColorsToTest = DE_LENGTH_OF_ARRAY(clearColorsToTest);
2094
2095 struct ImageLayerParams
2096 {
2097 deUint32 imageLayerCount;
2098 LayerRange imageViewRange;
2099 LayerRange clearLayerRange;
2100 bool twoStep;
2101 const char* testName;
2102 bool isCube;
2103 };
2104 const ImageLayerParams imageLayerParamsToTest[] =
2105 {
2106 {
2107 1u, // imageLayerCount
2108 {0u, 1u}, // imageViewRange
2109 {0u, 1u}, // clearLayerRange
2110 false, // twoStep
2111 "single_layer", // testName
2112 false // isCube
2113 },
2114 {
2115 16u, // imageLayerCount
2116 {3u, 12u}, // imageViewRange
2117 {2u, 5u}, // clearLayerRange
2118 false, // twoStep
2119 "multiple_layers", // testName
2120 false // isCube
2121 },
2122 {
2123 15u, // imageLayerCount
2124 { 3u, 6u }, // imageViewRange
2125 { 2u, 1u }, // clearLayerRange
2126 false, // twoStep
2127 "cube_layers", // testName
2128 true // isCube
2129 },
2130 {
2131 16u, // imageLayerCount
2132 { 3u, 12u }, // imageViewRange
2133 { 8u, VK_REMAINING_ARRAY_LAYERS }, // clearLayerRange
2134 false, // twoStep
2135 "remaining_array_layers", // testName
2136 false // isCube
2137 },
2138 {
2139 16u, // imageLayerCount
2140 { 3u, 12u }, // imageViewRange
2141 { 8u, VK_REMAINING_ARRAY_LAYERS }, // clearLayerRange
2142 true, // twoStep
2143 "remaining_array_layers_twostep", // testName
2144 false // isCube
2145 }
2146 };
2147
2148 // Include test cases with VK_REMAINING_ARRAY_LAYERS when using vkCmdClearColorImage
2149 const size_t numOfImageLayerParamsToTest = DE_LENGTH_OF_ARRAY(imageLayerParamsToTest);
2150
2151 // Exclude test cases with VK_REMAINING_ARRAY_LAYERS when using vkCmdClearAttachments
2152 const size_t numOfAttachmentLayerParamsToTest = numOfImageLayerParamsToTest - 2;
2153
2154 const VkExtent3D imageDimensions[] =
2155 {
2156 { 256, 1, 1},
2157 { 256, 256, 1},
2158 { 256, 256, 16},
2159 { 200, 1, 1},
2160 { 200, 180, 1},
2161 { 200, 180, 16},
2162 { 71, 1, 1},
2163 { 1, 33, 1},
2164 { 55, 21, 11},
2165 { 64, 11, 1},
2166 { 33, 128, 1},
2167 { 32, 29, 3}
2168 };
2169
2170 // Clear color image
2171 {
2172 const VkImageType imageTypesToTest[] =
2173 {
2174 VK_IMAGE_TYPE_1D,
2175 VK_IMAGE_TYPE_2D,
2176 VK_IMAGE_TYPE_3D
2177 };
2178 const size_t numOfImageTypesToTest = DE_LENGTH_OF_ARRAY(imageTypesToTest);
2179
2180 const VkImageTiling imageTilingsToTest[] =
2181 {
2182 VK_IMAGE_TILING_OPTIMAL,
2183 VK_IMAGE_TILING_LINEAR,
2184 };
2185 const size_t numOfImageTilingsToTest = DE_LENGTH_OF_ARRAY(imageTilingsToTest);
2186
2187 for (size_t imageTypeIndex = 0; imageTypeIndex < numOfImageTypesToTest; ++imageTypeIndex)
2188 {
2189 de::MovePtr<TestCaseGroup> imageTypeGroup(new TestCaseGroup(testCtx, getImageTypeCaseName(imageTypesToTest[imageTypeIndex]), ""));
2190
2191 for (size_t imageTilingIndex = 0; imageTilingIndex < numOfImageTilingsToTest; ++imageTilingIndex)
2192 {
2193 de::MovePtr<TestCaseGroup> imageTilingGroup(new TestCaseGroup(testCtx, getImageTilingCaseName(imageTilingsToTest[imageTilingIndex]), ""));
2194
2195 for (size_t imageLayerParamsIndex = 0; imageLayerParamsIndex < numOfImageLayerParamsToTest; ++imageLayerParamsIndex)
2196 {
2197 // 3D ARRAY images are not supported
2198 if (imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount > 1u && imageTypesToTest[imageTypeIndex] == VK_IMAGE_TYPE_3D)
2199 continue;
2200
2201 // CUBE images are not tested in clear image tests (they are tested in clear attachment tests)
2202 if (imageLayerParamsToTest[imageLayerParamsIndex].isCube)
2203 continue;
2204
2205 de::MovePtr<TestCaseGroup> imageLayersGroup(new TestCaseGroup(testCtx, imageLayerParamsToTest[imageLayerParamsIndex].testName, ""));
2206
2207 for (size_t imageDimensionsIndex = 0; imageDimensionsIndex < DE_LENGTH_OF_ARRAY(imageDimensions); ++imageDimensionsIndex)
2208 {
2209 const VkExtent3D dimensions = imageDimensions[imageDimensionsIndex];
2210 const std::string dimensionsString = extentToString(dimensions, imageTypesToTest[imageTypeIndex]);
2211
2212 if (imageTypesToTest[imageTypeIndex] == VK_IMAGE_TYPE_1D && dimensions.height > 1)
2213 continue;
2214 if (imageTypesToTest[imageTypeIndex] == VK_IMAGE_TYPE_2D && (dimensions.depth > 1 || dimensions.height == 1))
2215 continue;
2216 if (imageTypesToTest[imageTypeIndex] == VK_IMAGE_TYPE_3D && dimensions.depth == 1)
2217 continue;
2218
2219 for (size_t imageFormatIndex = 0; imageFormatIndex < numOfColorImageFormatsToTest; ++imageFormatIndex)
2220 {
2221 const VkFormat format = colorImageFormatsToTest[imageFormatIndex];
2222 const TextureFormat tcuFormat = mapVkFormat(format);
2223 const TextureChannelClass channelClass = getTextureChannelClass(tcuFormat.type);
2224 for (size_t clearColorIndex = 0; clearColorIndex < numOfClearColorsToTest; ++clearColorIndex)
2225 {
2226 const ClearTestColorParams& colorParams = clearColorsToTest[clearColorIndex];
2227
2228 if (colorParams.matchTextureChannelClass && channelClass != colorParams.textureChannelClass)
2229 continue;
2230
2231 VkClearValue clearColors[2] =
2232 {
2233 makeClearColorValue(format, colorParams.clearColors[0][0], colorParams.clearColors[0][1], colorParams.clearColors[0][2], colorParams.clearColors[0][3]),
2234 makeClearColorValue(format, colorParams.clearColors[1][0], colorParams.clearColors[1][1], colorParams.clearColors[1][2], colorParams.clearColors[1][3]),
2235 };
2236 VkClearValue expectedColors[2];
2237 if (clearColorsToTest[clearColorIndex].useSeparateExpectedColors)
2238 {
2239 expectedColors[0] = makeClearColorValue(format, colorParams.expectedColors[0][0], colorParams.expectedColors[0][1], colorParams.expectedColors[0][2], colorParams.expectedColors[0][3]);
2240 expectedColors[1] = makeClearColorValue(format, colorParams.expectedColors[1][0], colorParams.expectedColors[1][1], colorParams.expectedColors[1][2], colorParams.expectedColors[1][3]);
2241 }
2242 else
2243 {
2244 expectedColors[0] = clearColors[0];
2245 expectedColors[1] = clearColors[1];
2246 }
2247
2248 std::string testCaseName = getFormatCaseName(format) + dimensionsString + colorParams.testNameSuffix;
2249 TestParams testParams =
2250 {
2251 false, // bool useSingleMipLevel;
2252 imageTypesToTest[imageTypeIndex], // VkImageType imageType;
2253 format, // VkFormat imageFormat;
2254 imageTilingsToTest[imageTilingIndex], // VkImageTiling imageTiling;
2255 dimensions, // VkExtent3D imageExtent;
2256 imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount, // deUint32 imageLayerCount;
2257 {
2258 0u,
2259 imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount
2260 }, // LayerRange imageViewLayerRange;
2261 makeClearColorValue(format, 0.0f, 0.0f, 0.0f, 0.0f), // VkClearValue initValue;
2262 {
2263 clearColors[0], // VkClearValue clearValue[0];
2264 clearColors[1], // VkClearValue clearValue[1];
2265 },
2266 clearColorsToTest[clearColorIndex].useSeparateExpectedColors, // bool useSeparateExpectedClearValue;
2267 {
2268 expectedColors[0], // VkClearValue expectedClearValue[0];
2269 expectedColors[1], // VkClearValue expectedClearValue[1];
2270 },
2271 imageLayerParamsToTest[imageLayerParamsIndex].clearLayerRange, // LayerRange clearLayerRange;
2272 allocationKind, // AllocationKind allocationKind;
2273 false, // bool isCube;
2274 SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_NONE, // SeparateDepthStencilLayoutMode separateDepthStencilLayoutMode;
2275 false, // bool isColorMultipleSubresourceRangeTest;
2276 };
2277
2278 if (!imageLayerParamsToTest[imageLayerParamsIndex].twoStep)
2279 {
2280 imageLayersGroup->addChild(new InstanceFactory1<ClearColorImageTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName, "Clear Color Image", testParams));
2281
2282 // Removing linear images as the miplevels may be 1
2283 if (imageTilingsToTest[imageTilingIndex] == VK_IMAGE_TILING_OPTIMAL)
2284 {
2285 testParams.isColorMultipleSubresourceRangeTest = true;
2286 testCaseName += "_multiple_subresourcerange";
2287 imageLayersGroup->addChild(new InstanceFactory1<ClearColorImageMultipleSubresourceRangeTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName, "Clear Color Image with two ranges", testParams));
2288 }
2289 }
2290 else
2291 {
2292 imageLayersGroup->addChild(new InstanceFactory1<TwoStepClearColorImageTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName, "Clear Color Image", testParams));
2293 }
2294 }
2295 }
2296 }
2297 imageTilingGroup->addChild(imageLayersGroup.release());
2298 }
2299 imageTypeGroup->addChild(imageTilingGroup.release());
2300 }
2301 colorImageClearTests->addChild(imageTypeGroup.release());
2302 }
2303 imageClearingTests->addChild(colorImageClearTests.release());
2304 }
2305
2306 // Clear depth/stencil image
2307 {
2308 for (size_t imageLayerParamsIndex = 0; imageLayerParamsIndex < numOfImageLayerParamsToTest; ++imageLayerParamsIndex)
2309 {
2310 // CUBE images are not tested in clear image tests (they are tested in clear attachment tests)
2311 if (imageLayerParamsToTest[imageLayerParamsIndex].isCube)
2312 continue;
2313
2314 de::MovePtr<TestCaseGroup> imageLayersGroup(new TestCaseGroup(testCtx, imageLayerParamsToTest[imageLayerParamsIndex].testName, ""));
2315
2316 for (size_t imageDimensionsIndex = 0; imageDimensionsIndex < DE_LENGTH_OF_ARRAY(imageDimensions); ++imageDimensionsIndex)
2317 {
2318 const VkExtent3D dimensions = imageDimensions[imageDimensionsIndex];
2319 const std::string dimensionsString = extentToString(dimensions, VK_IMAGE_TYPE_2D);
2320
2321 if (dimensions.height == 1 || dimensions.depth > 1)
2322 continue;
2323
2324 for (size_t imageFormatIndex = 0; imageFormatIndex < numOfDepthStencilImageFormatsToTest; ++imageFormatIndex)
2325 {
2326 const VkFormat format = depthStencilImageFormatsToTest[imageFormatIndex];
2327 const bool hasDepth = tcu::hasDepthComponent(mapVkFormat(format).order);
2328 const bool hasStencil = tcu::hasStencilComponent(mapVkFormat(format).order);
2329 const int separateLayoutsLoopCount = (hasDepth && hasStencil) ? 3 : 1;
2330
2331 for (int separateDepthStencilLayoutMode = 0; separateDepthStencilLayoutMode < separateLayoutsLoopCount; ++separateDepthStencilLayoutMode)
2332 {
2333 const std::string testCaseName = getFormatCaseName(format) +
2334 ((separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_DEPTH) ? "_separate_layouts_depth" :
2335 (separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_STENCIL) ? "_separate_layouts_stencil" :
2336 "")
2337 + dimensionsString;
2338 TestParams testParams =
2339 {
2340 true, // bool useSingleMipLevel;
2341 VK_IMAGE_TYPE_2D, // VkImageType imageType;
2342 format, // VkFormat format;
2343 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
2344 dimensions, // VkExtent3D extent;
2345 imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount, // deUint32 imageLayerCount;
2346 {
2347 0u,
2348 imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount
2349 }, // LayerRange imageViewLayerRange;
2350 makeClearValueDepthStencil(0.0f, 0u), // VkClearValue initValue
2351 {
2352 makeClearValueDepthStencil(0.1f, 0x06), // VkClearValue clearValue[0];
2353 makeClearValueDepthStencil(0.3f, 0x04), // VkClearValue clearValue[1];
2354 },
2355 false, // bool useSeparateExpectedClearValue;
2356 { }, // VkClearValue[2] expectedClearValue;
2357 imageLayerParamsToTest[imageLayerParamsIndex].clearLayerRange, // LayerRange clearLayerRange;
2358 allocationKind, // AllocationKind allocationKind;
2359 false, // bool isCube;
2360 SeparateDepthStencilLayoutMode(separateDepthStencilLayoutMode), // SeparateDepthStencilLayoutMode separateDepthStencilLayoutMode;
2361 false, // bool isColorMultipleSubresourceRangeTest;
2362 };
2363
2364 if (!imageLayerParamsToTest[imageLayerParamsIndex].twoStep)
2365 {
2366 imageLayersGroup->addChild(new InstanceFactory1<ClearDepthStencilImageTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName, "Clear Depth/Stencil Image", testParams));
2367
2368 if (separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_NONE && hasDepth && hasStencil)
2369 {
2370 const std::string testCaseNameRanges = getFormatCaseName(format) + dimensionsString + "_multiple_subresourcerange";
2371 imageLayersGroup->addChild(new InstanceFactory1<ClearDepthStencilImageMultipleSubresourceRangeTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseNameRanges, "Clear Depth/Stencil Image with ranges", testParams));
2372 }
2373 }
2374 else
2375 {
2376 imageLayersGroup->addChild(new InstanceFactory1<TwoStepClearDepthStencilImageTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName, "Clear Depth/Stencil Image", testParams));
2377 }
2378 }
2379 }
2380 }
2381 depthStencilImageClearTests->addChild(imageLayersGroup.release());
2382 }
2383 imageClearingTests->addChild(depthStencilImageClearTests.release());
2384 }
2385
2386 // Clear color attachment
2387 {
2388 for (size_t imageLayerParamsIndex = 0; imageLayerParamsIndex < numOfAttachmentLayerParamsToTest; ++imageLayerParamsIndex)
2389 {
2390 if (!imageLayerParamsToTest[imageLayerParamsIndex].twoStep)
2391 {
2392 de::MovePtr<TestCaseGroup> colorAttachmentClearLayersGroup(new TestCaseGroup(testCtx, imageLayerParamsToTest[imageLayerParamsIndex].testName, ""));
2393 de::MovePtr<TestCaseGroup> partialColorAttachmentClearLayersGroup(new TestCaseGroup(testCtx, imageLayerParamsToTest[imageLayerParamsIndex].testName, ""));
2394
2395 for (size_t imageDimensionsIndex = 0; imageDimensionsIndex < DE_LENGTH_OF_ARRAY(imageDimensions); ++imageDimensionsIndex)
2396 {
2397 const VkExtent3D dimensions = imageDimensions[imageDimensionsIndex];
2398 const std::string dimensionsString = extentToString(dimensions, VK_IMAGE_TYPE_2D);
2399
2400 if (dimensions.height == 1 || dimensions.depth > 1)
2401 continue;
2402
2403 if (imageLayerParamsToTest[imageLayerParamsIndex].isCube && dimensions.width != dimensions.height)
2404 continue;
2405
2406 for (size_t imageFormatIndex = 0; imageFormatIndex < numOfColorImageFormatsToTest; ++imageFormatIndex)
2407 {
2408 const VkFormat format = colorImageFormatsToTest[imageFormatIndex];
2409 const TextureFormat tcuFormat = mapVkFormat(format);
2410 const TextureChannelClass channelClass = getTextureChannelClass(tcuFormat.type);
2411 for (size_t clearColorIndex = 0; clearColorIndex < numOfClearColorsToTest; ++clearColorIndex)
2412 {
2413 const ClearTestColorParams& colorParams = clearColorsToTest[clearColorIndex];
2414
2415 if (colorParams.matchTextureChannelClass && channelClass != colorParams.textureChannelClass)
2416 continue;
2417
2418 VkClearValue clearColors[2] =
2419 {
2420 makeClearColorValue(format, colorParams.clearColors[0][0], colorParams.clearColors[0][1], colorParams.clearColors[0][2], colorParams.clearColors[0][3]),
2421 makeClearColorValue(format, colorParams.clearColors[1][0], colorParams.clearColors[1][1], colorParams.clearColors[1][2], colorParams.clearColors[1][3]),
2422 };
2423 VkClearValue expectedColors[2];
2424 if (clearColorsToTest[clearColorIndex].useSeparateExpectedColors)
2425 {
2426 expectedColors[0] = makeClearColorValue(format, colorParams.expectedColors[0][0], colorParams.expectedColors[0][1], colorParams.expectedColors[0][2], colorParams.expectedColors[0][3]);
2427 expectedColors[1] = makeClearColorValue(format, colorParams.expectedColors[1][0], colorParams.expectedColors[1][1], colorParams.expectedColors[1][2], colorParams.expectedColors[1][3]);
2428 }
2429 else
2430 {
2431 expectedColors[0] = clearColors[0];
2432 expectedColors[1] = clearColors[1];
2433 }
2434
2435 const std::string testCaseName = getFormatCaseName(format) + dimensionsString + colorParams.testNameSuffix;
2436 const TestParams testParams =
2437 {
2438 true, // bool useSingleMipLevel;
2439 VK_IMAGE_TYPE_2D, // VkImageType imageType;
2440 format, // VkFormat format;
2441 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
2442 dimensions, // VkExtent3D extent;
2443 imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount, // deUint32 imageLayerCount;
2444 imageLayerParamsToTest[imageLayerParamsIndex].imageViewRange, // LayerRange imageViewLayerRange;
2445 makeClearColorValue(format, 0.2f, 0.1f, 0.7f, 0.8f), // VkClearValue initValue
2446 {
2447 clearColors[0], // VkClearValue clearValue[0];
2448 clearColors[1] // VkClearValue clearValue[1];
2449 },
2450 colorParams.useSeparateExpectedColors, // bool useSeparateExpectedClearValue;
2451 {
2452 expectedColors[0], // VkClearValue expectedClearValue[0];
2453 expectedColors[1] // VkClearValue expectedClearValue[1];
2454 },
2455 imageLayerParamsToTest[imageLayerParamsIndex].clearLayerRange, // LayerRange clearLayerRange;
2456 allocationKind, // AllocationKind allocationKind;
2457 imageLayerParamsToTest[imageLayerParamsIndex].isCube, // bool isCube;
2458 SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_NONE, // SeparateDepthStencilLayoutMode separateDepthStencilLayoutMode;
2459 false, // bool isColorMultipleSubresourceRangeTest;
2460 };
2461 colorAttachmentClearLayersGroup->addChild(new InstanceFactory1<ClearAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName, "Clear Color Attachment", testParams));
2462 if (dimensions.width > 1)
2463 partialColorAttachmentClearLayersGroup->addChild(new InstanceFactory1<PartialClearAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName, "Partial Clear Color Attachment", testParams));
2464 }
2465 }
2466 }
2467 colorAttachmentClearTests->addChild(colorAttachmentClearLayersGroup.release());
2468 partialColorAttachmentClearTests->addChild(partialColorAttachmentClearLayersGroup.release());
2469 }
2470 }
2471 imageClearingTests->addChild(colorAttachmentClearTests.release());
2472 imageClearingTests->addChild(partialColorAttachmentClearTests.release());
2473 }
2474
2475 // Clear depth/stencil attachment
2476 {
2477 for (size_t imageLayerParamsIndex = 0; imageLayerParamsIndex < numOfAttachmentLayerParamsToTest; ++imageLayerParamsIndex)
2478 {
2479 if (!imageLayerParamsToTest[imageLayerParamsIndex].twoStep)
2480 {
2481 de::MovePtr<TestCaseGroup> depthStencilLayersGroup(new TestCaseGroup(testCtx, imageLayerParamsToTest[imageLayerParamsIndex].testName, ""));
2482 de::MovePtr<TestCaseGroup> partialDepthStencilLayersGroup(new TestCaseGroup(testCtx, imageLayerParamsToTest[imageLayerParamsIndex].testName, ""));
2483
2484 for (size_t imageDimensionsIndex = 0; imageDimensionsIndex < DE_LENGTH_OF_ARRAY(imageDimensions); ++imageDimensionsIndex)
2485 {
2486 const VkExtent3D dimensions = imageDimensions[imageDimensionsIndex];
2487 const std::string dimensionsString = extentToString(dimensions, VK_IMAGE_TYPE_2D);
2488
2489 if (dimensions.height == 1 || dimensions.depth > 1)
2490 continue;
2491
2492 if (imageLayerParamsToTest[imageLayerParamsIndex].isCube && dimensions.width != dimensions.height)
2493 continue;
2494
2495 for (size_t imageFormatIndex = 0; imageFormatIndex < numOfDepthStencilImageFormatsToTest; ++imageFormatIndex)
2496 {
2497 const VkFormat format = depthStencilImageFormatsToTest[imageFormatIndex];
2498 const bool hasDepth = tcu::hasDepthComponent(mapVkFormat(format).order);
2499 const bool hasStencil = tcu::hasStencilComponent(mapVkFormat(format).order);
2500 const int separateLayoutsLoopCount = (hasDepth && hasStencil) ? 3 : 1;
2501
2502 for (int separateDepthStencilLayoutMode = 0; separateDepthStencilLayoutMode < separateLayoutsLoopCount; ++separateDepthStencilLayoutMode)
2503 {
2504 const std::string testCaseName = getFormatCaseName(format) +
2505 ((separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_DEPTH) ? "_separate_layouts_depth" :
2506 (separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_STENCIL) ? "_separate_layouts_stencil" :
2507 "")
2508 + dimensionsString;
2509
2510 const TestParams testParams =
2511 {
2512 true, // bool useSingleMipLevel;
2513 VK_IMAGE_TYPE_2D, // VkImageType imageType;
2514 format, // VkFormat format;
2515 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
2516 dimensions, // VkExtent3D extent;
2517 imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount, // deUint32 imageLayerCount;
2518 imageLayerParamsToTest[imageLayerParamsIndex].imageViewRange, // LayerRange imageViewLayerRange;
2519 makeClearValueDepthStencil(0.0f, 0u), // VkClearValue initValue
2520 {
2521 makeClearValueDepthStencil(0.1f, 0x06), // VkClearValue clearValue[0];
2522 makeClearValueDepthStencil(0.3f, 0x04), // VkClearValue clearValue[1];
2523 },
2524 false, // bool useSeparateExpectedClearValue;
2525 { }, // VkClearValue[2] expectedClearValue;
2526 imageLayerParamsToTest[imageLayerParamsIndex].clearLayerRange, // LayerRange clearLayerRange;
2527 allocationKind, // AllocationKind allocationKind;
2528 imageLayerParamsToTest[imageLayerParamsIndex].isCube, // bool isCube;
2529 SeparateDepthStencilLayoutMode(separateDepthStencilLayoutMode), // SeparateDepthStencilLayoutMode separateDepthStencilLayoutMode;
2530 false, // bool isColorMultipleSubresourceRangeTest;
2531 };
2532 depthStencilLayersGroup->addChild(new InstanceFactory1<ClearAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName, "Clear Depth/Stencil Attachment", testParams));
2533 if (dimensions.width > 1)
2534 partialDepthStencilLayersGroup->addChild(new InstanceFactory1<PartialClearAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName, "Partial Clear Depth/Stencil Attachment", testParams));
2535 }
2536 }
2537 }
2538 depthStencilAttachmentClearTests->addChild(depthStencilLayersGroup.release());
2539 partialDepthStencilAttachmentClearTests->addChild(partialDepthStencilLayersGroup.release());
2540 }
2541 }
2542 imageClearingTests->addChild(depthStencilAttachmentClearTests.release());
2543 imageClearingTests->addChild(partialDepthStencilAttachmentClearTests.release());
2544 }
2545
2546 return imageClearingTests;
2547 }
2548
createCoreImageClearingTests(tcu::TestCaseGroup * group)2549 void createCoreImageClearingTests (tcu::TestCaseGroup* group)
2550 {
2551 createImageClearingTestsCommon(group->getTestContext(), group, ALLOCATION_KIND_SUBALLOCATED);
2552 }
2553
createDedicatedAllocationImageClearingTests(tcu::TestCaseGroup * group)2554 void createDedicatedAllocationImageClearingTests (tcu::TestCaseGroup* group)
2555 {
2556 createImageClearingTestsCommon(group->getTestContext(), group, ALLOCATION_KIND_DEDICATED);
2557 }
2558
2559 } // anonymous
2560
createImageClearingTests(TestContext & testCtx)2561 TestCaseGroup* createImageClearingTests (TestContext& testCtx)
2562 {
2563 de::MovePtr<TestCaseGroup> imageClearingTests (new TestCaseGroup(testCtx, "image_clearing", "Image Clearing Tests"));
2564
2565 imageClearingTests->addChild(createTestGroup(testCtx, "core", "Core Image Clearing Tests", createCoreImageClearingTests));
2566 imageClearingTests->addChild(createTestGroup(testCtx, "dedicated_allocation", "Image Clearing Tests For Dedicated Memory Allocation", createDedicatedAllocationImageClearingTests));
2567
2568 return imageClearingTests.release();
2569 }
2570
2571 } // api
2572 } // vkt
2573