From 4cd52a34b9d39ce2f521081665748af232694145 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 17 Jul 2018 23:02:54 -0400 Subject: astc: In-class initialize member variables where appropriate --- src/video_core/textures/astc.cpp | 61 +++++++++++++++------------------------- 1 file changed, 22 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/video_core/textures/astc.cpp b/src/video_core/textures/astc.cpp index 3c4ad1c9d..b2adbe888 100644 --- a/src/video_core/textures/astc.cpp +++ b/src/video_core/textures/astc.cpp @@ -25,16 +25,15 @@ class BitStream { public: - BitStream(unsigned char* ptr, int nBits = 0, int start_offset = 0) - : m_BitsWritten(0), m_BitsRead(0), m_NumBits(nBits), m_CurByte(ptr), - m_NextBit(start_offset % 8), done(false) {} + explicit BitStream(unsigned char* ptr, int nBits = 0, int start_offset = 0) + : m_NumBits(nBits), m_CurByte(ptr), m_NextBit(start_offset % 8) {} + + ~BitStream() = default; int GetBitsWritten() const { return m_BitsWritten; } - ~BitStream() {} - void WriteBitsR(unsigned int val, unsigned int nBits) { for (unsigned int i = 0; i < nBits; i++) { WriteBit((val >> (nBits - i - 1)) & 1); @@ -95,13 +94,13 @@ private: done = done || ++m_BitsWritten >= m_NumBits; } - int m_BitsWritten; + int m_BitsWritten = 0; const int m_NumBits; unsigned char* m_CurByte; - int m_NextBit; - int m_BitsRead; + int m_NextBit = 0; + int m_BitsRead = 0; - bool done; + bool done = false; }; template @@ -382,17 +381,13 @@ private: namespace ASTCC { struct TexelWeightParams { - uint32_t m_Width; - uint32_t m_Height; - bool m_bDualPlane; - uint32_t m_MaxWeight; - bool m_bError; - bool m_bVoidExtentLDR; - bool m_bVoidExtentHDR; - - TexelWeightParams() { - memset(this, 0, sizeof(*this)); - } + uint32_t m_Width = 0; + uint32_t m_Height = 0; + bool m_bDualPlane = false; + uint32_t m_MaxWeight = 0; + bool m_bError = false; + bool m_bVoidExtentLDR = false; + bool m_bVoidExtentHDR = false; uint32_t GetPackedBitSize() { // How many indices do we have? @@ -668,27 +663,15 @@ IntType Replicate(const IntType& val, uint32_t numBits, uint32_t toBit) { class Pixel { protected: - typedef int16_t ChannelType; - uint8_t m_BitDepth[4]; - int16_t color[4]; + using ChannelType = int16_t; + uint8_t m_BitDepth[4] = {8, 8, 8, 8}; + int16_t color[4] = {}; public: - Pixel() { - for (int i = 0; i < 4; i++) { - m_BitDepth[i] = 8; - color[i] = 0; - } - } - - Pixel(ChannelType a, ChannelType r, ChannelType g, ChannelType b, unsigned bitDepth = 8) { - for (int i = 0; i < 4; i++) - m_BitDepth[i] = bitDepth; - - color[0] = a; - color[1] = r; - color[2] = g; - color[3] = b; - } + Pixel() = default; + Pixel(ChannelType a, ChannelType r, ChannelType g, ChannelType b, unsigned bitDepth = 8) + : m_BitDepth{uint8_t(bitDepth), uint8_t(bitDepth), uint8_t(bitDepth), uint8_t(bitDepth)}, + color{a, r, g, b} {} // Changes the depth of each pixel. This scales the values to // the appropriate bit depth by either truncating the least -- cgit v1.2.3 From e3fadb9616f20c3fe4c11ccd88394aa922115f56 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 17 Jul 2018 23:08:00 -0400 Subject: astc: Delete Bits' copy contstructor and assignment operator This also potentially avoids warnings, considering the copy assignment operator is supposed to have a return value. --- src/video_core/textures/astc.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/video_core/textures/astc.cpp b/src/video_core/textures/astc.cpp index b2adbe888..bafd137d5 100644 --- a/src/video_core/textures/astc.cpp +++ b/src/video_core/textures/astc.cpp @@ -105,17 +105,12 @@ private: template class Bits { -private: - const IntType& m_Bits; - - // Don't copy - Bits() {} - Bits(const Bits&) {} - Bits& operator=(const Bits&) {} - public: explicit Bits(IntType& v) : m_Bits(v) {} + Bits(const Bits&) = delete; + Bits& operator=(const Bits&) = delete; + uint8_t operator[](uint32_t bitPos) { return static_cast((m_Bits >> bitPos) & 1); } @@ -132,6 +127,9 @@ public: uint64_t mask = (1 << (end - start + 1)) - 1; return (m_Bits >> start) & mask; } + +private: + const IntType& m_Bits; }; enum EIntegerEncoding { eIntegerEncoding_JustBits, eIntegerEncoding_Quint, eIntegerEncoding_Trit }; -- cgit v1.2.3 From c5803e30d35f9ca5a4c08dc51ee15885a7814b74 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 17 Jul 2018 23:12:16 -0400 Subject: astc: const-correctness changes where applicable A few member functions didn't actually modify class state, so these can be amended as necessary. --- src/video_core/textures/astc.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/video_core/textures/astc.cpp b/src/video_core/textures/astc.cpp index bafd137d5..1f2eca787 100644 --- a/src/video_core/textures/astc.cpp +++ b/src/video_core/textures/astc.cpp @@ -106,16 +106,16 @@ private: template class Bits { public: - explicit Bits(IntType& v) : m_Bits(v) {} + explicit Bits(const IntType& v) : m_Bits(v) {} Bits(const Bits&) = delete; Bits& operator=(const Bits&) = delete; - uint8_t operator[](uint32_t bitPos) { + uint8_t operator[](uint32_t bitPos) const { return static_cast((m_Bits >> bitPos) & 1); } - IntType operator()(uint32_t start, uint32_t end) { + IntType operator()(uint32_t start, uint32_t end) const { if (start == end) { return (*this)[start]; } else if (start > end) { @@ -183,12 +183,12 @@ public: m_QuintValue = val; } - bool MatchesEncoding(const IntegerEncodedValue& other) { + bool MatchesEncoding(const IntegerEncodedValue& other) const { return m_Encoding == other.m_Encoding && m_NumBits == other.m_NumBits; } // Returns the number of bits required to encode nVals values. - uint32_t GetBitLength(uint32_t nVals) { + uint32_t GetBitLength(uint32_t nVals) const { uint32_t totalBits = m_NumBits * nVals; if (m_Encoding == eIntegerEncoding_Trit) { totalBits += (nVals * 8 + 4) / 5; @@ -387,7 +387,7 @@ struct TexelWeightParams { bool m_bVoidExtentLDR = false; bool m_bVoidExtentHDR = false; - uint32_t GetPackedBitSize() { + uint32_t GetPackedBitSize() const { // How many indices do we have? uint32_t nIdxs = m_Height * m_Width; if (m_bDualPlane) { @@ -788,8 +788,8 @@ public: } }; -void DecodeColorValues(uint32_t* out, uint8_t* data, uint32_t* modes, const uint32_t nPartitions, - const uint32_t nBitsForColorData) { +void DecodeColorValues(uint32_t* out, uint8_t* data, const uint32_t* modes, + const uint32_t nPartitions, const uint32_t nBitsForColorData) { // First figure out how many color values we have uint32_t nValues = 0; for (uint32_t i = 0; i < nPartitions; i++) { @@ -825,8 +825,7 @@ void DecodeColorValues(uint32_t* out, uint8_t* data, uint32_t* modes, const uint // Once we have the decoded values, we need to dequantize them to the 0-255 range // This procedure is outlined in ASTC spec C.2.13 uint32_t outIdx = 0; - std::vector::const_iterator itr; - for (itr = decodedColorValues.begin(); itr != decodedColorValues.end(); itr++) { + for (auto itr = decodedColorValues.begin(); itr != decodedColorValues.end(); ++itr) { // Have we already decoded all that we need? if (outIdx >= nValues) { break; @@ -1048,17 +1047,17 @@ uint32_t UnquantizeTexelWeight(const IntegerEncodedValue& val) { return result; } -void UnquantizeTexelWeights(uint32_t out[2][144], std::vector& weights, +void UnquantizeTexelWeights(uint32_t out[2][144], const std::vector& weights, const TexelWeightParams& params, const uint32_t blockWidth, const uint32_t blockHeight) { uint32_t weightIdx = 0; uint32_t unquantized[2][144]; - std::vector::const_iterator itr; - for (itr = weights.begin(); itr != weights.end(); itr++) { + + for (auto itr = weights.begin(); itr != weights.end(); ++itr) { unquantized[0][weightIdx] = UnquantizeTexelWeight(*itr); if (params.m_bDualPlane) { - itr++; + ++itr; unquantized[1][weightIdx] = UnquantizeTexelWeight(*itr); if (itr == weights.end()) { break; -- cgit v1.2.3 From 0f148548f3edfc62bcdd62ed42d6797380f6ab57 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 17 Jul 2018 23:46:30 -0400 Subject: astc: Mark functions as internally linked where applicable --- src/video_core/textures/astc.cpp | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/video_core/textures/astc.cpp b/src/video_core/textures/astc.cpp index 1f2eca787..6dfcadc6a 100644 --- a/src/video_core/textures/astc.cpp +++ b/src/video_core/textures/astc.cpp @@ -406,7 +406,7 @@ struct TexelWeightParams { } }; -TexelWeightParams DecodeBlockInfo(BitStream& strm) { +static TexelWeightParams DecodeBlockInfo(BitStream& strm) { TexelWeightParams params; // Read the entire block mode all at once @@ -605,8 +605,8 @@ TexelWeightParams DecodeBlockInfo(BitStream& strm) { return params; } -void FillVoidExtentLDR(BitStream& strm, uint32_t* const outBuf, uint32_t blockWidth, - uint32_t blockHeight) { +static void FillVoidExtentLDR(BitStream& strm, uint32_t* const outBuf, uint32_t blockWidth, + uint32_t blockHeight) { // Don't actually care about the void extent, just read the bits... for (int i = 0; i < 4; ++i) { strm.ReadBits(13); @@ -621,23 +621,25 @@ void FillVoidExtentLDR(BitStream& strm, uint32_t* const outBuf, uint32_t blockWi uint32_t rgba = (r >> 8) | (g & 0xFF00) | (static_cast(b) & 0xFF00) << 8 | (static_cast(a) & 0xFF00) << 16; - for (uint32_t j = 0; j < blockHeight; j++) + for (uint32_t j = 0; j < blockHeight; j++) { for (uint32_t i = 0; i < blockWidth; i++) { outBuf[j * blockWidth + i] = rgba; } + } } -void FillError(uint32_t* outBuf, uint32_t blockWidth, uint32_t blockHeight) { - for (uint32_t j = 0; j < blockHeight; j++) +static void FillError(uint32_t* outBuf, uint32_t blockWidth, uint32_t blockHeight) { + for (uint32_t j = 0; j < blockHeight; j++) { for (uint32_t i = 0; i < blockWidth; i++) { outBuf[j * blockWidth + i] = 0xFFFF00FF; } + } } // Replicates low numBits such that [(toBit - 1):(toBit - 1 - fromBit)] // is the same as [(numBits - 1):0] and repeats all the way down. template -IntType Replicate(const IntType& val, uint32_t numBits, uint32_t toBit) { +static IntType Replicate(const IntType& val, uint32_t numBits, uint32_t toBit) { if (numBits == 0) return 0; if (toBit == 0) @@ -788,8 +790,8 @@ public: } }; -void DecodeColorValues(uint32_t* out, uint8_t* data, const uint32_t* modes, - const uint32_t nPartitions, const uint32_t nBitsForColorData) { +static void DecodeColorValues(uint32_t* out, uint8_t* data, const uint32_t* modes, + const uint32_t nPartitions, const uint32_t nBitsForColorData) { // First figure out how many color values we have uint32_t nValues = 0; for (uint32_t i = 0; i < nPartitions; i++) { @@ -958,7 +960,7 @@ void DecodeColorValues(uint32_t* out, uint8_t* data, const uint32_t* modes, } } -uint32_t UnquantizeTexelWeight(const IntegerEncodedValue& val) { +static uint32_t UnquantizeTexelWeight(const IntegerEncodedValue& val) { uint32_t bitval = val.GetBitValue(); uint32_t bitlen = val.BaseBitLength(); @@ -1047,9 +1049,10 @@ uint32_t UnquantizeTexelWeight(const IntegerEncodedValue& val) { return result; } -void UnquantizeTexelWeights(uint32_t out[2][144], const std::vector& weights, - const TexelWeightParams& params, const uint32_t blockWidth, - const uint32_t blockHeight) { +static void UnquantizeTexelWeights(uint32_t out[2][144], + const std::vector& weights, + const TexelWeightParams& params, const uint32_t blockWidth, + const uint32_t blockHeight) { uint32_t weightIdx = 0; uint32_t unquantized[2][144]; @@ -1241,8 +1244,8 @@ static inline uint32_t Select2DPartition(int32_t seed, int32_t x, int32_t y, int } // Section C.2.14 -void ComputeEndpoints(Pixel& ep1, Pixel& ep2, const uint32_t*& colorValues, - uint32_t colorEndpointMode) { +static void ComputeEndpoints(Pixel& ep1, Pixel& ep2, const uint32_t*& colorValues, + uint32_t colorEndpointMode) { #define READ_UINT_VALUES(N) \ uint32_t v[N]; \ for (uint32_t i = 0; i < N; i++) { \ @@ -1362,8 +1365,8 @@ void ComputeEndpoints(Pixel& ep1, Pixel& ep2, const uint32_t*& colorValues, #undef READ_INT_VALUES } -void DecompressBlock(uint8_t inBuf[16], const uint32_t blockWidth, const uint32_t blockHeight, - uint32_t* outBuf) { +static void DecompressBlock(uint8_t inBuf[16], const uint32_t blockWidth, + const uint32_t blockHeight, uint32_t* outBuf) { BitStream strm(inBuf); TexelWeightParams weightParams = DecodeBlockInfo(strm); -- cgit v1.2.3 From 6a03badcbc92ab650900abaa64dd7d47e330b101 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 17 Jul 2018 23:53:21 -0400 Subject: astc: Initialize vector size directly in Decompress There's no need to perform a separate resize. --- src/video_core/textures/astc.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/video_core/textures/astc.cpp b/src/video_core/textures/astc.cpp index 6dfcadc6a..b1feacae9 100644 --- a/src/video_core/textures/astc.cpp +++ b/src/video_core/textures/astc.cpp @@ -1600,8 +1600,7 @@ namespace Tegra::Texture::ASTC { std::vector Decompress(std::vector& data, uint32_t width, uint32_t height, uint32_t block_width, uint32_t block_height) { uint32_t blockIdx = 0; - std::vector outData; - outData.resize(height * width * 4); + std::vector outData(height * width * 4); for (uint32_t j = 0; j < height; j += block_height) { for (uint32_t i = 0; i < width; i += block_width) { -- cgit v1.2.3