Skip to content

Commit

Permalink
Experimental RDO: Mode 6 with 2-bit index
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Evstyukhin committed Jan 31, 2021
1 parent 6b46835 commit 0f3e115
Show file tree
Hide file tree
Showing 9 changed files with 474 additions and 13 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019-2020 Andrew Evstyukhin
Copyright (c) 2019-2021 Andrew Evstyukhin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ For premultiplied alpha it is necessary to specify "/nomask" command-line option

Many encoders use single metric (RMSE / MSE / PSNR) insensitive to a direction. While SSIM is unhandy for direct compression, it enhances correlation when encoding produces equal deltas and so SSIM overcomes dithering.

## Special features

Additional mode 6 with 2-bit index instead of 4-bit gives a significant reduction in size.

## Usage

The solution was tested on SSSE3, SSE4.1, AVX, AVX2, AVX-512BW - capable CPUs for Win64 API only.
Expand Down Expand Up @@ -63,7 +67,7 @@ Compressing "frymire.png" (gained from https://github.com/castano/nvidia-texture
SubTexture RGB qMSE = 0.5, qPSNR = 50.950326, wSSIM_4x4 = 0.97143024
Saved frymire.ktx

Compressing "8192.png" (gained from https://bitbucket.org/wolfpld/etcpak/downloads/8192.png) in development mode:
Compressing "8192.png" (gained from removed https://bitbucket.org/wolfpld/etcpak/downloads/8192.png) in development mode:

Bc7Compress.exe /draft /nomask /noflip 8192.png 8192.ktx
Loaded 8192.png
Expand All @@ -75,7 +79,7 @@ Compressing "8192.png" (gained from https://bitbucket.org/wolfpld/etcpak/downloa

## Copyright

Copyright (c) 2019-2020 Andrew Evstyukhin
Copyright (c) 2019-2021 Andrew Evstyukhin

Licensed under the MIT License.

Expand Down
1 change: 1 addition & 0 deletions src/Bc7Compress.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
<ClCompile Include="Bc7CoreMode4.cpp" />
<ClCompile Include="Bc7CoreMode5.cpp" />
<ClCompile Include="Bc7CoreMode6.cpp" />
<ClCompile Include="Bc7CoreMode6Index2.cpp" />
<ClCompile Include="Bc7CoreMode7.cpp" />
<ClCompile Include="Bc7PcaEigen.cpp" />
<ClCompile Include="Bc7Tables.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions src/Bc7Compress.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,8 @@
<ClCompile Include="Bc7PcaEigen.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Bc7CoreMode6Index2.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
34 changes: 27 additions & 7 deletions src/Bc7Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#endif

#if defined(OPTION_COUNTERS)
static std::atomic_int gCounterModes[8];
static std::atomic_int gCounterModes[9 + 1];
static std::atomic_int gCompressAlready, gCompress, gCompressBad;
#endif

Expand Down Expand Up @@ -1491,19 +1491,27 @@ static void CompressBlock(uint8_t output[16], Cell& input) noexcept

if (input.Error.Total > denoiseStep)
{
Mode6::CompressBlockFast(input);
if constexpr (kDenoise || kDenoiseStep)
{
Mode6Index2::CompressBlockFast(input);
}

if (input.Error.Total > denoiseStep)
{
Mode4::CompressBlockFast(input);
Mode6::CompressBlockFast(input);

if (input.Error.Total > denoiseStep)
{
Mode5::CompressBlockFast(input);
Mode4::CompressBlockFast(input);

if (input.Error.Total > denoiseStep)
{
Mode7::CompressBlockFast(input);
Mode5::CompressBlockFast(input);

if (input.Error.Total > denoiseStep)
{
Mode7::CompressBlockFast(input);
}
}
}
}
Expand Down Expand Up @@ -1596,6 +1604,13 @@ static void CompressBlock(uint8_t output[16], Cell& input) noexcept
Mode7::CompressBlock(input);
}
break;

case 9:
if (input.Error.Total > 0)
{
Mode6Index2::CompressBlock(input);
}
break;
}

input.PersonalParameter = input.BestParameter;
Expand Down Expand Up @@ -1708,6 +1723,10 @@ static void CompressBlock(uint8_t output[16], Cell& input) noexcept
case 7:
Mode7::FinalPackBlock(output, input);
break;

case 9:
Mode6Index2::FinalPackBlock(output, input);
break;
}

DecompressBlock(output, temp);
Expand Down Expand Up @@ -1751,8 +1770,8 @@ static void CompressBlock(uint8_t output[16], Cell& input) noexcept

void CompressStatistics()
{
PRINTF("[Transparent]\tM4 = %i, M6 = %i, M5 = %i, M7 = %i",
gCounterModes[4].load(), gCounterModes[6].load(), gCounterModes[5].load(), gCounterModes[7].load());
PRINTF("[Transparent]\tM4 = %i, M6I2 = %i, M6 = %i, M5 = %i, M7 = %i",
gCounterModes[4].load(), gCounterModes[9].load(), gCounterModes[6].load(), gCounterModes[5].load(), gCounterModes[7].load());

PRINTF("[Opaque]\tM1 = %i, M3 = %i, M2 = %i, M0 = %i",
gCounterModes[1].load(), gCounterModes[3].load(), gCounterModes[2].load(), gCounterModes[0].load());
Expand All @@ -1766,6 +1785,7 @@ void CompressStatistics()
Mode0::PrintCounters();

Mode4::PrintCounters();
Mode6Index2::PrintCounters();
Mode6::PrintCounters();
Mode5::PrintCounters();
Mode7::PrintCounters();
Expand Down
16 changes: 13 additions & 3 deletions src/Bc7Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,18 @@ namespace Mode5 {

} // namespace Mode5

namespace Mode6Index2 {

void FinalPackBlock(uint8_t output[16], Cell& input) noexcept;

void CompressBlockFast(Cell& input) noexcept;

void CompressBlock(Cell& input) noexcept;

void PrintCounters() noexcept;

} // namespace Mode6Index2

namespace Mode6 {

void DecompressBlock(uint8_t input[16], Cell& output) noexcept;
Expand Down Expand Up @@ -285,9 +297,7 @@ struct WorkerItem
uint8_t* _Cell;
uint8_t* _Mask;

WorkerItem()
{
}
WorkerItem() = default;

WorkerItem(uint8_t* output, uint8_t* cell, uint8_t* mask)
: _Output(output)
Expand Down
Loading

0 comments on commit 0f3e115

Please sign in to comment.