diff --git a/DirectXTex/DirectXTex.h b/DirectXTex/DirectXTex.h index a6a7331..80bf95b 100644 --- a/DirectXTex/DirectXTex.h +++ b/DirectXTex/DirectXTex.h @@ -58,7 +58,7 @@ namespace DirectX bool IsPacked( _In_ DXGI_FORMAT fmt ); bool IsVideo( _In_ DXGI_FORMAT fmt ); bool IsSRGB( _In_ DXGI_FORMAT fmt ); - bool IsTypeless( _In_ DXGI_FORMAT fmt ); + bool IsTypeless( _In_ DXGI_FORMAT fmt, _In_ bool partialTypeless=true ); bool HasAlpha( _In_ DXGI_FORMAT fmt ); diff --git a/DirectXTex/DirectXTex.inl b/DirectXTex/DirectXTex.inl index 46f0c30..07202d8 100644 --- a/DirectXTex/DirectXTex.inl +++ b/DirectXTex/DirectXTex.inl @@ -127,7 +127,7 @@ inline bool IsSRGB( DXGI_FORMAT fmt ) } _Use_decl_annotations_ -inline bool IsTypeless( DXGI_FORMAT fmt ) +inline bool IsTypeless( DXGI_FORMAT fmt, bool partialTypeless ) { switch( fmt ) { @@ -136,15 +136,11 @@ inline bool IsTypeless( DXGI_FORMAT fmt ) case DXGI_FORMAT_R16G16B16A16_TYPELESS: case DXGI_FORMAT_R32G32_TYPELESS: case DXGI_FORMAT_R32G8X24_TYPELESS: - case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: - case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: case DXGI_FORMAT_R10G10B10A2_TYPELESS: case DXGI_FORMAT_R8G8B8A8_TYPELESS: case DXGI_FORMAT_R16G16_TYPELESS: case DXGI_FORMAT_R32_TYPELESS: case DXGI_FORMAT_R24G8_TYPELESS: - case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: - case DXGI_FORMAT_X24_TYPELESS_G8_UINT: case DXGI_FORMAT_R8G8_TYPELESS: case DXGI_FORMAT_R16_TYPELESS: case DXGI_FORMAT_R8_TYPELESS: @@ -159,6 +155,12 @@ inline bool IsTypeless( DXGI_FORMAT fmt ) case DXGI_FORMAT_BC7_TYPELESS: return true; + case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: + case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: + case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: + case DXGI_FORMAT_X24_TYPELESS_G8_UINT: + return partialTypeless; + default: return false; } diff --git a/DirectXTex/DirectXTexConvert.cpp b/DirectXTex/DirectXTexConvert.cpp index 59fba9b..1a55be6 100644 --- a/DirectXTex/DirectXTexConvert.cpp +++ b/DirectXTex/DirectXTexConvert.cpp @@ -530,7 +530,7 @@ bool _LoadScanline( XMVECTOR* pDestination, size_t count, { assert( pDestination && count > 0 && (((uintptr_t)pDestination & 0xF) == 0) ); assert( pSource && size > 0 ); - assert( IsValid(format) && !IsVideo(format) && !IsTypeless(format) && !IsCompressed(format) ); + assert( IsValid(format) && !IsVideo(format) && !IsTypeless(format,false) && !IsCompressed(format) ); XMVECTOR* __restrict dPtr = pDestination; if ( !dPtr ) @@ -601,6 +601,35 @@ bool _LoadScanline( XMVECTOR* pDestination, size_t count, } return false; + case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: + if ( size >= (sizeof(float)+sizeof(uint32_t)) ) + { + const float * sPtr = reinterpret_cast(pSource); + for( size_t icount = 0; icount < size; icount += (sizeof(float)+sizeof(uint32_t)) ) + { + if ( dPtr >= ePtr ) break; + *(dPtr++) = XMVectorSet( sPtr[0], 0.f /* typeless component assumed zero */, 0.f, 1.f ); + sPtr += 2; + } + return true; + } + return false; + + case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: + if ( size >= (sizeof(float)+sizeof(uint32_t)) ) + { + const float * sPtr = reinterpret_cast(pSource); + for( size_t icount = 0; icount < size; icount += (sizeof(float)+sizeof(uint32_t)) ) + { + const uint8_t* pg8 = reinterpret_cast( &sPtr[1] ); + if ( dPtr >= ePtr ) break; + *(dPtr++) = XMVectorSet( 0.f /* typeless component assumed zero */, static_cast( *pg8 ), 0.f, 1.f ); + sPtr += 2; + } + return true; + } + return false; + case DXGI_FORMAT_R10G10B10A2_UNORM: LOAD_SCANLINE( XMUDECN4, XMLoadUDecN4 ); @@ -726,6 +755,36 @@ bool _LoadScanline( XMVECTOR* pDestination, size_t count, } return false; + case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: + if ( size >= sizeof(uint32_t) ) + { + const uint32_t * sPtr = reinterpret_cast(pSource); + for( size_t icount = 0; icount < size; icount += sizeof(uint32_t) ) + { + float r = static_cast( *sPtr & 0xFFFFFF ) / 16777215.f; + ++sPtr; + if ( dPtr >= ePtr ) break; + *(dPtr++) = XMVectorSet( r, 0.f /* typeless component assumed zero */, 0.f, 1.f ); + } + return true; + } + return false; + + case DXGI_FORMAT_X24_TYPELESS_G8_UINT: + if ( size >= sizeof(uint32_t) ) + { + const uint32_t * sPtr = reinterpret_cast(pSource); + for( size_t icount = 0; icount < size; icount += sizeof(uint32_t) ) + { + float g = static_cast( ( *sPtr & 0xFF000000 ) >> 24 ); + ++sPtr; + if ( dPtr >= ePtr ) break; + *(dPtr++) = XMVectorSet( 0.f /* typeless component assumed zero */, g, 0.f, 1.f ); + } + return true; + } + return false; + case DXGI_FORMAT_R8G8_UNORM: LOAD_SCANLINE2( XMUBYTEN2, XMLoadUByteN2, g_XMIdentityR3 )