Skip to content

Commit 3840d5e

Browse files
author
devsh
committed
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla
2 parents 4cf7ff5 + e2e8d38 commit 3840d5e

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

include/nbl/ext/ImGui/ImGui.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class UI final : public core::IReferenceCounted
4848
//! required, fill the info to instruct the backend about the required UI resources
4949
SBindingInfo texturesInfo, samplersInfo;
5050

51+
uint32_t getTexturesCount() const { return texturesCount; }
52+
uint32_t getSamplersCount() const { return samplersCount; }
53+
5154
private:
5255
uint32_t texturesCount = {}, samplersCount = {};
5356

tools/nite/main.cpp

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#include <nabla.h>
77
#include "nbl/video/utilities/CSimpleResizeSurface.h"
88

9-
#include "SimpleWindowedApplication.hpp"
10-
#include "CEventCallback.hpp"
9+
#include "nbl/examples/common/SimpleWindowedApplication.hpp"
10+
#include "nbl/examples/common/CEventCallback.hpp"
1111

1212
#include "nbl/ext/ImGui/ImGui.h"
1313
#include "nbl/ui/ICursorControl.h"
@@ -39,6 +39,7 @@ class NITETool final : public examples::SimpleWindowedApplication
3939
static_assert(FRAMES_IN_FLIGHT > SC_IMG_COUNT);
4040

4141
constexpr static inline clock_t::duration DisplayImageDuration = std::chrono::milliseconds(900);
42+
constexpr static inline uint8_t MaxUITextureCount = 1u;
4243

4344
public:
4445
inline NITETool(const path& _localInputCWD, const path& _localOutputCWD, const path& _sharedInputCWD, const path& _sharedOutputCWD)
@@ -49,7 +50,7 @@ class NITETool final : public examples::SimpleWindowedApplication
4950
if (!m_surface)
5051
{
5152
{
52-
auto windowCallback = core::make_smart_refctd_ptr<CEventCallback>(smart_refctd_ptr(m_inputSystem), smart_refctd_ptr(m_logger));
53+
auto windowCallback = core::make_smart_refctd_ptr<examples::CEventCallback>(smart_refctd_ptr(m_inputSystem), smart_refctd_ptr(m_logger));
5354
IWindow::SCreationParams params = {};
5455
params.callback = core::make_smart_refctd_ptr<nbl::video::ISimpleManagedSurface::ICallback>();
5556
params.width = WIN_W;
@@ -107,7 +108,7 @@ class NITETool final : public examples::SimpleWindowedApplication
107108
const auto pModeArg = program.get<std::string>(NBL_MODE_ARG.data());
108109
const auto pGroupArg = program.get<std::string>(NBL_GROUP_ARG.data());
109110

110-
m_inputSystem = make_smart_refctd_ptr<InputSystem>(logger_opt_smart_ptr(smart_refctd_ptr(m_logger)));
111+
m_inputSystem = make_smart_refctd_ptr<examples::InputSystem>(logger_opt_smart_ptr(smart_refctd_ptr(m_logger)));
111112

112113
if (!device_base_t::onAppInitialized(smart_refctd_ptr(m_system)))
113114
return false;
@@ -157,7 +158,7 @@ class NITETool final : public examples::SimpleWindowedApplication
157158
if (!m_surface || !m_surface->init(gQueue, std::move(scResources), swapchainParams.sharedParams))
158159
return logFail("Could not create Window & Surface or initialize the Surface!");
159160

160-
m_maxFramesInFlight = m_surface->getMaxFramesInFlight();
161+
m_maxFramesInFlight = m_surface->getMaxAcquiresInFlight();
161162
if (FRAMES_IN_FLIGHT < m_maxFramesInFlight)
162163
{
163164
m_logger->log("Lowering frames in flight!", ILogger::ELL_WARNING);
@@ -174,26 +175,29 @@ class NITETool final : public examples::SimpleWindowedApplication
174175
return logFail("Couldn't create Command Buffer!");
175176
}
176177

177-
ui.manager = core::make_smart_refctd_ptr<nbl::ext::imgui::UI>
178-
(
179-
nbl::ext::imgui::UI::S_CREATION_PARAMETERS
180-
{
181-
.assetManager = m_assetManager.get(),
182-
.utilities = m_utils.get(),
183-
.transfer = getTransferUpQueue(),
184-
.renderpass = renderpass,
185-
.subpassIx = 0u
186-
}
187-
);
178+
nbl::ext::imgui::UI::SCreationParameters params;
179+
180+
params.resources.texturesInfo = { .setIx = 0u, .bindingIx = 0u };
181+
params.resources.samplersInfo = { .setIx = 0u, .bindingIx = 1u };
182+
params.assetManager = m_assetManager;
183+
params.pipelineCache = nullptr;
184+
params.pipelineLayout = nbl::ext::imgui::UI::createDefaultPipelineLayout(m_utils->getLogicalDevice(), params.resources.texturesInfo, params.resources.samplersInfo, MaxUITextureCount);
185+
params.renderpass = smart_refctd_ptr<IGPURenderpass>(renderpass);
186+
params.streamingBuffer = nullptr;
187+
params.subpassIx = 0u;
188+
params.transfer = getTransferUpQueue();
189+
params.utilities = m_utils;
190+
191+
ui.manager = nbl::ext::imgui::UI::create(std::move(params));
188192

189193
{
190194
// note that we use default layout provided by our extension (textures & samplers -> single set at 0u ix)
191195
const auto* descriptorSetLayout = ui.manager->getPipeline()->getLayout()->getDescriptorSetLayout(0u);
192196
const auto& params = ui.manager->getCreationParameters();
193197

194198
IDescriptorPool::SCreateInfo descriptorPoolInfo = {};
195-
descriptorPoolInfo.maxDescriptorCount[static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_SAMPLER)] = params.resources.count;
196-
descriptorPoolInfo.maxDescriptorCount[static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_SAMPLED_IMAGE)] = params.resources.count;
199+
descriptorPoolInfo.maxDescriptorCount[static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_SAMPLER)] = params.resources.getSamplersCount();
200+
descriptorPoolInfo.maxDescriptorCount[static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_SAMPLED_IMAGE)] = params.resources.getTexturesCount();
197201
descriptorPoolInfo.maxSets = 1u;
198202
descriptorPoolInfo.flags = IDescriptorPool::E_CREATE_FLAGS::ECF_UPDATE_AFTER_BIND_BIT;
199203

@@ -333,7 +337,7 @@ class NITETool final : public examples::SimpleWindowedApplication
333337
const auto uiParams = ui.manager->getCreationParameters();
334338
auto* pipeline = ui.manager->getPipeline();
335339
cb->bindGraphicsPipeline(pipeline);
336-
cb->bindDescriptorSets(EPBP_GRAPHICS, pipeline->getLayout(), uiParams.resources.textures.setIx, 1u, &ui.descriptorSet.get()); // note that we use default UI pipeline layout where uiParams.resources.textures.setIx == uiParams.resources.samplers.setIx
340+
cb->bindDescriptorSets(EPBP_GRAPHICS, pipeline->getLayout(), uiParams.resources.texturesInfo.setIx, 1u, &ui.descriptorSet.get()); // note that we use default UI pipeline layout where uiParams.resources.textures.setIx == uiParams.resources.samplers.setIx
337341
ui.manager->render(cb, waitInfo);
338342
cb->endRenderPass();
339343
}
@@ -470,15 +474,12 @@ class NITETool final : public examples::SimpleWindowedApplication
470474

471475
const auto cursorPosition = m_window->getCursorControl()->getPosition();
472476

473-
nbl::ext::imgui::UI::S_UPDATE_PARAMETERS params =
477+
nbl::ext::imgui::UI::SUpdateParameters params =
474478
{
475479
.mousePosition = nbl::hlsl::float32_t2(cursorPosition.x, cursorPosition.y) - nbl::hlsl::float32_t2(m_window->getX(), m_window->getY()),
476480
.displaySize = { m_window->getWidth(), m_window->getHeight() },
477-
.events =
478-
{
479-
.mouse = core::SRange<const nbl::ui::SMouseEvent>(capturedEvents.mouse.data(), capturedEvents.mouse.data() + capturedEvents.mouse.size()),
480-
.keyboard = core::SRange<const nbl::ui::SKeyboardEvent>(capturedEvents.keyboard.data(), capturedEvents.keyboard.data() + capturedEvents.keyboard.size())
481-
}
481+
.mouseEvents = core::SRange<const nbl::ui::SMouseEvent>(capturedEvents.mouse.data(), capturedEvents.mouse.data() + capturedEvents.mouse.size()),
482+
.keyboardEvents = core::SRange<const nbl::ui::SKeyboardEvent>(capturedEvents.keyboard.data(), capturedEvents.keyboard.data() + capturedEvents.keyboard.size()),
482483
};
483484

484485
ui.manager->update(params);
@@ -502,9 +503,9 @@ class NITETool final : public examples::SimpleWindowedApplication
502503
} ui;
503504

504505
smart_refctd_ptr<nbl::asset::IAssetManager> m_assetManager;
505-
core::smart_refctd_ptr<InputSystem> m_inputSystem;
506-
InputSystem::ChannelReader<IMouseEventChannel> mouse;
507-
InputSystem::ChannelReader<IKeyboardEventChannel> keyboard;
506+
core::smart_refctd_ptr<examples::InputSystem> m_inputSystem;
507+
examples::InputSystem::ChannelReader<IMouseEventChannel> mouse;
508+
examples::InputSystem::ChannelReader<IKeyboardEventChannel> keyboard;
508509

509510
// Test engine
510511
ImGuiTestEngine* engine = nullptr;

0 commit comments

Comments
 (0)