Skip to content

Commit 049e838

Browse files
authored
Merge pull request #46 from CapsCollective/feature/remove-volk
Removed all Vulkan leakages from modules
2 parents 01f7ded + cb642f4 commit 049e838

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1087
-1580
lines changed

engine/render/renderer/Renderer.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
// https://opensource.org/licenses/Zlib
77
//
88

9-
#define VOLK_IMPLEMENTATION
10-
119
#include "Renderer.h"
1210

1311
#include "platform/vulkan/Font.h"
1412
#include "platform/vulkan/utils/Types.h"
13+
#include "platform/vulkan/utils/Viewport.h"
1514
#include "statics/Statics.h"
1615

1716
namespace Siege
@@ -22,19 +21,20 @@ uint32_t Renderer::currentFrameIndex = 0;
2221

2322
Renderer::Renderer(Window& window) : window {window}
2423
{
24+
using namespace Vulkan::Utils;
2525
Statics::Initialise();
2626

2727
if (instance == nullptr) instance = this;
2828

29-
auto extent = window.GetExtents();
30-
3129
context.Init(window);
3230

33-
DescriptorPool::AddPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1024);
34-
DescriptorPool::AddPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1024);
35-
DescriptorPool::AddPoolSize(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1024);
36-
DescriptorPool::AddPoolSize(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1024);
37-
DescriptorPool::AddPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1024);
31+
DescriptorPool::Initialise();
32+
33+
DescriptorPool::AddPoolSize(UNIFORM, 1024);
34+
DescriptorPool::AddPoolSize(UNIFORM_DYNAMIC, 1024);
35+
DescriptorPool::AddPoolSize(STORAGE, 1024);
36+
DescriptorPool::AddPoolSize(STORAGE_DYNAMIC, 1024);
37+
DescriptorPool::AddPoolSize(TEXTURE2D, 1024);
3838

3939
DescriptorPool::BuildPool();
4040

@@ -174,6 +174,11 @@ void Renderer::EndFrame()
174174
renderer2D.Flush();
175175
}
176176

177+
void Renderer::ClearDeviceQueue()
178+
{
179+
Vulkan::Context::GetCurrentDevice()->WaitIdle();
180+
}
181+
177182
void Renderer::BeginSwapChainRenderPass()
178183
{
179184
auto& swapchain = context.GetSwapchain();
@@ -182,19 +187,14 @@ void Renderer::BeginSwapChainRenderPass()
182187

183188
auto swapExtent = swapchain.GetExtent();
184189

185-
swapchain.BeginRenderPass(commandBuffers, currentImageIndex, {{clearValue}, {{{1.f, 0.f}}}});
190+
swapchain.BeginRenderPass(commandBuffers, currentImageIndex, {0.96f, 0.96f, 0.96f, 1.f});
186191

187-
VkViewport viewport {};
188-
viewport.x = 0.0f;
189-
viewport.y = 0.0f;
190-
viewport.width = static_cast<float>(swapExtent.width);
191-
viewport.height = static_cast<float>(swapExtent.height);
192-
viewport.minDepth = 0.0f;
193-
viewport.maxDepth = 1.0f;
194-
VkRect2D scissor {{0, 0}, {swapExtent.width, swapExtent.height}};
192+
using namespace Vulkan::Utils;
195193

196-
vkCmdSetViewport(commandBuffers.GetActiveCommandBuffer(), 0, 1, &viewport);
197-
vkCmdSetScissor(commandBuffers.GetActiveCommandBuffer(), 0, 1, &scissor);
194+
SetViewport(commandBuffers.GetActiveCommandBuffer(),
195+
static_cast<float>(swapExtent.width),
196+
static_cast<float>(swapExtent.height));
197+
SetScissor(commandBuffers.GetActiveCommandBuffer(), swapExtent.width, swapExtent.height);
198198
}
199199

200200
void Renderer::EndSwapChainRenderPass()

engine/render/renderer/Renderer.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@
1212
#include <utils/Logging.h>
1313
#include <window/Window.h>
1414

15-
#include "descriptor/DescriptorPool.h"
1615
#include "lights/PointLight.h"
1716
#include "model/Model.h"
1817
#include "render/renderer/platform/vulkan/CommandBuffer.h"
1918
#include "render/renderer/platform/vulkan/Context.h"
19+
#include "render/renderer/platform/vulkan/DescriptorPool.h"
20+
#include "renderer/CameraData.h"
2021
#include "renderer/Renderer2D.h"
2122
#include "renderer/Renderer3D.h"
2223

