[d3d11] Optimized command submission

This commit is contained in:
Philip Rebohle 2018-01-13 05:00:27 +01:00
parent 96a97aa0c4
commit ac1fe7c2b0
3 changed files with 34 additions and 15 deletions

View File

@ -165,6 +165,7 @@ namespace dxvk {
void STDMETHODCALLTYPE D3D11DeviceContext::Flush() { void STDMETHODCALLTYPE D3D11DeviceContext::Flush() {
if (m_type == D3D11_DEVICE_CONTEXT_IMMEDIATE) { if (m_type == D3D11_DEVICE_CONTEXT_IMMEDIATE) {
m_parent->FlushInitContext();
m_executedDrawCalls = 0; m_executedDrawCalls = 0;
m_device->submitCommandList( m_device->submitCommandList(
@ -1553,8 +1554,8 @@ namespace dxvk {
// number of draw calls since the last explicit flush, flush // number of draw calls since the last explicit flush, flush
// the context in order to keep the GPU busy. We'll do this // the context in order to keep the GPU busy. We'll do this
// here because we are going to start a new render pass anyway. // here because we are going to start a new render pass anyway.
if (m_executedDrawCalls >= 500) // if (m_executedDrawCalls >= 500)
this->Flush(); // this->Flush();
for (UINT i = 0; i < m_state.om.renderTargetViews.size(); i++) { for (UINT i = 0; i < m_state.om.renderTargetViews.size(); i++) {
D3D11RenderTargetView* view = nullptr; D3D11RenderTargetView* view = nullptr;

View File

@ -36,7 +36,10 @@ namespace dxvk {
m_presentDevice->SetDeviceLayer(this); m_presentDevice->SetDeviceLayer(this);
m_context = new D3D11DeviceContext(this, m_dxvkDevice); m_context = new D3D11DeviceContext(this, m_dxvkDevice);
m_resourceInitContext = m_dxvkDevice->createContext(); m_resourceInitContext = m_dxvkDevice->createContext();
m_resourceInitContext->beginRecording(
m_dxvkDevice->createCommandList());
CreateCounterBuffer(); CreateCounterBuffer();
} }
@ -1309,6 +1312,22 @@ namespace dxvk {
} }
void D3D11Device::FlushInitContext() {
auto lock = LockResourceInitContext();
if (m_resourceInitUsed) {
m_dxvkDevice->submitCommandList(
m_resourceInitContext->endRecording(),
nullptr, nullptr);
m_resourceInitContext->beginRecording(
m_dxvkDevice->createCommandList());
m_resourceInitUsed = false;
}
}
VkPipelineStageFlags D3D11Device::GetEnabledShaderStages() const { VkPipelineStageFlags D3D11Device::GetEnabledShaderStages() const {
VkPipelineStageFlags enabledShaderPipelineStages VkPipelineStageFlags enabledShaderPipelineStages
= VK_PIPELINE_STAGE_VERTEX_SHADER_BIT = VK_PIPELINE_STAGE_VERTEX_SHADER_BIT
@ -1427,17 +1446,13 @@ namespace dxvk {
= pBuffer->GetBufferSlice(); = pBuffer->GetBufferSlice();
if (pInitialData != nullptr) { if (pInitialData != nullptr) {
std::lock_guard<std::mutex> lock(m_resourceInitMutex);; auto lock = LockResourceInitContext();
m_resourceInitContext->beginRecording(
m_dxvkDevice->createCommandList());
m_resourceInitContext->updateBuffer( m_resourceInitContext->updateBuffer(
bufferSlice.buffer(), bufferSlice.buffer(),
bufferSlice.offset(), bufferSlice.offset(),
bufferSlice.length(), bufferSlice.length(),
pInitialData->pSysMem); pInitialData->pSysMem);
m_dxvkDevice->submitCommandList(
m_resourceInitContext->endRecording(),
nullptr, nullptr);
} }
} }
@ -1445,9 +1460,7 @@ namespace dxvk {
void D3D11Device::InitTexture( void D3D11Device::InitTexture(
const Rc<DxvkImage>& image, const Rc<DxvkImage>& image,
const D3D11_SUBRESOURCE_DATA* pInitialData) { const D3D11_SUBRESOURCE_DATA* pInitialData) {
std::lock_guard<std::mutex> lock(m_resourceInitMutex);; auto lock = LockResourceInitContext();
m_resourceInitContext->beginRecording(
m_dxvkDevice->createCommandList());
const DxvkFormatInfo* formatInfo = imageFormatInfo(image->info().format); const DxvkFormatInfo* formatInfo = imageFormatInfo(image->info().format);
@ -1504,10 +1517,6 @@ namespace dxvk {
image, value, subresources); image, value, subresources);
} }
} }
m_dxvkDevice->submitCommandList(
m_resourceInitContext->endRecording(),
nullptr, nullptr);
} }

View File

@ -238,6 +238,8 @@ namespace dxvk {
void FreeCounterSlice(const DxvkBufferSlice& Slice); void FreeCounterSlice(const DxvkBufferSlice& Slice);
void FlushInitContext();
VkPipelineStageFlags GetEnabledShaderStages() const; VkPipelineStageFlags GetEnabledShaderStages() const;
DxgiFormatInfo STDMETHODCALLTYPE LookupFormat( DxgiFormatInfo STDMETHODCALLTYPE LookupFormat(
@ -274,6 +276,7 @@ namespace dxvk {
std::mutex m_resourceInitMutex; std::mutex m_resourceInitMutex;
Rc<DxvkContext> m_resourceInitContext; Rc<DxvkContext> m_resourceInitContext;
bool m_resourceInitUsed = false;
D3D11StateObjectSet<D3D11BlendState> m_bsStateObjects; D3D11StateObjectSet<D3D11BlendState> m_bsStateObjects;
D3D11StateObjectSet<D3D11DepthStencilState> m_dsStateObjects; D3D11StateObjectSet<D3D11DepthStencilState> m_dsStateObjects;
@ -316,6 +319,12 @@ namespace dxvk {
void CreateCounterBuffer(); void CreateCounterBuffer();
std::unique_lock<std::mutex> LockResourceInitContext() {
auto lock = std::unique_lock<std::mutex>(m_resourceInitMutex);
m_resourceInitUsed = true;
return lock;
}
}; };
} }