Add GeometryPointSize feature check
authorIlkka Saarelainen <ilkka.saarelainen@siru.fi>
Wed, 15 May 2019 12:01:14 +0000 (15:01 +0300)
committerAlexander Galazin <Alexander.Galazin@arm.com>
Wed, 22 May 2019 09:38:08 +0000 (05:38 -0400)
Some tests were using gl_PointSize without checking if the
shaderTessellationAndGeometryPointSize feature is supported and enabled.

This CL adds the feature checks to those tests. If the feature is not
supported/enabled, an alternative geometry shader code without
gl_PointSize will be used.

Affects:

dEQP-VK.glsl.*geometry
dEQP-VK.ycbcr.*geometry*
dEQP-VK.query_pool.*
dEQP-VK.transform_feedback.simple.streams_pointsize*

Components: Vulkan

VK-GL-CTS issue: 1763

Change-Id: If58bb5129144bae8d51dca84a3d0c89b46be1343
(cherry picked from commit d4b80f34b70ae497b6bb0573859209ae28197a35)

external/vulkancts/modules/vulkan/query_pool/vktQueryPoolStatisticsTests.cpp
external/vulkancts/modules/vulkan/shaderexecutor/vktShaderExecutor.cpp

index 23fb43b..578865f 100644 (file)
@@ -41,6 +41,7 @@
 #include "vkImageUtil.hpp"
 #include "tcuCommandLine.hpp"
 #include "tcuRGBA.hpp"
