1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2017 Google Inc.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Tests sparse render target.
22 *//*--------------------------------------------------------------------*/
24 #include "vktRenderPassSparseRenderTargetTests.hpp"
26 #include "vktTestCaseUtil.hpp"
27 #include "vktTestGroupUtil.hpp"
28 #include "pipeline/vktPipelineImageUtil.hpp"
31 #include "vkImageUtil.hpp"
32 #include "vkMemUtil.hpp"
33 #include "vkPrograms.hpp"
34 #include "vkQueryUtil.hpp"
36 #include "vkRefUtil.hpp"
37 #include "vkTypeUtil.hpp"
39 #include "tcuImageCompare.hpp"
40 #include "tcuResultCollector.hpp"
41 #include "tcuTextureUtil.hpp"
43 #include "deUniquePtr.hpp"
44 #include "deSharedPtr.hpp"
51 using tcu::ConstPixelBufferAccess;
52 using tcu::PixelBufferAccess;
64 deUint32 findQueueFamilyIndexWithCaps (const InstanceInterface& vkInstance, VkPhysicalDevice physicalDevice, VkQueueFlags requiredCaps)
66 const std::vector<VkQueueFamilyProperties> queueProps = getPhysicalDeviceQueueFamilyProperties(vkInstance, physicalDevice);
68 for (size_t queueNdx = 0; queueNdx < queueProps.size(); queueNdx++)
70 if ((queueProps[queueNdx].queueFlags & requiredCaps) == requiredCaps)
71 return (deUint32)queueNdx;
74 TCU_THROW(NotSupportedError, "No matching queue found");
77 Move<VkDevice> createDevice(const InstanceInterface& vkInstance, VkPhysicalDevice physicalDevice, deUint32 queueFamilyIndex)
79 const VkPhysicalDeviceFeatures deviceFeatures = getPhysicalDeviceFeatures(vkInstance, physicalDevice);
81 VkDeviceQueueCreateInfo queueInfo;
82 VkDeviceCreateInfo deviceInfo;
83 const float queuePriority = 1.0f;
85 deMemset(&queueInfo, 0, sizeof(queueInfo));
86 deMemset(&deviceInfo, 0, sizeof(deviceInfo));
88 queueInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
89 queueInfo.pNext = DE_NULL;
90 queueInfo.flags = (VkDeviceQueueCreateFlags)0u;
91 queueInfo.queueFamilyIndex = queueFamilyIndex;
92 queueInfo.queueCount = 1u;
93 queueInfo.pQueuePriorities = &queuePriority;
95 deviceInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
96 deviceInfo.pNext = DE_NULL;
97 deviceInfo.queueCreateInfoCount = 1u;
98 deviceInfo.pQueueCreateInfos = &queueInfo;
99 deviceInfo.enabledExtensionCount = 0u;
100 deviceInfo.ppEnabledExtensionNames = DE_NULL;
101 deviceInfo.enabledLayerCount = 0u;
102 deviceInfo.ppEnabledLayerNames = DE_NULL;
103 deviceInfo.pEnabledFeatures = &deviceFeatures;
105 if (!deviceFeatures.sparseBinding)
106 TCU_THROW(NotSupportedError, "Sparse binding not supported");
108 return createDevice(vkInstance, physicalDevice, &deviceInfo);
111 de::MovePtr<Allocation> createBufferMemory (const DeviceInterface& vk,
113 Allocator& allocator,
116 de::MovePtr<Allocation> allocation (allocator.allocate(getBufferMemoryRequirements(vk, device, buffer), MemoryRequirement::HostVisible));
117 VK_CHECK(vk.bindBufferMemory(device, buffer, allocation->getMemory(), allocation->getOffset()));
121 Move<VkImage> createSparseImageAndMemory (const DeviceInterface& vk,
123 const VkPhysicalDevice physicalDevice,
124 const InstanceInterface& instance,
125 Allocator& allocator,
126 vector<de::SharedPtr<Allocation> >& allocations,
127 deUint32 queueFamilyIndex,
129 const VkSemaphore& bindSemaphore,
134 const VkExtent3D imageExtent =
141 const VkImageCreateInfo imageCreateInfo =
143 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
145 VK_IMAGE_CREATE_SPARSE_BINDING_BIT | VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT,
151 VK_SAMPLE_COUNT_1_BIT,
152 VK_IMAGE_TILING_OPTIMAL,
153 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
154 VK_SHARING_MODE_EXCLUSIVE,
157 VK_IMAGE_LAYOUT_UNDEFINED
160 Move<VkImage> destImage = createImage(vk, device, &imageCreateInfo);
162 vkt::pipeline::allocateAndBindSparseImage(vk, device, physicalDevice, instance, imageCreateInfo, bindSemaphore, queue, allocator, allocations, mapVkFormat(format), *destImage);
167 Move<VkImageView> createImageView (const DeviceInterface& vk,
169 VkImageViewCreateFlags flags,
171 VkImageViewType viewType,
173 VkComponentMapping components,
174 VkImageSubresourceRange subresourceRange)
176 const VkImageViewCreateInfo pCreateInfo =
178 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
188 return createImageView(vk, device, &pCreateInfo);
191 Move<VkImageView> createImageView (const DeviceInterface& vkd,
195 VkImageAspectFlags aspect)
197 const VkImageSubresourceRange range =
206 return createImageView(vkd, device, 0u, image, VK_IMAGE_VIEW_TYPE_2D, format, makeComponentMappingRGBA(), range);
209 Move<VkBuffer> createBuffer (const DeviceInterface& vkd,
215 const VkBufferUsageFlags bufferUsage (VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT);
216 const VkDeviceSize pixelSize = mapVkFormat(format).getPixelSize();
217 const VkBufferCreateInfo createInfo =
219 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
223 width * height * pixelSize,
226 VK_SHARING_MODE_EXCLUSIVE,
231 return createBuffer(vkd, device, &createInfo);
234 Move<VkRenderPass> createRenderPass (const DeviceInterface& vkd,
238 const VkAttachmentReference dstAttachmentRef =
241 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
243 const VkAttachmentDescription dstAttachment =
248 VK_SAMPLE_COUNT_1_BIT,
250 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
251 VK_ATTACHMENT_STORE_OP_STORE,
253 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
254 VK_ATTACHMENT_STORE_OP_DONT_CARE,
256 VK_IMAGE_LAYOUT_UNDEFINED,
257 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
259 const VkSubpassDescription subpasses[] =
262 (VkSubpassDescriptionFlags)0,
263 VK_PIPELINE_BIND_POINT_GRAPHICS,
277 const VkRenderPassCreateInfo createInfo =
279 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
281 (VkRenderPassCreateFlags)0u,
293 return createRenderPass(vkd, device, &createInfo);
296 Move<VkFramebuffer> createFramebuffer (const DeviceInterface& vkd,
298 VkRenderPass renderPass,
299 VkImageView dstImageView,
303 const VkFramebufferCreateInfo createInfo =
305 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
318 return createFramebuffer(vkd, device, &createInfo);
321 Move<VkPipelineLayout> createRenderPipelineLayout (const DeviceInterface& vkd,
324 const VkPipelineLayoutCreateInfo createInfo =
326 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
328 (vk::VkPipelineLayoutCreateFlags)0,
337 return createPipelineLayout(vkd, device, &createInfo);
340 Move<VkPipeline> createRenderPipeline (const DeviceInterface& vkd,
342 VkRenderPass renderPass,
343 VkPipelineLayout pipelineLayout,
344 const vk::ProgramCollection<vk::ProgramBinary>& binaryCollection,
348 const Unique<VkShaderModule> vertexShaderModule (createShaderModule(vkd, device, binaryCollection.get("quad-vert"), 0u));
349 const Unique<VkShaderModule> fragmentShaderModule (createShaderModule(vkd, device, binaryCollection.get("quad-frag"), 0u));
350 const VkSpecializationInfo emptyShaderSpecializations =
359 const VkPipelineColorBlendAttachmentState attachmentBlendState =
362 VK_BLEND_FACTOR_SRC_ALPHA,
363 VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
368 VK_COLOR_COMPONENT_R_BIT|VK_COLOR_COMPONENT_G_BIT|VK_COLOR_COMPONENT_B_BIT|VK_COLOR_COMPONENT_A_BIT
370 const VkPipelineShaderStageCreateInfo shaderStages[2] =
373 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
375 (VkPipelineShaderStageCreateFlags)0u,
376 VK_SHADER_STAGE_VERTEX_BIT,
379 &emptyShaderSpecializations
382 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
384 (VkPipelineShaderStageCreateFlags)0u,
385 VK_SHADER_STAGE_FRAGMENT_BIT,
386 *fragmentShaderModule,
388 &emptyShaderSpecializations
391 const VkPipelineVertexInputStateCreateInfo vertexInputState =
393 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
395 (VkPipelineVertexInputStateCreateFlags)0u,
403 const VkPipelineInputAssemblyStateCreateInfo inputAssemblyState =
405 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
408 (VkPipelineInputAssemblyStateCreateFlags)0u,
409 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
412 const VkViewport viewport =
415 (float)width, (float)height,
419 const VkRect2D scissor =
424 const VkPipelineViewportStateCreateInfo viewportState =
426 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
428 (VkPipelineViewportStateCreateFlags)0u,
436 const VkPipelineRasterizationStateCreateInfo rasterState =
438 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
440 (VkPipelineRasterizationStateCreateFlags)0u,
443 VK_POLYGON_MODE_FILL,
445 VK_FRONT_FACE_COUNTER_CLOCKWISE,
452 const VkPipelineMultisampleStateCreateInfo multisampleState =
454 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
456 (VkPipelineMultisampleStateCreateFlags)0u,
458 VK_SAMPLE_COUNT_1_BIT,
465 const VkPipelineColorBlendStateCreateInfo blendState =
467 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
469 (VkPipelineColorBlendStateCreateFlags)0u,
474 &attachmentBlendState,
475 { 0.0f, 0.0f, 0.0f, 0.0f }
477 const VkGraphicsPipelineCreateInfo createInfo =
479 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
481 (VkPipelineCreateFlags)0u,
494 (const VkPipelineDynamicStateCreateInfo*)DE_NULL,
503 return createGraphicsPipeline(vkd, device, DE_NULL, &createInfo);
506 class SparseRenderTargetTestInstance : public TestInstance
509 SparseRenderTargetTestInstance (Context& context, VkFormat format);
510 ~SparseRenderTargetTestInstance (void);
512 tcu::TestStatus iterate (void);
515 const deUint32 m_width;
516 const deUint32 m_height;
517 const VkFormat m_format;
519 deUint32 m_queueFamilyIndex;
520 const Unique<VkDevice> m_device;
523 SimpleAllocator m_allocator;
524 vector<de::SharedPtr<Allocation> > m_allocations;
526 const Unique<VkSemaphore> m_bindSemaphore;
528 const Unique<VkImage> m_dstImage;
529 const Unique<VkImageView> m_dstImageView;
531 const Unique<VkBuffer> m_dstBuffer;
532 const de::UniquePtr<Allocation> m_dstBufferMemory;
534 const Unique<VkRenderPass> m_renderPass;
535 const Unique<VkFramebuffer> m_framebuffer;
537 const Unique<VkPipelineLayout> m_renderPipelineLayout;
538 const Unique<VkPipeline> m_renderPipeline;
540 const Unique<VkCommandPool> m_commandPool;
541 tcu::ResultCollector m_resultCollector;
544 SparseRenderTargetTestInstance::SparseRenderTargetTestInstance (Context& context, VkFormat format)
545 : TestInstance (context)
549 , m_queueFamilyIndex (findQueueFamilyIndexWithCaps(context.getInstanceInterface(), context.getPhysicalDevice(), VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_SPARSE_BINDING_BIT))
550 , m_device (createDevice(context.getInstanceInterface(), context.getPhysicalDevice(), m_queueFamilyIndex))
551 , m_queue (getDeviceQueue(context.getDeviceInterface(), *m_device, m_queueFamilyIndex, 0))
552 , m_allocator (context.getDeviceInterface(), *m_device, getPhysicalDeviceMemoryProperties(context.getInstanceInterface(), context.getPhysicalDevice()))
553 , m_bindSemaphore (createSemaphore(context.getDeviceInterface(), *m_device))
554 , m_dstImage (createSparseImageAndMemory(context.getDeviceInterface(), *m_device, context.getPhysicalDevice(), context.getInstanceInterface(), m_allocator, m_allocations, m_queueFamilyIndex, m_queue, *m_bindSemaphore, m_format, m_width, m_height))
555 , m_dstImageView (createImageView(context.getDeviceInterface(), *m_device, *m_dstImage, m_format, VK_IMAGE_ASPECT_COLOR_BIT))
556 , m_dstBuffer (createBuffer(context.getDeviceInterface(), *m_device, m_format, m_width, m_height))
557 , m_dstBufferMemory (createBufferMemory(context.getDeviceInterface(), *m_device, m_allocator, *m_dstBuffer))
558 , m_renderPass (createRenderPass(context.getDeviceInterface(), *m_device, m_format))
559 , m_framebuffer (createFramebuffer(context.getDeviceInterface(), *m_device, *m_renderPass, *m_dstImageView, m_width, m_height))
560 , m_renderPipelineLayout (createRenderPipelineLayout(context.getDeviceInterface(), *m_device))
561 , m_renderPipeline (createRenderPipeline(context.getDeviceInterface(), *m_device, *m_renderPass, *m_renderPipelineLayout, context.getBinaryCollection(), m_width, m_height))
562 , m_commandPool (createCommandPool(context.getDeviceInterface(), *m_device, VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, m_queueFamilyIndex))
566 SparseRenderTargetTestInstance::~SparseRenderTargetTestInstance (void)
570 tcu::TestStatus SparseRenderTargetTestInstance::iterate (void)
572 const DeviceInterface& vkd (m_context.getDeviceInterface());
573 const Unique<VkCommandBuffer> commandBuffer (allocateCommandBuffer(vkd, *m_device, *m_commandPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
576 const VkCommandBufferBeginInfo beginInfo =
578 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
581 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
585 VK_CHECK(vkd.beginCommandBuffer(*commandBuffer, &beginInfo));
589 const VkRenderPassBeginInfo beginInfo =
591 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
599 { m_width, m_height }
605 vkd.cmdBeginRenderPass(*commandBuffer, &beginInfo, VK_SUBPASS_CONTENTS_INLINE);
608 vkd.cmdBindPipeline(*commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_renderPipeline);
609 vkd.cmdDraw(*commandBuffer, 6u, 1u, 0u, 0u);
610 vkd.cmdEndRenderPass(*commandBuffer);
612 // Memory barrier between rendering and copy
614 const VkImageMemoryBarrier barrier =
616 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
619 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
620 VK_ACCESS_TRANSFER_READ_BIT,
622 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
623 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
625 VK_QUEUE_FAMILY_IGNORED,
626 VK_QUEUE_FAMILY_IGNORED,
630 VK_IMAGE_ASPECT_COLOR_BIT,
638 vkd.cmdPipelineBarrier(*commandBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &barrier);
641 // Copy image memory to buffer
643 const VkBufferImageCopy region =
649 VK_IMAGE_ASPECT_COLOR_BIT,
655 { m_width, m_height, 1u }
658 vkd.cmdCopyImageToBuffer(*commandBuffer, *m_dstImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *m_dstBuffer, 1u, ®ion);
661 // Memory barrier between copy and host access
663 const VkBufferMemoryBarrier barrier =
665 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
668 VK_ACCESS_TRANSFER_WRITE_BIT,
669 VK_ACCESS_HOST_READ_BIT,
671 VK_QUEUE_FAMILY_IGNORED,
672 VK_QUEUE_FAMILY_IGNORED,
679 vkd.cmdPipelineBarrier(*commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, 1u, &barrier, 0u, DE_NULL);
682 VK_CHECK(vkd.endCommandBuffer(*commandBuffer));
685 const VkSubmitInfo submitInfo =
687 VK_STRUCTURE_TYPE_SUBMIT_INFO,
701 VK_CHECK(vkd.queueSubmit(m_queue, 1u, &submitInfo, (VkFence)0u));
702 VK_CHECK(vkd.queueWaitIdle(m_queue));
706 const tcu::TextureFormat format (mapVkFormat(m_format));
707 const void* const ptr (m_dstBufferMemory->getHostPtr());
708 const tcu::ConstPixelBufferAccess access (format, m_width, m_height, 1, ptr);
709 tcu::TextureLevel reference (format, m_width, m_height);
710 const tcu::TextureChannelClass channelClass (tcu::getTextureChannelClass(format.type));
712 switch (channelClass)
714 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
716 const UVec4 bits (tcu::getTextureFormatBitDepth(format).cast<deUint32>());
717 const UVec4 color (1u << (bits.x()-1), 1u << (bits.y()-2), 1u << (bits.z()-3), 0xffffffff);
719 for (deUint32 y = 0; y < m_height; y++)
720 for (deUint32 x = 0; x < m_width; x++)
722 reference.getAccess().setPixel(color, x, y);
725 if (!tcu::intThresholdCompare(m_context.getTestContext().getLog(), "", "", reference.getAccess(), access, UVec4(0u), tcu::COMPARE_LOG_ON_ERROR))
726 m_resultCollector.fail("Compare failed.");
730 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
732 const UVec4 bits (tcu::getTextureFormatBitDepth(format).cast<deUint32>());
733 const UVec4 color (1u << (bits.x()-2), 1u << (bits.y()-3), 1u << (bits.z()-4), 0xffffffff);
735 for (deUint32 y = 0; y < m_height; y++)
736 for (deUint32 x = 0; x < m_width; x++)
738 reference.getAccess().setPixel(color, x, y);
741 if (!tcu::intThresholdCompare(m_context.getTestContext().getLog(), "", "", reference.getAccess(), access, UVec4(0u), tcu::COMPARE_LOG_ON_ERROR))
742 m_resultCollector.fail("Compare failed.");
746 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
747 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
749 const tcu::TextureFormatInfo info (tcu::getTextureFormatInfo(format));
750 const Vec4 maxValue (info.valueMax);
751 const Vec4 color (maxValue.x() / 2.0f, maxValue.y() / 4.0f, maxValue.z() / 8.0f, maxValue.w());
753 for (deUint32 y = 0; y < m_height; y++)
754 for (deUint32 x = 0; x < m_width; x++)
756 if (tcu::isSRGB(format))
757 reference.getAccess().setPixel(tcu::linearToSRGB(color), x, y);
759 reference.getAccess().setPixel(color, x, y);
763 // Allow error of 4 times the minimum presentable difference
764 const Vec4 threshold (4.0f * 1.0f / ((UVec4(1u) << tcu::getTextureFormatMantissaBitDepth(format).cast<deUint32>()) - 1u).cast<float>());
766 if (!tcu::floatThresholdCompare(m_context.getTestContext().getLog(), "", "", reference.getAccess(), access, threshold, tcu::COMPARE_LOG_ON_ERROR))
767 m_resultCollector.fail("Compare failed.");
772 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
774 const Vec4 color(0.5f, 0.25f, 0.125f, 1.0f);
776 for (deUint32 y = 0; y < m_height; y++)
777 for (deUint32 x = 0; x < m_width; x++)
779 if (tcu::isSRGB(format))
780 reference.getAccess().setPixel(tcu::linearToSRGB(color), x, y);
782 reference.getAccess().setPixel(color, x, y);
786 // Convert target format ulps to float ulps and allow 64ulp differences
787 const UVec4 threshold (64u * (UVec4(1u) << (UVec4(23) - tcu::getTextureFormatMantissaBitDepth(format).cast<deUint32>())));
789 if (!tcu::floatUlpThresholdCompare(m_context.getTestContext().getLog(), "", "", reference.getAccess(), access, threshold, tcu::COMPARE_LOG_ON_ERROR))
790 m_resultCollector.fail("Compare failed.");
796 DE_FATAL("Unknown channel class");
800 return tcu::TestStatus(m_resultCollector.getResult(), m_resultCollector.getMessage());
805 void init (vk::SourceCollections& dst, VkFormat format) const
807 std::ostringstream fragmentShader;
808 const tcu::TextureFormat texFormat (mapVkFormat(format));
809 const UVec4 bits (tcu::getTextureFormatBitDepth(texFormat).cast<deUint32>());
810 const tcu::TextureChannelClass channelClass (tcu::getTextureChannelClass(texFormat.type));
812 dst.glslSources.add("quad-vert") << glu::VertexSource(
814 "out gl_PerVertex {\n"
815 "\tvec4 gl_Position;\n"
820 " gl_Position = vec4(((gl_VertexIndex + 2) / 3) % 2 == 0 ? -1.0 : 1.0,\n"
821 " ((gl_VertexIndex + 1) / 3) % 2 == 0 ? -1.0 : 1.0, 0.0, 1.0);\n"
824 switch (channelClass)
826 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
830 "layout(location = 0) out highp uvec4 o_color;\n"
833 " o_color = uvec4(" << de::toString(1u << (bits.x()-1)) << ", " << de::toString(1u << (bits.y()-2)) << ", " << de::toString(1u << (bits.z()-3)) << ", 0xffffffff);"
838 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
842 "layout(location = 0) out highp ivec4 o_color;\n"
845 " o_color = ivec4(" << de::toString(1u << (bits.x()-2)) << ", " << de::toString(1u << (bits.y()-3)) << ", " << de::toString(1u << (bits.z()-4)) << ", 0xffffffff);"
854 "layout(location = 0) out highp vec4 o_color;\n"
857 " o_color = vec4(0.5, 0.25, 0.125, 1.0);\n"
863 dst.glslSources.add("quad-frag") << glu::FragmentSource(fragmentShader.str());
867 std::string formatToName (VkFormat format)
869 const std::string formatStr = de::toString(format);
870 const std::string prefix = "VK_FORMAT_";
872 DE_ASSERT(formatStr.substr(0, prefix.length()) == prefix);
874 return de::toLower(formatStr.substr(prefix.length()));
877 void initTests (tcu::TestCaseGroup* group)
879 static const VkFormat formats[] =
881 VK_FORMAT_R5G6B5_UNORM_PACK16,
886 VK_FORMAT_R8G8_UNORM,
887 VK_FORMAT_R8G8_SNORM,
890 VK_FORMAT_R8G8B8A8_UNORM,
891 VK_FORMAT_R8G8B8A8_SNORM,
892 VK_FORMAT_R8G8B8A8_UINT,
893 VK_FORMAT_R8G8B8A8_SINT,
894 VK_FORMAT_R8G8B8A8_SRGB,
895 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
896 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
897 VK_FORMAT_A8B8G8R8_UINT_PACK32,
898 VK_FORMAT_A8B8G8R8_SINT_PACK32,
899 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
900 VK_FORMAT_B8G8R8A8_UNORM,
901 VK_FORMAT_B8G8R8A8_SRGB,
902 VK_FORMAT_A2R10G10B10_UNORM_PACK32,
903 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
904 VK_FORMAT_A2B10G10R10_UINT_PACK32,
909 VK_FORMAT_R16_SFLOAT,
910 VK_FORMAT_R16G16_UNORM,
911 VK_FORMAT_R16G16_SNORM,
912 VK_FORMAT_R16G16_UINT,
913 VK_FORMAT_R16G16_SINT,
914 VK_FORMAT_R16G16_SFLOAT,
915 VK_FORMAT_R16G16B16A16_UNORM,
916 VK_FORMAT_R16G16B16A16_SNORM,
917 VK_FORMAT_R16G16B16A16_UINT,
918 VK_FORMAT_R16G16B16A16_SINT,
919 VK_FORMAT_R16G16B16A16_SFLOAT,
922 VK_FORMAT_R32_SFLOAT,
923 VK_FORMAT_R32G32_UINT,
924 VK_FORMAT_R32G32_SINT,
925 VK_FORMAT_R32G32_SFLOAT,
926 VK_FORMAT_R32G32B32A32_UINT,
927 VK_FORMAT_R32G32B32A32_SINT,
928 VK_FORMAT_R32G32B32A32_SFLOAT
931 tcu::TestContext& testCtx (group->getTestContext());
933 for (size_t formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(formats); formatNdx++)
935 const VkFormat format (formats[formatNdx]);
936 string testName (formatToName(format));
938 group->addChild(new InstanceFactory1<SparseRenderTargetTestInstance, VkFormat, Programs>(testCtx, tcu::NODETYPE_SELF_VALIDATE, testName.c_str(), testName.c_str(), format));
944 tcu::TestCaseGroup* createRenderPassSparseRenderTargetTests (tcu::TestContext& testCtx)
946 return createTestGroup(testCtx, "sparserendertarget", "Sparse render target tests", initTests);