diff --git a/DirectXTex/DirectXTex.h b/DirectXTex/DirectXTex.h index c3a997f..5b09eb6 100644 --- a/DirectXTex/DirectXTex.h +++ b/DirectXTex/DirectXTex.h @@ -67,6 +67,9 @@ namespace DirectX CP_FLAGS_NONE = 0x0, // Normal operation CP_FLAGS_LEGACY_DWORD = 0x1, // Assume pitch is DWORD aligned instead of BYTE aligned CP_FLAGS_PARAGRAPH = 0x2, // Assume pitch is 16-byte aligned instead of BYTE aligned + CP_FLAGS_YMM = 0x4, // Assume pitch is 32-byte aligned instead of BYTE aligned + CP_FLAGS_ZMM = 0x8, // Assume pitch is 64-byte aligned instead of BYTE aligned + CP_FLAGS_PAGE4K = 0x200, // Assume pitch is 4096-byte aligned instead of BYTE aligned CP_FLAGS_24BPP = 0x10000, // Override with a legacy 24 bits-per-pixel format size CP_FLAGS_16BPP = 0x20000, // Override with a legacy 16 bits-per-pixel format size CP_FLAGS_8BPP = 0x40000, // Override with a legacy 8 bits-per-pixel format size diff --git a/DirectXTex/DirectXTexCompress.cpp b/DirectXTex/DirectXTexCompress.cpp index a66bbdf..0e338ed 100644 --- a/DirectXTex/DirectXTexCompress.cpp +++ b/DirectXTex/DirectXTexCompress.cpp @@ -110,7 +110,7 @@ static HRESULT _CompressBC( _In_ const Image& image, _In_ const Image& result, _ uint8_t* dptr = pDest; size_t ph = std::min( 4, image.height - h ); size_t w = 0; - for( size_t count = 0; count < rowPitch; count += sbpp*4, w += 4 ) + for( size_t count = 0; count < result.rowPitch; count += blocksize, w += 4 ) { size_t pw = std::min( 4, image.width - w ); assert( pw > 0 && ph > 0 ); diff --git a/DirectXTex/DirectXTexUtil.cpp b/DirectXTex/DirectXTexUtil.cpp index 5a343fd..cd8a88f 100644 --- a/DirectXTex/DirectXTexUtil.cpp +++ b/DirectXTex/DirectXTexUtil.cpp @@ -654,20 +654,39 @@ void ComputePitch( DXGI_FORMAT fmt, size_t width, size_t height, else bpp = BitsPerPixel( fmt ); - if ( flags & CP_FLAGS_LEGACY_DWORD ) + if ( flags & ( CP_FLAGS_LEGACY_DWORD | CP_FLAGS_PARAGRAPH | CP_FLAGS_YMM | CP_FLAGS_ZMM | CP_FLAGS_PAGE4K ) ) { - // Special computation for some incorrectly created DDS files based on - // legacy DirectDraw assumptions about pitch alignment - rowPitch = ( ( width * bpp + 31 ) / 32 ) * sizeof(uint32_t); - slicePitch = rowPitch * height; - } - else if ( flags & CP_FLAGS_PARAGRAPH ) - { - rowPitch = ( ( width * bpp + 127 ) / 128 ) * 16; - slicePitch = rowPitch * height; + if ( flags & CP_FLAGS_PAGE4K ) + { + rowPitch = ( ( width * bpp + 32767 ) / 32768 ) * 4096; + slicePitch = rowPitch * height; + } + else if ( flags & CP_FLAGS_ZMM ) + { + rowPitch = ( ( width * bpp + 511 ) / 512 ) * 64; + slicePitch = rowPitch * height; + } + else if ( flags & CP_FLAGS_YMM ) + { + rowPitch = ( ( width * bpp + 255 ) / 256) * 32; + slicePitch = rowPitch * height; + } + else if ( flags & CP_FLAGS_PARAGRAPH ) + { + rowPitch = ( ( width * bpp + 127 ) / 128 ) * 16; + slicePitch = rowPitch * height; + } + else // DWORD alignment + { + // Special computation for some incorrectly created DDS files based on + // legacy DirectDraw assumptions about pitch alignment + rowPitch = ( ( width * bpp + 31 ) / 32 ) * sizeof(uint32_t); + slicePitch = rowPitch * height; + } } else { + // Default byte alignment rowPitch = ( width * bpp + 7 ) / 8; slicePitch = rowPitch * height; }