Commit 0de50d45 by Alexis Hetu Committed by Alexis Hétu

ETC2 decoder

A new ETC2 decoder was added to SwiftShader, based on the OpenGL ETC2 specification. The decoder is fully standalone and does not rely on any outside code (there are no files included in the header and the source file only include the header file, so it can easily be ported to any other project). Things to note: - In Surface.cpp, signed ETC2 images are decoded to full 32FP images, because of the lack of support for signed 8 bit R and RG internal formats. This should be fixed as soon as these formats are made available. - sRGB conversion is not performed within the decoder, so it has been added as a loop inside Surface::decodeETC2 after the ETC2 decoding is performed. This is to make sure that there is no loss of precision, should we choose to do the conversion to a higher bit precision format. The loop is fairly straightforward and does the conversion in place, so the impact on performance compared to doing the sRGB conversion in the decoder should be minimal. Change-Id: I3a1af623353344bf35818ba9c9f4cf349b587e2f Reviewed-on: https://swiftshader-review.googlesource.com/3960Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent c3d95f36
...@@ -45,6 +45,7 @@ COMMON_SRC_FILES += \ ...@@ -45,6 +45,7 @@ COMMON_SRC_FILES += \
Renderer/Clipper.cpp \ Renderer/Clipper.cpp \
Renderer/Color.cpp \ Renderer/Color.cpp \
Renderer/Context.cpp \ Renderer/Context.cpp \
Renderer/ETC_Decoder.cpp \
Renderer/Matrix.cpp \ Renderer/Matrix.cpp \
Renderer/PixelProcessor.cpp \ Renderer/PixelProcessor.cpp \
Renderer/Plane.cpp \ Renderer/Plane.cpp \
......
...@@ -199,6 +199,8 @@ ...@@ -199,6 +199,8 @@
<Unit filename="../../Renderer/Color.hpp" /> <Unit filename="../../Renderer/Color.hpp" />
<Unit filename="../../Renderer/Context.cpp" /> <Unit filename="../../Renderer/Context.cpp" />
<Unit filename="../../Renderer/Context.hpp" /> <Unit filename="../../Renderer/Context.hpp" />
<Unit filename="../../Renderer/ETC_Decoder.cpp" />
<Unit filename="../../Renderer/ETC_Decoder.hpp" />
<Unit filename="../../Renderer/LRUCache.hpp" /> <Unit filename="../../Renderer/LRUCache.hpp" />
<Unit filename="../../Renderer/Matrix.cpp" /> <Unit filename="../../Renderer/Matrix.cpp" />
<Unit filename="../../Renderer/Matrix.hpp" /> <Unit filename="../../Renderer/Matrix.hpp" />
......
...@@ -198,6 +198,8 @@ ...@@ -198,6 +198,8 @@
<Unit filename="../../Renderer/Color.hpp" /> <Unit filename="../../Renderer/Color.hpp" />
<Unit filename="../../Renderer/Context.cpp" /> <Unit filename="../../Renderer/Context.cpp" />
<Unit filename="../../Renderer/Context.hpp" /> <Unit filename="../../Renderer/Context.hpp" />
<Unit filename="../../Renderer/ETC_Decoder.cpp" />
<Unit filename="../../Renderer/ETC_Decoder.hpp" />
<Unit filename="../../Renderer/LRUCache.hpp" /> <Unit filename="../../Renderer/LRUCache.hpp" />
<Unit filename="../../Renderer/Matrix.cpp" /> <Unit filename="../../Renderer/Matrix.cpp" />
<Unit filename="../../Renderer/Matrix.hpp" /> <Unit filename="../../Renderer/Matrix.hpp" />
......
// SwiftShader Software Renderer
//
// Copyright(c) 2015 Google Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of Google Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
class ETC_Decoder
{
public:
enum InputType
{
ETC_R_SIGNED,
ETC_R_UNSIGNED,
ETC_RG_SIGNED,
ETC_RG_UNSIGNED,
ETC_RGB,
ETC_RGB_PUNCHTHROUGH_ALPHA,
ETC_RGBA
};
/// ETC_Decoder::Decode - Decodes 1 to 4 channel images to 8 bit output
/// @param src Pointer to ETC2 encoded image
/// @param dst Pointer to BGRA, 8 bit output
/// @param w src image width
/// @param h src image height
/// @param dstW dst image width
/// @param dstH dst image height
/// @param dstPitch dst image pitch (bytes per row)
/// @param dstBpp dst image bytes per pixel
/// @param inputType src's format
/// @return true if the decoding was performed
static bool Decode(const unsigned char* src, unsigned char *dst, int w, int h, int dstW, int dstH, int dstPitch, int dstBpp, InputType inputType);
};
...@@ -401,7 +401,6 @@ namespace sw ...@@ -401,7 +401,6 @@ namespace sw
#endif #endif
static void decodeATI1(Buffer &internal, const Buffer &external); static void decodeATI1(Buffer &internal, const Buffer &external);
static void decodeATI2(Buffer &internal, const Buffer &external); static void decodeATI2(Buffer &internal, const Buffer &external);
static void decodeETC1(Buffer &internal, const Buffer &external);
static void decodeEAC(Buffer &internal, const Buffer &external, int nbChannels, bool isSigned); static void decodeEAC(Buffer &internal, const Buffer &external, int nbChannels, bool isSigned);
static void decodeETC2(Buffer &internal, const Buffer &external, int nbAlphaBits, bool isSRGB); static void decodeETC2(Buffer &internal, const Buffer &external, int nbAlphaBits, bool isSRGB);
static void decodeASTC(Buffer &internal, const Buffer &external, int xSize, int ySize, int zSize, bool isSRGB); static void decodeASTC(Buffer &internal, const Buffer &external, int xSize, int ySize, int zSize, bool isSRGB);
......
...@@ -320,6 +320,7 @@ ...@@ -320,6 +320,7 @@
<ClCompile Include="..\Main\crc.cpp" /> <ClCompile Include="..\Main\crc.cpp" />
<ClCompile Include="..\Main\FrameBufferWin.cpp" /> <ClCompile Include="..\Main\FrameBufferWin.cpp" />
<ClCompile Include="..\Main\Register.cpp" /> <ClCompile Include="..\Main\Register.cpp" />
<ClCompile Include="..\Renderer\ETC_Decoder.cpp" />
<ClCompile Include="..\Shader\Constants.cpp" /> <ClCompile Include="..\Shader\Constants.cpp" />
<ClCompile Include="..\Shader\PixelPipeline.cpp" /> <ClCompile Include="..\Shader\PixelPipeline.cpp" />
<ClCompile Include="..\Shader\PixelProgram.cpp" /> <ClCompile Include="..\Shader\PixelProgram.cpp" />
...@@ -391,6 +392,7 @@ ...@@ -391,6 +392,7 @@
<ClInclude Include="..\Common\Version.h" /> <ClInclude Include="..\Common\Version.h" />
<ClInclude Include="..\Main\FrameBufferWin.hpp" /> <ClInclude Include="..\Main\FrameBufferWin.hpp" />
<ClInclude Include="..\Main\Register.hpp" /> <ClInclude Include="..\Main\Register.hpp" />
<ClInclude Include="..\Renderer\ETC_Decoder.hpp" />
<ClInclude Include="..\Renderer\RoutineCache.hpp" /> <ClInclude Include="..\Renderer\RoutineCache.hpp" />
<ClInclude Include="..\Shader\PixelPipeline.hpp" /> <ClInclude Include="..\Shader\PixelPipeline.hpp" />
<ClInclude Include="..\Shader\PixelProgram.hpp" /> <ClInclude Include="..\Shader\PixelProgram.hpp" />
......
...@@ -185,6 +185,9 @@ ...@@ -185,6 +185,9 @@
<ClCompile Include="..\Shader\PixelProgram.cpp"> <ClCompile Include="..\Shader\PixelProgram.cpp">
<Filter>Source Files\Shader</Filter> <Filter>Source Files\Shader</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\Renderer\ETC_Decoder.cpp">
<Filter>Source Files\Renderer</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="MemoryManager.hpp"> <ClInclude Include="MemoryManager.hpp">
...@@ -368,6 +371,9 @@ ...@@ -368,6 +371,9 @@
<ClInclude Include="..\Shader\PixelPipeline.hpp"> <ClInclude Include="..\Shader\PixelPipeline.hpp">
<Filter>Header Files\Shader</Filter> <Filter>Header Files\Shader</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\Renderer\ETC_Decoder.hpp">
<Filter>Header Files\Renderer</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="SwiftShader.ini" /> <None Include="SwiftShader.ini" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment