Skip to content

Commit 2d52920

Browse files
committed
Merge branch 'commonAPIUtils' into danylo_system
# Conflicts: # include/nbl/system/CAPKResourcesArchive.h # include/nbl/system/ISystem.h
2 parents c03fd26 + bad7131 commit 2d52920

File tree

4 files changed

+93
-80
lines changed

4 files changed

+93
-80
lines changed

examples_tests/common/CommonAPI.h

Lines changed: 87 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ class CommonAPI
359359

360360
void onMouseConnected_impl(nbl::core::smart_refctd_ptr<nbl::ui::IMouseEventChannel>&& mch) override
361361
{
362-
m_logger.log("A mouse %p has been connected", nbl::system::ILogger::ELL_INFO, mch);
362+
m_logger.log("A mouse %p has been connected", nbl::system::ILogger::ELL_INFO, mch.get());
363363
m_inputSystem.get()->add(m_inputSystem.get()->m_mouse,std::move(mch));
364364
}
365365
void onMouseDisconnected_impl(nbl::ui::IMouseEventChannel* mch) override
@@ -369,7 +369,7 @@ class CommonAPI
369369
}
370370
void onKeyboardConnected_impl(nbl::core::smart_refctd_ptr<nbl::ui::IKeyboardEventChannel>&& kbch) override
371371
{
372-
m_logger.log("A keyboard %p has been connected", nbl::system::ILogger::ELL_INFO, kbch);
372+
m_logger.log("A keyboard %p has been connected", nbl::system::ILogger::ELL_INFO, kbch.get());
373373
m_inputSystem.get()->add(m_inputSystem.get()->m_keyboard,std::move(kbch));
374374
}
375375
void onKeyboardDisconnected_impl(nbl::ui::IKeyboardEventChannel* kbch) override
@@ -682,6 +682,7 @@ class CommonAPI
682682
#endif
683683
}
684684

685+
template<bool gpuInit = true>
685686
static void Init(InitOutput<0>& result, nbl::video::E_API_TYPE api_type, const std::string_view app_name)
686687
{
687688
using namespace nbl;
@@ -695,91 +696,103 @@ class CommonAPI
695696
#endif
696697
result.inputSystem = nbl::core::make_smart_refctd_ptr<InputSystem>(system::logger_opt_smart_ptr(nbl::core::smart_refctd_ptr(result.logger)));
697698

698-
if(api_type == EAT_VULKAN)
699-
{
700-
result.apiConnection = nbl::video::CVulkanConnection::create(nbl::core::smart_refctd_ptr(result.system), 0, app_name.data(), true);
701-
}
702-
else if(api_type == EAT_OPENGL)
699+
if constexpr (gpuInit)
703700
{
704-
result.apiConnection = nbl::video::COpenGLConnection::create(nbl::core::smart_refctd_ptr(result.system), 0, app_name.data(), nbl::video::COpenGLDebugCallback(nbl::core::smart_refctd_ptr(result.logger)));
705-
}
706-
else if(api_type == EAT_OPENGL_ES)
707-
{
708-
result.apiConnection = nbl::video::COpenGLESConnection::create(nbl::core::smart_refctd_ptr(result.system), 0, app_name.data(), nbl::video::COpenGLDebugCallback(nbl::core::smart_refctd_ptr(result.logger)));
709-
}
710-
else
711-
{
712-
_NBL_TODO();
713-
}
701+
if (api_type == EAT_VULKAN)
702+
{
703+
result.apiConnection = nbl::video::CVulkanConnection::create(nbl::core::smart_refctd_ptr(result.system), 0, app_name.data(), true);
704+
}
705+
else if (api_type == EAT_OPENGL)
706+
{
707+
result.apiConnection = nbl::video::COpenGLConnection::create(nbl::core::smart_refctd_ptr(result.system), 0, app_name.data(), nbl::video::COpenGLDebugCallback(nbl::core::smart_refctd_ptr(result.logger)));
708+
}
709+
else if (api_type == EAT_OPENGL_ES)
710+
{
711+
result.apiConnection = nbl::video::COpenGLESConnection::create(nbl::core::smart_refctd_ptr(result.system), 0, app_name.data(), nbl::video::COpenGLDebugCallback(nbl::core::smart_refctd_ptr(result.logger)));
712+
}
713+
else
714+
{
715+
_NBL_TODO();
716+
}
714717

715-
auto gpus = result.apiConnection->getPhysicalDevices();
716-
assert(!gpus.empty());
717-
auto extractedInfos = extractGPUInfos(gpus, nullptr);
718-
auto suitableGPUIndex = findSuitableGPU(extractedInfos, false);
719-
auto gpu = gpus.begin()[suitableGPUIndex];
718+
auto gpus = result.apiConnection->getPhysicalDevices();
719+
assert(!gpus.empty());
720+
auto extractedInfos = extractGPUInfos(gpus, nullptr);
721+
auto suitableGPUIndex = findSuitableGPU(extractedInfos, false);
722+
auto gpu = gpus.begin()[suitableGPUIndex];
720723

721-
const auto& gpuInfo = extractedInfos[suitableGPUIndex];
724+
const auto& gpuInfo = extractedInfos[suitableGPUIndex];
722725

723-
float queuePriority = 1.f;
724-
constexpr uint32_t MaxQueueCount = 4;
725-
nbl::video::ILogicalDevice::SQueueCreationParams qcp[MaxQueueCount] = {};
726-
727-
uint32_t actualQueueCount = 1;
728-
uint32_t mainQueueFamilyIndex = QueueFamilyProps::InvalidIndex;
729-
mainQueueFamilyIndex = gpuInfo.queueFamilyProps.compute.index;
726+
float queuePriority = 1.f;
727+
constexpr uint32_t MaxQueueCount = 4;
728+
nbl::video::ILogicalDevice::SQueueCreationParams qcp[MaxQueueCount] = {};
730729

731-
qcp[0].familyIndex = mainQueueFamilyIndex;
732-
qcp[0].count = 1u;
733-
qcp[0].flags = static_cast<nbl::video::IGPUQueue::E_CREATE_FLAGS>(0);
734-
qcp[0].priorities = &queuePriority;
730+
uint32_t actualQueueCount = 1;
731+
uint32_t mainQueueFamilyIndex = QueueFamilyProps::InvalidIndex;
732+
mainQueueFamilyIndex = gpuInfo.queueFamilyProps.compute.index;
735733

736-
if(qcp[0].familyIndex != gpuInfo.queueFamilyProps.compute.index)
737-
{
738-
qcp[actualQueueCount].flags = static_cast<nbl::video::IGPUQueue::E_CREATE_FLAGS>(0);
739-
qcp[actualQueueCount].familyIndex = gpuInfo.queueFamilyProps.compute.index;
740-
qcp[actualQueueCount].count = 1u;
741-
qcp[actualQueueCount].priorities = &queuePriority;
742-
actualQueueCount++;
743-
}
744-
if(gpuInfo.queueFamilyProps.transfer.index != gpuInfo.queueFamilyProps.compute.index && gpuInfo.queueFamilyProps.transfer.index != gpuInfo.queueFamilyProps.graphics.index)
745-
{
746-
qcp[actualQueueCount].flags = static_cast<nbl::video::IGPUQueue::E_CREATE_FLAGS>(0);
747-
qcp[actualQueueCount].familyIndex = gpuInfo.queueFamilyProps.transfer.index;
748-
qcp[actualQueueCount].count = 1u;
749-
qcp[actualQueueCount].priorities = &queuePriority;
750-
actualQueueCount++;
751-
}
734+
qcp[0].familyIndex = mainQueueFamilyIndex;
735+
qcp[0].count = 1u;
736+
qcp[0].flags = static_cast<nbl::video::IGPUQueue::E_CREATE_FLAGS>(0);
737+
qcp[0].priorities = &queuePriority;
752738

753-
nbl::video::ILogicalDevice::SCreationParams dev_params;
754-
dev_params.queueParamsCount = actualQueueCount;
755-
dev_params.queueParams = qcp;
756-
result.logicalDevice = gpu->createLogicalDevice(dev_params);
739+
if (qcp[0].familyIndex != gpuInfo.queueFamilyProps.compute.index)
740+
{
741+
qcp[actualQueueCount].flags = static_cast<nbl::video::IGPUQueue::E_CREATE_FLAGS>(0);
742+
qcp[actualQueueCount].familyIndex = gpuInfo.queueFamilyProps.compute.index;
743+
qcp[actualQueueCount].count = 1u;
744+
qcp[actualQueueCount].priorities = &queuePriority;
745+
actualQueueCount++;
746+
}
747+
if (gpuInfo.queueFamilyProps.transfer.index != gpuInfo.queueFamilyProps.compute.index && gpuInfo.queueFamilyProps.transfer.index != gpuInfo.queueFamilyProps.graphics.index)
748+
{
749+
qcp[actualQueueCount].flags = static_cast<nbl::video::IGPUQueue::E_CREATE_FLAGS>(0);
750+
qcp[actualQueueCount].familyIndex = gpuInfo.queueFamilyProps.transfer.index;
751+
qcp[actualQueueCount].count = 1u;
752+
qcp[actualQueueCount].priorities = &queuePriority;
753+
actualQueueCount++;
754+
}
757755

758-
result.utilities = nbl::core::make_smart_refctd_ptr<nbl::video::IUtilities>(nbl::core::smart_refctd_ptr(result.logicalDevice));
759-
760-
result.mainQueue = result.logicalDevice->getQueue(mainQueueFamilyIndex, 0);
761-
result.queues[InitOutput<0>::EQT_COMPUTE] = result.logicalDevice->getQueue(gpuInfo.queueFamilyProps.compute.index, 0);
762-
result.queues[InitOutput<0>::EQT_TRANSFER_UP] = result.logicalDevice->getQueue(gpuInfo.queueFamilyProps.transfer.index, 0);
763-
result.queues[InitOutput<0>::EQT_TRANSFER_DOWN] = result.logicalDevice->getQueue(gpuInfo.queueFamilyProps.transfer.index, 0);
756+
nbl::video::ILogicalDevice::SCreationParams dev_params;
757+
dev_params.queueParamsCount = actualQueueCount;
758+
dev_params.queueParams = qcp;
759+
result.logicalDevice = gpu->createLogicalDevice(dev_params);
764760

765-
result.renderpass = createRenderpass(result.logicalDevice, asset::EF_B8G8R8A8_UNORM, asset::EF_UNKNOWN);
761+
result.utilities = nbl::core::make_smart_refctd_ptr<nbl::video::IUtilities>(nbl::core::smart_refctd_ptr(result.logicalDevice));
766762

767-
result.commandPool = result.logicalDevice->createCommandPool(mainQueueFamilyIndex, IGPUCommandPool::ECF_RESET_COMMAND_BUFFER_BIT);
768-
assert(result.commandPool);
769-
result.physicalDevice = gpu;
763+
result.mainQueue = result.logicalDevice->getQueue(mainQueueFamilyIndex, 0);
764+
result.queues[InitOutput<0>::EQT_COMPUTE] = result.logicalDevice->getQueue(gpuInfo.queueFamilyProps.compute.index, 0);
765+
result.queues[InitOutput<0>::EQT_TRANSFER_UP] = result.logicalDevice->getQueue(gpuInfo.queueFamilyProps.transfer.index, 0);
766+
result.queues[InitOutput<0>::EQT_TRANSFER_DOWN] = result.logicalDevice->getQueue(gpuInfo.queueFamilyProps.transfer.index, 0);
770767

771-
result.assetManager = nbl::core::make_smart_refctd_ptr<nbl::asset::IAssetManager>(nbl::core::smart_refctd_ptr(result.system)); // we should let user choose it?
768+
result.renderpass = createRenderpass(result.logicalDevice, asset::EF_B8G8R8A8_UNORM, asset::EF_UNKNOWN);
772769

773-
result.cpu2gpuParams.assetManager = result.assetManager.get();
774-
result.cpu2gpuParams.device = result.logicalDevice.get();
775-
result.cpu2gpuParams.finalQueueFamIx = mainQueueFamilyIndex;
776-
result.cpu2gpuParams.limits = result.physicalDevice->getLimits();
777-
result.cpu2gpuParams.pipelineCache = nullptr;
778-
result.cpu2gpuParams.sharingMode = nbl::asset::ESM_EXCLUSIVE;
779-
result.cpu2gpuParams.utilities = result.utilities.get();
770+
result.commandPool = result.logicalDevice->createCommandPool(mainQueueFamilyIndex, IGPUCommandPool::ECF_RESET_COMMAND_BUFFER_BIT);
771+
assert(result.commandPool);
772+
result.physicalDevice = gpu;
773+
774+
result.cpu2gpuParams.device = result.logicalDevice.get();
775+
result.cpu2gpuParams.finalQueueFamIx = mainQueueFamilyIndex;
776+
result.cpu2gpuParams.limits = result.physicalDevice->getLimits();
777+
result.cpu2gpuParams.pipelineCache = nullptr;
778+
result.cpu2gpuParams.sharingMode = nbl::asset::ESM_EXCLUSIVE;
779+
result.cpu2gpuParams.utilities = result.utilities.get();
780+
781+
result.cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_TRANSFER].queue = result.queues[InitOutput<0>::EQT_TRANSFER_UP];
782+
result.cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_COMPUTE].queue = result.queues[InitOutput<0>::EQT_COMPUTE];
783+
}
784+
else
785+
{
786+
result.cpu2gpuParams.device = nullptr;
787+
result.cpu2gpuParams.finalQueueFamIx = 0u;
788+
result.cpu2gpuParams.limits = {};
789+
result.cpu2gpuParams.pipelineCache = nullptr;
790+
result.cpu2gpuParams.sharingMode = nbl::asset::ESM_EXCLUSIVE;
791+
result.cpu2gpuParams.utilities = nullptr;
792+
}
780793

