Update documentation and clean code for Uniform Buffers, added time variable to descriptor set, preparing for Texture mapping.
This commit is contained in:
parent
086adae47a
commit
cb4500d97f
@ -77,13 +77,20 @@ partition "**DeviceControl**" {
|
|||||||
end note
|
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**" {
|
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(...);
|
:createGraphicsPipeline(...);
|
||||||
note right
|
note right
|
||||||
This is a complex function that goes through every
|
This is a complex function that goes through every
|
||||||
@ -116,6 +123,28 @@ partition "**Buffers**" {
|
|||||||
at corners to triangulate. this saves cycles at
|
at corners to triangulate. this saves cycles at
|
||||||
scale, complex objects rejoice!
|
scale, complex objects rejoice!
|
||||||
end note
|
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();
|
:Graphics::createCommandBuffer();
|
||||||
note right
|
note right
|
||||||
|
1
Flowgraph.svg
Normal file
1
Flowgraph.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 59 KiB |
@ -1,5 +1,4 @@
|
|||||||
#include "entrypoint.h"
|
#include "entrypoint.h"
|
||||||
#include "global.h"
|
|
||||||
DeviceControl::devicelibrary deviceLibs;
|
DeviceControl::devicelibrary deviceLibs;
|
||||||
Debug::vulkandebuglibs debugController;
|
Debug::vulkandebuglibs debugController;
|
||||||
Graphics::graphicspipeline graphicsPipeline;
|
Graphics::graphicspipeline graphicsPipeline;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "debug/vulkandebuglibs.h"
|
#include "debug/vulkandebuglibs.h"
|
||||||
#include "graphics/graphicspipeline.h"
|
#include "graphics/graphicspipeline.h"
|
||||||
#include "graphics/render.h"
|
#include "graphics/render.h"
|
||||||
|
#include "global.h"
|
||||||
class EntryApp {
|
class EntryApp {
|
||||||
public:
|
public:
|
||||||
static EntryApp& getInstance();
|
static EntryApp& getInstance();
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <glm/detail/qualifier.hpp>
|
#include <glm/detail/qualifier.hpp>
|
||||||
#include <glm/ext/vector_float2.hpp>
|
#include <glm/ext/vector_float2.hpp>
|
||||||
#include <glm/ext/vector_float3.hpp>
|
#include <glm/ext/vector_float3.hpp>
|
||||||
|
#include <glm/fwd.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
@ -29,11 +30,11 @@ namespace Global {
|
|||||||
extern VkDescriptorSetLayout descriptorSetLayout;
|
extern VkDescriptorSetLayout descriptorSetLayout;
|
||||||
extern uint32_t currentFrame;
|
extern uint32_t currentFrame;
|
||||||
extern std::vector<VkDescriptorSet> descriptorSets;
|
extern std::vector<VkDescriptorSet> descriptorSets;
|
||||||
|
|
||||||
struct UniformBufferObject {
|
struct UniformBufferObject {
|
||||||
glm::mat4 model;
|
float time;
|
||||||
glm::mat4 view;
|
alignas(16) glm::mat4 model;
|
||||||
glm::mat4 proj;
|
alignas(16) glm::mat4 view;
|
||||||
|
alignas(16) glm::mat4 proj;
|
||||||
};
|
};
|
||||||
struct Vertex {
|
struct Vertex {
|
||||||
glm::vec2 pos;
|
glm::vec2 pos;
|
||||||
|
@ -165,7 +165,7 @@ namespace Buffers {
|
|||||||
std::vector<uint16_t> bufferslibrary::getIndices() {
|
std::vector<uint16_t> bufferslibrary::getIndices() {
|
||||||
return indices;
|
return indices;
|
||||||
}
|
}
|
||||||
|
// ------------------------------ Uniform Buffer Setup -------------------------------- //
|
||||||
void bufferslibrary::createDescriptorSetLayout() {
|
void bufferslibrary::createDescriptorSetLayout() {
|
||||||
// Create a table of pointers to data, a Descriptor Set!
|
// Create a table of pointers to data, a Descriptor Set!
|
||||||
VkDescriptorSetLayoutBinding uboLayoutBinding{};
|
VkDescriptorSetLayoutBinding uboLayoutBinding{};
|
||||||
@ -187,10 +187,9 @@ namespace Buffers {
|
|||||||
throw std::runtime_error("Failed to create descriptor set layout!");
|
throw std::runtime_error("Failed to create descriptor set layout!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//void createMVPDescriptor() {
|
|
||||||
|
|
||||||
//}
|
|
||||||
void bufferslibrary::createUniformBuffers() {
|
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);
|
VkDeviceSize bufferSize = sizeof(Global::UniformBufferObject);
|
||||||
|
|
||||||
uniformBuffers.resize(Global::MAX_FRAMES_IN_FLIGHT);
|
uniformBuffers.resize(Global::MAX_FRAMES_IN_FLIGHT);
|
||||||
@ -203,12 +202,16 @@ namespace Buffers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
void bufferslibrary::updateUniformBuffer(uint32_t currentImage) {
|
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();
|
static auto startTime = std::chrono::high_resolution_clock::now();
|
||||||
// Calculate the time in seconds since rendering has began to floating point precision.
|
// Calculate the time in seconds since rendering has began to floating point precision.
|
||||||
auto currentTime = std::chrono::high_resolution_clock::now();
|
auto currentTime = std::chrono::high_resolution_clock::now();
|
||||||
float time = std::chrono::duration<float, std::chrono::seconds::period>(currentTime - startTime).count();
|
float time = std::chrono::duration<float, std::chrono::seconds::period>(currentTime - startTime).count();
|
||||||
|
|
||||||
Global::UniformBufferObject ubo{};
|
Global::UniformBufferObject ubo{};
|
||||||
|
ubo.time = time;
|
||||||
// Modify the model projection transformation to rotate around the Z over 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));
|
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.
|
// 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() {
|
void bufferslibrary::createDescriptorPool() {
|
||||||
|
// Create a pool to be used to allocate descriptor sets.
|
||||||
VkDescriptorPoolSize poolSize{};
|
VkDescriptorPoolSize poolSize{};
|
||||||
poolSize.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
poolSize.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
||||||
poolSize.descriptorCount = static_cast<uint32_t>(Global::MAX_FRAMES_IN_FLIGHT);
|
poolSize.descriptorCount = static_cast<uint32_t>(Global::MAX_FRAMES_IN_FLIGHT);
|
||||||
|
@ -238,7 +238,8 @@ namespace Graphics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
void graphicspipeline::createCommandPool() {
|
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);
|
Global::QueueFamilyIndices queueFamilyIndices = Global::findQueueFamilies(Global::physicalDevice);
|
||||||
|
|
||||||
VkCommandPoolCreateInfo poolInfo{};
|
VkCommandPoolCreateInfo poolInfo{};
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#version 450
|
#version 450
|
||||||
|
|
||||||
layout(binding = 0) uniform UniformBufferObject {
|
layout(binding = 0) uniform UniformBufferObject {
|
||||||
|
float time;
|
||||||
mat4 model;
|
mat4 model;
|
||||||
mat4 view;
|
mat4 view;
|
||||||
mat4 proj;
|
mat4 proj;
|
||||||
@ -14,6 +15,5 @@ layout(location = 0) out vec3 fragColor;
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 0.0, 1.0);
|
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 0.0, 1.0);
|
||||||
fragColor = inColor;
|
fragColor = inColor + sin(ubo.time*2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user