Skip to content

Commit b7e1139

Browse files
Merge pull request #878 from Devsh-Graphics-Programming/more_asset_converter_for_tlas
Working and Tested Asset Converter for Acceleration Structures
2 parents b7fc736 + ad96f8a commit b7e1139

23 files changed

+1230
-926
lines changed

include/nbl/asset/IAccelerationStructure.h

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -88,42 +88,62 @@ class IBottomLevelAccelerationStructure : public IAccelerationStructure
8888
NO_DUPLICATE_ANY_HIT_INVOCATION_BIT = 0x1u<<1u,
8989
};
9090

91+
enum class GeometryType : uint8_t
92+
{
93+
Triangles = 0,
94+
AABBs = 1,
95+
// Later: LSS and friends
96+
Count = 2
97+
};
98+
9199
// Note that in Vulkan strides are 64-bit value but restricted to be 32-bit in range
92-
template<typename BufferType> requires std::is_base_of_v<IBuffer,BufferType>
100+
template<typename BufferType> requires (!std::is_const_v<BufferType> && std::is_base_of_v<IBuffer,BufferType>)
93101
struct Triangles
94102
{
95-
using buffer_t = std::remove_const_t<BufferType>;
96-
constexpr static inline bool Host = std::is_same_v<buffer_t,ICPUBuffer>;
97-
// we make our life easier by not taking pointers to single matrix values
98-
using transform_t = std::conditional_t<Host,hlsl::float32_t3x4,asset::SBufferBinding<const buffer_t>>;
99-
100-
inline bool hasTransform() const
101-
{
102-
if constexpr (Host)
103-
return !core::isnan(transform[0][0]);
104-
else
105-
return bool(transform.buffer);
106-
}
107-
108-
// optional, only useful for baking model transforms of multiple meshes into one BLAS
109-
transform_t transform = {};
110-
// vertexData[1] are the vertex positions at time 1.0, and only used for AccelerationStructures created with `MOTION_BIT`
111-
asset::SBufferBinding<const buffer_t> vertexData[2] = {{},{}};
112-
asset::SBufferBinding<const buffer_t> indexData = {};
113-
uint32_t maxVertex = 0u;
114-
// type implicitly satisfies: https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkAccelerationStructureGeometryTrianglesDataKHR-vertexStride-03819
115-
uint32_t vertexStride = sizeof(float);
116-
E_FORMAT vertexFormat = EF_R32G32B32_SFLOAT;
117-
E_INDEX_TYPE indexType = EIT_UNKNOWN;
118-
core::bitflag<GEOMETRY_FLAGS> geometryFlags = GEOMETRY_FLAGS::NONE;
119-
// TODO: opacity and displacement micromap buffers and shizz
103+
public:
104+
using buffer_t = BufferType;
105+
constexpr static inline GeometryType Type = GeometryType::Triangles;
106+
107+
constexpr static inline bool HostTransform = std::is_same_v<buffer_t,ICPUBuffer>;
108+
// we make our life easier by not taking pointers to single matrix values
109+
using transform_t = std::conditional_t<HostTransform,hlsl::float32_t3x4,asset::SBufferBinding<const buffer_t>>;
110+
111+
inline bool hasTransform() const
112+
{
113+
if constexpr (HostTransform)
114+
return !core::isnan(transform[0][0]);
115+
else
116+
return bool(transform.buffer);
117+
}
118+
119+
// optional, only useful for baking model transforms of multiple meshes into one BLAS
120+
transform_t transform = __transform_initializer();
121+
// vertexData[1] are the vertex positions at time 1.0, and only used for AccelerationStructures created with `MOTION_BIT`
122+
asset::SBufferBinding<const buffer_t> vertexData[2] = {{},{}};
123+
asset::SBufferBinding<const buffer_t> indexData = {};
124+
uint32_t maxVertex = 0u;
125+
// type implicitly satisfies: https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkAccelerationStructureGeometryTrianglesDataKHR-vertexStride-03819
126+
uint32_t vertexStride = sizeof(float);
127+
E_FORMAT vertexFormat = EF_R32G32B32_SFLOAT;
128+
E_INDEX_TYPE indexType = EIT_UNKNOWN;
129+
core::bitflag<GEOMETRY_FLAGS> geometryFlags = GEOMETRY_FLAGS::NONE;
130+
// TODO: opacity and displacement micromap buffers and shizz
131+
132+
private:
133+
constexpr static transform_t __transform_initializer()
134+
{
135+
if constexpr (HostTransform)
136+
return hlsl::float32_t3x4(std::numeric_limits<float>::quiet_NaN());
137+
return {};
138+
}
120139
};
121140

122141
//
123-
template<typename BufferType> requires std::is_base_of_v<IBuffer,BufferType>
142+
template<typename BufferType> requires (!std::is_const_v<BufferType> && std::is_base_of_v<IBuffer,BufferType>)
124143
struct AABBs
125144
{
126-
using buffer_t = std::remove_const_t<BufferType>;
145+
using buffer_t = BufferType;
146+
constexpr static inline GeometryType Type = GeometryType::AABBs;
127147

128148
// for `MOTION_BIT` you don't get a second buffer for AABBs at different times because linear interpolation of AABBs doesn't work
129149
asset::SBufferBinding<const BufferType> data = {};

include/nbl/asset/ICPUAccelerationStructure.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class ICPUBottomLevelAccelerationStructure final : public IPreHashed, public IBo
140140

141141
inline core::blake3_hash_t computeContentHash() const override
142142
{
143-
if (!missingContent())
143+
if (missingContent())
144144
return INVALID_HASH;
145145
const bool isAABB = m_buildFlags.hasFlags(BUILD_FLAGS::GEOMETRY_TYPE_IS_AABB_BIT);
146146
core::blake3_hasher hasher;

0 commit comments

Comments
 (0)