2019-04-09 00:22:26 +08:00
|
|
|
|
#include"VKInstance.h"
|
|
|
|
|
#include<hgl/type/DataType.h>
|
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
|
|
|
|
|
2019-04-10 01:13:31 +08:00
|
|
|
|
Instance::Instance(const UTF8String &an,Window *w)
|
2019-04-09 00:22:26 +08:00
|
|
|
|
{
|
2019-04-10 01:13:31 +08:00
|
|
|
|
win=w;
|
2019-04-09 00:22:26 +08:00
|
|
|
|
app_name=an;
|
|
|
|
|
|
|
|
|
|
app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
|
|
|
|
app_info.pNext = nullptr;
|
|
|
|
|
app_info.pApplicationName = app_name.c_str();
|
|
|
|
|
app_info.applicationVersion = 1;
|
|
|
|
|
app_info.pEngineName = "CMGameEngine/ULRE";
|
|
|
|
|
app_info.engineVersion = 1;
|
|
|
|
|
app_info.apiVersion = VK_API_VERSION_1_0;
|
|
|
|
|
|
2019-04-10 01:13:31 +08:00
|
|
|
|
ext_list.Add(VK_KHR_SURFACE_EXTENSION_NAME);
|
|
|
|
|
ext_list.Add(win->GetVulkanSurfaceExtname());
|
|
|
|
|
|
2019-04-09 00:22:26 +08:00
|
|
|
|
inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
|
|
|
|
inst_info.pNext = nullptr;
|
|
|
|
|
inst_info.flags = 0;
|
|
|
|
|
inst_info.pApplicationInfo = &app_info;
|
2019-04-10 01:13:31 +08:00
|
|
|
|
inst_info.enabledExtensionCount = ext_list.GetCount();
|
|
|
|
|
inst_info.ppEnabledExtensionNames = ext_list.GetData();
|
2019-04-09 00:22:26 +08:00
|
|
|
|
inst_info.enabledLayerCount = 0;
|
|
|
|
|
inst_info.ppEnabledLayerNames = nullptr;
|
|
|
|
|
|
|
|
|
|
inst=nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Instance::~Instance()
|
|
|
|
|
{
|
2019-04-09 02:02:43 +08:00
|
|
|
|
physical_devices.Clear();
|
|
|
|
|
|
2019-04-09 00:22:26 +08:00
|
|
|
|
if(inst)
|
|
|
|
|
vkDestroyInstance(inst,nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Instance::Init()
|
|
|
|
|
{
|
|
|
|
|
if(inst)
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
VkResult res=vkCreateInstance(&inst_info,nullptr,&inst);
|
|
|
|
|
|
|
|
|
|
if(res)
|
|
|
|
|
{
|
|
|
|
|
inst=nullptr;
|
|
|
|
|
return(false);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-09 02:02:43 +08:00
|
|
|
|
{
|
|
|
|
|
uint32_t gpu_count = 1;
|
|
|
|
|
res = vkEnumeratePhysicalDevices(inst, &gpu_count, nullptr);
|
|
|
|
|
|
|
|
|
|
if(res!=VK_SUCCESS)
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
physical_devices.SetCount(gpu_count);
|
2019-04-10 21:54:39 +08:00
|
|
|
|
vkEnumeratePhysicalDevices(inst, &gpu_count,physical_devices.GetData());
|
2019-04-09 02:02:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-09 00:22:26 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-10 21:54:39 +08:00
|
|
|
|
RenderSurface *Instance::CreateRenderSurface(int pd_index)
|
2019-04-10 14:00:06 +08:00
|
|
|
|
{
|
2019-04-10 21:54:39 +08:00
|
|
|
|
VkPhysicalDevice pd;
|
|
|
|
|
|
|
|
|
|
if(!physical_devices.Get(pd_index,pd))
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
return(new RenderSurface(win,inst,pd));
|
2019-04-10 14:00:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-09 00:22:26 +08:00
|
|
|
|
VK_NAMESPACE_END
|