@@ -685,6 +685,7 @@ class CommonAPI
685
685
#endif
686
686
}
687
687
688
+ template <bool gpuInit = true >
688
689
static void Init (InitOutput<0 >& result, nbl::video::E_API_TYPE api_type, const std::string_view app_name)
689
690
{
690
691
using namespace nbl ;
@@ -698,91 +699,103 @@ class CommonAPI
698
699
#endif
699
700
result.inputSystem = nbl::core::make_smart_refctd_ptr<InputSystem>(system::logger_opt_smart_ptr (nbl::core::smart_refctd_ptr (result.logger )));
700
701
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)
702
+ if constexpr (gpuInit)
706
703
{
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
- }
704
+ if (api_type == EAT_VULKAN)
705
+ {
706
+ result.apiConnection = nbl::video::CVulkanConnection::create (nbl::core::smart_refctd_ptr (result.system ), 0 , app_name.data (), true );
707
+ }
708
+ else if (api_type == EAT_OPENGL)
709
+ {
710
+ 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 )));
711
+ }
712
+ else if (api_type == EAT_OPENGL_ES)
713
+ {
714
+ 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 )));
715
+ }
716
+ else
717
+ {
718
+ _NBL_TODO ();
719
+ }
717
720
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];
721
+ auto gpus = result.apiConnection ->getPhysicalDevices ();
722
+ assert (!gpus.empty ());
723
+ auto extractedInfos = extractGPUInfos (gpus, nullptr );
724
+ auto suitableGPUIndex = findSuitableGPU (extractedInfos, false );
725
+ auto gpu = gpus.begin ()[suitableGPUIndex];
723
726
724
- const auto & gpuInfo = extractedInfos[suitableGPUIndex];
727
+ const auto & gpuInfo = extractedInfos[suitableGPUIndex];
725
728
726
- float queuePriority = 1 .f ;
727
- constexpr uint32_t MaxQueueCount = 4 ;
728
- nbl::video::ILogicalDevice::SQueueCreationParams qcp[MaxQueueCount] = {};
729
-
730
- uint32_t actualQueueCount = 1 ;
731
- uint32_t mainQueueFamilyIndex = QueueFamilyProps::InvalidIndex;
732
- mainQueueFamilyIndex = gpuInfo.queueFamilyProps .compute .index ;
729
+ float queuePriority = 1 .f ;
730
+ constexpr uint32_t MaxQueueCount = 4 ;
731
+ nbl::video::ILogicalDevice::SQueueCreationParams qcp[MaxQueueCount] = {};
733
732
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;
733
+ uint32_t actualQueueCount = 1 ;
734
+ uint32_t mainQueueFamilyIndex = QueueFamilyProps::InvalidIndex;
735
+ mainQueueFamilyIndex = gpuInfo.queueFamilyProps .compute .index ;
738
736
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
- }
737
+ qcp[0 ].familyIndex = mainQueueFamilyIndex;
738
+ qcp[0 ].count = 1u ;
739
+ qcp[0 ].flags = static_cast <nbl::video::IGPUQueue::E_CREATE_FLAGS>(0 );
740
+ qcp[0 ].priorities = &queuePriority;
755
741
756
- nbl::video::ILogicalDevice::SCreationParams dev_params;
757
- dev_params.queueParamsCount = actualQueueCount;
758
- dev_params.queueParams = qcp;
759
- result.logicalDevice = gpu->createLogicalDevice (dev_params);
742
+ if (qcp[0 ].familyIndex != gpuInfo.queueFamilyProps .compute .index )
743
+ {
744
+ qcp[actualQueueCount].flags = static_cast <nbl::video::IGPUQueue::E_CREATE_FLAGS>(0 );
745
+ qcp[actualQueueCount].familyIndex = gpuInfo.queueFamilyProps .compute .index ;
746
+ qcp[actualQueueCount].count = 1u ;
747
+ qcp[actualQueueCount].priorities = &queuePriority;
748
+ actualQueueCount++;
749
+ }
750
+ if (gpuInfo.queueFamilyProps .transfer .index != gpuInfo.queueFamilyProps .compute .index && gpuInfo.queueFamilyProps .transfer .index != gpuInfo.queueFamilyProps .graphics .index )
751
+ {
752
+ qcp[actualQueueCount].flags = static_cast <nbl::video::IGPUQueue::E_CREATE_FLAGS>(0 );
753
+ qcp[actualQueueCount].familyIndex = gpuInfo.queueFamilyProps .transfer .index ;
754
+ qcp[actualQueueCount].count = 1u ;
755
+ qcp[actualQueueCount].priorities = &queuePriority;
756
+ actualQueueCount++;
757
+ }
760
758
761
- result.utilities = nbl::core::make_smart_refctd_ptr<nbl::video::IUtilities>(nbl::core::smart_refctd_ptr (result.logicalDevice ));
762
-
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 );
759
+ nbl::video::ILogicalDevice::SCreationParams dev_params;
760
+ dev_params.queueParamsCount = actualQueueCount;
761
+ dev_params.queueParams = qcp;
762
+ result.logicalDevice = gpu->createLogicalDevice (dev_params);
767
763
768
- result.renderpass = createRenderpass (result. logicalDevice , asset::EF_B8G8R8A8_UNORM, asset::EF_UNKNOWN );
764
+ result.utilities = nbl::core::make_smart_refctd_ptr<nbl::video::IUtilities>( nbl::core::smart_refctd_ptr (result. logicalDevice ) );
769
765
770
- result.commandPool = result.logicalDevice ->createCommandPool (mainQueueFamilyIndex, IGPUCommandPool::ECF_RESET_COMMAND_BUFFER_BIT);
771
- assert (result.commandPool );
772
- result.physicalDevice = gpu;
766
+ result.mainQueue = result.logicalDevice ->getQueue (mainQueueFamilyIndex, 0 );
767
+ result.queues [InitOutput<0 >::EQT_COMPUTE] = result.logicalDevice ->getQueue (gpuInfo.queueFamilyProps .compute .index , 0 );
768
+ result.queues [InitOutput<0 >::EQT_TRANSFER_UP] = result.logicalDevice ->getQueue (gpuInfo.queueFamilyProps .transfer .index , 0 );
769
+ result.queues [InitOutput<0 >::EQT_TRANSFER_DOWN] = result.logicalDevice ->getQueue (gpuInfo.queueFamilyProps .transfer .index , 0 );
773
770
774
- result.assetManager = nbl::core::make_smart_refctd_ptr<nbl:: asset::IAssetManager>( nbl::core::smart_refctd_ptr (result. system )); // we should let user choose it?
771
+ result.renderpass = createRenderpass (result. logicalDevice , asset::EF_B8G8R8A8_UNORM, asset::EF_UNKNOWN);
775
772
776
- result.cpu2gpuParams .assetManager = result.assetManager .get ();
777
- result.cpu2gpuParams .device = result.logicalDevice .get ();
778
- result.cpu2gpuParams .finalQueueFamIx = mainQueueFamilyIndex;
779
- result.cpu2gpuParams .limits = result.physicalDevice ->getLimits ();
780
- result.cpu2gpuParams .pipelineCache = nullptr ;
781
- result.cpu2gpuParams .sharingMode = nbl::asset::ESM_EXCLUSIVE;
782
- result.cpu2gpuParams .utilities = result.utilities .get ();
773
+ result.commandPool = result.logicalDevice ->createCommandPool (mainQueueFamilyIndex, IGPUCommandPool::ECF_RESET_COMMAND_BUFFER_BIT);
774
+ assert (result.commandPool );
775
+ result.physicalDevice = gpu;
776
+
777
+ result.cpu2gpuParams .device = result.logicalDevice .get ();
778
+ result.cpu2gpuParams .finalQueueFamIx = mainQueueFamilyIndex;
779
+ result.cpu2gpuParams .limits = result.physicalDevice ->getLimits ();
780
+ result.cpu2gpuParams .pipelineCache = nullptr ;
781
+ result.cpu2gpuParams .sharingMode = nbl::asset::ESM_EXCLUSIVE;
782
+ result.cpu2gpuParams .utilities = result.utilities .get ();
783
+
784
+ result.cpu2gpuParams .perQueue [nbl::video::IGPUObjectFromAssetConverter::EQU_TRANSFER].queue = result.queues [InitOutput<0 >::EQT_TRANSFER_UP];
785
+ result.cpu2gpuParams .perQueue [nbl::video::IGPUObjectFromAssetConverter::EQU_COMPUTE].queue = result.queues [InitOutput<0 >::EQT_COMPUTE];
786
+ }
787
+ else
788
+ {
789
+ result.cpu2gpuParams .device = nullptr ;
790
+ result.cpu2gpuParams .finalQueueFamIx = 0u ;
791
+ result.cpu2gpuParams .limits = {};
792
+ result.cpu2gpuParams .pipelineCache = nullptr ;
793
+ result.cpu2gpuParams .sharingMode = nbl::asset::ESM_EXCLUSIVE;
794
+ result.cpu2gpuParams .utilities = nullptr ;
795
+ }
783
796
784
- result.cpu2gpuParams . perQueue [ nbl::video::IGPUObjectFromAssetConverter::EQU_TRANSFER]. queue = result. queues [InitOutput< 0 >::EQT_TRANSFER_UP];
785
- result.cpu2gpuParams .perQueue [nbl::video::IGPUObjectFromAssetConverter::EQU_COMPUTE]. queue = result.queues [InitOutput< 0 >::EQT_COMPUTE] ;
797
+ result.assetManager = nbl::core::make_smart_refctd_ptr<nbl::asset::IAssetManager>( nbl::core::smart_refctd_ptr (result. system )); // we should let user choose it?
798
+ result.cpu2gpuParams .assetManager = result.assetManager . get () ;
786
799
}
787
800
788
801
static auto createFBOWithSwapchainImages (uint32_t imageCount, uint32_t width, uint32_t height,
0 commit comments