From 6e057b2b534ce8165da85602c5db1140f5d087eb Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sat, 14 Oct 2017 14:28:31 +0200 Subject: [PATCH] [dxvk] Command list now implements DxvkRecorder --- src/dxvk/dxvk_cmdlist.cpp | 64 +++++++++++++++++++++++++++++++++++++++ src/dxvk/dxvk_cmdlist.h | 58 ++++++++++++++++++++++++++++++++--- src/dxvk/dxvk_context.cpp | 50 ++++++++++++------------------ src/dxvk/dxvk_context.h | 12 ++++---- src/dxvk/dxvk_device.cpp | 2 +- src/dxvk/dxvk_recorder.h | 12 ++++---- 6 files changed, 149 insertions(+), 49 deletions(-) diff --git a/src/dxvk/dxvk_cmdlist.cpp b/src/dxvk/dxvk_cmdlist.cpp index 633ce6355..389e2c1e2 100644 --- a/src/dxvk/dxvk_cmdlist.cpp +++ b/src/dxvk/dxvk_cmdlist.cpp @@ -74,4 +74,68 @@ namespace dxvk { m_resources.reset(); } + + void DxvkCommandList::cmdBeginRenderPass( + const VkRenderPassBeginInfo* pRenderPassBegin, + VkSubpassContents contents) { + m_vkd->vkCmdBeginRenderPass(m_buffer, + pRenderPassBegin, contents); + } + + + void DxvkCommandList::cmdBindPipeline( + VkPipelineBindPoint pipelineBindPoint, + VkPipeline pipeline) { + m_vkd->vkCmdBindPipeline(m_buffer, + pipelineBindPoint, pipeline); + } + + + void DxvkCommandList::cmdClearAttachments( + uint32_t attachmentCount, + const VkClearAttachment* pAttachments, + uint32_t rectCount, + const VkClearRect* pRects) { + m_vkd->vkCmdClearAttachments(m_buffer, + attachmentCount, pAttachments, + rectCount, pRects); + } + + + void DxvkCommandList::cmdDispatch( + uint32_t x, + uint32_t y, + uint32_t z) { + m_vkd->vkCmdDispatch(m_buffer, x, y, z); + } + + + void DxvkCommandList::cmdDraw( + uint32_t vertexCount, + uint32_t instanceCount, + uint32_t firstVertex, + uint32_t firstInstance) { + m_vkd->vkCmdDraw(m_buffer, + vertexCount, instanceCount, + firstVertex, firstInstance); + } + + + void DxvkCommandList::cmdDrawIndexed( + uint32_t indexCount, + uint32_t instanceCount, + uint32_t firstIndex, + uint32_t vertexOffset, + uint32_t firstInstance) { + m_vkd->vkCmdDrawIndexed(m_buffer, + indexCount, instanceCount, + firstIndex, vertexOffset, + firstInstance); + } + + + void DxvkCommandList::cmdEndRenderPass() { + m_vkd->vkCmdEndRenderPass(m_buffer); + } + } \ No newline at end of file diff --git a/src/dxvk/dxvk_cmdlist.h b/src/dxvk/dxvk_cmdlist.h index 3bc3c0cfe..c11b439c4 100644 --- a/src/dxvk/dxvk_cmdlist.h +++ b/src/dxvk/dxvk_cmdlist.h @@ -3,6 +3,7 @@ #include #include "dxvk_lifetime.h" +#include "dxvk_recorder.h" namespace dxvk { @@ -15,7 +16,7 @@ namespace dxvk { * When the command list has completed execution, resources that * are no longer used may get destroyed. */ - class DxvkCommandList : public RcObject { + class DxvkCommandList : public DxvkRecorder { public: @@ -32,8 +33,21 @@ namespace dxvk { return m_buffer; } - void beginRecording(); - void endRecording(); + /** + * \brief Begins recording + * + * Resets the command buffer and + * begins command buffer recording. + */ + void beginRecording() final; + + /** + * \brief Ends recording + * + * Ends command buffer recording, making + * the command list ready for submission. + */ + void endRecording() final; /** * \brief Adds a resource to track @@ -44,7 +58,7 @@ namespace dxvk { * completed. */ void trackResource( - const Rc& rc); + const Rc& rc) final; /** * \brief Resets the command list @@ -54,7 +68,41 @@ namespace dxvk { * command list to the device, this method will be called once * the command list completes execution. */ - void reset(); + void reset() final; + + void cmdBeginRenderPass( + const VkRenderPassBeginInfo* pRenderPassBegin, + VkSubpassContents contents) final; + + void cmdBindPipeline( + VkPipelineBindPoint pipelineBindPoint, + VkPipeline pipeline) final; + + void cmdClearAttachments( + uint32_t attachmentCount, + const VkClearAttachment* pAttachments, + uint32_t rectCount, + const VkClearRect* pRects) final; + + void cmdDispatch( + uint32_t x, + uint32_t y, + uint32_t z) final; + + void cmdDraw( + uint32_t vertexCount, + uint32_t instanceCount, + uint32_t firstVertex, + uint32_t firstInstance) final; + + void cmdDrawIndexed( + uint32_t indexCount, + uint32_t instanceCount, + uint32_t firstIndex, + uint32_t vertexOffset, + uint32_t firstInstance) final; + + void cmdEndRenderPass() final; private: diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index b4563cda3..0dc6511af 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -3,8 +3,7 @@ namespace dxvk { - DxvkContext::DxvkContext(const Rc& vkd) - : m_vkd(vkd) { + DxvkContext::DxvkContext() { TRACE(this); } @@ -15,10 +14,10 @@ namespace dxvk { void DxvkContext::beginRecording( - const Rc& cmdList) { - TRACE(this, cmdList); - m_commandList = cmdList; - m_commandList->beginRecording(); + const Rc& recorder) { + TRACE(this, recorder); + m_cmd = recorder; + m_cmd->beginRecording(); // Make sure that we apply the current context state // to the command buffer when recording draw commands. @@ -46,8 +45,8 @@ namespace dxvk { this->endRenderPass(); // Finalize the command list - m_commandList->endRecording(); - m_commandList = nullptr; + m_cmd->endRecording(); + m_cmd = nullptr; return true; } @@ -57,10 +56,8 @@ namespace dxvk { const VkClearRect& clearArea) { this->flushGraphicsState(); - m_vkd->vkCmdClearAttachments( - m_commandList->handle(), - 1, &attachment, - 1, &clearArea); + m_cmd->cmdClearAttachments( + 1, &attachment, 1, &clearArea); } @@ -70,8 +67,7 @@ namespace dxvk { uint32_t wgCountZ) { this->flushComputeState(); - m_vkd->vkCmdDispatch( - m_commandList->handle(), + m_cmd->cmdDispatch( wgCountX, wgCountY, wgCountZ); } @@ -83,12 +79,9 @@ namespace dxvk { uint32_t firstInstance) { this->flushGraphicsState(); - m_vkd->vkCmdDraw( - m_commandList->handle(), - vertexCount, - instanceCount, - firstVertex, - firstInstance); + m_cmd->cmdDraw( + vertexCount, instanceCount, + firstVertex, firstInstance); } @@ -100,12 +93,9 @@ namespace dxvk { uint32_t firstInstance) { this->flushGraphicsState(); - m_vkd->vkCmdDrawIndexed( - m_commandList->handle(), - indexCount, - instanceCount, - firstIndex, - vertexOffset, + m_cmd->cmdDrawIndexed( + indexCount, instanceCount, + firstIndex, vertexOffset, firstInstance); } @@ -148,11 +138,9 @@ namespace dxvk { void DxvkContext::flushComputeState() { - VkCommandBuffer cmd = m_commandList->handle(); - if (m_state.c.flags.test(DxvkComputePipelineBit::PipelineDirty) && m_state.c.pipeline != nullptr) { - m_vkd->vkCmdBindPipeline(cmd, + m_cmd->cmdBindPipeline( VK_PIPELINE_BIND_POINT_COMPUTE, m_state.c.pipeline->handle()); } @@ -184,7 +172,7 @@ namespace dxvk { info.clearValueCount = 0; info.pClearValues = nullptr; - m_vkd->vkCmdBeginRenderPass(m_commandList->handle(), &info, VK_SUBPASS_CONTENTS_INLINE); + m_cmd->cmdBeginRenderPass(&info, VK_SUBPASS_CONTENTS_INLINE); m_state.g.flags.set(DxvkGraphicsPipelineBit::RenderPassBound); } @@ -192,7 +180,7 @@ namespace dxvk { void DxvkContext::endRenderPass() { TRACE(this); - m_vkd->vkCmdEndRenderPass(m_commandList->handle()); + m_cmd->cmdEndRenderPass(); m_state.g.flags.clr(DxvkGraphicsPipelineBit::RenderPassBound); } diff --git a/src/dxvk/dxvk_context.h b/src/dxvk/dxvk_context.h index 3af8bd97a..208f7523b 100644 --- a/src/dxvk/dxvk_context.h +++ b/src/dxvk/dxvk_context.h @@ -2,6 +2,7 @@ #include "dxvk_cmdlist.h" #include "dxvk_context_state.h" +#include "dxvk_deferred.h" namespace dxvk { @@ -16,7 +17,7 @@ namespace dxvk { public: - DxvkContext(const Rc& vkd); + DxvkContext(); ~DxvkContext(); /** @@ -25,10 +26,10 @@ namespace dxvk { * Begins recording a command list. This does * not alter any context state other than the * active command list. - * \param [in] cmdList Target command list + * \param [in] recorder Target recorder */ void beginRecording( - const Rc& cmdList); + const Rc& recorder); /** * \brief Ends command buffer recording @@ -124,9 +125,8 @@ namespace dxvk { private: - Rc m_vkd; - Rc m_commandList; - DxvkContextState m_state; + Rc m_cmd; + DxvkContextState m_state; void flushComputeState(); void flushGraphicsState(); diff --git a/src/dxvk/dxvk_device.cpp b/src/dxvk/dxvk_device.cpp index 9bde75aa5..9a4c68ddf 100644 --- a/src/dxvk/dxvk_device.cpp +++ b/src/dxvk/dxvk_device.cpp @@ -35,7 +35,7 @@ namespace dxvk { Rc DxvkDevice::createContext() { - return new DxvkContext(m_vkd); + return new DxvkContext(); } diff --git a/src/dxvk/dxvk_recorder.h b/src/dxvk/dxvk_recorder.h index 7639f307b..b92723e5d 100644 --- a/src/dxvk/dxvk_recorder.h +++ b/src/dxvk/dxvk_recorder.h @@ -22,6 +22,11 @@ namespace dxvk { virtual void beginRecording() = 0; virtual void endRecording() = 0; + virtual void trackResource( + const Rc& rc) = 0; + + virtual void reset() = 0; + virtual void cmdBeginRenderPass( const VkRenderPassBeginInfo* pRenderPassBegin, VkSubpassContents contents) = 0; @@ -54,12 +59,7 @@ namespace dxvk { uint32_t vertexOffset, uint32_t firstInstance) = 0; - virtual void cmdEndRenderPass(); - - virtual void trackResource( - const Rc& rc) = 0; - - virtual void reset() = 0; + virtual void cmdEndRenderPass() = 0; };