summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2020-04-09 02:37:51 -0300
committerGravatar ReinUsesLisp2020-04-09 02:37:51 -0300
commit0efc230381835ca3e5be560fd65eda023faf2b37 (patch)
tree55cb94baa9718cd293655855c0f783fe52b2eabc /src
parentMerge pull request #3624 from Kewlan/fix-sl-sr-position (diff)
downloadyuzu-0efc230381835ca3e5be560fd65eda023faf2b37.tar.gz
yuzu-0efc230381835ca3e5be560fd65eda023faf2b37.tar.xz
yuzu-0efc230381835ca3e5be560fd65eda023faf2b37.zip
astc: OutputBitStream style changes and make it constexpr
Diffstat (limited to 'src')
-rw-r--r--src/video_core/textures/astc.cpp58
1 files changed, 26 insertions, 32 deletions
diff --git a/src/video_core/textures/astc.cpp b/src/video_core/textures/astc.cpp
index 062b4f252..20706bda0 100644
--- a/src/video_core/textures/astc.cpp
+++ b/src/video_core/textures/astc.cpp
@@ -40,17 +40,17 @@ constexpr u32 Popcnt(u32 n) {
40class InputBitStream { 40class InputBitStream {
41public: 41public:
42 explicit InputBitStream(const u8* ptr, std::size_t start_offset = 0) 42 explicit InputBitStream(const u8* ptr, std::size_t start_offset = 0)
43 : m_CurByte(ptr), m_NextBit(start_offset % 8) {} 43 : cur_byte(ptr), next_bit(start_offset % 8) {}
44 44
45 std::size_t GetBitsRead() const { 45 std::size_t GetBitsRead() const {
46 return m_BitsRead; 46 return m_BitsRead;
47 } 47 }
48 48
49 u32 ReadBit() { 49 u32 ReadBit() {
50 u32 bit = *m_CurByte >> m_NextBit++; 50 u32 bit = *cur_byte >> next_bit++;
51 while (m_NextBit >= 8) { 51 while (next_bit >= 8) {
52 m_NextBit -= 8; 52 next_bit -= 8;
53 m_CurByte++; 53 cur_byte++;
54 } 54 }
55 55
56 m_BitsRead++; 56 m_BitsRead++;
@@ -75,64 +75,58 @@ public:
75 } 75 }
76 76
77private: 77private:
78 const u8* m_CurByte; 78 const u8* cur_byte;
79 std::size_t m_NextBit = 0; 79 std::size_t next_bit = 0;
80 std::size_t m_BitsRead = 0; 80 std::size_t m_BitsRead = 0;
81}; 81};
82 82
83class OutputBitStream { 83class OutputBitStream {
84public: 84public:
85 explicit OutputBitStream(u8* ptr, s32 nBits = 0, s32 start_offset = 0) 85 constexpr explicit OutputBitStream(u8* ptr, std::size_t bits = 0, std::size_t start_offset = 0)
86 : m_NumBits(nBits), m_CurByte(ptr), m_NextBit(start_offset % 8) {} 86 : cur_byte{ptr}, num_bits{bits}, next_bit{start_offset % 8} {}
87 87
88 ~OutputBitStream() = default; 88 constexpr std::size_t GetBitsWritten() const {
89 89 return bits_written;
90 s32 GetBitsWritten() const {
91 return m_BitsWritten;
92 } 90 }
93 91
94 void WriteBitsR(u32 val, u32 nBits) { 92 constexpr void WriteBitsR(u32 val, u32 nBits) {
95 for (u32 i = 0; i < nBits; i++) { 93 for (u32 i = 0; i < nBits; i++) {
96 WriteBit((val >> (nBits - i - 1)) & 1); 94 WriteBit((val >> (nBits - i - 1)) & 1);
97 } 95 }
98 } 96 }
99 97
100 void WriteBits(u32 val, u32 nBits) { 98 constexpr void WriteBits(u32 val, u32 nBits) {
101 for (u32 i = 0; i < nBits; i++) { 99 for (u32 i = 0; i < nBits; i++) {
102 WriteBit((val >> i) & 1); 100 WriteBit((val >> i) & 1);
103 } 101 }
104 } 102 }
105 103
106private: 104private:
107 void WriteBit(s32 b) { 105 constexpr void WriteBit(bool b) {
108 106 if (bits_written >= num_bits) {
109 if (done)
110 return; 107 return;
108 }
111 109
112 const u32 mask = 1 << m_NextBit++; 110 const u32 mask = 1 << next_bit++;
113 111
114 // clear the bit 112 // clear the bit
115 *m_CurByte &= static_cast<u8>(~mask); 113 *cur_byte &= static_cast<u8>(~mask);
116 114
117 // Write the bit, if necessary 115 // Write the bit, if necessary
118 if (b) 116 if (b)
119 *m_CurByte |= static_cast<u8>(mask); 117 *cur_byte |= static_cast<u8>(mask);
120 118
121 // Next byte? 119 // Next byte?
122 if (m_NextBit >= 8) { 120 if (next_bit >= 8) {
123 m_CurByte += 1; 121 cur_byte += 1;
124 m_NextBit = 0; 122 next_bit = 0;
125 } 123 }
126
127 done = done || ++m_BitsWritten >= m_NumBits;
128 } 124 }
129 125
130 s32 m_BitsWritten = 0; 126 u8* cur_byte;
131 const s32 m_NumBits; 127 std::size_t num_bits;
132 u8* m_CurByte; 128 std::size_t bits_written = 0;
133 s32 m_NextBit = 0; 129 std::size_t next_bit = 0;
134
135 bool done = false;
136}; 130};
137 131
138template <typename IntType> 132template <typename IntType>