Skip to content

Commit 96cb5f8

Browse files
debug draw complete, the bone AABBs seem off
1 parent bbee11f commit 96cb5f8

File tree

4 files changed

+91
-90
lines changed

4 files changed

+91
-90
lines changed

examples_tests/12.glTF/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class GLTFApp : public ApplicationBase
110110
ttDebugDrawPipeline = transformTreeManager->createDebugPipeline<scene::ITransformTreeWithNormalMatrices>(core::smart_refctd_ptr(renderpass));
111111
ttmDescriptorSets = transformTreeManager->createAllDescriptorSets(logicalDevice.get());
112112

113-
sicManager = scene::ISkinInstanceCacheManager::create(utilities.get(),transferUpQueue);
113+
sicManager = scene::ISkinInstanceCacheManager::create(utilities.get(),transferUpQueue,transformTreeManager.get());
114114
sicDebugDrawPipeline = sicManager->createDebugPipeline(core::smart_refctd_ptr(renderpass));
115115
sicDescriptorSets = sicManager->createAllDescriptorSets(logicalDevice.get());
116116

@@ -652,9 +652,9 @@ class GLTFApp : public ApplicationBase
652652

653653
sicManager->updateDebugDrawDescriptorSet(
654654
logicalDevice.get(),sicDescriptorSets.debugDraw.get(),
655+
transformTree.get(),SBufferBinding(aabbBinding),
655656
{0ull,utilities->createFilledDeviceLocalGPUBufferOnDedMem(transferUpQueue,sizeof(scene::ISkinInstanceCacheManager::DebugDrawData)*debugData.size(),debugData.data())},
656-
{0ull,utilities->createFilledDeviceLocalGPUBufferOnDedMem(transferUpQueue,sizeof(uint32_t)*jointCountInclPrefixSum.size(),jointCountInclPrefixSum.data())},
657-
SBufferBinding(aabbBinding)
657+
{0ull,utilities->createFilledDeviceLocalGPUBufferOnDedMem(transferUpQueue,sizeof(uint32_t)*jointCountInclPrefixSum.size(),jointCountInclPrefixSum.data())}
658658
);
659659
}
660660
}

include/nbl/builtin/glsl/skinning/debug.vert

Lines changed: 64 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,46 @@
88
#define NBL_GLSL_SKINNING_DEBUG_DESCRIPTOR_SET 1
99
#endif
1010

