From e0ee06a279e050237f2be0e3ba94883078daffc4 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 3 Aug 2022 18:15:32 +0200 Subject: [PATCH] [d3d11] Move IA* functions to D3D11CommonContext --- src/d3d11/d3d11_context.cpp | 147 --------------------------- src/d3d11/d3d11_context.h | 36 ------- src/d3d11/d3d11_context_common.cpp | 155 +++++++++++++++++++++++++++++ src/d3d11/d3d11_context_common.h | 36 +++++++ 4 files changed, 191 insertions(+), 183 deletions(-) diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index 0d4b27f55..92c356629 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -1284,153 +1284,6 @@ namespace dxvk { } - void STDMETHODCALLTYPE D3D11DeviceContext::IASetInputLayout(ID3D11InputLayout* pInputLayout) { - D3D10DeviceLock lock = LockContext(); - - auto inputLayout = static_cast(pInputLayout); - - if (m_state.ia.inputLayout != inputLayout) { - bool equal = false; - - // Some games (e.g. Grim Dawn) create lots and lots of - // identical input layouts, so we'll only apply the state - // if the input layouts has actually changed between calls. - if (m_state.ia.inputLayout != nullptr && inputLayout != nullptr) - equal = m_state.ia.inputLayout->Compare(inputLayout); - - m_state.ia.inputLayout = inputLayout; - - if (!equal) - ApplyInputLayout(); - } - } - - - void STDMETHODCALLTYPE D3D11DeviceContext::IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY Topology) { - D3D10DeviceLock lock = LockContext(); - - if (m_state.ia.primitiveTopology != Topology) { - m_state.ia.primitiveTopology = Topology; - ApplyPrimitiveTopology(); - } - } - - - void STDMETHODCALLTYPE D3D11DeviceContext::IASetVertexBuffers( - UINT StartSlot, - UINT NumBuffers, - ID3D11Buffer* const* ppVertexBuffers, - const UINT* pStrides, - const UINT* pOffsets) { - D3D10DeviceLock lock = LockContext(); - - for (uint32_t i = 0; i < NumBuffers; i++) { - auto newBuffer = static_cast(ppVertexBuffers[i]); - bool needsUpdate = m_state.ia.vertexBuffers[StartSlot + i].buffer != newBuffer; - - if (needsUpdate) - m_state.ia.vertexBuffers[StartSlot + i].buffer = newBuffer; - - needsUpdate |= m_state.ia.vertexBuffers[StartSlot + i].offset != pOffsets[i] - || m_state.ia.vertexBuffers[StartSlot + i].stride != pStrides[i]; - - if (needsUpdate) { - m_state.ia.vertexBuffers[StartSlot + i].offset = pOffsets[i]; - m_state.ia.vertexBuffers[StartSlot + i].stride = pStrides[i]; - - BindVertexBuffer(StartSlot + i, newBuffer, pOffsets[i], pStrides[i]); - } - } - } - - - void STDMETHODCALLTYPE D3D11DeviceContext::IASetIndexBuffer( - ID3D11Buffer* pIndexBuffer, - DXGI_FORMAT Format, - UINT Offset) { - D3D10DeviceLock lock = LockContext(); - - auto newBuffer = static_cast(pIndexBuffer); - bool needsUpdate = m_state.ia.indexBuffer.buffer != newBuffer; - - if (needsUpdate) - m_state.ia.indexBuffer.buffer = newBuffer; - - needsUpdate |= m_state.ia.indexBuffer.offset != Offset - || m_state.ia.indexBuffer.format != Format; - - if (needsUpdate) { - m_state.ia.indexBuffer.offset = Offset; - m_state.ia.indexBuffer.format = Format; - - BindIndexBuffer(newBuffer, Offset, Format); - } - } - - - void STDMETHODCALLTYPE D3D11DeviceContext::IAGetInputLayout(ID3D11InputLayout** ppInputLayout) { - D3D10DeviceLock lock = LockContext(); - - *ppInputLayout = m_state.ia.inputLayout.ref(); - } - - - void STDMETHODCALLTYPE D3D11DeviceContext::IAGetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY* pTopology) { - D3D10DeviceLock lock = LockContext(); - - *pTopology = m_state.ia.primitiveTopology; - } - - - void STDMETHODCALLTYPE D3D11DeviceContext::IAGetVertexBuffers( - UINT StartSlot, - UINT NumBuffers, - ID3D11Buffer** ppVertexBuffers, - UINT* pStrides, - UINT* pOffsets) { - D3D10DeviceLock lock = LockContext(); - - for (uint32_t i = 0; i < NumBuffers; i++) { - const bool inRange = StartSlot + i < m_state.ia.vertexBuffers.size(); - - if (ppVertexBuffers != nullptr) { - ppVertexBuffers[i] = inRange - ? m_state.ia.vertexBuffers[StartSlot + i].buffer.ref() - : nullptr; - } - - if (pStrides != nullptr) { - pStrides[i] = inRange - ? m_state.ia.vertexBuffers[StartSlot + i].stride - : 0u; - } - - if (pOffsets != nullptr) { - pOffsets[i] = inRange - ? m_state.ia.vertexBuffers[StartSlot + i].offset - : 0u; - } - } - } - - - void STDMETHODCALLTYPE D3D11DeviceContext::IAGetIndexBuffer( - ID3D11Buffer** ppIndexBuffer, - DXGI_FORMAT* pFormat, - UINT* pOffset) { - D3D10DeviceLock lock = LockContext(); - - if (ppIndexBuffer != nullptr) - *ppIndexBuffer = m_state.ia.indexBuffer.buffer.ref(); - - if (pFormat != nullptr) - *pFormat = m_state.ia.indexBuffer.format; - - if (pOffset != nullptr) - *pOffset = m_state.ia.indexBuffer.offset; - } - - void STDMETHODCALLTYPE D3D11DeviceContext::VSSetShader( ID3D11VertexShader* pVertexShader, ID3D11ClassInstance* const* ppClassInstances, diff --git a/src/d3d11/d3d11_context.h b/src/d3d11/d3d11_context.h index 21e5d4c03..e538a1cc6 100644 --- a/src/d3d11/d3d11_context.h +++ b/src/d3d11/d3d11_context.h @@ -208,42 +208,6 @@ namespace dxvk { ID3D11Buffer* pBufferForArgs, UINT AlignedByteOffsetForArgs); - void STDMETHODCALLTYPE IASetInputLayout( - ID3D11InputLayout* pInputLayout); - - void STDMETHODCALLTYPE IASetPrimitiveTopology( - D3D11_PRIMITIVE_TOPOLOGY Topology); - - void STDMETHODCALLTYPE IASetVertexBuffers( - UINT StartSlot, - UINT NumBuffers, - ID3D11Buffer* const* ppVertexBuffers, - const UINT* pStrides, - const UINT* pOffsets); - - void STDMETHODCALLTYPE IASetIndexBuffer( - ID3D11Buffer* pIndexBuffer, - DXGI_FORMAT Format, - UINT Offset); - - void STDMETHODCALLTYPE IAGetInputLayout( - ID3D11InputLayout** ppInputLayout); - - void STDMETHODCALLTYPE IAGetPrimitiveTopology( - D3D11_PRIMITIVE_TOPOLOGY* pTopology); - - void STDMETHODCALLTYPE IAGetVertexBuffers( - UINT StartSlot, - UINT NumBuffers, - ID3D11Buffer** ppVertexBuffers, - UINT* pStrides, - UINT* pOffsets); - - void STDMETHODCALLTYPE IAGetIndexBuffer( - ID3D11Buffer** ppIndexBuffer, - DXGI_FORMAT* pFormat, - UINT* pOffset); - void STDMETHODCALLTYPE VSSetShader( ID3D11VertexShader* pVertexShader, ID3D11ClassInstance* const* ppClassInstances, diff --git a/src/d3d11/d3d11_context_common.cpp b/src/d3d11/d3d11_context_common.cpp index 3e7430598..62410db1c 100644 --- a/src/d3d11/d3d11_context_common.cpp +++ b/src/d3d11/d3d11_context_common.cpp @@ -90,6 +90,161 @@ namespace dxvk { } + template + void STDMETHODCALLTYPE D3D11CommonContext::IASetInputLayout(ID3D11InputLayout* pInputLayout) { + D3D10DeviceLock lock = LockContext(); + + auto inputLayout = static_cast(pInputLayout); + + if (m_state.ia.inputLayout != inputLayout) { + bool equal = false; + + // Some games (e.g. Grim Dawn) create lots and lots of + // identical input layouts, so we'll only apply the state + // if the input layouts has actually changed between calls. + if (m_state.ia.inputLayout != nullptr && inputLayout != nullptr) + equal = m_state.ia.inputLayout->Compare(inputLayout); + + m_state.ia.inputLayout = inputLayout; + + if (!equal) + ApplyInputLayout(); + } + } + + + template + void STDMETHODCALLTYPE D3D11CommonContext::IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY Topology) { + D3D10DeviceLock lock = LockContext(); + + if (m_state.ia.primitiveTopology != Topology) { + m_state.ia.primitiveTopology = Topology; + ApplyPrimitiveTopology(); + } + } + + + template + void STDMETHODCALLTYPE D3D11CommonContext::IASetVertexBuffers( + UINT StartSlot, + UINT NumBuffers, + ID3D11Buffer* const* ppVertexBuffers, + const UINT* pStrides, + const UINT* pOffsets) { + D3D10DeviceLock lock = LockContext(); + + for (uint32_t i = 0; i < NumBuffers; i++) { + auto newBuffer = static_cast(ppVertexBuffers[i]); + bool needsUpdate = m_state.ia.vertexBuffers[StartSlot + i].buffer != newBuffer; + + if (needsUpdate) + m_state.ia.vertexBuffers[StartSlot + i].buffer = newBuffer; + + needsUpdate |= m_state.ia.vertexBuffers[StartSlot + i].offset != pOffsets[i] + || m_state.ia.vertexBuffers[StartSlot + i].stride != pStrides[i]; + + if (needsUpdate) { + m_state.ia.vertexBuffers[StartSlot + i].offset = pOffsets[i]; + m_state.ia.vertexBuffers[StartSlot + i].stride = pStrides[i]; + + BindVertexBuffer(StartSlot + i, newBuffer, pOffsets[i], pStrides[i]); + } + } + } + + + template + void STDMETHODCALLTYPE D3D11CommonContext::IASetIndexBuffer( + ID3D11Buffer* pIndexBuffer, + DXGI_FORMAT Format, + UINT Offset) { + D3D10DeviceLock lock = LockContext(); + + auto newBuffer = static_cast(pIndexBuffer); + bool needsUpdate = m_state.ia.indexBuffer.buffer != newBuffer; + + if (needsUpdate) + m_state.ia.indexBuffer.buffer = newBuffer; + + needsUpdate |= m_state.ia.indexBuffer.offset != Offset + || m_state.ia.indexBuffer.format != Format; + + if (needsUpdate) { + m_state.ia.indexBuffer.offset = Offset; + m_state.ia.indexBuffer.format = Format; + + BindIndexBuffer(newBuffer, Offset, Format); + } + } + + + template + void STDMETHODCALLTYPE D3D11CommonContext::IAGetInputLayout(ID3D11InputLayout** ppInputLayout) { + D3D10DeviceLock lock = LockContext(); + + *ppInputLayout = m_state.ia.inputLayout.ref(); + } + + + template + void STDMETHODCALLTYPE D3D11CommonContext::IAGetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY* pTopology) { + D3D10DeviceLock lock = LockContext(); + + *pTopology = m_state.ia.primitiveTopology; + } + + + template + void STDMETHODCALLTYPE D3D11CommonContext::IAGetVertexBuffers( + UINT StartSlot, + UINT NumBuffers, + ID3D11Buffer** ppVertexBuffers, + UINT* pStrides, + UINT* pOffsets) { + D3D10DeviceLock lock = LockContext(); + + for (uint32_t i = 0; i < NumBuffers; i++) { + const bool inRange = StartSlot + i < m_state.ia.vertexBuffers.size(); + + if (ppVertexBuffers) { + ppVertexBuffers[i] = inRange + ? m_state.ia.vertexBuffers[StartSlot + i].buffer.ref() + : nullptr; + } + + if (pStrides) { + pStrides[i] = inRange + ? m_state.ia.vertexBuffers[StartSlot + i].stride + : 0u; + } + + if (pOffsets) { + pOffsets[i] = inRange + ? m_state.ia.vertexBuffers[StartSlot + i].offset + : 0u; + } + } + } + + + template + void STDMETHODCALLTYPE D3D11CommonContext::IAGetIndexBuffer( + ID3D11Buffer** ppIndexBuffer, + DXGI_FORMAT* pFormat, + UINT* pOffset) { + D3D10DeviceLock lock = LockContext(); + + if (ppIndexBuffer) + *ppIndexBuffer = m_state.ia.indexBuffer.buffer.ref(); + + if (pFormat) + *pFormat = m_state.ia.indexBuffer.format; + + if (pOffset) + *pOffset = m_state.ia.indexBuffer.offset; + } + + template void STDMETHODCALLTYPE D3D11CommonContext::OMSetRenderTargets( UINT NumViews, diff --git a/src/d3d11/d3d11_context_common.h b/src/d3d11/d3d11_context_common.h index 6827063e8..a1c249301 100644 --- a/src/d3d11/d3d11_context_common.h +++ b/src/d3d11/d3d11_context_common.h @@ -85,6 +85,42 @@ namespace dxvk { UINT SrcDepthPitch, UINT CopyFlags); + void STDMETHODCALLTYPE IASetInputLayout( + ID3D11InputLayout* pInputLayout); + + void STDMETHODCALLTYPE IASetPrimitiveTopology( + D3D11_PRIMITIVE_TOPOLOGY Topology); + + void STDMETHODCALLTYPE IASetVertexBuffers( + UINT StartSlot, + UINT NumBuffers, + ID3D11Buffer* const* ppVertexBuffers, + const UINT* pStrides, + const UINT* pOffsets); + + void STDMETHODCALLTYPE IASetIndexBuffer( + ID3D11Buffer* pIndexBuffer, + DXGI_FORMAT Format, + UINT Offset); + + void STDMETHODCALLTYPE IAGetInputLayout( + ID3D11InputLayout** ppInputLayout); + + void STDMETHODCALLTYPE IAGetPrimitiveTopology( + D3D11_PRIMITIVE_TOPOLOGY* pTopology); + + void STDMETHODCALLTYPE IAGetVertexBuffers( + UINT StartSlot, + UINT NumBuffers, + ID3D11Buffer** ppVertexBuffers, + UINT* pStrides, + UINT* pOffsets); + + void STDMETHODCALLTYPE IAGetIndexBuffer( + ID3D11Buffer** ppIndexBuffer, + DXGI_FORMAT* pFormat, + UINT* pOffset); + void STDMETHODCALLTYPE OMSetRenderTargets( UINT NumViews, ID3D11RenderTargetView* const* ppRenderTargetViews,