Browse Source

添加项目文件。

master
zara 1 year ago
parent
commit
490eeef4d2
  1. 15
      CMakeLists.txt
  2. 61
      CMakePresets.json
  3. 19
      triangle/CMakeLists.txt
  4. 147
      triangle/triangle.cpp
  5. 8
      triangle/triangle.h

15
CMakeLists.txt

@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
# CMakeList.txt: CMake
#
#
cmake_minimum_required (VERSION 3.8)
# MSVC
if (POLICY CMP0141)
cmake_policy(SET CMP0141 NEW)
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
endif()
project ("triangle")
#
add_subdirectory ("triangle")

61
CMakePresets.json

@ -0,0 +1,61 @@ @@ -0,0 +1,61 @@
{
"version": 3,
"configurePresets": [
{
"name": "windows-base",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_C_COMPILER": "cl.exe",
"CMAKE_CXX_COMPILER": "cl.exe"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "x64-debug",
"displayName": "x64 Debug",
"inherits": "windows-base",
"architecture": {
"value": "x64",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "x64-release",
"displayName": "x64 Release",
"inherits": "x64-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "x86-debug",
"displayName": "x86 Debug",
"inherits": "windows-base",
"architecture": {
"value": "x86",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "x86-release",
"displayName": "x86 Release",
"inherits": "x86-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
}
]
}

19
triangle/CMakeLists.txt

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
# CMakeList.txt: triangle CMake
#
#
#
add_executable (triangle "triangle.cpp" "triangle.h")
if (CMAKE_VERSION VERSION_GREATER 3.12)
set_property(TARGET triangle PROPERTY CXX_STANDARD 20)
endif()
find_package(Vulkan)
if(${Vulkan_FOUND})
target_link_libraries(${PROJECT_NAME} ${Vulkan_LIBRARIES})
target_include_directories(${PROJECT_NAME} PRIVATE ${Vulkan_INCLUDE_DIRS})
endif()
# TODO:

147
triangle/triangle.cpp

@ -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;
}

8
triangle/triangle.h

@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
// triangle.h: 标准系统包含文件的包含文件
// 或项目特定的包含文件。
#pragma once
#include <iostream>
// TODO: 在此处引用程序需要的其他标头。
Loading…
Cancel
Save