2324
namespace Siege
2425
{
26+
2527
class Renderer
2628
{
2729
public:
@@ -48,15 +50,7 @@ class Renderer
4850
bool StartFrame();
4951
void EndFrame();
5052

51-
void ClearDeviceQueue()
52-
{
53-
vkDeviceWaitIdle(Context().GetVkLogicalDevice());
54-
}
55-
56-
void SetClearValue(float r, float g, float b, float a)
57-
{
58-
clearValue = {{r, g, b, a}};
59-
}
53+
void ClearDeviceQueue();
6054

6155
void DrawQuad(const Vec2 position,
6256
const Vec2 scale = {1.f, 1.f},
@@ -99,9 +93,6 @@ class Renderer
9993
static Vulkan::CommandBuffer commandBuffers;
10094
static uint32_t currentFrameIndex;
10195

102-
// Make this adjustable in the window, not the renderer.
103-
VkClearColorValue clearValue {{0.96f, 0.96f, 0.96f, 1.f}};
104-
10596
void RecreateSwapChain();
10697

10798
void BeginSwapChainRenderPass();

engine/render/renderer/buffer/Buffer.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212

1313
#include "render/renderer/platform/vulkan/Context.h"
1414
#include "render/renderer/platform/vulkan/utils/Device.h"
15+
#include "render/renderer/platform/vulkan/utils/TypeAdaptor.h"
1516

1617
namespace Siege::Buffer
1718
{
1819
// TODO: Wrap this in a static class 'BufferAllocator' so that we
1920
// don't need to keep a static instance.
2021

21-
void CreateBuffer(VkDeviceSize size,
22-
VkBufferUsageFlags usage,
23-
VkMemoryPropertyFlags properties,
22+
void CreateBuffer(unsigned long size,
23+
unsigned int usage,
24+
unsigned int properties,
2425
VkBuffer& buffer,
2526
VkDeviceMemory& bufferMemory)
2627
{
@@ -54,7 +55,7 @@ void CreateBuffer(VkDeviceSize size,
5455
vkBindBufferMemory(device, buffer, bufferMemory, 0);
5556
};
5657

57-
void CopyData(Buffer& dstBuffer, VkDeviceSize size, const void* bufferData, VkDeviceSize offset)
58+
void CopyData(Buffer& dstBuffer, unsigned long size, const void* bufferData, unsigned long offset)
5859
{
5960
auto device = Vulkan::Context::GetVkLogicalDevice();
6061

@@ -64,7 +65,7 @@ void CopyData(Buffer& dstBuffer, VkDeviceSize size, const void* bufferData, VkDe
6465
vkUnmapMemory(device, dstBuffer.bufferMemory);
6566
}
6667

67-
void AppendData(Buffer& dstBuffer, VkDeviceSize size, const void* bufferData)
68+
void AppendData(Buffer& dstBuffer, unsigned long size, const void* bufferData)
6869
{
6970
auto device = Vulkan::Context::GetVkLogicalDevice();
7071

@@ -76,7 +77,7 @@ void AppendData(Buffer& dstBuffer, VkDeviceSize size, const void* bufferData)
7677
dstBuffer.size = dstBuffer.size + size;
7778
}
7879

79-
void CopyBuffer(VkBuffer& srcBuffer, VkBuffer& dstBuffer, VkDeviceSize size)
80+
void CopyBuffer(VkBuffer& srcBuffer, VkBuffer& dstBuffer, unsigned long size)
8081
{
8182
Vulkan::Context::GetCurrentDevice()->CopyBuffer(srcBuffer, dstBuffer, size);
8283
}

engine/render/renderer/buffer/Buffer.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
#ifndef SIEGE_ENGINE_BUFFER_H
1010
#define SIEGE_ENGINE_BUFFER_H
1111

12-
#include "../Core.h"
12+
#include "render/renderer/platform/vulkan/utils/Types.h"
1313

1414
namespace Siege::Buffer
1515
{
1616
struct Buffer
1717
{
18-
VkBuffer buffer {VK_NULL_HANDLE};
19-
VkDeviceMemory bufferMemory {VK_NULL_HANDLE};
18+
VkBuffer buffer {nullptr};
19+
VkDeviceMemory bufferMemory {nullptr};
2020
uint64_t size = 0;
2121
};
2222

@@ -30,9 +30,9 @@ struct Buffer
3030
* @param buffer - the buffer that the function should write data to.
3131
* @param bufferMemory - the buffer memory data the function should write data to.
3232
**/
33-
void CreateBuffer(VkDeviceSize size,
34-
VkBufferUsageFlags usage,
35-
VkMemoryPropertyFlags properties,
33+
void CreateBuffer(unsigned long size,
34+
unsigned int usage,
35+
unsigned int properties,
3636
VkBuffer& buffer,
3737
VkDeviceMemory& bufferMemory);
3838

@@ -44,7 +44,7 @@ void CreateBuffer(VkDeviceSize size,
4444
* @param typeFilter - The bitmask for the required memory type
4545
* @param properties - The available device memory properties. Used to query for available memory.
4646
**/
47-
uint32_t FindMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties);
47+
uint32_t FindMemoryType(unsigned long typeFilter, Vulkan::Utils::MemoryProperty properties);
4848

4949
/**
5050
* Copies data into a buffer. Data can be any type as specified by
@@ -55,11 +55,11 @@ uint32_t FindMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties);
5555
* @param bufferData - the data being copied into the buffer
5656
**/
5757
void CopyData(Buffer& dstBuffer,
58-
VkDeviceSize size,
58+
unsigned long size,
5959
const void* bufferData,
60-
VkDeviceSize offset = 0);
60+
unsigned long offset = 0);
6161

62-
void AppendData(Buffer& dstBuffer, VkDeviceSize size, const void* bufferData);
62+
void AppendData(Buffer& dstBuffer, unsigned long size, const void* bufferData);
6363

6464
/**
6565
* Copies a buffer. This is generally used when copying the values within a buffer into
@@ -69,7 +69,7 @@ void AppendData(Buffer& dstBuffer, VkDeviceSize size, const void* bufferData);
6969
* @param dstBuffer - the buffer where the data is being copied into.
7070
* @param size - the expected size of the resulting buffer.
7171
**/
72-
void CopyBuffer(VkBuffer& srcBuffer, VkBuffer& dstBuffer, VkDeviceSize size);
72+
void CopyBuffer(VkBuffer& srcBuffer, VkBuffer& dstBuffer, unsigned long size);
7373

7474
/**
7575
* Destroys a buffer struct and releases memory back to the device.

engine/render/renderer/descriptor/DescriptorPool.cpp

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)