@@ -813,7 +813,7 @@ uint8 FormatChannels(TexelInputFormatType fmt) {
813813}
814814
815815struct LinearTile : TileBase {
816- void reset (uint32, uint32, uint32) {}
816+ void reset (uint32, uint32, uint32) override {}
817817 uint32 get (uint32 inTexel) const override { return inTexel; }
818818};
819819
@@ -822,7 +822,7 @@ struct MortonTile : TileBase {
822822
823823 MortonTile (uint32 width, uint32 height) : settings(width, height) {}
824824
825- void reset (uint32, uint32, uint32) {}
825+ void reset (uint32, uint32, uint32) override {}
826826
827827 uint32 get (uint32 inTexel) const override {
828828 return MortonAddr (inTexel % settings.width , inTexel / settings.height ,
@@ -850,7 +850,7 @@ struct MortonPow2Tile : TileBase {
850850 : width(width_), height(height_),
851851 widthp2 (RoundToPow2(std::max(width_, size_t (8 )))) {}
852852
853- void reset (uint32, uint32, uint32) {}
853+ void reset (uint32, uint32, uint32) override {}
854854
855855 static size_t MortonAddr (size_t x, size_t y, size_t width) {
856856 const size_t x0 = x & 1 ;
@@ -912,7 +912,7 @@ struct NXTile : TileBase {
912912 yTailOffset = macroTileHeight + 2 ;
913913 }
914914
915- void reset (uint32, uint32, uint32) {}
915+ void reset (uint32, uint32, uint32) override {}
916916
917917 uint32 get (uint32 inTexel) const override {
918918 // 12 11 10 9 8 7 6 5 4 3 2 1 0
@@ -1483,9 +1483,8 @@ void Reencode(NewTexelContextCreate ctx, uint32 numDesiredChannels,
14831483 if ((numDesiredChannels > 2 &&
14841484 ctx.baseFormat .swizzle .b == TexelSwizzleType::DeriveZ) ||
14851485 (numDesiredChannels == 2 &&
1486- (ctx.baseFormat .swizzle .b == TexelSwizzleType::DeriveZOrBlue ||
1487- ctx.baseFormat .swizzle .b ==
1488- TexelSwizzleType::DeriveZOrBlueInverted))) {
1486+ (ctx.baseFormat .swizzle .b == TexelSwizzleType::DeriveZOrBlue ||
1487+ ctx.baseFormat .swizzle .b == TexelSwizzleType::DeriveZOrBlueInverted))) {
14891488 ComputeBC5Blue (outData_.data (), numTexels * numDesiredChannels,
14901489 numDesiredChannels);
14911490 }
@@ -1600,10 +1599,12 @@ struct NewTexelContextDDS : NewTexelContextImpl {
16001599 std::vector<std::vector<bool >> mipmaps;
16011600 std::string yasBuffer;
16021601 bool mustDecode;
1602+ uint8 numChannels;
16031603
16041604 NewTexelContextDDS (NewTexelContextCreate ctx_, bool isBase = false )
16051605 : NewTexelContextImpl(ctx_), dds(MakeDDS(ctx)),
1606- mustDecode (IsFormatSupported(ctx.formatOverride, ctx.baseFormat.type)) {
1606+ mustDecode (IsFormatSupported(ctx.formatOverride, ctx.baseFormat.type)),
1607+ numChannels(DesiredDDSChannels(ctx.baseFormat.type)) {
16071608 mipmaps.resize (std::max (1U , dds.mipMapCount ));
16081609 const int8 numFaces = std::max (ctx.numFaces , int8 (1 ));
16091610 const uint32 arraySize = dds.arraySize * numFaces;
@@ -1621,10 +1622,9 @@ struct NewTexelContextDDS : NewTexelContextImpl {
16211622
16221623 if (!isBase) {
16231624 TexelInputFormat baseFmt = ctx.baseFormat ;
1625+ mustDecode |= MustSwizzle (baseFmt.swizzle , numChannels);
16241626
16251627 if (mustDecode) {
1626- uint8 numChannels = DesiredDDSChannels (ctx.baseFormat .type );
1627-
16281628 switch (numChannels) {
16291629 case 1 :
16301630 baseFmt.type = TexelInputFormatType::R8;
@@ -1709,34 +1709,9 @@ struct NewTexelContextDDS : NewTexelContextImpl {
17091709
17101710 mctx.height *= mctx.depth ;
17111711
1712- auto DecodeStream = [&] {
1713- uint8 numChannels = DesiredDDSChannels (ctx.baseFormat .type );
1714- if (numChannels == 4 ) {
1715- UCVector4 *bgn = reinterpret_cast <UCVector4 *>(yasBuffer.data ());
1716- UCVector4 *edn =
1717- reinterpret_cast <UCVector4 *>(yasBuffer.data () + rDataSize);
1718-
1719- DecodeToRGBA (static_cast <const char *>(data), mctx, {bgn, edn});
1720- } else if (numChannels == 3 ) {
1721- UCVector *bgn = reinterpret_cast <UCVector *>(yasBuffer.data ());
1722- UCVector *edn =
1723- reinterpret_cast <UCVector *>(yasBuffer.data () + rDataSize);
1724-
1725- DecodeToRGB (static_cast <const char *>(data), mctx, {bgn, edn});
1726-
1727- } else if (numChannels == 1 ) {
1728- DecodeToGray (static_cast <const char *>(data), mctx,
1729- {yasBuffer.data (), rDataSize});
1730- } else {
1731- throw std::logic_error (" Implement channel" );
1732- }
1733- };
1734-
1735- const bool mustDecode =
1736- IsFormatSupported (ctx.formatOverride , ctx.baseFormat .type );
1737-
17381712 if (mustDecode) {
1739- DecodeStream ();
1713+ Reencode (mctx, numChannels, static_cast <const char *>(data),
1714+ {rData, rDataSize});
17401715 } else if (ctx.baseFormat .tile == TexelTile::Linear &&
17411716 !ctx.baseFormat .swapPacked ) {
17421717 memcpy (rData, data, rDataSize);
@@ -1767,15 +1742,17 @@ struct NewTexelContextDDS : NewTexelContextImpl {
17671742
17681743struct NewTexelContextDDSLegacy : NewTexelContextDDS {
17691744 std::vector<std::string> arrayMipmapBuffers;
1745+ uint8 numChannels;
17701746
17711747 NewTexelContextDDSLegacy (NewTexelContextCreate ctx_)
1772- : NewTexelContextDDS(ctx_, true ) {
1748+ : NewTexelContextDDS(ctx_, true ),
1749+ numChannels (DesiredDDSLegacyChannels(ctx_.baseFormat.type)) {
17731750 arrayMipmapBuffers.resize (dds.arraySize );
17741751 dds.arraySize = 1 ;
17751752 TexelInputFormat baseFmt = ctx.baseFormat ;
1753+ mustDecode |= MustSwizzle (ctx.baseFormat .swizzle , numChannels);
17761754
17771755 if (mustDecode) {
1778- uint8 numChannels = DesiredDDSLegacyChannels (ctx.baseFormat .type );
17791756 switch (numChannels) {
17801757 case 1 :
17811758 baseFmt.type = TexelInputFormatType::R8;
@@ -1876,30 +1853,9 @@ struct NewTexelContextDDSLegacy : NewTexelContextDDS {
18761853
18771854 mctx.height *= mctx.depth ;
18781855
1879- auto DecodeStream = [&] {
1880- uint8 numChannels = DesiredDDSLegacyChannels (ctx.baseFormat .type );
1881- if (numChannels == 4 ) {
1882- UCVector4 *bgn = reinterpret_cast <UCVector4 *>(buffar.data ());
1883- UCVector4 *edn =
1884- reinterpret_cast <UCVector4 *>(buffar.data () + rDataSize);
1885-
1886- DecodeToRGBA (static_cast <const char *>(data), mctx, {bgn, edn});
1887- } else if (numChannels == 3 ) {
1888- UCVector *bgn = reinterpret_cast <UCVector *>(buffar.data ());
1889- UCVector *edn = reinterpret_cast <UCVector *>(buffar.data () + rDataSize);
1890-
1891- DecodeToRGB (static_cast <const char *>(data), mctx, {bgn, edn});
1892-
1893- } else if (numChannels == 1 ) {
1894- DecodeToGray (static_cast <const char *>(data), mctx,
1895- {buffar.data (), rDataSize});
1896- } else {
1897- throw std::logic_error (" Implement channel" );
1898- }
1899- };
1900-
19011856 if (mustDecode) {
1902- DecodeStream ();
1857+ Reencode (mctx, numChannels, static_cast <const char *>(data),
1858+ {rData, rDataSize});
19031859 } else if (ctx.baseFormat .tile == TexelTile::Linear &&
19041860 !ctx.baseFormat .swapPacked ) {
19051861 memcpy (rData, data, rDataSize);
0 commit comments