Skip to content

Commit d7eca2b

Browse files
committed
pull master, resolve conflicts
2 parents 439177e + 43a1d17 commit d7eca2b

31 files changed

+1109
-1482
lines changed

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636
[submodule "3rdparty/gli"]
3737
path = 3rdparty/gli
3838
url = [email protected]:Devsh-Graphics-Programming/gli.git
39-
[submodule "3rdparty/parallel-hashmap"]
40-
path = 3rdparty/parallel-hashmap
41-
url = [email protected]:Devsh-Graphics-Programming/parallel-hashmap.git
4239
[submodule "3rdparty/jitify"]
4340
path = 3rdparty/jitify
4441
url = [email protected]:Devsh-Graphics-Programming/jitify.git
@@ -121,3 +118,6 @@
121118
[submodule "docker/msvc-winsdk"]
122119
path = docker/msvc-winsdk
123120
url = ../docker-nanoserver-msvc-winsdk
121+
[submodule "3rdparty/gtl"]
122+
path = 3rdparty/gtl
123+
url = https://github.com/greg7mdp/gtl.git

3rdparty/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ add_dependencies(3rdparty ${NBL_3RDPARTY_TARGETS})
522522

523523
NBL_ADJUST_FOLDERS(3rdaprty)
524524

525-
nbl_install_dir("${CMAKE_CURRENT_SOURCE_DIR}/parallel-hashmap/parallel_hashmap")
525+
nbl_install_dir("${CMAKE_CURRENT_SOURCE_DIR}/gtl/include")
526526

527527
# parent scope exports, must be at the end of the file
528528
set(_NBL_3RDPARTY_TARGETS_

3rdparty/gtl

Submodule gtl added at 6ad66cd

3rdparty/parallel-hashmap

Lines changed: 0 additions & 1 deletion
This file was deleted.

include/nbl/asset/ICPUPolygonGeometry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class NBL_API2 ICPUPolygonGeometry final : public IPolygonGeometry<ICPUBuffer>
116116
return nullptr;
117117
}
118118

119-
//
119+
// TODO: either SoA or AoS but add names
120120
inline const core::vector<SDataView>& getAuxAttributeViews() const {return base_t::getAuxAttributeViews();}
121121
inline core::vector<SDataView>* getAuxAttributeViews()
122122
{

include/nbl/asset/IGeometry.h

Lines changed: 126 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "nbl/builtin/hlsl/shapes/aabb.hlsl"
99

1010
#include "nbl/asset/IAsset.h"
11+
#include "nbl/asset/format/EFormat.h"
1112

1213

1314
namespace nbl::asset
@@ -48,9 +49,112 @@ class IGeometryBase : public virtual core::IReferenceCounted
4849
S8_NORM,
4950
BitCount=4
5051
};
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+
}
51103
// using `nbl::hlsl::` concepts instead of `std::` so that `nbl::hlsl::float16_t` can be used
52104
union SAABBStorage
53105
{
106+
template<typename Visitor>
107+
inline void visit(const EAABBFormat format, Visitor&& visitor)
108+
{
109+
switch (format)
110+
{
111+
case EAABBFormat::F64:
112+
visitor(f64);
113+
break;
114+
case EAABBFormat::U64:
115+
visitor(u64);
116+
break;
117+
case EAABBFormat::S64:
118+
visitor(s64);
119+
break;
120+
case EAABBFormat::F32:
121+
visitor(f32);
122+
break;
123+
case EAABBFormat::U32:
124+
visitor(u32);
125+
break;
126+
case EAABBFormat::S32:
127+
visitor(s32);
128+
break;
129+
case EAABBFormat::F16:
130+
visitor(f16);
131+
break;
132+
case EAABBFormat::U16: [[fallthrough]];
133+
case EAABBFormat::U16_NORM:
134+
visitor(u16);
135+
break;
136+
case EAABBFormat::S16: [[fallthrough]];
137+
case EAABBFormat::S16_NORM:
138+
visitor(s16);
139+
break;
140+
case EAABBFormat::U8: [[fallthrough]];
141+
case EAABBFormat::U8_NORM:
142+
visitor(u8);
143+
break;
144+
case EAABBFormat::S8: [[fallthrough]];
145+
case EAABBFormat::S8_NORM:
146+
visitor(s8);
147+
break;
148+
default:
149+
break;
150+
}
151+
}
152+
template<typename Visitor>
153+
inline void visit(const EAABBFormat format, Visitor&& visitor) const
154+
{
155+
const_cast<SAABBStorage*>(this)->visit(format,std::forward<Visitor>(visitor));
156+
}
157+
54158
hlsl::shapes::AABB<4,hlsl::float64_t> f64 = hlsl::shapes::AABB<4,hlsl::float64_t>::create();
55159
hlsl::shapes::AABB<4,uint64_t> u64;
56160
hlsl::shapes::AABB<4,int64_t> s64;
@@ -102,57 +206,9 @@ class IGeometryBase : public virtual core::IReferenceCounted
102206

103207
//
104208
template<typename Visitor>
105-
inline void visitAABB(Visitor& visitor)
106-
{
107-
switch (rangeFormat)
108-
{
109-
case EAABBFormat::F64:
110-
visitor(encodedDataRange.f64);
111-
break;
112-
case EAABBFormat::U64:
113-
visitor(encodedDataRange.u64);
114-
break;
115-
case EAABBFormat::S64:
116-
visitor(encodedDataRange.s64);
117-
break;
118-
case EAABBFormat::F32:
119-
visitor(encodedDataRange.f32);
120-
break;
121-
case EAABBFormat::U32:
122-
visitor(encodedDataRange.u32);
123-
break;
124-
case EAABBFormat::S32:
125-
visitor(encodedDataRange.s32);
126-
break;
127-
case EAABBFormat::F16:
128-
visitor(encodedDataRange.f16);
129-
break;
130-
case EAABBFormat::U16: [[fallthrough]];
131-
case EAABBFormat::U16_NORM:
132-
visitor(encodedDataRange.u16);
133-
break;
134-
case EAABBFormat::S16: [[fallthrough]];
135-
case EAABBFormat::S16_NORM:
136-
visitor(encodedDataRange.s16);
137-
break;
138-
case EAABBFormat::U8: [[fallthrough]];
139-
case EAABBFormat::U8_NORM:
140-
visitor(encodedDataRange.u8);
141-
break;
142-
case EAABBFormat::S8: [[fallthrough]];
143-
case EAABBFormat::S8_NORM:
144-
visitor(encodedDataRange.s8);
145-
break;
146-
default:
147-
break;
148-
}
149-
}
209+
inline void visitAABB(Visitor&& visitor) {encodedDataRange.visit(rangeFormat,std::forward<Visitor>(visitor));}
150210
template<typename Visitor>
151-
inline void visitAABB(const Visitor& visitor) const
152-
{
153-
auto tmp = [&visitor](const auto& aabb)->void{visitor(aabb);};
154-
const_cast<typename std::decay_t<decltype(*this)>*>(this)->visitAABB(tmp);
155-
}
211+
inline void visitAABB(Visitor&& visitor) const {encodedDataRange.visit(rangeFormat,std::forward<Visitor>(visitor));}
156212

157213
//
158214
inline void resetRange(const EAABBFormat newFormat)
@@ -188,7 +244,13 @@ class IGeometryBase : public virtual core::IReferenceCounted
188244
EAABBFormat rangeFormat : int(EAABBFormat::BitCount) = EAABBFormat::F64;
189245
};
190246

