forked from SpaRcle-Studio/EvoVulkan
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
157 lines (117 loc) · 5.02 KB
/
main.cpp
File metadata and controls
157 lines (117 loc) · 5.02 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//
// Created by Nikita on 12.04.2021.
//
#include "UnitTests/Example.h"
int main() {
auto* kernel = new VulkanExample();
auto printMemory = [kernel]() -> std::string {
if (!kernel->GetDevice())
return std::string();
else
return "{" + std::to_string(kernel->GetDevice()->GetAllocatedMemorySize() / 1024 / 1024) + "MB} ";
};
EvoVulkan::Tools::VkDebug::Error = std::function<void(const std::string& msg)>([printMemory](const std::string& msg) {
std::cout << printMemory() << "[Error] " << msg << std::endl;
});
EvoVulkan::Tools::VkDebug::Graph = std::function<void(const std::string& msg)>([printMemory](const std::string& msg) {
std::cout << printMemory() << "[Graph] " << msg << std::endl;
});
EvoVulkan::Tools::VkDebug::Log = std::function<void(const std::string& msg)>([printMemory](const std::string& msg) {
std::cout << printMemory() << "[Log] " << msg << std::endl;
});
EvoVulkan::Tools::VkDebug::Warn = std::function<void(const std::string& msg)>([printMemory](const std::string& msg) {
std::cout << printMemory() << "[Warn] " << msg << std::endl;
});
//!=================================================================================================================
glfwInit();
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
unsigned int width = 600; //1280
unsigned int height = 600; //820
bool validationEnabled = true;
auto window = glfwCreateWindow((int)width, (int)height, "Vulkan application", nullptr, nullptr); //1280, 1024
glfwSetWindowSizeCallback(window, [](GLFWwindow* window, int width, int height) {
auto kernel = static_cast<Core::VulkanKernel*>(glfwGetWindowUserPointer(window));
kernel->SetSize(width, height);
});
//!=================================================================================================================
glfwSetWindowUserPointer(window, (void*)kernel);
kernel->SetValidationLayersEnabled(validationEnabled);
kernel->SetSize(width, height);
kernel->SetMultisampling(8);
std::vector<const char*> extensions;
extensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
extensions.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
if (validationEnabled)
extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
if (!kernel->PreInit("Simple engine", "NoEngine",
R"(C:\VulkanSDK\1.2.170.0\Bin\glslc.exe)",
{ extensions },
{ "VK_LAYER_KHRONOS_validation" }))
{
std::cout << "Failed to pre-initialize Evo Vulkan!\n";
return -1;
}
std::function<VkSurfaceKHR(const VkInstance& instance)> surfCreate = [window](const VkInstance& instance) -> VkSurfaceKHR {
VkSurfaceKHR surfaceKhr = {};
if (glfwCreateWindowSurface(instance, window, nullptr, &surfaceKhr) != VK_SUCCESS) {
EvoVulkan::Tools::VkDebug::Error("VulkanKernel::Init(lambda) : failed to create glfw window surface!");
return VK_NULL_HANDLE;
} else
return surfaceKhr;
};
if (!kernel->Init(
surfCreate,
{ VK_KHR_SWAPCHAIN_EXTENSION_NAME },
true, // sample shading
true // vsync
)) {
std::cout << "Failed to initialize Evo Vulkan!\n";
return -1;
}
if (!kernel->PostInit()) {
std::cout << "Failed to post-initialize Evo Vulkan!\n";
return -1;
}
//!=================================================================================================================
if (!kernel->LoadTexture())
return -1;
if (!kernel->LoadCubeMap())
return -1;
if (!kernel->SetupShader())
return -1;
if (!kernel->SetupUniforms())
return -1;
if (!kernel->GenerateGeometry())
return -1;
std::vector<EvoVulkan::Core::DescriptorSet> descriptors;
for (uint32_t i = 0; i < 100000; i++)
descriptors.emplace_back(kernel->GetDescriptorManager()->AllocateDescriptorSets(
kernel->m_geometry->GetDescriptorSetLayout(),
{ VkDescriptorType::VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER }));
for (auto& descriptor : descriptors)
kernel->GetDescriptorManager()->FreeDescriptorSet(descriptor);
/*std::array<Types::Buffer*, 4000> buffers = { };
for (auto& buffer : buffers) {
buffer = Types::Buffer::Create(
kernel->GetDevice(),
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
16);
}*/
#ifdef EVOVULKAN_EXAMPLE_H
kernel->LoadSkybox();
#endif
kernel->BuildCmdBuffers();
std::cout << kernel->GetDevice()->GetAllocatedHeapsCount() << std::endl;
while (!glfwWindowShouldClose(window) && !kernel->HasErrors()) {
glfwPollEvents();
kernel->NextFrame();
kernel->UpdateUBO();
}
kernel->Destroy();
delete kernel;
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}