Skip to content

Commit 569839e

Browse files
author
devsh
committed
add IGPUPolygonGeometry and attempt AssetConverter implementation for it
1 parent 65c2047 commit 569839e

File tree

5 files changed

+357
-6
lines changed

5 files changed

+357
-6
lines changed

include/nbl/asset/ICPUPolygonGeometry.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ class NBL_API2 ICPUPolygonGeometry final : public IPolygonGeometry<ICPUBuffer>
1717
{
1818
using base_t = IPolygonGeometry<ICPUBuffer>;
1919

20-
protected:
20+
public:
2121
using SDataView = base_t::SDataView;
2222

23-
public:
2423
inline ICPUPolygonGeometry() = default;
2524

2625
constexpr static inline auto AssetType = ET_GEOMETRY;
@@ -73,7 +72,7 @@ class NBL_API2 ICPUPolygonGeometry final : public IPolygonGeometry<ICPUBuffer>
7372
return false;
7473
}
7574

76-
//
75+
//
7776
inline bool setJointOBBView(SDataView&& view)
7877
{
7978
if (isMutable())
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright (C) 2018-2023 - DevSH Graphics Programming Sp. z O.O.
2+
// This file is part of the "Nabla Engine".
3+
// For conditions of distribution and use, see copyright notice in nabla.h
4+
#ifndef _NBL_VIDEO_I_GPU_POLYGON_GEOMETRY_H_INCLUDED_
5+
#define _NBL_VIDEO_I_GPU_POLYGON_GEOMETRY_H_INCLUDED_
6+
7+
8+
#include "nbl/asset/IPolygonGeometry.h"
9+
10+
#include "nbl/video/IGPUBuffer.h"
11+
12+
13+
namespace nbl::video
14+
{
15+
16+
//
17+
class IGPUPolygonGeometry final : public asset::IPolygonGeometry<const IGPUBuffer>
18+
{
19+
using base_t = asset::IPolygonGeometry<const IGPUBuffer>;
20+
21+
public:
22+
using SDataView = base_t::SDataView;
23+
struct SCreationParams
24+
{
25+
SDataView positionView = {};
26+
SDataView jointOBBView = {};
27+
SDataView indexView = {};
28+
const IIndexingCallback* indexing = nullptr;
29+
SDataView normalView = {};
30+
std::span<const SJointWeight> jointWeightViews = {};
31+
std::span<const SDataView> auxAttributeViews = {};
32+
uint32_t jointCount = 0;
33+
};
34+
static inline core::smart_refctd_ptr<IGPUPolygonGeometry> create(SCreationParams&& params)
35+
{
36+
auto retval = core::smart_refctd_ptr<IGPUPolygonGeometry>(new IGPUPolygonGeometry(),core::dont_grab);
37+
retval->m_positionView = params.positionView;
38+
if (params.jointCount)
39+
retval->m_jointOBBView = params.jointOBBView;
40+
retval->m_indexView = params.indexView;
41+
retval->m_indexing = params.indexing;
42+
if (params.jointCount)
43+
retval->m_jointWeightViews.insert(retval->m_jointWeightViews.begin(),params.jointWeightViews.begin(),params.jointWeightViews.end());
44+
retval->m_normalView = params.normalView;
45+
retval->m_auxAttributeViews.insert(retval->m_auxAttributeViews.begin(),params.auxAttributeViews.begin(),params.auxAttributeViews.end());
46+
retval->m_jointCount = params.jointCount;
47+
if (!retval->valid())
48+
return nullptr;
49+
return retval;
50+
}
51+
52+
// passthrough
53+
#if 0
54+
inline const SDataView& getNormalView() const {return base_t::getNormalView();}
55+
inline const core::vector<SJointWeight>& getJointWeightViews() const {return base_t::getJointWeightViews();}
56+
inline const core::vector<SDataView>& getAuxAttributeViews() const {return base_t::getAuxAttributeViews();}
57+
#endif
58+
59+
private:
60+
inline IGPUPolygonGeometry() = default;
61+
inline ~IGPUPolygonGeometry() = default;
62+
};
63+
64+
}
65+
66+
#endif

include/nbl/video/asset_traits.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "nbl/video/IGPUImageView.h"
2121
#include "nbl/asset/ICPUAccelerationStructure.h"
2222
#include "nbl/video/IGPUAccelerationStructure.h"
23+
#include "nbl/asset/ICPUPolygonGeometry.h"
24+
#include "nbl/video/IGPUPolygonGeometry.h"
2325

2426

2527
namespace nbl::video
@@ -229,6 +231,20 @@ struct asset_traits<asset::ICPUDescriptorSet>
229231
};
230232

