新增VulkanInstanceLayer可自定义指定
This commit is contained in:
parent
2ac749bf95
commit
c6b6773101
@ -35,18 +35,13 @@ constexpr char *data_type_name[]
|
||||
"SRGB"
|
||||
};//
|
||||
|
||||
int main(int,char **)
|
||||
vulkan::Instance *InitVulkanInstance()
|
||||
{
|
||||
Window * win =nullptr;
|
||||
vulkan::Instance * inst =nullptr;
|
||||
vulkan::Device * device =nullptr;
|
||||
const vulkan::PhysicalDevice *physical_device =nullptr;
|
||||
|
||||
#ifdef _DEBUG
|
||||
if(!CheckStrideBytesByFormat())
|
||||
{
|
||||
std::cerr<<"check stride bytes by format failed."<<std::endl;
|
||||
return(1);
|
||||
return(nullptr);
|
||||
}
|
||||
#endif//_DEBUG
|
||||
|
||||
@ -54,10 +49,30 @@ int main(int,char **)
|
||||
|
||||
InitVulkanProperties();
|
||||
|
||||
inst=vulkan::CreateInstance(U8_TEXT("VulkanTest"));
|
||||
CreateInstanceLayerInfo cili;
|
||||
|
||||
memset(&cili,0,sizeof(CreateInstanceLayerInfo));
|
||||
|
||||
cili.lunarg.standard_validation=true;
|
||||
cili.khronos.validation=true;
|
||||
|
||||
return vulkan::CreateInstance(U8_TEXT("VulkanTest"),nullptr,&cili);
|
||||
}
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
Window * win =nullptr;
|
||||
vulkan::Instance * inst =nullptr;
|
||||
vulkan::Device * device =nullptr;
|
||||
const vulkan::PhysicalDevice *physical_device =nullptr;
|
||||
|
||||
inst=InitVulkanInstance();
|
||||
|
||||
if(!inst)
|
||||
{
|
||||
std::cerr<<"[VULKAN FATAL ERROR] Create Vulkan Instance failed.";
|
||||
return(false);
|
||||
}
|
||||
|
||||
physical_device=inst->GetDevice(VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU);
|
||||
|
||||
|
@ -52,8 +52,6 @@ class VertexAttributeBinding;
|
||||
|
||||
class Renderable;
|
||||
|
||||
using CharPointerList=hgl::List<const char *>;
|
||||
|
||||
enum class ShaderStage
|
||||
{
|
||||
Vertex =VK_SHADER_STAGE_VERTEX_BIT,
|
||||
@ -104,11 +102,5 @@ inline void debug_out(const hgl::List<VkExtensionProperties> &extension_properti
|
||||
++ep;
|
||||
}
|
||||
}
|
||||
|
||||
void InitVulkanProperties();
|
||||
const List<VkLayerProperties> & GetLayerProperties();
|
||||
const List<VkExtensionProperties> & GetExtensionProperties();
|
||||
const bool CheckLayerSupport(const char *);
|
||||
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_INCLUDE
|
||||
|
@ -8,6 +8,47 @@
|
||||
#include<hgl/graph/vulkan/VKDebugOut.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
#define VK_BOOL1BIT(name) bool name:1;
|
||||
struct CreateInstanceLayerInfo
|
||||
{
|
||||
struct
|
||||
{
|
||||
VK_BOOL1BIT(api_dump)
|
||||
VK_BOOL1BIT(device_simulation)
|
||||
VK_BOOL1BIT(monitor)
|
||||
VK_BOOL1BIT(screenshot)
|
||||
VK_BOOL1BIT(standard_validation)
|
||||
VK_BOOL1BIT(vktrace)
|
||||
}lunarg;
|
||||
|
||||
struct
|
||||
{
|
||||
VK_BOOL1BIT(validation)
|
||||
}khronos;
|
||||
|
||||
struct
|
||||
{
|
||||
VK_BOOL1BIT(optimus)
|
||||
}nv;
|
||||
|
||||
struct
|
||||
{
|
||||
VK_BOOL1BIT(steam_overlay)
|
||||
VK_BOOL1BIT(steam_fossilize)
|
||||
}valve;
|
||||
|
||||
struct
|
||||
{
|
||||
VK_BOOL1BIT(Capture)
|
||||
}RenderDoc;
|
||||
|
||||
struct
|
||||
{
|
||||
VK_BOOL1BIT(helper);
|
||||
}bandicam;
|
||||
};
|
||||
#undef VK_BOOL1BIT
|
||||
|
||||
class Instance
|
||||
{
|
||||
VkInstance inst;
|
||||
@ -18,7 +59,7 @@ VK_NAMESPACE_BEGIN
|
||||
|
||||
private:
|
||||
|
||||
friend Instance *CreateInstance(const UTF8String &app_name,VKDebugOut *out=nullptr);
|
||||
friend Instance *CreateInstance(const UTF8String &app_name,VKDebugOut *out=nullptr,CreateInstanceLayerInfo *cili=nullptr);
|
||||
|
||||
Instance(VkInstance,VKDebugOut *);
|
||||
|
||||
@ -32,6 +73,11 @@ VK_NAMESPACE_BEGIN
|
||||
const PhysicalDevice * GetDevice (VkPhysicalDeviceType)const;
|
||||
};//class Instance
|
||||
|
||||
Instance *CreateInstance(const UTF8String &,VKDebugOut *); ///<创建一个Vulkan实例
|
||||
void InitVulkanProperties();
|
||||
const List<VkLayerProperties> & GetLayerProperties();
|
||||
const List<VkExtensionProperties> & GetExtensionProperties();
|
||||
const bool CheckLayerSupport(const char *);
|
||||
|
||||
Instance *CreateInstance(const UTF8String &,VKDebugOut *,CreateInstanceLayerInfo *); ///<创建一个Vulkan实例
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_INSTANCE_INCLUDE
|
||||
|
@ -7,7 +7,9 @@
|
||||
VK_NAMESPACE_BEGIN
|
||||
Device *CreateRenderDevice(VkInstance,const PhysicalDevice *,Window *);
|
||||
|
||||
Instance *CreateInstance(const UTF8String &app_name,VKDebugOut *out)
|
||||
using CharPointerList=hgl::List<const char *>;
|
||||
|
||||
Instance *CreateInstance(const UTF8String &app_name,VKDebugOut *out,CreateInstanceLayerInfo *layer_info)
|
||||
{
|
||||
VkApplicationInfo app_info;
|
||||
VkInstanceCreateInfo inst_info;
|
||||
@ -24,12 +26,44 @@ Instance *CreateInstance(const UTF8String &app_name,VKDebugOut *out)
|
||||
|
||||
ext_list.Add(VK_KHR_SURFACE_EXTENSION_NAME);
|
||||
ext_list.Add(HGL_VK_SURFACE_EXTENSION_NAME); //此宏在VKSurfaceExtensionName.h中定义
|
||||
|
||||
#ifdef _DEBUG
|
||||
ext_list.Add(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
|
||||
ext_list.Add(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
|
||||
#endif//_DEBUG
|
||||
|
||||
layer_list.Add("VK_LAYER_KHRONOS_validation");
|
||||
layer_list.Add("VK_LAYER_LUNARG_standard_validation");
|
||||
layer_list.Add("VK_LAYER_RENDERDOC_Capture");
|
||||
if(layer_info)
|
||||
{
|
||||
#define VK_LAYER_LUNARG_ADD(name) if(layer_info->lunarg.name)layer_list.Add("VK_LAYER_LUNARG_" #name);
|
||||
|
||||
VK_LAYER_LUNARG_ADD(api_dump)
|
||||
VK_LAYER_LUNARG_ADD(device_simulation)
|
||||
VK_LAYER_LUNARG_ADD(monitor)
|
||||
VK_LAYER_LUNARG_ADD(screenshot)
|
||||
VK_LAYER_LUNARG_ADD(standard_validation)
|
||||
VK_LAYER_LUNARG_ADD(vktrace)
|
||||
|
||||
#define VK_LAYER_KHRONOS_ADD(name) if(layer_info->khronos.name)layer_list.Add("VK_LAYER_KHRONOS_" #name);
|
||||
|
||||
VK_LAYER_KHRONOS_ADD(validation)
|
||||
|
||||
#define VK_LAYER_NV_ADD(name) if(layer_info->nv.name)layer_list.Add("VK_LAYER_NV_" #name);
|
||||
|
||||
VK_LAYER_NV_ADD(optimus)
|
||||
|
||||
#define VK_LAYER_VALVE_ADD(name) if(layer_info->valve.name)layer_list.Add("VK_LAYER_VALVE_" #name);
|
||||
|
||||
VK_LAYER_VALVE_ADD(steam_overlay)
|
||||
VK_LAYER_VALVE_ADD(steam_fossilize)
|
||||
|
||||
#define VK_LAYER_RENDERDOC_ADD(name) if(layer_info->RenderDoc.name)layer_list.Add("VK_LAYER_RENDERDOC_" #name);
|
||||
|
||||
VK_LAYER_RENDERDOC_ADD(Capture)
|
||||
|
||||
#define VK_LAYER_BANDICAM_ADD(name) if(layer_info->bandicam.name)layer_list.Add("VK_LAYER_bandicam_" #name);
|
||||
|
||||
VK_LAYER_BANDICAM_ADD(helper)
|
||||
}
|
||||
|
||||
inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||
inst_info.pNext = nullptr;
|
||||
@ -44,10 +78,14 @@ Instance *CreateInstance(const UTF8String &app_name,VKDebugOut *out)
|
||||
|
||||
if(vkCreateInstance(&inst_info,nullptr,&inst)==VK_SUCCESS)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if(!out)
|
||||
out=new VKDebugOut;
|
||||
#endif//_DEBUG
|
||||
|
||||
if(out)
|
||||
out->Init(inst);
|
||||
|
||||
out->Init(inst);
|
||||
return(new Instance(inst,out));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user