247+
virtual EAABBFormat getAABBFormat() const = 0;
191248
virtual const SAABBStorage& getAABB() const = 0;
249+
template<typename Visitor>
250+
inline void visitAABB(Visitor&& visitor) const
251+
{
252+
getAABB().visit(getAABBFormat(),std::forward<Visitor>(visitor));
253+
}
192254

193255
protected:
194256
virtual inline ~IGeometryBase() = default;
@@ -224,7 +286,7 @@ class IGeometry : public std::conditional_t<std::is_same_v<BufferType,ICPUBuffer
224286
explicit inline operator SBufferBinding<const BufferType>() const
225287
{
226288
if (*this)
227-
return {.offset=src.offset,.buffer=smart_refctd_ptr(src.buffer)};
289+
return {.offset=src.offset,.buffer=core::smart_refctd_ptr(src.buffer)};
228290
return {};
229291
}
230292

@@ -242,7 +304,9 @@ class IGeometry : public std::conditional_t<std::is_same_v<BufferType,ICPUBuffer
242304
template<typename Index=uint32_t, typename U=BufferType> requires (std::is_same_v<U,BufferType> && std::is_same_v<U,ICPUBuffer>)
243305
inline const void* getPointer(const Index elIx=0) const
244306
{
245-
return const_cast<typename std::decay_t<decltype(*this)>*>(this)->getPointer<U>(elIx);
307+
if (*this)
308+
return reinterpret_cast<const uint8_t*>(src.buffer->getPointer())+src.offset+elIx*composed.getStride();
309+
return nullptr;
246310
}
247311
template<typename Index=uint32_t, typename U=BufferType> requires (std::is_same_v<U,BufferType> && std::is_same_v<U,ICPUBuffer>)
248312
inline void* getPointer(const Index elIx=0)
@@ -266,11 +330,16 @@ class IGeometry : public std::conditional_t<std::is_same_v<BufferType,ICPUBuffer
266330
assert(!isScaledFormat(composed.format)); // handle this by improving the decode functions, not adding workarounds here
267331
if (decodePixels<code_t>(composed.format,srcArr,tmp,0,0))
268332
{
269-
if (isNormalizedFormat(composed.format))
333+
using traits = hlsl::vector_traits<V>;
334+
const auto range = composed.getRange<hlsl::shapes::AABB<traits::Dimension,typename traits::scalar_type>>();
335+
for (auto i=0u; i<traits::Dimension; i++)
270336
{
271-
using traits = hlsl::vector_traits<V>;
272-
const auto range = composed.getRange<hlsl::shapes::AABB<traits::Dimension,traits::scalar_type>>();
273-
v = v*(range.maxVx-range.minVx)+range.minVx;
337+
if (isNormalizedFormat(composed.format))
338+
{
339+
v[i] = tmp[i] * (range.maxVx[i] - range.minVx[i]) + range.minVx[i];
340+
}
341+
else
342+
v[i] = tmp[i];
274343
}
275344
return true;
276345
}
@@ -290,7 +359,7 @@ class IGeometry : public std::conditional_t<std::is_same_v<BufferType,ICPUBuffer
290359
using traits = hlsl::vector_traits<V>;
291360
using code_t = std::conditional_t<hlsl::concepts::FloatingPointVector<V>,hlsl::float64_t,std::conditional_t<hlsl::concepts::SignedIntVector<V>,int64_t,uint64_t>>;
292361
code_t tmp[traits::Dimension];
293-
const auto range = composed.getRange<traits::Dimension,traits::scalar_type>();
362+
const auto range = composed.getRange<traits::Dimension,typename traits::scalar_type>();
294363
for (auto i=0u; i<traits::Dimension; i++)
295364
{
296365
if (isNormalizedFormat(composed.format))

include/nbl/asset/IPolygonGeometry.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class IPolygonGeometry : public IIndexableGeometry<BufferType>, public IPolygonG
147147
return false;
148148
// the variable length vectors must be filled with valid views
149149
for (const auto& pair : m_jointWeightViews)
150-
if (!pair || !pair.weights.getElementCount()<vertexCount)
150+
if (!pair || pair.weights.getElementCount()<vertexCount)
151151
return false;
152152
for (const auto& view : m_auxAttributeViews)
153153
if (!view)
@@ -160,6 +160,7 @@ class IPolygonGeometry : public IIndexableGeometry<BufferType>, public IPolygonG
160160
inline EPrimitiveType getPrimitiveType() const override final {return PrimitiveType;}
161161

162162
//
163+
inline IGeometryBase::EAABBFormat getAABBFormat() const override final {return base_t::m_positionView.composed.rangeFormat;}
163164
inline const IGeometryBase::SAABBStorage& getAABB() const override final {return base_t::m_positionView.composed.encodedDataRange;}
164165

165166
//

include/nbl/asset/interchange/IAssetLoader.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ class NBL_API2 IAssetLoader : public virtual core::IReferenceCounted
107107
decryptionKey(rhs.decryptionKey),
108108
cacheFlags(rhs.cacheFlags),
109109
loaderFlags(rhs.loaderFlags),
110-
meshManipulatorOverride(rhs.meshManipulatorOverride),
111110
logger(rhs.logger),
112111
workingDirectory(rhs.workingDirectory)
113112
{
@@ -117,7 +116,6 @@ class NBL_API2 IAssetLoader : public virtual core::IReferenceCounted
117116
const uint8_t* decryptionKey;
118117
E_CACHING_FLAGS cacheFlags;
119118
E_LOADER_PARAMETER_FLAGS loaderFlags; //!< Flags having an impact on extraordinary tasks during loading process
120-
CPolygonGeometryManipulator* meshManipulatorOverride = nullptr; //!< pointer used for specifying custom mesh manipulator to use, if nullptr - default mesh manipulator will be used
121119
std::filesystem::path workingDirectory = "";
122120
system::logger_opt_ptr logger;
123121
};

include/nbl/asset/interchange/IGeometryLoader.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,21 @@ class IGeometryLoader : public IAssetLoader
2121
virtual inline uint64_t getSupportedAssetTypesBitfield() const override {return IAsset::ET_GEOMETRY;}
2222

2323
protected:
24-
IGeometryLoader() {}
25-
virtual ~IGeometryLoader() = 0;
24+
inline IGeometryLoader() {}
25+
26+
static inline IGeometry<ICPUBuffer>::SDataView createView(const E_FORMAT format, const size_t elementCount, const void* data=nullptr)
27+
{
28+
const auto stride = getTexelOrBlockBytesize(format);
29+
auto buffer = ICPUBuffer::create({{stride*elementCount},const_cast<void*>(data)});
30+
return {
31+
.composed = {
32+
.stride = stride,
33+
.format = format,
34+
.rangeFormat = IGeometryBase::getMatchingAABBFormat(format)
35+
},
36+
.src = {.offset=0,.size=buffer->getSize(),.buffer=std::move(buffer)}
37+
};
38+
}
2639

2740
private:
2841
};

0 commit comments

Comments
 (0)