11+
#ifndef NBL_GLSL_TRANSFORM_TREE_POOL_NODE_PARENT_DESCRIPTOR_BINDING
12+
#define NBL_GLSL_TRANSFORM_TREE_POOL_NODE_PARENT_DESCRIPTOR_BINDING 0
13+
#endif
14+
#ifndef NBL_GLSL_TRANSFORM_TREE_POOL_NODE_PARENT_DESCRIPTOR_QUALIFIERS
15+
#define NBL_GLSL_TRANSFORM_TREE_POOL_NODE_PARENT_DESCRIPTOR_QUALIFIERS readonly restrict
16+
#endif
17+
layout(
18+
set=NBL_GLSL_SKINNING_DEBUG_DESCRIPTOR_SET,
19+
binding=NBL_GLSL_TRANSFORM_TREE_POOL_NODE_PARENT_DESCRIPTOR_BINDING
20+
) NBL_GLSL_TRANSFORM_TREE_POOL_NODE_PARENT_DESCRIPTOR_QUALIFIERS buffer NodeParents
21+
{
22+
uint data[];
23+
} nodeParents;
24+
25+
#include "nbl/builtin/glsl/shapes/aabb.glsl"
26+
#ifndef NBL_GLSL_SKINNING_DEBUG_AABB_DESCRIPTOR_BINDING
27+
#define NBL_GLSL_SKINNING_DEBUG_AABB_DESCRIPTOR_BINDING 1
28+
#endif
29+
#ifndef NBL_GLSL_SKINNING_DEBUG_AABB_DESCRIPTOR_QUALIFIERS
30+
#define NBL_GLSL_SKINNING_DEBUG_AABB_DESCRIPTOR_QUALIFIERS readonly restrict
31+
#endif
32+
#ifndef NBL_GLSL_SKINNING_DEBUG_AABB_DESCRIPTOR_DECLARED
33+
#define NBL_GLSL_SKINNING_DEBUG_AABB_DESCRIPTOR_DECLARED
34+
layout(
35+
set=NBL_GLSL_SKINNING_DEBUG_DESCRIPTOR_SET,
36+
binding=NBL_GLSL_SKINNING_DEBUG_AABB_DESCRIPTOR_BINDING
37+
) NBL_GLSL_SKINNING_DEBUG_AABB_DESCRIPTOR_QUALIFIERS buffer DebugAABB
38+
{
39+
nbl_glsl_shapes_CompressedAABB_t data[];
40+
} debugAABB;
41+
#endif
42+
1143
struct nbl_glsl_skinning_DebugData_t
1244
{
1345
uint skinOffset;
1446
uint aabbOffset;
1547
uint pivotNode;
1648
};
1749
#ifndef NBL_GLSL_SKINNING_DEBUG_DATA_DESCRIPTOR_BINDING
18-
#define NBL_GLSL_SKINNING_DEBUG_DATA_DESCRIPTOR_BINDING 0
50+
#define NBL_GLSL_SKINNING_DEBUG_DATA_DESCRIPTOR_BINDING 2
1951
#endif
2052
#ifndef NBL_GLSL_SKINNING_DEBUG_DATA_DESCRIPTOR_QUALIFIERS
2153
#define NBL_GLSL_SKINNING_DEBUG_DATA_DESCRIPTOR_QUALIFIERS readonly restrict
@@ -32,7 +64,7 @@ layout(
3264
#endif
3365

3466
#ifndef NBL_GLSL_SKINNING_DEBUG_JOINT_COUNT_INCL_PREFIX_SUM_DESCRIPTOR_BINDING
35-
#define NBL_GLSL_SKINNING_DEBUG_JOINT_COUNT_INCL_PREFIX_SUM_DESCRIPTOR_BINDING 1
67+
#define NBL_GLSL_SKINNING_DEBUG_JOINT_COUNT_INCL_PREFIX_SUM_DESCRIPTOR_BINDING 3
3668
#endif
3769
#ifndef NBL_GLSL_SKINNING_DEBUG_JOINT_COUNT_INCL_PREFIX_SUM_DESCRIPTOR_QUALIFIERS
3870
#define NBL_GLSL_SKINNING_DEBUG_JOINT_COUNT_INCL_PREFIX_SUM_DESCRIPTOR_QUALIFIERS readonly restrict
@@ -48,24 +80,6 @@ layout(
4880
};
4981
#endif
5082

51-
#include "nbl/builtin/glsl/shapes/aabb.glsl"
52-
#ifndef NBL_GLSL_SKINNING_DEBUG_AABB_DESCRIPTOR_BINDING
53-
#define NBL_GLSL_SKINNING_DEBUG_AABB_DESCRIPTOR_BINDING 2
54-
#endif
55-
#ifndef NBL_GLSL_SKINNING_DEBUG_AABB_DESCRIPTOR_QUALIFIERS
56-
#define NBL_GLSL_SKINNING_DEBUG_AABB_DESCRIPTOR_QUALIFIERS readonly restrict
57-
#endif
58-
#ifndef NBL_GLSL_SKINNING_DEBUG_AABB_DESCRIPTOR_DECLARED
59-
#define NBL_GLSL_SKINNING_DEBUG_AABB_DESCRIPTOR_DECLARED
60-
layout(
61-
set=NBL_GLSL_SKINNING_DEBUG_DESCRIPTOR_SET,
62-
binding=NBL_GLSL_SKINNING_DEBUG_AABB_DESCRIPTOR_BINDING
63-
) NBL_GLSL_SKINNING_DEBUG_AABB_DESCRIPTOR_QUALIFIERS buffer DebugAABB
64-
{
65-
nbl_glsl_shapes_CompressedAABB_t data[];
66-
} debugAABB;
67-
#endif
68-
6983

7084
layout( push_constant, row_major ) uniform PushConstants
7185
{
@@ -91,17 +105,34 @@ void main()
91105
uint jointID = gl_InstanceIndex;
92106
if (bool(skinInstanceID))
93107
jointID -= jointCountInclPrefixSum[skinInstanceID-1u];
94-
95-
// TODO: draw the parent hierarchy too
96-
const nbl_glsl_shapes_AABB_t aabb = nbl_glsl_shapes_CompressedAABB_t_decompress(debugAABB.data[dd.aabbOffset+jointID]);
97-
98-
const bvec3 mask = bvec3(gl_VertexIndex&0x1u,gl_VertexIndex&0x2u,gl_VertexIndex&0x4u);
99-
const vec3 pos = nbl_glsl_pseudoMul3x4with3x1(
100-
nbl_glsl_pseudoMul4x3with4x3(nodeGlobalTransforms.data[dd.pivotNode],skinningTransforms.data[dd.skinOffset+jointID]),
101-
mix(aabb.minVx,aabb.maxVx,mask)
102-
);
103-
104-
outColor = pc.aabbColor;
105-
gl_Position = nbl_glsl_pseudoMul4x4with3x1(pc.viewProj,pos);
106-
108+
109+
const uint skeletonNode = jointNodes.data[dd.skinOffset+jointID];
110+
111+
vec3 pos;
112+
if (gl_VertexIndex<8u) // render box
113+
{
114+
const nbl_glsl_shapes_AABB_t aabb = nbl_glsl_shapes_CompressedAABB_t_decompress(debugAABB.data[dd.aabbOffset+jointID]);
115+
116+
const bvec3 mask = bvec3(gl_VertexIndex&0x1u,gl_VertexIndex&0x2u,gl_VertexIndex&0x4u);
117+
//pos = nbl_glsl_pseudoMul3x4with3x1(nodeGlobalTransforms.data[skeletonNode],mix(aabb.minVx,aabb.maxVx,mask));
118+
pos = nbl_glsl_pseudoMul3x4with3x1(skinningTransforms.data[dd.skinOffset+jointID],mix(aabb.minVx,aabb.maxVx,mask));
119+
120+
outColor = pc.aabbColor.rgb;
121+
}
122+
else // render node-parent line
123+
{
124+
const uint nodeParentID = nodeParents.data[skeletonNode];
125+
126+
uint id = skeletonNode;
127+
if (bool(gl_VertexIndex&0x1u)&&nodeParentID!=NBL_GLSL_PROPERTY_POOL_INVALID)
128+
id = nodeParentID;
129+
pos = nodeGlobalTransforms.data[id][3];
130+
131+
outColor = pc.lineColor.rgb;
132+
}
133+
134+
if (dd.pivotNode!=NBL_GLSL_PROPERTY_POOL_INVALID)
135+
gl_Position = nbl_glsl_pseudoMul4x4with3x1(pc.viewProj,nbl_glsl_pseudoMul3x4with3x1(nodeGlobalTransforms.data[dd.pivotNode],pos));
136+
else
137+
gl_Position = nbl_glsl_pseudoMul4x4with3x1(pc.viewProj,pos);
107138
}

include/nbl/scene/ISkinInstanceCacheManager.h

Lines changed: 16 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ISkinInstanceCacheManager : public virtual core::IReferenceCounted
2020
{
2121
public:
2222
// creation
23-
static inline core::smart_refctd_ptr<ISkinInstanceCacheManager> create(video::IUtilities* utils, video::IGPUQueue* uploadQueue)
23+
static inline core::smart_refctd_ptr<ISkinInstanceCacheManager> create(video::IUtilities* utils, video::IGPUQueue* uploadQueue, ITransformTreeManager* ttm)
2424
{
2525
auto device = utils->getLogicalDevice();
2626
auto system = device->getPhysicalDevice()->getSystem();
@@ -49,39 +49,6 @@ class ISkinInstanceCacheManager : public virtual core::IReferenceCounted
4949
if (!initTimestampValue)
5050
return nullptr;
5151
initTimestampValue->setObjectDebugName("ISkinInstanceCacheManager::m_initTimestampValue");
52-
53-
tmp.resize(sizeof(uint16_t)*IndexCount);
54-
uint16_t* debugIndices = reinterpret_cast<uint16_t*>(tmp.data());
55-
{
56-
std::fill_n(debugIndices,24u,0u);
57-
debugIndices[0] = 0b000;
58-
debugIndices[1] = 0b001;
59-
debugIndices[2] = 0b001;
60-
debugIndices[3] = 0b011;
61-
debugIndices[4] = 0b011;
62-
debugIndices[5] = 0b010;
63-
debugIndices[6] = 0b010;
64-
debugIndices[7] = 0b000;
65-
debugIndices[8] = 0b000;
66-
debugIndices[9] = 0b100;
67-
debugIndices[10] = 0b001;
68-
debugIndices[11] = 0b101;
69-
debugIndices[12] = 0b010;
70-
debugIndices[13] = 0b110;
71-
debugIndices[14] = 0b011;
72-
debugIndices[15] = 0b111;
73-
debugIndices[16] = 0b100;
74-
debugIndices[17] = 0b101;
75-
debugIndices[18] = 0b101;
76-
debugIndices[19] = 0b111;
77-
debugIndices[20] = 0b100;
78-
debugIndices[21] = 0b110;
79-
debugIndices[22] = 0b110;
80-
debugIndices[23] = 0b111;
81-
}
82-
auto debugIndexBuffer = utils->createFilledDeviceLocalGPUBufferOnDedMem(uploadQueue,tmp.size(),debugIndices);
83-
if (!debugIndexBuffer)
84-
return nullptr;
8552

8653
auto cacheDsLayout = ISkinInstanceCache::createCacheDescriptorSetLayout(device);
8754
auto cacheUpdateDsLayout = createCacheUpdateDescriptorSetLayout(device);
@@ -115,9 +82,8 @@ class ISkinInstanceCacheManager : public virtual core::IReferenceCounted
11582
return nullptr;
11683

11784
auto* sicm = new ISkinInstanceCacheManager(
118-
core::smart_refctd_ptr<video::ILogicalDevice>(device),
119-
std::move(cacheUpdatePipeline),std::move(debugDrawIndepenedentPipeline),
120-
std::move(initTimestampValue),std::move(debugIndexBuffer)
85+
core::smart_refctd_ptr<video::ILogicalDevice>(device),ttm,
86+
std::move(cacheUpdatePipeline),std::move(debugDrawIndepenedentPipeline),std::move(initTimestampValue)
12187
);
12288
return core::smart_refctd_ptr<ISkinInstanceCacheManager>(sicm,core::dont_grab);
12389
}
@@ -446,7 +412,7 @@ class ISkinInstanceCacheManager : public virtual core::IReferenceCounted
446412
}
447413

448414
//
449-
static inline constexpr uint32_t DebugDrawDescriptorBindingCount = 3u;
415+
static inline constexpr uint32_t DebugDrawDescriptorBindingCount = 4u;
450416
static inline core::smart_refctd_ptr<video::IGPUDescriptorSetLayout> createDebugDrawDescriptorSetLayout(video::ILogicalDevice* device, asset::ISpecializedShader::E_SHADER_STAGE* stageAccessFlags=nullptr)
451417
{
452418
video::IGPUDescriptorSetLayout::SBinding bindings[DebugDrawDescriptorBindingCount];
@@ -462,9 +428,10 @@ class ISkinInstanceCacheManager : public virtual core::IReferenceCounted
462428
};
463429
static inline void updateDebugDrawDescriptorSet(
464430
video::ILogicalDevice* device, video::IGPUDescriptorSet* debugDrawDS,
431+
const scene::ITransformTree* transformTree,
432+
asset::SBufferBinding<video::IGPUBuffer>&& aabbPool,
465433
asset::SBufferBinding<video::IGPUBuffer>&& skinInstanceDebugData,
466-
asset::SBufferBinding<video::IGPUBuffer>&& skinInstanceJointCountInclPrefixSum,
467-
asset::SBufferBinding<video::IGPUBuffer>&& aabbPool
434+
asset::SBufferBinding<video::IGPUBuffer>&& skinInstanceJointCountInclPrefixSum
468435
)
469436
{
470437
video::IGPUDescriptorSet::SWriteDescriptorSet writes[DebugDrawDescriptorBindingCount];
@@ -478,9 +445,10 @@ class ISkinInstanceCacheManager : public virtual core::IReferenceCounted
478445
writes[i].descriptorType = asset::EDT_STORAGE_BUFFER;
479446
writes[i].info = infos+i;
480447
}
481-
infos[0] = skinInstanceDebugData;
482-
infos[1] = skinInstanceJointCountInclPrefixSum;
483-
infos[2] = aabbPool;
448+
infos[0] = transformTree->getNodePropertyPool()->getPropertyMemoryBlock(scene::ITransformTree::parent_prop_ix);
449+
infos[1] = aabbPool;
450+
infos[2] = skinInstanceDebugData;
451+
infos[3] = skinInstanceJointCountInclPrefixSum;
484452
device->updateDescriptorSets(DebugDrawDescriptorBindingCount,writes,0u,nullptr);
485453
}
486454
struct DebugPushConstants
@@ -503,7 +471,7 @@ class ISkinInstanceCacheManager : public virtual core::IReferenceCounted
503471
cmdbuf->bindGraphicsPipeline(pipeline);
504472
cmdbuf->bindIndexBuffer(m_debugIndexBuffer.get(),0u,asset::EIT_16BIT);
505473
cmdbuf->pushConstants(layout,asset::ISpecializedShader::ESS_VERTEX,0u,sizeof(DebugPushConstants),&pushConstants);
506-
cmdbuf->drawIndexed(IndexCount,totalJointCount,0u,0u,0u);
474+
cmdbuf->drawIndexed(ITransformTreeManager::DebugIndexCount,totalJointCount,0u,0u,0u);
507475
}
508476

