ShaderRenderCase: Make the addUniform a template method
authorPeter Gal <pgal.u-szeged@partner.samsung.com>
Mon, 31 Aug 2015 17:13:18 +0000 (19:13 +0200)
committerPeter Gal <pgal.u-szeged@partner.samsung.com>
Thu, 12 Nov 2015 18:52:42 +0000 (19:52 +0100)
external/vulkancts/modules/vulkan/shaderrendercase/vktShaderRenderCase.cpp
external/vulkancts/modules/vulkan/shaderrendercase/vktShaderRenderCase.hpp
external/vulkancts/modules/vulkan/shaderrendercase/vktShaderRenderCaseTests.cpp

index 23e1d4a..4211e68 100644 (file)
@@ -339,7 +339,7 @@ tcu::TestStatus ShaderRenderCaseInstance::iterate (void)
                return tcu::TestStatus::fail("Image mismatch");
 }
 
-void ShaderRenderCaseInstance::setupUniformData (deUint32 size, void* dataPtr)
+void ShaderRenderCaseInstance::setupUniformData (deUint32 size, const void* dataPtr)
 {
        const VkDevice                          vkDevice                        = m_context.getDevice();
        const DeviceInterface&          vk                                      = m_context.getDeviceInterface();
@@ -440,49 +440,6 @@ void ShaderRenderCaseInstance::addAttribute (deUint32 bindingLocation, vk::VkFor
        m_vertexBufferAllocs.push_back(alloc.release());
 }
 
-void ShaderRenderCaseInstance::addUniform (deUint32 bindingLocation, VkDescriptorType descriptorType, float data)
-{
-       m_descriptorSetLayoutBuilder.addSingleBinding(descriptorType, VK_SHADER_STAGE_VERTEX_BIT);
-       m_descriptorPoolBuilder.addType(descriptorType);
-
-       setupUniformData(sizeof(data), &data);
-
-       const VkDescriptorInfo view =
-       {
-               m_uniformBufferViews[m_uniformBufferViews.size() - 1],                                                                                  // VkBufferView         bufferView;
-               0,                                                                                      // VkSampler            sampler;
-               0,                                                                                      // VkImageView          imageView;
-               0,                                                                                      // VkAttachmentView     attachmentView;
-               (VkImageLayout)0,                                                       // VkImageLayout        imageLayout;
-       };
-
-       m_uniformDescriptorInfos.push_back(view);
-
-       m_uniformLocations.push_back(bindingLocation);
-}
-
-void ShaderRenderCaseInstance::addUniform (deUint32 bindingLocation, VkDescriptorType descriptorType, tcu::Vec4 data)
-{
-       m_descriptorSetLayoutBuilder.addSingleBinding(descriptorType, VK_SHADER_STAGE_VERTEX_BIT);
-       m_descriptorPoolBuilder.addType(descriptorType);
-
-       setupUniformData(sizeof(data), &data[0]);
-
-       const VkDescriptorInfo view =
-       {
-               m_uniformBufferViews[m_uniformBufferViews.size() - 1],                                                                                  // VkBufferView         bufferView;
-               0,                                                                                      // VkSampler            sampler;
-               0,                                                                                      // VkImageView          imageView;
-               0,                                                                                      // VkAttachmentView     attachmentView;
-               (VkImageLayout)0,                                                       // VkImageLayout        imageLayout;
-       };
-
-       m_uniformDescriptorInfos.push_back(view);
-
-       m_uniformLocations.push_back(bindingLocation);
-}
-
-
 void ShaderRenderCaseInstance::setupShaderData (void)
 {
        // TODO!!!
index 4dddaa2..547d954 100644 (file)
@@ -210,8 +210,8 @@ public:
 
        void                                    addAttribute                            (deUint32 bindingLocation, vk::VkFormat, deUint32 sizePerElement, deUint32 count, const void* data);
 
-       void                                    addUniform                                      (deUint32 bindingLocation, vk::VkDescriptorType descriptorType, float data);
-       void                                    addUniform                                      (deUint32 bindingLocation, vk::VkDescriptorType descriptorType, tcu::Vec4 data);
+       template<typename T>
+       void                                    addUniform                                      (deUint32 bindingLocation, vk::VkDescriptorType descriptorType, const T data);
 
 protected:
        virtual void                    setupShaderData                         (void);
@@ -227,7 +227,7 @@ protected:
 
 private:
 
-       void                                    setupUniformData                        (deUint32 size, void* dataPtr);
+       void                                    setupUniformData                        (deUint32 size, const void* dataPtr);
        void                                    setupDefaultInputs                      (const QuadGrid& quadGrid);
 
        void                                    render                                          (tcu::Surface& result, const QuadGrid& quadGrid);
@@ -294,6 +294,29 @@ private:
        std::vector<vk::Allocation*>                                            m_vertexBufferAllocs;
 };
 
+template<typename T>
+void ShaderRenderCaseInstance::addUniform (deUint32 bindingLocation, vk::VkDescriptorType descriptorType, const T data)
+{
+       m_descriptorSetLayoutBuilder.addSingleBinding(descriptorType, vk::VK_SHADER_STAGE_VERTEX_BIT);
+       m_descriptorPoolBuilder.addType(descriptorType);
+
+       setupUniformData(sizeof(T), &data);
+
+       const vk::VkDescriptorInfo view =
+       {
+               m_uniformBufferViews[m_uniformBufferViews.size() - 1],                                                                                  // VkBufferView         bufferView;
+               0,                                                                                      // VkSampler            sampler;
+               0,                                                                                      // VkImageView          imageView;
+               0,                                                                                      // VkAttachmentView     attachmentView;
+               (vk::VkImageLayout)0,                                                   // VkImageLayout        imageLayout;
+       };
+
+       m_uniformDescriptorInfos.push_back(view);
+
+       m_uniformLocations.push_back(bindingLocation);
+}
+
+
 
 } // shaderrendercase
 } // vkt
