ShaderRenderCase: Add a single uniform to try out the api
authorPeter Gal <pgal.u-szeged@partner.samsung.com>
Fri, 28 Aug 2015 15:15:34 +0000 (17:15 +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 714995b..f6f4837 100644 (file)
@@ -499,6 +499,115 @@ void ShaderRenderCaseInstance::render (Surface& result, const QuadGrid& quadGrid
                m_framebuffer = createFramebuffer(vk, vkDevice, &framebufferParams);
        }
 
+       // Create descriptors
+       {
+               const VkDescriptorSetLayoutBinding layoutBindings[1] =
+               {
+                       {
+                               VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,                  // VkDescriptorType         descriptorType;
+                               1u,                                                                                     // deUint32                             arraySize;
+                               VK_SHADER_STAGE_VERTEX_BIT,                                     // VkShaderStageFlags   stageFlags;
+                               DE_NULL                                                                         // const VkSampler*             pImmutableSamplers;
+                       },
+               };
+
+               const VkDescriptorSetLayoutCreateInfo descriptorLayoutParams =
+               {
+                       VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,    // VkStructureType                                              sType;
+                       DE_NULL,                                                                                                // cost void*                                                   pNexŧ;
+                       DE_LENGTH_OF_ARRAY(layoutBindings),                                             // deUint32                                                             count;
+                       layoutBindings                                                                                  // const VkDescriptorSetLayoutBinding   pBinding;
+               };
+
+               m_descriptorSetLayout = createDescriptorSetLayout(vk, vkDevice, &descriptorLayoutParams);
+
+
+               const float uniformData[] = { 1.0f };
+               const VkDeviceSize uniformSize = DE_LENGTH_OF_ARRAY(uniformData) * sizeof(float);
+               const VkBufferCreateInfo uniformBufferParams =
+               {
+                       VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,           // VkStructureType              sType;
+                       DE_NULL,                                                                        // const void*                  pNext;
+                       uniformSize,                    // VkDeviceSize                 size;
+                       VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,                     // VkBufferUsageFlags   usage;
+                       0u,                                                                                     // VkBufferCreateFlags  flags;
+                       VK_SHARING_MODE_EXCLUSIVE,                                      // VkSharingMode                sharingMode;
+                       1u,                                                                                     // deUint32                             queueFamilyCount;
+                       &queueFamilyIndex                                                       // const deUint32*              pQueueFamilyIndices;
+               };
+
+               m_uniformBuffer                 = createBuffer(vk, vkDevice, &uniformBufferParams);
+               m_uniformBufferAlloc    = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_uniformBuffer), MemoryRequirement::HostVisible);
+
+               VK_CHECK(vk.bindBufferMemory(vkDevice, *m_uniformBuffer, m_uniformBufferAlloc->getMemory(), 0));
+
+               void* bufferPtr;
+               VK_CHECK(vk.mapMemory(vkDevice, m_uniformBufferAlloc->getMemory(), 0, uniformSize, 0, &bufferPtr));
+               deMemcpy(bufferPtr, uniformData, uniformSize);
+               VK_CHECK(vk.unmapMemory(vkDevice, m_uniformBufferAlloc->getMemory()));
+
+               const VkBufferViewCreateInfo viewInfo =
+               {
+                       VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO,      // VkStructureType      sType;
+                       DE_NULL,                                                                        // void*                        pNext;
+                       *m_uniformBuffer,                                                       // VkBuffer                     buffer;
+                       VK_BUFFER_VIEW_TYPE_FORMATTED,                                  // VkBufferViewType     viewType;
+                       VK_FORMAT_R32_SFLOAT,                                           // VkFormat     format;
+                       0u,                                                                                     // VkDeviceSize offset;
+                       uniformSize                                                                     // VkDeviceSize range;
+               };
+
+               m_uniformBufferView = createBufferView(vk, vkDevice, &viewInfo);
+
+               const VkDescriptorTypeCount descriptorTypes[] =
+               {
+                       {
+                               VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,                              // VkDescriptorType             type;
+                               1                                                                                               // deUint32                             count;
+                       }
+               };
+
+               const VkDescriptorPoolCreateInfo descriptorPoolParams =
+               {
+                       VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,  // VkStructureType                                      sType;
+                       DE_NULL,                                                                                // void*                                                        pNext;
+                       DE_LENGTH_OF_ARRAY(descriptorTypes),                    // deUint32                                                     count;
+                       descriptorTypes                                                                 // const VkDescriptorTypeCount*         pTypeCount
+               };
+
+               m_descriptorPool = createDescriptorPool(vk, vkDevice, VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &descriptorPoolParams);
+
+               m_descriptorSet = allocDescriptorSet(vk, vkDevice, *m_descriptorPool, VK_DESCRIPTOR_SET_USAGE_STATIC, *m_descriptorSetLayout);
+
+               const VkDescriptorInfo descriptorInfos[] =
+               {
+                       {
+                               *m_uniformBufferView,                                           // VkBufferView         bufferView;
+                               0,                                                                                      // VkSampler            sampler;
+                               0,                                                                                      // VkImageView          imageView;
+                               0,                                                                                      // VkAttachmentView     attachmentView;
+                               (VkImageLayout)0,                                                       // VkImageLayout        imageLayout;
+
+                       }
+               };
+
+               const VkWriteDescriptorSet writeDescritporSets[] =
+               {
+                       {
+                               VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,         // VkStructureType              sType;
+                               DE_NULL,                                                                        // const void*           pNext;
+                               *m_descriptorSet,                                                       // VkDescriptorSet              destSet;
+                               0,                                                                                      // deUint32             destBinding;
+                               0,                                                                                      // deUint32             destArrayElement;
+                               1,                                                                                      // deUint32             count;
+                               VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,                      // VkDescriptorType             descriptorType;
+                               descriptorInfos,                                                        // const VkDescriptorInfo*      pDescriptors;
+                       }
+               };
+
+               VK_CHECK(vk.updateDescriptorSets(vkDevice, 1, writeDescritporSets, 0u, DE_NULL));
+       }
+
        // Create pipeline layout
        {
                // TODO:: Connect uniforms here?
@@ -506,8 +615,8 @@ void ShaderRenderCaseInstance::render (Surface& result, const QuadGrid& quadGrid
                {
                        VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,          // VkStructureType                              sType;
                        DE_NULL,                                                                                        // const void*                                  pNext;
-                       0u,                                                                                                     // deUint32                                             descriptorSetCount;
-                       DE_NULL,                                                                                        // const VkDescriptorSetLayout* pSetLayouts;
+                       1u,                                                                                                     // deUint32                                             descriptorSetCount;
+                       &*m_descriptorSetLayout,                                                        // const VkDescriptorSetLayout* pSetLayouts;
                        0u,                                                                                                     // deUint32                                             pushConstantRangeCount;
                        DE_NULL                                                                                         // const VkPushConstantRange*   pPushConstantRanges;
                };
@@ -862,6 +971,8 @@ void ShaderRenderCaseInstance::render (Surface& result, const QuadGrid& quadGrid
 
                vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_graphicsPipeline);
 
+               vk.cmdBindDescriptorSets(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipelineLayout, 0u, 1, &*m_descriptorSet, 0u, DE_NULL);
+
                vk.cmdBindIndexBuffer(*m_cmdBuffer, *m_indiceBuffer, 0, VK_INDEX_TYPE_UINT16);
 
                const VkDeviceSize vertexBindingOffset = 0;
index bad21fe..5be14db 100644 (file)
@@ -242,6 +242,14 @@ private:
        vk::Move<vk::VkBuffer>                                          m_indiceBuffer;
        de::MovePtr<vk::Allocation>                             m_indiceBufferAlloc;
 
+       vk::Move<vk::VkDescriptorSetLayout>             m_descriptorSetLayout;
+       vk::Move<vk::VkBuffer>                                          m_uniformBuffer;
+       de::MovePtr<vk::Allocation>                             m_uniformBufferAlloc;
+       vk::Move<vk::VkBufferView>                              m_uniformBufferView;
+
+       vk::Move<vk::VkDescriptorPool>          m_descriptorPool;
+       vk::Move<vk::VkDescriptorSet>           m_descriptorSet;
+
        vk::Move<vk::VkCmdPool>                                         m_cmdPool;
        vk::Move<vk::VkCmdBuffer>                                       m_cmdBuffer;
 
index 5c92491..976b3a2 100644 (file)
@@ -33,13 +33,21 @@ tcu::TestCaseGroup* createTests (tcu::TestContext& testCtx)
 {
        de::MovePtr<tcu::TestCaseGroup> shaderRenderCaseTests (new tcu::TestCaseGroup(testCtx, "shaderRenderCase", "ShaderRenderCase Tests"));
 
-       std::string base_vertex = "#version 300 es\n"
+       std::string base_vertex = "#version 140\n"
+               "#extension GL_ARB_separate_shader_objects : enable\n"
+               "#extension GL_ARB_shading_language_420pack : enable\n"
+
         "layout(location = 0) in highp vec4 a_position;\n"
         "layout(location = 1) in highp vec4 a_coords;\n"
         "layout(location = 2) in highp vec4 a_unitCoords;\n"
         "layout(location = 3) in mediump float a_one;\n"
+
+               "layout (set=0, binding=0) uniform buf {\n"
+               "       float item;\n"
+               "};\n"
+
                "out mediump vec4 v_color;\n"
-        "void main (void) { gl_Position = a_position; v_color = vec4(a_coords.xyz, a_one); }\n";
+        "void main (void) { gl_Position = a_position; v_color = vec4(a_coords.xyz, item); }\n";
 
        std::string base_fragment = "#version 300 es\n"
         "layout(location = 0) out lowp vec4 o_color;\n"