|
#include <stdio.h> |
|
#include <stdlib.h> |
|
#include <string.h> |
|
#include <stdbool.h> |
|
|
|
#define VK_USE_PLATFORM_WIN32_KHR |
|
#define GLFW_INCLUDE_NONE |
|
#define GLFW_INCLUDE_VULKAN |
|
#define GLFW_EXPOSE_NATIVE_WIN32 |
|
#include <GLFW/glfw3.h> |
|
#include <GLFW/glfw3native.h> |
|
#define CLAMP( x, min, max ) ( ( (x) < (min) ) ? (min) : ( ( (x) > (max) ) ? (max) : (x) ) ) |
|
|
|
GLFWwindow* window; |
|
|
|
VkInstance instance; |
|
//VkAllocationCallbacks *allocator = NULL; |
|
const VkAllocationCallbacks* allocatorCallBacks; |
|
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE; |
|
VkDevice device; |
|
// Check the surface proprties and formats. |
|
VkSurfaceCapabilitiesKHR surfaceCapabilities; |
|
VkSurfaceKHR surface; |
|
|
|
VkFormat swapChainImageFormat; |
|
VkExtent2D swapChainExtent; |
|
|
|
VkQueue presentQueue; |
|
|
|
VkSwapchainKHR swapChain; |
|
VkRenderPass renderPass; |
|
|
|
VkFramebuffer frameBuffer; |
|
VkDescriptorSetLayout descSetLayout; |
|
VkPipelineLayout pipeLayout; |
|
VkPipeline pipeline; |
|
|
|
// https://stackoverflow.com/questions/18205906/api-returning-a-structure |
|
//typedef struct { |
|
//uint32_t graphicsFamily; |
|
//bool isComplete(){ //nope |
|
//return graphicsFamily.has_value(); |
|
//} |
|
//} QueueFamilyIndices; |
|
|
|
typedef struct{ |
|
uint32_t graphicsFamily; |
|
uint32_t presentFamily; |
|
} QueueFamilyIndices; |
|
|
|
QueueFamilyIndices findQueueFamilies(VkPhysicalDevice _device) { |
|
QueueFamilyIndices indices; |
|
|
|
uint32_t queueFamilyCount = 0; |
|
vkGetPhysicalDeviceQueueFamilyProperties(_device, &queueFamilyCount, NULL); |
|
|
|
printf("_device queueFamilyCount %i\n",queueFamilyCount); |
|
|
|
VkQueueFamilyProperties *queueFamilies = (VkQueueFamilyProperties*)malloc(sizeof(VkQueueFamilyProperties*)*queueFamilyCount); |
|
vkGetPhysicalDeviceQueueFamilyProperties(_device, &queueFamilyCount, queueFamilies); |
|
|
|
for(int i = 0;i < queueFamilyCount;i++){ |
|
if (queueFamilies[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) { |
|
indices.graphicsFamily = i; |
|
//printf("queueFamilyCount >> %i\n",queueFamilyCount); |
|
//break; |
|
} |
|
|
|
//if (indices.graphicsFamily) { |
|
//printf("queueFamilyCount BREAK\n"); |
|
//break; |
|
//} |
|
} |
|
|
|
//std::vector<VkQueueFamilyProperties> queueFamilies(queueFamilyCount); |
|
//vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, queueFamilies.data()); |
|
|
|
return indices; |
|
} |
|
|
|
|
|
const char* validationLayers = { |
|
"VK_LAYER_KHRONOS_validation" |
|
}; |
|
#ifdef NDEBUG |
|
const bool enableValidationLayers = false; |
|
#else |
|
const bool enableValidationLayers = true; |
|
#endif |
|
|
|
// https://stackoverflow.com/questions/4180818/finding-the-length-of-a-character-array-in-c |
|
//returns the size of a character array using a pointer to the first element of the character array |
|
int size(const char** ptr) |
|
{ |
|
//variable used to access the subsequent array elements. |
|
int offset = 0; |
|
//variable that counts the number of elements in your array |
|
int count = 0; |
|
|
|
//While loop that tests whether the end of the array has been reached |
|
while (*(ptr + offset) != '\0') |
|
{ |
|
//increment the count variable |
|
++count; |
|
//advance to the next element of the array |
|
++offset; |
|
} |
|
//return the size of the array |
|
return count; |
|
} |
|
|
|
bool checkValidationLayerSupport() { |
|
uint32_t layerCount; |
|
vkEnumerateInstanceLayerProperties(&layerCount, NULL); |
|
printf("ValidationLayerSupport: %i\n",layerCount); |
|
|
|
VkLayerProperties *availableLayers = (VkLayerProperties*)malloc(layerCount * sizeof(VkLayerProperties)); |
|
|
|
vkEnumerateInstanceLayerProperties(&layerCount, availableLayers); |
|
printf("ValidationLayerSupport:> %i\n",layerCount); |
|
|
|
bool layerFound = false; |
|
for(int i =0; i < layerCount;i++){ |
|
printf("availableLayer Name: %s\n",availableLayers[i].layerName); |
|
//if (strcmp("VK_LAYER_KHRONOS_validation",availableLayers[i].layerName) == 0){ |
|
if (strcmp(validationLayers,availableLayers[i].layerName) == 0){ |
|
printf("FOUND ValidationLayerSupport >> %i\n", i); |
|
layerFound=true; |
|
break; |
|
} |
|
} |
|
return layerFound; |
|
//return false; |
|
} |
|
|
|
const char** getRequiredExtensions() { |
|
//void getRequiredExtensions() { |
|
uint32_t glfwExtensionCount = 0; |
|
const char** glfwExtensions; |
|
// VkLayerProperties *availableLayers = (VkLayerProperties*)malloc(layerCount * sizeof(VkLayerProperties)); |
|
glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount); |
|
//for(int i =0 ; i < glfwExtensionCount;i++){ |
|
//printf("glfwGetRequiredInstanceExtensions: %s\n", glfwExtensions[i]); |
|
//} |
|
if (enableValidationLayers) { |
|
const char** extensions = (char**)malloc((glfwExtensionCount + 1) * sizeof(char**)); |
|
//extensions[0] = glfwExtensions[0]; |
|
//extensions[1] = glfwExtensions[1]; |
|
//extensions[2] = VK_EXT_DEBUG_UTILS_EXTENSION_NAME; |
|
for(int e = 0; e < glfwExtensionCount; e++){ |
|
//printf("extensions: %s\n", extensions[e]);//will crash since it not assign string |
|
extensions[e] = glfwExtensions[e]; |
|
//printf("glfwGetRequiredInstanceExtensions: %s\n", glfwExtensions[ii]); |
|
} |
|
extensions[glfwExtensionCount+1] = VK_EXT_DEBUG_UTILS_EXTENSION_NAME; |
|
|
|
printf("enableValidationLayers TRUE\n"); |
|
//extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); |
|
return extensions; |
|
}else{ |
|
printf("enableValidationLayers FALSE\n"); |
|
return glfwExtensions; |
|
} |
|
//return extensions; |
|
} |
|
|
|
void initVukan(){ |
|
VkApplicationInfo appInfo; |
|
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
|
appInfo.pApplicationName = "Hello Triangle"; |
|
appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0); |
|
appInfo.pEngineName = "No Engine"; |
|
appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0); |
|
appInfo.apiVersion = VK_API_VERSION_1_0; |
|
|
|
VkInstanceCreateInfo instanceCreateInfo; |
|
instanceCreateInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; |
|
instanceCreateInfo.pApplicationInfo = &appInfo; |
|
|
|
uint32_t glfwExtensionCount = 0; |
|
const char** glfwExtensions; |
|
|
|
glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount); |
|
|
|
printf("glfwExtensionCount %i\n", glfwExtensionCount); |
|
|
|
//getRequiredExtensions(); |
|
|
|
const char** exts = getRequiredExtensions(); |
|
//size_t count = sizeof(exts); |
|
//printf("extensions: %s\n", exts[0]); |
|
//https://stackoverflow.com/questions/37538/how-do-i-determine-the-size-of-my-array-in-c |
|
//printf("exts %d\n", (int) sizeof(exts)); |
|
//printf("Length of array exts %d\n", (int) (sizeof(exts) / sizeof(char**)) ); |
|
//printf("Length of array exts %d\n", (int) (strlen(exts) ) );//nope |
|
printf("Length of array exts %d\n", (int) (size(exts) ) ); |
|
|
|
instanceCreateInfo.enabledExtensionCount = glfwExtensionCount; |
|
instanceCreateInfo.ppEnabledExtensionNames = glfwExtensions; |
|
instanceCreateInfo.enabledLayerCount = 0; |
|
instanceCreateInfo.pNext = NULL;//need to variable else it will crash |
|
|
|
printf("glfwExtensions: %s\n",glfwExtensions[0]); |
|
printf("glfwExtensions: %s\n",glfwExtensions[1]); |
|
|
|
//if (vkCreateInstance(&instanceCreateInfo, NULL, &instance) != VK_SUCCESS) { |
|
if (vkCreateInstance(&instanceCreateInfo, allocatorCallBacks, &instance) != VK_SUCCESS) { |
|
printf("failed to create instance!"); |
|
}else{ |
|
printf("create instance\n"); |
|
} |
|
|
|
checkValidationLayerSupport(); |
|
//=============================================== |
|
// |
|
//=============================================== |
|
// https://harrylovescode.gitbooks.io/vulkan-api/content/chap03/chap03.html |
|
VkPhysicalDevice phys[4]; |
|
uint32_t physCount = 4; |
|
vkEnumeratePhysicalDevices(instance, &physCount, phys); |
|
if (physCount == 0) { |
|
//throw std::runtime_error("failed to find GPUs with Vulkan support!"); |
|
printf("failed to find GPUs with Vulkan support!"); |
|
} |
|
printf("physCount %i\n",physCount); |
|
//by default it should be one graphic card |
|
for(int i = 0;i < physCount;i++){ |
|
//physicalDevice = phys[0]; |
|
physicalDevice = phys[i]; |
|
//need to check for physicalDevices |
|
break; |
|
} |
|
|
|
|
|
//physicalDevice = phys[0]; |
|
|
|
//findQueueFamilies(physicalDevice); |
|
|
|
VkPhysicalDeviceProperties deviceProperties; |
|
VkPhysicalDeviceFeatures deviceFeatures; |
|
vkGetPhysicalDeviceProperties(physicalDevice, &deviceProperties); |
|
vkGetPhysicalDeviceFeatures(physicalDevice, &deviceFeatures); |
|
|
|
printf("deviceName: %s\n",deviceProperties.deviceName); |
|
//printf("apiVersion: %d\n",deviceProperties.apiVersion); |
|
//printf("apiVersion: %d.%d.%d\n", |
|
//VK_VERSION_MAJOR(physicalProperties.apiVersion), |
|
//VK_VERSION_MINOR(physicalProperties.apiVersion), |
|
//VK_VERSION_PATCH(physicalProperties.apiVersion) |
|
//); |
|
//printf("driverVersion: %d\n",deviceProperties.driverVersion); |
|
//printf("vendorID: %d\n",deviceProperties.vendorID); |
|
|
|
uint32_t queueFamilyCount = 0; |
|
|
|
vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &queueFamilyCount, NULL); |
|
printf("QueueFamilyProperties: %i \n",queueFamilyCount); |
|
|
|
|
|
//=============================================== |
|
// DEVICE |
|
//=============================================== |
|
float priorities[] = { 1.0f }; |
|
VkDeviceQueueCreateInfo queueInfo; |
|
queueInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; |
|
queueInfo.pNext = NULL; |
|
queueInfo.flags = 0; |
|
queueInfo.queueFamilyIndex = 0; |
|
queueInfo.queueCount = 1; |
|
queueInfo.pQueuePriorities = &priorities[0]; |
|
|
|
const char * enabledExtensions[] = { VK_KHR_SWAPCHAIN_EXTENSION_NAME }; |
|
VkDeviceCreateInfo deviceInfo; |
|
deviceInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; |
|
deviceInfo.pNext = NULL; |
|
deviceInfo.flags = 0; |
|
deviceInfo.queueCreateInfoCount = 1; |
|
deviceInfo.pQueueCreateInfos = &queueInfo; |
|
//deviceInfo.enabledExtensionCount = enabledExtensions.size(); |
|
//deviceInfo.ppEnabledExtensionNames = enabledExtensions.data(); |
|
deviceInfo.enabledExtensionCount = 1; |
|
deviceInfo.ppEnabledExtensionNames = enabledExtensions; |
|
deviceInfo.pEnabledFeatures = NULL; |
|
|
|
if (vkCreateDevice(physicalDevice, &deviceInfo, NULL, &device) != VK_SUCCESS) { |
|
printf("failed to create device!"); |
|
}else{ |
|
printf("create device\n"); |
|
} |
|
|
|
//=============================================== |
|
// SURFACE |
|
//=============================================== |
|
VkWin32SurfaceCreateInfoKHR surfaceCreateInfo; |
|
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR; |
|
surfaceCreateInfo.hwnd = glfwGetWin32Window(window); |
|
surfaceCreateInfo.hinstance = GetModuleHandle(NULL); |
|
surfaceCreateInfo.flags = 0; |
|
surfaceCreateInfo.pNext = NULL; |
|
|
|
if (vkCreateWin32SurfaceKHR(instance, &surfaceCreateInfo, NULL, &surface) != VK_SUCCESS){ |
|
printf("failed to create window surface!\n"); |
|
}else{ |
|
printf("create window surface!\n"); |
|
} |
|
|
|
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice,surface,&surfaceCapabilities); |
|
//=============================================== |
|
// SWAPCHAIN |
|
//=============================================== |
|
|
|
uint32_t width = 640; |
|
uint32_t height = 480; |
|
VkExtent2D swapchainExtent = |
|
{ |
|
CLAMP( (uint32_t)width, surfaceCapabilities.minImageExtent.width, surfaceCapabilities.maxImageExtent.width ), |
|
CLAMP( (uint32_t)height, surfaceCapabilities.minImageExtent.height, surfaceCapabilities.maxImageExtent.height ), |
|
}; |
|
|
|
VkExtent2D surfaceResolution = surfaceCapabilities.currentExtent; |
|
|
|
uint32_t surfaceFormatCount = 0; |
|
vkGetPhysicalDeviceSurfaceFormatsKHR( physicalDevice, surface, &surfaceFormatCount, NULL ); |
|
printf("surfaceFormatCount %i\n",surfaceFormatCount); |
|
VkSurfaceFormatKHR *surfaceFormats= (VkSurfaceFormatKHR*)malloc(sizeof(VkSurfaceFormatKHR*)*surfaceFormatCount); |
|
vkGetPhysicalDeviceSurfaceFormatsKHR( physicalDevice, surface, &surfaceFormatCount, surfaceFormats); |
|
VkFormat colorFormat; |
|
if( surfaceFormatCount == 1 && surfaceFormats[0].format == VK_FORMAT_UNDEFINED ) { |
|
colorFormat = VK_FORMAT_B8G8R8_UNORM; |
|
} else { |
|
colorFormat = surfaceFormats[0].format; |
|
} |
|
//IMAGE |
|
swapChainImageFormat=surfaceFormats[0].format; |
|
swapChainExtent =surfaceCapabilities.currentExtent; |
|
|
|
VkColorSpaceKHR colorSpace; |
|
colorSpace = surfaceFormats[0].colorSpace; |
|
VkSurfaceFormatKHR surfaceFormat; |
|
surfaceFormat = surfaceFormats[0]; |
|
VkPresentModeKHR presentMode = VK_PRESENT_MODE_FIFO_KHR; |
|
|
|
uint32_t desiredImageCount = 2; |
|
if( desiredImageCount < surfaceCapabilities.minImageCount ) { |
|
desiredImageCount = surfaceCapabilities.minImageCount; |
|
} else if( surfaceCapabilities.maxImageCount != 0 && desiredImageCount > surfaceCapabilities.maxImageCount ) { |
|
desiredImageCount = surfaceCapabilities.maxImageCount; |
|
} |
|
VkSurfaceTransformFlagBitsKHR preTransform; |
|
if ( surfaceCapabilities.supportedTransforms & VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR ){ |
|
preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; |
|
}else{ |
|
preTransform = surfaceCapabilities.currentTransform; |
|
} |
|
|
|
VkSwapchainCreateInfoKHR swapCreateInfo; |
|
swapCreateInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
|
swapCreateInfo.surface = surface; |
|
swapCreateInfo.minImageCount = desiredImageCount; |
|
swapCreateInfo.imageFormat = colorFormat; |
|
swapCreateInfo.imageColorSpace = colorSpace; |
|
swapCreateInfo.imageExtent = surfaceResolution; |
|
swapCreateInfo.imageArrayLayers = 1; |
|
swapCreateInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
|
swapCreateInfo.flags = 0; |
|
swapCreateInfo.imageSharingMode=VK_SHARING_MODE_EXCLUSIVE; |
|
swapCreateInfo.preTransform = preTransform; |
|
swapCreateInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; |
|
swapCreateInfo.presentMode= VK_PRESENT_MODE_FIFO_KHR; |
|
swapCreateInfo.clipped = VK_TRUE; |
|
swapCreateInfo.oldSwapchain = VK_NULL_HANDLE; |
|
swapCreateInfo.pNext=NULL; |
|
//system("pause"); |
|
//swapChain |
|
if (vkCreateSwapchainKHR(device, &swapCreateInfo, NULL, &swapChain) != VK_SUCCESS){ |
|
printf("failed to create swapChain!\n"); |
|
}else{ |
|
printf("create swapChain!\n"); |
|
} |
|
|
|
//=============================================== |
|
// SWAPCHAIN IMAGES NOT WORKING... |
|
//=============================================== |
|
//this should be properly enumerated |
|
//VkImage swapChainImages; |
|
uint32_t swapChainImageCount; |
|
|
|
vkGetSwapchainImagesKHR(device, swapChain, &swapChainImageCount, NULL); |
|
printf("swapChainImageCount %i\n",swapChainImageCount); |
|
|
|
VkImage *swapChainImages= (VkImage*)malloc(sizeof(VkImage*)*swapChainImageCount); |
|
vkGetSwapchainImagesKHR(device, swapChain, &swapChainImageCount, swapChainImages); |
|
|
|
VkImageView *swapChainImageViews = (VkImageView*)malloc(sizeof(VkImageView*)*swapChainImageCount); |
|
|
|
/* |
|
for (int ii = 0; ii < swapChainImageCount; ii++) { |
|
VkImageViewCreateInfo imageViewCreateInfo; |
|
imageViewCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
|
imageViewCreateInfo.image = swapChainImages[ii]; |
|
imageViewCreateInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; |
|
imageViewCreateInfo.format = swapChainImageFormat; |
|
imageViewCreateInfo.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; |
|
imageViewCreateInfo.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; |
|
imageViewCreateInfo.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; |
|
imageViewCreateInfo.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; |
|
imageViewCreateInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
|
imageViewCreateInfo.subresourceRange.baseMipLevel = 0; |
|
imageViewCreateInfo.subresourceRange.levelCount = 1; |
|
imageViewCreateInfo.subresourceRange.baseArrayLayer = 0; |
|
imageViewCreateInfo.subresourceRange.layerCount = 1; |
|
|
|
|
|
if (vkCreateImageView(device, &imageViewCreateInfo, NULL, &swapChainImageViews[ii]) != VK_SUCCESS){ |
|
printf("failed to create swapChainImageViews!\n"); |
|
}else{ |
|
printf("create swapChainImageViews!\n"); |
|
} |
|
} |
|
*/ |
|
|
|
// Synchronisation is needed here! |
|
//uint32_t currentSwapImage; |
|
//vkAcquireNextImageKHR(device, swapChain, UINT64_MAX, presentCompleteSemaphore, NULL, ¤tSwapImage); |
|
|
|
// pass appropriate creation info to create view of image |
|
//VkImageView backbufferView; |
|
//vkCreateImageView(device, &backbufferViewCreateInfo, NULL, &backbufferView); |
|
|
|
VkQueue queue; |
|
vkGetDeviceQueue(device, 0, 0, &queue); |
|
|
|
//=============================================== |
|
// RENDER PASS not working... |
|
//=============================================== |
|
//VkRenderPassCreateInfo renderpassCreateInfo = { |
|
// here you will specify the total list of attachments |
|
// (which in this case is just one, that's e.g. R8G8B8A8_UNORM) |
|
// as well as describe a single subpass, using that attachment |
|
// for color and with no depth-stencil attachment |
|
//}; |
|
//VkRenderPassCreateInfo renderpassCreateInfo; |
|
|
|
VkAttachmentDescription colorAttachment; |
|
//colorAttachment.format = swapChainImageFormat; |
|
colorAttachment.format = VK_FORMAT_B8G8R8A8_SRGB; |
|
colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT; |
|
colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
|
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE; |
|
colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
|
colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
|
colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
|
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; |
|
|
|
VkAttachmentReference colorAttachmentRef; |
|
colorAttachmentRef.attachment = 0; |
|
colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
|
|
|
VkSubpassDescription subpass; |
|
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; |
|
subpass.colorAttachmentCount = 1; |
|
subpass.pColorAttachments = &colorAttachmentRef; |
|
|
|
VkRenderPassCreateInfo renderPassInfo; |
|
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
|
renderPassInfo.attachmentCount = 1; |
|
renderPassInfo.pAttachments = &colorAttachment; |
|
renderPassInfo.subpassCount = 1; |
|
renderPassInfo.pSubpasses = &subpass; |
|
|
|
if(vkCreateRenderPass(device, &renderPassInfo, NULL, &renderPass) != VK_SUCCESS) { |
|
printf("failed to create vkCreateRenderPass!\n"); |
|
}else{ |
|
printf("create vkCreateRenderPass\n"); |
|
} |
|
|
|
//=============================================== |
|
// FRAME BUFFER |
|
//=============================================== |
|
|
|
//VkFramebufferCreateInfo framebufferCreateInfo = { |
|
// include backbufferView here to render to, and renderpass to be |
|
// compatible with. |
|
//}; |
|
//VkFramebufferCreateInfo framebufferCreateInfo; |
|
|
|
|
|
//if(vkCreateFramebuffer(device, &framebufferCreateInfo, NULL, &frameBuffer) != VK_SUCCESS) { |
|
//printf("failed to create Framebuffer!\n"); |
|
//}else{ |
|
//printf("Create Framebuffer\n"); |
|
//} |
|
|
|
//=============================================== |
|
// Descriptor Set Layout |
|
//=============================================== |
|
//VkDescriptorSetLayoutCreateInfo descSetLayoutCreateInfo = { |
|
// whatever we want to match our shader. e.g. Binding 0 = UBO for a simple |
|
// case with just a vertex shader UBO with transform data. |
|
//}; |
|
|
|
//VkDescriptorSetLayoutCreateInfo descSetLayoutCreateInfo; |
|
|
|
//if(vkCreateDescriptorSetLayout(device, &descSetLayoutCreateInfo, NULL, &descSetLayout) != VK_SUCCESS) { |
|
//printf("failed to create DescriptorSetLayout!\n"); |
|
//}else{ |
|
//printf("Create DescriptorSetLayout\n"); |
|
//} |
|
//=============================================== |
|
// Descriptor Set Layout |
|
//=============================================== |
|
//VkPipelineCreateInfo pipeLayoutCreateInfo = { |
|
// one descriptor set, with layout descSetLayout |
|
//}; |
|
//VkPipelineCacheCreateInfo pipeLayoutCreateInfo; |
|
|
|
//VkPipelineLayout pipeLayout; |
|
//vkCreatePipelineLayout(device, &pipeLayoutCreateInfo, NULL, &pipeLayout); |
|
|
|
|
|
//=============================================== |
|
// SHADER |
|
//=============================================== |
|
// upload the SPIR-V shaders |
|
//VkShaderModule vertModule, fragModule; |
|
//vkCreateShaderModule(device, &vertModuleInfoWithSPIRV, NULL, &vertModule); |
|
//vkCreateShaderModule(device, &fragModuleInfoWithSPIRV, NULL, &fragModule); |
|
|
|
//=============================================== |
|
// Graphics Pipeline |
|
//=============================================== |
|
//VkGraphicsPipelineCreateInfo pipeCreateInfo = { |
|
// there are a LOT of sub-structures under here to fully specify |
|
// the PSO state. It will reference vertModule, fragModule and pipeLayout |
|
// as well as renderpass for compatibility |
|
//}; |
|
//VkGraphicsPipelineCreateInfo pipeCreateInfo; |
|
|
|
//VkPipeline pipeline; |
|
//vkCreateGraphicsPipelines(device, NULL, 1, &pipeCreateInfo, NULL, &pipeline); |
|
//=============================================== |
|
// Descriptor Pool |
|
//=============================================== |
|
//VkDescriptorPoolCreateInfo descPoolCreateInfo = { |
|
// the creation info states how many descriptor sets are in this pool |
|
//}; |
|
|
|
//VkDescriptorPool descPool; |
|
//vkCreateDescriptorPool(device, &descPoolCreateInfo, NULL, &descPool); |
|
//=============================================== |
|
// Descriptor Set Allocate |
|
//=============================================== |
|
//VkDescriptorSetAllocateInfo descAllocInfo = { |
|
// from pool descPool, with layout descSetLayout |
|
//}; |
|
|
|
//VkDescriptorSet descSet; |
|
//vkAllocateDescriptorSets(device, &descAllocInfo, &descSet); |
|
//=============================================== |
|
// Buffer, Memory Allocate |
|
//=============================================== |
|
//VkBufferCreateInfo bufferCreateInfo = { |
|
// buffer for uniform usage, of appropriate size |
|
//}; |
|
|
|
//VkMemoryAllocateInfo memAllocInfo = { |
|
// skipping querying for memory requirements. Let's assume the buffer |
|
// can be placed in host visible memory. |
|
//}; |
|
//VkBuffer buffer; |
|
//VkDeviceMemory memory; |
|
//vkCreateBuffer(device, &bufferCreateInfo, NULL, &buffer); |
|
//vkAllocateMemory(device, &memAllocInfo, NULL, &memory); |
|
//vkBindBufferMemory(device, buffer, memory, 0); |
|
|
|
//void *data = NULL; |
|
//vkMapMemory(device, memory, 0, VK_WHOLE_SIZE, 0, &data); |
|
// fill data pointer with lovely transform goodness |
|
//vkUnmapMemory(device, memory); |
|
|
|
//=============================================== |
|
// Write Descriptor Set |
|
//=============================================== |
|
//VkWriteDescriptorSet descriptorWrite = { |
|
// write the details of our UBO buffer into binding 0 |
|
//}; |
|
|
|
//vkUpdateDescriptorSets(device, 1, &descriptorWrite, 0, NULL); |
|
|
|
//=============================================== |
|
// // |
|
//=============================================== |
|
|
|
|
|
|
|
//=============================================== |
|
// |
|
//=============================================== |
|
|
|
|
|
|
|
|
|
} |
|
|
|
void cleanup() { |
|
//vkDestroySurfaceKHR(instance, surface, NULL); |
|
//vkDestroyInstance(instance, NULL); |
|
//vkDestroyDevice(device, NULL); |
|
} |
|
|
|
int main(const int argc, const char *argv[]) { |
|
//GLFWwindow* window; |
|
|
|
// Initialize the library |
|
if (!glfwInit()) |
|
return -1; |
|
|
|
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); |
|
|
|
// Create a windowed mode window and its OpenGL context |
|
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL); |
|
if (!window) |
|
{ |
|
glfwTerminate(); |
|
return -1; |
|
} |
|
|
|
// Setup Vulkan |
|
if (!glfwVulkanSupported()) |
|
{ |
|
printf("GLFW: Vulkan Not Supported\n"); |
|
return 1; |
|
}else{ |
|
printf("GLFW: Vulkan Supported\n"); |
|
} |
|
initVukan(); |
|
//createInstance(); |
|
//pickPhysicalDevice(); |
|
//createLogicalDevice(); |
|
//createSurface(); |
|
//createSwapChain(); |
|
//createImageViews(); |
|
//createRenderPass(); |
|
//createDescriptorSetLayout(); |
|
//createGraphicsPipeline(); |
|
//createFramebuffers(); |
|
//createCommandPool(); |
|
//createVertexBuffer(); |
|
//createIndexBuffer(); |
|
//createUniformBuffers(); |
|
//createDescriptorPool(); |
|
//createDescriptorSets(); |
|
//createCommandBuffers(); |
|
//createSyncObjects(); |
|
|
|
|
|
|
|
|
|
//system("pause"); |
|
// Create Window Surface |
|
//VkSurfaceKHR surface; |
|
//VkResult err = glfwCreateWindowSurface(instance, window, g_Allocator, &surface); |
|
//if (err) |
|
//{ |
|
// Window surface creation failed |
|
//printf("GLFW: Window surface creation failed\n"); |
|
//}else{ |
|
//printf("GLFW: Window Vulkan surface created!\n"); |
|
//} |
|
|
|
// Create Framebuffers |
|
//int w, h; |
|
//glfwGetFramebufferSize(window, &w, &h); |
|
|
|
/* Make the window's context current */ |
|
glfwMakeContextCurrent(window); |
|
|
|
// Loop until the user closes the window |
|
while (!glfwWindowShouldClose(window)) |
|
{ |
|
// Poll for and process events |
|
glfwPollEvents(); |
|
|
|
//Swap front and back buffers |
|
glfwSwapBuffers(window); |
|
} |
|
|
|
|
|
cleanup(); |
|
glfwDestroyWindow(window); |
|
glfwTerminate(); |
|
|
|
return 0; |
|
} |