|
8 | 8 | #include "nbl/builtin/hlsl/shapes/aabb.hlsl"
|
9 | 9 |
|
10 | 10 | #include "nbl/asset/IAsset.h"
|
| 11 | +#include "nbl/asset/format/EFormat.h" |
11 | 12 |
|
12 | 13 |
|
13 | 14 | namespace nbl::asset
|
@@ -48,6 +49,57 @@ class IGeometryBase : public virtual core::IReferenceCounted
|
48 | 49 | S8_NORM,
|
49 | 50 | BitCount=4
|
50 | 51 | };
|
| 52 | + // |
| 53 | + static inline EAABBFormat getMatchingAABBFormat(const E_FORMAT attributeFormat) |
| 54 | + { |
| 55 | + if (isBlockCompressionFormat(attributeFormat)) |
| 56 | + return EAABBFormat::BitCount; |
| 57 | + if (isFloatingPointFormat(attributeFormat)) |
| 58 | + { |
| 59 | + const auto maxVal = getFormatMaxValue<double>(attributeFormat,0); |
| 60 | + if (maxVal>hlsl::numeric_limits<hlsl::float32_t>::max) |
| 61 | + return EAABBFormat::F64; |
| 62 | + if (maxVal>hlsl::numeric_limits<hlsl::float16_t>::max) |
| 63 | + return EAABBFormat::F32; |
| 64 | + return EAABBFormat::F16; |
| 65 | + } |
| 66 | + else if (isNormalizedFormat(attributeFormat)) |
| 67 | + { |
| 68 | + const auto precision = getFormatPrecision<float>(attributeFormat,0,0.f); |
| 69 | + const auto minVal = getFormatMinValue<float>(attributeFormat,0); |
| 70 | + if (minVal<-0.f) |
| 71 | + return precision<getFormatPrecision<float>(EF_R8_SNORM,0,0.f) ? EAABBFormat::S16_NORM:EAABBFormat::S8_NORM; |
| 72 | + else |
| 73 | + return precision<getFormatPrecision<float>(EF_R8_UNORM,0,0.f) ? EAABBFormat::U16_NORM:EAABBFormat::U8_NORM; |
| 74 | + } |
| 75 | + else if (isIntegerFormat(attributeFormat)) |
| 76 | + { |
| 77 | + if (isSignedFormat(attributeFormat)) |
| 78 | + { |
| 79 | + const auto maxVal = getFormatMaxValue<int64_t>(attributeFormat,0); |
| 80 | + if (maxVal>hlsl::numeric_limits<int32_t>::max) |
| 81 | + return EAABBFormat::S64; |
| 82 | + else if (maxVal>hlsl::numeric_limits<int16_t>::max) |
| 83 | + return EAABBFormat::S32; |
| 84 | + else if (maxVal>hlsl::numeric_limits<int8_t>::max) |
| 85 | + return EAABBFormat::S16; |
| 86 | + return EAABBFormat::S8; |
| 87 | + } |
| 88 | + else |
| 89 | + { |
| 90 | + const auto maxVal = getFormatMaxValue<uint64_t>(attributeFormat,0); |
| 91 | + if (maxVal>hlsl::numeric_limits<uint32_t>::max) |
| 92 | + return EAABBFormat::U64; |
| 93 | + else if (maxVal>hlsl::numeric_limits<uint16_t>::max) |
| 94 | + return EAABBFormat::U32; |
| 95 | + else if (maxVal>hlsl::numeric_limits<uint8_t>::max) |
| 96 | + return EAABBFormat::U16; |
| 97 | + return EAABBFormat::U8; |
| 98 | + |
| 99 | + } |
| 100 | + } |
| 101 | + return EAABBFormat::BitCount; |
| 102 | + } |
51 | 103 | // using `nbl::hlsl::` concepts instead of `std::` so that `nbl::hlsl::float16_t` can be used
|
52 | 104 | union SAABBStorage
|
53 | 105 | {
|
|
0 commit comments