...
 
Commits (6)
......@@ -32,26 +32,28 @@ namespace dxup {
if (ppbData == nullptr)
return log::d3derr(D3DERR_INVALIDCALL, "ReturnPtr for buffer lock was null!");
D3DLOCKED_RECT lockedRect;
RECT rectToLock;
rectToLock.top = 0;
rectToLock.bottom = 1;
rectToLock.left = OffsetToLock;
rectToLock.right = OffsetToLock + SizeToLock;
D3DLOCKED_BOX lockedBox;
D3DBOX boxToLock;
boxToLock.Top = 0;
boxToLock.Bottom = 1;
boxToLock.Left = OffsetToLock;
boxToLock.Right = OffsetToLock + SizeToLock;
boxToLock.Front = 0;
boxToLock.Back = 1;
bool degenerate = OffsetToLock == 0 && SizeToLock == 0;
HRESULT result = this->GetDXUPResource()->D3D9LockRect(0, 0, &lockedRect, degenerate ? nullptr : &rectToLock, Flags, this->GetD3D9Desc().Usage);
HRESULT result = this->GetDXUPResource()->D3D9LockBox(0, 0, &lockedBox, degenerate ? nullptr : &boxToLock, Flags, this->GetD3D9Desc().Usage);
if (FAILED(result))
return result;
*ppbData = lockedRect.pBits;
*ppbData = lockedBox.pBits;
return D3D_OK;
}
HRESULT STDMETHODCALLTYPE Unlock() override {
return this->GetDXUPResource()->D3D9UnlockRect(0, 0);
return this->GetDXUPResource()->D3D9UnlockBox(0, 0);
}
};
......
......@@ -23,6 +23,41 @@ namespace dxup {
return false;
}
DXUPResource* DXUPResource::CreateTexture3D(Direct3DDevice9Ex* device, ID3D11Texture3D* texture, DWORD d3d9Usage, D3DFORMAT d3d9Format) {
D3D11_TEXTURE3D_DESC desc;
texture->GetDesc(&desc);
Com<ID3D11ShaderResourceView> srv;
Com<ID3D11ShaderResourceView> srvSRGB;
if (desc.BindFlags & D3D11_BIND_SHADER_RESOURCE) {
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
srvDesc.ViewDimension = D3D10_1_SRV_DIMENSION_TEXTURE3D;
srvDesc.Texture3D.MipLevels = 0xFFFFFFFF;
srvDesc.Texture3D.MostDetailedMip = 0;
srvDesc.Format = desc.Format;
srvDesc.Format = convert::makeUntypeless(srvDesc.Format, false);
device->GetD3D11Device()->CreateShaderResourceView(texture, &srvDesc, &srv);
srvDesc.Format = desc.Format;
srvDesc.Format = convert::makeUntypeless(srvDesc.Format, true);
device->GetD3D11Device()->CreateShaderResourceView(texture, &srvDesc, &srvSRGB);
}
Com<ID3D11Texture3D> stagingTexture;
if (NeedsStaging(desc.Usage, d3d9Usage, d3d9Format)) {
makeStagingDesc(desc, d3d9Usage, d3d9Format);
device->GetD3D11Device()->CreateTexture3D(&desc, nullptr, &stagingTexture);
if (d3d9Format == D3DFMT_R8G8B8)
log::warn("CreateTexture3D: has format D3DFMT_R8G8B8.");
}
return new DXUPResource(device, texture, stagingTexture.ptr(), nullptr, srv.ptr(), srvSRGB.ptr(), desc.Format, 1, std::max(desc.MipLevels, 1u), desc.Usage == D3D11_USAGE_DYNAMIC);
}
DXUPResource* DXUPResource::CreateTexture2D(Direct3DDevice9Ex* device, ID3D11Texture2D* texture, DWORD d3d9Usage, D3DFORMAT d3d9Format) {
D3D11_TEXTURE2D_DESC desc;
texture->GetDesc(&desc);
......@@ -86,6 +121,8 @@ namespace dxup {
D3D11_RESOURCE_DIMENSION dimension;
resource->GetType(&dimension);
if (dimension == D3D11_RESOURCE_DIMENSION_TEXTURE3D)
return CreateTexture3D(device, useAs<ID3D11Texture3D>(resource), d3d9Usage, d3d9Format);
if (dimension == D3D11_RESOURCE_DIMENSION_TEXTURE2D)
return CreateTexture2D(device, useAs<ID3D11Texture2D>(resource), d3d9Usage, d3d9Format);
else if (dimension == D3D11_RESOURCE_DIMENSION_BUFFER)
......@@ -176,7 +213,7 @@ namespace dxup {
, m_mips{ mips }
, m_dxgiFormat{ dxgiFormat }
, m_dynamic{ dynamic } {
m_stagingRects.resize(GetSubresources());
m_stagingBoxes.resize(GetSubresources());
ResetMipMapTracking();
for (uint32_t i = 0; i < 6; i++)
m_dirtySubresources[i] = 0;
......
......@@ -54,8 +54,8 @@ namespace dxup {
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObj) override;
HRESULT D3D9LockRect(UINT slice, UINT mip, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags, DWORD Usage);
HRESULT D3D9UnlockRect(UINT slice, UINT mip);
HRESULT D3D9LockBox(UINT slice, UINT mip, D3DLOCKED_BOX* pLockedBox, CONST D3DBOX* pBox, DWORD Flags, DWORD Usage);
HRESULT D3D9UnlockBox(UINT slice, UINT mip);
DXGI_FORMAT GetDXGIFormat();
......@@ -71,6 +71,7 @@ namespace dxup {
static bool NeedsStaging(D3D11_USAGE d3d11Usage, DWORD d3d9Usage, D3DFORMAT d3d9Format);
static DXUPResource* CreateTexture2D(Direct3DDevice9Ex* device, ID3D11Texture2D* texture, DWORD d3d9Usage, D3DFORMAT d3d9Format);
static DXUPResource* CreateTexture3D(Direct3DDevice9Ex* device, ID3D11Texture3D* texture, DWORD d3d9Usage, D3DFORMAT d3d9Format);
static DXUPResource* CreateBuffer(Direct3DDevice9Ex* device, ID3D11Buffer* buffer, DWORD d3d9Usage);
DXUPResource(Direct3DDevice9Ex* device, ID3D11Resource* resource, ID3D11Resource* staging, ID3D11Resource* fixup8888, ID3D11ShaderResourceView* srv, ID3D11ShaderResourceView* srvSRGB, DXGI_FORMAT dxgiFormat, UINT slices, UINT mips, bool dynamic);
......@@ -87,8 +88,8 @@ namespace dxup {
Com<ID3D11Resource> m_staging;
Com<ID3D11Resource> m_fixup8888;
bool IsStagingRectDegenerate(UINT subresource);
std::vector<RECT> m_stagingRects;
bool IsStagingBoxDegenerate(UINT subresource);
std::vector<D3DBOX> m_stagingBoxes;
bool m_dynamic;
......
......@@ -3,8 +3,8 @@
namespace dxup {
bool DXUPResource::IsStagingRectDegenerate(UINT subresource) {
return isRectDegenerate(m_stagingRects[subresource]);
bool DXUPResource::IsStagingBoxDegenerate(UINT subresource) {
return isBoxDegenerate(m_stagingBoxes[subresource]);
}
UINT DXUPResource::CalcMapFlags(UINT d3d9LockFlags) {
......@@ -65,21 +65,22 @@ namespace dxup {
}
}
HRESULT DXUPResource::D3D9LockRect(UINT slice, UINT mip, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags, DWORD Usage) {
HRESULT DXUPResource::D3D9LockBox(UINT slice, UINT mip, D3DLOCKED_BOX* pLockedBox, CONST D3DBOX* pBox, DWORD Flags, DWORD Usage) {
CriticalSection cs(m_device);
if (!pLockedRect)
return log::d3derr(D3DERR_INVALIDCALL, "Return value (locked rect) was null in D3D9LockRect.");
if (pLockedBox == nullptr)
return log::d3derr(D3DERR_INVALIDCALL, "D3D9LockBox: return value (locked box) was nullptr.");
pLockedRect->pBits = nullptr;
pLockedRect->Pitch = 0;
pLockedBox->pBits = nullptr;
pLockedBox->RowPitch = 0;
pLockedBox->SlicePitch = 0;
UINT subresource = D3D11CalcSubresource(mip, slice, m_mips);
if (pRect == nullptr)
std::memset(&m_stagingRects[subresource], 0, sizeof(RECT));
if (pBox == nullptr)
std::memset(&m_stagingBoxes[subresource], 0, sizeof(D3DBOX));
else
m_stagingRects[subresource] = *pRect;
m_stagingBoxes[subresource] = *pBox;
if (!(Flags & D3DLOCK_DISCARD) && !(Flags & D3DLOCK_NOOVERWRITE) && !(Usage & D3DUSAGE_WRITEONLY))
MakeClean();
......@@ -97,17 +98,18 @@ namespace dxup {
size_t offset = 0;
if (!IsStagingRectDegenerate(subresource))
offset = (m_stagingRects[subresource].top * res.RowPitch) + (m_stagingRects[subresource].left * bitsPerPixel(m_dxgiFormat) / 8);
if (!IsStagingBoxDegenerate(subresource))
offset = (m_stagingBoxes[subresource].Top * res.RowPitch) + (m_stagingBoxes[subresource].Left * bitsPerPixel(m_dxgiFormat) / 8);
uint8_t* data = (uint8_t*)res.pData;
pLockedRect->pBits = &data[offset];
pLockedRect->Pitch = res.RowPitch;
pLockedBox->pBits = &data[offset];
pLockedBox->RowPitch = res.RowPitch;
pLockedBox->SlicePitch = res.DepthPitch;
return D3D_OK;
}
HRESULT DXUPResource::D3D9UnlockRect(UINT slice, UINT mip) {
HRESULT DXUPResource::D3D9UnlockBox(UINT slice, UINT mip) {
CriticalSection cs(m_device);
UINT subresource = D3D11CalcSubresource(mip, slice, m_mips);
......@@ -131,8 +133,8 @@ namespace dxup {
uint8_t* write = (uint8_t*)fixupRes.pData;
// TODO: Investigate if this is right or good enough.
uint32_t mippedHeight = desc.Height >> mip;
uint32_t mippedWidth = desc.Width >> mip;
uint32_t mippedHeight = std::max(1u, desc.Height >> mip);
uint32_t mippedWidth = std::max(1u, desc.Width >> mip);
for (uint32_t y = 0; y < mippedHeight; y++) {
for (uint32_t x = 0; x < mippedWidth; x++) {
......@@ -160,17 +162,34 @@ namespace dxup {
for (uint64_t mip = 0; mip < m_mips; mip++) {
UINT subresource = D3D11CalcSubresource(mip, slice, m_mips);
bool useRect = !IsStagingRectDegenerate(subresource);
bool useRect = !IsStagingBoxDegenerate(subresource);
D3D11_BOX box = { 0 };
if (useRect) {
box.left = alignRectForFormat(true, m_dxgiFormat, m_stagingRects[subresource].left);
box.top = alignRectForFormat(true, m_dxgiFormat, m_stagingRects[subresource].top);
box.right = alignRectForFormat(false, m_dxgiFormat, m_stagingRects[subresource].right);
box.bottom = alignRectForFormat(false, m_dxgiFormat, m_stagingRects[subresource].bottom);
D3D11_RESOURCE_DIMENSION dimension;
GetResource()->GetType(&dimension);
if (dimension == D3D11_RESOURCE_DIMENSION_BUFFER) {
box.top = 0;
box.bottom = 1;
box.left = m_stagingBoxes[subresource].Left;
box.right = m_stagingBoxes[subresource].Right;
}
else {
box.top = alignRectForFormat(true, m_dxgiFormat, m_stagingBoxes[subresource].Top);
box.bottom = alignRectForFormat(false, m_dxgiFormat, m_stagingBoxes[subresource].Bottom);
box.left = alignRectForFormat(true, m_dxgiFormat, m_stagingBoxes[subresource].Left);
box.right = alignRectForFormat(false, m_dxgiFormat, m_stagingBoxes[subresource].Right);
}
box.front = 0;
box.back = 1;
if (dimension == D3D11_RESOURCE_DIMENSION_TEXTURE2D || dimension == D3D11_RESOURCE_DIMENSION_BUFFER) {
box.front = 0;
box.back = 1;
}
else {
box.front = alignRectForFormat(true, m_dxgiFormat, m_stagingBoxes[subresource].Front);
box.back = alignRectForFormat(false, m_dxgiFormat, m_stagingBoxes[subresource].Back);
}
}
if (delta & (1ull << mip))
......
......@@ -640,8 +640,7 @@ namespace dxup {
HRESULT STDMETHODCALLTYPE Direct3DDevice9Ex::CreateVolumeTexture(UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DVolumeTexture9** ppVolumeTexture, HANDLE* pSharedHandle) {
CriticalSection cs(this);
log::stub("Direct3DDevice9Ex::CreateVolumeTexture");
return D3D_OK;
return Direct3DVolumeTexture9::Create(this, Width, Height, Depth, Levels, Usage, Format, Pool, (Direct3DVolumeTexture9**)ppVolumeTexture);
}
HRESULT STDMETHODCALLTYPE Direct3DDevice9Ex::CreateCubeTexture(UINT EdgeLength, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture9** ppCubeTexture, HANDLE* pSharedHandle) {
CriticalSection cs(this);
......@@ -660,8 +659,8 @@ namespace dxup {
D3D11_BUFFER_DESC desc;
desc.ByteWidth = Length;
desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
desc.CPUAccessFlags = convert::cpuFlags(Pool, Usage);
desc.Usage = convert::usage(Pool, Usage);
desc.CPUAccessFlags = convert::cpuFlags(Pool, Usage, D3DRTYPE_VERTEXBUFFER);
desc.Usage = convert::usage(Pool, Usage, D3DRTYPE_VERTEXBUFFER);
desc.MiscFlags = 0;
desc.StructureByteStride = 0;
......@@ -697,8 +696,8 @@ namespace dxup {
D3D11_BUFFER_DESC desc;
desc.ByteWidth = Length;
desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
desc.CPUAccessFlags = convert::cpuFlags(Pool, Usage);
desc.Usage = convert::usage(Pool, Usage);
desc.CPUAccessFlags = convert::cpuFlags(Pool, Usage, D3DRTYPE_INDEXBUFFER);
desc.Usage = convert::usage(Pool, Usage, D3DRTYPE_INDEXBUFFER);
desc.MiscFlags = 0;
desc.StructureByteStride = 0;
......
......@@ -38,18 +38,18 @@ namespace dxup {
HRESULT STDMETHODCALLTYPE FreePrivateData(REFGUID refguid) override {
return m_map.FreePrivateData(refguid);
}
DWORD STDMETHODCALLTYPE SetPriority(DWORD PriorityNew) override {
DWORD STDMETHODCALLTYPE SetPriority(DWORD PriorityNew) {
DWORD oldPriority = m_d3d9Desc.Priority;
m_d3d9Desc.Priority = PriorityNew;
return oldPriority;
}
DWORD STDMETHODCALLTYPE GetPriority() override {
DWORD STDMETHODCALLTYPE GetPriority() {
return m_d3d9Desc.Priority;
}
void STDMETHODCALLTYPE PreLoad() override {
void STDMETHODCALLTYPE PreLoad() {
log::stub("Direct3DResource9::PreLoad");
}
D3DRESOURCETYPE STDMETHODCALLTYPE GetType() override {
D3DRESOURCETYPE STDMETHODCALLTYPE GetType() {
return ResourceType;
}
......
......@@ -3,6 +3,7 @@
#include "d3d9_texture.h"
#include "d3d9_format.h"
#include "../util/config.h"
#include <algorithm>
namespace dxup {
......@@ -50,8 +51,8 @@ namespace dxup {
m_resource->GetResourceAs<ID3D11Texture2D>()->GetDesc(&desc);
pDesc->Format = m_d3d9Desc.Format;
pDesc->Height = desc.Height;
pDesc->Width = desc.Width;
pDesc->Height = std::max(1u, desc.Height >> m_mip);
pDesc->Width = std::max(1u, desc.Width >> m_mip);
pDesc->Pool = m_d3d9Desc.Pool;
pDesc->MultiSampleType = (D3DMULTISAMPLE_TYPE)desc.SampleDesc.Count;
pDesc->MultiSampleQuality = desc.SampleDesc.Quality;
......@@ -61,14 +62,28 @@ namespace dxup {
return D3D_OK;
}
HRESULT Direct3DSurface9::LockRect(D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
return m_resource->D3D9LockRect(m_slice, m_mip, pLockedRect, pRect, Flags, m_d3d9Desc.Usage);
if (pLockedRect == nullptr)
return log::d3derr(D3DERR_INVALIDCALL, "Direct3DSurface9::LockRect: pLockedRect was nullptr.");
D3DLOCKED_BOX lockedBox;
D3DBOX box;
if (pRect != nullptr) {
box.Top = pRect->top;
box.Left = pRect->left;
box.Bottom = pRect->bottom;
box.Right = pRect->right;
box.Front = 0;
box.Back = 1;
}
HRESULT result = m_resource->D3D9LockBox(m_slice, m_mip, &lockedBox, pRect != nullptr ? &box : nullptr, Flags, m_d3d9Desc.Usage);
pLockedRect->pBits = lockedBox.pBits;
pLockedRect->Pitch = lockedBox.RowPitch;
return result;
}
HRESULT Direct3DSurface9::UnlockRect() {
return m_resource->D3D9UnlockRect(m_slice, m_mip);
}
D3DRESOURCETYPE STDMETHODCALLTYPE Direct3DSurface9::GetType() {
return D3DRTYPE_SURFACE;
return m_resource->D3D9UnlockBox(m_slice, m_mip);
}
HRESULT Direct3DSurface9::GetDC(HDC *phdc) {
......
......@@ -20,7 +20,6 @@ namespace dxup {
HRESULT WINAPI UnlockRect() override;
HRESULT WINAPI GetDC(HDC *phdc) override;
HRESULT WINAPI ReleaseDC(HDC hdc) override;
D3DRESOURCETYPE STDMETHODCALLTYPE GetType() override;
UINT GetMip();
UINT GetSlice();
......
This diff is collapsed.
......@@ -3,6 +3,7 @@
#include "d3d9_d3d11_resource.h"
#include "d3d9_resource.h"
#include "d3d9_surface.h"
#include "d3d9_volume.h"
#include <vector>
namespace dxup {
......@@ -120,4 +121,35 @@ namespace dxup {
};
using Direct3DVolumeTexture9Base = Direct3DBaseTexture9<D3DRTYPE_VOLUMETEXTURE, IDirect3DVolumeTexture9>;
class Direct3DVolumeTexture9 final : public Direct3DVolumeTexture9Base {
public:
~Direct3DVolumeTexture9();
HRESULT STDMETHODCALLTYPE GetLevelDesc(UINT Level, D3DVOLUME_DESC* pDesc) override;
HRESULT STDMETHODCALLTYPE GetVolumeLevel(UINT Level, IDirect3DVolume9** ppVolumeLevel) override;
HRESULT STDMETHODCALLTYPE LockBox(UINT Level, D3DLOCKED_BOX* pLockedBox, const D3DBOX* pBox, DWORD Flags) override;
HRESULT STDMETHODCALLTYPE UnlockBox(UINT Level) override;
HRESULT STDMETHODCALLTYPE AddDirtyBox(const D3DBOX* pDirtyBox) override;
static HRESULT Create(Direct3DDevice9Ex* device,
UINT width,
UINT height,
UINT depth,
UINT levels,
DWORD usage,
D3DFORMAT format,
D3DPOOL pool,
Direct3DVolumeTexture9** outTexture);
private:
Direct3DVolumeTexture9(Direct3DDevice9Ex* device, DXUPResource* resource, const D3D9ResourceDesc& desc);
std::vector<IDirect3DVolume9*> m_volumes;
};
}
\ No newline at end of file
......@@ -185,18 +185,18 @@ namespace dxup {
return scanlineConverter.toT(ScanlineOrdering);
}
D3D11_USAGE usage(D3DPOOL pool, UINT usage) {
D3D11_USAGE usage(D3DPOOL pool, UINT usage, D3DRESOURCETYPE type) {
if (pool == D3DPOOL_SYSTEMMEM || pool == D3DPOOL_SCRATCH)
return D3D11_USAGE_STAGING;
if (usage & D3DUSAGE_DYNAMIC && !(usage & D3DUSAGE_RENDERTARGET) && !(usage & D3DUSAGE_DEPTHSTENCIL) && !(usage & D3DUSAGE_AUTOGENMIPMAP))
if (usage & D3DUSAGE_DYNAMIC && !(usage & D3DUSAGE_RENDERTARGET) && !(usage & D3DUSAGE_DEPTHSTENCIL) && !(usage & D3DUSAGE_AUTOGENMIPMAP) && type != D3DRTYPE_CUBETEXTURE)
return D3D11_USAGE_DYNAMIC;
return D3D11_USAGE_DEFAULT;
}
UINT cpuFlags(D3DPOOL pool, UINT usage) {
D3D11_USAGE d3d11Usage = convert::usage(pool, usage);
UINT cpuFlags(D3DPOOL pool, UINT usage, D3DRESOURCETYPE type) {
D3D11_USAGE d3d11Usage = convert::usage(pool, usage, type);
if (d3d11Usage != D3D11_USAGE_DEFAULT) {
if (usage & D3DUSAGE_WRITEONLY)
return D3D11_CPU_ACCESS_WRITE;
......
......@@ -18,8 +18,8 @@ namespace dxup {
DXGI_MODE_SCANLINE_ORDER scanlineOrdering(D3DSCANLINEORDERING ScanlineOrdering);
D3DSCANLINEORDERING scanlineOrdering(DXGI_MODE_SCANLINE_ORDER ScanlineOrdering);
UINT cpuFlags(D3DPOOL pool, UINT usage);
D3D11_USAGE usage(D3DPOOL pool, UINT usage);
UINT cpuFlags(D3DPOOL pool, UINT usage, D3DRESOURCETYPE type);
D3D11_USAGE usage(D3DPOOL pool, UINT usage, D3DRESOURCETYPE type);
UINT primitiveData(D3DPRIMITIVETYPE type, UINT count, D3D_PRIMITIVE_TOPOLOGY& topology);
......@@ -186,6 +186,10 @@ namespace dxup {
return rect.top == 0 && rect.right == 0 && rect.left == 0 && rect.bottom == 0;
}
inline bool isBoxDegenerate(const D3DBOX& box) {
return box.Top == 0 && box.Right == 0 && box.Left == 0 && box.Bottom == 0 && box.Front == 0 && box.Back == 0;
}
template <typename T, typename J>
T* useAs(J* obj) {
return reinterpret_cast<T*>(obj);
......
#include "d3d9_volume.h"
#include "d3d9_format.h"
#include "d3d9_texture.h"
#include "d3d9_format.h"
#include "../util/config.h"
#include <algorithm>
namespace dxup {
Direct3DVolume9::Direct3DVolume9(UINT mip, Direct3DDevice9Ex* device, IUnknown* container, DXUPResource* resource, const D3D9ResourceDesc& desc)
: Direct3DVolume9Base{ device, nullptr, desc }
, m_container{ container }
, m_mip{ mip } {
this->SetResource(resource);
}
HRESULT Direct3DVolume9::GetContainer(REFIID riid, void** ppContainer) {
InitReturnPtr(ppContainer);
if (ppContainer == nullptr)
return log::d3derr(D3DERR_INVALIDCALL, "GetContainer: ppContainer was nullptr.");
if (m_container == nullptr)
return log::d3derr(D3DERR_INVALIDCALL, "GetContainer: m_container was nullptr.");
return FAILED(m_container->QueryInterface(riid, ppContainer)) ? D3DERR_INVALIDCALL : D3D_OK;
}
HRESULT Direct3DVolume9::QueryInterface(REFIID riid, void** ppvObj) {
InitReturnPtr(ppvObj);
if (ppvObj == nullptr)
return E_POINTER;
// This isn't a IDirect3DResource9. W h y?
if (riid == __uuidof(IDirect3DVolume9) || /*riid == __uuidof(IDirect3DResource9) ||*/ riid == __uuidof(IUnknown)) {
*ppvObj = ref(this);
return D3D_OK;
}
return E_NOINTERFACE;
}
HRESULT Direct3DVolume9::GetDesc(D3DVOLUME_DESC *pDesc) {
if (!pDesc)
return log::d3derr(D3DERR_INVALIDCALL, "GetDesc: pDesc was nullptr.");
D3D11_TEXTURE3D_DESC desc;
m_resource->GetResourceAs<ID3D11Texture3D>()->GetDesc(&desc);
pDesc->Format = m_d3d9Desc.Format;
pDesc->Height = std::max(1u, desc.Height >> m_mip);
pDesc->Width = std::max(1u, desc.Width >> m_mip);
pDesc->Depth = std::max(1u, desc.Depth >> m_mip);
pDesc->Pool = m_d3d9Desc.Pool;
pDesc->Type = D3DRTYPE_VOLUME;
pDesc->Usage = m_d3d9Desc.Usage;
return D3D_OK;
}
HRESULT Direct3DVolume9::LockBox(D3DLOCKED_BOX* pLockedBox, CONST D3DBOX* pBox, DWORD Flags) {
return m_resource->D3D9LockBox(0, m_mip, pLockedBox, pBox, Flags, m_d3d9Desc.Usage);
}
HRESULT Direct3DVolume9::UnlockBox() {
return m_resource->D3D9UnlockBox(0, m_mip);
}
ULONG STDMETHODCALLTYPE Direct3DVolume9::AddRef() {
if (m_container != nullptr)
m_container->AddRef();
return Direct3DVolume9Base::AddRef();
}
ULONG STDMETHODCALLTYPE Direct3DVolume9::Release() {
if (m_container != nullptr)
m_container->Release();
return Direct3DVolume9Base::Release();
}
UINT Direct3DVolume9::GetMip() {
return m_mip;
}
UINT Direct3DVolume9::GetSubresource() {
return GetMip();
}
void Direct3DVolume9::ClearResource() {
m_resource = nullptr;
}
void Direct3DVolume9::SetResource(DXUPResource* resource) {
this->ClearResource();
m_resource = resource;
}
Direct3DVolume9* Direct3DVolume9::Wrap(UINT mip, Direct3DDevice9Ex* device, IUnknown* container, DXUPResource* resource, const D3D9ResourceDesc& desc) {
return new Direct3DVolume9(mip, device, container, resource, desc);
}
}
\ No newline at end of file
#pragma once
#include "d3d9_resource.h"
#include "d3d9_d3d11_resource.h"
#include <vector>
namespace dxup {
using Direct3DVolume9Base = Direct3DResource9<D3DRTYPE_VOLUME, IDirect3DVolume9>;
// A d3d9 surface is essentially some subresource of a d3d11 texture.
class Direct3DVolume9 final : public Direct3DVolume9Base {
public:
HRESULT WINAPI QueryInterface(REFIID riid, LPVOID* ppv) override;
HRESULT WINAPI GetContainer(REFIID riid, void** ppContainer) override;
HRESULT WINAPI GetDesc(D3DVOLUME_DESC *pDesc) override;
HRESULT WINAPI LockBox(D3DLOCKED_BOX* pLockedBox, CONST D3DBOX* pBox, DWORD Flags) override;
HRESULT WINAPI UnlockBox() override;
UINT GetMip();
UINT GetSubresource();
ULONG STDMETHODCALLTYPE AddRef() override;
ULONG STDMETHODCALLTYPE Release() override;
void ClearResource();
void SetResource(DXUPResource* resource);
static Direct3DVolume9* Wrap(UINT mip, Direct3DDevice9Ex* device, IUnknown* container, DXUPResource* resource, const D3D9ResourceDesc& desc);
private:
Direct3DVolume9(UINT mip, Direct3DDevice9Ex* device, IUnknown* container, DXUPResource* resource, const D3D9ResourceDesc& desc);
IUnknown* m_container;
UINT m_mip;
};
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ d3d9_main_src = [
'd3d9_interface.cpp',
'd3d9_main.cpp',
'd3d9_surface.cpp',
'd3d9_volume.cpp',
'd3d9_swapchain.cpp',
'd3d9_util.cpp',
'd3d9_format.cpp',
......