From 553c90307a42e398908965c241c8acc879117d38 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sat, 11 Aug 2018 19:28:30 +0200 Subject: [PATCH] [d3d10] Implement D3D10Buffer --- src/d3d10/d3d10_buffer.cpp | 113 +++++++++++++++++++++++++++++++++++++ src/d3d10/d3d10_buffer.h | 70 +++++++++++++++++++++++ src/d3d10/d3d10_device.cpp | 24 +++++++- src/d3d11/d3d11_buffer.cpp | 10 +++- src/d3d11/d3d11_buffer.h | 10 +++- src/d3d11/meson.build | 1 + 6 files changed, 224 insertions(+), 4 deletions(-) create mode 100644 src/d3d10/d3d10_buffer.cpp create mode 100644 src/d3d10/d3d10_buffer.h diff --git a/src/d3d10/d3d10_buffer.cpp b/src/d3d10/d3d10_buffer.cpp new file mode 100644 index 000000000..e1075eb15 --- /dev/null +++ b/src/d3d10/d3d10_buffer.cpp @@ -0,0 +1,113 @@ +#include "d3d10_buffer.h" + +#include "../d3d11/d3d11_buffer.h" +#include "../d3d11/d3d11_device.h" +#include "../d3d11/d3d11_context.h" + +namespace dxvk { + + HRESULT STDMETHODCALLTYPE D3D10Buffer::QueryInterface( + REFIID riid, + void** ppvObject) { + return m_d3d11->QueryInterface(riid, ppvObject); + } + + + ULONG STDMETHODCALLTYPE D3D10Buffer::AddRef() { + return m_d3d11->AddRef(); + } + + + ULONG STDMETHODCALLTYPE D3D10Buffer::Release() { + return m_d3d11->Release(); + } + + + void STDMETHODCALLTYPE D3D10Buffer::GetDevice( + ID3D10Device** ppDevice) { + GetD3D10Device(m_d3d11, ppDevice); + } + + + HRESULT STDMETHODCALLTYPE D3D10Buffer::GetPrivateData( + REFGUID guid, + UINT* pDataSize, + void* pData) { + return m_d3d11->GetPrivateData(guid, pDataSize, pData); + } + + + HRESULT STDMETHODCALLTYPE D3D10Buffer::SetPrivateData( + REFGUID guid, + UINT DataSize, + const void* pData) { + return m_d3d11->SetPrivateData(guid, DataSize, pData); + } + + + HRESULT STDMETHODCALLTYPE D3D10Buffer::SetPrivateDataInterface( + REFGUID guid, + const IUnknown* pData) { + return m_d3d11->SetPrivateDataInterface(guid, pData); + } + + + void STDMETHODCALLTYPE D3D10Buffer::GetType( + D3D10_RESOURCE_DIMENSION* rType) { + *rType = D3D10_RESOURCE_DIMENSION_TEXTURE1D; + } + + + void STDMETHODCALLTYPE D3D10Buffer::SetEvictionPriority( + UINT EvictionPriority) { + m_d3d11->SetEvictionPriority(EvictionPriority); + } + + + UINT STDMETHODCALLTYPE D3D10Buffer::GetEvictionPriority() { + return m_d3d11->GetEvictionPriority(); + } + + + HRESULT STDMETHODCALLTYPE D3D10Buffer::Map( + D3D10_MAP MapType, + UINT MapFlags, + void** ppData) { + Com ctx; + GetD3D11Context(m_d3d11, &ctx); + + D3D11_MAPPED_SUBRESOURCE sr; + HRESULT hr = ctx->Map(m_d3d11, 0, + D3D11_MAP(MapType), MapFlags, &sr); + + if (FAILED(hr)) + return hr; + + if (ppData != nullptr) { + *ppData = sr.pData; + return S_OK; + } return S_FALSE; + } + + + void STDMETHODCALLTYPE D3D10Buffer::Unmap() { + Com ctx; + GetD3D11Context(m_d3d11, &ctx); + + ctx->Unmap(m_d3d11, 0); + } + + + void STDMETHODCALLTYPE D3D10Buffer::GetDesc( + D3D10_BUFFER_DESC* pDesc) { + D3D11_BUFFER_DESC d3d11Desc; + m_d3d11->GetDesc(&d3d11Desc); + + pDesc->ByteWidth = d3d11Desc.ByteWidth; + pDesc->Usage = D3D10_USAGE(d3d11Desc.Usage); + pDesc->BindFlags = d3d11Desc.BindFlags & 0x7F; + pDesc->CPUAccessFlags = d3d11Desc.CPUAccessFlags; + pDesc->MiscFlags = ConvertD3D11ResourceFlags(d3d11Desc.MiscFlags); + } + +} \ No newline at end of file diff --git a/src/d3d10/d3d10_buffer.h b/src/d3d10/d3d10_buffer.h new file mode 100644 index 000000000..3930f92be --- /dev/null +++ b/src/d3d10/d3d10_buffer.h @@ -0,0 +1,70 @@ +#pragma once + +#include "d3d10_util.h" + +namespace dxvk { + + class D3D11Buffer; + class D3D11Device; + + class D3D10Buffer : public ID3D10Buffer { + + public: + + D3D10Buffer(D3D11Buffer* 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 GetType( + D3D10_RESOURCE_DIMENSION* rType); + + void STDMETHODCALLTYPE SetEvictionPriority( + UINT EvictionPriority); + + UINT STDMETHODCALLTYPE GetEvictionPriority(); + + HRESULT STDMETHODCALLTYPE Map( + D3D10_MAP MapType, + UINT MapFlags, + void** ppData); + + void STDMETHODCALLTYPE Unmap(); + + void STDMETHODCALLTYPE GetDesc( + D3D10_BUFFER_DESC* pDesc); + + D3D11Buffer* GetD3D11Iface() { + return m_d3d11; + } + + private: + + D3D11Buffer* m_d3d11; + + }; + +} \ No newline at end of file diff --git a/src/d3d10/d3d10_device.cpp b/src/d3d10/d3d10_device.cpp index 1c7eabf35..e3667509f 100644 --- a/src/d3d10/d3d10_device.cpp +++ b/src/d3d10/d3d10_device.cpp @@ -93,8 +93,28 @@ namespace dxvk { const D3D10_BUFFER_DESC* pDesc, const D3D10_SUBRESOURCE_DATA* pInitialData, ID3D10Buffer** ppBuffer) { - Logger::err("D3D10Device::CreateBuffer: Not implemented"); - return E_NOTIMPL; + InitReturnPtr(ppBuffer); + + D3D11_BUFFER_DESC d3d11Desc; + d3d11Desc.ByteWidth = pDesc->ByteWidth; + d3d11Desc.Usage = D3D11_USAGE(pDesc->Usage); + d3d11Desc.BindFlags = pDesc->BindFlags; + d3d11Desc.CPUAccessFlags = pDesc->CPUAccessFlags; + d3d11Desc.MiscFlags = ConvertD3D10ResourceFlags(pDesc->MiscFlags); + d3d11Desc.StructureByteStride = 0; + + ID3D11Buffer* d3d11Buffer = nullptr; + HRESULT hr = m_device->CreateBuffer(&d3d11Desc, + reinterpret_cast(pInitialData), + ppBuffer != nullptr ? &d3d11Buffer : nullptr); + + if (FAILED(hr)) + return hr; + + if (ppBuffer != nullptr) { + *ppBuffer = static_cast(d3d11Buffer)->GetD3D10Iface(); + return S_OK; + } return S_FALSE; } diff --git a/src/d3d11/d3d11_buffer.cpp b/src/d3d11/d3d11_buffer.cpp index 004452d06..b925d10e9 100644 --- a/src/d3d11/d3d11_buffer.cpp +++ b/src/d3d11/d3d11_buffer.cpp @@ -12,7 +12,8 @@ namespace dxvk { : m_device (pDevice), m_desc (*pDesc), m_buffer (CreateBuffer(pDesc)), - m_mappedSlice (m_buffer->slice()) { + m_mappedSlice (m_buffer->slice()), + m_d3d10 (this) { } @@ -33,6 +34,13 @@ namespace dxvk { return S_OK; } + if (riid == __uuidof(ID3D10DeviceChild) + || riid == __uuidof(ID3D10Resource) + || riid == __uuidof(ID3D10Buffer)) { + *ppvObject = ref(&m_d3d10); + return S_OK; + } + Logger::warn("D3D11Buffer::QueryInterface: Unknown interface query"); Logger::warn(str::format(riid)); return E_NOINTERFACE; diff --git a/src/d3d11/d3d11_buffer.h b/src/d3d11/d3d11_buffer.h index 1e1ac21a2..2d567dd3f 100644 --- a/src/d3d11/d3d11_buffer.h +++ b/src/d3d11/d3d11_buffer.h @@ -1,6 +1,8 @@ #pragma once -#include +#include "../dxvk/dxvk_device.h" + +#include "../d3d10/d3d10_buffer.h" #include "d3d11_device_child.h" #include "d3d11_interfaces.h" @@ -73,6 +75,10 @@ namespace dxvk { m_mappedSlice = slice; } + D3D10Buffer* GetD3D10Iface() { + return &m_d3d10; + } + private: const Com m_device; @@ -80,6 +86,8 @@ namespace dxvk { Rc m_buffer; DxvkPhysicalBufferSlice m_mappedSlice; + + D3D10Buffer m_d3d10; Rc CreateBuffer( const D3D11_BUFFER_DESC* pDesc) const; diff --git a/src/d3d11/meson.build b/src/d3d11/meson.build index 5e453a465..69c92b9be 100644 --- a/src/d3d11/meson.build +++ b/src/d3d11/meson.build @@ -1,4 +1,5 @@ d3d10_src = [ + '../d3d10/d3d10_buffer.cpp', '../d3d10/d3d10_device.cpp', '../d3d10/d3d10_texture.cpp', '../d3d10/d3d10_util.cpp',