From 759ff737a40bc3c64c48569db160d38716cad528 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sat, 11 Aug 2018 20:42:28 +0200 Subject: [PATCH] [d3d10] Implement D3D10SamplerState --- src/d3d10/d3d10_device.cpp | 29 ++++++++++++++- src/d3d10/d3d10_sampler.cpp | 73 +++++++++++++++++++++++++++++++++++++ src/d3d10/d3d10_sampler.h | 55 ++++++++++++++++++++++++++++ src/d3d11/d3d11_sampler.cpp | 8 +++- src/d3d11/d3d11_sampler.h | 9 ++++- src/d3d11/meson.build | 1 + 6 files changed, 171 insertions(+), 4 deletions(-) create mode 100644 src/d3d10/d3d10_sampler.cpp create mode 100644 src/d3d10/d3d10_sampler.h diff --git a/src/d3d10/d3d10_device.cpp b/src/d3d10/d3d10_device.cpp index ef0da5461..af9e6300a 100644 --- a/src/d3d10/d3d10_device.cpp +++ b/src/d3d10/d3d10_device.cpp @@ -335,8 +335,33 @@ namespace dxvk { HRESULT STDMETHODCALLTYPE D3D10Device::CreateSamplerState( const D3D10_SAMPLER_DESC* pSamplerDesc, ID3D10SamplerState** ppSamplerState) { - Logger::err("D3D10Device::CreateSamplerState: Not implemented"); - return E_NOTIMPL; + InitReturnPtr(ppSamplerState); + + D3D11_SAMPLER_DESC d3d11Desc; + d3d11Desc.Filter = D3D11_FILTER(pSamplerDesc->Filter); + d3d11Desc.AddressU = D3D11_TEXTURE_ADDRESS_MODE(pSamplerDesc->AddressU); + d3d11Desc.AddressV = D3D11_TEXTURE_ADDRESS_MODE(pSamplerDesc->AddressV); + d3d11Desc.AddressW = D3D11_TEXTURE_ADDRESS_MODE(pSamplerDesc->AddressW); + d3d11Desc.MipLODBias = pSamplerDesc->MipLODBias; + d3d11Desc.MaxAnisotropy = pSamplerDesc->MaxAnisotropy; + d3d11Desc.ComparisonFunc = D3D11_COMPARISON_FUNC(pSamplerDesc->ComparisonFunc); + d3d11Desc.MinLOD = pSamplerDesc->MinLOD; + d3d11Desc.MaxLOD = pSamplerDesc->MaxLOD; + + for (uint32_t i = 0; i < 4; i++) + d3d11Desc.BorderColor[i] = pSamplerDesc->BorderColor[i]; + + ID3D11SamplerState* d3d11SamplerState = nullptr; + HRESULT hr = m_device->CreateSamplerState(&d3d11Desc, + ppSamplerState ? &d3d11SamplerState : nullptr); + + if (FAILED(hr)) + return hr; + + if (ppSamplerState) { + *ppSamplerState = static_cast(d3d11SamplerState)->GetD3D10Iface(); + return S_OK; + } return S_FALSE; } diff --git a/src/d3d10/d3d10_sampler.cpp b/src/d3d10/d3d10_sampler.cpp new file mode 100644 index 000000000..3db1450a1 --- /dev/null +++ b/src/d3d10/d3d10_sampler.cpp @@ -0,0 +1,73 @@ +#include "d3d10_sampler.h" + +#include "../d3d11/d3d11_device.h" +#include "../d3d11/d3d11_sampler.h" + +namespace dxvk { + + HRESULT STDMETHODCALLTYPE D3D10SamplerState::QueryInterface( + REFIID riid, + void** ppvObject) { + return m_d3d11->QueryInterface(riid, ppvObject); + } + + + ULONG STDMETHODCALLTYPE D3D10SamplerState::AddRef() { + return m_d3d11->AddRef(); + } + + + ULONG STDMETHODCALLTYPE D3D10SamplerState::Release() { + return m_d3d11->Release(); + } + + + void STDMETHODCALLTYPE D3D10SamplerState::GetDevice( + ID3D10Device** ppDevice) { + GetD3D10Device(m_d3d11, ppDevice); + } + + + HRESULT STDMETHODCALLTYPE D3D10SamplerState::GetPrivateData( + REFGUID guid, + UINT* pDataSize, + void* pData) { + return m_d3d11->GetPrivateData(guid, pDataSize, pData); + } + + + HRESULT STDMETHODCALLTYPE D3D10SamplerState::SetPrivateData( + REFGUID guid, + UINT DataSize, + const void* pData) { + return m_d3d11->SetPrivateData(guid, DataSize, pData); + } + + + HRESULT STDMETHODCALLTYPE D3D10SamplerState::SetPrivateDataInterface( + REFGUID guid, + const IUnknown* pData) { + return m_d3d11->SetPrivateDataInterface(guid, pData); + } + + + void STDMETHODCALLTYPE D3D10SamplerState::GetDesc( + D3D10_SAMPLER_DESC* pDesc) { + D3D11_SAMPLER_DESC d3d11Desc; + m_d3d11->GetDesc(&d3d11Desc); + + pDesc->Filter = D3D10_FILTER(d3d11Desc.Filter); + pDesc->AddressU = D3D10_TEXTURE_ADDRESS_MODE(d3d11Desc.AddressU); + pDesc->AddressV = D3D10_TEXTURE_ADDRESS_MODE(d3d11Desc.AddressV); + pDesc->AddressW = D3D10_TEXTURE_ADDRESS_MODE(d3d11Desc.AddressW); + pDesc->MipLODBias = d3d11Desc.MipLODBias; + pDesc->MaxAnisotropy = d3d11Desc.MaxAnisotropy; + pDesc->ComparisonFunc = D3D10_COMPARISON_FUNC(d3d11Desc.ComparisonFunc); + pDesc->MinLOD = d3d11Desc.MinLOD; + pDesc->MaxLOD = d3d11Desc.MaxLOD; + + for (uint32_t i = 0; i < 4; i++) + pDesc->BorderColor[i] = d3d11Desc.BorderColor[i]; + } + +} \ No newline at end of file diff --git a/src/d3d10/d3d10_sampler.h b/src/d3d10/d3d10_sampler.h new file mode 100644 index 000000000..82633e84a --- /dev/null +++ b/src/d3d10/d3d10_sampler.h @@ -0,0 +1,55 @@ +#pragma once + +#include "d3d10_util.h" + +namespace dxvk { + + class D3D11Device; + class D3D11SamplerState; + + class D3D10SamplerState : public ID3D10SamplerState { + + public: + + D3D10SamplerState(D3D11SamplerState* 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_SAMPLER_DESC* pDesc); + + D3D11SamplerState* GetD3D11Iface() { + return m_d3d11; + } + + private: + + D3D11SamplerState* m_d3d11; + + }; + +} \ No newline at end of file diff --git a/src/d3d11/d3d11_sampler.cpp b/src/d3d11/d3d11_sampler.cpp index 48ac045f8..1c0630791 100644 --- a/src/d3d11/d3d11_sampler.cpp +++ b/src/d3d11/d3d11_sampler.cpp @@ -7,7 +7,7 @@ namespace dxvk { D3D11SamplerState::D3D11SamplerState( D3D11Device* device, const D3D11_SAMPLER_DESC& desc) - : m_device(device), m_desc(desc) { + : m_device(device), m_desc(desc), m_d3d10(this) { DxvkSamplerCreateInfo info; // While D3D11_FILTER is technically an enum, its value bits @@ -65,6 +65,12 @@ namespace dxvk { return S_OK; } + if (riid == __uuidof(ID3D10DeviceChild) + || riid == __uuidof(ID3D10SamplerState)) { + *ppvObject = ref(&m_d3d10); + return S_OK; + } + Logger::warn("D3D11SamplerState::QueryInterface: Unknown interface query"); Logger::warn(str::format(riid)); return E_NOINTERFACE; diff --git a/src/d3d11/d3d11_sampler.h b/src/d3d11/d3d11_sampler.h index 7343a1237..75d16fa18 100644 --- a/src/d3d11/d3d11_sampler.h +++ b/src/d3d11/d3d11_sampler.h @@ -1,6 +1,8 @@ #pragma once -#include +#include "../dxvk/dxvk_device.h" + +#include "../d3d10/d3d10_sampler.h" #include "d3d11_device_child.h" @@ -32,6 +34,10 @@ namespace dxvk { Rc GetDXVKSampler() const { return m_sampler; } + + D3D10SamplerState* GetD3D10Iface() { + return &m_d3d10; + } static HRESULT NormalizeDesc( D3D11_SAMPLER_DESC* pDesc); @@ -41,6 +47,7 @@ namespace dxvk { D3D11Device* const m_device; D3D11_SAMPLER_DESC m_desc; Rc m_sampler; + D3D10SamplerState m_d3d10; static bool ValidateAddressMode( D3D11_TEXTURE_ADDRESS_MODE Mode); diff --git a/src/d3d11/meson.build b/src/d3d11/meson.build index 69c92b9be..8e876cf01 100644 --- a/src/d3d11/meson.build +++ b/src/d3d11/meson.build @@ -1,6 +1,7 @@ d3d10_src = [ '../d3d10/d3d10_buffer.cpp', '../d3d10/d3d10_device.cpp', + '../d3d10/d3d10_sampler.cpp', '../d3d10/d3d10_texture.cpp', '../d3d10/d3d10_util.cpp', ]