1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-03-14 22:29:15 +01:00

[dxvk] More convenient command list assignment API

This commit is contained in:
Philip Rebohle 2017-12-01 10:08:49 +01:00
parent 27905d0711
commit 4e39ef859b
7 changed files with 22 additions and 28 deletions

View File

@ -11,8 +11,8 @@ namespace dxvk {
: m_parent(parent), : m_parent(parent),
m_device(device) { m_device(device) {
m_context = m_device->createContext(); m_context = m_device->createContext();
m_cmdList = m_device->createCommandList(); m_context->beginRecording(
m_context->beginRecording(m_cmdList); m_device->createCommandList());
} }
@ -55,12 +55,12 @@ namespace dxvk {
void D3D11DeviceContext::Flush() { void D3D11DeviceContext::Flush() {
if (m_type == D3D11_DEVICE_CONTEXT_IMMEDIATE) { if (m_type == D3D11_DEVICE_CONTEXT_IMMEDIATE) {
m_context->endRecording();
m_device->submitCommandList( m_device->submitCommandList(
m_cmdList, nullptr, nullptr); m_context->endRecording(),
nullptr, nullptr);
m_cmdList = m_device->createCommandList(); m_context->beginRecording(
m_context->beginRecording(m_cmdList); m_device->createCommandList());
} else { } else {
Logger::err("D3D11DeviceContext::Flush: Not supported on deferred context"); Logger::err("D3D11DeviceContext::Flush: Not supported on deferred context");
} }

View File

@ -545,7 +545,6 @@ namespace dxvk {
Rc<DxvkDevice> m_device; Rc<DxvkDevice> m_device;
Rc<DxvkContext> m_context; Rc<DxvkContext> m_context;
Rc<DxvkCommandList> m_cmdList;
D3D11ContextState m_state; D3D11ContextState m_state;

View File

@ -9,7 +9,8 @@ namespace dxvk {
HWND window, HWND window,
UINT bufferWidth, UINT bufferWidth,
UINT bufferHeight) UINT bufferHeight)
: m_device(device) { : m_device (device),
m_context (device->createContext()) {
// Create Vulkan surface for the window // Create Vulkan surface for the window
HINSTANCE instance = reinterpret_cast<HINSTANCE>( HINSTANCE instance = reinterpret_cast<HINSTANCE>(
@ -32,10 +33,6 @@ namespace dxvk {
m_acquireSync = m_device->createSemaphore(); m_acquireSync = m_device->createSemaphore();
m_presentSync = 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 // Set up context state. The shader bindings and the
// constant state objects will never be modified. // constant state objects will never be modified.
m_context->bindShader(VK_SHADER_STAGE_VERTEX_BIT, createVertexShader()); m_context->bindShader(VK_SHADER_STAGE_VERTEX_BIT, createVertexShader());
@ -104,10 +101,11 @@ namespace dxvk {
void DxgiPresenter::presentImage(const Rc<DxvkImageView>& view) { void DxgiPresenter::presentImage(const Rc<DxvkImageView>& view) {
m_context->beginRecording(
m_device->createCommandList());
auto framebuffer = m_swapchain->getFramebuffer(m_acquireSync); auto framebuffer = m_swapchain->getFramebuffer(m_acquireSync);
auto framebufferSize = framebuffer->size(); auto framebufferSize = framebuffer->size();
m_context->beginRecording(m_commandList);
m_context->bindFramebuffer(framebuffer); m_context->bindFramebuffer(framebuffer);
VkViewport viewport; VkViewport viewport;
@ -128,9 +126,9 @@ namespace dxvk {
// TODO bind back buffer as a shader resource // TODO bind back buffer as a shader resource
m_context->draw(4, 1, 0, 0); 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_acquireSync, m_presentSync);
m_swapchain->present(m_presentSync); m_swapchain->present(m_presentSync);

View File

@ -37,6 +37,7 @@ namespace dxvk {
private: private:
Rc<DxvkDevice> m_device; Rc<DxvkDevice> m_device;
Rc<DxvkContext> m_context;
Rc<DxvkSurface> m_surface; Rc<DxvkSurface> m_surface;
Rc<DxvkSwapchain> m_swapchain; Rc<DxvkSwapchain> m_swapchain;
@ -44,9 +45,6 @@ namespace dxvk {
Rc<DxvkSemaphore> m_acquireSync; Rc<DxvkSemaphore> m_acquireSync;
Rc<DxvkSemaphore> m_presentSync; Rc<DxvkSemaphore> m_presentSync;
Rc<DxvkContext> m_context;
Rc<DxvkCommandList> m_commandList;
Rc<DxvkShader> createVertexShader(); Rc<DxvkShader> createVertexShader();
Rc<DxvkShader> createFragmentShader(); Rc<DxvkShader> createFragmentShader();

View File

@ -40,11 +40,11 @@ namespace dxvk {
} }
void DxvkContext::endRecording() { Rc<DxvkCommandList> DxvkContext::endRecording() {
this->renderPassEnd(); this->renderPassEnd();
m_cmd->endRecording(); m_cmd->endRecording();
m_cmd = nullptr; return std::exchange(m_cmd, nullptr);
} }

View File

@ -44,8 +44,9 @@ namespace dxvk {
* *
* This will not change any context state * This will not change any context state
* other than the active command list. * other than the active command list.
* \returns Active command list
*/ */
void endRecording(); Rc<DxvkCommandList> endRecording();
/** /**
* \brief Sets framebuffer * \brief Sets framebuffer

View File

@ -76,8 +76,7 @@ public:
VK_PRESENT_MODE_FIFO_KHR, VK_PRESENT_MODE_FIFO_KHR,
VkExtent2D { 640, 480 }, VkExtent2D { 640, 480 },
})), })),
m_dxvkContext (m_dxvkDevice->createContext()), m_dxvkContext (m_dxvkDevice->createContext()) {
m_dxvkCommandList (m_dxvkDevice->createCommandList()) {
m_dxvkContext->setInputAssemblyState( m_dxvkContext->setInputAssemblyState(
new DxvkInputAssemblyState( new DxvkInputAssemblyState(
@ -135,7 +134,8 @@ public:
auto fb = m_dxvkSwapchain->getFramebuffer(sync1); auto fb = m_dxvkSwapchain->getFramebuffer(sync1);
auto fbSize = fb->size(); auto fbSize = fb->size();
m_dxvkContext->beginRecording(m_dxvkCommandList); m_dxvkContext->beginRecording(
m_dxvkDevice->createCommandList());
m_dxvkContext->bindFramebuffer(fb); m_dxvkContext->bindFramebuffer(fb);
VkViewport viewport; VkViewport viewport;
@ -171,10 +171,9 @@ public:
clearAttachment, clearAttachment,
clearArea); clearArea);
m_dxvkContext->draw(3, 1, 0, 0); m_dxvkContext->draw(3, 1, 0, 0);
m_dxvkContext->endRecording();
auto fence = m_dxvkDevice->submitCommandList( auto fence = m_dxvkDevice->submitCommandList(
m_dxvkCommandList, sync1, sync2); m_dxvkContext->endRecording(), sync1, sync2);
m_dxvkSwapchain->present(sync2); m_dxvkSwapchain->present(sync2);
m_dxvkDevice->waitForIdle(); m_dxvkDevice->waitForIdle();
} }
@ -187,7 +186,6 @@ private:
Rc<DxvkSurface> m_dxvkSurface; Rc<DxvkSurface> m_dxvkSurface;
Rc<DxvkSwapchain> m_dxvkSwapchain; Rc<DxvkSwapchain> m_dxvkSwapchain;
Rc<DxvkContext> m_dxvkContext; Rc<DxvkContext> m_dxvkContext;
Rc<DxvkCommandList> m_dxvkCommandList;
Rc<DxvkShader> m_dxvkVertexShader; Rc<DxvkShader> m_dxvkVertexShader;
Rc<DxvkShader> m_dxvkFragmentShader; Rc<DxvkShader> m_dxvkFragmentShader;