509477
//
@@ -530,14 +498,14 @@ class ISkinInstanceCacheManager : public virtual core::IReferenceCounted
530498
protected:
531499
ISkinInstanceCacheManager(
532500
core::smart_refctd_ptr<video::ILogicalDevice>&& _device,
501+
const ITransformTreeManager* ttm,
533502
core::smart_refctd_ptr<video::IGPUComputePipeline>&& _cacheUpdate,
534503
core::smart_refctd_ptr<video::IGPURenderpassIndependentPipeline>&& _debugDrawRenderpassIndependent,
535-
core::smart_refctd_ptr<video::IGPUBuffer>&& _initialTimestampBuffer,
536-
core::smart_refctd_ptr<video::IGPUBuffer>&& _debugIndexBuffer
504+
core::smart_refctd_ptr<video::IGPUBuffer>&& _initialTimestampBuffer
537505
) : m_device(std::move(_device)), m_cacheUpdate(std::move(_cacheUpdate)),
538506
m_debugDrawRenderpassIndependent(std::move(_debugDrawRenderpassIndependent)),
539507
m_initialTimestampBuffer(std::move(_initialTimestampBuffer)),
540-
m_debugIndexBuffer(std::move(_debugIndexBuffer)),
508+
m_debugIndexBuffer(ttm->getDebugIndexBuffer()),
541509
m_workgroupSize(m_device->getPhysicalDevice()->getLimits().maxOptimallyResidentWorkgroupInvocations)
542510
{
543511
}
@@ -552,8 +520,7 @@ class ISkinInstanceCacheManager : public virtual core::IReferenceCounted
552520
const uint32_t m_workgroupSize;
553521

