@@ -41,15 +41,17 @@ struct unorm_constant<float,21> { NBL_CONSTEXPR_STATIC_INLINE uint32_t value = 0
4141template<>
4242struct unorm_constant<float ,32 > { NBL_CONSTEXPR_STATIC_INLINE uint32_t value = 0x2f800004u; };
4343
44- template<typename Q, typename F>
44+ // FullWidth if intend to decode before scramble, not if decode after scramble
45+ template<typename Q, typename F, bool FullWidth=true >
4546struct encode_helper
4647{
4748 NBL_CONSTEXPR_STATIC_INLINE uint16_t Dim = Q::Dimension;
4849 using sequence_type = Q;
4950 using input_type = vector <F, Dim>;
5051 using uniform_storage_scalar_type = unsigned_integer_of_size_t<sizeof (F)>;
5152 using uniform_storage_type = vector <uniform_storage_scalar_type, Dim>; // type that holds uint bit representation of a unorm that can have 1s in MSB (normalized w.r.t whole scalar)
52- NBL_CONSTEXPR_STATIC_INLINE uint32_t UNormMultiplier = (1u << (8u * size_of_v<uniform_storage_scalar_type> - 1u)) - 1u;
53+ NBL_CONSTEXPR_STATIC_INLINE uint16_t Bits = FullWidth ? (8u * size_of_v<uniform_storage_scalar_type> - 1u) : sequence_type::BitsPerComponent;
54+ NBL_CONSTEXPR_STATIC_INLINE uint32_t UNormMultiplier = (1u << Bits) - 1u;
5355
5456 static sequence_type __call (const input_type unormvec)
5557 {
@@ -129,10 +131,10 @@ struct QuantizedSequence<T, 1 NBL_PARTIAL_REQ_BOT(impl::SequenceSpecialization<T
129131 store_type get (const uint16_t idx) { assert (idx >= 0 && idx < 1 ); return data; }
130132 void set (const uint16_t idx, const store_type value) { assert (idx >= 0 && idx < 1 ); data = value; }
131133
132- template<typename F>
134+ template<typename F, bool FullWidth >
133135 static this_t encode (const vector <F, Dimension> value)
134136 {
135- return impl::encode_helper<this_t,F>::__call (value);
137+ return impl::encode_helper<this_t,F,FullWidth >::__call (value);
136138 }
137139
138140 template<typename F>
@@ -186,10 +188,10 @@ struct QuantizedSequence<T, Dim NBL_PARTIAL_REQ_BOT(impl::SequenceSpecialization
186188 data = glsl::bitfieldInsert (data, value >> DiscardBits, BitsPerComponent * idx, BitsPerComponent);
187189 }
188190
189- template<typename F>
191+ template<typename F, bool FullWidth >
190192 static this_t encode (const vector <F, Dimension> value)
191193 {
192- return impl::encode_helper<this_t,F>::__call (value);
194+ return impl::encode_helper<this_t,F,FullWidth >::__call (value);
193195 }
194196
195197 template<typename F>
@@ -230,10 +232,10 @@ struct QuantizedSequence<T, Dim NBL_PARTIAL_REQ_BOT(impl::SequenceSpecialization
230232 scalar_type get (const uint16_t idx) { assert (idx >= 0 && idx < Dim); return data[idx]; }
231233 void set (const uint16_t idx, const scalar_type value) { assert (idx >= 0 && idx < Dim); data[idx] = value; }
232234
233- template<typename F>
235+ template<typename F, bool FullWidth >
234236 static this_t encode (const vector <F, Dimension> value)
235237 {
236- return impl::encode_helper<this_t,F>::__call (value);
238+ return impl::encode_helper<this_t,F,FullWidth >::__call (value);
237239 }
238240
239241 template<typename F>
@@ -305,10 +307,10 @@ struct QuantizedSequence<T, Dim NBL_PARTIAL_REQ_BOT(is_same_v<T,uint32_t2> && Di
305307 data[1 ] = glsl::bitfieldInsert (data[1 ], trunc_val, DiscardBits - 1u, BitsPerComponent);
306308 }
307309
308- template<typename F>
310+ template<typename F, bool FullWidth >
309311 static this_t encode (const vector <F, Dimension> value)
310312 {
311- return impl::encode_helper<this_t,F>::__call (value);
313+ return impl::encode_helper<this_t,F,FullWidth >::__call (value);
312314 }
313315
314316 template<typename F>
@@ -377,10 +379,10 @@ struct QuantizedSequence<T, Dim NBL_PARTIAL_REQ_BOT(is_same_v<T,uint16_t2> && Di
377379 }
378380 }
379381
380- template<typename F>
382+ template<typename F, bool FullWidth >
381383 static this_t encode (const vector <F, Dimension> value)
382384 {
383- return impl::encode_helper<this_t,F>::__call (value);
385+ return impl::encode_helper<this_t,F,FullWidth >::__call (value);
384386 }
385387
386388 template<typename F>
0 commit comments