From 68bfacfcaa4743f5ec4213282b2da7b5120a1754 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sat, 11 Aug 2018 22:31:12 +0200 Subject: [PATCH] [d3d10] Implement D3D10DepthStencilState --- src/d3d10/d3d10_depth_stencil.cpp | 60 +++++++++++++++++++++++++++++++ src/d3d10/d3d10_depth_stencil.h | 55 ++++++++++++++++++++++++++++ src/d3d10/d3d10_device.cpp | 16 +++++++-- src/d3d11/d3d11_depth_stencil.cpp | 8 ++++- src/d3d11/d3d11_depth_stencil.h | 11 ++++-- src/d3d11/meson.build | 1 + 6 files changed, 145 insertions(+), 6 deletions(-) create mode 100644 src/d3d10/d3d10_depth_stencil.cpp create mode 100644 src/d3d10/d3d10_depth_stencil.h diff --git a/src/d3d10/d3d10_depth_stencil.cpp b/src/d3d10/d3d10_depth_stencil.cpp new file mode 100644 index 00000000..a56749cb --- /dev/null +++ b/src/d3d10/d3d10_depth_stencil.cpp @@ -0,0 +1,60 @@ +#include "d3d10_depth_stencil.h" + +#include "../d3d11/d3d11_depth_stencil.h" +#include "../d3d11/d3d11_device.h" + +namespace dxvk { + + HRESULT STDMETHODCALLTYPE D3D10DepthStencilState::QueryInterface( + REFIID riid, + void** ppvObject) { + return m_d3d11->QueryInterface(riid, ppvObject); + } + + + ULONG STDMETHODCALLTYPE D3D10DepthStencilState::AddRef() { + return m_d3d11->AddRef(); + } + + + ULONG STDMETHODCALLTYPE D3D10DepthStencilState::Release() { + return m_d3d11->Release(); + } + + + void STDMETHODCALLTYPE D3D10DepthStencilState::GetDevice( + ID3D10Device** ppDevice) { + GetD3D10Device(m_d3d11, ppDevice); + } + + + HRESULT STDMETHODCALLTYPE D3D10DepthStencilState::GetPrivateData( + REFGUID guid, + UINT* pDataSize, + void* pData) { + return m_d3d11->GetPrivateData(guid, pDataSize, pData); + } + + + HRESULT STDMETHODCALLTYPE D3D10DepthStencilState::SetPrivateData( + REFGUID guid, + UINT DataSize, + const void* pData) { + return m_d3d11->SetPrivateData(guid, DataSize, pData); + } + + + HRESULT STDMETHODCALLTYPE D3D10DepthStencilState::SetPrivateDataInterface( + REFGUID guid, + const IUnknown* pData) { + return m_d3d11->SetPrivateDataInterface(guid, pData); + } + + + void STDMETHODCALLTYPE D3D10DepthStencilState::GetDesc( + D3D10_DEPTH_STENCIL_DESC* pDesc) { + static_assert(sizeof(D3D10_DEPTH_STENCIL_DESC) == sizeof(D3D11_DEPTH_STENCIL_DESC)); + m_d3d11->GetDesc(reinterpret_cast(pDesc)); + } + +} \ No newline at end of file diff --git a/src/d3d10/d3d10_depth_stencil.h b/src/d3d10/d3d10_depth_stencil.h new file mode 100644 index 00000000..953a8b0c --- /dev/null +++ b/src/d3d10/d3d10_depth_stencil.h @@ -0,0 +1,55 @@ +#pragma once + +#include "d3d10_util.h" + +namespace dxvk { + + class D3D11DepthStencilState; + class D3D11Device; + + class D3D10DepthStencilState : public ID3D10DepthStencilState { + + public: + + D3D10DepthStencilState(D3D11DepthStencilState* pParent) + : m_d3d11(pParent) { } + + HRESULT STDMETHODCALLTYPE QueryInterface( + REFIID riid, + void** ppvObject); + + ULONG STDMETHODCALLTYPE AddRef(); + + ULONG STDMETHODCALLTYPE Release(); + + void STDMETHODCALLTYPE GetDevice( + ID3D10Device** ppDevice); + + HRESULT STDMETHODCALLTYPE GetPrivateData( + REFGUID guid, + UINT* pDataSize, + void* pData); + + HRESULT STDMETHODCALLTYPE SetPrivateData( + REFGUID guid, + UINT DataSize, + const void* pData); + + HRESULT STDMETHODCALLTYPE SetPrivateDataInterface( + REFGUID guid, + const IUnknown* pData); + + void STDMETHODCALLTYPE GetDesc( + D3D10_DEPTH_STENCIL_DESC* pDesc); + + D3D11DepthStencilState* GetD3D11Iface() { + return m_d3d11; + } + + private: + + D3D11DepthStencilState* m_d3d11; + + }; + +} \ No newline at end of file diff --git a/src/d3d10/d3d10_device.cpp b/src/d3d10/d3d10_device.cpp index d3637b4e..9b995397 100644 --- a/src/d3d10/d3d10_device.cpp +++ b/src/d3d10/d3d10_device.cpp @@ -373,8 +373,20 @@ namespace dxvk { HRESULT STDMETHODCALLTYPE D3D10Device::CreateDepthStencilState( const D3D10_DEPTH_STENCIL_DESC* pDepthStencilDesc, ID3D10DepthStencilState** ppDepthStencilState) { - Logger::err("D3D10Device::CreateDepthStencilState: Not implemented"); - return E_NOTIMPL; + InitReturnPtr(ppDepthStencilState); + + ID3D11DepthStencilState* d3d11DepthStencilState = nullptr; + HRESULT hr = m_device->CreateDepthStencilState( + reinterpret_cast(pDepthStencilDesc), + ppDepthStencilState ? &d3d11DepthStencilState : nullptr); + + if (FAILED(hr)) + return hr; + + if (ppDepthStencilState != nullptr) { + *ppDepthStencilState = static_cast(d3d11DepthStencilState)->GetD3D10Iface(); + return S_OK; + } return S_FALSE; } diff --git a/src/d3d11/d3d11_depth_stencil.cpp b/src/d3d11/d3d11_depth_stencil.cpp index 04efe245..9763df39 100644 --- a/src/d3d11/d3d11_depth_stencil.cpp +++ b/src/d3d11/d3d11_depth_stencil.cpp @@ -6,7 +6,7 @@ namespace dxvk { D3D11DepthStencilState::D3D11DepthStencilState( D3D11Device* device, const D3D11_DEPTH_STENCIL_DESC& desc) - : m_device(device), m_desc(desc) { + : m_device(device), m_desc(desc), m_d3d10(this) { m_state.enableDepthTest = desc.DepthEnable; m_state.enableDepthWrite = desc.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ALL; m_state.enableStencilTest = desc.StencilEnable; @@ -30,6 +30,12 @@ namespace dxvk { *ppvObject = ref(this); return S_OK; } + + if (riid == __uuidof(ID3D10DeviceChild) + || riid == __uuidof(ID3D10DepthStencilState)) { + *ppvObject = ref(this); + return S_OK; + } Logger::warn("D3D11DepthStencilState::QueryInterface: Unknown interface query"); Logger::warn(str::format(riid)); diff --git a/src/d3d11/d3d11_depth_stencil.h b/src/d3d11/d3d11_depth_stencil.h index 5e3f7c33..809c9ae5 100644 --- a/src/d3d11/d3d11_depth_stencil.h +++ b/src/d3d11/d3d11_depth_stencil.h @@ -1,6 +1,8 @@ #pragma once -#include +#include "../dxvk/dxvk_device.h" + +#include "../d3d10/d3d10_depth_stencil.h" #include "d3d11_device_child.h" #include "d3d11_util.h" @@ -33,18 +35,21 @@ namespace dxvk { void BindToContext( const Rc& ctx); + D3D10DepthStencilState* GetD3D10Iface() { + return &m_d3d10; + } + static D3D11_DEPTH_STENCIL_DESC DefaultDesc(); static HRESULT NormalizeDesc( D3D11_DEPTH_STENCIL_DESC* pDesc); - - private: D3D11Device* const m_device; D3D11_DEPTH_STENCIL_DESC m_desc; DxvkDepthStencilState m_state; + D3D10DepthStencilState m_d3d10; VkStencilOpState DecodeStencilOpState( const D3D11_DEPTH_STENCILOP_DESC& StencilDesc, diff --git a/src/d3d11/meson.build b/src/d3d11/meson.build index a3bcd782..c99a1460 100644 --- a/src/d3d11/meson.build +++ b/src/d3d11/meson.build @@ -1,6 +1,7 @@ d3d10_src = [ '../d3d10/d3d10_blend.cpp', '../d3d10/d3d10_buffer.cpp', + '../d3d10/d3d10_depth_stencil.cpp', '../d3d10/d3d10_device.cpp', '../d3d10/d3d10_input_layout.cpp', '../d3d10/d3d10_sampler.cpp',