+#include "tcuStringTemplate.hpp"
 
 namespace vkt
 {
@@ -1243,12 +1244,13 @@ void GeometryShaderTestInstance::checkExtensions (void)
 
 void GeometryShaderTestInstance::createPipeline (void)
 {
-       const DeviceInterface&  vk              = m_context.getDeviceInterface();
-       const VkDevice                  device  = m_context.getDevice();
+       const DeviceInterface&  vk                                              = m_context.getDeviceInterface();
+       const VkDevice                  device                                  = m_context.getDevice();
+       const VkBool32                  useGeomPointSize                = m_context.getDeviceFeatures().shaderTessellationAndGeometryPointSize && (m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST);
 
        // Pipeline
        Unique<VkShaderModule> vs(createShaderModule(vk, device, m_context.getBinaryCollection().get("vertex"), (VkShaderModuleCreateFlags)0));
-       Unique<VkShaderModule> gs(createShaderModule(vk, device, m_context.getBinaryCollection().get("geometry"), (VkShaderModuleCreateFlags)0));
+       Unique<VkShaderModule> gs(createShaderModule(vk, device, m_context.getBinaryCollection().get(useGeomPointSize ? "geometry_point_size" : "geometry"), (VkShaderModuleCreateFlags)0));
        Unique<VkShaderModule> fs(createShaderModule(vk, device, m_context.getBinaryCollection().get("fragment"), (VkShaderModuleCreateFlags)0));
 
        const PipelineCreateInfo::ColorBlendState::Attachment attachmentState;
@@ -2057,6 +2059,7 @@ public:
                if(m_parametersGraphic.queryStatisticFlags & (VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT | VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT |
                                                                        VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT | VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT))
                { // Geometry Shader
+                       const bool isTopologyPointSize = m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
                        std::ostringstream      source;
                        source  << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450)<<"\n"
                                        << "layout("<<inputTypeToGLString(m_parametersGraphic.primitiveTopology)<<") in;\n"
@@ -2066,14 +2069,17 @@ public:
                                        << "void main (void)\n"
                                        << "{\n"
                                        << "    out_color = in_color[0];\n"
+                                       << (isTopologyPointSize ? "${pointSize}" : "" )
                                        << "    gl_Position = gl_in[0].gl_Position;\n"
                                        << "    EmitVertex();\n"
                                        << "    EndPrimitive();\n"
                                        << "\n"
                                        << "    out_color = in_color[0];\n"
+                                       << (isTopologyPointSize ? "${pointSize}" : "")
                                        << "    gl_Position = vec4(1.0, 1.0, 1.0, 1.0);\n"
                                        << "    EmitVertex();\n"
                                        << "    out_color = in_color[0];\n"
+                                       << (isTopologyPointSize ? "${pointSize}" : "")
                                        << "    gl_Position = vec4(-1.0, -1.0, 1.0, 1.0);\n"
                                        << "    EmitVertex();\n"
                                        << "    EndPrimitive();\n"
@@ -2099,21 +2105,44 @@ public:
                        else
                        {
                                source  << "    out_color = in_color[0];\n"
-                                               << "    gl_Position =  vec4(1.0, 1.0, 1.0, 1.0);\n"
+                                               << (isTopologyPointSize ? "${pointSize}" : "")
+                                               << "    gl_Position = vec4(1.0, 1.0, 1.0, 1.0);\n"
                                                << "    EmitVertex();\n"
                                                << "    out_color = in_color[0];\n"
+                                               << (isTopologyPointSize ? "${pointSize}" : "")
                                                << "    gl_Position = vec4(1.0, -1.0, 1.0, 1.0);\n"
                                                << "    EmitVertex();\n"
                                                << "    out_color = in_color[0];\n"
+                                               << (isTopologyPointSize ? "${pointSize}" : "")
                                                << "    gl_Position = vec4(-1.0, 1.0, 1.0, 1.0);\n"
                                                << "    EmitVertex();\n"
                                                << "    out_color = in_color[0];\n"
+                                               << (isTopologyPointSize ? "${pointSize}" : "")
                                                << "    gl_Position = vec4(-1.0, -1.0, 1.0, 1.0);\n"
                                                << "    EmitVertex();\n"
                                                << "    EndPrimitive();\n";
                        }
                        source  << "}\n";
-                       sourceCollections.glslSources.add("geometry") << glu::GeometrySource(source.str());
+
+                       if (isTopologyPointSize)
+                       {
+                               // Add geometry shader codes with and without gl_PointSize if the primitive topology is VK_PRIMITIVE_TOPOLOGY_POINT_LIST
+
+                               tcu::StringTemplate sourceTemplate(source.str());
+
+                               std::map<std::string, std::string> pointSize;
+                               std::map<std::string, std::string> noPointSize;
+
+                               pointSize["pointSize"]          = "     gl_PointSize = gl_in[0].gl_PointSize;\n";
+                               noPointSize["pointSize"]        = "";
+
+                               sourceCollections.glslSources.add("geometry") << glu::GeometrySource(sourceTemplate.specialize(noPointSize));
+                               sourceCollections.glslSources.add("geometry_point_size") << glu::GeometrySource(sourceTemplate.specialize(pointSize));
+                       }
+                       else
+                       {
+                               sourceCollections.glslSources.add("geometry") << glu::GeometrySource(source.str());
+                       }
                }
 
                { // Fragment Shader
index 2fb1715..2bd1b65 100644 (file)
@@ -426,7 +426,7 @@ static std::string generatePassthroughFragmentShader (const ShaderSpec& shaderSp
        return src.str();
 }
 
-static std::string generateGeometryShader (const ShaderSpec& shaderSpec, const std::string& inputPrefix, const std::string& outputPrefix)
+static std::string generateGeometryShader (const ShaderSpec& shaderSpec, const std::string& inputPrefix, const std::string& outputPrefix, const bool pointSizeSupported)
 {
        DE_ASSERT(!inputPrefix.empty() && !outputPrefix.empty());
 
@@ -467,7 +467,8 @@ static std::string generateGeometryShader (const ShaderSpec& shaderSpec, const s
        src << "\n"
                << "void main (void)\n"
                << "{\n"
-               << "    gl_Position = gl_in[0].gl_Position;\n\n";
+               << "    gl_Position = gl_in[0].gl_Position;\n"
+               << (pointSizeSupported ? "      gl_PointSize = gl_in[0].gl_PointSize;\n\n" : "");
 
        // Fetch input variables
        for (vector<Symbol>::const_iterator input = shaderSpec.inputs.begin(); input != shaderSpec.inputs.end(); ++input)
@@ -1177,7 +1178,10 @@ void FragmentOutExecutor::execute (int numValues, const void* const* inputs, voi
 
                if (useGeometryShader)
                {
-                       geometryShaderModule = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("geom"), 0);
+                       if (m_context.getDeviceFeatures().shaderTessellationAndGeometryPointSize)
+                               geometryShaderModule = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("geom_point_size"), 0);
+                       else
+                               geometryShaderModule = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("geom"), 0);
                }
        }
 
@@ -1449,7 +1453,8 @@ void GeometryShaderExecutor::generateSources (const ShaderSpec& shaderSpec, Sour
 
        programCollection.glslSources.add("vert") << glu::VertexSource(generatePassthroughVertexShader(shaderSpec, "a_", "vtx_out_")) << shaderSpec.buildOptions;
 
-       programCollection.glslSources.add("geom") << glu::GeometrySource(generateGeometryShader(shaderSpec, "vtx_out_", "geom_out_")) << shaderSpec.buildOptions;
+       programCollection.glslSources.add("geom") << glu::GeometrySource(generateGeometryShader(shaderSpec, "vtx_out_", "geom_out_", false)) << shaderSpec.buildOptions;
+       programCollection.glslSources.add("geom_point_size") << glu::GeometrySource(generateGeometryShader(shaderSpec, "vtx_out_", "geom_out_", true)) << shaderSpec.buildOptions;
 
        /* \todo [2015-09-18 rsipka] set useIntOutputs parameter if needed. */
        programCollection.glslSources.add("frag") << glu::FragmentSource(generatePassthroughFragmentShader(shaderSpec, false, outputLayout.locationMap, "geom_out_", "o_")) << shaderSpec.buildOptions;