Jump to content
  • Advertisement
Sign in to follow this  
Florent 974

DX11 Locking lowest mip levels of a DXT texture

This topic is 2899 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm writing a cross platform engine (GL, GL ES, DX9, DX10, DX11), I've got a Texture class with a Lock and Unlock method, in directX, depending on the pool & usage some textures can be locked directly and some cannot and must use a temporary "staging" texture ( or surface for locking a single mip level ), this works perfectly, except with DX9...

In (more or less) pseudo code this look like this (Considering only the particular case of a DXT texture in D3DPOOL_DEFAULT which cannot be locked directly):

Texture::Lock( u32 _mipLevel )
u32 mipWidth, mipHeight;
GetMipMapDimensions( _mipLevel, mipWidth, mipHeight );

//DX9 complains about creating DXT textures less than 4x4 in size
mipWidth = Max( mipWidth, 4 );
mipHeight = Max( mipHeight, 4 );

pDevice->CreateTexture( mipWidth, mipHeight,
1,//mip maps
&m_pStagingTexture, NULL );

m_pStagingTexture->Lock( ... );

Texture::Unlock( u32 _mipLevel )
if( m_pStagingTexture )
m_pStagingTexture->UnlockRect( 0 );

IDirect3DSurface9* pStagingSurface;
IDirect3DSurface9* pDestSurface;

m_pStagingTexture->GetSurfaceLevel( 0, &pStagingSurface );

((IDirect3DTexture9*)m_pTex)->GetSurfaceLevel( _mipLevel, &pDestSurface );

//Here I also tried to call UpdateSurface with various parameters for pSourceRect and pDestinationPoint instead of NULL, with no success :(
pDevice->UpdateSurface( pStagingSurface, NULL, pDestSurface, NULL );

SAFE_RELEASE( m_pStagingTexture )



This works nicely for uncompressed formats, but this breaks when locking the lowest mip levels (1x1 and 2x2) because of the DXT 4x4 block size

if TRY_FORCING_MINIMUM_STAGING_TEX_SIZE is NOT defined I get "Direct3D9: (ERROR) :DXT Formats require width/height to be a multiple of 4. CreateTexture failed." while creating the staging texture

if TRY_FORCING_MINIMUM_STAGING_TEX_SIZE is defined I get "Direct3D9: (ERROR) :pRect doesn't fit inside the surface" while calling UpdateSurface

I think I could get away by creating a staging texture with the full mip chain instead of only the mip level I'm locking and then using UpdateTexture instead of UpdateSurface but this would be very sub-optimal as well as making my code kind-of ugly

Do you know a solution to this problem ? ( I could eventually use D3DPOOL_MANAGED textures and lock them directly, but I'd rather avoid that solution if possible )

Thanks in advance

Florent Tournade

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!