Selaa lähdekoodia

Vulkan: Work on the framebuffer and commandbuffer

Panagiotis Christopoulos Charitos 9 vuotta sitten
vanhempi
sitoutus
78a7c726a5

+ 9 - 0
README.md

@@ -71,3 +71,12 @@ To build the release version:
 	- Invoke the mingw's make: mingw32-make
 
 > NOTE: If you have a better way to build on Windows please let us know.
+
+> NOTE 2: The Windows build tends to brake often since Windows is not the 
+> primary developement platform. Please report any bugs.
+
+Next steps
+==========
+
+Try to build with samples enabled (see the relevant option in your CMake GUI) 
+and try running the simple_scene executable. More samples will follow.

+ 16 - 8
include/anki/gr/vulkan/CommandBufferImpl.h

@@ -10,6 +10,9 @@
 namespace anki
 {
 
+// Forward
+class CommandBufferInitInfo;
+
 /// @addtogroup vulkan
 /// @{
 
@@ -18,14 +21,19 @@ class CommandBufferImpl : public VulkanObject
 {
 public:
 	/// Default constructor
-	CommandBufferImpl(GrManager* manager)
-		: VulkanObject(manager)
-	{
-	}
-
-	~CommandBufferImpl()
-	{
-	}
+	CommandBufferImpl(GrManager* manager);
+
+	~CommandBufferImpl();
+
+	ANKI_USE_RESULT Error init(const CommandBufferInitInfo& init);
+
+private:
+	VkCommandBuffer m_handle = VK_NULL_HANDLE;
+	Bool8 m_secondLevel = false;
+	Thread::Id m_tid = 0;
+
+	/// Some common checks that happen on every command.
+	void commandChecks();
 };
 /// @}
 

+ 4 - 3
include/anki/gr/vulkan/FramebufferImpl.h

@@ -22,6 +22,7 @@ class FramebufferImpl : public VulkanObject
 public:
 	VkFramebuffer m_framebuffer = VK_NULL_HANDLE;
 	VkRenderPass m_renderPass = VK_NULL_HANDLE;
+	Bool8 m_defaultFramebuffer = false;
 
 	FramebufferImpl(GrManager* manager)
 		: VulkanObject(manager)
@@ -30,15 +31,15 @@ public:
 
 	~FramebufferImpl();
 
-	void init(const FramebufferInitInfo& init);
+	ANKI_USE_RESULT Error init(const FramebufferInitInfo& init);
 
 private:
-	void initRenderPass(const FramebufferInitInfo& init);
+	ANKI_USE_RESULT Error initRenderPass(const FramebufferInitInfo& init);
 
 	void setupAttachmentDescriptor(
 		const Attachment& in, VkAttachmentDescription& out, Bool depthStencil);
 
-	void initFramebuffer(const FramebufferInitInfo& init);
+	ANKI_USE_RESULT Error initFramebuffer(const FramebufferInitInfo& init);
 };
 /// @}
 

+ 11 - 0
src/gr/vulkan/CommandBuffer.cpp

@@ -23,11 +23,20 @@ CommandBuffer::~CommandBuffer()
 //==============================================================================
 void CommandBuffer::init(CommandBufferInitInfo& inf)
 {
+	m_impl.reset(getAllocator().newInstance<CommandBufferImpl>(&getManager()));
+	
+	if(m_impl->init(inf))
+	{
+		ANKI_LOGF("Cannot recover");
+	}
 }
 
 //==============================================================================
 CommandBufferInitHints CommandBuffer::computeInitHints() const
 {
+	// TODO
+	CommandBufferInitHints hints;
+	return hints;
 }
 
 //==============================================================================
@@ -174,6 +183,8 @@ void CommandBuffer::pushSecondLevelCommandBuffer(CommandBufferPtr cmdb)
 //==============================================================================
 Bool CommandBuffer::isEmpty() const
 {
+	// TODO
+	return false;
 }
 
 } // end namespace anki

+ 42 - 0
src/gr/vulkan/CommandBufferImpl.cpp

@@ -4,3 +4,45 @@
 // http://www.anki3d.org/LICENSE
 
 #include <anki/gr/vulkan/CommandBufferImpl.h>
+#include <anki/gr/CommandBuffer.h>
+#include <anki/gr/vulkan/GrManagerImpl.h>
+
+namespace anki
+{
+
+//==============================================================================
+CommandBufferImpl::CommandBufferImpl(GrManager* manager)
+	: VulkanObject(manager)
+{
+}
+
+//==============================================================================
+CommandBufferImpl::~CommandBufferImpl()
+{
+	if(m_handle)
+	{
+		getGrManagerImpl().deleteCommandBuffer(m_handle, m_secondLevel, m_tid);
+	}
+}
+
+//==============================================================================
+Error CommandBufferImpl::init(const CommandBufferInitInfo& init)
+{
+	m_secondLevel = init.m_secondLevel;
+	m_tid = Thread::getCurrentThreadId();
+
+	m_handle = getGrManagerImpl().newCommandBuffer(m_tid, m_secondLevel);
+	ANKI_ASSERT(m_handle);
+
+	return ErrorCode::NONE;
+}
+
+//==============================================================================
+void CommandBufferImpl::commandChecks()
+{
+	ANKI_ASSERT(Thread::getCurrentThreadId() == m_tid
+		&& "Commands must be recorder by the thread this command buffer was "
+		   "created");
+}
+
+} // end namespace anki