554522
core::smart_refctd_ptr<video::IGPURenderpassIndependentPipeline> m_debugDrawRenderpassIndependent;
555-
core::smart_refctd_ptr<video::IGPUBuffer> m_debugIndexBuffer;
556-
constexpr static inline auto IndexCount = 24u;
523+
core::smart_refctd_ptr<const video::IGPUBuffer> m_debugIndexBuffer;
557524
};
558525

559526
} // end namespace nbl::scene

include/nbl/scene/ITransformTreeManager.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class ITransformTreeManager : public virtual core::IReferenceCounted
137137
}
138138
auto defaultFillValues = utils->createFilledDeviceLocalGPUBufferOnDedMem(uploadQueue,tmp.size(),fillData);
139139
defaultFillValues->setObjectDebugName("ITransformTreeManager::m_defaultFillValues");
140-
tmp.resize(sizeof(uint16_t)*IndexCount);
140+
tmp.resize(sizeof(uint16_t)*DebugIndexCount);
141141
uint16_t* debugIndices = reinterpret_cast<uint16_t*>(tmp.data());
142142
{
143143
std::fill_n(debugIndices,24u,0u);
@@ -701,6 +701,12 @@ class ITransformTreeManager : public virtual core::IReferenceCounted
701701
}
702702

703703

