1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-02-20 19:54:19 +01:00

[d3d11] Move RS* methods to D3D11CommonContext

This commit is contained in:
Philip Rebohle 2022-08-03 20:30:11 +02:00
parent 1ef9d5389b
commit 4d498851a8
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
4 changed files with 180 additions and 174 deletions

View File

@ -1168,158 +1168,6 @@ namespace dxvk {
}
void STDMETHODCALLTYPE D3D11DeviceContext::RSSetState(ID3D11RasterizerState* pRasterizerState) {
D3D10DeviceLock lock = LockContext();
auto currRasterizerState = m_state.rs.state;
auto nextRasterizerState = static_cast<D3D11RasterizerState*>(pRasterizerState);
if (m_state.rs.state != nextRasterizerState) {
m_state.rs.state = nextRasterizerState;
ApplyRasterizerState();
// If necessary, update the rasterizer sample count push constant
uint32_t currSampleCount = currRasterizerState != nullptr ? currRasterizerState->Desc()->ForcedSampleCount : 0;
uint32_t nextSampleCount = nextRasterizerState != nullptr ? nextRasterizerState->Desc()->ForcedSampleCount : 0;
if (currSampleCount != nextSampleCount)
ApplyRasterizerSampleCount();
// In D3D11, the rasterizer state defines whether the scissor test is
// enabled, so if that changes, we need to update scissor rects as well.
bool currScissorEnable = currRasterizerState != nullptr ? currRasterizerState->Desc()->ScissorEnable : false;
bool nextScissorEnable = nextRasterizerState != nullptr ? nextRasterizerState->Desc()->ScissorEnable : false;
if (currScissorEnable != nextScissorEnable)
ApplyViewportState();
}
}
void STDMETHODCALLTYPE D3D11DeviceContext::RSSetViewports(
UINT NumViewports,
const D3D11_VIEWPORT* pViewports) {
D3D10DeviceLock lock = LockContext();
if (unlikely(NumViewports > m_state.rs.viewports.size()))
return;
bool dirty = m_state.rs.numViewports != NumViewports;
m_state.rs.numViewports = NumViewports;
for (uint32_t i = 0; i < NumViewports; i++) {
const D3D11_VIEWPORT& vp = m_state.rs.viewports[i];
dirty |= vp.TopLeftX != pViewports[i].TopLeftX
|| vp.TopLeftY != pViewports[i].TopLeftY
|| vp.Width != pViewports[i].Width
|| vp.Height != pViewports[i].Height
|| vp.MinDepth != pViewports[i].MinDepth
|| vp.MaxDepth != pViewports[i].MaxDepth;
m_state.rs.viewports[i] = pViewports[i];
}
if (dirty)
ApplyViewportState();
}
void STDMETHODCALLTYPE D3D11DeviceContext::RSSetScissorRects(
UINT NumRects,
const D3D11_RECT* pRects) {
D3D10DeviceLock lock = LockContext();
if (unlikely(NumRects > m_state.rs.scissors.size()))
return;
bool dirty = m_state.rs.numScissors != NumRects;
m_state.rs.numScissors = NumRects;
for (uint32_t i = 0; i < NumRects; i++) {
if (pRects[i].bottom >= pRects[i].top
&& pRects[i].right >= pRects[i].left) {
const D3D11_RECT& sr = m_state.rs.scissors[i];
dirty |= sr.top != pRects[i].top
|| sr.left != pRects[i].left
|| sr.bottom != pRects[i].bottom
|| sr.right != pRects[i].right;
m_state.rs.scissors[i] = pRects[i];
}
}
if (m_state.rs.state != nullptr && dirty) {
D3D11_RASTERIZER_DESC rsDesc;
m_state.rs.state->GetDesc(&rsDesc);
if (rsDesc.ScissorEnable)
ApplyViewportState();
}
}
void STDMETHODCALLTYPE D3D11DeviceContext::RSGetState(ID3D11RasterizerState** ppRasterizerState) {
D3D10DeviceLock lock = LockContext();
if (ppRasterizerState != nullptr)
*ppRasterizerState = ref(m_state.rs.state);
}
void STDMETHODCALLTYPE D3D11DeviceContext::RSGetViewports(
UINT* pNumViewports,
D3D11_VIEWPORT* pViewports) {
D3D10DeviceLock lock = LockContext();
uint32_t numWritten = m_state.rs.numViewports;
if (pViewports) {
numWritten = std::min(numWritten, *pNumViewports);
for (uint32_t i = 0; i < *pNumViewports; i++) {
if (i < m_state.rs.numViewports) {
pViewports[i] = m_state.rs.viewports[i];
} else {
pViewports[i].TopLeftX = 0.0f;
pViewports[i].TopLeftY = 0.0f;
pViewports[i].Width = 0.0f;
pViewports[i].Height = 0.0f;
pViewports[i].MinDepth = 0.0f;
pViewports[i].MaxDepth = 0.0f;
}
}
}
*pNumViewports = numWritten;
}
void STDMETHODCALLTYPE D3D11DeviceContext::RSGetScissorRects(
UINT* pNumRects,
D3D11_RECT* pRects) {
D3D10DeviceLock lock = LockContext();
uint32_t numWritten = m_state.rs.numScissors;
if (pRects) {
numWritten = std::min(numWritten, *pNumRects);
for (uint32_t i = 0; i < *pNumRects; i++) {
if (i < m_state.rs.numScissors) {
pRects[i] = m_state.rs.scissors[i];
} else {
pRects[i].left = 0;
pRects[i].top = 0;
pRects[i].right = 0;
pRects[i].bottom = 0;
}
}
}
*pNumRects = m_state.rs.numScissors;
}
void STDMETHODCALLTYPE D3D11DeviceContext::SOSetTargets(
UINT NumBuffers,
ID3D11Buffer* const* ppSOTargets,

View File

@ -206,28 +206,6 @@ namespace dxvk {
ID3D11Buffer* pBufferForArgs,
UINT AlignedByteOffsetForArgs);
void STDMETHODCALLTYPE RSSetState(
ID3D11RasterizerState* pRasterizerState);
void STDMETHODCALLTYPE RSSetViewports(
UINT NumViewports,
const D3D11_VIEWPORT* pViewports);
void STDMETHODCALLTYPE RSSetScissorRects(
UINT NumRects,
const D3D11_RECT* pRects);
void STDMETHODCALLTYPE RSGetState(
ID3D11RasterizerState** ppRasterizerState);
void STDMETHODCALLTYPE RSGetViewports(
UINT* pNumViewports,
D3D11_VIEWPORT* pViewports);
void STDMETHODCALLTYPE RSGetScissorRects(
UINT* pNumRects,
D3D11_RECT* pRects);
void STDMETHODCALLTYPE SOSetTargets(
UINT NumBuffers,
ID3D11Buffer* const* ppSOTargets,

View File

@ -1502,6 +1502,164 @@ namespace dxvk {
}
template<typename ContextType>
void STDMETHODCALLTYPE D3D11CommonContext<ContextType>::RSSetState(ID3D11RasterizerState* pRasterizerState) {
D3D10DeviceLock lock = LockContext();
auto currRasterizerState = m_state.rs.state;
auto nextRasterizerState = static_cast<D3D11RasterizerState*>(pRasterizerState);
if (m_state.rs.state != nextRasterizerState) {
m_state.rs.state = nextRasterizerState;
ApplyRasterizerState();
// If necessary, update the rasterizer sample count push constant
uint32_t currSampleCount = currRasterizerState != nullptr ? currRasterizerState->Desc()->ForcedSampleCount : 0;
uint32_t nextSampleCount = nextRasterizerState != nullptr ? nextRasterizerState->Desc()->ForcedSampleCount : 0;
if (currSampleCount != nextSampleCount)
ApplyRasterizerSampleCount();
// In D3D11, the rasterizer state defines whether the scissor test is
// enabled, so if that changes, we need to update scissor rects as well.
bool currScissorEnable = currRasterizerState != nullptr ? currRasterizerState->Desc()->ScissorEnable : false;
bool nextScissorEnable = nextRasterizerState != nullptr ? nextRasterizerState->Desc()->ScissorEnable : false;
if (currScissorEnable != nextScissorEnable)
ApplyViewportState();
}
}
template<typename ContextType>
void STDMETHODCALLTYPE D3D11CommonContext<ContextType>::RSSetViewports(
UINT NumViewports,
const D3D11_VIEWPORT* pViewports) {
D3D10DeviceLock lock = LockContext();
if (unlikely(NumViewports > m_state.rs.viewports.size()))
return;
bool dirty = m_state.rs.numViewports != NumViewports;
m_state.rs.numViewports = NumViewports;
for (uint32_t i = 0; i < NumViewports; i++) {
const D3D11_VIEWPORT& vp = m_state.rs.viewports[i];
dirty |= vp.TopLeftX != pViewports[i].TopLeftX
|| vp.TopLeftY != pViewports[i].TopLeftY
|| vp.Width != pViewports[i].Width
|| vp.Height != pViewports[i].Height
|| vp.MinDepth != pViewports[i].MinDepth
|| vp.MaxDepth != pViewports[i].MaxDepth;
m_state.rs.viewports[i] = pViewports[i];
}
if (dirty)
ApplyViewportState();
}
template<typename ContextType>
void STDMETHODCALLTYPE D3D11CommonContext<ContextType>::RSSetScissorRects(
UINT NumRects,
const D3D11_RECT* pRects) {
D3D10DeviceLock lock = LockContext();
if (unlikely(NumRects > m_state.rs.scissors.size()))
return;
bool dirty = m_state.rs.numScissors != NumRects;
m_state.rs.numScissors = NumRects;
for (uint32_t i = 0; i < NumRects; i++) {
if (pRects[i].bottom >= pRects[i].top
&& pRects[i].right >= pRects[i].left) {
const D3D11_RECT& sr = m_state.rs.scissors[i];
dirty |= sr.top != pRects[i].top
|| sr.left != pRects[i].left
|| sr.bottom != pRects[i].bottom
|| sr.right != pRects[i].right;
m_state.rs.scissors[i] = pRects[i];
}
}
if (m_state.rs.state != nullptr && dirty) {
D3D11_RASTERIZER_DESC rsDesc;
m_state.rs.state->GetDesc(&rsDesc);
if (rsDesc.ScissorEnable)
ApplyViewportState();
}
}
template<typename ContextType>
void STDMETHODCALLTYPE D3D11CommonContext<ContextType>::RSGetState(ID3D11RasterizerState** ppRasterizerState) {
D3D10DeviceLock lock = LockContext();
if (ppRasterizerState)
*ppRasterizerState = ref(m_state.rs.state);
}
template<typename ContextType>
void STDMETHODCALLTYPE D3D11CommonContext<ContextType>::RSGetViewports(
UINT* pNumViewports,
D3D11_VIEWPORT* pViewports) {
D3D10DeviceLock lock = LockContext();
uint32_t numWritten = m_state.rs.numViewports;
if (pViewports) {
numWritten = std::min(numWritten, *pNumViewports);
for (uint32_t i = 0; i < *pNumViewports; i++) {
if (i < m_state.rs.numViewports) {
pViewports[i] = m_state.rs.viewports[i];
} else {
pViewports[i].TopLeftX = 0.0f;
pViewports[i].TopLeftY = 0.0f;
pViewports[i].Width = 0.0f;
pViewports[i].Height = 0.0f;
pViewports[i].MinDepth = 0.0f;
pViewports[i].MaxDepth = 0.0f;
}
}
}
*pNumViewports = numWritten;
}
template<typename ContextType>
void STDMETHODCALLTYPE D3D11CommonContext<ContextType>::RSGetScissorRects(
UINT* pNumRects,
D3D11_RECT* pRects) {
D3D10DeviceLock lock = LockContext();
uint32_t numWritten = m_state.rs.numScissors;
if (pRects) {
numWritten = std::min(numWritten, *pNumRects);
for (uint32_t i = 0; i < *pNumRects; i++) {
if (i < m_state.rs.numScissors) {
pRects[i] = m_state.rs.scissors[i];
} else {
pRects[i].left = 0;
pRects[i].top = 0;
pRects[i].right = 0;
pRects[i].bottom = 0;
}
}
}
*pNumRects = m_state.rs.numScissors;
}
template<typename ContextType>
BOOL STDMETHODCALLTYPE D3D11CommonContext<ContextType>::IsAnnotationEnabled() {
return m_annotation.GetStatus();

View File

@ -503,6 +503,28 @@ namespace dxvk {
ID3D11DepthStencilState** ppDepthStencilState,
UINT* pStencilRef);
void STDMETHODCALLTYPE RSSetState(
ID3D11RasterizerState* pRasterizerState);
void STDMETHODCALLTYPE RSSetViewports(
UINT NumViewports,
const D3D11_VIEWPORT* pViewports);
void STDMETHODCALLTYPE RSSetScissorRects(
UINT NumRects,
const D3D11_RECT* pRects);
void STDMETHODCALLTYPE RSGetState(
ID3D11RasterizerState** ppRasterizerState);
void STDMETHODCALLTYPE RSGetViewports(
UINT* pNumViewports,
D3D11_VIEWPORT* pViewports);
void STDMETHODCALLTYPE RSGetScissorRects(
UINT* pNumRects,
D3D11_RECT* pRects);
BOOL STDMETHODCALLTYPE IsAnnotationEnabled();
protected: