Init OK! but sumbit a null CmdBuffer is a Bug.
This commit is contained in:
parent
2bb1056b2a
commit
359c1cdc87
@ -7,5 +7,10 @@ int os_main(int,os_char **)
|
|||||||
{
|
{
|
||||||
RenderFramework rf;
|
RenderFramework rf;
|
||||||
|
|
||||||
|
if(!rf.Init(1280,720,OS_TEXT("FirstApp")))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
rf.Run();
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
@ -101,6 +101,8 @@ public:
|
|||||||
|
|
||||||
virtual void MainLoop(); ///<主循环
|
virtual void MainLoop(); ///<主循环
|
||||||
|
|
||||||
|
virtual void Run();
|
||||||
|
|
||||||
public: //TileData
|
public: //TileData
|
||||||
|
|
||||||
TileData *CreateTileData(const VkFormat video_format,const uint width,const uint height,const uint count); ///<创建一个Tile数据集
|
TileData *CreateTileData(const VkFormat video_format,const uint width,const uint height,const uint count); ///<创建一个Tile数据集
|
||||||
|
@ -99,7 +99,7 @@ public:
|
|||||||
* 请求下一帧画面的索引
|
* 请求下一帧画面的索引
|
||||||
* @param present_complete_semaphore 推送完成信号
|
* @param present_complete_semaphore 推送完成信号
|
||||||
*/
|
*/
|
||||||
int AcquireNextImage();
|
uint32_t AcquireNextImage();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 推送后台画面到前台
|
* 推送后台画面到前台
|
||||||
|
@ -27,7 +27,7 @@ public:
|
|||||||
|
|
||||||
virtual void OnResize(const VkExtent2D &)override; ///<窗口大小改变
|
virtual void OnResize(const VkExtent2D &)override; ///<窗口大小改变
|
||||||
|
|
||||||
virtual void OnExecute(const double,RenderCmdBuffer *);
|
//virtual void OnExecute(const double,RenderCmdBuffer *);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include<hgl/graph/RenderFramework.h>
|
#include<hgl/graph/RenderFramework.h>
|
||||||
#include<hgl/graph/manager/RenderPassManager.h>
|
#include<hgl/graph/manager/RenderPassManager.h>
|
||||||
|
#include<hgl/graph/manager/TextureManager.h>
|
||||||
#include<hgl/graph/module/SwapchainModule.h>
|
#include<hgl/graph/module/SwapchainModule.h>
|
||||||
#include<hgl/graph/VKDeviceCreater.h>
|
#include<hgl/graph/VKDeviceCreater.h>
|
||||||
#include<hgl/Time.h>
|
#include<hgl/Time.h>
|
||||||
@ -59,8 +60,6 @@ void RenderFramework::EndFrame()
|
|||||||
{
|
{
|
||||||
swapchain_module->EndFrame();
|
swapchain_module->EndFrame();
|
||||||
|
|
||||||
device->WaitIdle();
|
|
||||||
|
|
||||||
last_time=cur_time;
|
last_time=cur_time;
|
||||||
++frame_count;
|
++frame_count;
|
||||||
}
|
}
|
||||||
@ -83,13 +82,27 @@ void RenderFramework::MainLoop()
|
|||||||
rm->OnExecute(delta_time,nullptr);
|
rm->OnExecute(delta_time,nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EndFrame();
|
||||||
|
|
||||||
for(auto rm:module_list)
|
for(auto rm:module_list)
|
||||||
{
|
{
|
||||||
if(rm->IsEnable())
|
if(rm->IsEnable())
|
||||||
rm->OnPostFrame();
|
rm->OnPostFrame();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
EndFrame();
|
void RenderFramework::Run()
|
||||||
|
{
|
||||||
|
if(!win)return;
|
||||||
|
if(!swapchain_module)return;
|
||||||
|
|
||||||
|
while(win->Update())
|
||||||
|
{
|
||||||
|
if(win->IsVisible())
|
||||||
|
MainLoop();
|
||||||
|
|
||||||
|
device->WaitIdle();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RenderFramework::Init(uint w,uint h,const OSString &app_name)
|
bool RenderFramework::Init(uint w,uint h,const OSString &app_name)
|
||||||
@ -127,6 +140,7 @@ bool RenderFramework::Init(uint w,uint h,const OSString &app_name)
|
|||||||
graph_module_manager=InitGraphModuleManager(device);
|
graph_module_manager=InitGraphModuleManager(device);
|
||||||
|
|
||||||
render_pass_manager =graph_module_manager->GetModule<RenderPassManager>(true);
|
render_pass_manager =graph_module_manager->GetModule<RenderPassManager>(true);
|
||||||
|
texture_manager =graph_module_manager->GetModule<TextureManager>(true);
|
||||||
swapchain_module =graph_module_manager->GetModule<SwapchainModule>(true);
|
swapchain_module =graph_module_manager->GetModule<SwapchainModule>(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,23 +71,16 @@ namespace
|
|||||||
// VK_EXT_SAMPLER_FILTER_MINMAX_EXTENSION_NAME,
|
// VK_EXT_SAMPLER_FILTER_MINMAX_EXTENSION_NAME,
|
||||||
|
|
||||||
VK_KHR_SPIRV_1_4_EXTENSION_NAME,
|
VK_KHR_SPIRV_1_4_EXTENSION_NAME,
|
||||||
|
|
||||||
|
VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME,
|
||||||
|
VK_IMG_FORMAT_PVRTC_EXTENSION_NAME,
|
||||||
|
VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME,
|
||||||
|
VK_EXT_BLEND_OPERATION_ADVANCED_EXTENSION_NAME
|
||||||
};
|
};
|
||||||
|
|
||||||
for(const char *ext_name:require_ext_list)
|
for(const char *ext_name:require_ext_list)
|
||||||
if(physical_device->CheckExtensionSupport(ext_name))
|
if(physical_device->CheckExtensionSupport(ext_name))
|
||||||
ext_list->Add(ext_name);
|
ext_list->Add(ext_name);
|
||||||
|
|
||||||
if(require.lineRasterization>=VulkanHardwareRequirement::SupportLevel::Want)
|
|
||||||
ext_list->Add(VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME);
|
|
||||||
|
|
||||||
if(require.texture_compression.PVRTC>=VulkanHardwareRequirement::SupportLevel::Want) //前面检测过了,所以这里不用再次检测是否支持
|
|
||||||
ext_list->Add(VK_IMG_FORMAT_PVRTC_EXTENSION_NAME);
|
|
||||||
|
|
||||||
if(require.fullDrawIndexUint8>=VulkanHardwareRequirement::SupportLevel::Want)
|
|
||||||
ext_list->Add(VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME);
|
|
||||||
|
|
||||||
if(require.blendOperationAdvanced>=VulkanHardwareRequirement::SupportLevel::Want)
|
|
||||||
ext_list->Add(VK_EXT_BLEND_OPERATION_ADVANCED_EXTENSION_NAME);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetDeviceFeatures(VkPhysicalDeviceFeatures *features,const VkPhysicalDeviceFeatures &pdf,const VulkanHardwareRequirement &require)
|
void SetDeviceFeatures(VkPhysicalDeviceFeatures *features,const VkPhysicalDeviceFeatures &pdf,const VulkanHardwareRequirement &require)
|
||||||
@ -222,7 +215,7 @@ VkDevice VulkanDeviceCreater::CreateDevice(const uint32_t graphics_family)
|
|||||||
VkDeviceCreateInfo create_info;
|
VkDeviceCreateInfo create_info;
|
||||||
|
|
||||||
create_info.sType =VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
|
create_info.sType =VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
|
||||||
create_info.pNext =nullptr;
|
//create_info.pNext =nullptr;
|
||||||
create_info.flags =0;
|
create_info.flags =0;
|
||||||
create_info.queueCreateInfoCount =1;
|
create_info.queueCreateInfoCount =1;
|
||||||
create_info.pQueueCreateInfos =&queue_info;
|
create_info.pQueueCreateInfos =&queue_info;
|
||||||
@ -232,18 +225,38 @@ VkDevice VulkanDeviceCreater::CreateDevice(const uint32_t graphics_family)
|
|||||||
create_info.ppEnabledLayerNames =nullptr;
|
create_info.ppEnabledLayerNames =nullptr;
|
||||||
create_info.pEnabledFeatures =&features;
|
create_info.pEnabledFeatures =&features;
|
||||||
|
|
||||||
|
void **pNext=const_cast<void **>(&create_info.pNext);
|
||||||
|
|
||||||
VkPhysicalDeviceIndexTypeUint8FeaturesEXT index_type_uint8_features;
|
VkPhysicalDeviceIndexTypeUint8FeaturesEXT index_type_uint8_features;
|
||||||
|
|
||||||
if(physical_device->SupportU8Index()
|
if(physical_device->SupportU8Index()
|
||||||
&&require.fullDrawIndexUint8>=VulkanHardwareRequirement::SupportLevel::Want)
|
&&require.fullDrawIndexUint8>=VulkanHardwareRequirement::SupportLevel::Want)
|
||||||
{
|
{
|
||||||
create_info.pNext=&index_type_uint8_features;
|
*pNext=&index_type_uint8_features;
|
||||||
|
|
||||||
index_type_uint8_features.sType =VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT;
|
index_type_uint8_features.sType =VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT;
|
||||||
index_type_uint8_features.pNext =nullptr;
|
//index_type_uint8_features.pNext =nullptr;
|
||||||
index_type_uint8_features.indexTypeUint8=VK_TRUE;
|
index_type_uint8_features.indexTypeUint8=VK_TRUE;
|
||||||
|
|
||||||
|
pNext=const_cast<void **>(&index_type_uint8_features.pNext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT blend_op_advanced_features;
|
||||||
|
|
||||||
|
if(physical_device->SupportBlendOpAdvanced()
|
||||||
|
&&require.blendOperationAdvanced>=VulkanHardwareRequirement::SupportLevel::Want)
|
||||||
|
{
|
||||||
|
*pNext=&blend_op_advanced_features;
|
||||||
|
|
||||||
|
blend_op_advanced_features.sType=VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT;
|
||||||
|
//blend_op_advanced_features.pNext=nullptr;
|
||||||
|
blend_op_advanced_features.advancedBlendCoherentOperations=VK_TRUE;
|
||||||
|
|
||||||
|
pNext=const_cast<void **>(&blend_op_advanced_features.pNext);
|
||||||
|
}
|
||||||
|
|
||||||
|
*pNext=nullptr;
|
||||||
|
|
||||||
VkDevice device;
|
VkDevice device;
|
||||||
|
|
||||||
if(vkCreateDevice(*physical_device,&create_info,nullptr,&device)==VK_SUCCESS)
|
if(vkCreateDevice(*physical_device,&create_info,nullptr,&device)==VK_SUCCESS)
|
||||||
|
@ -72,6 +72,9 @@ GPUPhysicalDevice::GPUPhysicalDevice(VkInstance inst,VkPhysicalDevice pd)
|
|||||||
VkPhysicalDeviceFeatures2 features2;
|
VkPhysicalDeviceFeatures2 features2;
|
||||||
VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT boaf;
|
VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT boaf;
|
||||||
|
|
||||||
|
hgl_zero(features2);
|
||||||
|
hgl_zero(boaf);
|
||||||
|
|
||||||
features2.sType=VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR;
|
features2.sType=VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR;
|
||||||
features2.pNext=&features11;
|
features2.pNext=&features11;
|
||||||
|
|
||||||
@ -103,6 +106,7 @@ GPUPhysicalDevice::GPUPhysicalDevice(VkInstance inst,VkPhysicalDevice pd)
|
|||||||
hgl_zero(properties11);
|
hgl_zero(properties11);
|
||||||
hgl_zero(properties12);
|
hgl_zero(properties12);
|
||||||
hgl_zero(properties13);
|
hgl_zero(properties13);
|
||||||
|
hgl_zero(blendOpAdvProperties);
|
||||||
|
|
||||||
auto func=(PFN_vkGetPhysicalDeviceProperties2KHR)vkGetInstanceProcAddr(inst,"vkGetPhysicalDeviceProperties2KHR");
|
auto func=(PFN_vkGetPhysicalDeviceProperties2KHR)vkGetInstanceProcAddr(inst,"vkGetPhysicalDeviceProperties2KHR");
|
||||||
|
|
||||||
@ -110,6 +114,8 @@ GPUPhysicalDevice::GPUPhysicalDevice(VkInstance inst,VkPhysicalDevice pd)
|
|||||||
{
|
{
|
||||||
VkPhysicalDeviceProperties2 properties2;
|
VkPhysicalDeviceProperties2 properties2;
|
||||||
|
|
||||||
|
hgl_zero(properties2);
|
||||||
|
|
||||||
properties2.sType=VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
|
properties2.sType=VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
|
||||||
properties2.pNext=&properties11;
|
properties2.pNext=&properties11;
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ RenderTarget::RenderTarget(DeviceQueue *q,Semaphore *s)
|
|||||||
render_pass=nullptr;
|
render_pass=nullptr;
|
||||||
fbo=nullptr;
|
fbo=nullptr;
|
||||||
|
|
||||||
image_count=0;
|
color_count=0;
|
||||||
color_textures=nullptr;
|
color_textures=nullptr;
|
||||||
depth_texture=nullptr;
|
depth_texture=nullptr;
|
||||||
render_complete_semaphore=s;
|
render_complete_semaphore=s;
|
||||||
@ -26,11 +26,10 @@ RenderTarget::RenderTarget(DeviceQueue *q,Semaphore *s,RenderPass *_rp,Framebuff
|
|||||||
|
|
||||||
depth_texture=dt;
|
depth_texture=dt;
|
||||||
|
|
||||||
image_count=cc;
|
color_count=cc;
|
||||||
if(image_count>0)
|
if(color_count>0)
|
||||||
{
|
{
|
||||||
color_textures=new Texture2D *[image_count];
|
color_textures=hgl_new_copy(ctl,color_count);
|
||||||
hgl_cpy(color_textures,ctl,image_count);
|
|
||||||
|
|
||||||
extent.width=color_textures[0]->GetWidth();
|
extent.width=color_textures[0]->GetWidth();
|
||||||
extent.height=color_textures[0]->GetHeight();
|
extent.height=color_textures[0]->GetHeight();
|
||||||
@ -53,7 +52,7 @@ RenderTarget::~RenderTarget()
|
|||||||
{
|
{
|
||||||
SAFE_CLEAR(queue);
|
SAFE_CLEAR(queue);
|
||||||
SAFE_CLEAR(depth_texture);
|
SAFE_CLEAR(depth_texture);
|
||||||
SAFE_CLEAR_OBJECT_ARRAY_OBJECT(color_textures,image_count);
|
SAFE_CLEAR_OBJECT_ARRAY_OBJECT(color_textures,color_count);
|
||||||
|
|
||||||
SAFE_CLEAR(render_complete_semaphore);
|
SAFE_CLEAR(render_complete_semaphore);
|
||||||
SAFE_CLEAR(fbo);
|
SAFE_CLEAR(fbo);
|
||||||
|
@ -30,12 +30,12 @@ RTSwapchain::~RTSwapchain()
|
|||||||
delete swapchain;
|
delete swapchain;
|
||||||
}
|
}
|
||||||
|
|
||||||
int RTSwapchain::AcquireNextImage()
|
uint32_t RTSwapchain::AcquireNextImage()
|
||||||
{
|
{
|
||||||
if(vkAcquireNextImageKHR(device,swapchain->swap_chain,UINT64_MAX,*(this->present_complete_semaphore),VK_NULL_HANDLE,¤t_frame)==VK_SUCCESS)
|
if(vkAcquireNextImageKHR(device,swapchain->swap_chain,UINT64_MAX,*(this->present_complete_semaphore),VK_NULL_HANDLE,¤t_frame)==VK_SUCCESS)
|
||||||
return current_frame;
|
return current_frame;
|
||||||
|
|
||||||
return -1;
|
return UINT32_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RTSwapchain::PresentBackbuffer(VkSemaphore *wait_semaphores,const uint32_t count)
|
bool RTSwapchain::PresentBackbuffer(VkSemaphore *wait_semaphores,const uint32_t count)
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
void InitGraphModuleFactory();
|
||||||
|
void ClearGraphModuleFactory();
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
using GraphModuleManagerMap=Map<GPUDevice *,GraphModuleManager *>;
|
using GraphModuleManagerMap=Map<GPUDevice *,GraphModuleManager *>;
|
||||||
@ -22,6 +25,9 @@ GraphModuleManager *InitGraphModuleManager(GPUDevice *dev)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
InitGraphModuleFactory();
|
||||||
|
RegistryCommonGraphModule();
|
||||||
|
|
||||||
graph_module_manager_map=new GraphModuleManagerMap;
|
graph_module_manager_map=new GraphModuleManagerMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,6 +54,13 @@ bool ClearGraphModuleManager(GPUDevice *dev)
|
|||||||
graph_module_manager_map->DeleteByKey(dev);
|
graph_module_manager_map->DeleteByKey(dev);
|
||||||
|
|
||||||
delete gmm;
|
delete gmm;
|
||||||
|
|
||||||
|
if(graph_module_manager_map->IsEmpty())
|
||||||
|
{
|
||||||
|
ClearGraphModuleFactory();
|
||||||
|
SAFE_CLEAR(graph_module_manager_map);
|
||||||
|
}
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include<hgl/graph/VKSwapchain.h>
|
#include<hgl/graph/VKSwapchain.h>
|
||||||
#include<hgl/graph/VKDeviceAttribute.h>
|
#include<hgl/graph/VKDeviceAttribute.h>
|
||||||
#include<hgl/graph/VKRenderTarget.h>
|
#include<hgl/graph/VKRenderTarget.h>
|
||||||
|
#include<hgl/graph/VKCommandBuffer.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
namespace
|
namespace
|
||||||
@ -144,9 +145,6 @@ bool SwapchainModule::CreateSwapchainFBO()
|
|||||||
|
|
||||||
bool SwapchainModule::CreateSwapchain()
|
bool SwapchainModule::CreateSwapchain()
|
||||||
{
|
{
|
||||||
if(swapchain)
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
auto *dev_attr=GetDeviceAttribute();
|
auto *dev_attr=GetDeviceAttribute();
|
||||||
|
|
||||||
if(!dev_attr)
|
if(!dev_attr)
|
||||||
@ -207,7 +205,7 @@ void SwapchainModule::InitRenderCmdBuffer()
|
|||||||
|
|
||||||
AnsiString cmd_buf_name;
|
AnsiString cmd_buf_name;
|
||||||
|
|
||||||
for(int32_t i=0;i<swapchain->image_count;i++)
|
for(uint32_t i=0;i<swapchain->image_count;i++)
|
||||||
{
|
{
|
||||||
cmd_buf_name=device->GetPhysicalDevice()->GetDeviceName()+AnsiString(":RenderCmdBuffer_")+AnsiString::numberOf(i);
|
cmd_buf_name=device->GetPhysicalDevice()->GetDeviceName()+AnsiString(":RenderCmdBuffer_")+AnsiString::numberOf(i);
|
||||||
|
|
||||||
@ -268,9 +266,9 @@ void SwapchainModule::OnResize(const VkExtent2D &extent)
|
|||||||
|
|
||||||
bool SwapchainModule::BeginFrame()
|
bool SwapchainModule::BeginFrame()
|
||||||
{
|
{
|
||||||
int index=swapchain_rt->AcquireNextImage();
|
uint32_t index=swapchain_rt->AcquireNextImage();
|
||||||
|
|
||||||
if(index<0||index>=swapchain->image_count)
|
if(index>=swapchain->image_count)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
@ -280,9 +278,12 @@ void SwapchainModule::EndFrame()
|
|||||||
{
|
{
|
||||||
int index=swapchain_rt->GetCurrentFrameIndices();
|
int index=swapchain_rt->GetCurrentFrameIndices();
|
||||||
|
|
||||||
|
VkCommandBuffer cb=*(cmd_buf[index]);
|
||||||
|
|
||||||
|
swapchain_rt->Submit(cb);
|
||||||
swapchain_rt->Submit();
|
swapchain_rt->PresentBackbuffer();
|
||||||
|
swapchain_rt->WaitQueue();
|
||||||
|
swapchain_rt->WaitFence();
|
||||||
}
|
}
|
||||||
|
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
Loading…
x
Reference in New Issue
Block a user