1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2016 The Khronos Group Inc.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *//*!
20 * \file vktSparseResourcesImageSparseBinding.cpp
21 * \brief Sparse fully resident images with mipmaps tests
22 *//*--------------------------------------------------------------------*/
23
24 #include "vktSparseResourcesBufferSparseBinding.hpp"
25 #include "vktSparseResourcesTestsUtil.hpp"
26 #include "vktSparseResourcesBase.hpp"
27 #include "vktTestCaseUtil.hpp"
28
29 #include "vkDefs.hpp"
30 #include "vkRef.hpp"
31 #include "vkRefUtil.hpp"
32 #include "vkPlatform.hpp"
33 #include "vkPrograms.hpp"
34 #include "vkMemUtil.hpp"
35 #include "vkBarrierUtil.hpp"
36 #include "vkBuilderUtil.hpp"
37 #include "vkImageUtil.hpp"
38 #include "vkQueryUtil.hpp"
39 #include "vkTypeUtil.hpp"
40 #include "vkCmdUtil.hpp"
41
42 #include "deUniquePtr.hpp"
43 #include "deStringUtil.hpp"
44 #include "tcuTextureUtil.hpp"
45
46 #include <string>
47 #include <vector>
48
49 using namespace vk;
50
51 namespace vkt
52 {
53 namespace sparse
54 {
55 namespace
56 {
57
58 class ImageSparseBindingCase : public TestCase
59 {
60 public:
61 ImageSparseBindingCase (tcu::TestContext& testCtx,
62 const std::string& name,
63 const std::string& description,
64 const ImageType imageType,
65 const tcu::UVec3& imageSize,
66 const VkFormat format,
67 const bool useDeviceGroups = false);
68
69 TestInstance* createInstance (Context& context) const;
70 virtual void checkSupport (Context& context) const;
71
72 private:
73 const bool m_useDeviceGroups;
74 const ImageType m_imageType;
75 const tcu::UVec3 m_imageSize;
76 const VkFormat m_format;
77 };
78
ImageSparseBindingCase(tcu::TestContext & testCtx,const std::string & name,const std::string & description,const ImageType imageType,const tcu::UVec3 & imageSize,const VkFormat format,const bool useDeviceGroups)79 ImageSparseBindingCase::ImageSparseBindingCase (tcu::TestContext& testCtx,
80 const std::string& name,
81 const std::string& description,
82 const ImageType imageType,
83 const tcu::UVec3& imageSize,
84 const VkFormat format,
85 const bool useDeviceGroups)
86
87 : TestCase (testCtx, name, description)
88 , m_useDeviceGroups (useDeviceGroups)
89 , m_imageType (imageType)
90 , m_imageSize (imageSize)
91 , m_format (format)
92 {
93 }
94
checkSupport(Context & context) const95 void ImageSparseBindingCase::checkSupport (Context& context) const
96 {
97 context.requireDeviceCoreFeature(DEVICE_CORE_FEATURE_SPARSE_BINDING);
98
99 if (!isImageSizeSupported(context.getInstanceInterface(), context.getPhysicalDevice(), m_imageType, m_imageSize))
100 TCU_THROW(NotSupportedError, "Image size not supported for device");
101
102 if (formatIsR64(m_format))
103 {
104 context.requireDeviceFunctionality("VK_EXT_shader_image_atomic_int64");
105
106 if (context.getShaderImageAtomicInt64FeaturesEXT().sparseImageInt64Atomics == VK_FALSE)
107 {
108 TCU_THROW(NotSupportedError, "sparseImageInt64Atomics is not supported for device");
109 }
110 }
111 }
112
113 class ImageSparseBindingInstance : public SparseResourcesBaseInstance
114 {
115 public:
116 ImageSparseBindingInstance (Context& context,
117 const ImageType imageType,
118 const tcu::UVec3& imageSize,
119 const VkFormat format,
120 const bool useDeviceGroups);
121
122 tcu::TestStatus iterate (void);
123
124 private:
125 const bool m_useDeviceGroups;
126 const ImageType m_imageType;
127 const tcu::UVec3 m_imageSize;
128 const VkFormat m_format;
129 };
130
ImageSparseBindingInstance(Context & context,const ImageType imageType,const tcu::UVec3 & imageSize,const VkFormat format,const bool useDeviceGroups)131 ImageSparseBindingInstance::ImageSparseBindingInstance (Context& context,
132 const ImageType imageType,
133 const tcu::UVec3& imageSize,
134 const VkFormat format,
135 const bool useDeviceGroups)
136
137 : SparseResourcesBaseInstance (context, useDeviceGroups)
138 , m_useDeviceGroups (useDeviceGroups)
139 , m_imageType (imageType)
140 , m_imageSize (imageSize)
141 , m_format (format)
142 {
143 }
144
iterate(void)145 tcu::TestStatus ImageSparseBindingInstance::iterate (void)
146 {
147 const InstanceInterface& instance = m_context.getInstanceInterface();
148
149 {
150 // Create logical device supporting both sparse and compute queues
151 QueueRequirementsVec queueRequirements;
152 queueRequirements.push_back(QueueRequirements(VK_QUEUE_SPARSE_BINDING_BIT, 1u));
153 queueRequirements.push_back(QueueRequirements(VK_QUEUE_COMPUTE_BIT, 1u));
154
155 createDeviceSupportingQueues(queueRequirements);
156 }
157
158 const VkPhysicalDevice physicalDevice = getPhysicalDevice();
159 VkImageCreateInfo imageSparseInfo;
160 std::vector<DeviceMemorySp> deviceMemUniquePtrVec;
161
162 const DeviceInterface& deviceInterface = getDeviceInterface();
163 const Queue& sparseQueue = getQueue(VK_QUEUE_SPARSE_BINDING_BIT, 0);
164 const Queue& computeQueue = getQueue(VK_QUEUE_COMPUTE_BIT, 0);
165 const PlanarFormatDescription formatDescription = getPlanarFormatDescription(m_format);
166
167 // Go through all physical devices
168 for (deUint32 physDevID = 0; physDevID < m_numPhysicalDevices; ++physDevID)
169 {
170 const deUint32 firstDeviceID = physDevID;
171 const deUint32 secondDeviceID = (firstDeviceID + 1) % m_numPhysicalDevices;
172
173 imageSparseInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; //VkStructureType sType;
174 imageSparseInfo.pNext = DE_NULL; //const void* pNext;
175 imageSparseInfo.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT; //VkImageCreateFlags flags;
176 imageSparseInfo.imageType = mapImageType(m_imageType); //VkImageType imageType;
177 imageSparseInfo.format = m_format; //VkFormat format;
178 imageSparseInfo.extent = makeExtent3D(getLayerSize(m_imageType, m_imageSize)); //VkExtent3D extent;
179 imageSparseInfo.arrayLayers = getNumLayers(m_imageType, m_imageSize); //deUint32 arrayLayers;
180 imageSparseInfo.samples = VK_SAMPLE_COUNT_1_BIT; //VkSampleCountFlagBits samples;
181 imageSparseInfo.tiling = VK_IMAGE_TILING_OPTIMAL; //VkImageTiling tiling;
182 imageSparseInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; //VkImageLayout initialLayout;
183 imageSparseInfo.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
184 VK_IMAGE_USAGE_TRANSFER_DST_BIT; //VkImageUsageFlags usage;
185 imageSparseInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; //VkSharingMode sharingMode;
186 imageSparseInfo.queueFamilyIndexCount = 0u; //deUint32 queueFamilyIndexCount;
187 imageSparseInfo.pQueueFamilyIndices = DE_NULL; //const deUint32* pQueueFamilyIndices;
188
189 if (m_imageType == IMAGE_TYPE_CUBE || m_imageType == IMAGE_TYPE_CUBE_ARRAY)
190 {
191 imageSparseInfo.flags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
192 }
193
194 {
195 VkImageFormatProperties imageFormatProperties;
196 if (instance.getPhysicalDeviceImageFormatProperties(physicalDevice,
197 imageSparseInfo.format,
198 imageSparseInfo.imageType,
199 imageSparseInfo.tiling,
200 imageSparseInfo.usage,
201 imageSparseInfo.flags,
202 &imageFormatProperties) == VK_ERROR_FORMAT_NOT_SUPPORTED)
203 {
204 TCU_THROW(NotSupportedError, "Image format does not support sparse binding operations");
205 }
206
207 imageSparseInfo.mipLevels = getMipmapCount(m_format, formatDescription, imageFormatProperties, imageSparseInfo.extent);
208 }
209
210 // Create sparse image
211 const Unique<VkImage> imageSparse(createImage(deviceInterface, getDevice(), &imageSparseInfo));
212
213 // Create sparse image memory bind semaphore
214 const Unique<VkSemaphore> imageMemoryBindSemaphore(createSemaphore(deviceInterface, getDevice()));
215
216 // Get sparse image general memory requirements
217 const VkMemoryRequirements imageMemoryRequirements = getImageMemoryRequirements(deviceInterface, getDevice(), *imageSparse);
218
219 // Check if required image memory size does not exceed device limits
220 if (imageMemoryRequirements.size > getPhysicalDeviceProperties(instance, getPhysicalDevice(secondDeviceID)).limits.sparseAddressSpaceSize)
221 TCU_THROW(NotSupportedError, "Required memory size for sparse resource exceeds device limits");
222
223 DE_ASSERT((imageMemoryRequirements.size % imageMemoryRequirements.alignment) == 0);
224
225 {
226 std::vector<VkSparseMemoryBind> sparseMemoryBinds;
227 const deUint32 numSparseBinds = static_cast<deUint32>(imageMemoryRequirements.size / imageMemoryRequirements.alignment);
228 const deUint32 memoryType = findMatchingMemoryType(instance, getPhysicalDevice(secondDeviceID), imageMemoryRequirements, MemoryRequirement::Any);
229
230 if (memoryType == NO_MATCH_FOUND)
231 return tcu::TestStatus::fail("No matching memory type found");
232
233 if (firstDeviceID != secondDeviceID)
234 {
235 VkPeerMemoryFeatureFlags peerMemoryFeatureFlags = (VkPeerMemoryFeatureFlags)0;
236 const deUint32 heapIndex = getHeapIndexForMemoryType(instance, getPhysicalDevice(secondDeviceID), memoryType);
237 deviceInterface.getDeviceGroupPeerMemoryFeatures(getDevice(), heapIndex, firstDeviceID, secondDeviceID, &peerMemoryFeatureFlags);
238
239 if (((peerMemoryFeatureFlags & VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT) == 0) ||
240 ((peerMemoryFeatureFlags & VK_PEER_MEMORY_FEATURE_COPY_DST_BIT) == 0))
241 {
242 TCU_THROW(NotSupportedError, "Peer memory does not support COPY_SRC and COPY_DST");
243 }
244 }
245
246 for (deUint32 sparseBindNdx = 0; sparseBindNdx < numSparseBinds; ++sparseBindNdx)
247 {
248 const VkSparseMemoryBind sparseMemoryBind = makeSparseMemoryBind(deviceInterface, getDevice(),
249 imageMemoryRequirements.alignment, memoryType, imageMemoryRequirements.alignment * sparseBindNdx);
250
251 deviceMemUniquePtrVec.push_back(makeVkSharedPtr(Move<VkDeviceMemory>(check<VkDeviceMemory>(sparseMemoryBind.memory), Deleter<VkDeviceMemory>(deviceInterface, getDevice(), DE_NULL))));
252
253 sparseMemoryBinds.push_back(sparseMemoryBind);
254 }
255
256 const VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo = makeSparseImageOpaqueMemoryBindInfo(*imageSparse, static_cast<deUint32>(sparseMemoryBinds.size()), sparseMemoryBinds.data());
257
258 const VkDeviceGroupBindSparseInfo devGroupBindSparseInfo =
259 {
260 VK_STRUCTURE_TYPE_DEVICE_GROUP_BIND_SPARSE_INFO, //VkStructureType sType;
261 DE_NULL, //const void* pNext;
262 firstDeviceID, //deUint32 resourceDeviceIndex;
263 secondDeviceID, //deUint32 memoryDeviceIndex;
264 };
265
266 const VkBindSparseInfo bindSparseInfo =
267 {
268 VK_STRUCTURE_TYPE_BIND_SPARSE_INFO, //VkStructureType sType;
269 m_useDeviceGroups ? &devGroupBindSparseInfo : DE_NULL, //const void* pNext;
270 0u, //deUint32 waitSemaphoreCount;
271 DE_NULL, //const VkSemaphore* pWaitSemaphores;
272 0u, //deUint32 bufferBindCount;
273 DE_NULL, //const VkSparseBufferMemoryBindInfo* pBufferBinds;
274 1u, //deUint32 imageOpaqueBindCount;
275 &opaqueBindInfo, //const VkSparseImageOpaqueMemoryBindInfo* pImageOpaqueBinds;
276 0u, //deUint32 imageBindCount;
277 DE_NULL, //const VkSparseImageMemoryBindInfo* pImageBinds;
278 1u, //deUint32 signalSemaphoreCount;
279 &imageMemoryBindSemaphore.get() //const VkSemaphore* pSignalSemaphores;
280 };
281
282 // Submit sparse bind commands for execution
283 VK_CHECK(deviceInterface.queueBindSparse(sparseQueue.queueHandle, 1u, &bindSparseInfo, DE_NULL));
284 }
285
286 deUint32 imageSizeInBytes = 0;
287
288 for (deUint32 planeNdx = 0; planeNdx < formatDescription.numPlanes; ++planeNdx)
289 for (deUint32 mipmapNdx = 0; mipmapNdx < imageSparseInfo.mipLevels; ++mipmapNdx)
290 imageSizeInBytes += getImageMipLevelSizeInBytes(imageSparseInfo.extent, imageSparseInfo.arrayLayers, formatDescription, planeNdx, mipmapNdx, BUFFER_IMAGE_COPY_OFFSET_GRANULARITY);
291
292 std::vector<VkBufferImageCopy> bufferImageCopy(formatDescription.numPlanes * imageSparseInfo.mipLevels);
293 {
294 deUint32 bufferOffset = 0;
295 for (deUint32 planeNdx = 0; planeNdx < formatDescription.numPlanes; ++planeNdx)
296 {
297 const VkImageAspectFlags aspect = (formatDescription.numPlanes > 1) ? getPlaneAspect(planeNdx) : VK_IMAGE_ASPECT_COLOR_BIT;
298
299 for (deUint32 mipmapNdx = 0; mipmapNdx < imageSparseInfo.mipLevels; ++mipmapNdx)
300 {
301 bufferImageCopy[planeNdx*imageSparseInfo.mipLevels + mipmapNdx] =
302 {
303 bufferOffset, // VkDeviceSize bufferOffset;
304 0u, // deUint32 bufferRowLength;
305 0u, // deUint32 bufferImageHeight;
306 makeImageSubresourceLayers(aspect, mipmapNdx, 0u, imageSparseInfo.arrayLayers), // VkImageSubresourceLayers imageSubresource;
307 makeOffset3D(0, 0, 0), // VkOffset3D imageOffset;
308 vk::getPlaneExtent(formatDescription, imageSparseInfo.extent, planeNdx, mipmapNdx) // VkExtent3D imageExtent;
309 };
310 bufferOffset += getImageMipLevelSizeInBytes(imageSparseInfo.extent, imageSparseInfo.arrayLayers, formatDescription, planeNdx, mipmapNdx, BUFFER_IMAGE_COPY_OFFSET_GRANULARITY);
311 }
312 }
313 }
314
315 // Create command buffer for compute and transfer operations
316 const Unique<VkCommandPool> commandPool(makeCommandPool(deviceInterface, getDevice(), computeQueue.queueFamilyIndex));
317 const Unique<VkCommandBuffer> commandBuffer(allocateCommandBuffer(deviceInterface, getDevice(), *commandPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
318
319 // Start recording commands
320 beginCommandBuffer(deviceInterface, *commandBuffer);
321
322 const VkBufferCreateInfo inputBufferCreateInfo = makeBufferCreateInfo(imageSizeInBytes, VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
323 const Unique<VkBuffer> inputBuffer (createBuffer(deviceInterface, getDevice(), &inputBufferCreateInfo));
324 const de::UniquePtr<Allocation> inputBufferAlloc (bindBuffer(deviceInterface, getDevice(), getAllocator(), *inputBuffer, MemoryRequirement::HostVisible));
325
326 std::vector<deUint8> referenceData(imageSizeInBytes);
327 for (deUint32 valueNdx = 0; valueNdx < imageSizeInBytes; ++valueNdx)
328 {
329 referenceData[valueNdx] = static_cast<deUint8>((valueNdx % imageMemoryRequirements.alignment) + 1u);
330 }
331
332 {
333 deMemcpy(inputBufferAlloc->getHostPtr(), referenceData.data(), imageSizeInBytes);
334 flushAlloc(deviceInterface, getDevice(), *inputBufferAlloc);
335
336 const VkBufferMemoryBarrier inputBufferBarrier = makeBufferMemoryBarrier (
337 VK_ACCESS_HOST_WRITE_BIT,
338 VK_ACCESS_TRANSFER_READ_BIT,
339 *inputBuffer,
340 0u,
341 imageSizeInBytes
342 );
343 deviceInterface.cmdPipelineBarrier(*commandBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 1u, &inputBufferBarrier, 0u, DE_NULL);
344 }
345
346 {
347 std::vector<VkImageMemoryBarrier> imageSparseTransferDstBarriers;
348
349 for (deUint32 planeNdx = 0; planeNdx < formatDescription.numPlanes; ++planeNdx)
350 {
351 const VkImageAspectFlags aspect = (formatDescription.numPlanes > 1) ? getPlaneAspect(planeNdx) : VK_IMAGE_ASPECT_COLOR_BIT;
352
353 imageSparseTransferDstBarriers.push_back( makeImageMemoryBarrier (
354 0u,
355 VK_ACCESS_TRANSFER_WRITE_BIT,
356 VK_IMAGE_LAYOUT_UNDEFINED,
357 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
358 *imageSparse,
359 makeImageSubresourceRange(aspect, 0u, imageSparseInfo.mipLevels, 0u, imageSparseInfo.arrayLayers),
360 sparseQueue.queueFamilyIndex != computeQueue.queueFamilyIndex ? sparseQueue.queueFamilyIndex : VK_QUEUE_FAMILY_IGNORED,
361 sparseQueue.queueFamilyIndex != computeQueue.queueFamilyIndex ? computeQueue.queueFamilyIndex : VK_QUEUE_FAMILY_IGNORED
362 ));
363 }
364 deviceInterface.cmdPipelineBarrier(*commandBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, static_cast<deUint32>(imageSparseTransferDstBarriers.size()), imageSparseTransferDstBarriers.data());
365 }
366
367 deviceInterface.cmdCopyBufferToImage(*commandBuffer, *inputBuffer, *imageSparse, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, static_cast<deUint32>(bufferImageCopy.size()), bufferImageCopy.data());
368
369 {
370 std::vector<VkImageMemoryBarrier> imageSparseTransferSrcBarriers;
371
372 for (deUint32 planeNdx = 0; planeNdx < formatDescription.numPlanes; ++planeNdx)
373 {
374 const VkImageAspectFlags aspect = (formatDescription.numPlanes > 1) ? getPlaneAspect(planeNdx) : VK_IMAGE_ASPECT_COLOR_BIT;
375
376 imageSparseTransferSrcBarriers.push_back( makeImageMemoryBarrier (
377 VK_ACCESS_TRANSFER_WRITE_BIT,
378 VK_ACCESS_TRANSFER_READ_BIT,
379 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
380 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
381 *imageSparse,
382 makeImageSubresourceRange(aspect, 0u, imageSparseInfo.mipLevels, 0u, imageSparseInfo.arrayLayers)
383 ));
384 }
385
386 deviceInterface.cmdPipelineBarrier(*commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, static_cast<deUint32>(imageSparseTransferSrcBarriers.size()), imageSparseTransferSrcBarriers.data());
387 }
388
389 const VkBufferCreateInfo outputBufferCreateInfo = makeBufferCreateInfo(imageSizeInBytes, VK_BUFFER_USAGE_TRANSFER_DST_BIT);
390 const Unique<VkBuffer> outputBuffer (createBuffer(deviceInterface, getDevice(), &outputBufferCreateInfo));
391 const de::UniquePtr<Allocation> outputBufferAlloc (bindBuffer(deviceInterface, getDevice(), getAllocator(), *outputBuffer, MemoryRequirement::HostVisible));
392
393 deviceInterface.cmdCopyImageToBuffer(*commandBuffer, *imageSparse, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *outputBuffer, static_cast<deUint32>(bufferImageCopy.size()), bufferImageCopy.data());
394
395 {
396 const VkBufferMemoryBarrier outputBufferBarrier = makeBufferMemoryBarrier
397 (
398 VK_ACCESS_TRANSFER_WRITE_BIT,
399 VK_ACCESS_HOST_READ_BIT,
400 *outputBuffer,
401 0u,
402 imageSizeInBytes
403 );
404
405 deviceInterface.cmdPipelineBarrier(*commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, 1u, &outputBufferBarrier, 0u, DE_NULL);
406 }
407
408 // End recording commands
409 endCommandBuffer(deviceInterface, *commandBuffer);
410
411 const VkPipelineStageFlags stageBits[] = { VK_PIPELINE_STAGE_TRANSFER_BIT };
412
413 // Submit commands for execution and wait for completion
414 submitCommandsAndWait(deviceInterface, getDevice(), computeQueue.queueHandle, *commandBuffer, 1u, &imageMemoryBindSemaphore.get(), stageBits,
415 0, DE_NULL, m_useDeviceGroups, firstDeviceID);
416
417 // Retrieve data from buffer to host memory
418 invalidateAlloc(deviceInterface, getDevice(), *outputBufferAlloc);
419
420 // Wait for sparse queue to become idle
421 deviceInterface.queueWaitIdle(sparseQueue.queueHandle);
422
423 const deUint8* outputData = static_cast<const deUint8*>(outputBufferAlloc->getHostPtr());
424 bool ignoreLsb6Bits = areLsb6BitsDontCare(imageSparseInfo.format);
425 bool ignoreLsb4Bits = areLsb4BitsDontCare(imageSparseInfo.format);
426
427 for (deUint32 planeNdx = 0; planeNdx < formatDescription.numPlanes; ++planeNdx)
428 {
429 for (deUint32 mipmapNdx = 0; mipmapNdx < imageSparseInfo.mipLevels; ++mipmapNdx)
430 {
431 const deUint32 mipLevelSizeInBytes = getImageMipLevelSizeInBytes(imageSparseInfo.extent, imageSparseInfo.arrayLayers, formatDescription, planeNdx, mipmapNdx);
432 const deUint32 bufferOffset = static_cast<deUint32>(bufferImageCopy[ planeNdx * imageSparseInfo.mipLevels + mipmapNdx].bufferOffset);
433
434 // Validate results
435 for (size_t byteNdx = 0; byteNdx < mipLevelSizeInBytes; byteNdx++)
436 {
437 const deUint8 res = *(outputData + bufferOffset + byteNdx);
438 const deUint8 ref = referenceData[bufferOffset + byteNdx];
439
440 deUint8 mask = 0xFF;
441
442 if (!(byteNdx & 0x01) && (ignoreLsb6Bits))
443 mask = 0xC0;
444 else if (!(byteNdx & 0x01) && (ignoreLsb4Bits))
445 mask = 0xF0;
446
447 if ((res & mask) != (ref & mask))
448 {
449 return tcu::TestStatus::fail("Failed");
450 }
451 }
452 }
453 }
454 }
455
456 return tcu::TestStatus::pass("Passed");
457 }
458
createInstance(Context & context) const459 TestInstance* ImageSparseBindingCase::createInstance (Context& context) const
460 {
461 return new ImageSparseBindingInstance(context, m_imageType, m_imageSize, m_format, m_useDeviceGroups);
462 }
463
464 } // anonymous ns
465
createImageSparseBindingTestsCommon(tcu::TestContext & testCtx,de::MovePtr<tcu::TestCaseGroup> testGroup,const bool useDeviceGroup=false)466 tcu::TestCaseGroup* createImageSparseBindingTestsCommon(tcu::TestContext& testCtx, de::MovePtr<tcu::TestCaseGroup> testGroup, const bool useDeviceGroup = false)
467 {
468 const std::vector<TestImageParameters> imageParameters
469 {
470 { IMAGE_TYPE_1D, { tcu::UVec3(512u, 1u, 1u ), tcu::UVec3(1024u, 1u, 1u), tcu::UVec3(11u, 1u, 1u) }, getTestFormats(IMAGE_TYPE_1D) },
471 { IMAGE_TYPE_1D_ARRAY, { tcu::UVec3(512u, 1u, 64u), tcu::UVec3(1024u, 1u, 8u), tcu::UVec3(11u, 1u, 3u) }, getTestFormats(IMAGE_TYPE_1D_ARRAY) },
472 { IMAGE_TYPE_2D, { tcu::UVec3(512u, 256u, 1u ), tcu::UVec3(1024u, 128u, 1u), tcu::UVec3(11u, 137u, 1u) }, getTestFormats(IMAGE_TYPE_2D) },
473 { IMAGE_TYPE_2D_ARRAY, { tcu::UVec3(512u, 256u, 6u ), tcu::UVec3(1024u, 128u, 8u), tcu::UVec3(11u, 137u, 3u) }, getTestFormats(IMAGE_TYPE_2D_ARRAY) },
474 { IMAGE_TYPE_3D, { tcu::UVec3(512u, 256u, 6u ), tcu::UVec3(1024u, 128u, 8u), tcu::UVec3(11u, 137u, 3u) }, getTestFormats(IMAGE_TYPE_3D) },
475 { IMAGE_TYPE_CUBE, { tcu::UVec3(256u, 256u, 1u ), tcu::UVec3(128u, 128u, 1u), tcu::UVec3(137u, 137u, 1u) }, getTestFormats(IMAGE_TYPE_CUBE) },
476 { IMAGE_TYPE_CUBE_ARRAY, { tcu::UVec3(256u, 256u, 6u ), tcu::UVec3(128u, 128u, 8u), tcu::UVec3(137u, 137u, 3u) }, getTestFormats(IMAGE_TYPE_CUBE_ARRAY) }
477 };
478
479 for (size_t imageTypeNdx = 0; imageTypeNdx < imageParameters.size(); ++imageTypeNdx)
480 {
481 const ImageType imageType = imageParameters[imageTypeNdx].imageType;
482 de::MovePtr<tcu::TestCaseGroup> imageTypeGroup (new tcu::TestCaseGroup(testCtx, getImageTypeName(imageType).c_str(), ""));
483
484 for (size_t formatNdx = 0; formatNdx < imageParameters[imageTypeNdx].formats.size(); ++formatNdx)
485 {
486 VkFormat format = imageParameters[imageTypeNdx].formats[formatNdx].format;
487 tcu::UVec3 imageSizeAlignment = getImageSizeAlignment(format);
488 de::MovePtr<tcu::TestCaseGroup> formatGroup (new tcu::TestCaseGroup(testCtx, getImageFormatID(format).c_str(), ""));
489
490 for (size_t imageSizeNdx = 0; imageSizeNdx < imageParameters[imageTypeNdx].imageSizes.size(); ++imageSizeNdx)
491 {
492 const tcu::UVec3 imageSize = imageParameters[imageTypeNdx].imageSizes[imageSizeNdx];
493
494 // skip test for images with odd sizes for some YCbCr formats
495 if ((imageSize.x() % imageSizeAlignment.x()) != 0)
496 continue;
497 if ((imageSize.y() % imageSizeAlignment.y()) != 0)
498 continue;
499
500 std::ostringstream stream;
501 stream << imageSize.x() << "_" << imageSize.y() << "_" << imageSize.z();
502
503 formatGroup->addChild(new ImageSparseBindingCase(testCtx, stream.str(), "", imageType, imageSize, format, useDeviceGroup));
504 }
505 imageTypeGroup->addChild(formatGroup.release());
506 }
507 testGroup->addChild(imageTypeGroup.release());
508 }
509
510 return testGroup.release();
511 }
512
createImageSparseBindingTests(tcu::TestContext & testCtx)513 tcu::TestCaseGroup* createImageSparseBindingTests(tcu::TestContext& testCtx)
514 {
515 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "image_sparse_binding", "Image Sparse Binding"));
516 return createImageSparseBindingTestsCommon(testCtx, testGroup);
517 }
518
createDeviceGroupImageSparseBindingTests(tcu::TestContext & testCtx)519 tcu::TestCaseGroup* createDeviceGroupImageSparseBindingTests(tcu::TestContext& testCtx)
520 {
521 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "device_group_image_sparse_binding", "Device Group Image Sparse Binding"));
522 return createImageSparseBindingTestsCommon(testCtx, testGroup, true);
523 }
524
525 } // sparse
526 } // vkt
527