From 2591bbdabd3e3239d2ceacc2dbaec23ed5f200b8 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sun, 18 Mar 2018 22:53:20 +0100 Subject: [PATCH] [d3d11] Implemented ID3D11RasterizerState1 stub --- src/d3d11/d3d11_device.cpp | 35 +++++++++---------- src/d3d11/d3d11_rasterizer.cpp | 61 +++++++++++++++++++++++++++++++++- src/d3d11/d3d11_rasterizer.h | 23 +++++++++---- src/d3d11/d3d11_state.cpp | 10 +++--- src/d3d11/d3d11_state.h | 4 +-- 5 files changed, 103 insertions(+), 30 deletions(-) diff --git a/src/d3d11/d3d11_device.cpp b/src/d3d11/d3d11_device.cpp index 0a97e73fd..94983fc25 100644 --- a/src/d3d11/d3d11_device.cpp +++ b/src/d3d11/d3d11_device.cpp @@ -1152,22 +1152,12 @@ namespace dxvk { HRESULT STDMETHODCALLTYPE D3D11Device::CreateRasterizerState( const D3D11_RASTERIZER_DESC* pRasterizerDesc, ID3D11RasterizerState** ppRasterizerState) { - D3D11_RASTERIZER_DESC desc; + D3D11_RASTERIZER_DESC1 desc = pRasterizerDesc != nullptr + ? D3D11RasterizerState::PromoteDesc(pRasterizerDesc) + : D3D11RasterizerState::DefaultDesc(); - if (pRasterizerDesc != nullptr) { - desc = *pRasterizerDesc; - } else { - desc.FillMode = D3D11_FILL_SOLID; - desc.CullMode = D3D11_CULL_BACK; - desc.FrontCounterClockwise = FALSE; - desc.DepthBias = 0; - desc.SlopeScaledDepthBias = 0.0f; - desc.DepthBiasClamp = 0.0f; - desc.DepthClipEnable = TRUE; - desc.ScissorEnable = FALSE; - desc.MultisampleEnable = FALSE; - desc.AntialiasedLineEnable = FALSE; - } + if (FAILED(D3D11RasterizerState::NormalizeDesc(&desc))) + return E_INVALIDARG; if (ppRasterizerState != nullptr) { *ppRasterizerState = m_rsStateObjects.Create(this, desc); @@ -1175,13 +1165,24 @@ namespace dxvk { } return S_FALSE; } + HRESULT D3D11Device::CreateRasterizerState1( const D3D11_RASTERIZER_DESC1* pRasterizerDesc, ID3D11RasterizerState1** ppRasterizerState) { - Logger::err("D3D11Device::CreateRasterizerState1: Not implemented"); - return E_NOTIMPL; + D3D11_RASTERIZER_DESC1 desc = pRasterizerDesc != nullptr + ? *pRasterizerDesc + : D3D11RasterizerState::DefaultDesc(); + + if (FAILED(D3D11RasterizerState::NormalizeDesc(&desc))) + return E_INVALIDARG; + + if (ppRasterizerState != nullptr) { + *ppRasterizerState = m_rsStateObjects.Create(this, desc); + return S_OK; + } return S_FALSE; } + HRESULT STDMETHODCALLTYPE D3D11Device::CreateSamplerState( const D3D11_SAMPLER_DESC* pSamplerDesc, ID3D11SamplerState** ppSamplerState) { diff --git a/src/d3d11/d3d11_rasterizer.cpp b/src/d3d11/d3d11_rasterizer.cpp index 739b00a4a..98d53011f 100644 --- a/src/d3d11/d3d11_rasterizer.cpp +++ b/src/d3d11/d3d11_rasterizer.cpp @@ -5,7 +5,7 @@ namespace dxvk { D3D11RasterizerState::D3D11RasterizerState( D3D11Device* device, - const D3D11_RASTERIZER_DESC& desc) + const D3D11_RASTERIZER_DESC1& desc) : m_device(device), m_desc(desc) { // State that is not supported in D3D11 @@ -57,6 +57,9 @@ namespace dxvk { if (desc.AntialiasedLineEnable) Logger::err("D3D11RasterizerState: Antialiased lines not supported"); + + if (desc.ForcedSampleCount) + Logger::err("D3D11RasterizerState: Forced sample count not supported"); } @@ -82,6 +85,20 @@ namespace dxvk { void STDMETHODCALLTYPE D3D11RasterizerState::GetDesc(D3D11_RASTERIZER_DESC* pDesc) { + pDesc->FillMode = m_desc.FillMode; + pDesc->CullMode = m_desc.CullMode; + pDesc->FrontCounterClockwise = m_desc.FrontCounterClockwise; + pDesc->DepthBias = m_desc.DepthBias; + pDesc->DepthBiasClamp = m_desc.DepthBiasClamp; + pDesc->SlopeScaledDepthBias = m_desc.SlopeScaledDepthBias; + pDesc->DepthClipEnable = m_desc.DepthClipEnable; + pDesc->ScissorEnable = m_desc.ScissorEnable; + pDesc->MultisampleEnable = m_desc.MultisampleEnable; + pDesc->AntialiasedLineEnable = m_desc.AntialiasedLineEnable; + } + + + void STDMETHODCALLTYPE D3D11RasterizerState::GetDesc1(D3D11_RASTERIZER_DESC1* pDesc) { *pDesc = m_desc; } @@ -90,4 +107,46 @@ namespace dxvk { ctx->setRasterizerState(m_state); } + + D3D11_RASTERIZER_DESC1 D3D11RasterizerState::DefaultDesc() { + D3D11_RASTERIZER_DESC1 dstDesc; + dstDesc.FillMode = D3D11_FILL_SOLID; + dstDesc.CullMode = D3D11_CULL_BACK; + dstDesc.FrontCounterClockwise = FALSE; + dstDesc.DepthBias = 0; + dstDesc.SlopeScaledDepthBias = 0.0f; + dstDesc.DepthBiasClamp = 0.0f; + dstDesc.DepthClipEnable = TRUE; + dstDesc.ScissorEnable = FALSE; + dstDesc.MultisampleEnable = FALSE; + dstDesc.AntialiasedLineEnable = FALSE; + dstDesc.ForcedSampleCount = 0; + return dstDesc; + } + + + D3D11_RASTERIZER_DESC1 D3D11RasterizerState::PromoteDesc( + const D3D11_RASTERIZER_DESC* pSrcDesc) { + D3D11_RASTERIZER_DESC1 dstDesc; + dstDesc.FillMode = pSrcDesc->FillMode; + dstDesc.CullMode = pSrcDesc->CullMode; + dstDesc.FrontCounterClockwise = pSrcDesc->FrontCounterClockwise; + dstDesc.DepthBias = pSrcDesc->DepthBias; + dstDesc.DepthBiasClamp = pSrcDesc->DepthBiasClamp; + dstDesc.SlopeScaledDepthBias = pSrcDesc->SlopeScaledDepthBias; + dstDesc.DepthClipEnable = pSrcDesc->DepthClipEnable; + dstDesc.ScissorEnable = pSrcDesc->ScissorEnable; + dstDesc.MultisampleEnable = pSrcDesc->MultisampleEnable; + dstDesc.AntialiasedLineEnable = pSrcDesc->AntialiasedLineEnable; + dstDesc.ForcedSampleCount = 0; + return dstDesc; + } + + + HRESULT D3D11RasterizerState::NormalizeDesc( + D3D11_RASTERIZER_DESC1* pDesc) { + // TODO validate + return S_OK; + } + } \ No newline at end of file diff --git a/src/d3d11/d3d11_rasterizer.h b/src/d3d11/d3d11_rasterizer.h index 9538bc57a..91c3fc8db 100644 --- a/src/d3d11/d3d11_rasterizer.h +++ b/src/d3d11/d3d11_rasterizer.h @@ -8,15 +8,15 @@ namespace dxvk { class D3D11Device; - class D3D11RasterizerState : public D3D11DeviceChild { + class D3D11RasterizerState : public D3D11DeviceChild { public: - using DescType = D3D11_RASTERIZER_DESC; + using DescType = D3D11_RASTERIZER_DESC1; D3D11RasterizerState( D3D11Device* device, - const D3D11_RASTERIZER_DESC& desc); + const D3D11_RASTERIZER_DESC1& desc); ~D3D11RasterizerState(); HRESULT STDMETHODCALLTYPE QueryInterface( @@ -29,14 +29,25 @@ namespace dxvk { void STDMETHODCALLTYPE GetDesc( D3D11_RASTERIZER_DESC* pDesc) final; + void STDMETHODCALLTYPE GetDesc1( + D3D11_RASTERIZER_DESC1* pDesc) final; + void BindToContext( const Rc& ctx); + static D3D11_RASTERIZER_DESC1 DefaultDesc(); + + static D3D11_RASTERIZER_DESC1 PromoteDesc( + const D3D11_RASTERIZER_DESC* pDesc); + + static HRESULT NormalizeDesc( + D3D11_RASTERIZER_DESC1* pDesc); + private: - D3D11Device* const m_device; - D3D11_RASTERIZER_DESC m_desc; - DxvkRasterizerState m_state; + D3D11Device* const m_device; + D3D11_RASTERIZER_DESC1 m_desc; + DxvkRasterizerState m_state; }; diff --git a/src/d3d11/d3d11_state.cpp b/src/d3d11/d3d11_state.cpp index 3896a3cf5..9c1e767b6 100644 --- a/src/d3d11/d3d11_state.cpp +++ b/src/d3d11/d3d11_state.cpp @@ -46,7 +46,7 @@ namespace dxvk { size_t D3D11StateDescHash::operator () ( - const D3D11_RASTERIZER_DESC& desc) const { + const D3D11_RASTERIZER_DESC1& desc) const { DxvkHashState hash; hash.add(desc.FillMode); hash.add(desc.CullMode); @@ -58,6 +58,7 @@ namespace dxvk { hash.add(desc.ScissorEnable); hash.add(desc.MultisampleEnable); hash.add(desc.AntialiasedLineEnable); + hash.add(desc.ForcedSampleCount); return hash; } @@ -139,8 +140,8 @@ namespace dxvk { bool D3D11StateDescEqual::operator () ( - const D3D11_RASTERIZER_DESC& a, - const D3D11_RASTERIZER_DESC& b) const { + const D3D11_RASTERIZER_DESC1& a, + const D3D11_RASTERIZER_DESC1& b) const { return a.FillMode == b.FillMode && a.CullMode == b.CullMode && a.FrontCounterClockwise == b.FrontCounterClockwise @@ -150,7 +151,8 @@ namespace dxvk { && a.DepthClipEnable == b.DepthClipEnable && a.ScissorEnable == b.ScissorEnable && a.MultisampleEnable == b.MultisampleEnable - && a.AntialiasedLineEnable == b.AntialiasedLineEnable; + && a.AntialiasedLineEnable == b.AntialiasedLineEnable + && a.ForcedSampleCount == b.ForcedSampleCount; } diff --git a/src/d3d11/d3d11_state.h b/src/d3d11/d3d11_state.h index b4a2d36b2..7babe8bde 100644 --- a/src/d3d11/d3d11_state.h +++ b/src/d3d11/d3d11_state.h @@ -15,7 +15,7 @@ namespace dxvk { size_t operator () (const D3D11_BLEND_DESC& desc) const; size_t operator () (const D3D11_DEPTH_STENCILOP_DESC& desc) const; size_t operator () (const D3D11_DEPTH_STENCIL_DESC& desc) const; - size_t operator () (const D3D11_RASTERIZER_DESC& desc) const; + size_t operator () (const D3D11_RASTERIZER_DESC1& desc) const; size_t operator () (const D3D11_RENDER_TARGET_BLEND_DESC& desc) const; size_t operator () (const D3D11_SAMPLER_DESC& desc) const; }; @@ -25,7 +25,7 @@ namespace dxvk { bool operator () (const D3D11_BLEND_DESC& a, const D3D11_BLEND_DESC& b) const; bool operator () (const D3D11_DEPTH_STENCILOP_DESC& a, const D3D11_DEPTH_STENCILOP_DESC& b) const; bool operator () (const D3D11_DEPTH_STENCIL_DESC& a, const D3D11_DEPTH_STENCIL_DESC& b) const; - bool operator () (const D3D11_RASTERIZER_DESC& a, const D3D11_RASTERIZER_DESC& b) const; + bool operator () (const D3D11_RASTERIZER_DESC1& a, const D3D11_RASTERIZER_DESC1& b) const; bool operator () (const D3D11_RENDER_TARGET_BLEND_DESC& a, const D3D11_RENDER_TARGET_BLEND_DESC& b) const; bool operator () (const D3D11_SAMPLER_DESC& a, const D3D11_SAMPLER_DESC& b) const; };