Avoid fragment shader in some depth/stencil tests
authorRicardo Garcia <rgarcia@igalia.com>
Mon, 30 Mar 2020 13:04:37 +0000 (15:04 +0200)
committerAlexander Galazin <Alexander.Galazin@arm.com>
Thu, 9 Apr 2020 07:11:24 +0000 (03:11 -0400)
This commit makes depth/stencil tests with no color attachments have no
fragment shader at all, instead of an empty fragment shader.

In addition, make stencil export tests keep the stencil value when
running with color attachments.

Affected tests:
dEQP-VK.pipeline.stencil.nocolor.*
dEQP-VK.pipeline.depth.nocolor.*
dEQP-VK.pipeline.shader_stencil_export.*

Components: Vulkan
VK-GL-CTS issue: 2235

Change-Id: Ic6090d140f247f79bb59425cb6db1db59a193114

external/vulkancts/modules/vulkan/pipeline/vktPipelineDepthTests.cpp
external/vulkancts/modules/vulkan/pipeline/vktPipelineStencilExportTests.cpp
external/vulkancts/modules/vulkan/pipeline/vktPipelineStencilTests.cpp

index 20c3d4d78025c508f1f5fade959ea825898ddb81..c715290c85de7287efa21133e4573ba0ae5afcb8 100644 (file)
@@ -287,12 +287,6 @@ void DepthTest::initPrograms (SourceCollections& programCollection) const
                        "{\n"
                        "       gl_Position = position;\n"
                        "}\n");
-
-               programCollection.glslSources.add("color_frag") << glu::FragmentSource(
-                       "#version 310 es\n"
-                       "void main (void)\n"
-                       "{\n"
-                       "}\n");
        }
 
 }
@@ -470,8 +464,9 @@ DepthTestInstance::DepthTestInstance (Context&                              context,
        }
 
        // Shader modules
-       m_vertexShaderModule    = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("color_vert"), 0);
-       m_fragmentShaderModule  = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("color_frag"), 0);
+       m_vertexShaderModule            = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("color_vert"), 0);
+       if (m_colorAttachmentEnable)
+               m_fragmentShaderModule  = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("color_frag"), 0);
 
        // Create pipeline
        {
@@ -546,6 +541,24 @@ DepthTestInstance::DepthTestInstance (Context&                             context,
                        m_depthBoundsMax,                       // float                        maxDepthBounds;
                };
 
+               // Make sure rasterization is not disabled when the fragment shader is missing.
+               const vk::VkPipelineRasterizationStateCreateInfo rasterizationStateParams =
+               {
+                       vk::VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, //      VkStructureType                                                 sType;
+                       nullptr,                                                                                                                //      const void*                                                             pNext;
+                       0u,                                                                                                                             //      VkPipelineRasterizationStateCreateFlags flags;
+                       VK_FALSE,                                                                                                               //      VkBool32                                                                depthClampEnable;
+                       VK_FALSE,                                                                                                               //      VkBool32                                                                rasterizerDiscardEnable;
+                       vk::VK_POLYGON_MODE_FILL,                                                                               //      VkPolygonMode                                                   polygonMode;
+                       vk::VK_CULL_MODE_NONE,                                                                                  //      VkCullModeFlags                                                 cullMode;
+                       vk::VK_FRONT_FACE_COUNTER_CLOCKWISE,                                                    //      VkFrontFace                                                             frontFace;
+                       VK_FALSE,                                                                                                               //      VkBool32                                                                depthBiasEnable;
+                       0.0f,                                                                                                                   //      float                                                                   depthBiasConstantFactor;
+                       0.0f,                                                                                                                   //      float                                                                   depthBiasClamp;
+                       0.0f,                                                                                                                   //      float                                                                   depthBiasSlopeFactor;
+                       1.0f,                                                                                                                   //      float                                                                   lineWidth;
+               };
+
                for (int quadNdx = 0; quadNdx < DepthTest::QUAD_COUNT; quadNdx++)
                {
                        depthStencilStateParams.depthCompareOp  = depthCompareOps[quadNdx];
@@ -564,7 +577,7 @@ DepthTestInstance::DepthTestInstance (Context&                              context,
                                                                                                                                                   0u,                                                                  // const deUint32                                subpass
                                                                                                                                                   0u,                                                                  // const deUint32                                patchControlPoints
                                                                                                                                                   &vertexInputStateParams,                             // const VkPipelineVertexInputStateCreateInfo*   vertexInputStateCreateInfo
-                                                                                                                                                  DE_NULL,                                                             // const VkPipelineRasterizationStateCreateInfo* rasterizationStateCreateInfo
+                                                                                                                                                  &rasterizationStateParams,                   // const VkPipelineRasterizationStateCreateInfo* rasterizationStateCreateInfo
                                                                                                                                                   DE_NULL,                                                             // const VkPipelineMultisampleStateCreateInfo*   multisampleStateCreateInfo
                                                                                                                                                   &depthStencilStateParams);                   // const VkPipelineDepthStencilStateCreateInfo*  depthStencilStateCreateInfo
                }
index a9e6cce0eb71c7c99d9509e3e238c190860453b3..428c57a49316a161b25689217202249e498fddbc 100644 (file)
@@ -327,9 +327,9 @@ Move<VkPipeline> makeGraphicsPipeline (const DeviceInterface&               vk,
        };
 
        const VkStencilOpState stencilOpState = makeStencilOpState(
-               VK_STENCIL_OP_REPLACE,                                                                                  // stencil fail
-               VK_STENCIL_OP_REPLACE,                                                                                  // depth & stencil pass
-               VK_STENCIL_OP_REPLACE,                                                                                  // depth only fail
+               useColor ? VK_STENCIL_OP_KEEP : VK_STENCIL_OP_REPLACE,                  // stencil fail
+               useColor ? VK_STENCIL_OP_KEEP : VK_STENCIL_OP_REPLACE,                  // depth & stencil pass
+               useColor ? VK_STENCIL_OP_KEEP : VK_STENCIL_OP_REPLACE,                  // depth only fail
                useColor ? VK_COMPARE_OP_EQUAL : VK_COMPARE_OP_NEVER,                   // compare op
                useColor ? 0xffu : 0u,                                                                                  // compare mask
                useColor ? 0u : 0xffu,                                                                                  // write mask
index 5a297424d5594a8bbfd4e94b69bd296faea7275f..6837dbb0413d1f9d8c1d1c29563b70ebd13d4e30 100644 (file)
@@ -332,12 +332,6 @@ void StencilTest::initPrograms (SourceCollections& sourceCollections) const
                        "{\n"
                        "       gl_Position = position;\n"
                        "}\n");
-
-               sourceCollections.glslSources.add("color_frag") << glu::FragmentSource(
-                       "#version 310 es\n"
-                       "void main (void)\n"
-                       "{\n"
-                       "}\n");
        }
 }
 
@@ -508,8 +502,9 @@ StencilTestInstance::StencilTestInstance (Context&                                  context,
                m_pipelineLayout = createPipelineLayout(vk, vkDevice, &pipelineLayoutParams);
        }
 
-       m_vertexShaderModule    = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("color_vert"), 0);
-       m_fragmentShaderModule  = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("color_frag"), 0);
+       m_vertexShaderModule            = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("color_vert"), 0);
+       if (m_colorAttachmentEnable)
+               m_fragmentShaderModule  = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("color_frag"), 0);
 
        // Create pipeline
        {
@@ -568,6 +563,24 @@ StencilTestInstance::StencilTestInstance (Context&                                 context,
                        1.0f                                                                                                            // float                                                                        maxDepthBounds;
                };
 
+               // Make sure rasterization is not disabled when the fragment shader is missing.
+               const vk::VkPipelineRasterizationStateCreateInfo rasterizationStateParams =
+               {
+                       vk::VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, //      VkStructureType                                                 sType;
+                       nullptr,                                                                                                                //      const void*                                                             pNext;
+                       0u,                                                                                                                             //      VkPipelineRasterizationStateCreateFlags flags;
+                       VK_FALSE,                                                                                                               //      VkBool32                                                                depthClampEnable;
+                       VK_FALSE,                                                                                                               //      VkBool32                                                                rasterizerDiscardEnable;
+                       vk::VK_POLYGON_MODE_FILL,                                                                               //      VkPolygonMode                                                   polygonMode;
+                       vk::VK_CULL_MODE_NONE,                                                                                  //      VkCullModeFlags                                                 cullMode;
+                       vk::VK_FRONT_FACE_COUNTER_CLOCKWISE,                                                    //      VkFrontFace                                                             frontFace;
+                       VK_FALSE,                                                                                                               //      VkBool32                                                                depthBiasEnable;
+                       0.0f,                                                                                                                   //      float                                                                   depthBiasConstantFactor;
+                       0.0f,                                                                                                                   //      float                                                                   depthBiasClamp;
+                       0.0f,                                                                                                                   //      float                                                                   depthBiasSlopeFactor;
+                       1.0f,                                                                                                                   //      float                                                                   lineWidth;
+               };
+
                // Setup different stencil masks and refs in each quad
                for (int quadNdx = 0; quadNdx < StencilTest::QUAD_COUNT; quadNdx++)
                {
@@ -598,7 +611,7 @@ StencilTestInstance::StencilTestInstance (Context&                                  context,
                                                                                                                                0u,                                                                             // const deUint32                                subpass
                                                                                                                                0u,                                                                             // const deUint32                                patchControlPoints
                                                                                                                                &vertexInputStateParams,                                // const VkPipelineVertexInputStateCreateInfo*   vertexInputStateCreateInfo
-                                                                                                                               DE_NULL,                                                                // const VkPipelineRasterizationStateCreateInfo* rasterizationStateCreateInfo
+                                                                                                                               &rasterizationStateParams,                              // const VkPipelineRasterizationStateCreateInfo* rasterizationStateCreateInfo
                                                                                                                                DE_NULL,                                                                // const VkPipelineMultisampleStateCreateInfo*   multisampleStateCreateInfo
                                                                                                                                &depthStencilStateParams);                              // const VkPipelineDepthStencilStateCreateInfo*  depthStencilStateCreateInfo
                }