2019-08-15 11:00:15 +08:00
|
|
|
|
#include<iostream>
|
|
|
|
|
#include<hgl/graph/vulkan/VK.h>
|
|
|
|
|
#include<hgl/graph/vulkan/VKDevice.h>
|
|
|
|
|
#include<hgl/graph/vulkan/VKInstance.h>
|
|
|
|
|
|
|
|
|
|
using namespace hgl;
|
|
|
|
|
using namespace hgl::graph;
|
2019-08-13 17:08:37 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_USING;
|
|
|
|
|
|
2019-08-14 16:36:02 +08:00
|
|
|
|
constexpr char *texture_compress_name[]=
|
|
|
|
|
{
|
|
|
|
|
"NONE",
|
|
|
|
|
"S3TC",
|
|
|
|
|
"PVRTC",
|
|
|
|
|
"ETC1",
|
|
|
|
|
"ETC2",
|
|
|
|
|
"EAC",
|
|
|
|
|
"ATC",
|
|
|
|
|
"ASTC",
|
|
|
|
|
"YUV"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
constexpr char *data_type_name[]
|
|
|
|
|
{
|
|
|
|
|
"NONE",
|
|
|
|
|
"UNORM",
|
|
|
|
|
"SNORM",
|
|
|
|
|
"USCALED",
|
|
|
|
|
"SSCALED",
|
|
|
|
|
"UINT",
|
|
|
|
|
"SINT",
|
|
|
|
|
"UFLOAT",
|
|
|
|
|
"SFLOAT",
|
|
|
|
|
"SRGB"
|
|
|
|
|
};//
|
|
|
|
|
|
2019-11-13 19:55:13 +08:00
|
|
|
|
vulkan::Instance *InitVulkanInstance()
|
2019-08-13 17:08:37 +08:00
|
|
|
|
{
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
if(!CheckStrideBytesByFormat())
|
|
|
|
|
{
|
|
|
|
|
std::cerr<<"check stride bytes by format failed."<<std::endl;
|
2019-11-13 19:55:13 +08:00
|
|
|
|
return(nullptr);
|
2019-08-13 17:08:37 +08:00
|
|
|
|
}
|
|
|
|
|
#endif//_DEBUG
|
|
|
|
|
|
2019-08-15 11:00:15 +08:00
|
|
|
|
InitNativeWindowSystem();
|
|
|
|
|
|
2019-11-06 20:52:09 +08:00
|
|
|
|
InitVulkanProperties();
|
|
|
|
|
|
2019-11-13 19:55:13 +08:00
|
|
|
|
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;
|
2019-11-14 17:57:46 +08:00
|
|
|
|
vulkan::Instance * inst =nullptr;
|
2019-11-13 19:55:13 +08:00
|
|
|
|
vulkan::Device * device =nullptr;
|
|
|
|
|
const vulkan::PhysicalDevice *physical_device =nullptr;
|
|
|
|
|
|
|
|
|
|
inst=InitVulkanInstance();
|
2019-08-15 11:00:15 +08:00
|
|
|
|
|
|
|
|
|
if(!inst)
|
2019-11-13 19:55:13 +08:00
|
|
|
|
{
|
|
|
|
|
std::cerr<<"[VULKAN FATAL ERROR] Create Vulkan Instance failed.";
|
2019-08-15 11:00:15 +08:00
|
|
|
|
return(false);
|
2019-11-13 19:55:13 +08:00
|
|
|
|
}
|
2019-08-15 11:00:15 +08:00
|
|
|
|
|
2019-11-13 16:01:13 +08:00
|
|
|
|
physical_device=inst->GetDevice(VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU);
|
2019-08-15 11:00:15 +08:00
|
|
|
|
|
2019-11-13 16:01:13 +08:00
|
|
|
|
if(!physical_device)
|
|
|
|
|
physical_device=inst->GetDevice(VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU);
|
2019-08-15 11:00:15 +08:00
|
|
|
|
|
2019-08-14 16:36:02 +08:00
|
|
|
|
uint32_t count;
|
|
|
|
|
const VulkanFormat *vf=GetVulkanFormatList(count);
|
|
|
|
|
|
|
|
|
|
if(!count)return(255);
|
|
|
|
|
|
|
|
|
|
for(uint32_t i=0;i<count;i++)
|
2019-08-13 17:08:37 +08:00
|
|
|
|
{
|
2019-08-14 16:36:02 +08:00
|
|
|
|
std::cout<<i<<". ";
|
|
|
|
|
|
|
|
|
|
std::cout<<" Format [ID:"<<vf->format<<"]["<<vf->name<<"] ";
|
|
|
|
|
|
|
|
|
|
if(vf->compress_type!=TextureCompressType::NONE)
|
|
|
|
|
std::cout<<"use "<<texture_compress_name[size_t(vf->compress_type)]<<" compress.";
|
|
|
|
|
else
|
|
|
|
|
std::cout<<vf->bytes<<" bytes/pixel.";
|
|
|
|
|
|
|
|
|
|
if(vf->depth!=VulkanDataType::NONE)
|
|
|
|
|
std::cout<<"[Depth:"<<data_type_name[size_t(vf->depth)]<<"]";
|
|
|
|
|
|
|
|
|
|
if(vf->stencil!=VulkanDataType::NONE)
|
|
|
|
|
std::cout<<"[Stencil:"<<data_type_name[size_t(vf->stencil)]<<"]";
|
|
|
|
|
|
|
|
|
|
if((vf->depth==VulkanDataType::NONE)
|
|
|
|
|
&&(vf->stencil==VulkanDataType::NONE))
|
|
|
|
|
std::cout<<"[Color:"<<data_type_name[size_t(vf->color)]<<"]";
|
2019-08-15 11:00:15 +08:00
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const VkFormatProperties fp=physical_device->GetFormatProperties(vf->format);
|
|
|
|
|
|
|
|
|
|
if(fp.optimalTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
|
|
|
|
|
std::cout<<"[Optimal]";
|
|
|
|
|
if(fp.linearTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
|
|
|
|
|
std::cout<<"[Linear]";
|
|
|
|
|
if(fp.bufferFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
|
|
|
|
|
std::cout<<"[Buffer]";
|
|
|
|
|
}
|
2019-08-14 16:36:02 +08:00
|
|
|
|
|
|
|
|
|
std::cout<<std::endl;
|
2019-08-13 17:08:37 +08:00
|
|
|
|
|
2019-08-14 16:36:02 +08:00
|
|
|
|
++vf;
|
2019-08-13 17:08:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-15 11:00:15 +08:00
|
|
|
|
delete inst;
|
2019-11-13 16:01:13 +08:00
|
|
|
|
|
2019-08-13 17:08:37 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|