Skip to content

Commit 4007a2b

Browse files
committed
Renamed Queue to submitCommands
1 parent 9279219 commit 4007a2b

File tree

10 files changed

+202
-108
lines changed

10 files changed

+202
-108
lines changed

engine/render/renderer/platform/vulkan/Fence.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,11 @@ class Fence
7979
return Get(index);
8080
}
8181

82+
// TODO (Aryeh): Add some form of bounds checking?
8283
/**
8384
* Gets the raw vulkan Fence pointer stored by the wrapper
85+
* @warn this method does not bounds check the index. It is the user's responsibility to make
86+
* sure the index is valid
8487
* @param index the index to access, defaults to 0
8588
* @return the pointer to the raw vulkan pointer
8689
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include "Context.h"
1212
#include "utils/Device.h"
13-
#include "utils/Queue.h"
13+
#include "utils/SubmitCommands.h"
1414
#include "utils/Swapchain.h"
1515
#include "utils/TypeAdaptor.h"
1616

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

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

engine/render/renderer/platform/vulkan/utils/Queue.cpp renamed to engine/render/renderer/platform/vulkan/utils/SubmitCommands.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// https://opensource.org/licenses/Zlib
77
//
88

9-
#include "Queue.h"
9+
#include "SubmitCommands.h"
1010

1111
#include <utils/Logging.h>
1212

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
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+
#ifndef SIEGE_ENGINE_SUBMIT_COMMANDS_H
10+
#define SIEGE_ENGINE_SUBMIT_COMMANDS_H
11+
12+
#include <utils/collections/StackArray.h>
13+
#include <volk/volk.h>
14+
15+
#include "Types.h"
16+
17+
namespace Siege::Vulkan::Utils
18+
{
19+
20+
/**
21+
* Specifies the number of acceptable semaphores which can be submitted for signalling at any point
22+
* in time
23+
*/
24+
static inline constexpr size_t MAX_SEMAPHORES = 10;
25+
26+
/**
27+
* The SubmitGraphicsCommand type handles all requirements for submitting draw commands to
28+
* the GPU's graphics queue. The purpose is to act as a readable storage container for submitting
29+
* graphics commands to the GPU
30+
*/
31+
struct SubmitGraphicsCommand
32+
{
33+
/**
34+
* The number of command buffers which can be submitted for any single command submission
35+
*/
36+
static inline constexpr size_t MAX_COMMAND_BUFFERS = 10;
37+
38+
/**
39+
* Specifies the Queue to submit to
40+
* @param targetQueue the queue to submit commands to
41+
* @return A reference to the command builder
42+
*/
43+
SubmitGraphicsCommand& ToQueue(VkQueue targetQueue);
44+
45+
/**
46+
* Specifies which semaphores to wait on before submitting the commands
47+
* @param list a list of semaphores to wait on before submitting the commands
48+
* @return A reference to the command builder
49+
*/
50+
SubmitGraphicsCommand& WaitOnSemaphores(std::initializer_list<VkSemaphore> list);
51+
52+
/**
53+
* Specifies which command buffers to submit to the graphics queue
54+
* @param list a list of all command buffers to use for drawing
55+
* @return A reference to the command builder
56+
*/
57+
SubmitGraphicsCommand& WithCommandBuffers(std::initializer_list<VkCommandBuffer> list);
58+
59+
/**
60+
* Specifies which semaphores to signal once the submission has completed
61+
* @param list a list of semaphores to signal once submission is complete
62+
* @return A reference to the command builder
63+
*/
64+
SubmitGraphicsCommand& SignalSemaphores(std::initializer_list<VkSemaphore> list);
65+
66+
/**
67+
* Specifies which pipeline stages the command applies to (vertex, fragment... etc)
68+
* @param list a list of the pipeline stages the command will affect
69+
* @return A reference to the command builder
70+
*/
71+
SubmitGraphicsCommand& WithPipelineStages(std::initializer_list<VkPipelineStageFlags> list);
72+
73+
/**
74+
* Submits the command to the graphics queue
75+
* @param inFlightFence the per-frame fence the command should be submitted to
76+
*/
77+
void Submit(VkFence inFlightFence);
78+
79+
VkQueue queue {VK_NULL_HANDLE};
80+
::Siege::Utils::MSArray<VkSemaphore, MAX_SEMAPHORES> waitSemaphores;
81+
::Siege::Utils::MSArray<VkCommandBuffer, MAX_COMMAND_BUFFERS> commandBuffers;
82+
::Siege::Utils::MSArray<VkSemaphore, MAX_SEMAPHORES> signalSemaphores;
83+
::Siege::Utils::MSArray<VkPipelineStageFlags, MAX_SEMAPHORES> waitDstStageMask;
84+
};
85+
86+
/**
87+
* The SubmitPresentCommand type handles all requirements for submitting commands to the present
88+
* queue (the present queue actually handles the drawing of images to the screen). It acts as a
89+
* storage container for all data required to submit commands to the present queue.
90+
*/
91+
struct SubmitPresentCommand
92+
{
93+
/**
94+
* The maximum number of swapchains to use for submission
95+
*/
96+
static inline constexpr size_t MAX_SWAPCHAINS = 10;
97+
/**
98+
* The maximum number of images (represented by indices) which can be submitted at once
99+
*/
100+
static inline constexpr size_t MAX_INDICES = 10;
101+
102+
/**
103+
* Specifies the Queue to submit to
104+
* @param targetQueue the queue to submit commands to
105+
* @return A reference to the command builder
106+
*/
107+
SubmitPresentCommand& ToQueue(VkQueue targetQueue);
108+
109+
/**
110+
* Specifies which semaphores to signal once the submission has completed
111+
* @param list a list of semaphores to signal once submission is complete
112+
* @return A reference to the command builder
113+
*/
114+
SubmitPresentCommand& SignalSemaphores(std::initializer_list<VkSemaphore> list);
115+
116+
/**
117+
* Specifies which swapchains the command will apply to
118+
* @param list a list of swapchains to use for submission
119+
* @return A reference to the command builder
120+
*/
121+
SubmitPresentCommand& ForSwapchains(std::initializer_list<VkSwapchainKHR> list);
122+
123+
/**
124+
* Specifies which images to use for submission
125+
* @param list a list of images to be used for presentation
126+
* @return A reference to the command builder
127+
*/
128+
SubmitPresentCommand& WithImageIndices(std::initializer_list<uint32_t> list);
129+
130+
/**
131+
* @brief Submits the command to the present queue
132+
* @return the result of the submission. Can return the following:\n
133+
* SUCCESS - The submission was successful\n
134+
* SUBOPTIMAL - The swapchain no longer matches the surface exactly (this can happen when a
135+
* window is resized)\n OUT_OF_DATE - A surface has changed in such a way that the swapchain is
136+
* no longer compatible with it\n RESIZED - The window has been resized and we must rebuild our
137+
* swapchain to match the new extents\n
138+
*/
139+
Utils::Result Submit();
140+
141+
VkQueue queue {VK_NULL_HANDLE};
142+
::Siege::Utils::MSArray<VkSemaphore, MAX_SEMAPHORES> signalSemaphores;
143+
::Siege::Utils::MSArray<VkSwapchainKHR, MAX_SWAPCHAINS> swapchains;
144+
::Siege::Utils::MSArray<uint32_t, MAX_INDICES> indices;
145+
};
146+
} // namespace Siege::Vulkan::Utils
147+
148+
#endif // SIEGE_ENGINE_SUBMIT_COMMANDS_H

