-
Notifications
You must be signed in to change notification settings - Fork 66
New debug draw extension for AABBs #900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
865e606
ca86128
0ae3da2
cd2ef95
fe55bd7
98ccfb2
a755514
473592b
f68f9c5
daf34e0
33692fd
72e3569
5285e78
328aa34
a14c9dc
9a35c9f
c6bd10b
1cb4c14
31e93f0
e5ceb1b
fe0a438
bfa233f
3b67580
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
+7 −0 | 12_MeshLoaders/CMakeLists.txt | |
+118 −68 | 12_MeshLoaders/main.cpp | |
+11 −0 | 34_DebugDraw/CMakeLists.txt | |
+28 −0 | 34_DebugDraw/config.json.template | |
+23 −0 | 34_DebugDraw/include/common.hpp | |
+413 −0 | 34_DebugDraw/main.cpp | |
+50 −0 | 34_DebugDraw/pipeline.groovy | |
+2 −0 | CMakeLists.txt |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright (C) 2018-2025 - DevSH Graphics Programming Sp. z O.O. | ||
// This file is part of the "Nabla Engine". | ||
// For conditions of distribution and use, see copyright notice in nabla.h | ||
|
||
#ifndef _NBL_EXT_DRAW_AABB_H_ | ||
#define _NBL_EXT_DRAW_AABB_H_ | ||
|
||
#include "nbl/video/declarations.h" | ||
#include "nbl/builtin/hlsl/cpp_compat.hlsl" | ||
#include "nbl/builtin/hlsl/shapes/aabb.hlsl" | ||
#include "nbl/ext/DebugDraw/builtin/hlsl/common.hlsl" | ||
|
||
namespace nbl::ext::debug_draw | ||
{ | ||
class DrawAABB final : public core::IReferenceCounted | ||
{ | ||
public: | ||
static constexpr inline uint32_t IndicesCount = 24u; | ||
static constexpr inline uint32_t VerticesCount = 8u; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused variable, yeet it |
||
|
||
enum DrawMode : uint16_t | ||
{ | ||
ADM_DRAW_SINGLE = 0b01, | ||
ADM_DRAW_BATCH = 0b10, | ||
ADM_DRAW_BOTH = 0b11 | ||
}; | ||
|
||
struct SCachedCreationParameters | ||
{ | ||
using streaming_buffer_t = video::StreamingTransientDataBufferST<core::allocator<uint8_t>>; | ||
|
||
static constexpr inline auto RequiredAllocateFlags = core::bitflag<video::IDeviceMemoryAllocation::E_MEMORY_ALLOCATE_FLAGS>(video::IDeviceMemoryAllocation::EMAF_DEVICE_ADDRESS_BIT); | ||
static constexpr inline auto RequiredUsageFlags = core::bitflag(asset::IBuffer::EUF_STORAGE_BUFFER_BIT) | asset::IBuffer::EUF_SHADER_DEVICE_ADDRESS_BIT; | ||
|
||
DrawMode drawMode = ADM_DRAW_BOTH; | ||
|
||
core::smart_refctd_ptr<video::IUtilities> utilities; | ||
|
||
//! optional, default MDI buffer allocated if not provided | ||
core::smart_refctd_ptr<streaming_buffer_t> streamingBuffer = nullptr; | ||
}; | ||
|
||
struct SCreationParameters : SCachedCreationParameters | ||
{ | ||
video::IQueue* transfer = nullptr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment that its only needed to make the 24 element index buffer and not used for anything later |
||
core::smart_refctd_ptr<asset::IAssetManager> assetManager = nullptr; | ||
|
||
core::smart_refctd_ptr<video::IGPUPipelineLayout> singlePipelineLayout; | ||
core::smart_refctd_ptr<video::IGPUPipelineLayout> batchPipelineLayout; | ||
core::smart_refctd_ptr<video::IGPURenderpass> renderpass = nullptr; | ||
}; | ||
|
||
// creates an instance that can draw one AABB via push constant or multiple using streaming buffer | ||
static core::smart_refctd_ptr<DrawAABB> create(SCreationParameters&& params); | ||
|
||
// creates pipeline layout from push constant range | ||
static core::smart_refctd_ptr<video::IGPUPipelineLayout> createPipelineLayoutFromPCRange(video::ILogicalDevice* device, const asset::SPushConstantRange& pcRange); | ||
|
||
// creates default pipeline layout for streaming version | ||
static core::smart_refctd_ptr<video::IGPUPipelineLayout> createDefaultPipelineLayout(video::ILogicalDevice* device); | ||
|
||
//! mounts the extension's archive to given system - useful if you want to create your own shaders with common header included | ||
static const core::smart_refctd_ptr<system::IFileArchive> mount(core::smart_refctd_ptr<system::ILogger> logger, system::ISystem* system, const std::string_view archiveAlias = ""); | ||
devshgraphicsprogramming marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
inline const SCachedCreationParameters& getCreationParameters() const { return m_cachedCreationParams; } | ||
|
||
// records draw command for single AABB, user has to set pipeline outside | ||
bool renderSingle(video::IGPUCommandBuffer* commandBuffer, const hlsl::shapes::AABB<3, float>& aabb, const hlsl::float32_t4& color, const hlsl::float32_t4x4& cameraMat); | ||
|
||
bool render(video::IGPUCommandBuffer* commandBuffer, video::ISemaphore::SWaitInfo waitInfo, std::span<const InstanceData> aabbInstances, const hlsl::float32_t4x4& cameraMat); | ||
|
||
static hlsl::float32_t4x4 getTransformFromAABB(const hlsl::shapes::AABB<3, float>& aabb); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. docs please for this, also make it inline |
||
|
||
protected: | ||
DrawAABB(SCreationParameters&& _params, core::smart_refctd_ptr<video::IGPUGraphicsPipeline> singlePipeline, core::smart_refctd_ptr<video::IGPUGraphicsPipeline> batchPipeline, | ||
core::smart_refctd_ptr<video::IGPUBuffer> indicesBuffer); | ||
~DrawAABB() override; | ||
|
||
private: | ||
static bool validateCreationParameters(SCreationParameters& params); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make it an |
||
static core::smart_refctd_ptr<video::IGPUGraphicsPipeline> createPipeline(SCreationParameters& params, const video::IGPUPipelineLayout* pipelineLayout, const std::string& vsPath, const std::string& fsPath); | ||
static bool createStreamingBuffer(SCreationParameters& params); | ||
static core::smart_refctd_ptr<video::IGPUBuffer> createIndicesBuffer(SCreationParameters& params); | ||
|
||
core::smart_refctd_ptr<video::IGPUBuffer> m_indicesBuffer; | ||
|
||
SCachedCreationParameters m_cachedCreationParams; | ||
|
||
core::smart_refctd_ptr<video::IGPUGraphicsPipeline> m_singlePipeline; | ||
core::smart_refctd_ptr<video::IGPUGraphicsPipeline> m_batchPipeline; | ||
}; | ||
} | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma shader_stage(fragment) | ||
|
||
#include "nbl/ext/DebugDraw/builtin/hlsl/common.hlsl" | ||
|
||
using namespace nbl::ext::debug_draw; | ||
|
||
[shader("pixel")] | ||
float32_t4 main(PSInput input) : SV_TARGET | ||
{ | ||
float32_t4 outColor = input.color; | ||
|
||
return outColor; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma shader_stage(vertex) | ||
|
||
#include "nbl/builtin/hlsl/math/linalg/fast_affine.hlsl" | ||
#include "nbl/builtin/hlsl/glsl_compat/core.hlsl" | ||
#include "nbl/builtin/hlsl/bda/__ptr.hlsl" | ||
#include "nbl/ext/DebugDraw/builtin/hlsl/common.hlsl" | ||
|
||
using namespace nbl::hlsl; | ||
using namespace nbl::ext::debug_draw; | ||
|
||
[[vk::push_constant]] SPushConstants pc; | ||
|
||
[shader("vertex")] | ||
PSInput main() | ||
{ | ||
const float32_t3 unitAABBVertices[8] = { | ||
float32_t3(0.0, 0.0, 0.0), | ||
float32_t3(1.0, 0.0, 0.0), | ||
float32_t3(0.0, 0.0, 1.0), | ||
float32_t3(1.0, 0.0, 1.0), | ||
float32_t3(0.0, 1.0, 0.0), | ||
float32_t3(1.0, 1.0, 0.0), | ||
float32_t3(0.0, 1.0, 1.0), | ||
float32_t3(1.0, 1.0, 1.0) | ||
}; | ||
|
||
PSInput output; | ||
float32_t3 vertex = unitAABBVertices[glsl::gl_VertexIndex()]; | ||
Comment on lines
+16
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its better to use arithmetic for this, e.g. const uint32_t index = glsl::gl_VertexIndex();
cosnt float32_t vertex = (promote<uint32_t3>(index)>>uint32_t(0,2,1)) & 0x1u; Also its slightly annoying that that you took Y coordinate to be more important than Z There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this repeats betwee n the single and multiple draw vertex shader, turn this into a function and slap it in |
||
InstanceData instance = vk::BufferPointer<InstanceData>(pc.pInstanceBuffer + sizeof(InstanceData) * glsl::gl_InstanceIndex()).Get(); | ||
|
||
output.position = math::linalg::promoted_mul(instance.transform, vertex); | ||
output.color = instance.color; | ||
|
||
return output; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#ifndef _NBL_DEBUG_DRAW_EXT_COMMON_HLSL | ||
#define _NBL_DEBUG_DRAW_EXT_COMMON_HLSL | ||
|
||
#include "nbl/builtin/hlsl/cpp_compat.hlsl" | ||
|
||
namespace nbl | ||
{ | ||
namespace ext | ||
{ | ||
namespace debug_draw | ||
{ | ||
|
||
struct InstanceData | ||
{ | ||
hlsl::float32_t4x4 transform; | ||
hlsl::float32_t4 color; | ||
}; | ||
|
||
struct SSinglePushConstants | ||
{ | ||
InstanceData instance; | ||
}; | ||
|
||
struct SPushConstants | ||
{ | ||
uint64_t pInstanceBuffer; | ||
}; | ||
|
||
#ifdef __HLSL_VERSION | ||
struct PSInput | ||
{ | ||
float32_t4 position : SV_Position; | ||
float32_t4 color : TEXCOORD0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are you using HW attributes for color? the color is per-instance There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah these are Vx-Px inter-stage shenanigans, I'll allow, make sure you label color flat though There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. still not labelled as flat interpolation |
||
}; | ||
#endif | ||
|
||
} | ||
} | ||
} | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma shader_stage(vertex) | ||
|
||
#include "nbl/builtin/hlsl/math/linalg/fast_affine.hlsl" | ||
#include "nbl/builtin/hlsl/glsl_compat/core.hlsl" | ||
#include "nbl/builtin/hlsl/bda/__ptr.hlsl" | ||
#include "nbl/ext/DebugDraw/builtin/hlsl/common.hlsl" | ||
|
||
using namespace nbl::hlsl; | ||
using namespace nbl::ext::debug_draw; | ||
|
||
[[vk::push_constant]] SSinglePushConstants pc; | ||
|
||
[shader("vertex")] | ||
PSInput main() | ||
{ | ||
const float32_t3 unitAABBVertices[8] = { | ||
float32_t3(0.0, 0.0, 0.0), | ||
float32_t3(1.0, 0.0, 0.0), | ||
float32_t3(0.0, 0.0, 1.0), | ||
float32_t3(1.0, 0.0, 1.0), | ||
float32_t3(0.0, 1.0, 0.0), | ||
float32_t3(1.0, 1.0, 0.0), | ||
float32_t3(0.0, 1.0, 1.0), | ||
float32_t3(1.0, 1.0, 1.0) | ||
}; | ||
|
||
PSInput output; | ||
float32_t3 vertex = unitAABBVertices[glsl::gl_VertexIndex()]; | ||
|
||
output.position = math::linalg::promoted_mul(pc.instance.transform, vertex); | ||
output.color = pc.instance.color; | ||
|
||
return output; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ class NBL_API2 ISystem : public core::IReferenceCounted | |
// | ||
virtual inline bool isDirectory(const system::path& p) const | ||
{ | ||
// TODO: fix bug, input "nbl/ext/DebugDraw/builtin/hlsl" -> returs true when no such dir present in mounted stuff due to how it uses parent paths in loop (goes up up till matches "nbl" builtin archive and thinks it resolved the requested dir) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AnastaZIuk open an issue about it |
||
if (isPathReadOnly(p)) | ||
return p.extension()==""; // TODO: this is a temporary decision until we figure out how to check if a file is directory in android APK | ||
else | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
full header guard