ShaderRenderCase: use safe containers for vertex buffers and allocs
authorPeter Gal <pgal.u-szeged@partner.samsung.com>
Tue, 6 Oct 2015 13:31:51 +0000 (15:31 +0200)
committerPeter Gal <pgal.u-szeged@partner.samsung.com>
Thu, 12 Nov 2015 18:52:43 +0000 (19:52 +0100)
external/vulkancts/modules/vulkan/shaderrendercase/vktShaderRenderCase.cpp
external/vulkancts/modules/vulkan/shaderrendercase/vktShaderRenderCase.hpp

index 44a995fe407a51792ae192dfddc01aa7c9ad3921..232b2375541d38f5c14215fd44a98d669772fd99 100644 (file)
@@ -400,12 +400,6 @@ ShaderRenderCaseInstance::~ShaderRenderCaseInstance (void)
        const VkDevice                  vkDevice        = m_context.getDevice();
        const DeviceInterface&  vk                      = m_context.getDeviceInterface();
 
-       for (size_t bufferNdx = 0; bufferNdx < m_vertexBuffers.size(); bufferNdx++)
-       {
-               VK_CHECK(vk.freeMemory(vkDevice, m_vertexBufferAllocs[bufferNdx]->getMemory()));
-               VK_CHECK(vk.destroyBuffer(vkDevice, m_vertexBuffers[bufferNdx]));
-       }
-
        for (size_t uniformNdx = 0; uniformNdx < m_uniformInfos.size(); uniformNdx++)
        {
                if (m_uniformInfos[uniformNdx].type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER)
@@ -574,8 +568,8 @@ void ShaderRenderCaseInstance::addAttribute (deUint32 bindingLocation, vk::VkFor
        deMemcpy(bufferPtr, dataPtr, inputSize);
        VK_CHECK(vk.unmapMemory(vkDevice, alloc->getMemory()));
 
-       m_vertexBuffers.push_back(buffer.disown());
-       m_vertexBufferAllocs.push_back(alloc.release());
+       m_vertexBuffers.push_back(VkBufferSp(new vk::Unique<VkBuffer>(buffer)));
+       m_vertexBufferAllocs.push_back(AllocationSp(new de::UniquePtr<vk::Allocation>(alloc)));
 }
 
 void ShaderRenderCaseInstance::useAttribute (deUint32 bindingLocation, BaseAttributeType type)
@@ -1345,7 +1339,13 @@ void ShaderRenderCaseInstance::render (tcu::Surface& result, const QuadGrid& qua
                const deUint32 numberOfVertexAttributes = (deUint32)m_vertexBuffers.size();
                const std::vector<VkDeviceSize> offsets(numberOfVertexAttributes, 0);
 
-               vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, numberOfVertexAttributes, &m_vertexBuffers[0], &offsets[0]);
+               std::vector<VkBuffer> buffers(numberOfVertexAttributes);
+               for (size_t i = 0; i < numberOfVertexAttributes; i++)
+               {
+                       buffers[i] = m_vertexBuffers[i].get()->get();
+               }
+
+               vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, numberOfVertexAttributes, &buffers[0], &offsets[0]);
                vk.cmdDrawIndexed(*m_cmdBuffer, 0, quadGrid.getNumTriangles() * 3, 0, 0, 1);
 
                vk.cmdEndRenderPass(*m_cmdBuffer);
index 0fb82091693f1529759b899cc7a7a5281f2b4c9d..aadccd012f6a8739db2d8e0aaafd1747b8ed3757 100644 (file)
@@ -39,6 +39,7 @@
 #include "tcuSurface.hpp"
 
 #include "deMemory.h"
+#include "deSharedPtr.hpp"
 #include "deUniquePtr.hpp"
 
 #include "vkDefs.hpp"
@@ -466,8 +467,12 @@ private:
 
        std::vector<vk::VkVertexInputBindingDescription>        m_vertexBindingDescription;
        std::vector<vk::VkVertexInputAttributeDescription>      m_vertexattributeDescription;
-       std::vector<vk::VkBuffer>                                                       m_vertexBuffers;
-       std::vector<vk::Allocation*>                                            m_vertexBufferAllocs;
+
+       typedef de::SharedPtr<vk::Unique<vk::VkBuffer> > VkBufferSp;
+       std::vector<VkBufferSp>                                                         m_vertexBuffers;
+
+       typedef de::SharedPtr<de::UniquePtr<vk::Allocation> > AllocationSp;
+       std::vector<AllocationSp>                                                       m_vertexBufferAllocs;
 };
 
 template<typename T>