engine/utils/collections/HeapArray.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ class MHArray
267267
* @param index the index of the element we want to check
268268
* @return `true` if this element has been set, `false` if it has not
269269
*/
270-
bool Active(size_t index) const
270+
bool IsActive(size_t index) const
271271
{
272272
return bitField.IsSet(index + 1);
273273
}

engine/utils/collections/Iterators.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class MIter
123123
{
124124
ptr = arrPtr->Data() && arrPtr->Count() > 0 ? arrPtr : nullptr;
125125

126-
while (ptr && !ptr->Active(index)) index++;
126+
while (ptr && !ptr->IsActive(index)) index++;
127127
}
128128

129129
/**
@@ -136,7 +136,7 @@ class MIter
136136
{
137137
// If the next element in the array is invalid, keep incrementing until we find one that
138138
// is
139-
while (ptr->Data() && !ptr->Active(index + 1)) index++;
139+
while (ptr->Data() && !ptr->IsActive(index + 1)) index++;
140140

141141
// TODO: Profile if using a reinterpret cast would be faster here
142142
ptr = index < ptr->Size() ? ptr : 0;

engine/utils/collections/StackArray.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ class MSArray
389389
* @param index the index of the element being searched for.
390390
* @return true if the index has been previously assigned to.
391391
*/
392-
inline bool Active(size_t index) const
392+
inline bool IsActive(size_t index) const
393393
{
394394
return bitField.IsSet(index + 1);
395395
}

tests/utils/test_HeapArray.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ UTEST(test_MSArray, CreateHeapArrayFromRawArray)
4949
ASSERT_EQ(array.Size(), 4);
5050
ASSERT_NE(array.Data(), nullptr);
5151