+ 5 - 0
src/gr/vulkan/Framebuffer.cpp

@@ -23,6 +23,11 @@ Framebuffer::~Framebuffer()
 //==============================================================================
 void Framebuffer::init(const FramebufferInitInfo& init)
 {
+	m_impl.reset(getAllocator().newInstance<FramebufferImpl>(&getManager()));
+	if(m_impl->init(init))
+	{
+		ANKI_LOGF("Cannot recover");
+	}
 }
 
 } // end namespace anki

+ 27 - 15
src/gr/vulkan/FramebufferImpl.cpp

@@ -12,22 +12,33 @@ namespace anki
 //==============================================================================
 FramebufferImpl::~FramebufferImpl()
 {
-	if(m_framebuffer)
+	if(m_renderPass)
 	{
-		vkDestroyFramebuffer(getDevice(), m_framebuffer, nullptr);
+		vkDestroyRenderPass(getDevice(), m_renderPass, nullptr);
 	}
 
-	if(m_renderPass)
+	if(m_framebuffer)
 	{
-		vkDestroyRenderPass(getDevice(), m_renderPass, nullptr);
+		vkDestroyFramebuffer(getDevice(), m_framebuffer, nullptr);
 	}
 }
 
 //==============================================================================
-void FramebufferImpl::init(const FramebufferInitInfo& init)
+Error FramebufferImpl::init(const FramebufferInitInfo& init)
 {
-	initRenderPass(init);
-	initFramebuffer(init);
+	if(init.m_colorAttachmentCount == 0
+		&& !init.m_depthStencilAttachment.m_texture.isCreated())
+	{
+		m_defaultFramebuffer = true;
+	}
+	else
+	{
+		m_defaultFramebuffer = false;
+		ANKI_CHECK(initRenderPass(init));
+		ANKI_CHECK(initFramebuffer(init));
+	}
+
+	return ErrorCode::NONE;
 }
 
 //==============================================================================
@@ -55,12 +66,10 @@ void FramebufferImpl::setupAttachmentDescriptor(
 }
 
 //==============================================================================
-void FramebufferImpl::initRenderPass(const FramebufferInitInfo& init)
+Error FramebufferImpl::initRenderPass(const FramebufferInitInfo& init)
 {
-	VkRenderPassCreateInfo ci;
+	VkRenderPassCreateInfo ci = {};
 	ci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
-	ci.pNext = nullptr;
-	ci.flags = 0;
 
 	// First setup the attachments
 	ci.attachmentCount = 0;
@@ -117,12 +126,13 @@ void FramebufferImpl::initRenderPass(const FramebufferInitInfo& init)
 	ci.dependencyCount = 0;
 	ci.pDependencies = nullptr;
 
-	ANKI_VK_CHECKF(
-		vkCreateRenderPass(getDevice(), &ci, nullptr, &m_renderPass));
+	ANKI_VK_CHECK(vkCreateRenderPass(getDevice(), &ci, nullptr, &m_renderPass));
+
+	return ErrorCode::NONE;
 }
 
 //==============================================================================
-void FramebufferImpl::initFramebuffer(const FramebufferInitInfo& init)
+Error FramebufferImpl::initFramebuffer(const FramebufferInitInfo& init)
 {
 	Bool hasDepthStencil = init.m_depthStencilAttachment.m_format.m_components
 		!= ComponentFormat::NONE;
@@ -138,8 +148,10 @@ void FramebufferImpl::initFramebuffer(const FramebufferInitInfo& init)
 	// TODO set views
 	// TODO set size and the rest
 
-	ANKI_VK_CHECKF(
+	ANKI_VK_CHECK(
 		vkCreateFramebuffer(getDevice(), &ci, nullptr, &m_framebuffer));
+
+	return ErrorCode::NONE;
 }
 
 } // end namespace anki

+ 4 - 1
src/gr/vulkan/Pipeline.cpp

@@ -26,7 +26,10 @@ Pipeline::~Pipeline()
 void Pipeline::init(const PipelineInitInfo& init)
 {
 	m_impl.reset(getAllocator().newInstance<PipelineImpl>(&getManager()));
-	m_impl->init(init);
+	if(m_impl->init(init))
+	{
+		ANKI_LOGF("Cannot recover");
+	}
 }
 
 } // end namespace anki