231233

234+
template<>
235+
struct asset_traits<asset::ICPUPolygonGeometry>
236+
{
237+
// the asset type
238+
using asset_t = asset::ICPUPolygonGeometry;
239+
// depends on `ICPUBuffer`
240+
constexpr static inline bool HasChildren = true;
241+
// the video type
242+
using video_t = IGPUPolygonGeometry;
243+
// lookup type
244+
using lookup_t = const video_t*;
245+
};
246+
247+
232248
/* TODO
233249
template<>
234250
struct asset_traits<asset::ICPUFramebuffer>;

include/nbl/video/utilities/CAssetConverter.h

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ class CAssetConverter : public core::IReferenceCounted
5050
asset::ICPUComputePipeline,
5151
asset::ICPURenderpass,
5252
asset::ICPUGraphicsPipeline,
53-
asset::ICPUDescriptorSet
53+
asset::ICPUDescriptorSet,
5454
//asset::ICPUFramebuffer doesn't exist yet XD
55+
asset::ICPUPolygonGeometry
5556
>;
5657

5758
struct SCreationParams
@@ -430,6 +431,29 @@ class CAssetConverter : public core::IReferenceCounted
430431

431432
bool invalid = true;
432433
};
434+
template<>
435+
struct NBL_API2 patch_impl_t<asset::ICPUPolygonGeometry>
436+
{
437+
public:
438+
PATCH_IMPL_BOILERPLATE(asset::ICPUPolygonGeometry);
439+
440+
using usage_flags_t = IGPUBuffer::E_USAGE_FLAGS;
441+
// assume programmable pulling for all attributes
442+
core::bitflag<usage_flags_t> positionBufferUsages = usage_flags_t::EUF_SHADER_DEVICE_ADDRESS_BIT;
443+
// assume nothing
444+
core::bitflag<usage_flags_t> indexBufferUsages = usage_flags_t::EUF_NONE;
445+
core::bitflag<usage_flags_t> otherBufferUsages = usage_flags_t::EUF_SHADER_DEVICE_ADDRESS_BIT;
446+
447+
protected:
448+
inline std::pair<bool,this_t> combine(const this_t& other) const
449+
{
450+
this_t retval = *this;
451+
retval.indexBufferUsages |= other.indexBufferUsages;
452+
retval.positionBufferUsages |= other.positionBufferUsages;
453+
retval.otherBufferUsages |= other.otherBufferUsages;
454+
return {true,retval};
455+
}
456+
};
433457
#undef PATCH_IMPL_BOILERPLATE
434458
// The default specialization provides simple equality operations and hash operations, this will work as long as your patch_impl_t doesn't:
435459
// - use a container like `core::vector<T>`, etc.
@@ -554,6 +578,7 @@ class CAssetConverter : public core::IReferenceCounted
554578
virtual const patch_t<asset::ICPUBufferView>* operator()(const lookup_t<asset::ICPUBufferView>&) const = 0;
555579
virtual const patch_t<asset::ICPUImageView>* operator()(const lookup_t<asset::ICPUImageView>&) const = 0;
556580
virtual const patch_t<asset::ICPUPipelineLayout>* operator()(const lookup_t<asset::ICPUPipelineLayout>&) const = 0;
581+
virtual const patch_t<asset::ICPUPolygonGeometry>* operator()(const lookup_t<asset::ICPUPolygonGeometry>&) const = 0;
557582

558583
// certain items are not patchable, so there's no `patch_t` with non zero size
559584
inline const patch_t<asset::ICPUDescriptorSetLayout>* operator()(const lookup_t<asset::ICPUDescriptorSetLayout>& unpatchable) const
@@ -568,7 +593,7 @@ class CAssetConverter : public core::IReferenceCounted
568593
{
569594
return unpatchable.patch;
570595
}
571-
596+
572597
// while other things are top level assets in the graph and `operator()` would never be called on their patch
573598
};
574599
// `cacheMistrustLevel` is how deep from `asset` do we start trusting the cache to contain correct non stale hashes
@@ -681,6 +706,7 @@ class CAssetConverter : public core::IReferenceCounted
681706
bool operator()(lookup_t<asset::ICPURenderpass>);
682707
bool operator()(lookup_t<asset::ICPUGraphicsPipeline>);
683708
bool operator()(lookup_t<asset::ICPUDescriptorSet>);
709+
bool operator()(lookup_t<asset::ICPUPolygonGeometry>);
684710
};
685711

686712
//

0 commit comments

Comments
 (0)