781-
result.cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_TRANSFER].queue = result.queues[InitOutput<0>::EQT_TRANSFER_UP];
782-
result.cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_COMPUTE].queue = result.queues[InitOutput<0>::EQT_COMPUTE];
794+
result.assetManager = nbl::core::make_smart_refctd_ptr<nbl::asset::IAssetManager>(nbl::core::smart_refctd_ptr(result.system)); // we should let user choose it?
795+
result.cpu2gpuParams.assetManager = result.assetManager.get();
783796
}
784797

785798
static auto createFBOWithSwapchainImages(uint32_t imageCount, uint32_t width, uint32_t height,

include/nbl/system/CApplicationAndroid.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ namespace nbl::system
2020
protected:
2121
virtual void onStateSaved_impl(android_app* params) {}
2222
bool paused = false;
23-
bool initialized = false;
23+
/* bool initialized = false;*/
2424
android_app* m_app;
2525
JNIEnv* m_env;
2626
public:
2727
void pause() { paused = true; }
2828
void resume() { paused = false; }
29-
void initialize() { initialized = true; }
30-
bool isInitialized() const { return initialized; }
29+
//void initialize() { initialized = true; }
30+
//bool isInitialized() const { return initialized; }
3131
bool isPaused() const { return paused; }
3232
android_app* getApp() { return m_app; }
3333
struct SSavedState {
@@ -73,11 +73,11 @@ namespace nbl::system
7373
break;
7474
case APP_CMD_INIT_WINDOW:
7575
{
76-
if (!framework->isInitialized())
76+
/* if (!framework->isInitialized())
7777
{
7878
framework->onAppInitialized();
7979
framework->initialize();
80-
}
80+
}*/
8181

8282
}
8383
break;

include/nbl/system/IFileArchive.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class CInnerArchiveFile : public CFileView<T>
5050
static void operator delete[](void* ptr) noexcept
5151
{
5252
assert(false);
53-
return nullptr;
5453
}
5554
};
5655

include/nbl/ui/CGraphicalApplicationAndroid.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ namespace nbl::ui
114114
//if (app->savedState != nullptr) {
115115
// ctx.state = (nbl::system::CApplicationAndroid::SSavedState*)app->savedState;
116116
//}
117+
framework->onAppInitialized();
117118
android_poll_source* source;
118119
int ident;
119120
int events;

0 commit comments

Comments
 (0)