index 6d85450..e5ef6de 100644 (file)
@@ -12,7 +12,15 @@ namespace shaderrendercase
 
 inline void eval_DEBUG      (ShaderEvalContext& c) { c.color = tcu::Vec4(1, 0, 1, 1); }
 
-void empty_uniform (ShaderRenderCaseInstance& instance) {}
+void empty_uniform (ShaderRenderCaseInstance& /* instance */) {}
+
+struct  test_struct {
+       tcu::Vec4 a;
+       tcu::Vec4 b;
+       tcu::Vec4 c;
+       tcu::Vec4 d;
+};
+
 
 
 void dummy_uniforms (ShaderRenderCaseInstance& instance)
@@ -20,13 +28,23 @@ void dummy_uniforms (ShaderRenderCaseInstance& instance)
        instance.addUniform(0u, vk::VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1.0f);
        instance.addUniform(1u, vk::VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0.5f);
        instance.addUniform(2u, vk::VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, tcu::Vec4(1, 0.5f, 1.0f, 0.5f));
+
+       test_struct data =
+       {
+               tcu::Vec4(0.1f),
+               tcu::Vec4(0.2f),
+               tcu::Vec4(0.3f),
+               tcu::Vec4(0.4f),
+       };
+
+       instance.addUniform<test_struct>(3u, vk::VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, data);
 }
 
 void dummy_attributes (ShaderRenderCaseInstance& instance, deUint32 numVertices)
 {
        std::vector<float> data;
        data.resize(numVertices);
-       for(int i = 0; i < numVertices; i++)
+       for(deUint32 i = 0; i < numVertices; i++)
                data[i] = 1.0;
 
        instance.addAttribute(4u, vk::VK_FORMAT_R32_SFLOAT, sizeof(float), numVertices, &data[0]);
@@ -78,8 +96,15 @@ tcu::TestCaseGroup* createTests (tcu::TestContext& testCtx)
                "       vec4 item3;\n"
                "};\n"
 
+               "struct FF { highp float a, b; };\n"
+               "layout (set=0, binding=3) uniform buf4 {\n"
+               "       FF f_1;\n"
+               "       FF f_2;\n"
+               "       highp vec2 f_3[2];\n"
+               "};\n"
+
                "out mediump vec4 v_color;\n"
-        "void main (void) { gl_Position = a_position; v_color = vec4(a_coords.xyz, a_in1); }\n";
+        "void main (void) { gl_Position = a_position; v_color = vec4(a_coords.xyz, f_1.a + f_2.a + f_3[0].x + f_3[1].x); }\n";
 
        std::string base_fragment = "#version 300 es\n"
         "layout(location = 0) out lowp vec4 o_color;\n"