704+
constexpr static inline auto DebugAABBIndices = 24u;
705+
constexpr static inline auto DebugLineIndices = 2u;
706+
constexpr static inline auto DebugIndexCount = DebugAABBIndices + DebugLineIndices;
707+
//
708+
inline const video::IGPUBuffer* getDebugIndexBuffer() const { return m_debugIndexBuffer.get(); }
709+
704710
static inline constexpr uint32_t DebugNodeIDAttributeIndex = 14u;
705711
static inline constexpr uint32_t DebugAABBIDAttributeIndex = 15u;
706712
static inline constexpr uint32_t DebugNodeIDBindingIndex = DebugNodeIDAttributeIndex;
@@ -752,7 +758,7 @@ class ITransformTreeManager : public virtual core::IReferenceCounted
752758
}
753759
cmdbuf->bindIndexBuffer(m_debugIndexBuffer.get(),0u,asset::EIT_16BIT);
754760
cmdbuf->pushConstants(layout,asset::ISpecializedShader::ESS_VERTEX,0u,sizeof(DebugPushConstants),&pushConstants);
755-
cmdbuf->drawIndexed(IndexCount,count,0u,0u,0u);
761+
cmdbuf->drawIndexed(DebugIndexCount,count,0u,0u,0u);
756762
}
757763

758764
//
@@ -926,9 +932,6 @@ class ITransformTreeManager : public virtual core::IReferenceCounted
926932
const uint32_t m_workgroupSize;
927933

928934
core::smart_refctd_ptr<video::IGPUBuffer> m_debugIndexBuffer;
929-
constexpr static inline auto AABBIndices = 24u;
930-
constexpr static inline auto LineIndices = 2u;
931-
constexpr static inline auto IndexCount = AABBIndices+LineIndices;
932935

933936

934937
};

0 commit comments

Comments
 (0)