Skip to content

Commit c489f5a

Browse files
add IAnimationBlendManager
1 parent a4d3257 commit c489f5a

File tree

4 files changed

+104
-6
lines changed

4 files changed

+104
-6
lines changed

include/nbl/asset/IAnimationLibrary.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ template <class BufferType>
2323
class IAnimationLibrary : public virtual core::IReferenceCounted
2424
{
2525
public:
26+
using keyframe_t = uint32_t;
27+
using animation_t = uint32_t;
2628
using timestamp_t = uint32_t;
29+
2730
struct alignas(8) Keyframe
2831
{
2932
Keyframe() : scale(0ull) // TODO: initialize scale to 1.f
@@ -71,14 +74,14 @@ class IAnimationLibrary : public virtual core::IReferenceCounted
7174
{
7275
data[0] = data[1] = 0xffffffffu;
7376
}
74-
inline Animation(const uint32_t keyframeOffset, const uint32_t keyframeCount, const E_INTERPOLATION_MODE interpolation)
77+
inline Animation(const keyframe_t keyframeOffset, const uint32_t keyframeCount, const E_INTERPOLATION_MODE interpolation)
7578
{
7679
data[0] = keyframeOffset;
7780
assert(keyframeCount<0x4fffffffu);
7881
data[1] = keyframeCount|interpolation;
7982
}
8083

81-
inline uint32_t getKeyframeOffset() const
84+
inline keyframe_t getKeyframeOffset() const
8285
{
8386
return data[0];
8487
}
@@ -121,7 +124,7 @@ class IAnimationLibrary : public virtual core::IReferenceCounted
121124
return m_animationStorageRange.size/sizeof(Animation);
122125
}
123126

124-
inline uint32_t getAnimationOffsetFromName(const char* animationName) const
127+
inline animation_t getAnimationOffsetFromName(const char* animationName) const
125128
{
126129
m_temporaryString = animationName;
127130
auto found = m_nameToAnimation.find(0xffffffffu);
@@ -217,7 +220,7 @@ class IAnimationLibrary : public virtual core::IReferenceCounted
217220
};
218221
core::vector<char> m_stringPool;
219222
mutable const char* m_temporaryString;
220-
core::map<uint32_t,uint32_t,StringComparator> m_nameToAnimation;
223+
core::map<uint32_t,animation_t,StringComparator> m_nameToAnimation;
221224

222225
SBufferBinding<BufferType> m_keyframeStorageBinding,m_timestampStorageBinding;
223226
SBufferRange<BufferType> m_animationStorageRange;
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright (C) 2019 - DevSH Graphics Programming Sp. z O.O.
2+
// For conditions of distribution and use, see copyright notice in nabla.h
3+
// See the original file in irrlicht source for authors
4+
5+
#ifndef __NBL_SCENE_I_ANIMATION_BLEND_MANAGER_H_INCLUDED__
6+
#define __NBL_SCENE_I_ANIMATION_BLEND_MANAGER_H_INCLUDED__
7+
8+
#include "nbl/core/core.h"
9+
#include "nbl/video/video.h"
10+
11+
#include "nbl/scene/ITransformTreeManager.h"
12+
13+
namespace nbl
14+
{
15+
namespace scene
16+
{
17+
18+
class IAnimationBlendManager : public virtual core::IReferenceCounted
19+
{
20+
public:
21+
using blend_t = uint32_t;
22+
23+
// creation (TODO: should we support adding and removing animation libraries at runtime?)
24+
static inline core::smart_refctd_ptr<ITransformTreeManager> create(video::IVideoDriver* _driver, core::smart_refctd_ptr<video::IGPUAnimationLibrary>&& _animationLibrary)
25+
{
26+
if (true) // TODO: some checks and validation before creating?
27+
return nullptr;
28+
29+
auto* abm = new IAnimationBlendManager(_driver,std::move(_animationLibrary));
30+
return core::smart_refctd_ptr<IAnimationBlendManager>(abm,core::dont_grab);
31+
}
32+
33+
// TODO: we should probably group blends of different update frequencies separately
34+
void registerBlends(blend_t* blendsOut)
35+
{
36+
// TODO: register animation blends as <video::IGPUAnimationLibrary::animation_t,<updateFrequency,finishAndPause/finish/loop/<pingpongCurrFWD,pingpongCurrBWD>>,target node_t> (use a pool allocator)
37+
}
38+
39+
// add to a contiguous list in GPU memory
40+
void startBlends(const blend_t* begin, const blend_t* end)
41+
{
42+
// easy enough, just add the uints to the back of a GPU buffer and increment the counter used in dispatch indirect buffer
43+
}
44+
// remove from a contiguous list in GPU memory
45+
void pauseBlends(const blend_t* begin, const blend_t* end)
46+
{
47+
}
48+
49+
//
50+
void seekBlends(const blend_t* begin, const blend_t* end, const ITransformTreeManager::timestamp_t* timestamps)
51+
{
52+
}
53+
54+
// need to pause the blends first
55+
void deregisterBlends(const blend_t* begin, const blend_t* end)
56+
{
57+
}
58+
59+
void computeBlends(ITransformTreeManager::timestamp_t newTimestamp,
60+
const asset::SBufferBinding<video::IGPUBuffer>& relativeTformUpdateIndirectParameters,
61+
const asset::SBufferBinding<video::IGPUBuffer>& nodeIDBuffer, // first uint in the nodeIDBuffer is used to denote how many requests we have
62+
const asset::SBufferBinding<video::IGPUBuffer>& modificationRequestBuffer,
63+
const asset::SBufferBinding<video::IGPUBuffer>& modificationRequestTimestampBuffer)
64+
{
65+
m_driver->bindComputePipeline(m_computeBlendsPipeline.get());
66+
// TODO: bind descriptor sets
67+
m_driver->dispatchIndirect(m_dispatchIndirectCommandBuffer.get(),0u);
68+
// TODO: pipeline barrier for SSBO and TBO and COMMAND_BIT too
69+
}
70+
protected:
71+
IAnimationBlendManager(video::IVideoDriver* _driver, core::smart_refctd_ptr<video::IGPUAnimationLibrary>&& _animationLibrary) : m_driver(_driver), m_animationLibrary(std::move(_animationLibrary))
72+
{
73+
}
74+
~IAnimationBlendManager()
75+
{
76+
// everything drops itself automatically
77+
}
78+
79+
video::IVideoDriver* m_driver;
80+
core::smart_refctd_ptr<video::IGPUAnimationLibrary> m_animationLibrary;
81+
core::smart_refctd_ptr<video::IGPUComputePipeline> m_computeBlendsPipeline;
82+
core::smart_refctd_ptr<video::IGPUDescriptorSet> m_animationDS; // animation library (keyframes + animations) + registered blends + active blends
83+
core::smart_refctd_ptr<video::IGPUBuffer> m_dispatchIndirectCommandBuffer;
84+
};
85+
86+
87+
} // end namespace scene
88+
} // end namespace nbl
89+
90+
#endif
91+

include/nbl/scene/ITransformTreeManager.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ class ITransformTreeManager : public virtual core::IReferenceCounted
211211
core::smart_refctd_ptr<property_pool_t> m_nodeStorage;
212212
core::smart_refctd_ptr<video::IGPUComputePipeline> m_updatePipeline,m_recomputePipeline,m_updateAndRecomputePipeline;
213213
core::smart_refctd_ptr<video::IGPUDescriptorSet> m_transformHierarchyDS;
214+
// TODO: do we keep a contiguous `node_t` array in-case we want to shortcut to full tree reevaluation when the number of relative transform modification requsts > totalNodes*ratio (or overflows the temporary buffer we've provided) ?
215+
/** Ideal O(1) insertion and erasure
216+
* Add: new nodes using pool allocator, add the node_t references to the back of the contiguous array (increment atomic) and record where the reference is (offset into contiguous) as an additional property of the node
217+
* Remove: lookup the contiguous offset property for the removed node, decremenet contiguous array size atomic and save the return value as the reference to be swapped, swap the erased reference with the one to be swapped, dereference the swapped reference and update its pointer to contiguous
218+
**/
214219
};
215220

216221

include/nbl/scene/scene.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
#include "nbl/ui/ui.h"
1111

1212
//
13-
//#include "nbl/scene/IAnimationBlendManager.h"
14-
#include "nbl/scene/ITransformTreeManager.h"
13+
#include "nbl/scene/IAnimationBlendManager.h"
1514
//#include "nbl/scene/ILevelOfDetailLibrary.h"
1615
//#include "nbl/scene/ISensor.h" or asset? or a struct?
1716
//#include "nbl/scene/ICamera.h" or do we stick it inside the renderpass?

0 commit comments

Comments
 (0)