Skip to content

Commit acade7d

Browse files
committed
Removed volk from DescriptorPool header
1 parent 01f7ded commit acade7d

File tree

12 files changed

+112
-97
lines changed

12 files changed

+112
-97
lines changed

engine/render/renderer/Renderer.cpp

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

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

1311
#include "platform/vulkan/Font.h"
@@ -22,19 +20,20 @@ uint32_t Renderer::currentFrameIndex = 0;
2220

2321
Renderer::Renderer(Window& window) : window {window}
2422
{
23+
using namespace Vulkan::Utils;
2524
Statics::Initialise();
2625

2726
if (instance == nullptr) instance = this;
2827

29-
auto extent = window.GetExtents();
30-
3128
context.Init(window);
3229

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);
30+
DescriptorPool::Initialise();
31+
32+
DescriptorPool::AddPoolSize(UNIFORM, 1024);
33+
DescriptorPool::AddPoolSize(UNIFORM_DYNAMIC, 1024);
34+
DescriptorPool::AddPoolSize(STORAGE, 1024);
35+
DescriptorPool::AddPoolSize(STORAGE_DYNAMIC, 1024);
36+
DescriptorPool::AddPoolSize(TEXTURE2D, 1024);
3837

3938
DescriptorPool::BuildPool();
4039

engine/render/renderer/Renderer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
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"
17+
#include "render/renderer/platform/vulkan/DescriptorPool.h"
1818
#include "render/renderer/platform/vulkan/CommandBuffer.h"
1919
#include "render/renderer/platform/vulkan/Context.h"
2020
#include "renderer/Renderer2D.h"

engine/render/renderer/descriptor/DescriptorPool.cpp

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

engine/render/renderer/platform/vulkan/Context.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
//
2-
//
32
// Copyright (c) 2022 Jonathan Moallem (@J-Mo63) & Aryeh Zinn (@Raelr)
43
//
54
// This code is released under an unmodified zlib license.
65
// For conditions of distribution and use, please see:
76
// https://opensource.org/licenses/Zlib
87
//
98

9+
#define VOLK_IMPLEMENTATION
10+
1011
#include "Context.h"
12+
#include "render/renderer/Renderer.h"
1113

1214
#include <GLFW/glfw3.h>
1315
#include <utils/Logging.h>
1416

