1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// 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 State Information
	VkPipelineVertexInputStateCreateInfo vertInfo = {};
	vertInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;

	// 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;