// Load Vertex Shader (SPIR-V) to memory
unsigned long size;
void* pVertex = Win32_FileLoader(L"vert.spv", &size);
VkShaderModuleCreateInfo moduleInfo = {};
moduleInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
moduleInfo.codeSize = size;
moduleInfo.pCode = (uint32_t*)pVertex;
// Create Vertex Shader Module
VkShaderModule vertexModule;
res = vkCreateShaderModule(_VkSystem.device, &moduleInfo, 0, &vertexModule);
if (res != VK_SUCCESS)
return 1;
// Setup Stage info for the Vertex Shader
VkPipelineShaderStageCreateInfo stageInfo = {};
stageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
stageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT;
stageInfo.pName = "main";
stageInfo.module = vertexModule;
VkPipelineLayoutCreateInfo layoutInfo = {};
layoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
// Create the Pipeline Layout
VkPipelineLayout pipeLayout;
res = vkCreatePipelineLayout(_VkSystem.device, &layoutInfo, 0, &pipeLayout);
if (res != VK_SUCCESS)
return 1;
VkViewport viewPort = {};
viewPort.width = 1280;
viewPort.height = 720;
VkRect2D scissors = {};
scissors.extent.width = viewPort.width;
scissors.extent.height = viewPort.height;
// Setup Viewport state information
VkPipelineViewportStateCreateInfo viewportInfo = {};
viewportInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
viewportInfo.viewportCount = viewportInfo.scissorCount = 1;
viewportInfo.pViewports = (const VkViewport*)&viewportInfo;
viewportInfo.pScissors = &scissors;
// Setup Rasterization State Information
VkPipelineRasterizationStateCreateInfo rasterInfo = {};
rasterInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
rasterInfo.polygonMode = VK_POLYGON_MODE_FILL;
rasterInfo.cullMode = VK_CULL_MODE_NONE;
rasterInfo.frontFace = VK_FRONT_FACE_CLOCKWISE;
rasterInfo.rasterizerDiscardEnable = 1;
rasterInfo.lineWidth = 1.0f;
// Setup Input Assembly State Information
VkPipelineInputAssemblyStateCreateInfo assemblyInfo = {};
assemblyInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
assemblyInfo.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
// Setup Vertex Input Attribute Description
VkVertexInputAttributeDescription vertAttribDesc = {};
vertAttribDesc.binding = 0;
vertAttribDesc.format = VK_FORMAT_B8G8R8A8_UNORM;
// Setup Vertex Input Binding Description
VkVertexInputBindingDescription vertBindDesc = {};
vertBindDesc.binding = 0;
vertBindDesc.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
// Setup Vertex Input State Information
VkPipelineVertexInputStateCreateInfo vertInfo = {};
vertInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
vertInfo.pVertexAttributeDescriptions = &vertAttribDesc;
vertInfo.vertexAttributeDescriptionCount = 1;
vertInfo.pVertexBindingDescriptions = &vertBindDesc;
vertInfo.vertexBindingDescriptionCount = 1;
// Setup Graphics Pipeline Information
VkGraphicsPipelineCreateInfo pipelineInfo = {};
pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
pipelineInfo.renderPass = _VkSystem.renderPass;
pipelineInfo.stageCount = 1;
pipelineInfo.pStages = &stageInfo;
pipelineInfo.pVertexInputState = &vertInfo;
pipelineInfo.pInputAssemblyState = &assemblyInfo;
pipelineInfo.pRasterizationState = &rasterInfo;
pipelineInfo.layout = pipeLayout;
pipelineInfo.pViewportState = &viewportInfo;
// Create Graphics Pipeline
VkPipeline graphicPipeline;
res = vkCreateGraphicsPipelines(_VkSystem.device, 0, 1, &pipelineInfo, 0, &graphicPipeline);
if (res != VK_SUCCESS)
return 1;