1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 The Khronos Group Inc.
6 * Copyright (c) 2015 Imagination Technologies Ltd.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 * \brief Utilities for images.
23 *//*--------------------------------------------------------------------*/
25 #include "vktPipelineImageUtil.hpp"
26 #include "vkImageUtil.hpp"
27 #include "vkMemUtil.hpp"
28 #include "vkQueryUtil.hpp"
29 #include "vkRefUtil.hpp"
30 #include "tcuTextureUtil.hpp"
31 #include "tcuAstcUtil.hpp"
32 #include "deRandom.hpp"
41 /*! Gets the next multiple of a given divisor */
42 static deUint32 getNextMultiple (deUint32 divisor, deUint32 value)
44 if (value % divisor == 0)
48 return value + divisor - (value % divisor);
51 /*! Gets the next value that is multiple of all given divisors */
52 static deUint32 getNextMultiple (const std::vector<deUint32>& divisors, deUint32 value)
54 deUint32 nextMultiple = value;
55 bool nextMultipleFound = false;
59 nextMultipleFound = true;
61 for (size_t divNdx = 0; divNdx < divisors.size(); divNdx++)
62 nextMultipleFound = nextMultipleFound && (nextMultiple % divisors[divNdx] == 0);
64 if (nextMultipleFound)
67 DE_ASSERT(nextMultiple < ~((deUint32)0u));
68 nextMultiple = getNextMultiple(divisors[0], nextMultiple + 1);
74 bool isSupportedSamplableFormat (const InstanceInterface& instanceInterface, VkPhysicalDevice device, VkFormat format)
76 if (isCompressedFormat(format))
78 VkPhysicalDeviceFeatures physicalFeatures;
79 const tcu::CompressedTexFormat compressedFormat = mapVkCompressedFormat(format);
81 instanceInterface.getPhysicalDeviceFeatures(device, &physicalFeatures);
83 if (tcu::isAstcFormat(compressedFormat))
85 if (!physicalFeatures.textureCompressionASTC_LDR)
88 else if (tcu::isEtcFormat(compressedFormat))
90 if (!physicalFeatures.textureCompressionETC2)
95 DE_FATAL("Unsupported compressed format");
99 VkFormatProperties formatProps;
100 instanceInterface.getPhysicalDeviceFormatProperties(device, format, &formatProps);
102 return (formatProps.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) != 0u;
105 // \todo [2016-01-21 pyry] Update this to just rely on vkDefs.hpp once
106 // CTS has been updated to 1.0.2.
109 VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT = 0x00001000,
112 bool isLinearFilteringSupported (const InstanceInterface& vki, VkPhysicalDevice physicalDevice, VkFormat format, VkImageTiling tiling)
114 const VkFormatProperties formatProperties = getPhysicalDeviceFormatProperties(vki, physicalDevice, format);
115 const VkFormatFeatureFlags formatFeatures = tiling == VK_IMAGE_TILING_LINEAR
116 ? formatProperties.linearTilingFeatures
117 : formatProperties.optimalTilingFeatures;
121 case VK_FORMAT_R32_SFLOAT:
122 case VK_FORMAT_R32G32_SFLOAT:
123 case VK_FORMAT_R32G32B32_SFLOAT:
124 case VK_FORMAT_R32G32B32A32_SFLOAT:
125 case VK_FORMAT_R64_SFLOAT:
126 case VK_FORMAT_R64G64_SFLOAT:
127 case VK_FORMAT_R64G64B64_SFLOAT:
128 case VK_FORMAT_R64G64B64A64_SFLOAT:
129 return (formatFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT) != 0;
132 // \todo [2016-01-21 pyry] Check for all formats once drivers have been updated to 1.0.2
133 // and we have tests to verify format properties.
138 VkBorderColor getFormatBorderColor (BorderColor color, VkFormat format)
140 if (!isCompressedFormat(format) && (isIntFormat(format) || isUintFormat(format)))
144 case BORDER_COLOR_OPAQUE_BLACK: return VK_BORDER_COLOR_INT_OPAQUE_BLACK;
145 case BORDER_COLOR_OPAQUE_WHITE: return VK_BORDER_COLOR_INT_OPAQUE_WHITE;
146 case BORDER_COLOR_TRANSPARENT_BLACK: return VK_BORDER_COLOR_INT_TRANSPARENT_BLACK;
155 case BORDER_COLOR_OPAQUE_BLACK: return VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK;
156 case BORDER_COLOR_OPAQUE_WHITE: return VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
157 case BORDER_COLOR_TRANSPARENT_BLACK: return VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
164 return VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
167 void getLookupScaleBias (vk::VkFormat format, tcu::Vec4& lookupScale, tcu::Vec4& lookupBias)
169 if (!isCompressedFormat(format))
171 const tcu::TextureFormatInfo fmtInfo = tcu::getTextureFormatInfo(mapVkFormat(format));
173 // Needed to normalize various formats to 0..1 range for writing into RT
174 lookupScale = fmtInfo.lookupScale;
175 lookupBias = fmtInfo.lookupBias;
181 case VK_FORMAT_EAC_R11_SNORM_BLOCK:
182 lookupScale = tcu::Vec4(0.5f, 1.0f, 1.0f, 1.0f);
183 lookupBias = tcu::Vec4(0.5f, 0.0f, 0.0f, 0.0f);
186 case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
187 lookupScale = tcu::Vec4(0.5f, 0.5f, 1.0f, 1.0f);
188 lookupBias = tcu::Vec4(0.5f, 0.5f, 0.0f, 0.0f);
192 // else: All supported compressed formats are fine with no normalization.
193 // ASTC LDR blocks decompress to f16 so querying normalization parameters
194 // based on uncompressed formats would actually lead to massive precision loss
195 // and complete lack of coverage in case of R8G8B8A8_UNORM RT.
196 lookupScale = tcu::Vec4(1.0f);
197 lookupBias = tcu::Vec4(0.0f);
203 de::MovePtr<tcu::TextureLevel> readColorAttachment (const vk::DeviceInterface& vk,
206 deUint32 queueFamilyIndex,
207 vk::Allocator& allocator,
210 const tcu::UVec2& renderSize)
212 Move<VkBuffer> buffer;
213 de::MovePtr<Allocation> bufferAlloc;
214 Move<VkCommandPool> cmdPool;
215 Move<VkCommandBuffer> cmdBuffer;
217 const tcu::TextureFormat tcuFormat = mapVkFormat(format);
218 const VkDeviceSize pixelDataSize = renderSize.x() * renderSize.y() * tcuFormat.getPixelSize();
219 de::MovePtr<tcu::TextureLevel> resultLevel (new tcu::TextureLevel(tcuFormat, renderSize.x(), renderSize.y()));
221 // Create destination buffer
223 const VkBufferCreateInfo bufferParams =
225 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
226 DE_NULL, // const void* pNext;
227 0u, // VkBufferCreateFlags flags;
228 pixelDataSize, // VkDeviceSize size;
229 VK_BUFFER_USAGE_TRANSFER_DST_BIT, // VkBufferUsageFlags usage;
230 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
231 0u, // deUint32 queueFamilyIndexCount;
232 DE_NULL // const deUint32* pQueueFamilyIndices;
235 buffer = createBuffer(vk, device, &bufferParams);
236 bufferAlloc = allocator.allocate(getBufferMemoryRequirements(vk, device, *buffer), MemoryRequirement::HostVisible);
237 VK_CHECK(vk.bindBufferMemory(device, *buffer, bufferAlloc->getMemory(), bufferAlloc->getOffset()));
240 // Create command pool and buffer
242 const VkCommandPoolCreateInfo cmdPoolParams =
244 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
245 DE_NULL, // const void* pNext;
246 VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, // VkCmdPoolCreateFlags flags;
247 queueFamilyIndex, // deUint32 queueFamilyIndex;
250 cmdPool = createCommandPool(vk, device, &cmdPoolParams);
252 const VkCommandBufferAllocateInfo cmdBufferAllocateInfo =
254 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
255 DE_NULL, // const void* pNext;
256 *cmdPool, // VkCommandPool commandPool;
257 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
258 1u // deUint32 bufferCount;
261 cmdBuffer = allocateCommandBuffer(vk, device, &cmdBufferAllocateInfo);
266 const VkFenceCreateInfo fenceParams =
268 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // VkStructureType sType;
269 DE_NULL, // const void* pNext;
270 0u // VkFenceCreateFlags flags;
273 fence = createFence(vk, device, &fenceParams);
276 // Barriers for copying image to buffer
278 const VkImageMemoryBarrier imageBarrier =
280 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
281 DE_NULL, // const void* pNext;
282 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkAccessFlags srcAccessMask;
283 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask;
284 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout oldLayout;
285 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // VkImageLayout newLayout;
286 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
287 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
288 image, // VkImage image;
289 { // VkImageSubresourceRange subresourceRange;
290 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
291 0u, // deUint32 baseMipLevel;
292 1u, // deUint32 mipLevels;
293 0u, // deUint32 baseArraySlice;
294 1u // deUint32 arraySize;
298 const VkBufferMemoryBarrier bufferBarrier =
300 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
301 DE_NULL, // const void* pNext;
302 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
303 VK_ACCESS_HOST_READ_BIT, // VkAccessFlags dstAccessMask;
304 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
305 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
306 *buffer, // VkBuffer buffer;
307 0u, // VkDeviceSize offset;
308 pixelDataSize // VkDeviceSize size;
311 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
313 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
314 DE_NULL, // const void* pNext;
315 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
316 (const VkCommandBufferInheritanceInfo*)DE_NULL,
319 // Copy image to buffer
321 const VkBufferImageCopy copyRegion =
323 0u, // VkDeviceSize bufferOffset;
324 (deUint32)renderSize.x(), // deUint32 bufferRowLength;
325 (deUint32)renderSize.y(), // deUint32 bufferImageHeight;
326 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u }, // VkImageSubresourceLayers imageSubresource;
327 { 0, 0, 0 }, // VkOffset3D imageOffset;
328 { renderSize.x(), renderSize.y(), 1u } // VkExtent3D imageExtent;
331 VK_CHECK(vk.beginCommandBuffer(*cmdBuffer, &cmdBufferBeginInfo));
332 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &imageBarrier);
333 vk.cmdCopyImageToBuffer(*cmdBuffer, image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *buffer, 1, ©Region);
334 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &bufferBarrier, 0, (const VkImageMemoryBarrier*)DE_NULL);
335 VK_CHECK(vk.endCommandBuffer(*cmdBuffer));
337 const VkSubmitInfo submitInfo =
339 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
340 DE_NULL, // const void* pNext;
341 0u, // deUint32 waitSemaphoreCount;
342 DE_NULL, // const VkSemaphore* pWaitSemaphores;
344 1u, // deUint32 commandBufferCount;
345 &cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
346 0u, // deUint32 signalSemaphoreCount;
347 DE_NULL // const VkSemaphore* pSignalSemaphores;
350 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *fence));
351 VK_CHECK(vk.waitForFences(device, 1, &fence.get(), 0, ~(0ull) /* infinity */));
354 invalidateMappedMemoryRange(vk, device, bufferAlloc->getMemory(), bufferAlloc->getOffset(), VK_WHOLE_SIZE);
355 tcu::copy(*resultLevel, tcu::ConstPixelBufferAccess(resultLevel->getFormat(), resultLevel->getSize(), bufferAlloc->getHostPtr()));
363 VkImageAspectFlags getImageAspectFlags (const tcu::TextureFormat textureFormat)
365 VkImageAspectFlags imageAspectFlags = 0;
367 if (tcu::hasDepthComponent(textureFormat.order))
368 imageAspectFlags |= VK_IMAGE_ASPECT_DEPTH_BIT;
370 if (tcu::hasStencilComponent(textureFormat.order))
371 imageAspectFlags |= VK_IMAGE_ASPECT_STENCIL_BIT;
373 if (imageAspectFlags == 0)
374 imageAspectFlags = VK_IMAGE_ASPECT_COLOR_BIT;
376 return imageAspectFlags;
381 void uploadTestTextureInternal (const DeviceInterface& vk,
384 deUint32 queueFamilyIndex,
385 Allocator& allocator,
386 const TestTexture& srcTexture,
387 const TestTexture* srcStencilTexture,
388 tcu::TextureFormat format,
392 Move<VkBuffer> buffer;
393 de::MovePtr<Allocation> bufferAlloc;
394 Move<VkCommandPool> cmdPool;
395 Move<VkCommandBuffer> cmdBuffer;
397 const VkImageAspectFlags imageAspectFlags = getImageAspectFlags(format);
398 deUint32 stencilOffset = 0u;
400 // Calculate buffer size
401 bufferSize = (srcTexture.isCompressed())? srcTexture.getCompressedSize(): srcTexture.getSize();
403 // Stencil-only texture should be provided if (and only if) the image has a combined DS format
404 DE_ASSERT((tcu::hasDepthComponent(format.order) && tcu::hasStencilComponent(format.order)) == (srcStencilTexture != DE_NULL));
406 if (srcStencilTexture != DE_NULL)
408 stencilOffset = static_cast<deUint32>(deAlign32(static_cast<deInt32>(bufferSize), 4));
409 bufferSize = stencilOffset + srcStencilTexture->getSize();
412 // Create source buffer
414 const VkBufferCreateInfo bufferParams =
416 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
417 DE_NULL, // const void* pNext;
418 0u, // VkBufferCreateFlags flags;
419 bufferSize, // VkDeviceSize size;
420 VK_BUFFER_USAGE_TRANSFER_SRC_BIT, // VkBufferUsageFlags usage;
421 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
422 0u, // deUint32 queueFamilyIndexCount;
423 DE_NULL, // const deUint32* pQueueFamilyIndices;
426 buffer = createBuffer(vk, device, &bufferParams);
427 bufferAlloc = allocator.allocate(getBufferMemoryRequirements(vk, device, *buffer), MemoryRequirement::HostVisible);
428 VK_CHECK(vk.bindBufferMemory(device, *buffer, bufferAlloc->getMemory(), bufferAlloc->getOffset()));
431 // Create command pool and buffer
433 const VkCommandPoolCreateInfo cmdPoolParams =
435 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
436 DE_NULL, // const void* pNext;
437 VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, // VkCommandPoolCreateFlags flags;
438 queueFamilyIndex, // deUint32 queueFamilyIndex;
441 cmdPool = createCommandPool(vk, device, &cmdPoolParams);
443 const VkCommandBufferAllocateInfo cmdBufferAllocateInfo =
445 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
446 DE_NULL, // const void* pNext;
447 *cmdPool, // VkCommandPool commandPool;
448 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
449 1u, // deUint32 bufferCount;
452 cmdBuffer = allocateCommandBuffer(vk, device, &cmdBufferAllocateInfo);
457 const VkFenceCreateInfo fenceParams =
459 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // VkStructureType sType;
460 DE_NULL, // const void* pNext;
461 0u // VkFenceCreateFlags flags;
464 fence = createFence(vk, device, &fenceParams);
467 // Barriers for copying buffer to image
468 const VkBufferMemoryBarrier preBufferBarrier =
470 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
471 DE_NULL, // const void* pNext;
472 VK_ACCESS_HOST_WRITE_BIT, // VkAccessFlags srcAccessMask;
473 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask;
474 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
475 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
476 *buffer, // VkBuffer buffer;
477 0u, // VkDeviceSize offset;
478 bufferSize // VkDeviceSize size;
481 const VkImageMemoryBarrier preImageBarrier =
483 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
484 DE_NULL, // const void* pNext;
485 0u, // VkAccessFlags srcAccessMask;
486 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask;
487 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
488 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout newLayout;
489 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
490 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
491 destImage, // VkImage image;
492 { // VkImageSubresourceRange subresourceRange;
493 imageAspectFlags, // VkImageAspectFlags aspectMask;
494 0u, // deUint32 baseMipLevel;
495 (deUint32)srcTexture.getNumLevels(), // deUint32 mipLevels;
496 0u, // deUint32 baseArraySlice;
497 (deUint32)srcTexture.getArraySize(), // deUint32 arraySize;
501 const VkImageMemoryBarrier postImageBarrier =
503 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
504 DE_NULL, // const void* pNext;
505 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
506 VK_ACCESS_SHADER_READ_BIT, // VkAccessFlags dstAccessMask;
507 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
508 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, // VkImageLayout newLayout;
509 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
510 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
511 destImage, // VkImage image;
512 { // VkImageSubresourceRange subresourceRange;
513 imageAspectFlags, // VkImageAspectFlags aspectMask;
514 0u, // deUint32 baseMipLevel;
515 (deUint32)srcTexture.getNumLevels(), // deUint32 mipLevels;
516 0u, // deUint32 baseArraySlice;
517 (deUint32)srcTexture.getArraySize(), // deUint32 arraySize;
521 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
523 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
524 DE_NULL, // const void* pNext;
525 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
526 (const VkCommandBufferInheritanceInfo*)DE_NULL,
529 std::vector<VkBufferImageCopy> copyRegions = srcTexture.getBufferCopyRegions();
532 srcTexture.write(reinterpret_cast<deUint8*>(bufferAlloc->getHostPtr()));
534 if (srcStencilTexture != DE_NULL)
536 DE_ASSERT(stencilOffset != 0u);
538 srcStencilTexture->write(reinterpret_cast<deUint8*>(bufferAlloc->getHostPtr()) + stencilOffset);
540 std::vector<VkBufferImageCopy> stencilCopyRegions = srcStencilTexture->getBufferCopyRegions();
541 for (size_t regionIdx = 0; regionIdx < stencilCopyRegions.size(); regionIdx++)
543 VkBufferImageCopy region = stencilCopyRegions[regionIdx];
544 region.bufferOffset += stencilOffset;
546 copyRegions.push_back(region);
550 flushMappedMemoryRange(vk, device, bufferAlloc->getMemory(), bufferAlloc->getOffset(), VK_WHOLE_SIZE);
552 // Copy buffer to image
553 VK_CHECK(vk.beginCommandBuffer(*cmdBuffer, &cmdBufferBeginInfo));
554 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &preBufferBarrier, 1, &preImageBarrier);
555 vk.cmdCopyBufferToImage(*cmdBuffer, *buffer, destImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, (deUint32)copyRegions.size(), copyRegions.data());
556 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &postImageBarrier);
558 VK_CHECK(vk.endCommandBuffer(*cmdBuffer));
560 const VkSubmitInfo submitInfo =
562 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
563 DE_NULL, // const void* pNext;
564 0u, // deUint32 waitSemaphoreCount;
565 DE_NULL, // const VkSemaphore* pWaitSemaphores;
567 1u, // deUint32 commandBufferCount;
568 &cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
569 0u, // deUint32 signalSemaphoreCount;
570 DE_NULL // const VkSemaphore* pSignalSemaphores;
573 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *fence));
574 VK_CHECK(vk.waitForFences(device, 1, &fence.get(), true, ~(0ull) /* infinity */));
577 void uploadTestTexture (const DeviceInterface& vk,
580 deUint32 queueFamilyIndex,
581 Allocator& allocator,
582 const TestTexture& srcTexture,
585 if (tcu::isCombinedDepthStencilType(srcTexture.getTextureFormat().type))
587 de::MovePtr<TestTexture> srcDepthTexture;
588 de::MovePtr<TestTexture> srcStencilTexture;
590 if (tcu::hasDepthComponent(srcTexture.getTextureFormat().order))
592 tcu::TextureFormat format;
593 switch (srcTexture.getTextureFormat().type) {
594 case tcu::TextureFormat::UNSIGNED_INT_16_8_8:
595 format = tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::UNORM_INT16);
597 case tcu::TextureFormat::UNSIGNED_INT_24_8_REV:
598 format = tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::UNSIGNED_INT_24_8_REV);
600 case tcu::TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV:
601 format = tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::FLOAT);
607 srcDepthTexture = srcTexture.copy(format);
610 if (tcu::hasStencilComponent(srcTexture.getTextureFormat().order))
611 srcStencilTexture = srcTexture.copy(tcu::getEffectiveDepthStencilTextureFormat(srcTexture.getTextureFormat(), tcu::Sampler::MODE_STENCIL));
613 uploadTestTextureInternal(vk, device, queue, queueFamilyIndex, allocator, *srcDepthTexture, srcStencilTexture.get(), srcTexture.getTextureFormat(), destImage);
616 uploadTestTextureInternal(vk, device, queue, queueFamilyIndex, allocator, srcTexture, DE_NULL, srcTexture.getTextureFormat(), destImage);
619 // Utilities for test textures
621 template<typename TcuTextureType>
622 void allocateLevels (TcuTextureType& texture)
624 for (int levelNdx = 0; levelNdx < texture.getNumLevels(); levelNdx++)
625 texture.allocLevel(levelNdx);
628 template<typename TcuTextureType>
629 std::vector<tcu::PixelBufferAccess> getLevelsVector (const TcuTextureType& texture)
631 std::vector<tcu::PixelBufferAccess> levels(texture.getNumLevels());
633 for (int levelNdx = 0; levelNdx < texture.getNumLevels(); levelNdx++)
634 levels[levelNdx] = *reinterpret_cast<const tcu::PixelBufferAccess*>(&texture.getLevel(levelNdx));
641 TestTexture::TestTexture (const tcu::TextureFormat& format, int width, int height, int depth)
643 DE_ASSERT(width >= 1);
644 DE_ASSERT(height >= 1);
645 DE_ASSERT(depth >= 1);
653 TestTexture::TestTexture (const tcu::CompressedTexFormat& format, int width, int height, int depth)
655 DE_ASSERT(width >= 1);
656 DE_ASSERT(height >= 1);
657 DE_ASSERT(depth >= 1);
665 TestTexture::~TestTexture (void)
667 for (size_t levelNdx = 0; levelNdx < m_compressedLevels.size(); levelNdx++)
668 delete m_compressedLevels[levelNdx];
671 deUint32 TestTexture::getSize (void) const
673 std::vector<deUint32> offsetMultiples;
674 deUint32 textureSize = 0;
676 offsetMultiples.push_back(4);
677 offsetMultiples.push_back(getLevel(0, 0).getFormat().getPixelSize());
679 for (int levelNdx = 0; levelNdx < getNumLevels(); levelNdx++)
681 for (int layerNdx = 0; layerNdx < getArraySize(); layerNdx++)
683 const tcu::ConstPixelBufferAccess level = getLevel(levelNdx, layerNdx);
684 textureSize = getNextMultiple(offsetMultiples, textureSize);
685 textureSize += level.getWidth() * level.getHeight() * level.getDepth() * level.getFormat().getPixelSize();
692 deUint32 TestTexture::getCompressedSize (void) const
695 throw tcu::InternalError("Texture is not compressed");
697 std::vector<deUint32> offsetMultiples;
698 deUint32 textureSize = 0;
700 offsetMultiples.push_back(4);
701 offsetMultiples.push_back(tcu::getBlockSize(getCompressedLevel(0, 0).getFormat()));
703 for (int levelNdx = 0; levelNdx < getNumLevels(); levelNdx++)
705 for (int layerNdx = 0; layerNdx < getArraySize(); layerNdx++)
707 textureSize = getNextMultiple(offsetMultiples, textureSize);
708 textureSize += getCompressedLevel(levelNdx, layerNdx).getDataSize();
715 tcu::CompressedTexture& TestTexture::getCompressedLevel (int level, int layer)
717 DE_ASSERT(level >= 0 && level < getNumLevels());
718 DE_ASSERT(layer >= 0 && layer < getArraySize());
720 return *m_compressedLevels[level * getArraySize() + layer];
723 const tcu::CompressedTexture& TestTexture::getCompressedLevel (int level, int layer) const
725 DE_ASSERT(level >= 0 && level < getNumLevels());
726 DE_ASSERT(layer >= 0 && layer < getArraySize());
728 return *m_compressedLevels[level * getArraySize() + layer];
731 std::vector<VkBufferImageCopy> TestTexture::getBufferCopyRegions (void) const
733 std::vector<deUint32> offsetMultiples;
734 std::vector<VkBufferImageCopy> regions;
735 deUint32 layerDataOffset = 0;
737 offsetMultiples.push_back(4);
741 offsetMultiples.push_back(tcu::getBlockSize(getCompressedLevel(0, 0).getFormat()));
743 for (int levelNdx = 0; levelNdx < getNumLevels(); levelNdx++)
745 for (int layerNdx = 0; layerNdx < getArraySize(); layerNdx++)
747 const tcu::CompressedTexture& level = getCompressedLevel(levelNdx, layerNdx);
748 tcu::IVec3 blockPixelSize = getBlockPixelSize(level.getFormat());
749 layerDataOffset = getNextMultiple(offsetMultiples, layerDataOffset);
751 const VkBufferImageCopy layerRegion =
753 layerDataOffset, // VkDeviceSize bufferOffset;
754 (deUint32)getNextMultiple(blockPixelSize.x(), level.getWidth()), // deUint32 bufferRowLength;
755 (deUint32)getNextMultiple(blockPixelSize.y(), level.getHeight()), // deUint32 bufferImageHeight;
756 { // VkImageSubresourceLayers imageSubresource;
757 VK_IMAGE_ASPECT_COLOR_BIT,
762 { 0u, 0u, 0u }, // VkOffset3D imageOffset;
763 { // VkExtent3D imageExtent;
764 (deUint32)level.getWidth(),
765 (deUint32)level.getHeight(),
766 (deUint32)level.getDepth()
770 regions.push_back(layerRegion);
771 layerDataOffset += level.getDataSize();
777 std::vector<VkImageAspectFlags> imageAspects;
778 tcu::TextureFormat textureFormat = getTextureFormat();
780 if (tcu::hasDepthComponent(textureFormat.order))
781 imageAspects.push_back(VK_IMAGE_ASPECT_DEPTH_BIT);
783 if (tcu::hasStencilComponent(textureFormat.order))
784 imageAspects.push_back(VK_IMAGE_ASPECT_STENCIL_BIT);
786 if (imageAspects.empty())
787 imageAspects.push_back(VK_IMAGE_ASPECT_COLOR_BIT);
789 offsetMultiples.push_back(getLevel(0, 0).getFormat().getPixelSize());
791 for (int levelNdx = 0; levelNdx < getNumLevels(); levelNdx++)
793 for (int layerNdx = 0; layerNdx < getArraySize(); layerNdx++)
795 const tcu::ConstPixelBufferAccess level = getLevel(levelNdx, layerNdx);
797 layerDataOffset = getNextMultiple(offsetMultiples, layerDataOffset);
799 for (size_t aspectIndex = 0; aspectIndex < imageAspects.size(); ++aspectIndex)
801 const VkBufferImageCopy layerRegion =
803 layerDataOffset, // VkDeviceSize bufferOffset;
804 (deUint32)level.getWidth(), // deUint32 bufferRowLength;
805 (deUint32)level.getHeight(), // deUint32 bufferImageHeight;
806 { // VkImageSubresourceLayers imageSubresource;
807 imageAspects[aspectIndex],
812 { 0u, 0u, 0u }, // VkOffset3D imageOffset;
813 { // VkExtent3D imageExtent;
814 (deUint32)level.getWidth(),
815 (deUint32)level.getHeight(),
816 (deUint32)level.getDepth()
820 regions.push_back(layerRegion);
822 layerDataOffset += level.getWidth() * level.getHeight() * level.getDepth() * level.getFormat().getPixelSize();
830 void TestTexture::write (deUint8* destPtr) const
832 std::vector<deUint32> offsetMultiples;
833 deUint32 levelOffset = 0;
835 offsetMultiples.push_back(4);
839 offsetMultiples.push_back(tcu::getBlockSize(getCompressedLevel(0, 0).getFormat()));
841 for (int levelNdx = 0; levelNdx < getNumLevels(); levelNdx++)
843 for (int layerNdx = 0; layerNdx < getArraySize(); layerNdx++)
845 levelOffset = getNextMultiple(offsetMultiples, levelOffset);
847 const tcu::CompressedTexture& compressedTex = getCompressedLevel(levelNdx, layerNdx);
849 deMemcpy(destPtr + levelOffset, compressedTex.getData(), compressedTex.getDataSize());
850 levelOffset += compressedTex.getDataSize();
856 offsetMultiples.push_back(getLevel(0, 0).getFormat().getPixelSize());
858 for (int levelNdx = 0; levelNdx < getNumLevels(); levelNdx++)
860 for (int layerNdx = 0; layerNdx < getArraySize(); layerNdx++)
862 levelOffset = getNextMultiple(offsetMultiples, levelOffset);
864 const tcu::ConstPixelBufferAccess srcAccess = getLevel(levelNdx, layerNdx);
865 const tcu::PixelBufferAccess destAccess (srcAccess.getFormat(), srcAccess.getSize(), srcAccess.getPitch(), destPtr + levelOffset);
867 tcu::copy(destAccess, srcAccess);
868 levelOffset += srcAccess.getWidth() * srcAccess.getHeight() * srcAccess.getDepth() * srcAccess.getFormat().getPixelSize();
874 void TestTexture::copyToTexture (TestTexture& destTexture) const
876 for (int levelNdx = 0; levelNdx < getNumLevels(); levelNdx++)
877 for (int layerNdx = 0; layerNdx < getArraySize(); layerNdx++)
878 tcu::copy(destTexture.getLevel(levelNdx, layerNdx), getLevel(levelNdx, layerNdx));
881 void TestTexture::populateLevels (const std::vector<tcu::PixelBufferAccess>& levels)
883 for (size_t levelNdx = 0; levelNdx < levels.size(); levelNdx++)
884 TestTexture::fillWithGradient(levels[levelNdx]);
887 void TestTexture::populateCompressedLevels (tcu::CompressedTexFormat format, const std::vector<tcu::PixelBufferAccess>& decompressedLevels)
889 // Generate random compressed data and update decompressed data
891 de::Random random(123);
893 for (size_t levelNdx = 0; levelNdx < decompressedLevels.size(); levelNdx++)
895 const tcu::PixelBufferAccess level = decompressedLevels[levelNdx];
896 tcu::CompressedTexture* compressedLevel = new tcu::CompressedTexture(format, level.getWidth(), level.getHeight(), level.getDepth());
897 deUint8* const compressedData = (deUint8*)compressedLevel->getData();
899 if (tcu::isAstcFormat(format))
901 // \todo [2016-01-20 pyry] Comparison doesn't currently handle invalid blocks correctly so we use only valid blocks
902 tcu::astc::generateRandomValidBlocks(compressedData, compressedLevel->getDataSize()/tcu::astc::BLOCK_SIZE_BYTES,
903 format, tcu::TexDecompressionParams::ASTCMODE_LDR, random.getUint32());
907 // Generate random compressed data
908 // Random initial values cause assertion during the decompression in case of COMPRESSEDTEXFORMAT_ETC1_RGB8 format
909 if (format != tcu::COMPRESSEDTEXFORMAT_ETC1_RGB8)
910 for (int byteNdx = 0; byteNdx < compressedLevel->getDataSize(); byteNdx++)
911 compressedData[byteNdx] = 0xFF & random.getUint32();
914 m_compressedLevels.push_back(compressedLevel);
916 // Store decompressed data
917 compressedLevel->decompress(level, tcu::TexDecompressionParams(tcu::TexDecompressionParams::ASTCMODE_LDR));
921 void TestTexture::fillWithGradient (const tcu::PixelBufferAccess& levelAccess)
923 const tcu::TextureFormatInfo formatInfo = tcu::getTextureFormatInfo(levelAccess.getFormat());
924 tcu::fillWithComponentGradients(levelAccess, formatInfo.valueMin, formatInfo.valueMax);
929 TestTexture1D::TestTexture1D (const tcu::TextureFormat& format, int width)
930 : TestTexture (format, width, 1, 1)
931 , m_texture (format, width)
933 allocateLevels(m_texture);
934 TestTexture::populateLevels(getLevelsVector(m_texture));
937 TestTexture1D::TestTexture1D (const tcu::CompressedTexFormat& format, int width)
938 : TestTexture (format, width, 1, 1)
939 , m_texture (tcu::getUncompressedFormat(format), width)
941 allocateLevels(m_texture);
942 TestTexture::populateCompressedLevels(format, getLevelsVector(m_texture));
945 TestTexture1D::~TestTexture1D (void)
949 int TestTexture1D::getNumLevels (void) const
951 return m_texture.getNumLevels();
954 tcu::PixelBufferAccess TestTexture1D::getLevel (int level, int layer)
956 DE_ASSERT(layer == 0);
958 return m_texture.getLevel(level);
961 const tcu::ConstPixelBufferAccess TestTexture1D::getLevel (int level, int layer) const
963 DE_ASSERT(layer == 0);
965 return m_texture.getLevel(level);
968 const tcu::Texture1D& TestTexture1D::getTexture (void) const
973 tcu::Texture1D& TestTexture1D::getTexture (void)
978 de::MovePtr<TestTexture> TestTexture1D::copy(const tcu::TextureFormat format) const
980 DE_ASSERT(!isCompressed());
982 de::MovePtr<TestTexture> texture (new TestTexture1D(format, m_texture.getWidth()));
984 copyToTexture(*texture);
989 // TestTexture1DArray
991 TestTexture1DArray::TestTexture1DArray (const tcu::TextureFormat& format, int width, int arraySize)
992 : TestTexture (format, width, 1, arraySize)
993 , m_texture (format, width, arraySize)
995 allocateLevels(m_texture);
996 TestTexture::populateLevels(getLevelsVector(m_texture));
999 TestTexture1DArray::TestTexture1DArray (const tcu::CompressedTexFormat& format, int width, int arraySize)
1000 : TestTexture (format, width, 1, arraySize)
1001 , m_texture (tcu::getUncompressedFormat(format), width, arraySize)
1003 allocateLevels(m_texture);
1005 std::vector<tcu::PixelBufferAccess> layers;
1006 for (int levelNdx = 0; levelNdx < m_texture.getNumLevels(); levelNdx++)
1007 for (int layerNdx = 0; layerNdx < m_texture.getNumLayers(); layerNdx++)
1008 layers.push_back(getLevel(levelNdx, layerNdx));
1010 TestTexture::populateCompressedLevels(format, layers);
1013 TestTexture1DArray::~TestTexture1DArray (void)
1017 int TestTexture1DArray::getNumLevels (void) const
1019 return m_texture.getNumLevels();
1022 tcu::PixelBufferAccess TestTexture1DArray::getLevel (int level, int layer)
1024 const tcu::PixelBufferAccess levelLayers = m_texture.getLevel(level);
1025 const deUint32 layerSize = levelLayers.getWidth() * levelLayers.getFormat().getPixelSize();
1026 const deUint32 layerOffset = layerSize * layer;
1028 return tcu::PixelBufferAccess(levelLayers.getFormat(), levelLayers.getWidth(), 1, 1, (deUint8*)levelLayers.getDataPtr() + layerOffset);
1031 const tcu::ConstPixelBufferAccess TestTexture1DArray::getLevel (int level, int layer) const
1033 const tcu::ConstPixelBufferAccess levelLayers = m_texture.getLevel(level);
1034 const deUint32 layerSize = levelLayers.getWidth() * levelLayers.getFormat().getPixelSize();
1035 const deUint32 layerOffset = layerSize * layer;
1037 return tcu::ConstPixelBufferAccess(levelLayers.getFormat(), levelLayers.getWidth(), 1, 1, (deUint8*)levelLayers.getDataPtr() + layerOffset);
1040 const tcu::Texture1DArray& TestTexture1DArray::getTexture (void) const
1045 tcu::Texture1DArray& TestTexture1DArray::getTexture (void)
1050 int TestTexture1DArray::getArraySize (void) const
1052 return m_texture.getNumLayers();
1055 de::MovePtr<TestTexture> TestTexture1DArray::copy(const tcu::TextureFormat format) const
1057 DE_ASSERT(!isCompressed());
1059 de::MovePtr<TestTexture> texture (new TestTexture1DArray(format, m_texture.getWidth(), getArraySize()));
1061 copyToTexture(*texture);
1068 TestTexture2D::TestTexture2D (const tcu::TextureFormat& format, int width, int height)
1069 : TestTexture (format, width, height, 1)
1070 , m_texture (format, width, height)
1072 allocateLevels(m_texture);
1073 TestTexture::populateLevels(getLevelsVector(m_texture));
1076 TestTexture2D::TestTexture2D (const tcu::CompressedTexFormat& format, int width, int height)
1077 : TestTexture (format, width, height, 1)
1078 , m_texture (tcu::getUncompressedFormat(format), width, height)
1080 allocateLevels(m_texture);
1081 TestTexture::populateCompressedLevels(format, getLevelsVector(m_texture));
1084 TestTexture2D::~TestTexture2D (void)
1088 int TestTexture2D::getNumLevels (void) const
1090 return m_texture.getNumLevels();
1093 tcu::PixelBufferAccess TestTexture2D::getLevel (int level, int layer)
1095 DE_ASSERT(layer == 0);
1097 return m_texture.getLevel(level);
1100 const tcu::ConstPixelBufferAccess TestTexture2D::getLevel (int level, int layer) const
1102 DE_ASSERT(layer == 0);
1104 return m_texture.getLevel(level);
1107 const tcu::Texture2D& TestTexture2D::getTexture (void) const
1112 tcu::Texture2D& TestTexture2D::getTexture (void)
1117 de::MovePtr<TestTexture> TestTexture2D::copy(const tcu::TextureFormat format) const
1119 DE_ASSERT(!isCompressed());
1121 de::MovePtr<TestTexture> texture (new TestTexture2D(format, m_texture.getWidth(), m_texture.getHeight()));
1123 copyToTexture(*texture);
1128 // TestTexture2DArray
1130 TestTexture2DArray::TestTexture2DArray (const tcu::TextureFormat& format, int width, int height, int arraySize)
1131 : TestTexture (format, width, height, arraySize)
1132 , m_texture (format, width, height, arraySize)
1134 allocateLevels(m_texture);
1135 TestTexture::populateLevels(getLevelsVector(m_texture));
1138 TestTexture2DArray::TestTexture2DArray (const tcu::CompressedTexFormat& format, int width, int height, int arraySize)
1139 : TestTexture (format, width, height, arraySize)
1140 , m_texture (tcu::getUncompressedFormat(format), width, height, arraySize)
1142 allocateLevels(m_texture);
1144 std::vector<tcu::PixelBufferAccess> layers;
1145 for (int levelNdx = 0; levelNdx < m_texture.getNumLevels(); levelNdx++)
1146 for (int layerNdx = 0; layerNdx < m_texture.getNumLayers(); layerNdx++)
1147 layers.push_back(getLevel(levelNdx, layerNdx));
1149 TestTexture::populateCompressedLevels(format, layers);
1152 TestTexture2DArray::~TestTexture2DArray (void)
1156 int TestTexture2DArray::getNumLevels (void) const
1158 return m_texture.getNumLevels();
1161 tcu::PixelBufferAccess TestTexture2DArray::getLevel (int level, int layer)
1163 const tcu::PixelBufferAccess levelLayers = m_texture.getLevel(level);
1164 const deUint32 layerSize = levelLayers.getWidth() * levelLayers.getHeight() * levelLayers.getFormat().getPixelSize();
1165 const deUint32 layerOffset = layerSize * layer;
1167 return tcu::PixelBufferAccess(levelLayers.getFormat(), levelLayers.getWidth(), levelLayers.getHeight(), 1, (deUint8*)levelLayers.getDataPtr() + layerOffset);
1170 const tcu::ConstPixelBufferAccess TestTexture2DArray::getLevel (int level, int layer) const
1172 const tcu::ConstPixelBufferAccess levelLayers = m_texture.getLevel(level);
1173 const deUint32 layerSize = levelLayers.getWidth() * levelLayers.getHeight() * levelLayers.getFormat().getPixelSize();
1174 const deUint32 layerOffset = layerSize * layer;
1176 return tcu::ConstPixelBufferAccess(levelLayers.getFormat(), levelLayers.getWidth(), levelLayers.getHeight(), 1, (deUint8*)levelLayers.getDataPtr() + layerOffset);
1179 const tcu::Texture2DArray& TestTexture2DArray::getTexture (void) const
1184 tcu::Texture2DArray& TestTexture2DArray::getTexture (void)
1189 int TestTexture2DArray::getArraySize (void) const
1191 return m_texture.getNumLayers();
1194 de::MovePtr<TestTexture> TestTexture2DArray::copy(const tcu::TextureFormat format) const
1196 DE_ASSERT(!isCompressed());
1198 de::MovePtr<TestTexture> texture (new TestTexture2DArray(format, m_texture.getWidth(), m_texture.getHeight(), getArraySize()));
1200 copyToTexture(*texture);
1207 TestTexture3D::TestTexture3D (const tcu::TextureFormat& format, int width, int height, int depth)
1208 : TestTexture (format, width, height, depth)
1209 , m_texture (format, width, height, depth)
1211 allocateLevels(m_texture);
1212 TestTexture::populateLevels(getLevelsVector(m_texture));
1215 TestTexture3D::TestTexture3D (const tcu::CompressedTexFormat& format, int width, int height, int depth)
1216 : TestTexture (format, width, height, depth)
1217 , m_texture (tcu::getUncompressedFormat(format), width, height, depth)
1219 allocateLevels(m_texture);
1220 TestTexture::populateCompressedLevels(format, getLevelsVector(m_texture));
1223 TestTexture3D::~TestTexture3D (void)
1227 int TestTexture3D::getNumLevels (void) const
1229 return m_texture.getNumLevels();
1232 tcu::PixelBufferAccess TestTexture3D::getLevel (int level, int layer)
1234 DE_ASSERT(layer == 0);
1236 return m_texture.getLevel(level);
1239 const tcu::ConstPixelBufferAccess TestTexture3D::getLevel (int level, int layer) const
1241 DE_ASSERT(layer == 0);
1243 return m_texture.getLevel(level);
1246 const tcu::Texture3D& TestTexture3D::getTexture (void) const
1251 tcu::Texture3D& TestTexture3D::getTexture (void)
1256 de::MovePtr<TestTexture> TestTexture3D::copy(const tcu::TextureFormat format) const
1258 DE_ASSERT(!isCompressed());
1260 de::MovePtr<TestTexture> texture (new TestTexture3D(format, m_texture.getWidth(), m_texture.getHeight(), m_texture.getDepth()));
1262 copyToTexture(*texture);
1269 const static tcu::CubeFace tcuFaceMapping[tcu::CUBEFACE_LAST] =
1271 tcu::CUBEFACE_POSITIVE_X,
1272 tcu::CUBEFACE_NEGATIVE_X,
1273 tcu::CUBEFACE_POSITIVE_Y,
1274 tcu::CUBEFACE_NEGATIVE_Y,
1275 tcu::CUBEFACE_POSITIVE_Z,
1276 tcu::CUBEFACE_NEGATIVE_Z
1279 TestTextureCube::TestTextureCube (const tcu::TextureFormat& format, int size)
1280 : TestTexture (format, size, size, 1)
1281 , m_texture (format, size)
1283 for (int levelNdx = 0; levelNdx < getNumLevels(); levelNdx++)
1285 for (int faceNdx = 0; faceNdx < tcu::CUBEFACE_LAST; faceNdx++)
1287 m_texture.allocLevel(tcuFaceMapping[faceNdx], levelNdx);
1288 TestTexture::fillWithGradient(m_texture.getLevelFace(levelNdx, tcuFaceMapping[faceNdx]));
1293 TestTextureCube::TestTextureCube (const tcu::CompressedTexFormat& format, int size)
1294 : TestTexture (format, size, size, 1)
1295 , m_texture (tcu::getUncompressedFormat(format), size)
1297 std::vector<tcu::PixelBufferAccess> levels(m_texture.getNumLevels() * tcu::CUBEFACE_LAST);
1299 for (int levelNdx = 0; levelNdx < getNumLevels(); levelNdx++)
1301 for (int faceNdx = 0; faceNdx < tcu::CUBEFACE_LAST; faceNdx++)
1303 m_texture.allocLevel(tcuFaceMapping[faceNdx], levelNdx);
1304 levels[levelNdx * tcu::CUBEFACE_LAST + faceNdx] = m_texture.getLevelFace(levelNdx, tcuFaceMapping[faceNdx]);
1308 TestTexture::populateCompressedLevels(format, levels);
1311 TestTextureCube::~TestTextureCube (void)
1315 int TestTextureCube::getNumLevels (void) const
1317 return m_texture.getNumLevels();
1320 tcu::PixelBufferAccess TestTextureCube::getLevel (int level, int layer)
1322 return m_texture.getLevelFace(level, tcuFaceMapping[layer]);
1325 const tcu::ConstPixelBufferAccess TestTextureCube::getLevel (int level, int layer) const
1327 return m_texture.getLevelFace(level, tcuFaceMapping[layer]);
1330 int TestTextureCube::getArraySize (void) const
1332 return (int)tcu::CUBEFACE_LAST;
1335 const tcu::TextureCube& TestTextureCube::getTexture (void) const
1340 tcu::TextureCube& TestTextureCube::getTexture (void)
1345 de::MovePtr<TestTexture> TestTextureCube::copy(const tcu::TextureFormat format) const
1347 DE_ASSERT(!isCompressed());
1349 de::MovePtr<TestTexture> texture (new TestTextureCube(format, m_texture.getSize()));
1351 copyToTexture(*texture);
1356 // TestTextureCubeArray
1358 TestTextureCubeArray::TestTextureCubeArray (const tcu::TextureFormat& format, int size, int arraySize)
1359 : TestTexture (format, size, size, arraySize)
1360 , m_texture (format, size, arraySize)
1362 allocateLevels(m_texture);
1363 TestTexture::populateLevels(getLevelsVector(m_texture));
1366 TestTextureCubeArray::TestTextureCubeArray (const tcu::CompressedTexFormat& format, int size, int arraySize)
1367 : TestTexture (format, size, size, arraySize)
1368 , m_texture (tcu::getUncompressedFormat(format), size, arraySize)
1370 DE_ASSERT(arraySize % 6 == 0);
1372 allocateLevels(m_texture);
1374 std::vector<tcu::PixelBufferAccess> layers;
1375 for (int levelNdx = 0; levelNdx < m_texture.getNumLevels(); levelNdx++)
1376 for (int layerNdx = 0; layerNdx < m_texture.getDepth(); layerNdx++)
1377 layers.push_back(getLevel(levelNdx, layerNdx));
1379 TestTexture::populateCompressedLevels(format, layers);
1382 TestTextureCubeArray::~TestTextureCubeArray (void)
1386 int TestTextureCubeArray::getNumLevels (void) const
1388 return m_texture.getNumLevels();
1391 tcu::PixelBufferAccess TestTextureCubeArray::getLevel (int level, int layer)
1393 const tcu::PixelBufferAccess levelLayers = m_texture.getLevel(level);
1394 const deUint32 layerSize = levelLayers.getWidth() * levelLayers.getHeight() * levelLayers.getFormat().getPixelSize();
1395 const deUint32 layerOffset = layerSize * layer;
1397 return tcu::PixelBufferAccess(levelLayers.getFormat(), levelLayers.getWidth(), levelLayers.getHeight(), 1, (deUint8*)levelLayers.getDataPtr() + layerOffset);
1400 const tcu::ConstPixelBufferAccess TestTextureCubeArray::getLevel (int level, int layer) const
1402 const tcu::ConstPixelBufferAccess levelLayers = m_texture.getLevel(level);
1403 const deUint32 layerSize = levelLayers.getWidth() * levelLayers.getHeight() * levelLayers.getFormat().getPixelSize();
1404 const deUint32 layerOffset = layerSize * layer;
1406 return tcu::ConstPixelBufferAccess(levelLayers.getFormat(), levelLayers.getWidth(), levelLayers.getHeight(), 1, (deUint8*)levelLayers.getDataPtr() + layerOffset);
1409 int TestTextureCubeArray::getArraySize (void) const
1411 return m_texture.getDepth();
1414 const tcu::TextureCubeArray& TestTextureCubeArray::getTexture (void) const
1419 tcu::TextureCubeArray& TestTextureCubeArray::getTexture (void)
1424 de::MovePtr<TestTexture> TestTextureCubeArray::copy(const tcu::TextureFormat format) const
1426 DE_ASSERT(!isCompressed());
1428 de::MovePtr<TestTexture> texture (new TestTextureCubeArray(format, m_texture.getSize(), getArraySize()));
1430 copyToTexture(*texture);