Skip to content

Commit cd67d94

Browse files
committed
removed sequence partial spec data too big, minor fixes
1 parent 1223e88 commit cd67d94

File tree

1 file changed

+6
-91
lines changed

1 file changed

+6
-91
lines changed

include/nbl/builtin/hlsl/sampling/quantized_sequence.hlsl

Lines changed: 6 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ struct QuantizedSequence<T, Dim NBL_PARTIAL_REQ_BOT(impl::SequenceSpecialization
252252
};
253253

254254
// uint32_t2; Dim=3 -- should never use uint16_t2 instead of uint32_t
255-
template<typename T, uint16_t Dim> NBL_PARTIAL_REQ_TOP(impl::SequenceSpecialization<T> && size_of_v<typename vector_traits<T>::scalar_type> == 4 && vector_traits<T>::Dimension == 2 && Dim == 3)
256-
struct QuantizedSequence<T, Dim NBL_PARTIAL_REQ_BOT(impl::SequenceSpecialization<T> && size_of_v<typename vector_traits<T>::scalar_type> == 4 && vector_traits<T>::Dimension == 2 && Dim == 3) >
255+
template<typename T, uint16_t Dim> NBL_PARTIAL_REQ_TOP(is_same_v<T,uint32_t2> && Dim == 3)
256+
struct QuantizedSequence<T, Dim NBL_PARTIAL_REQ_BOT(is_same_v<T,uint32_t2> && Dim == 3) >
257257
{
258258
using this_t = QuantizedSequence<T, Dim>;
259259
using store_type = T;
@@ -326,8 +326,8 @@ struct QuantizedSequence<T, Dim NBL_PARTIAL_REQ_BOT(impl::SequenceSpecialization
326326
};
327327

328328
// uint16_t2; Dim=4 -- should use uint16_t4 instead of uint32_t2
329-
template<typename T, uint16_t Dim> NBL_PARTIAL_REQ_TOP(impl::SequenceSpecialization<T> && size_of_v<typename vector_traits<T>::scalar_type> == 2 && vector_traits<T>::Dimension == 2 && Dim == 4)
330-
struct QuantizedSequence<T, Dim NBL_PARTIAL_REQ_BOT(impl::SequenceSpecialization<T> && size_of_v<typename vector_traits<T>::scalar_type> == 2 && vector_traits<T>::Dimension == 2 && Dim == 4) >
329+
template<typename T, uint16_t Dim> NBL_PARTIAL_REQ_TOP(is_same_v<T,uint16_t2> && Dim == 4)
330+
struct QuantizedSequence<T, Dim NBL_PARTIAL_REQ_BOT(is_same_v<T,uint16_t2> && Dim == 4) >
331331
{
332332
using this_t = QuantizedSequence<T, Dim>;
333333
using store_type = T;
@@ -348,7 +348,7 @@ struct QuantizedSequence<T, Dim NBL_PARTIAL_REQ_BOT(impl::SequenceSpecialization
348348
scalar_type get(const uint16_t idx)
349349
{
350350
assert(idx >= 0 && idx < 4);
351-
if (idx >= 0 && idx < 2) // x y
351+
if (idx < 2) // x y
352352
{
353353
return glsl::bitfieldExtract(data[0], BitsPerComponent * idx, BitsPerComponent);
354354
}
@@ -361,7 +361,7 @@ struct QuantizedSequence<T, Dim NBL_PARTIAL_REQ_BOT(impl::SequenceSpecialization
361361
void set(const uint16_t idx, const scalar_type value)
362362
{
363363
assert(idx >= 0 && idx < 4);
364-
if (idx >= 0 && idx < 2) // x y
364+
if (idx < 2) // x y
365365
{
366366
glsl::bitfieldInsert(data[0], value, BitsPerComponent * idx, BitsPerComponent);
367367
}
@@ -397,91 +397,6 @@ struct QuantizedSequence<T, Dim NBL_PARTIAL_REQ_BOT(impl::SequenceSpecialization
397397

398398
// no uint16_t4, uint32_t4; Dim=2
399399

400-
// uint32_t4; Dim=3 --> returns uint32_t2 - 42 bits per component: 32 in x, 10 in y
401-
// use uint32_t2 instead of uint16_t4
402-
template<typename T, uint16_t Dim> NBL_PARTIAL_REQ_TOP(impl::SequenceSpecialization<T> && size_of_v<typename vector_traits<T>::scalar_type> == 4 && vector_traits<T>::Dimension == 4 && Dim == 3)
403-
struct QuantizedSequence<T, Dim NBL_PARTIAL_REQ_BOT(impl::SequenceSpecialization<T> && size_of_v<typename vector_traits<T>::scalar_type> == 4 && vector_traits<T>::Dimension == 4 && Dim == 3) >
404-
{
405-
using this_t = QuantizedSequence<T, Dim>;
406-
using store_type = T;
407-
using scalar_type = typename vector_traits<T>::scalar_type;
408-
using base_type = vector<scalar_type, 2>;
409-
NBL_CONSTEXPR_STATIC_INLINE uint16_t StoreBits = uint16_t(8u) * size_of_v<store_type>;
410-
NBL_CONSTEXPR_STATIC_INLINE uint16_t BitsPerComponent = StoreBits / Dim;
411-
NBL_CONSTEXPR_STATIC_INLINE uint16_t Dimension = Dim;
412-
413-
base_type get(const uint16_t idx)
414-
{
415-
assert(idx >= 0 && idx < 3);
416-
if (idx == 0) // x
417-
{
418-
base_type x;
419-
x[0] = data[0];
420-
x[1] = glsl::bitfieldExtract(data[1], 0u, 10u);
421-
return x;
422-
}
423-
else if (idx == 1) // y
424-
{
425-
base_type y;
426-
y[0] = glsl::bitfieldExtract(data[1], 10u, 22u);
427-
y[0] |= glsl::bitfieldExtract(data[2], 0u, 10u) << 22u;
428-
y[1] = glsl::bitfieldExtract(data[2], 10u, 10u);
429-
return y;
430-
}
431-
else // z
432-
{
433-
base_type z;
434-
z[0] = glsl::bitfieldInsert(data[2], 20u, 12u);
435-
z[0] |= glsl::bitfieldInsert(data[3], 0u, 20u) << 12u;
436-
z[1] = glsl::bitfieldInsert(data[3], 20u, 10u);
437-
return z;
438-
}
439-
}
440-
441-
void set(const uint16_t idx, const base_type value)
442-
{
443-
assert(idx >= 0 && idx < 3);
444-
if (idx == 0) // x
445-
{
446-
data[0] = value[0];
447-
glsl::bitfieldInsert(data[1], value[1], 0u, 10u);
448-
}
449-
else if (idx == 1) // y
450-
{
451-
glsl::bitfieldInsert(data[1], value[0], 10u, 22u);
452-
glsl::bitfieldInsert(data[2], value[0] >> 22u, 0u, 10u);
453-
glsl::bitfieldInsert(data[2], value[1], 10u, 10u);
454-
}
455-
else // z
456-
{
457-
glsl::bitfieldInsert(data[2], value[0], 20u, 12u);
458-
glsl::bitfieldInsert(data[3], value[0] >> 12u, 0u, 20u);
459-
glsl::bitfieldInsert(data[3], value[1], 20u, 10u);
460-
}
461-
}
462-
463-
template<typename F>
464-
vector<F,Dimension> decode(const vector<unsigned_integer_of_size_t<sizeof(F)>,Dimension> scrambleKey)
465-
{
466-
impl::decode_before_scramble_helper<this_t,F> helper;
467-
helper.val.data = data;
468-
return helper(scrambleKey);
469-
}
470-
template<typename F>
471-
vector<F,Dimension> decode(NBL_CONST_REF_ARG(this_t) scrambleKey)
472-
{
473-
impl::decode_after_scramble_helper<this_t,F> helper;
474-
helper.val.data = data;
475-
return helper(scrambleKey);
476-
}
477-
478-
store_type data;
479-
// data[0] = | -- x 32 bits -- |
480-
// data[1] = MSB | -- y 22 bits -- | -- x 10 bits -- | LSB
481-
// data[2] = MSB | -- z 12 bits -- | -- y 20 bits -- | LSB
482-
// data[3] = | -- z 30 bits -- |
483-
};
484-
485400
}
486401

487402
}

0 commit comments

Comments
 (0)