From 4d17b1752fcb399d497e06c1a2d6cab129d9b1e5 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sat, 20 Jan 2018 18:01:43 +0100 Subject: [PATCH] [d3d11] Use EmitCs for general setup and synchronization methods --- src/d3d11/d3d11_context.cpp | 37 ++++++++++++++++++++------------- src/d3d11/d3d11_context.h | 2 +- src/d3d11/d3d11_context_imm.cpp | 14 +++++++------ 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index cd9d3bf4..04344289 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -15,8 +15,7 @@ namespace dxvk { : m_parent(parent), m_device(device) { m_context = m_device->createContext(); - m_context->beginRecording( - m_device->createCommandList()); + // Create default state objects. We won't ever return them // to the application, but we'll use them to apply state. Com defaultBlendState; @@ -30,23 +29,33 @@ namespace dxvk { // Apply default state to the context. This is required // in order to initialize the DXVK contex properly. - m_defaultBlendState = static_cast(defaultBlendState.ptr()); - m_defaultBlendState->BindToContext(m_context, 0xFFFFFFFF); - + m_defaultBlendState = static_cast (defaultBlendState.ptr()); m_defaultDepthStencilState = static_cast(defaultDepthStencilState.ptr()); - m_defaultDepthStencilState->BindToContext(m_context); - - m_defaultRasterizerState = static_cast(defaultRasterizerState.ptr()); - m_defaultRasterizerState->BindToContext(m_context); - - m_context->setBlendConstants(DxvkBlendConstants { - m_state.om.blendFactor[0], m_state.om.blendFactor[1], - m_state.om.blendFactor[2], m_state.om.blendFactor[3] }); - m_context->setStencilReference(m_state.om.stencilRef); + m_defaultRasterizerState = static_cast (defaultRasterizerState.ptr()); // Create a default sampler that we're going to bind // when the application binds null to a sampler slot. m_defaultSampler = CreateDefaultSampler(); + + EmitCs([ + dev = m_device, + bsState = m_defaultBlendState, + dsState = m_defaultDepthStencilState, + rsState = m_defaultRasterizerState, + blendConst = DxvkBlendConstants { + m_state.om.blendFactor[0], m_state.om.blendFactor[1], + m_state.om.blendFactor[2], m_state.om.blendFactor[3] }, + stencilRef = m_state.om.stencilRef + ] (DxvkContext* ctx) { + ctx->beginRecording(dev->createCommandList()); + + bsState->BindToContext(ctx, 0xFFFFFFFF); + dsState->BindToContext(ctx); + rsState->BindToContext(ctx); + + ctx->setBlendConstants (blendConst); + ctx->setStencilReference(stencilRef); + }); } diff --git a/src/d3d11/d3d11_context.h b/src/d3d11/d3d11_context.h index aad51309..9c1301ac 100644 --- a/src/d3d11/d3d11_context.h +++ b/src/d3d11/d3d11_context.h @@ -568,7 +568,7 @@ namespace dxvk { template void EmitCs(Cmd&& command) { // TODO push to CS chunk - command.execute(m_context.ptr()); + command(m_context.ptr()); } }; diff --git a/src/d3d11/d3d11_context_imm.cpp b/src/d3d11/d3d11_context_imm.cpp index ffc62d64..506f98f7 100644 --- a/src/d3d11/d3d11_context_imm.cpp +++ b/src/d3d11/d3d11_context_imm.cpp @@ -41,12 +41,14 @@ namespace dxvk { m_parent->FlushInitContext(); m_drawCount = 0; - m_device->submitCommandList( - m_context->endRecording(), - nullptr, nullptr); - - m_context->beginRecording( - m_device->createCommandList()); + EmitCs([dev = m_device] (DxvkContext* ctx) { + dev->submitCommandList( + ctx->endRecording(), + nullptr, nullptr); + + ctx->beginRecording( + dev->createCommandList()); + }); }