Преглед изворни кода

Added Vulkan descriptor pool

BearishSun пре 9 година
родитељ
комит
f2dfe437d4

+ 2 - 0
Source/BansheeVulkanRenderAPI/CMakeSources.cmake

@@ -22,6 +22,7 @@ set(BS_BANSHEEVULKANRENDERAPI_INC_NOFILTER
 	"Include/BsVulkanFramebuffer.h"
 	"Include/BsVulkanUtility.h"
 	"Include/BsVulkanGpuParams.h"
+	"Include/BsVulkanDescriptorPool.h"
 )
 
 set(BS_BANSHEEVULKANRENDERAPI_INC_MANAGERS
@@ -60,6 +61,7 @@ set(BS_BANSHEEVULKANRENDERAPI_SRC_NOFILTER
 	"Source/BsVulkanFramebuffer.cpp"
 	"Source/BsVulkanUtility.cpp"
 	"Source/BsVulkanGpuParams.cpp"
+	"Source/BsVulkanDescriptorPool.cpp"
 )
 
 set(BS_BANSHEEVULKANRENDERAPI_SRC_MANAGERS

+ 35 - 0
Source/BansheeVulkanRenderAPI/Include/BsVulkanDescriptorPool.h

@@ -0,0 +1,35 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#pragma once
+
+#include "BsVulkanPrerequisites.h"
+
+namespace BansheeEngine
+{
+	/** @addtogroup Vulkan
+	 *  @{
+	 */
+
+	/** Pool that allocates and distributes Vulkan descriptor sets. */
+	class VulkanDescriptorPool
+	{
+	public:
+		VulkanDescriptorPool(VulkanDevice& device);
+		~VulkanDescriptorPool();
+
+		/** Returns a handle to the internal Vulkan descriptor pool. */
+		VkDescriptorPool getHandle() const { return mPool; }
+
+	private:
+		static const UINT32 sMaxSets = 8192;
+		static const UINT32 sMaxSampledImages = 4096;
+		static const UINT32 sMaxImages = 2048;
+		static const UINT32 sMaxBuffers = 2048;
+		static const UINT32 sMaxUniformBuffers = 2048;
+
+		VulkanDevice& mDevice;
+		VkDescriptorPool mPool;
+	};
+
+	/** @} */
+}

+ 40 - 0
Source/BansheeVulkanRenderAPI/Source/BsVulkanDescriptorPool.cpp

@@ -0,0 +1,40 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#include "BsVulkanDescriptorPool.h"
+#include "BsVulkanDevice.h"
+
+namespace BansheeEngine
+{
+	VulkanDescriptorPool::VulkanDescriptorPool(VulkanDevice& device)
+		:mDevice(device)
+	{
+		VkDescriptorPoolSize poolSizes[4];
+		poolSizes[0].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
+		poolSizes[0].descriptorCount = sMaxSampledImages;
+
+		poolSizes[1].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
+		poolSizes[1].descriptorCount = sMaxUniformBuffers;
+
+		poolSizes[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
+		poolSizes[2].descriptorCount = sMaxImages;
+
+		poolSizes[3].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
+		poolSizes[3].descriptorCount = sMaxBuffers;
+
+		VkDescriptorPoolCreateInfo poolCI;
+		poolCI.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
+		poolCI.pNext = nullptr;
+		poolCI.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
+		poolCI.maxSets = sMaxSets;
+		poolCI.poolSizeCount = sizeof(poolSizes)/sizeof(poolSizes[0]);
+		poolCI.pPoolSizes = poolSizes;
+
+		VkResult result = vkCreateDescriptorPool(mDevice.getLogical(), &poolCI, gVulkanAllocator, &mPool);
+		assert(result == VK_SUCCESS);
+	}
+
+	VulkanDescriptorPool::~VulkanDescriptorPool()
+	{
+		vkDestroyDescriptorPool(mDevice.getLogical(), mPool, gVulkanAllocator);
+	}
+}