|
|
|
@ -0,0 +1,147 @@
@@ -0,0 +1,147 @@
|
|
|
|
|
// triangle.cpp: 定义应用程序的入口点。
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#include "triangle.h" |
|
|
|
|
#include <vulkan/vulkan.h> |
|
|
|
|
#include <iostream> |
|
|
|
|
|
|
|
|
|
using namespace std; |
|
|
|
|
|
|
|
|
|
int main() |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
VkInstance vkins; |
|
|
|
|
|
|
|
|
|
VkApplicationInfo appinfo = {}; |
|
|
|
|
VkInstanceCreateInfo inscrtinfo = {}; |
|
|
|
|
VkResult ret; |
|
|
|
|
appinfo.apiVersion = VK_MAKE_API_VERSION(1, 1, 2, 0); |
|
|
|
|
appinfo.applicationVersion = VK_MAKE_VERSION(1, 2, 0); |
|
|
|
|
appinfo.engineVersion = VK_MAKE_VERSION(0, 0, 1); |
|
|
|
|
appinfo.pApplicationName = "testapp"; |
|
|
|
|
appinfo.pEngineName = "testengine"; |
|
|
|
|
appinfo.pNext = nullptr; |
|
|
|
|
appinfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
|
|
|
|
|
|
|
|
|
inscrtinfo.enabledExtensionCount = 0; |
|
|
|
|
inscrtinfo.enabledLayerCount = 0; |
|
|
|
|
inscrtinfo.flags = { }; |
|
|
|
|
inscrtinfo.pApplicationInfo = &appinfo; |
|
|
|
|
inscrtinfo.pNext = nullptr; |
|
|
|
|
inscrtinfo.ppEnabledExtensionNames = nullptr; |
|
|
|
|
inscrtinfo.ppEnabledLayerNames = nullptr; |
|
|
|
|
inscrtinfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; |
|
|
|
|
|
|
|
|
|
vkCreateInstance(&inscrtinfo, nullptr, &vkins); |
|
|
|
|
if (vkins == nullptr) { |
|
|
|
|
std::cout << "create instance failed" << std::endl; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
uint32_t devicenum; |
|
|
|
|
ret = vkEnumeratePhysicalDevices(vkins, &devicenum, nullptr); |
|
|
|
|
if (ret != VK_SUCCESS) { |
|
|
|
|
std::cout << "get device failed " << std::endl; |
|
|
|
|
return -2; |
|
|
|
|
} |
|
|
|
|
if (devicenum == 0) { |
|
|
|
|
std::cout << "no device found " << std::endl; |
|
|
|
|
return -2; |
|
|
|
|
} |
|
|
|
|
std::cout << "device nums " << devicenum << std::endl; |
|
|
|
|
VkPhysicalDevice vkpdevice; |
|
|
|
|
|
|
|
|
|
ret = vkEnumeratePhysicalDevices(vkins, &devicenum, &vkpdevice); |
|
|
|
|
if (ret != VK_SUCCESS) { |
|
|
|
|
std::cout << "" << std::endl; |
|
|
|
|
} |
|
|
|
|
uint32_t vkqnum; |
|
|
|
|
VkQueueFamilyProperties* qfprop; |
|
|
|
|
vkGetPhysicalDeviceQueueFamilyProperties(vkpdevice, &vkqnum, nullptr); |
|
|
|
|
if (vkqnum == 0) { |
|
|
|
|
std::cout << " " << std::endl; |
|
|
|
|
} |
|
|
|
|
qfprop = (VkQueueFamilyProperties*)malloc(sizeof(VkQueueFamilyProperties) * vkqnum); |
|
|
|
|
vkGetPhysicalDeviceQueueFamilyProperties(vkpdevice, &vkqnum, qfprop); |
|
|
|
|
for (int i = 0; i < vkqnum; i++) { |
|
|
|
|
std::cout << "queue " << i << " flags =" << qfprop[i].queueFlags << ", num " << qfprop[i].queueCount << std::endl; |
|
|
|
|
std::cout << " timestamp " << qfprop[i].timestampValidBits << std::endl; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VkDevice vkd = {}; |
|
|
|
|
VkDeviceCreateInfo vkdcinfo = {}; |
|
|
|
|
VkDeviceQueueCreateInfo vkdqcinfo = {}; |
|
|
|
|
vkdcinfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; |
|
|
|
|
vkdcinfo.pNext = nullptr; |
|
|
|
|
vkdcinfo.flags = 0; |
|
|
|
|
|
|
|
|
|
vkdqcinfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; |
|
|
|
|
vkdqcinfo.flags = 0; |
|
|
|
|
vkdqcinfo.queueFamilyIndex = 0; |
|
|
|
|
vkdqcinfo.queueCount = 4; |
|
|
|
|
vkdqcinfo.pQueuePriorities = nullptr; |
|
|
|
|
|
|
|
|
|
vkdcinfo.queueCreateInfoCount = 1; |
|
|
|
|
vkdcinfo.pQueueCreateInfos = &vkdqcinfo; |
|
|
|
|
vkdcinfo.enabledExtensionCount = 0; |
|
|
|
|
vkdcinfo.enabledLayerCount = 0; |
|
|
|
|
vkdcinfo.ppEnabledExtensionNames = nullptr; |
|
|
|
|
vkdcinfo.ppEnabledLayerNames = nullptr; |
|
|
|
|
vkdcinfo.pEnabledFeatures = nullptr; |
|
|
|
|
|
|
|
|
|
vkCreateDevice(vkpdevice, &vkdcinfo, nullptr, &vkd); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t propcount; |
|
|
|
|
VkLayerProperties* props; |
|
|
|
|
|
|
|
|
|
vkEnumerateInstanceLayerProperties(&propcount, nullptr); |
|
|
|
|
std::cout << "line at " << __LINE__ << "\t" << propcount << std::endl; |
|
|
|
|
props = (VkLayerProperties*)malloc(sizeof(VkLayerProperties) * propcount); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vkEnumerateInstanceLayerProperties(&propcount, props); |
|
|
|
|
for (int i = 0; i < propcount; i++) { |
|
|
|
|
std::cout << props[i].layerName << " " << props[i].specVersion << " " << |
|
|
|
|
props[i].implementationVersion << " " << props[i].description << std::endl; |
|
|
|
|
} |
|
|
|
|
std::cout << " \n \n \n"; |
|
|
|
|
uint32_t nums; |
|
|
|
|
vkEnumerateDeviceLayerProperties(vkpdevice, &nums, nullptr); |
|
|
|
|
props = (VkLayerProperties*)malloc(sizeof(VkLayerProperties) * nums); |
|
|
|
|
vkEnumerateDeviceLayerProperties(vkpdevice, &nums, props); |
|
|
|
|
for (int i = 0; i < nums; i++) { |
|
|
|
|
std::cout << props[i].layerName << " " << props[i].specVersion << " " << |
|
|
|
|
props[i].implementationVersion << " " << props[i].description << std::endl; |
|
|
|
|
} |
|
|
|
|
std::cout << "\n\n\n"; |
|
|
|
|
VkExtensionProperties* extprops; |
|
|
|
|
vkEnumerateInstanceExtensionProperties(nullptr, &nums, nullptr); |
|
|
|
|
extprops = (VkExtensionProperties*)malloc(sizeof(VkExtensionProperties) * nums); |
|
|
|
|
vkEnumerateInstanceExtensionProperties(nullptr, &nums, extprops); |
|
|
|
|
for (int i = 0; i < nums; i++) { |
|
|
|
|
std::cout << extprops[i].extensionName << " " << extprops[i].specVersion << std::endl; |
|
|
|
|
} |
|
|
|
|
std::cout << "\n\n\n"; |
|
|
|
|
vkEnumerateDeviceExtensionProperties(vkpdevice, nullptr, &nums, nullptr); |
|
|
|
|
extprops = (VkExtensionProperties*)malloc(sizeof(VkExtensionProperties) * nums); |
|
|
|
|
vkEnumerateDeviceExtensionProperties(vkpdevice, nullptr, &nums, extprops); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < nums; i++) { |
|
|
|
|
std::cout << extprops[i].extensionName << " " << extprops[i].specVersion << std::endl; |
|
|
|
|
} |
|
|
|
|
std::cout << "\n\n\n" ; |
|
|
|
|
char* msg = (char*)malloc(1024 * 4); |
|
|
|
|
vkGetInstanceProcAddr(vkins, msg); |
|
|
|
|
std::cout << "msg = " << msg << std::endl; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vkDeviceWaitIdle(vkd); |
|
|
|
|
vkDestroyDevice(vkd, nullptr); |
|
|
|
|
vkDestroyInstance(vkins, nullptr); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cout << "Hello CMake." << endl; |
|
|
|
|
return 0; |
|
|
|
|
} |