Merge pull request #2044 from LukeUsher/create-surface-as-texture

d3d: wrap surfaces in textures
This commit is contained in:
PatrickvL 2020-11-25 22:05:09 +01:00 committed by GitHub
commit b2ca28198e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 40 deletions

View File

@ -5691,30 +5691,34 @@ void CreateHostResource(xbox::X_D3DResource *pResource, DWORD D3DUsage, int iTex
// Create the surface/volume/(volume/cube/)texture
switch (XboxResourceType) {
case xbox::X_D3DRTYPE_SURFACE: {
if (D3DUsage & D3DUSAGE_RENDERTARGET) {
hRet = g_pD3DDevice->CreateRenderTarget(dwWidth * g_RenderScaleFactor, dwHeight * g_RenderScaleFactor, PCFormat,
g_EmuCDPD.HostPresentationParameters.MultiSampleType,
0, // MultisampleQuality
true, // Lockable
&pNewHostSurface,
nullptr // pSharedHandle
);
DEBUG_D3DRESULT(hRet, "g_pD3DDevice->CreateRenderTarget");
} else
if (D3DUsage & D3DUSAGE_DEPTHSTENCIL) {
hRet = g_pD3DDevice->CreateDepthStencilSurface(dwWidth * g_RenderScaleFactor, dwHeight * g_RenderScaleFactor, PCFormat,
g_EmuCDPD.HostPresentationParameters.MultiSampleType,
0, // MultisampleQuality
false, // Discard
&pNewHostSurface,
nullptr
nullptr // pSharedHandle
);
DEBUG_D3DRESULT(hRet, "g_pD3DDevice->CreateDepthStencilSurface");
}
else {
D3DPool = D3DPOOL_SYSTEMMEM;
hRet = g_pD3DDevice->CreateOffscreenPlainSurface(dwWidth, dwHeight, PCFormat, D3DPool, &pNewHostSurface, nullptr);
DEBUG_D3DRESULT(hRet, "g_pD3DDevice->CreateOffscreenPlainSurface");
// Note : This handles both (D3DUsage & D3DUSAGE_RENDERTARGET) and otherwise alike
hRet = g_pD3DDevice->CreateTexture(dwWidth * g_RenderScaleFactor, dwHeight * g_RenderScaleFactor,
1, // Levels
D3DUSAGE_RENDERTARGET, // Usage always as render target
PCFormat,
D3DPool, // D3DPOOL_DEFAULT
&pNewHostTexture,
nullptr // pSharedHandle
);
DEBUG_D3DRESULT(hRet, "g_pD3DDevice->CreateTexture");
if (hRet == D3D_OK) {
HRESULT hRet2 = pNewHostTexture->GetSurfaceLevel(0, &pNewHostSurface);
DEBUG_D3DRESULT(hRet2, "pNewHostTexture->pNewHostSurface");
pNewHostTexture->Release();
pNewHostTexture = nullptr;
}
}
// First fail, retry with a fallback format
@ -5725,7 +5729,7 @@ void CreateHostResource(xbox::X_D3DResource *pResource, DWORD D3DUsage, int iTex
DXGetErrorString(hRet), DXGetErrorDescription(hRet));
}
else {
EmuLog(LOG_LEVEL::WARNING, "CreateImageSurface Failed\n\nError: %s\nDesc: %s",
EmuLog(LOG_LEVEL::WARNING, "CreateTexture Failed\n\nError: %s\nDesc: %s",
DXGetErrorString(hRet), DXGetErrorDescription(hRet));
}
@ -6958,35 +6962,22 @@ IDirect3DBaseTexture* CxbxConvertXboxSurfaceToHostTexture(xbox::X_D3DBaseTexture
{
LOG_INIT; // Allows use of DEBUG_D3DRESULT
IDirect3DTexture* pNewHostTexture = nullptr;
#if 0 // TODO : Complete, debug and activate (and then cleanup GetHostBaseTexture)
D3DFORMAT PCFormat = D3DFMT_A8B8G8R8; // TODO : Derive from pBaseTexture
IDirect3DSurface* pHostSurface = GetHostSurface(pBaseTexture); // TODO : Extend this with a texture channel number too, if surfaces send to SetTexture can be paletized format?
DWORD dwWidth = GetPixelContainerWidth(pBaseTexture);
DWORD dwHeight = GetPixelContainerHeight(pBaseTexture);
UINT dwMipMapLevels = CxbxGetPixelContainerMipMapLevels(pBaseTexture);
HRESULT hRet = g_pD3DDevice->CreateTexture(dwWidth, dwHeight, dwMipMapLevels,
/*Usage=*/0, PCFormat, D3DPOOL_SYSTEMMEM, &pNewHostTexture, nullptr);
DEBUG_D3DRESULT(hRet, "g_pD3DDevice->CreateTexture (in CxbxConvertXboxSurfaceToHostTexture)");
if (hRet != D3D_OK) {
CxbxKrnlCleanup("CreateTexture Failed!\n\nError: \nDesc: "/*,
DXGetErrorString(hRet), DXGetErrorDescription(hRet)*/);
IDirect3DSurface* pHostSurface = GetHostSurface(pBaseTexture);
if (!pHostSurface) {
LOG_TEST_CASE("Failed to get host surface");
return nullptr;
}
IDirect3DSurface* pHostTextureSurface = nullptr;
hRet = pNewHostTexture->GetSurfaceLevel(/*Level=*/0, &pHostTextureSurface);
DEBUG_D3DRESULT(hRet, "pHostBaseTexture->GetSurfaceLevel");
IDirect3DBaseTexture* pNewHostBaseTexture = nullptr;
auto hRet = pHostSurface->GetContainer(IID_PPV_ARGS(&pNewHostBaseTexture));
DEBUG_D3DRESULT(hRet, "pHostSurface->GetContainer");
if (hRet == D3D_OK) {
hRet = D3DXLoadSurfaceFromSurface(pHostTextureSurface, nullptr, nullptr, pHostSurface, nullptr, nullptr, D3DX_FILTER_NONE, 0x00000000);
DEBUG_D3DRESULT(hRet, "D3DXLoadSurfaceFromSurface");
pHostTextureSurface->Release();
if (FAILED(hRet)) {
LOG_TEST_CASE("Failed to get Texture from Surface");
return nullptr;
}
#endif
return (IDirect3DBaseTexture*)pNewHostTexture; // return it as a base texture
return pNewHostBaseTexture;
}
void CxbxUpdateHostTextures()