Fix required sample counts per spec issue 478
authorPyry Haulos <phaulos@google.com>
Tue, 11 Oct 2016 15:33:15 +0000 (08:33 -0700)
committerPyry Haulos <phaulos@google.com>
Tue, 11 Oct 2016 15:36:04 +0000 (08:36 -0700)
Affects dEQP-VK.api.info.image_format_properties.*

See CTS issue #507 and spec issue #478

Change-Id: Id08e798f1c598fe5861234778318acdc3098a3df

external/vulkancts/modules/vulkan/api/vktApiFeatureInfo.cpp

index ee49082..ff7bfb6 100644 (file)
@@ -1772,26 +1772,55 @@ VkSampleCountFlags getRequiredOptimalTilingSampleCounts (const VkPhysicalDeviceL
 {
        if (!isCompressedFormat(format))
        {
-               const tcu::TextureFormat                tcuFormat       = mapVkFormat(format);
-
-               if (usageFlags & VK_IMAGE_USAGE_STORAGE_BIT)
-                       return deviceLimits.storageImageSampleCounts;
-               else if (tcuFormat.order == tcu::TextureFormat::D)
-                       return deviceLimits.sampledImageDepthSampleCounts;
-               else if (tcuFormat.order == tcu::TextureFormat::S)
-                       return deviceLimits.sampledImageStencilSampleCounts;
-               else if (tcuFormat.order == tcu::TextureFormat::DS)
-                       return deviceLimits.sampledImageDepthSampleCounts & deviceLimits.sampledImageStencilSampleCounts;
-               else
+               const tcu::TextureFormat                tcuFormat               = mapVkFormat(format);
+               const bool                                              hasDepthComp    = (tcuFormat.order == tcu::TextureFormat::D || tcuFormat.order == tcu::TextureFormat::DS);
+               const bool                                              hasStencilComp  = (tcuFormat.order == tcu::TextureFormat::S || tcuFormat.order == tcu::TextureFormat::DS);
+               const bool                                              isColorFormat   = !hasDepthComp && !hasStencilComp;
+               VkSampleCountFlags                              sampleCounts    = ~(VkSampleCountFlags)0;
+
+               DE_ASSERT((hasDepthComp || hasStencilComp) != isColorFormat);
+
+               if ((usageFlags & VK_IMAGE_USAGE_STORAGE_BIT) != 0)
+                       sampleCounts &= deviceLimits.storageImageSampleCounts;
+
+               if ((usageFlags & VK_IMAGE_USAGE_SAMPLED_BIT) != 0)
                {
-                       const tcu::TextureChannelClass  chnClass        = tcu::getTextureChannelClass(tcuFormat.type);
+                       if (hasDepthComp)
+                               sampleCounts &= deviceLimits.sampledImageDepthSampleCounts;
 
-                       if (chnClass == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER ||
-                               chnClass == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER)
-                               return deviceLimits.sampledImageIntegerSampleCounts;
-                       else
-                               return deviceLimits.sampledImageColorSampleCounts;
+                       if (hasStencilComp)
+                               sampleCounts &= deviceLimits.sampledImageStencilSampleCounts;
+
+                       if (isColorFormat)
+                       {
+                               const tcu::TextureChannelClass  chnClass        = tcu::getTextureChannelClass(tcuFormat.type);
+
+                               if (chnClass == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER ||
+                                       chnClass == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER)
+                                       sampleCounts &= deviceLimits.sampledImageIntegerSampleCounts;
+                               else
+                                       sampleCounts &= deviceLimits.sampledImageColorSampleCounts;
+                       }
+               }
+
+               if ((usageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) != 0)
+                       sampleCounts &= deviceLimits.framebufferColorSampleCounts;
+
+               if ((usageFlags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) != 0)
+               {
+                       if (hasDepthComp)
+                               sampleCounts &= deviceLimits.framebufferDepthSampleCounts;
+
+                       if (hasStencilComp)
+                               sampleCounts &= deviceLimits.framebufferStencilSampleCounts;
                }
+
+               // If there is no usage flag set that would have corresponding device limit,
+               // only VK_SAMPLE_COUNT_1_BIT is required.
+               if (sampleCounts == ~(VkSampleCountFlags)0)
+                       sampleCounts &= VK_SAMPLE_COUNT_1_BIT;
+
+               return sampleCounts;
        }
        else
                return VK_SAMPLE_COUNT_1_BIT;