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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104 | // Horrible
int SetupGraphicsPipeline(VkDescriptorSetLayout* setLayout, VkDescriptorSet* descSet, VkDeviceMemory* devMemory, VkBuffer* buffer)
{
VkResult res;
// Create Vertex Shader Module
VkShaderModule vertexModule;
if (CreateShaderModule(L"vert.spv", &vertexModule) != VK_SUCCESS)
return 1;
// Create Fragment Shader Module
VkShaderModule fragModule;
if (CreateShaderModule(L"frag.spv", &fragModule) != VK_SUCCESS)
return 1;
// Create 2 Shader Stage Create Info for Vertex and Fragment shaders
VkPipelineShaderStageCreateInfo stageInfo[2] = {};
// Setup Stage info for the Vertex Shader
SetupShaderStageInfo(&stageInfo[0], vertexModule, "main", VK_SHADER_STAGE_VERTEX_BIT);
// Setup Stage info for the Fragment Shader
SetupShaderStageInfo(&stageInfo[1], fragModule, "main", VK_SHADER_STAGE_FRAGMENT_BIT);
if (CreateUniformDescription(_VkSystem.descPool, setLayout,
descSet, devMemory, buffer) != VK_SUCCESS)
return 1;
VkDescriptorSetLayout layouts[] = { _VkSystem.mainUniform.setLayout , _VkSystem.textureDesc.setLayout };
VkPipelineLayoutCreateInfo layoutInfo = {};
layoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
layoutInfo.setLayoutCount = _countof(layouts);
layoutInfo.pSetLayouts = layouts;
// Create the Pipeline Layout
VkPipelineLayout pipeLayout;
res = vkCreatePipelineLayout(_VkSystem.device, &layoutInfo, 0, &pipeLayout);
if (res != VK_SUCCESS)
return 1;
// Setup Viewport State Information
VkPipelineViewportStateCreateInfo viewportInfo;
VkViewport viewPort;
VkRect2D scissors;
SetupViewPortStateInfo(&viewportInfo, &viewPort, &scissors, SCREEN_WIDTH, SCREEN_HEIGHT);
// Setup Rasterization State Information
VkPipelineRasterizationStateCreateInfo rasterInfo = {};
SetupRasterizationStateInfo(&rasterInfo);
// 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
VkVertexInputAttributeDescription vertAttribDesc;
VkVertexInputBindingDescription vertBindDesc;
VkPipelineVertexInputStateCreateInfo vertInfo;
SetupVertexInputStateInfo(&vertInfo, &vertAttribDesc, &vertBindDesc, VK_FORMAT_R32G32_SFLOAT,
VK_VERTEX_INPUT_RATE_VERTEX, sizeof(float) * 2);
VkPipelineMultisampleStateCreateInfo multiInfo = {};
multiInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
multiInfo.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
// Set Color Blend Attachment State (we want RGBA to be enabled for writing)
VkPipelineColorBlendAttachmentState blendAttachment = {};
blendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
VkPipelineColorBlendStateCreateInfo blendInfo = {};
blendInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
blendInfo.attachmentCount = 1;
blendInfo.pAttachments = &blendAttachment;
// Setup Graphics Pipeline Information
VkGraphicsPipelineCreateInfo pipelineInfo = {};
pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
pipelineInfo.renderPass = _VkSystem.renderPass;
pipelineInfo.stageCount = _countof(stageInfo);
pipelineInfo.pStages = stageInfo;
pipelineInfo.pVertexInputState = &vertInfo;
pipelineInfo.pInputAssemblyState = &assemblyInfo;
pipelineInfo.pRasterizationState = &rasterInfo;
pipelineInfo.layout = pipeLayout;
pipelineInfo.pViewportState = &viewportInfo;
pipelineInfo.pColorBlendState = &blendInfo;
pipelineInfo.pMultisampleState = &multiInfo;
// Create Graphics Pipeline
VkPipeline graphicPipeline;
res = vkCreateGraphicsPipelines(_VkSystem.device, 0, 1, &pipelineInfo, 0, &graphicPipeline);
if (res != VK_SUCCESS)
return 1;
_VkSystem.graphicsPipeline = graphicPipeline;
_VkSystem.pipeLayout = pipeLayout;
return res;
}
|