15-
#include "render/renderer/Renderer.h"
16-
1717
namespace Siege::Vulkan
1818
{
1919
Context::~Context()
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// Copyright (c) 2022 Jonathan Moallem (@J-Mo63) & Aryeh Zinn (@Raelr)
3+
//
4+
// This code is released under an unmodified zlib license.
5+
// For conditions of distribution and use, please see:
6+
// https://opensource.org/licenses/Zlib
7+
//
8+
9+
#include "DescriptorPool.h"
10+
11+
#include "render/renderer/platform/vulkan/Context.h"
12+
#include "render/renderer/platform/vulkan/utils/Descriptor.h"
13+
14+
namespace Siege
15+
{
16+
Vulkan::Utils::UniformAllocator DescriptorPool::descriptorPool {nullptr};
17+
MHArray<Vulkan::Utils::UniformAllocation> DescriptorPool::sizes;
18+
19+
void DescriptorPool::AddPoolSize(const Vulkan::Utils::UniformType type, const uint32_t size)
20+
{
21+
sizes.Append({type, size});
22+
}
23+
24+
void DescriptorPool::Initialise()
25+
{
26+
using namespace Vulkan::Utils;
27+
sizes = MHArray<UniformAllocation>(Descriptor::MAX_DESCRIPTOR_POOL_SIZES);
28+
}
29+
30+
void DescriptorPool::BuildPool()
31+
{
32+
using namespace Vulkan::Utils;
33+
descriptorPool = Descriptor::CreateDescriptorPool(Vulkan::Context::GetVkLogicalDevice(),
34+
sizes.Data(),
35+
sizes.Count());
36+
}
37+
38+
void DescriptorPool::DestroyPool()
39+
{
40+
Vulkan::Utils::Descriptor::DestroyDescriptorPool(Vulkan::Context::GetVkLogicalDevice(),
41+
descriptorPool);
42+
}
43+
} // namespace Siege

engine/render/renderer/descriptor/DescriptorPool.h renamed to engine/render/renderer/platform/vulkan/DescriptorPool.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,21 @@
99
#ifndef SIEGE_ENGINE_DESCRIPTOR_POOL_H
1010
#define SIEGE_ENGINE_DESCRIPTOR_POOL_H
1111

12-
#include "../Core.h"
12+
#include <utils/collections/HeapArray.h>
13+
14+
#include "render/renderer/platform/vulkan/utils/Types.h"
1315

1416
namespace Siege
1517
{
18+
// TODO(Aryeh): Remove the statics in this file (remember to create constructors and Swap functions)
1619
class DescriptorPool
1720
{
1821
public:
1922

20-
static void AddPoolSize(const VkDescriptorType type, const uint32_t size);
21-
static VkDescriptorPool& GetDescriptorPool()
23+
static void Initialise();
24+
static void AddPoolSize(const Vulkan::Utils::UniformType type, const unsigned int size);
25+
26+
static inline Vulkan::Utils::UniformAllocator& GetDescriptorPool()
2227
{
2328
return descriptorPool;
2429
}
@@ -28,10 +33,8 @@ class DescriptorPool
2833

2934
private:
3035

31-
static constexpr size_t MAX_DESCRIPTOR_POOL_SIZES = 1024;
32-
33-
static VkDescriptorPool descriptorPool;
34-
static MSArray<VkDescriptorPoolSize, MAX_DESCRIPTOR_POOL_SIZES> sizes;
36+
static Vulkan::Utils::UniformAllocator descriptorPool;
37+
static MHArray<Vulkan::Utils::UniformAllocation> sizes;
3538
};
3639
} // namespace Siege
3740

engine/render/renderer/platform/vulkan/Material.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "Pipeline.h"
1717
#include "Swapchain.h"
1818
#include "render/renderer/Renderer.h"
19-
#include "render/renderer/descriptor/DescriptorPool.h"
19+
#include "render/renderer/platform/vulkan/DescriptorPool.h"
2020
#include "render/renderer/platform/vulkan/utils/Descriptor.h"
2121
#include "utils/TypeAdaptor.h"
2222

engine/render/renderer/platform/vulkan/utils/Descriptor.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,35 @@
88

99
#include "Descriptor.h"
1010

11+
#include <utils/Logging.h>
12+
1113
namespace Siege::Vulkan::Utils::Descriptor
1214
{
15+
VkDescriptorPool CreateDescriptorPool(VkDevice device,
16+
UniformAllocation* sizes,
17+
unsigned int sizeCount)
18+
{
19+
VkDescriptorPool pool {VK_NULL_HANDLE};
20+
21+
VkDescriptorPoolCreateInfo poolCreateInfo {};
22+
poolCreateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
23+
poolCreateInfo.flags = 0;
24+
poolCreateInfo.maxSets = MAX_DESCRIPTOR_POOL_SIZES;
25+
poolCreateInfo.poolSizeCount = sizeCount;
26+
poolCreateInfo.pPoolSizes = reinterpret_cast<VkDescriptorPoolSize*>(sizes);
27+
28+
CC_ASSERT(vkCreateDescriptorPool(device, &poolCreateInfo, nullptr, &pool) == VK_SUCCESS,
29+
"Unable to create descriptor pool!")
30+
31+
return pool;
32+
}
33+
34+
void DestroyDescriptorPool(VkDevice device, VkDescriptorPool pool)
35+
{
36+
if (pool == nullptr) return;
37+
vkDestroyDescriptorPool(device, pool, nullptr);
38+
}
39+
1340
VkDescriptorSetLayoutBinding CreateLayoutBinding(uint32_t binding,
1441
uint32_t count,
1542
uint32_t type,

engine/render/renderer/platform/vulkan/utils/Descriptor.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@
1111

1212
#include <cstdint>
1313

14+
#include "Types.h"
1415
#include "volk/volk.h"
1516

1617
namespace Siege::Vulkan::Utils::Descriptor
1718
{
1819

19-
enum Type
20-
{
21-
UNIFORM = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
22-
STORAGE = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
23-
UNIFORM_DYNAMIC = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC,
24-
STORAGE_DYNAMIC = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
25-
};
20+
static constexpr unsigned int MAX_DESCRIPTOR_POOL_SIZES = 1024;
21+
22+
VkDescriptorPool CreateDescriptorPool(VkDevice device,
23+
UniformAllocation* sizes,
24+
unsigned int sizeCount);
25+
26+
void DestroyDescriptorPool(VkDevice device, VkDescriptorPool pool);
2627

2728
VkDescriptorSetLayoutBinding CreateLayoutBinding(uint32_t binding,
2829
uint32_t count,

engine/render/renderer/platform/vulkan/utils/Image.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//
2-
//
32
// Copyright (c) 2022 Jonathan Moallem (@J-Mo63) & Aryeh Zinn (@Raelr)
43
//
54
// This code is released under an unmodified zlib license.

0 commit comments

Comments
 (0)