52-
ASSERT_TRUE(array.Active(0));
53-
ASSERT_TRUE(array.Active(1));
54-
ASSERT_TRUE(array.Active(2));
55-
ASSERT_TRUE(array.Active(3));
52+
ASSERT_TRUE(array.IsActive(0));
53+
ASSERT_TRUE(array.IsActive(1));
54+
ASSERT_TRUE(array.IsActive(2));
55+
ASSERT_TRUE(array.IsActive(3));
5656

5757
ASSERT_EQ(array[0], 1);
5858
ASSERT_EQ(array[1], 2);
@@ -187,12 +187,12 @@ UTEST(test_HeapArray, CheckElementIsActive)
187187

188188
array[0] = 1;
189189

190-
ASSERT_TRUE(array.Active(0));
191-
ASSERT_FALSE(array.Active(1));
190+
ASSERT_TRUE(array.IsActive(0));
191+
ASSERT_FALSE(array.IsActive(1));
192192

193193
array[1] = 2;
194194

195-
ASSERT_TRUE(array.Active(1));
195+
ASSERT_TRUE(array.IsActive(1));
196196
}
197197

198198
UTEST(test_HeapArray, RemoveElementByIndex)
@@ -202,22 +202,22 @@ UTEST(test_HeapArray, RemoveElementByIndex)
202202
array[0] = 1;
203203

204204
ASSERT_EQ(array.Count(), 1);
205-
ASSERT_TRUE(array.Active(0));
205+
ASSERT_TRUE(array.IsActive(0));
206206

207207
array[1] = 2;
208208

209209
ASSERT_EQ(array.Count(), 2);
210-
ASSERT_TRUE(array.Active(1));
210+
ASSERT_TRUE(array.IsActive(1));
211211

212212
array.Remove(1);
213213

214214
ASSERT_EQ(array.Count(), 1);
215-
ASSERT_FALSE(array.Active(1));
215+
ASSERT_FALSE(array.IsActive(1));
216216

217217
array.Remove(0);
218218

219219
ASSERT_EQ(array.Count(), 0);
220-
ASSERT_FALSE(array.Active(0));
220+
ASSERT_FALSE(array.IsActive(0));
221221
}
222222

223223
UTEST(test_HeapArray, CopyArray)
@@ -519,14 +519,14 @@ UTEST(test_MHArray, ResizeArray)
519519
ASSERT_EQ(array[2], 3);
520520
ASSERT_EQ(array[3], 4);
521521

522-
ASSERT_FALSE(array.Active(4));
523-
ASSERT_FALSE(array.Active(5));
522+
ASSERT_FALSE(array.IsActive(4));
523+
ASSERT_FALSE(array.IsActive(5));
524524

525525
array[4] = 5;
526526
array[5] = 6;
527527

528-
ASSERT_TRUE(array.Active(4));
529-
ASSERT_TRUE(array.Active(5));
528+
ASSERT_TRUE(array.IsActive(4));
529+
ASSERT_TRUE(array.IsActive(5));
530530

531531
ASSERT_EQ(array[4], 5);
532532
ASSERT_EQ(array[5], 6);
@@ -553,10 +553,10 @@ UTEST(test_MHArray, ResizeArrayToSmallerSize)
553553
ASSERT_EQ(array[0], 1);
554554
ASSERT_EQ(array[1], 2);
555555

556-
ASSERT_TRUE(array.Active(0));
557-
ASSERT_TRUE(array.Active(1));
558-
ASSERT_FALSE(array.Active(2));
559-
ASSERT_FALSE(array.Active(3));
556+
ASSERT_TRUE(array.IsActive(0));
557+
ASSERT_TRUE(array.IsActive(1));
558+
ASSERT_FALSE(array.IsActive(2));
559+
ASSERT_FALSE(array.IsActive(3));
560560
}
561561

562562
UTEST(test_MHArray, ResizeLargeArray)
@@ -575,7 +575,7 @@ UTEST(test_MHArray, ResizeLargeArray)
575575
ASSERT_EQ(array.Size(), 9);
576576
ASSERT_EQ(array.Count(), 9);
577577

578-
ASSERT_FALSE(array.Active(9));
578+
ASSERT_FALSE(array.IsActive(9));
579579
}
580580

581581
UTEST(test_MHArray, ClearArray)
@@ -593,8 +593,8 @@ UTEST(test_MHArray, ClearArray)
593593
ASSERT_EQ(array.Size(), 2);
594594
ASSERT_EQ(array.Count(), 0);
595595

596-
ASSERT_FALSE(array.Active(0));
597-
ASSERT_FALSE(array.Active(1));
596+
ASSERT_FALSE(array.IsActive(0));
597+
ASSERT_FALSE(array.IsActive(1));
598598
}
599599

600600
UTEST(test_MHArray, ClearEmptyArray)

0 commit comments

Comments
 (0)