2019-08-23 11:18:09 +08:00
|
|
|
|
#include<hgl/platform/Vulkan.h>
|
|
|
|
|
#include<hgl/platform/Window.h>
|
2020-10-21 11:43:18 +08:00
|
|
|
|
#include<hgl/graph/VKDevice.h>
|
|
|
|
|
#include<hgl/graph/VKInstance.h>
|
|
|
|
|
#include<hgl/graph/VKPhysicalDevice.h>
|
|
|
|
|
#include<hgl/graph/VKFramebuffer.h>
|
|
|
|
|
#include<hgl/graph/VKTexture.h>
|
2023-05-11 21:14:35 +08:00
|
|
|
|
#include<hgl/graph/VKDeviceCreater.h>
|
2020-10-21 11:43:18 +08:00
|
|
|
|
#include<hgl/graph/VKDevice.h>
|
2021-11-23 11:54:35 +08:00
|
|
|
|
#include<hgl/graph/VKDebugMaker.h>
|
2019-04-11 02:29:21 +08:00
|
|
|
|
|
2019-05-23 13:24:21 +08:00
|
|
|
|
|
2019-04-11 02:29:21 +08:00
|
|
|
|
VK_NAMESPACE_BEGIN
|
2020-11-05 14:02:35 +08:00
|
|
|
|
VkPipelineCache CreatePipelineCache(VkDevice device,const VkPhysicalDeviceProperties &);
|
2019-07-15 22:37:00 +08:00
|
|
|
|
|
2021-11-23 11:54:35 +08:00
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
DebugMaker *CreateDebugMaker(VkDevice);
|
2022-09-26 16:11:42 +08:00
|
|
|
|
DebugUtils *CreateDebugUtils(VkDevice);
|
2021-11-23 11:54:35 +08:00
|
|
|
|
#endif//_DEBUG
|
|
|
|
|
|
2019-04-11 02:29:21 +08:00
|
|
|
|
namespace
|
|
|
|
|
{
|
2023-05-10 21:26:15 +08:00
|
|
|
|
void SetDeviceExtension(CharPointerList *ext_list,const GPUPhysicalDevice *physical_device,const VulkanHardwareRequirement &require)
|
2019-04-11 02:29:21 +08:00
|
|
|
|
{
|
2021-11-22 14:19:59 +08:00
|
|
|
|
ext_list->Add(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
|
2021-09-23 19:08:41 +08:00
|
|
|
|
|
|
|
|
|
constexpr char *require_ext_list[]=
|
|
|
|
|
{
|
2021-11-23 10:24:03 +08:00
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
VK_EXT_DEBUG_MARKER_EXTENSION_NAME,
|
|
|
|
|
#endif//_DEBUG
|
2023-05-10 21:48:26 +08:00
|
|
|
|
VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME,
|
|
|
|
|
VK_EXT_EXTENDED_DYNAMIC_STATE_2_EXTENSION_NAME,
|
|
|
|
|
VK_EXT_EXTENDED_DYNAMIC_STATE_3_EXTENSION_NAME,
|
2023-02-13 11:48:53 +08:00
|
|
|
|
// VK_EXT_VERTEX_INPUT_DYNAMIC_STATE_EXTENSION_NAME,
|
2022-06-18 15:23:17 +08:00
|
|
|
|
VK_EXT_PRIMITIVE_TOPOLOGY_LIST_RESTART_EXTENSION_NAME,
|
2023-02-13 11:48:53 +08:00
|
|
|
|
// VK_EXT_CONDITIONAL_RENDERING_EXTENSION_NAME,
|
2021-11-23 10:24:03 +08:00
|
|
|
|
// VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME,
|
|
|
|
|
// VK_EXT_HDR_METADATA_EXTENSION_NAME,
|
2021-11-23 11:54:35 +08:00
|
|
|
|
// VK_EXT_FULL_SCREEN_EXCLUSIVE_EXTENSION_NAME,
|
|
|
|
|
// VK_AMD_DISPLAY_NATIVE_HDR_EXTENSION_NAME,
|
2022-08-18 19:01:08 +08:00
|
|
|
|
// VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME,
|
2021-11-23 11:54:35 +08:00
|
|
|
|
|
|
|
|
|
// VK_EXT_SAMPLER_FILTER_MINMAX_EXTENSION_NAME,
|
2021-09-23 19:08:41 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for(const char *ext_name:require_ext_list)
|
|
|
|
|
if(physical_device->CheckExtensionSupport(ext_name))
|
2021-11-22 14:19:59 +08:00
|
|
|
|
ext_list->Add(ext_name);
|
2023-05-10 21:26:15 +08:00
|
|
|
|
|
2023-05-10 21:56:32 +08:00
|
|
|
|
if(require.line_rasterization)
|
|
|
|
|
ext_list->Add(VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME);
|
|
|
|
|
|
2023-05-10 21:26:15 +08:00
|
|
|
|
if(require.texture_compression.pvrtc) //前面检测过了,所以这里不用再次检测是否支持
|
|
|
|
|
ext_list->Add(VK_IMG_FORMAT_PVRTC_EXTENSION_NAME);
|
2023-05-11 21:14:35 +08:00
|
|
|
|
|
|
|
|
|
if(require.uint8_draw_index)
|
|
|
|
|
ext_list->Add(VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME);
|
2021-11-22 14:19:59 +08:00
|
|
|
|
}
|
2020-07-28 16:36:39 +08:00
|
|
|
|
|
2023-05-10 21:26:15 +08:00
|
|
|
|
void SetDeviceFeatures(VkPhysicalDeviceFeatures *features,const VkPhysicalDeviceFeatures &pdf,const VulkanHardwareRequirement &require)
|
2021-11-22 14:19:59 +08:00
|
|
|
|
{
|
|
|
|
|
#define FEATURE_COPY(name) features->name=pdf.name;
|
|
|
|
|
|
2023-05-10 21:26:15 +08:00
|
|
|
|
if(require.geometry_shader) FEATURE_COPY(geometryShader);
|
|
|
|
|
// if(require.compute_shader) FEATURE_COPY(computeShader);
|
|
|
|
|
|
|
|
|
|
FEATURE_COPY(multiDrawIndirect);
|
2021-11-22 14:05:18 +08:00
|
|
|
|
|
2023-05-10 21:26:15 +08:00
|
|
|
|
FEATURE_COPY(samplerAnisotropy);
|
|
|
|
|
|
|
|
|
|
if(require.texture_cube_array) FEATURE_COPY(imageCubeArray);
|
|
|
|
|
if(require.uint32_draw_index) FEATURE_COPY(fullDrawIndexUint32);
|
|
|
|
|
if(require.wide_lines) FEATURE_COPY(wideLines)
|
|
|
|
|
if(require.large_points) FEATURE_COPY(largePoints)
|
2021-12-16 17:27:33 +08:00
|
|
|
|
|
2021-11-22 14:19:59 +08:00
|
|
|
|
#undef FEATURE_COPY
|
|
|
|
|
}
|
2021-11-22 14:05:18 +08:00
|
|
|
|
|
2020-10-21 12:39:22 +08:00
|
|
|
|
void GetDeviceQueue(GPUDeviceAttribute *attr)
|
2019-04-19 13:43:50 +08:00
|
|
|
|
{
|
|
|
|
|
vkGetDeviceQueue(attr->device,attr->graphics_family,0,&attr->graphics_queue);
|
|
|
|
|
|
|
|
|
|
if(attr->graphics_family==attr->present_family)
|
|
|
|
|
attr->present_queue=attr->graphics_queue;
|
|
|
|
|
else
|
|
|
|
|
vkGetDeviceQueue(attr->device,attr->present_family,0,&attr->present_queue);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-11 20:24:09 +08:00
|
|
|
|
VkCommandPool CreateCommandPool(VkDevice device,uint32_t graphics_family)
|
2019-04-11 02:29:21 +08:00
|
|
|
|
{
|
|
|
|
|
VkCommandPoolCreateInfo cmd_pool_info={};
|
|
|
|
|
|
2021-11-30 15:25:34 +08:00
|
|
|
|
cmd_pool_info.sType =VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
|
|
|
|
cmd_pool_info.pNext =nullptr;
|
|
|
|
|
cmd_pool_info.queueFamilyIndex =graphics_family;
|
|
|
|
|
cmd_pool_info.flags =VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
|
2019-04-11 02:29:21 +08:00
|
|
|
|
|
|
|
|
|
VkCommandPool cmd_pool;
|
|
|
|
|
|
|
|
|
|
if(vkCreateCommandPool(device,&cmd_pool_info,nullptr,&cmd_pool)==VK_SUCCESS)
|
|
|
|
|
return cmd_pool;
|
|
|
|
|
|
2019-07-06 16:46:19 +08:00
|
|
|
|
return(VK_NULL_HANDLE);
|
2019-04-11 02:29:21 +08:00
|
|
|
|
}
|
2019-04-11 20:24:09 +08:00
|
|
|
|
|
2020-10-24 21:50:36 +08:00
|
|
|
|
ImageView *Create2DImageView(VkDevice device,VkFormat format,const VkExtent2D &ext,const uint32_t miplevel,VkImage img=VK_NULL_HANDLE)
|
2019-04-12 00:09:26 +08:00
|
|
|
|
{
|
2019-07-10 21:00:36 +08:00
|
|
|
|
VkExtent3D extent;
|
|
|
|
|
|
|
|
|
|
copy(extent,ext);
|
|
|
|
|
|
2020-10-24 21:50:36 +08:00
|
|
|
|
return CreateImageView(device,VK_IMAGE_VIEW_TYPE_2D,format,extent,miplevel,VK_IMAGE_ASPECT_COLOR_BIT,img);
|
2019-04-12 00:09:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-24 21:50:36 +08:00
|
|
|
|
ImageView *CreateDepthImageView(VkDevice device,VkFormat format,const VkExtent2D &ext,const uint32_t miplevel,VkImage img=VK_NULL_HANDLE)
|
2019-04-12 00:09:26 +08:00
|
|
|
|
{
|
2019-07-10 21:00:36 +08:00
|
|
|
|
VkExtent3D extent;
|
|
|
|
|
|
2020-06-24 19:13:29 +08:00
|
|
|
|
copy(extent,ext,1);
|
2020-10-24 21:50:36 +08:00
|
|
|
|
return CreateImageView(device,VK_IMAGE_VIEW_TYPE_2D,format,extent,miplevel,VK_IMAGE_ASPECT_DEPTH_BIT,img);
|
2019-04-12 00:09:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-15 22:37:00 +08:00
|
|
|
|
VkDescriptorPool CreateDescriptorPool(VkDevice device,uint32_t sets_count)
|
2019-04-12 16:35:44 +08:00
|
|
|
|
{
|
2019-06-22 16:22:38 +08:00
|
|
|
|
VkDescriptorPoolSize pool_size[]=
|
|
|
|
|
{
|
2019-07-15 22:37:00 +08:00
|
|
|
|
{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, sets_count},
|
|
|
|
|
{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, sets_count},
|
|
|
|
|
{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, sets_count},
|
|
|
|
|
{VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, sets_count}
|
2019-06-22 16:22:38 +08:00
|
|
|
|
};
|
2019-04-12 16:35:44 +08:00
|
|
|
|
|
2019-07-15 22:37:00 +08:00
|
|
|
|
VkDescriptorPoolCreateInfo dp_create_info;
|
|
|
|
|
dp_create_info.sType =VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
|
|
|
|
dp_create_info.pNext =nullptr;
|
|
|
|
|
dp_create_info.flags =0;
|
|
|
|
|
dp_create_info.maxSets =sets_count;
|
2019-06-22 16:22:38 +08:00
|
|
|
|
dp_create_info.poolSizeCount=sizeof(pool_size)/sizeof(VkDescriptorPoolSize);
|
2019-07-15 22:37:00 +08:00
|
|
|
|
dp_create_info.pPoolSizes =pool_size;
|
2019-04-12 16:35:44 +08:00
|
|
|
|
|
|
|
|
|
VkDescriptorPool desc_pool;
|
|
|
|
|
|
2019-04-12 16:39:05 +08:00
|
|
|
|
if(vkCreateDescriptorPool(device,&dp_create_info,nullptr,&desc_pool)!=VK_SUCCESS)
|
2019-07-06 16:46:19 +08:00
|
|
|
|
return(VK_NULL_HANDLE);
|
2019-04-12 16:35:44 +08:00
|
|
|
|
|
|
|
|
|
return desc_pool;
|
|
|
|
|
}
|
2019-05-07 12:46:25 +08:00
|
|
|
|
}//namespace
|
2019-04-11 02:29:21 +08:00
|
|
|
|
|
2020-06-11 18:25:08 +08:00
|
|
|
|
#ifndef VK_DRIVER_ID_BEGIN_RANGE
|
|
|
|
|
#define VK_DRIVER_ID_BEGIN_RANGE VK_DRIVER_ID_AMD_PROPRIETARY
|
|
|
|
|
#endif//VK_DRIVER_ID_BEGIN_RANGE
|
|
|
|
|
|
|
|
|
|
#ifndef VK_DRIVER_ID_END_RANGE
|
|
|
|
|
#define VK_DRIVER_ID_END_RANGE VK_DRIVER_ID_MESA_LLVMPIPE
|
|
|
|
|
#endif//VK_DRIVER_ID_END_RANGE
|
|
|
|
|
|
|
|
|
|
#ifndef VK_DRIVER_ID_RANGE_SIZE
|
|
|
|
|
constexpr size_t VK_DRIVER_ID_RANGE_SIZE=VK_DRIVER_ID_END_RANGE-VK_DRIVER_ID_BEGIN_RANGE+1;
|
|
|
|
|
#endif//VK_DRIVER_ID_RANGE_SIZE
|
|
|
|
|
|
2023-05-11 00:54:47 +08:00
|
|
|
|
#ifdef _DEBUG
|
2023-05-11 21:14:35 +08:00
|
|
|
|
void OutputPhysicalDeviceCaps(const GPUPhysicalDevice *);
|
2023-05-11 00:54:47 +08:00
|
|
|
|
#endif//_DEBUG
|
|
|
|
|
|
2023-05-11 21:14:35 +08:00
|
|
|
|
VkDevice VulkanDeviceCreater::CreateDevice(const uint32_t graphics_family)
|
2019-05-07 12:46:25 +08:00
|
|
|
|
{
|
2023-05-11 21:14:35 +08:00
|
|
|
|
float queue_priorities[1]={0.0};
|
|
|
|
|
|
|
|
|
|
VkDeviceQueueCreateInfo queue_info;
|
|
|
|
|
queue_info.sType =VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
|
|
|
|
|
queue_info.pNext =nullptr;
|
|
|
|
|
queue_info.queueFamilyIndex =graphics_family;
|
|
|
|
|
queue_info.queueCount =1;
|
|
|
|
|
queue_info.pQueuePriorities =queue_priorities;
|
|
|
|
|
queue_info.flags =0; //如果这里写VK_DEVICE_QUEUE_CREATE_PROTECTED_BIT,会导致vkGetDeviceQueue调用崩溃
|
|
|
|
|
|
|
|
|
|
VkDeviceCreateInfo create_info;
|
|
|
|
|
|
|
|
|
|
create_info.sType =VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
|
|
|
|
|
create_info.pNext =nullptr;
|
|
|
|
|
create_info.flags =0;
|
|
|
|
|
create_info.queueCreateInfoCount =1;
|
|
|
|
|
create_info.pQueueCreateInfos =&queue_info;
|
|
|
|
|
create_info.enabledExtensionCount =ext_list.GetCount();
|
|
|
|
|
create_info.ppEnabledExtensionNames =ext_list.GetData();
|
|
|
|
|
create_info.enabledLayerCount =0;
|
|
|
|
|
create_info.ppEnabledLayerNames =nullptr;
|
|
|
|
|
create_info.pEnabledFeatures =&features;
|
|
|
|
|
|
|
|
|
|
VkDevice device;
|
|
|
|
|
|
|
|
|
|
if(vkCreateDevice(*physical_device,&create_info,nullptr,&device)==VK_SUCCESS)
|
|
|
|
|
return device;
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2019-05-23 13:24:21 +08:00
|
|
|
|
|
2023-05-11 21:14:35 +08:00
|
|
|
|
GPUDevice *VulkanDeviceCreater::CreateRenderDevice()
|
|
|
|
|
{
|
|
|
|
|
GPUDeviceAttribute *device_attr=new GPUDeviceAttribute(instance,physical_device,surface);
|
2019-04-11 02:29:21 +08:00
|
|
|
|
|
2020-10-21 12:39:22 +08:00
|
|
|
|
AutoDelete<GPUDeviceAttribute> auto_delete(device_attr);
|
2019-05-05 14:22:58 +08:00
|
|
|
|
|
2019-07-15 22:37:00 +08:00
|
|
|
|
if(device_attr->graphics_family==ERROR_FAMILY_INDEX)
|
2019-04-11 02:29:21 +08:00
|
|
|
|
return(nullptr);
|
|
|
|
|
|
2023-05-11 21:14:35 +08:00
|
|
|
|
SetDeviceExtension(&ext_list,physical_device,require);
|
|
|
|
|
SetDeviceFeatures(&features,physical_device->GetFeatures10(),require);
|
|
|
|
|
|
|
|
|
|
device_attr->device=CreateDevice(device_attr->graphics_family);
|
2019-04-11 02:29:21 +08:00
|
|
|
|
|
2019-07-15 22:37:00 +08:00
|
|
|
|
if(!device_attr->device)
|
2019-04-11 02:29:21 +08:00
|
|
|
|
return(nullptr);
|
|
|
|
|
|
2021-11-23 11:54:35 +08:00
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
device_attr->debug_maker=CreateDebugMaker(device_attr->device);
|
2022-09-26 16:11:42 +08:00
|
|
|
|
device_attr->debug_utils=CreateDebugUtils(device_attr->device);
|
2021-11-23 11:54:35 +08:00
|
|
|
|
#endif//_DEBUG
|
|
|
|
|
|
2019-07-15 22:37:00 +08:00
|
|
|
|
GetDeviceQueue(device_attr);
|
2019-04-19 13:43:50 +08:00
|
|
|
|
|
2019-07-15 22:37:00 +08:00
|
|
|
|
device_attr->cmd_pool=CreateCommandPool(device_attr->device,device_attr->graphics_family);
|
2019-04-11 02:29:21 +08:00
|
|
|
|
|
2019-07-15 22:37:00 +08:00
|
|
|
|
if(!device_attr->cmd_pool)
|
2019-04-11 02:29:21 +08:00
|
|
|
|
return(nullptr);
|
2019-07-15 22:37:00 +08:00
|
|
|
|
|
2023-05-11 21:14:35 +08:00
|
|
|
|
device_attr->desc_pool=CreateDescriptorPool(device_attr->device,require.descriptor_pool);
|
2019-04-11 02:29:21 +08:00
|
|
|
|
|
2019-07-15 22:37:00 +08:00
|
|
|
|
if(!device_attr->desc_pool)
|
2019-04-11 21:12:54 +08:00
|
|
|
|
return(nullptr);
|
|
|
|
|
|
2023-05-11 21:14:35 +08:00
|
|
|
|
device_attr->pipeline_cache=CreatePipelineCache(device_attr->device,physical_device->GetProperties());
|
2019-04-12 16:35:44 +08:00
|
|
|
|
|
2019-07-15 22:37:00 +08:00
|
|
|
|
if(!device_attr->pipeline_cache)
|
2019-04-19 20:30:08 +08:00
|
|
|
|
return(nullptr);
|
|
|
|
|
|
2022-09-26 16:11:42 +08:00
|
|
|
|
auto_delete.Discard(); //discard autodelete
|
2019-04-18 22:24:39 +08:00
|
|
|
|
|
2020-10-21 12:39:22 +08:00
|
|
|
|
return(new GPUDevice(device_attr));
|
2019-04-11 02:29:21 +08:00
|
|
|
|
}
|
2019-08-23 11:18:09 +08:00
|
|
|
|
|
2023-05-11 21:14:35 +08:00
|
|
|
|
VulkanDeviceCreater::VulkanDeviceCreater( VulkanInstance *vi,
|
|
|
|
|
Window *win,
|
|
|
|
|
const PreferFormats *spf_color,
|
|
|
|
|
const PreferFormats *spf_depth,
|
|
|
|
|
const VulkanHardwareRequirement *req)
|
|
|
|
|
{
|
|
|
|
|
instance=vi;
|
|
|
|
|
window=win;
|
|
|
|
|
|
|
|
|
|
physical_device=nullptr;
|
|
|
|
|
|
|
|
|
|
perfer_color_formats=spf_color;
|
|
|
|
|
perfer_depth_formats=spf_depth;
|
|
|
|
|
|
|
|
|
|
if(req)
|
|
|
|
|
hgl_cpy(require,*req);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool VulkanDeviceCreater::RequirementCheck()
|
2023-05-10 21:26:15 +08:00
|
|
|
|
{
|
2023-05-11 21:14:35 +08:00
|
|
|
|
const VkPhysicalDeviceLimits &limits=physical_device->GetLimits();
|
2023-05-10 21:26:15 +08:00
|
|
|
|
|
2023-05-11 21:14:35 +08:00
|
|
|
|
if(require.min_1d_image_size >0&&require.min_1d_image_size >limits.maxImageDimension1D )return(false);
|
|
|
|
|
if(require.min_2d_image_size >0&&require.min_2d_image_size >limits.maxImageDimension2D )return(false);
|
|
|
|
|
if(require.min_3d_image_size >0&&require.min_3d_image_size >limits.maxImageDimension3D )return(false);
|
|
|
|
|
if(require.min_cube_image_size >0&&require.min_cube_image_size >limits.maxImageDimensionCube )return(false);
|
|
|
|
|
if(require.min_array_image_layers >0&&require.min_array_image_layers >limits.maxImageArrayLayers )return(false);
|
2023-05-10 21:26:15 +08:00
|
|
|
|
|
|
|
|
|
if(require.min_vertex_input_attribute >0&&require.min_vertex_input_attribute >limits.maxVertexInputAttributes)return(false);
|
|
|
|
|
if(require.min_color_attachments >0&&require.min_color_attachments >limits.maxColorAttachments )return(false);
|
|
|
|
|
|
|
|
|
|
if(require.min_push_constant_size >0&&require.min_push_constant_size >limits.maxPushConstantsSize )return(false);
|
|
|
|
|
if(require.min_ubo_range >0&&require.min_ubo_range >limits.maxUniformBufferRange )return(false);
|
|
|
|
|
if(require.min_ssbo_range >0&&require.min_ssbo_range >limits.maxStorageBufferRange )return(false);
|
|
|
|
|
|
|
|
|
|
if(require.min_draw_indirect_count >0&&require.min_draw_indirect_count >limits.maxDrawIndirectCount )return(false);
|
|
|
|
|
|
2023-05-11 21:14:35 +08:00
|
|
|
|
const VkPhysicalDeviceFeatures &features10=physical_device->GetFeatures10();
|
|
|
|
|
const VkPhysicalDeviceVulkan13Features &features13=physical_device->GetFeatures13();
|
2023-05-10 21:26:15 +08:00
|
|
|
|
|
|
|
|
|
if(require.geometry_shader &&(!features10.geometryShader ))return(false);
|
|
|
|
|
if(require.tessellation_shader &&(!features10.tessellationShader ))return(false);
|
|
|
|
|
|
|
|
|
|
if(require.multi_draw_indirect &&(!features10.multiDrawIndirect ))return(false);
|
|
|
|
|
|
|
|
|
|
if(require.wide_lines &&(!features10.wideLines ))return(false);
|
|
|
|
|
if(require.large_points &&(!features10.largePoints ))return(false);
|
|
|
|
|
if(require.texture_cube_array &&(!features10.imageCubeArray ))return(false);
|
2023-05-11 21:14:35 +08:00
|
|
|
|
|
|
|
|
|
if(require.uint8_draw_index &&(!physical_device->CheckExtensionSupport(VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME)))return(false);
|
2023-05-10 21:26:15 +08:00
|
|
|
|
if(require.uint32_draw_index &&(!features10.fullDrawIndexUint32 ))return(false);
|
|
|
|
|
|
|
|
|
|
if(require.texture_compression.bc &&(!features10.textureCompressionBC))return(false);
|
|
|
|
|
if(require.texture_compression.etc2 &&(!features10.textureCompressionETC2))return(false);
|
|
|
|
|
if(require.texture_compression.astc_ldr &&(!features10.textureCompressionASTC_LDR))return(false);
|
|
|
|
|
if(require.texture_compression.astc_hdr &&(!features13.textureCompressionASTC_HDR))return(false);
|
2023-05-11 21:14:35 +08:00
|
|
|
|
if(require.texture_compression.pvrtc &&(!physical_device->CheckExtensionSupport(VK_IMG_FORMAT_PVRTC_EXTENSION_NAME)))return(false);
|
2023-05-10 21:26:15 +08:00
|
|
|
|
|
2023-05-11 21:14:35 +08:00
|
|
|
|
if(require.dynamic_rendering&&(!features13.dynamicRendering))return(false);
|
2023-05-10 21:48:26 +08:00
|
|
|
|
|
2023-05-11 21:14:35 +08:00
|
|
|
|
if(require.dynamic_state[0]&&(!physical_device->CheckExtensionSupport(VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME )))return(false);
|
|
|
|
|
if(require.dynamic_state[1]&&(!physical_device->CheckExtensionSupport(VK_EXT_EXTENDED_DYNAMIC_STATE_2_EXTENSION_NAME )))return(false);
|
|
|
|
|
if(require.dynamic_state[2]&&(!physical_device->CheckExtensionSupport(VK_EXT_EXTENDED_DYNAMIC_STATE_3_EXTENSION_NAME )))return(false);
|
2023-05-10 21:26:15 +08:00
|
|
|
|
|
2023-05-11 21:14:35 +08:00
|
|
|
|
if(require.line_rasterization&&(!physical_device->CheckExtensionSupport(VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME)))return(false);
|
2023-05-10 21:56:32 +08:00
|
|
|
|
|
2023-05-10 21:26:15 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-11 21:14:35 +08:00
|
|
|
|
GPUDevice *VulkanDeviceCreater::Create()
|
2019-08-23 11:18:09 +08:00
|
|
|
|
{
|
2023-05-11 21:14:35 +08:00
|
|
|
|
if(!instance||!window)
|
2019-08-23 11:18:09 +08:00
|
|
|
|
return(nullptr);
|
|
|
|
|
|
2023-05-11 21:14:35 +08:00
|
|
|
|
if(!ChoosePhysicalDevice())
|
|
|
|
|
return(false);
|
2019-08-23 11:18:09 +08:00
|
|
|
|
|
2023-05-11 21:14:35 +08:00
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
OutputPhysicalDeviceCaps(physical_device);
|
|
|
|
|
#endif//_DEBUG
|
2019-08-23 11:18:09 +08:00
|
|
|
|
|
2023-05-10 21:26:15 +08:00
|
|
|
|
|
2023-05-11 21:14:35 +08:00
|
|
|
|
if(!RequirementCheck())
|
|
|
|
|
return(false);
|
2023-05-10 21:26:15 +08:00
|
|
|
|
|
2023-05-11 21:14:35 +08:00
|
|
|
|
surface=CreateVulkanSurface(*instance,window);
|
2019-08-23 11:18:09 +08:00
|
|
|
|
|
|
|
|
|
if(!surface)
|
|
|
|
|
return(nullptr);
|
|
|
|
|
|
2023-05-11 21:14:35 +08:00
|
|
|
|
extent.width =window->GetWidth();
|
|
|
|
|
extent.height =window->GetHeight();
|
|
|
|
|
|
|
|
|
|
GPUDevice *device=CreateRenderDevice();
|
2019-08-23 11:18:09 +08:00
|
|
|
|
|
|
|
|
|
if(!device)
|
|
|
|
|
{
|
2023-05-11 21:14:35 +08:00
|
|
|
|
vkDestroySurfaceKHR(*instance,surface,nullptr);
|
2019-08-23 11:18:09 +08:00
|
|
|
|
return(nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return device;
|
|
|
|
|
}
|
2019-04-11 02:29:21 +08:00
|
|
|
|
VK_NAMESPACE_END
|