...
 
Commits (2)
......@@ -635,99 +635,7 @@ namespace dxup {
HRESULT STDMETHODCALLTYPE Direct3DDevice9Ex::CreateTexture(UINT Width, UINT Height, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture9** ppTexture, HANDLE* pSharedHandle) {
CriticalSection cs(this);
return CreateTextureInternal(D3DRTYPE_TEXTURE, false, Width, Height, Levels, Usage, Format, Pool, D3DMULTISAMPLE_NONMASKABLE, 0, false, (void**)ppTexture, pSharedHandle);
}
HRESULT Direct3DDevice9Ex::CreateTextureInternal(
D3DRESOURCETYPE Type,
bool singletonSurface,
UINT Width,
UINT Height,
UINT Levels,
DWORD Usage,
D3DFORMAT Format,
D3DPOOL Pool,
D3DMULTISAMPLE_TYPE MultiSample,
DWORD MultisampleQuality,
BOOL Discard,
void** ppTexture,
HANDLE* pSharedHandle) {
InitReturnPtr(ppTexture);
InitReturnPtr(pSharedHandle);
if (Width == 0)
return log::d3derr(D3DERR_INVALIDCALL, "CreateTextureInternal: width was 0.");
if (Height == 0)
return log::d3derr(D3DERR_INVALIDCALL, "CreateTextureInternal: height was 0.");
if (Usage & D3DUSAGE_AUTOGENMIPMAP && Levels > 1)
return log::d3derr(D3DERR_INVALIDCALL, "CreateTextureInternal: mipmap generation requested with more than 1 level.");
if (m_parent->CheckDeviceFormat(m_adapterNum, m_deviceType, D3DFMT_X8R8G8B8, Usage, Type, Format) != D3D_OK)
return log::d3derr(D3DERR_INVALIDCALL, "CreateTextureInternal: unsupported format (%d).", Format);
if (!ppTexture)
return log::d3derr(D3DERR_INVALIDCALL, "CreateTextureInternal: ppTexture was nullptr.");
D3D11_USAGE d3d11Usage = convert::usage(Pool, Usage);
if (Type == D3DRTYPE_CUBETEXTURE)
d3d11Usage = D3D11_USAGE_DEFAULT;
D3D11_TEXTURE2D_DESC desc;
desc.Width = Width;
desc.Height = Height;
desc.Format = convert::format(Format);
desc.Usage = d3d11Usage;
desc.CPUAccessFlags = Type == D3DRTYPE_CUBETEXTURE ? 0 : convert::cpuFlags(Pool, Usage);
desc.MipLevels = d3d11Usage == D3D11_USAGE_DYNAMIC ? 1 : Levels;
desc.ArraySize = Type == D3DRTYPE_CUBETEXTURE ? 6 : 1;
//UINT sampleCount = std::max(1u, (UINT)MultiSample);
bool isDepthStencil = Usage & D3DUSAGE_DEPTHSTENCIL;
bool isRenderTarget = Usage & D3DUSAGE_RENDERTARGET;
//m_device->CheckMultisampleQualityLevels(desc.Format, sampleCount, )
desc.SampleDesc.Count = 1;//sampleCount;
desc.SampleDesc.Quality = 0;//equateMultisampleQuality ? sampleCount : 0;
desc.BindFlags = 0;
desc.MiscFlags = Type == D3DRTYPE_CUBETEXTURE ? D3D11_RESOURCE_MISC_TEXTURECUBE : 0;
if (!isDepthStencil && d3d11Usage != D3D11_USAGE_STAGING)
desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;
if (d3d11Usage == D3D11_USAGE_DEFAULT) {
desc.BindFlags |= isRenderTarget ? D3D11_BIND_RENDER_TARGET : 0;
desc.BindFlags |= isDepthStencil ? D3D11_BIND_DEPTH_STENCIL : 0;
desc.MiscFlags |= Usage & D3DUSAGE_AUTOGENMIPMAP ? D3D11_RESOURCE_MISC_GENERATE_MIPS : 0;
}
Com<ID3D11Texture2D> texture;
HRESULT result = m_device->CreateTexture2D(&desc, nullptr, &texture);
if (FAILED(result))
return log::d3derr(D3DERR_INVALIDCALL, "CreateTextureInternal: failed to create D3D11 texture. D3DFORMAT: %d, DXGI_FORMAT: %d", Format, desc.Format); // TODO: stringify
DXUPResource* resource = DXUPResource::Create(this, texture.ptr(), Usage, Format);
if (resource == nullptr)
return log::d3derr(D3DERR_INVALIDCALL, "CreateTextureInternal: failed to create DXUP resource.");
D3D9ResourceDesc d3d9Desc;
d3d9Desc.Discard = Discard;
d3d9Desc.Format = Format;
d3d9Desc.Pool = Pool;
d3d9Desc.Usage = Usage;
if (Type == D3DRTYPE_CUBETEXTURE)
*ppTexture = ref(new Direct3DCubeTexture9(singletonSurface, this, resource, d3d9Desc));
else
*ppTexture = ref(new Direct3DTexture9(singletonSurface, this, resource, d3d9Desc));
return D3D_OK;
return Direct3DTexture9::Create(this, Width, Height, Levels, Usage, Format, Pool, (Direct3DTexture9**)ppTexture);
}
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);
......@@ -738,7 +646,7 @@ namespace dxup {
HRESULT STDMETHODCALLTYPE Direct3DDevice9Ex::CreateCubeTexture(UINT EdgeLength, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture9** ppCubeTexture, HANDLE* pSharedHandle) {
CriticalSection cs(this);
return CreateTextureInternal(D3DRTYPE_CUBETEXTURE, false, EdgeLength, EdgeLength, Levels, Usage, Format, Pool, D3DMULTISAMPLE_NONMASKABLE, 0, false, (void**)ppCubeTexture, pSharedHandle);
return Direct3DCubeTexture9::Create(this, EdgeLength, Levels, Usage, Format, Pool, (Direct3DCubeTexture9**)ppCubeTexture);
}
HRESULT STDMETHODCALLTYPE Direct3DDevice9Ex::CreateVertexBuffer(UINT Length, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer9** ppVertexBuffer, HANDLE* pSharedHandle) {
CriticalSection cs(this);
......@@ -768,7 +676,7 @@ namespace dxup {
D3D9ResourceDesc d3d9Desc;
d3d9Desc.Pool = Pool;
d3d9Desc.FVF = FVF;
d3d9Desc.FVF = FVF;https://www.youtube.com/watch?v=Zsu0RGeJkQg&t=907s
d3d9Desc.Usage = Usage;
*ppVertexBuffer = ref(new Direct3DVertexBuffer9(this, resource, d3d9Desc));
......@@ -815,34 +723,12 @@ namespace dxup {
HRESULT STDMETHODCALLTYPE Direct3DDevice9Ex::CreateRenderTarget(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle) {
CriticalSection cs(this);
InitReturnPtr(ppSurface);
if (ppSurface == nullptr)
return log::d3derr(D3DERR_INVALIDCALL, "CreateRenderTarget: ppSurface was nullptr.");
Com<IDirect3DTexture9> d3d9Texture;
// NOTE(Josh): May need to handle Lockable in future.
HRESULT result = CreateTextureInternal(D3DRTYPE_TEXTURE, true, Width, Height, 1, D3DUSAGE_RENDERTARGET, Format, D3DPOOL_DEFAULT, MultiSample, MultisampleQuality, false, (void**) &d3d9Texture, pSharedHandle);
if (FAILED(result))
return log::d3derr(D3DERR_INVALIDCALL, "CreateRenderTarget: failed to create rendertarget.");
return d3d9Texture->GetSurfaceLevel(0, ppSurface);
return Direct3DSurface9::Create(this, Width, Height, D3DUSAGE_RENDERTARGET, Format, MultiSample, false, (Direct3DSurface9 **)ppSurface);
}
HRESULT STDMETHODCALLTYPE Direct3DDevice9Ex::CreateDepthStencilSurface(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Discard, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle) {
CriticalSection cs(this);
InitReturnPtr(ppSurface);
if (ppSurface == nullptr)
return log::d3derr(D3DERR_INVALIDCALL, "CreateDepthStencilSurface: ppSurface was nullptr.");
Com<IDirect3DTexture9> d3d9Texture;
HRESULT result = CreateTextureInternal(D3DRTYPE_TEXTURE, true, Width, Height, 1, D3DUSAGE_DEPTHSTENCIL, Format, D3DPOOL_DEFAULT, MultiSample, MultisampleQuality, Discard, (void**) &d3d9Texture, pSharedHandle);
if (FAILED(result))
return log::d3derr(D3DERR_INVALIDCALL, "CreateDepthStencilSurface: failed to create depth stencil.");
return d3d9Texture->GetSurfaceLevel(0, ppSurface);
return Direct3DSurface9::Create(this, Width, Height, D3DUSAGE_DEPTHSTENCIL, Format, MultiSample, Discard, (Direct3DSurface9**)ppSurface);
}
HRESULT STDMETHODCALLTYPE Direct3DDevice9Ex::UpdateSurface(IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestinationSurface, CONST POINT* pDestPoint) {
CriticalSection cs(this);
......
......@@ -156,21 +156,6 @@ namespace dxup {
HRESULT STDMETHODCALLTYPE ResetEx(D3DPRESENT_PARAMETERS* pPresentationParameters, D3DDISPLAYMODEEX *pFullscreenDisplayMode) override;
HRESULT STDMETHODCALLTYPE GetDisplayModeEx(UINT iSwapChain, D3DDISPLAYMODEEX* pMode, D3DDISPLAYROTATION* pRotation) override;
HRESULT CreateTextureInternal(
D3DRESOURCETYPE Type,
bool FakeSurface,
UINT Width,
UINT Height,
UINT Levels,
DWORD Usage,
D3DFORMAT Format,
D3DPOOL Pool,
D3DMULTISAMPLE_TYPE MultiSample,
DWORD MultisampleQuality,
BOOL Discard,
void** ppTexture,
HANDLE* pSharedHandle);
void GetParent(Direct3D9Ex** parent);
ID3D11DeviceContext* GetContext();
ID3D11Device* GetD3D11Device();
......@@ -186,6 +171,10 @@ namespace dxup {
IDirect3DDevice9Ex** outDevice
);
inline bool checkFormat(DWORD usage, D3DRESOURCETYPE type, D3DFORMAT format) {
return m_parent->CheckDeviceFormat(m_adapterNum, m_deviceType, D3DFMT_X8R8G8B8, usage, type, format) == D3D_OK;
}
inline D3D9ImmediateRenderer* GetRenderer() {
return m_renderer;
}
......
......@@ -6,35 +6,22 @@
namespace dxup {
Direct3DSurface9::Direct3DSurface9(bool singletonSurface, UINT slice, UINT mip, Direct3DDevice9Ex* device, IUnknown* container, DXUPResource* resource, const D3D9ResourceDesc& desc)
Direct3DSurface9::Direct3DSurface9(UINT slice, UINT mip, Direct3DDevice9Ex* device, IUnknown* container, DXUPResource* resource, const D3D9ResourceDesc& desc)
: Direct3DSurface9Base{ device, nullptr, desc }
, m_container{ container }
, m_slice{ slice }
, m_mip{ mip }
, m_rtView{ nullptr }
, m_rtViewSRGB{ nullptr }
, m_singletonSurface{ singletonSurface }
{
if (singletonSurface && m_container != nullptr)
m_container->AddRef();
, m_rtViewSRGB{ nullptr } {
this->SetResource(resource);
}
Direct3DSurface9::~Direct3DSurface9() {
if (m_singletonSurface && m_container != nullptr)
m_container->Release();
}
HRESULT Direct3DSurface9::GetContainer(REFIID riid, void** ppContainer) {
InitReturnPtr(ppContainer);
if (ppContainer == nullptr)
return log::d3derr(D3DERR_INVALIDCALL, "GetContainer: ppContainer was nullptr.");
if (riid == __uuidof(IDirect3DDevice9) || riid == __uuidof(IDirect3DDevice9Ex)) {
*ppContainer = (void*)ref(m_device);
return D3D_OK;
}
if (m_container == nullptr)
return log::d3derr(D3DERR_INVALIDCALL, "GetContainer: m_container was nullptr.");
......@@ -217,4 +204,74 @@ namespace dxup {
rect.bottom = box->bottom;
return this->isRectValid(&rect);
}
HRESULT Direct3DSurface9::Create(Direct3DDevice9Ex* device,
UINT width,
UINT height,
DWORD usage,
D3DFORMAT format,
D3DMULTISAMPLE_TYPE multisample,
BOOL discard,
Direct3DSurface9** outSurface) {
InitReturnPtr(outSurface);
if (width == 0)
return log::d3derr(D3DERR_INVALIDCALL, "Direct3DSurface9::Create: width was 0.");
if (height == 0)
return log::d3derr(D3DERR_INVALIDCALL, "Direct3DSurface9::Create: height was 0.");
if (!device->checkFormat(usage, D3DRTYPE_SURFACE, format))
return log::d3derr(D3DERR_INVALIDCALL, "Direct3DSurface9::Create: unsupported format (%d).", format);
if (!outSurface)
return log::d3derr(D3DERR_INVALIDCALL, "Direct3DSurface9::Create: outSurface was nullptr.");
D3D11_TEXTURE2D_DESC desc;
desc.Width = width;
desc.Height = height;
desc.Format = convert::format(format);
desc.Usage = D3D11_USAGE_DEFAULT;
desc.CPUAccessFlags = 0;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.SampleDesc.Count = std::clamp((UINT)multisample, 1u, 16u);
desc.SampleDesc.Quality = 0;
desc.BindFlags = 0;
desc.MiscFlags = 0;
if (!(usage & D3DUSAGE_DEPTHSTENCIL))
desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;
desc.BindFlags |= (usage & D3DUSAGE_RENDERTARGET) ? D3D11_BIND_RENDER_TARGET : 0;
desc.BindFlags |= (usage & D3DUSAGE_DEPTHSTENCIL) ? D3D11_BIND_DEPTH_STENCIL : 0;
Com<ID3D11Texture2D> texture;
HRESULT result = device->GetD3D11Device()->CreateTexture2D(&desc, nullptr, &texture);
if (result == E_OUTOFMEMORY)
return log::d3derr(D3DERR_OUTOFVIDEOMEMORY, "Direct3DSurface9::Create: out of vram.");
if (FAILED(result))
return log::d3derr(D3DERR_INVALIDCALL, "Direct3DSurface9::Create: failed to create D3D11 texture. D3DFORMAT: %d, DXGI_FORMAT: %d", format, desc.Format); // TODO: stringify
DXUPResource * resource = DXUPResource::Create(device, texture.ptr(), usage, format);
if (resource == nullptr)
return log::d3derr(D3DERR_INVALIDCALL, "Direct3DSurface9::Create: failed to create DXUP resource.");
D3D9ResourceDesc d3d9Desc;
d3d9Desc.Format = format;
d3d9Desc.Pool = D3DPOOL_DEFAULT;
d3d9Desc.Usage = usage;
d3d9Desc.Discard = discard;
*outSurface = ref(Direct3DSurface9::Wrap(0, 0, device, device, resource, d3d9Desc));
return D3D_OK;
}
Direct3DSurface9* Direct3DSurface9::Wrap(UINT slice, UINT mip, Direct3DDevice9Ex* device, IUnknown* container, DXUPResource* resource, const D3D9ResourceDesc& desc) {
return new Direct3DSurface9(slice, mip, device, container, resource, desc);
}
}
\ No newline at end of file
......@@ -13,9 +13,6 @@ namespace dxup {
public:
Direct3DSurface9(bool fakeSurface, UINT slice, UINT mip, Direct3DDevice9Ex* device, IUnknown* container, DXUPResource* resource, const D3D9ResourceDesc& desc);
~Direct3DSurface9();
HRESULT WINAPI QueryInterface(REFIID riid, LPVOID* ppv) override;
HRESULT WINAPI GetContainer(REFIID riid, void** ppContainer) override;
HRESULT WINAPI GetDesc(D3DSURFACE_DESC *pDesc) override;
......@@ -42,8 +39,21 @@ namespace dxup {
bool isRectValid(const RECT* rect);
bool isBoxValid(const D3D11_BOX* box);
static HRESULT Create(Direct3DDevice9Ex* device,
UINT width,
UINT height,
DWORD usage,
D3DFORMAT format,
D3DMULTISAMPLE_TYPE multisample,
BOOL discard,
Direct3DSurface9** outSurface);
static Direct3DSurface9* Wrap(UINT slice, UINT mip, Direct3DDevice9Ex* device, IUnknown* container, DXUPResource* resource, const D3D9ResourceDesc& desc);
private:
Direct3DSurface9(UINT slice, UINT mip, Direct3DDevice9Ex* device, IUnknown* container, DXUPResource* resource, const D3D9ResourceDesc& desc);
IUnknown* m_container;
Com<IDXGISurface1> m_surface;
......@@ -51,8 +61,6 @@ namespace dxup {
Com<ID3D11RenderTargetView> m_rtViewSRGB;
Com<ID3D11DepthStencilView> m_dsView;
bool m_singletonSurface;
UINT m_slice;
UINT m_mip;
};
......
......@@ -90,7 +90,7 @@ namespace dxup {
if (m_buffers[i] != nullptr)
m_buffers[i]->SetResource(resource);
else
m_buffers[i] = new Direct3DSurface9(false, 0, 0, m_device, this, resource, d3d9Desc);
m_buffers[i] = Direct3DSurface9::Wrap(0, 0, m_device, this, resource, d3d9Desc);
if (m_rtRequired) {
D3D11_TEXTURE2D_DESC rtDesc;
......@@ -119,7 +119,7 @@ namespace dxup {
if (m_exposedBuffers[i] != nullptr)
m_exposedBuffers[i]->SetResource(resource);
else
m_exposedBuffers[i] = new Direct3DSurface9(false, 0, 0, m_device, this, resource, d3d9Desc);
m_exposedBuffers[i] = Direct3DSurface9::Wrap(0, 0, m_device, this, resource, d3d9Desc);
}
Com<IDXGIOutput> output;
......
This diff is collapsed.
......@@ -7,39 +7,13 @@
namespace dxup {
const D3DCUBEMAP_FACES Face0 = (D3DCUBEMAP_FACES)0;
template <D3DRESOURCETYPE ResourceType, uint32_t slices, typename ID3D9BaseType>
class Direct3DGeneric2DTexture9 : public Direct3DResource9<ResourceType, ID3D9BaseType> {
template <D3DRESOURCETYPE ResourceType, typename ID3D9BaseType>
class Direct3DBaseTexture9 : public Direct3DResource9<ResourceType, ID3D9BaseType> {
public:
Direct3DGeneric2DTexture9(bool singletonSurface, Direct3DDevice9Ex* device, DXUPResource* resource, const D3D9ResourceDesc& desc)
: Direct3DResource9<ResourceType, ID3D9BaseType>{ device, resource, desc }
, m_singletonSurface{ singletonSurface } {
m_surfaces.reserve(resource->GetSubresources());
// This should allow us to match D3D11CalcSubresource.
for (UINT slice = 0; slice < resource->GetSlices(); slice++) {
for (UINT mip = 0; mip < resource->GetMips(); mip++) {
Direct3DSurface9* surface = new Direct3DSurface9(singletonSurface, slice, mip, device, this, resource, desc);
if (!singletonSurface)
surface->AddRefPrivate();
m_surfaces.push_back(surface);
}
}
}
~Direct3DGeneric2DTexture9() {
if (!m_singletonSurface) {
for (IDirect3DSurface9* surface : m_surfaces) {
Direct3DSurface9* internalSurface = reinterpret_cast<Direct3DSurface9*>(surface);
internalSurface->ReleasePrivate();
}
}
}
Direct3DBaseTexture9(Direct3DDevice9Ex* pDevice, DXUPResource* resource, const D3D9ResourceDesc& d3d9Desc)
: Direct3DResource9<ResourceType, ID3D9BaseType>{ pDevice, resource, d3d9Desc } {}
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObj) {
InitReturnPtr(ppvObj);
......@@ -47,7 +21,7 @@ namespace dxup {
if (ppvObj == nullptr)
return E_POINTER;
if (riid == __uuidof(ID3D9BaseType) || riid == __uuidof(IDirect3DResource9) || riid == __uuidof(IUnknown)) {
if (riid == __uuidof(ID3D9BaseType) || riid == __uuidof(IDirect3DBaseTexture9) || riid == __uuidof(IDirect3DResource9) || riid == __uuidof(IUnknown)) {
*ppvObj = ref(this);
return D3D_OK;
}
......@@ -59,67 +33,6 @@ namespace dxup {
return (DWORD)this->GetDXUPResource()->GetMips();
}
HRESULT STDMETHODCALLTYPE GetLevelDesc(UINT Level, D3DSURFACE_DESC *pDesc) {
if (Level >= m_surfaces.size())
return log::d3derr(D3DERR_INVALIDCALL, "GetLevelDesc: level out of bounds.");
return m_surfaces[Level]->GetDesc(pDesc);
}
HRESULT STDMETHODCALLTYPE GetCubeMapSurface(D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface9** ppCubeMapSurface) {
UINT subresource = D3D11CalcSubresource(Level, (UINT)FaceType, this->GetDXUPResource()->GetMips());
InitReturnPtr(ppCubeMapSurface);
if (subresource >= m_surfaces.size())
return log::d3derr(D3DERR_INVALIDCALL, "GetCubeMapSurface: subresource out of bounds (FaceType = %d, Level = %d).", FaceType, Level);
if (ppCubeMapSurface == nullptr)
return log::d3derr(D3DERR_INVALIDCALL, "GetCubeMapSurface: ppCubeMapSurface was nullptr.");
*ppCubeMapSurface = ref(m_surfaces[subresource]);
return D3D_OK;
}
HRESULT STDMETHODCALLTYPE GetSurfaceLevel(UINT Level, IDirect3DSurface9** ppSurfaceLevel) {
return this->GetCubeMapSurface((D3DCUBEMAP_FACES)0, Level, ppSurfaceLevel);
}
HRESULT STDMETHODCALLTYPE LockRect(D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, const RECT* pRect, DWORD Flags) {
UINT subresource = D3D11CalcSubresource(Level, (UINT)FaceType, this->GetDXUPResource()->GetMips());
if (subresource >= m_surfaces.size())
return log::d3derr(D3DERR_INVALIDCALL, "LockRect: subresource out of bounds (FaceType = %d, Level = %d).", FaceType, Level);
return m_surfaces[subresource]->LockRect(pLockedRect, pRect, Flags);
}
HRESULT STDMETHODCALLTYPE LockRect(UINT Level, D3DLOCKED_RECT* pLockedRect, const RECT* pRect, DWORD Flags) {
return this->LockRect(Face0, Level, pLockedRect, pRect, Flags);
}
HRESULT STDMETHODCALLTYPE UnlockRect(D3DCUBEMAP_FACES FaceType, UINT Level) {
UINT subresource = D3D11CalcSubresource(Level, (UINT)FaceType, this->GetDXUPResource()->GetMips());
if (subresource >= m_surfaces.size())
return log::d3derr(D3DERR_INVALIDCALL, "UnlockRect: subresource out of bounds (FaceType = %d, Level = %d).", FaceType, Level);
return m_surfaces[subresource]->UnlockRect();
}
HRESULT STDMETHODCALLTYPE UnlockRect(UINT Level) {
return this->UnlockRect(Face0, Level);
}
HRESULT STDMETHODCALLTYPE AddDirtyRect(D3DCUBEMAP_FACES FaceType, const RECT* pDirtyRect) {
log::stub("Direct3DTexture9::AddDirtyRect");
return D3D_OK;
}
HRESULT STDMETHODCALLTYPE AddDirtyRect(const RECT* pDirtyRect) {
return this->AddDirtyRect(Face0, pDirtyRect);
}
void STDMETHODCALLTYPE GenerateMipSubLevels() {
if (this->GetDXUPResource()->GetSRV(false) != nullptr)
......@@ -128,10 +41,6 @@ namespace dxup {
log::warn("GenerateMipSubLevels called on a texture with no SRV.");
}
inline bool IsFakeSurface() {
return m_singletonSurface;
}
DWORD STDMETHODCALLTYPE SetLOD(DWORD LODNew) override {
log::stub("Direct3DBaseTexture9::SetLOD");
return 0;
......@@ -150,11 +59,65 @@ namespace dxup {
return D3DTEXF_ANISOTROPIC;
}
};
using Direct3DTexture9Base = Direct3DBaseTexture9<D3DRTYPE_TEXTURE, IDirect3DTexture9>;
class Direct3DTexture9 final : public Direct3DTexture9Base {
public:
~Direct3DTexture9();
HRESULT STDMETHODCALLTYPE GetLevelDesc(UINT Level, D3DSURFACE_DESC *pDesc) override;
HRESULT STDMETHODCALLTYPE GetSurfaceLevel(UINT Level, IDirect3DSurface9** ppSurfaceLevel) override;
HRESULT STDMETHODCALLTYPE LockRect(UINT Level, D3DLOCKED_RECT* pLockedRect, const RECT* pRect, DWORD Flags) override;
HRESULT STDMETHODCALLTYPE UnlockRect(UINT Level) override;
HRESULT STDMETHODCALLTYPE AddDirtyRect(const RECT* pDirtyRect) override;
static HRESULT Create(Direct3DDevice9Ex* device,
UINT width,
UINT height,
UINT levels,
DWORD usage,
D3DFORMAT format,
D3DPOOL pool,
Direct3DTexture9** outTexture);
private:
bool m_singletonSurface;
Direct3DTexture9(Direct3DDevice9Ex* device, DXUPResource* resource, const D3D9ResourceDesc& desc);
std::vector<IDirect3DSurface9*> m_surfaces;
};
using Direct3DCubeTexture9Base = Direct3DBaseTexture9<D3DRTYPE_CUBETEXTURE, IDirect3DCubeTexture9>;
class Direct3DCubeTexture9 final : public Direct3DCubeTexture9Base {
public:
~Direct3DCubeTexture9();
HRESULT STDMETHODCALLTYPE GetLevelDesc(UINT Level, D3DSURFACE_DESC *pDesc) override;
HRESULT STDMETHODCALLTYPE GetCubeMapSurface(D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface9** ppCubeMapSurface) override;
HRESULT STDMETHODCALLTYPE LockRect(D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, const RECT* pRect, DWORD Flags) override;
HRESULT STDMETHODCALLTYPE UnlockRect(D3DCUBEMAP_FACES FaceType, UINT Level) override;
HRESULT STDMETHODCALLTYPE AddDirtyRect(D3DCUBEMAP_FACES FaceType, const RECT* pDirtyRect) override;
static HRESULT Create(Direct3DDevice9Ex* device,
UINT edgeLength,
UINT levels,
DWORD usage,
D3DFORMAT format,
D3DPOOL pool,
Direct3DCubeTexture9** outTexture);
private:
Direct3DCubeTexture9(Direct3DDevice9Ex* device, DXUPResource* resource, const D3D9ResourceDesc& desc);
std::vector<IDirect3DSurface9*> m_surfaces;
};
using Direct3DTexture9 = Direct3DGeneric2DTexture9<D3DRTYPE_TEXTURE, 1, IDirect3DTexture9>;
using Direct3DCubeTexture9 = Direct3DGeneric2DTexture9<D3DRTYPE_CUBETEXTURE, 6, IDirect3DCubeTexture9>;
}
\ No newline at end of file
......@@ -189,7 +189,7 @@ namespace dxup {
if (pool == D3DPOOL_SYSTEMMEM || pool == D3DPOOL_SCRATCH)
return D3D11_USAGE_STAGING;
if (usage & D3DUSAGE_DYNAMIC)
if (usage & D3DUSAGE_DYNAMIC && !(usage & D3DUSAGE_RENDERTARGET) && !(usage & D3DUSAGE_DEPTHSTENCIL) && !(usage & D3DUSAGE_AUTOGENMIPMAP))
return D3D11_USAGE_DYNAMIC;
return D3D11_USAGE_DEFAULT;
......
......@@ -12,7 +12,8 @@ d3d9_main_src = [
'd3d9_state_cache.cpp',
'd3d9_state.cpp',
'd3d9_renderer.cpp',
'd3d11_dynamic_buffer.cpp'
'd3d11_dynamic_buffer.cpp',
'd3d9_texture.cpp'
]
d3d9_deps = [ lib_d3d11, lib_dxgi, lib_shlwapi, util_dep, dx9asm_dep ]
......