diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index 6d3e5f07..34083dc3 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -11,8 +11,8 @@ namespace dxvk { : m_parent(parent), m_device(device) { m_context = m_device->createContext(); - m_cmdList = m_device->createCommandList(); - m_context->beginRecording(m_cmdList); + m_context->beginRecording( + m_device->createCommandList()); } @@ -55,12 +55,12 @@ namespace dxvk { void D3D11DeviceContext::Flush() { if (m_type == D3D11_DEVICE_CONTEXT_IMMEDIATE) { - m_context->endRecording(); m_device->submitCommandList( - m_cmdList, nullptr, nullptr); + m_context->endRecording(), + nullptr, nullptr); - m_cmdList = m_device->createCommandList(); - m_context->beginRecording(m_cmdList); + m_context->beginRecording( + m_device->createCommandList()); } else { Logger::err("D3D11DeviceContext::Flush: Not supported on deferred context"); } diff --git a/src/d3d11/d3d11_context.h b/src/d3d11/d3d11_context.h index 778f233e..43ff63d6 100644 --- a/src/d3d11/d3d11_context.h +++ b/src/d3d11/d3d11_context.h @@ -545,7 +545,6 @@ namespace dxvk { Rc m_device; Rc m_context; - Rc m_cmdList; D3D11ContextState m_state; diff --git a/src/dxgi/dxgi_presenter.cpp b/src/dxgi/dxgi_presenter.cpp index 679bd723..18679712 100644 --- a/src/dxgi/dxgi_presenter.cpp +++ b/src/dxgi/dxgi_presenter.cpp @@ -9,7 +9,8 @@ namespace dxvk { HWND window, UINT bufferWidth, UINT bufferHeight) - : m_device(device) { + : m_device (device), + m_context (device->createContext()) { // Create Vulkan surface for the window HINSTANCE instance = reinterpret_cast( @@ -32,10 +33,6 @@ namespace dxvk { m_acquireSync = m_device->createSemaphore(); m_presentSync = m_device->createSemaphore(); - // Create context and a command list - m_context = m_device->createContext(); - m_commandList = m_device->createCommandList(); - // Set up context state. The shader bindings and the // constant state objects will never be modified. m_context->bindShader(VK_SHADER_STAGE_VERTEX_BIT, createVertexShader()); @@ -104,10 +101,11 @@ namespace dxvk { void DxgiPresenter::presentImage(const Rc& view) { + m_context->beginRecording( + m_device->createCommandList()); + auto framebuffer = m_swapchain->getFramebuffer(m_acquireSync); auto framebufferSize = framebuffer->size(); - - m_context->beginRecording(m_commandList); m_context->bindFramebuffer(framebuffer); VkViewport viewport; @@ -128,9 +126,9 @@ namespace dxvk { // TODO bind back buffer as a shader resource m_context->draw(4, 1, 0, 0); - m_context->endRecording(); - m_device->submitCommandList(m_commandList, + m_device->submitCommandList( + m_context->endRecording(), m_acquireSync, m_presentSync); m_swapchain->present(m_presentSync); diff --git a/src/dxgi/dxgi_presenter.h b/src/dxgi/dxgi_presenter.h index 718fad34..cda3ab5d 100644 --- a/src/dxgi/dxgi_presenter.h +++ b/src/dxgi/dxgi_presenter.h @@ -37,6 +37,7 @@ namespace dxvk { private: Rc m_device; + Rc m_context; Rc m_surface; Rc m_swapchain; @@ -44,9 +45,6 @@ namespace dxvk { Rc m_acquireSync; Rc m_presentSync; - Rc m_context; - Rc m_commandList; - Rc createVertexShader(); Rc createFragmentShader(); diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index 894bd418..2d353886 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -40,11 +40,11 @@ namespace dxvk { } - void DxvkContext::endRecording() { + Rc DxvkContext::endRecording() { this->renderPassEnd(); m_cmd->endRecording(); - m_cmd = nullptr; + return std::exchange(m_cmd, nullptr); } diff --git a/src/dxvk/dxvk_context.h b/src/dxvk/dxvk_context.h index d17a1ac2..2facb31c 100644 --- a/src/dxvk/dxvk_context.h +++ b/src/dxvk/dxvk_context.h @@ -44,8 +44,9 @@ namespace dxvk { * * This will not change any context state * other than the active command list. + * \returns Active command list */ - void endRecording(); + Rc endRecording(); /** * \brief Sets framebuffer diff --git a/tests/dxvk/test_dxvk_triangle.cpp b/tests/dxvk/test_dxvk_triangle.cpp index 1bba8991..235dfa15 100644 --- a/tests/dxvk/test_dxvk_triangle.cpp +++ b/tests/dxvk/test_dxvk_triangle.cpp @@ -76,8 +76,7 @@ public: VK_PRESENT_MODE_FIFO_KHR, VkExtent2D { 640, 480 }, })), - m_dxvkContext (m_dxvkDevice->createContext()), - m_dxvkCommandList (m_dxvkDevice->createCommandList()) { + m_dxvkContext (m_dxvkDevice->createContext()) { m_dxvkContext->setInputAssemblyState( new DxvkInputAssemblyState( @@ -135,7 +134,8 @@ public: auto fb = m_dxvkSwapchain->getFramebuffer(sync1); auto fbSize = fb->size(); - m_dxvkContext->beginRecording(m_dxvkCommandList); + m_dxvkContext->beginRecording( + m_dxvkDevice->createCommandList()); m_dxvkContext->bindFramebuffer(fb); VkViewport viewport; @@ -171,10 +171,9 @@ public: clearAttachment, clearArea); m_dxvkContext->draw(3, 1, 0, 0); - m_dxvkContext->endRecording(); auto fence = m_dxvkDevice->submitCommandList( - m_dxvkCommandList, sync1, sync2); + m_dxvkContext->endRecording(), sync1, sync2); m_dxvkSwapchain->present(sync2); m_dxvkDevice->waitForIdle(); } @@ -187,7 +186,6 @@ private: Rc m_dxvkSurface; Rc m_dxvkSwapchain; Rc m_dxvkContext; - Rc m_dxvkCommandList; Rc m_dxvkVertexShader; Rc m_dxvkFragmentShader;