Merge pull request #275 from Areloch/3DTextureFix

Fixes the backend logic for setting/creating 3DTextures in D3D11
This commit is contained in:
Brian Roberts 2020-08-12 14:50:04 -05:00 committed by GitHub
commit f582fa0dcd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 24 deletions

View file

@ -133,6 +133,11 @@ void GFXD3D11TextureManager::_innerCreateTexture( GFXD3D11TextureObject *retTex,
AssertFatal(false, "GFXD3D11TextureManager::_createTexture - failed to create volume texture!"); AssertFatal(false, "GFXD3D11TextureManager::_createTexture - failed to create volume texture!");
} }
if (!retTex->mProfile->isSystemMemory())
{
createResourceView(height, width, depth, d3dTextureFormat, numMipLevels, bindFlags, retTex);
}
retTex->mTextureSize.set(width, height, depth); retTex->mTextureSize.set(width, height, depth);
retTex->get3DTex()->GetDesc(&desc); retTex->get3DTex()->GetDesc(&desc);
retTex->mMipLevels = numMipLevels; retTex->mMipLevels = numMipLevels;

View file

@ -70,9 +70,17 @@ GFXLockedRect *GFXD3D11TextureObject::lock(U32 mipLevel /*= 0*/, RectI *inRect /
if( !mStagingTex || if( !mStagingTex ||
mStagingTex->getWidth() != getWidth() || mStagingTex->getWidth() != getWidth() ||
mStagingTex->getHeight() != getHeight() ) mStagingTex->getHeight() != getHeight() ||
mStagingTex->getDepth() != getDepth())
{ {
mStagingTex.set( getWidth(), getHeight(), mFormat, &GFXSystemMemTextureProfile, avar("%s() - mLockTex (line %d)", __FUNCTION__, __LINE__) ); if (getDepth() != 0)
{
mStagingTex.set(getWidth(), getHeight(), getDepth(), mFormat, &GFXSystemMemTextureProfile, avar("%s() - mLockTex (line %d)", __FUNCTION__, __LINE__, 0));
}
else
{
mStagingTex.set(getWidth(), getHeight(), mFormat, &GFXSystemMemTextureProfile, avar("%s() - mLockTex (line %d)", __FUNCTION__, __LINE__));
}
} }
ID3D11DeviceContext* pContext = D3D11DEVICECONTEXT; ID3D11DeviceContext* pContext = D3D11DEVICECONTEXT;
@ -82,13 +90,20 @@ GFXLockedRect *GFXD3D11TextureObject::lock(U32 mipLevel /*= 0*/, RectI *inRect /
GFXD3D11TextureObject* pD3DStagingTex = (GFXD3D11TextureObject*)&(*mStagingTex); GFXD3D11TextureObject* pD3DStagingTex = (GFXD3D11TextureObject*)&(*mStagingTex);
//map staging texture //map staging texture
HRESULT hr = pContext->Map(pD3DStagingTex->get2DTex(), mLockedSubresource, D3D11_MAP_READ, 0, &mapInfo); HRESULT hr;
bool is3D = mStagingTex->getDepth() != 0;
if (is3D) //3d texture
hr = pContext->Map(pD3DStagingTex->get3DTex(), mLockedSubresource, D3D11_MAP_READ, 0, &mapInfo);
else
hr = pContext->Map(pD3DStagingTex->get2DTex(), mLockedSubresource, D3D11_MAP_READ, 0, &mapInfo);
if (FAILED(hr)) if (FAILED(hr))
AssertFatal(false, "GFXD3D11TextureObject:lock - failed to map render target resource!"); AssertFatal(false, "GFXD3D11TextureObject:lock - failed to map render target resource!");
const U32 width = mTextureSize.x >> mipLevel; const U32 width = mTextureSize.x >> mipLevel;
const U32 height = mTextureSize.y >> mipLevel; const U32 height = mTextureSize.y >> mipLevel;
const U32 depth = is3D ? mTextureSize.z >> mipLevel : 1;
//calculate locked box region and offset //calculate locked box region and offset
if (inRect) if (inRect)
@ -100,7 +115,7 @@ GFXLockedRect *GFXD3D11TextureObject::lock(U32 mipLevel /*= 0*/, RectI *inRect /
mLockBox.left = inRect->point.x; mLockBox.left = inRect->point.x;
mLockBox.bottom = inRect->point.y + inRect->extent.y; mLockBox.bottom = inRect->point.y + inRect->extent.y;
mLockBox.right = inRect->point.x + inRect->extent.x; mLockBox.right = inRect->point.x + inRect->extent.x;
mLockBox.back = 1; mLockBox.back = depth;
mLockBox.front = 0; mLockBox.front = 0;
//calculate offset //calculate offset
@ -112,7 +127,7 @@ GFXLockedRect *GFXD3D11TextureObject::lock(U32 mipLevel /*= 0*/, RectI *inRect /
mLockBox.left = 0; mLockBox.left = 0;
mLockBox.bottom = height; mLockBox.bottom = height;
mLockBox.right = width; mLockBox.right = width;
mLockBox.back = 1; mLockBox.back = depth;
mLockBox.front = 0; mLockBox.front = 0;
} }
@ -132,12 +147,27 @@ void GFXD3D11TextureObject::unlock(U32 mipLevel)
ID3D11DeviceContext* pContext = D3D11DEVICECONTEXT; ID3D11DeviceContext* pContext = D3D11DEVICECONTEXT;
GFXD3D11TextureObject* pD3DStagingTex = (GFXD3D11TextureObject*)&(*mStagingTex); GFXD3D11TextureObject* pD3DStagingTex = (GFXD3D11TextureObject*)&(*mStagingTex);
ID3D11Texture2D *pStagingTex = pD3DStagingTex->get2DTex();
//unmap staging texture bool is3D = mStagingTex->getDepth() != 0;
pContext->Unmap(pStagingTex, mLockedSubresource);
//copy lock box region from the staging texture to our regular texture if (is3D)
pContext->CopySubresourceRegion(mD3DTexture, mLockedSubresource, mLockBox.left, mLockBox.top, 0, pStagingTex, mLockedSubresource, &mLockBox); {
ID3D11Texture3D* pStagingTex = pD3DStagingTex->get3DTex();
//unmap staging texture
pContext->Unmap(pStagingTex, mLockedSubresource);
//copy lock box region from the staging texture to our regular texture
pContext->CopySubresourceRegion(mD3DTexture, mLockedSubresource, mLockBox.left, mLockBox.top, mLockBox.front, pStagingTex, mLockedSubresource, &mLockBox);
}
else
{
ID3D11Texture2D* pStagingTex = pD3DStagingTex->get2DTex();
//unmap staging texture
pContext->Unmap(pStagingTex, mLockedSubresource);
//copy lock box region from the staging texture to our regular texture
pContext->CopySubresourceRegion(mD3DTexture, mLockedSubresource, mLockBox.left, mLockBox.top, 0, pStagingTex, mLockedSubresource, &mLockBox);
}
PROFILE_END(); PROFILE_END();

View file

@ -161,14 +161,14 @@ bool GFXTexHandle::set( U32 width, U32 height, GFXFormat format, GFXTextureProfi
return isValid(); return isValid();
} }
bool GFXTexHandle::set( U32 width, U32 height, U32 depth, void *pixels, GFXFormat format, GFXTextureProfile *profile, const String &desc, U32 numMipLevels ) bool GFXTexHandle::set(U32 width, U32 height, U32 depth, GFXFormat format, GFXTextureProfile* profile, const String& desc, U32 numMipLevels)
{ {
// Clear the existing texture first, so that // Clear the existing texture first, so that
// its memory is free for the new allocation. // its memory is free for the new allocation.
free(); free();
// Create and set the new texture. // Create and set the new texture.
StrongObjectRef::set( TEXMGR->createTexture( width, height, depth, pixels, format, profile,numMipLevels ) ); StrongObjectRef::set(TEXMGR->createTexture(width, height, depth, format, profile, numMipLevels));
#ifdef TORQUE_DEBUG #ifdef TORQUE_DEBUG
if ( getPointer() ) if ( getPointer() )

View file

@ -60,7 +60,7 @@ public:
// Sized bitmap // Sized bitmap
GFXTexHandle( U32 width, U32 height, GFXFormat format, GFXTextureProfile *profile, const String &desc, U32 numMipLevels = 1, S32 antialiasLevel = 0); GFXTexHandle( U32 width, U32 height, GFXFormat format, GFXTextureProfile *profile, const String &desc, U32 numMipLevels = 1, S32 antialiasLevel = 0);
bool set( U32 width, U32 height, GFXFormat format, GFXTextureProfile *profile, const String &desc, U32 numMipLevels = 1, S32 antialiasLevel = 0); bool set( U32 width, U32 height, GFXFormat format, GFXTextureProfile *profile, const String &desc, U32 numMipLevels = 1, S32 antialiasLevel = 0);
bool set( U32 width, U32 height, U32 depth, void *pixels, GFXFormat format, GFXTextureProfile *profile, const String &desc, U32 numMipLevels = 1 ); bool set( U32 width, U32 height, U32 depth, GFXFormat format, GFXTextureProfile* profile, const String& desc, U32 numMipLevels = 1);
/// Returns the width and height as a point. /// Returns the width and height as a point.
Point2I getWidthHeight() const { return getPointer() ? Point2I( getPointer()->getWidth(), getPointer()->getHeight() ) : Point2I::Zero; } Point2I getWidthHeight() const { return getPointer() ? Point2I( getPointer()->getWidth(), getPointer()->getHeight() ) : Point2I::Zero; }

View file

@ -815,7 +815,6 @@ GFXTextureObject *GFXTextureManager::createTexture( U32 width, U32 height, GFXFo
GFXTextureObject *GFXTextureManager::createTexture( U32 width, GFXTextureObject *GFXTextureManager::createTexture( U32 width,
U32 height, U32 height,
U32 depth, U32 depth,
void *pixels,
GFXFormat format, GFXFormat format,
GFXTextureProfile *profile, GFXTextureProfile *profile,
U32 numMipLevels) U32 numMipLevels)
@ -831,14 +830,6 @@ GFXTextureObject *GFXTextureManager::createTexture( U32 width,
return NULL; return NULL;
} }
// Call the internal load...
if( !_loadTexture( ret, pixels ) )
{
Con::errorf("GFXTextureManager - failed to load volume texture" );
return NULL;
}
// And do book-keeping... // And do book-keeping...
// - texture info // - texture info
ret->mBitmapSize.set( width, height, depth ); ret->mBitmapSize.set( width, height, depth );

View file

@ -119,7 +119,6 @@ public:
virtual GFXTextureObject *createTexture( U32 width, virtual GFXTextureObject *createTexture( U32 width,
U32 height, U32 height,
U32 depth, U32 depth,
void *pixels,
GFXFormat format, GFXFormat format,
GFXTextureProfile *profile, GFXTextureProfile *profile,
U32 numMipLevels = 1); U32 numMipLevels = 1);