Skip to content

Commit fdd675b

Browse files
committed
create pipelineLayout util can takes mode, also create layout if missing in params struct
1 parent f0f9957 commit fdd675b

File tree

2 files changed

+24
-27
lines changed

2 files changed

+24
-27
lines changed

include/nbl/ext/DebugDraw/CDrawAABB.h

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,18 @@ namespace nbl::ext::debug_draw
5252

5353
inline bool validate() const
5454
{
55-
const auto validation = std::to_array
56-
({
57-
std::make_pair(bool(assetManager), "Invalid `creationParams.assetManager` is nullptr!"),
58-
std::make_pair(bool(assetManager->getSystem()), "Invalid `creationParams.assetManager->getSystem()` is nullptr!"),
59-
std::make_pair(bool(utilities), "Invalid `creationParams.utilities` is nullptr!"),
60-
std::make_pair(bool(transfer), "Invalid `creationParams.transfer` is nullptr!"),
61-
std::make_pair(bool(renderpass), "Invalid `creationParams.renderpass` is nullptr!"),
62-
(assetManager && utilities && transfer && renderpass) ? std::make_pair(bool(utilities->getLogicalDevice()->getPhysicalDevice()->getQueueFamilyProperties()[transfer->getFamilyIndex()].queueFlags.hasFlags(video::IQueue::FAMILY_FLAGS::TRANSFER_BIT)), "Invalid `creationParams.transfer` is not capable of transfer operations!") : std::make_pair(false, "Pass valid required DrawAABB::S_CREATION_PARAMETERS!")
63-
});
55+
assert(bool(assetManager));
56+
assert(bool(assetManager->getSystem()));
57+
assert(bool(utilities));
58+
assert(bool(transfer));
59+
assert(bool(renderpass));
6460

6561
system::logger_opt_ptr logger = utilities->getLogger();
66-
for (const auto& [ok, error] : validation)
67-
if (!ok)
68-
{
69-
logger.log(error, system::ILogger::ELL_ERROR);
70-
return false;
71-
}
62+
if (!bool(utilities->getLogicalDevice()->getPhysicalDevice()->getQueueFamilyProperties()[transfer->getFamilyIndex()].queueFlags.hasFlags(video::IQueue::FAMILY_FLAGS::TRANSFER_BIT)))
63+
{
64+
logger.log("Invalid `creationParams.transfer` is not capable of transfer operations!", system::ILogger::ELL_ERROR);
65+
return false;
66+
}
7267

7368
return true;
7469
}
@@ -80,8 +75,8 @@ namespace nbl::ext::debug_draw
8075
// creates pipeline layout from push constant range
8176
static core::smart_refctd_ptr<video::IGPUPipelineLayout> createPipelineLayoutFromPCRange(video::ILogicalDevice* device, const asset::SPushConstantRange& pcRange);
8277

83-
// creates default pipeline layout for streaming version
84-
static core::smart_refctd_ptr<video::IGPUPipelineLayout> createDefaultPipelineLayout(video::ILogicalDevice* device);
78+
// creates default pipeline layout for pipeline specified by draw mode (note: if mode==BOTH, returns layout for BATCH mode)
79+
static core::smart_refctd_ptr<video::IGPUPipelineLayout> createDefaultPipelineLayout(video::ILogicalDevice* device, DrawMode mode = ADM_DRAW_BATCH);
8580

8681
//! mounts the extension's archive to given system - useful if you want to create your own shaders with common header included
8782
static const core::smart_refctd_ptr<system::IFileArchive> mount(core::smart_refctd_ptr<system::ILogger> logger, system::ISystem* system, const std::string_view archiveAlias = "");

src/nbl/ext/DebugDraw/CDrawAABB.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ core::smart_refctd_ptr<DrawAABB> DrawAABB::create(SCreationParameters&& params)
3131
smart_refctd_ptr<IGPUGraphicsPipeline> singlePipeline = nullptr;
3232
if (params.drawMode & ADM_DRAW_SINGLE)
3333
{
34-
singlePipeline = createPipeline(params, params.singlePipelineLayout.get(), "single.vertex.hlsl", "aabb_instances.fragment.hlsl");
34+
auto pipelineLayout = params.singlePipelineLayout;
35+
if (!pipelineLayout)
36+
pipelineLayout = createDefaultPipelineLayout(params.utilities->getLogicalDevice(), ADM_DRAW_SINGLE);
37+
singlePipeline = createPipeline(params, pipelineLayout.get(), "single.vertex.hlsl", "aabb_instances.fragment.hlsl");
3538
if (!singlePipeline)
3639
{
3740
logger->log("Failed to create pipeline!", ILogger::ELL_ERROR);
@@ -42,7 +45,10 @@ core::smart_refctd_ptr<DrawAABB> DrawAABB::create(SCreationParameters&& params)
4245
smart_refctd_ptr<IGPUGraphicsPipeline> batchPipeline = nullptr;
4346
if (params.drawMode & ADM_DRAW_BATCH)
4447
{
45-
batchPipeline = createPipeline(params, params.batchPipelineLayout.get(), "aabb_instances.vertex.hlsl", "aabb_instances.fragment.hlsl");
48+
auto pipelineLayout = params.batchPipelineLayout;
49+
if (!pipelineLayout)
50+
pipelineLayout = createDefaultPipelineLayout(params.utilities->getLogicalDevice(), ADM_DRAW_BATCH);
51+
batchPipeline = createPipeline(params, pipelineLayout.get(), "aabb_instances.vertex.hlsl", "aabb_instances.fragment.hlsl");
4652
if (!batchPipeline)
4753
{
4854
logger->log("Failed to create pipeline!", ILogger::ELL_ERROR);
@@ -287,14 +293,15 @@ core::smart_refctd_ptr<video::IGPUPipelineLayout> DrawAABB::createPipelineLayout
287293
return device->createPipelineLayout({ &pcRange , 1 }, nullptr, nullptr, nullptr, nullptr);
288294
}
289295

290-
core::smart_refctd_ptr<video::IGPUPipelineLayout> DrawAABB::createDefaultPipelineLayout(video::ILogicalDevice* device)
296+
core::smart_refctd_ptr<video::IGPUPipelineLayout> DrawAABB::createDefaultPipelineLayout(video::ILogicalDevice* device, DrawMode mode)
291297
{
298+
const uint32_t pcSize = (mode & ADM_DRAW_BATCH) ? sizeof(SPushConstants) : sizeof(SSinglePushConstants);
292299
SPushConstantRange pcRange = {
293300
.stageFlags = IShader::E_SHADER_STAGE::ESS_VERTEX,
294301
.offset = 0,
295-
.size = sizeof(SPushConstants)
302+
.size = pcSize
296303
};
297-
return device->createPipelineLayout({ &pcRange , 1 }, nullptr, nullptr, nullptr, nullptr);
304+
return createPipelineLayoutFromPCRange(device, pcRange);
298305
}
299306

300307
bool DrawAABB::renderSingle(IGPUCommandBuffer* commandBuffer, const hlsl::shapes::AABB<3, float>& aabb, const hlsl::float32_t4& color, const hlsl::float32_t4x4& cameraMat)
@@ -322,11 +329,6 @@ bool DrawAABB::renderSingle(IGPUCommandBuffer* commandBuffer, const hlsl::shapes
322329
return true;
323330
}
324331

325-
//bool DrawAABB::render(IGPUCommandBuffer* commandBuffer, ISemaphore::SWaitInfo waitInfo, std::span<const InstanceData> aabbInstances, const hlsl::float32_t4x4& cameraMat)
326-
//{
327-
//
328-
//}
329-
330332
hlsl::float32_t4x4 DrawAABB::getTransformFromAABB(const hlsl::shapes::AABB<3, float>& aabb)
331333
{
332334
const auto diagonal = aabb.getExtent();

0 commit comments

Comments
 (0)