Compare commits

...

2 Commits

10 changed files with 54 additions and 170 deletions

View File

@ -77,13 +77,20 @@ partition "**DeviceControl**" {
end note
}
:**Graphics**::createRenderPass(...);
note right
This is pretty simple, it sets up the image bit depth
and the color bit depth! Basically, the format of the
displayed images, simple, but important!
end note
:**Buffers**::createDescriptorSetLayout();
note right
This function creates a table of pointers to the stored
data that we want, in this case it would be pointing to
pre-programmed model view and projection values, and
a time variable.
end note
partition "**Graphics**" {
:createRenderPass(...);
note right
This is pretty simple, it sets up the image bit depth
and the color bit depth! Basically, the format of the
displayed images, simple, but important!
end note
:createGraphicsPipeline(...);
note right
This is a complex function that goes through every
@ -116,6 +123,28 @@ partition "**Buffers**" {
at corners to triangulate. this saves cycles at
scale, complex objects rejoice!
end note
:createUniformBuffer();
note right
Map the buffer data to memory (The struct) as a pointer
we can use this as a reference of where to write data to
when the fence lets us write data.
(see **recordCommandBuffer()**).
end note
:createDescriptorPool();
note right
Here we create a pool to manage the memory and allocate
space for the descriptor sets! Very useful and the same
structure as command buffers & pools.
end note
:createDescriptorSetLayout();
note right
//Descriptor set **layouts** specify the types of resources accessible//
//by the graphical pipeline. A descriptor set is the actual buffer//
//or resource that gets bound to descriptors and passed in.//
These differ from Vertex & Index buffers, as they are not unique
to the graphics pipeline. Specification of compute vs. graphics is
therefore necessary. (see **createDescriptorSets()**)
end note
}
:Graphics::createCommandBuffer();
note right

1
Flowgraph.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 59 KiB

View File

@ -1,151 +0,0 @@
@startuml
title Main Execution
caption
//**Main execution from the run function in the entrypoint**//
//**This dictates basic flow of the vulkan boilerplate system. **//
endcaption
:main;
://**run()**//; <<procedure>>
split
://**initWindow()**//; <<procedure>>
:glfwInit();
:window = glfwCreateWindow(...);
note left
//Create window and initialize default settings//
endnote
:glfwSetWindowUserPointer(...);
note left
//Set the user-defined pointer of the window//
endnote
:glfwSetFramebufferSizeCallback(...);
note left
//This is a callback to resizing of the window//
//we call and set a bool to true, which we get//
//and rebuild the swap chain when true.//
endnote
stop
split again
://**initVulkan()**//; <<procedure>>
split
://**createInstance()**//; <<procedure>>
split
:Debug::checkUnavailableValidationLayers();
:**VkApplicationInfo** appInfo{};
://set appInfo data, Vulkan version,//
//Engine version and name, and title//;
:**VkApplicationCreateInfo** createInfo{};
:createInfo.pApplicationInfo = &appInfo;
:Debug::vulkanDebugSetup(createInfo, vulkaninstance);
end split
split again
:Debug::setupDebugMessenger(VkInstance&);
note right: Setup debug messenger, print data to console
:glfwCreateWindowSurface(...);
note right
This function handles Window System Integration
automatically across platforms based on build environment.
====
//Basically, this is an abstraction of the Window across platforms//
end note
partition "**DeviceControl**" {
:pickPhysicalDevice(...);
note right
Enumerate through GPU's in the
system and choose a compatible one.
====
//in the future, this should choose the BEST//
//GPU, not just the first one that is compatible..//
end note
:createLogicalDevice(...);
note right
Logical devices interface with the
physical device and defines queues
end note
:createSwapChain(...);
note right
Swap Chains are used to handle buffer ownership
infrastructure. Being platform agnostic has its
complications, this is a perfect example.
This process is HEAVILY documented.
end note
:createImageViews(...);
note right
This is a cool function, quite a simple
description of images that will be shown on the
screen! It also determines //how// to access the image
end note
}
partition "**Graphics**" {
:createRenderPass(...);
note right
This is pretty simple, it sets up the image bit depth
and the color bit depth! Basically, the format of the
displayed images, simple, but important!
end note
:createGraphicsPipeline(...);
note right
This is a complex function that goes through every
step of the render pipeline and sets the settings we
desire for each step! **HEAVILY** documented.
end note
:createFramebuffers(...);
note right
This function creates framebuffers for all the images
that are queued to be displayed, very important!
end note
:createCommandPool(...);
note right
Commands in Vulkan are not executed using function calls
You have to record the ops you want to perform to command
buffer objects, pools manage the memory used for buffers.
end note
}
partition "**Buffers**" {
:createVertexBuffer();
note right
Vertex buffers are incredibly useful, in essence,
you can read data from memory as vertex input to the
vertex shader rather than hardcoded data!
end note
:createIndexBuffer();
note right
Index buffers are cool, basically, you can store
some vertices that would normally be duplicated
at corners to triangulate. this saves cycles at
scale, complex objects rejoice!
end note
}
:Graphics::createCommandBuffer();
note right
This is the partner to the commandPool creator,
storing the commands we wish to perform whilst
waiting in a queue. These are very efficient.
end note
:RenderPresent::createSyncObject();
note right
This is **HEAVILY** documented, create Semaphores
and Fences, for halting and starting execution, basically
a traffic controller for the GPU.
end note
end split
stop
split again
repeat ://**mainLoop()**//; <<procedure>>
:glfwPollEvents();
:RenderPresent::drawFrame();
repeat while (!glfwWindowShouldClose(...))
:vkDeviceWaitIdle(...);
stop
split again
://**cleanup()**//; <<procedure>>
note right
//This function initiates a series of shutdown//
//destroy functions, safely stopping execution//;
endnote
:return EXIT_SUCCESS;
stop
end split
@enduml

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 50 KiB

View File

@ -1,5 +1,4 @@
#include "entrypoint.h"
#include "global.h"
DeviceControl::devicelibrary deviceLibs;
Debug::vulkandebuglibs debugController;
Graphics::graphicspipeline graphicsPipeline;

View File

@ -3,6 +3,7 @@
#include "debug/vulkandebuglibs.h"
#include "graphics/graphicspipeline.h"
#include "graphics/render.h"
#include "global.h"
class EntryApp {
public:
static EntryApp& getInstance();

View File

@ -3,6 +3,7 @@
#include <glm/detail/qualifier.hpp>
#include <glm/ext/vector_float2.hpp>
#include <glm/ext/vector_float3.hpp>
#include <glm/fwd.hpp>
#include <iostream>
#include <vector>
#include <optional>
@ -29,11 +30,11 @@ namespace Global {
extern VkDescriptorSetLayout descriptorSetLayout;
extern uint32_t currentFrame;
extern std::vector<VkDescriptorSet> descriptorSets;
struct UniformBufferObject {
glm::mat4 model;
glm::mat4 view;
glm::mat4 proj;
float time;
alignas(16) glm::mat4 model;
alignas(16) glm::mat4 view;
alignas(16) glm::mat4 proj;
};
struct Vertex {
glm::vec2 pos;

View File

@ -165,7 +165,7 @@ namespace Buffers {
std::vector<uint16_t> bufferslibrary::getIndices() {
return indices;
}
// ------------------------------ Uniform Buffer Setup -------------------------------- //
void bufferslibrary::createDescriptorSetLayout() {
// Create a table of pointers to data, a Descriptor Set!
VkDescriptorSetLayoutBinding uboLayoutBinding{};
@ -187,10 +187,9 @@ namespace Buffers {
throw std::runtime_error("Failed to create descriptor set layout!");
}
}
//void createMVPDescriptor() {
//}
void bufferslibrary::createUniformBuffers() {
// Map the uniform buffer to memory as a pointer we can use to write data to later. This stays mapped to memory for the applications lifetime.
// This technique is called "persistent mapping", not having to map the buffer every time we need to update it increases performance, though not free
VkDeviceSize bufferSize = sizeof(Global::UniformBufferObject);
uniformBuffers.resize(Global::MAX_FRAMES_IN_FLIGHT);
@ -203,12 +202,16 @@ namespace Buffers {
}
}
void bufferslibrary::updateUniformBuffer(uint32_t currentImage) {
// Update the uniform buffer every frame to change the position, but notably, use chrono to know exactly how much to move
// so we aren't locked to the framerate as the world time.
static auto startTime = std::chrono::high_resolution_clock::now();
// Calculate the time in seconds since rendering has began to floating point precision.
auto currentTime = std::chrono::high_resolution_clock::now();
float time = std::chrono::duration<float, std::chrono::seconds::period>(currentTime - startTime).count();
Global::UniformBufferObject ubo{};
ubo.time = time;
// Modify the model projection transformation to rotate around the Z over time.
ubo.model = glm::rotate(glm::mat4(1.0f), time * glm::radians(90.0f), glm::vec3(0.0f, 0.0f, 1.0f));
// Modify the view transformation to look at the object from above at a 45 degree angle.
@ -229,6 +232,7 @@ namespace Buffers {
}
}
void bufferslibrary::createDescriptorPool() {
// Create a pool to be used to allocate descriptor sets.
VkDescriptorPoolSize poolSize{};
poolSize.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
poolSize.descriptorCount = static_cast<uint32_t>(Global::MAX_FRAMES_IN_FLIGHT);

View File

@ -238,7 +238,8 @@ namespace Graphics {
}
}
void graphicspipeline::createCommandPool() {
// Commands in Vulkan are not executed using function calls, you have to record the ops you wish to perform
// to command buffers, pools manage the memory used by the buffer!
Global::QueueFamilyIndices queueFamilyIndices = Global::findQueueFamilies(Global::physicalDevice);
VkCommandPoolCreateInfo poolInfo{};

View File

@ -1,6 +1,7 @@
#version 450
layout(binding = 0) uniform UniformBufferObject {
float time;
mat4 model;
mat4 view;
mat4 proj;
@ -14,6 +15,5 @@ layout(location = 0) out vec3 fragColor;
void main() {
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 0.0, 1.0);
fragColor = inColor;
fragColor = inColor + sin(ubo.time*2);
}