Skip to content

Commit 097e488

Browse files
committed
Introduced vsg::Slots struct for holding the max state and view slot numbers.
1 parent 73505ff commit 097e488

19 files changed

Lines changed: 84 additions & 59 deletions

include/vsg/app/CommandGraph.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ namespace vsg
3939

4040
int queueFamily = -1;
4141
int presentFamily = -1;
42-
uint32_t maxStateSlot = 0;
43-
uint32_t maxViewSlot = 0;
4442
int submitOrder = 0;
43+
Slots maxSlots;
4544

4645
ref_ptr<RecordTraversal> getOrCreateRecordTraversal();
4746

include/vsg/app/CompileManager.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ namespace vsg
2727
{
2828
int result = VK_INCOMPLETE;
2929
std::string message;
30-
uint32_t maxStateSlot = 0;
31-
uint32_t maxViewSlot = 0;
30+
Slots maxSlots;
3231
bool containsPagedLOD = false;
3332
ResourceRequirements::Views views;
3433
ResourceRequirements::DynamicData dynamicData;

include/vsg/app/RecordTraversal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
1616
#include <vsg/core/Object.h>
1717
#include <vsg/core/type_name.h>
1818
#include <vsg/maths/mat4.h>
19+
#include <vsg/vk/Slots.h>
1920

2021
#include <set>
2122
#include <vector>
@@ -69,7 +70,7 @@ namespace vsg
6970
class VSG_DECLSPEC RecordTraversal : public Object
7071
{
7172
public:
72-
explicit RecordTraversal(uint32_t in_maxStateSlot = 0, uint32_t in_maxViewSlot = 0, const std::set<Bin*>& in_bins = {});
73+
explicit RecordTraversal(const Slots& in_maxSlots = {}, const std::set<Bin*>& in_bins = {});
7374

7475
RecordTraversal(const RecordTraversal&) = delete;
7576
RecordTraversal& operator=(const RecordTraversal& rhs) = delete;

include/vsg/state/ResourceHints.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ namespace vsg
3030
DYNAMIC_VIEWPORTSTATE = 1 << 1
3131
};
3232

33+
3334
/// ResourceHints provides settings that help preallocation of Vulkan resources and memory.
3435
class VSG_DECLSPEC ResourceHints : public Inherit<Object, ResourceHints>
3536
{
3637
public:
3738
ResourceHints();
3839

39-
bool empty() const noexcept { return maxStateSlot == 0 && maxViewSlot == 0 && numDescriptorSets == 0 && descriptorPoolSizes.empty(); }
40+
bool empty() const noexcept { return maxSlots.state == 0 && maxSlots.view == 0 && numDescriptorSets == 0 && descriptorPoolSizes.empty(); }
4041

41-
uint32_t maxStateSlot = 0;
42-
uint32_t maxViewSlot = 0;
42+
Slots maxSlots;
4343
uint32_t numDescriptorSets = 0;
4444
DescriptorPoolSizes descriptorPoolSizes;
4545

include/vsg/vk/CommandBuffer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace vsg
2323
class ViewDependentState;
2424
class GPUStatsCollection;
2525

26+
2627
/// CommandBuffer encapsulates VkCommandBuffer
2728
class VSG_DECLSPEC CommandBuffer : public Inherit<Object, CommandBuffer>
2829
{

include/vsg/vk/ResourceRequirements.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ namespace vsg
8888
Views views;
8989
ViewDetailStack viewDetailsStack;
9090

91-
uint32_t maxStateSlot = 0;
92-
uint32_t maxViewSlot = 0;
91+
Slots maxSlots;
9392
uint32_t externalNumDescriptorSets = 0;
9493
bool containsPagedLOD = false;
9594

include/vsg/vk/Slots.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#pragma once
2+
3+
/* <editor-fold desc="MIT License">
4+
5+
Copyright(c) 2025 Robert Osfield
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8+
9+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10+
11+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12+
13+
</editor-fold> */
14+
15+
namespace vsg
16+
{
17+
18+
/// max slot values used for general state and view state related State::stateStacks
19+
struct Slots
20+
{
21+
uint32_t state = 0;
22+
uint32_t view = 0;
23+
24+
/// return maximum of the state and view slot numbers
25+
uint32_t max() const
26+
{
27+
return view > state ? view : state;
28+
}
29+
30+
void merge(const Slots& rhs)
31+
{
32+
if (rhs.state > state) state = rhs.state;
33+
if (rhs.view > view) view = rhs.view;
34+
}
35+
};
36+
37+
} // namespace vsg

include/vsg/vk/State.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ namespace vsg
226226
class State : public Inherit<Object, State>
227227
{
228228
public:
229-
explicit State(uint32_t in_maxStateSlot, uint32_t in_maxViewSlot);
229+
explicit State(const Slots& in_maxSlots);
230230

231231
using StateCommandStack = StateStack<StateCommand>;
232232
using StateStacks = std::vector<StateCommandStack>;
@@ -246,9 +246,8 @@ namespace vsg
246246
dmat4 inheritedViewMatrix;
247247
dmat4 inheritedViewTransform;
248248

249+
Slots maxSlots;
249250
uint32_t activeMaxStateSlot = 0;
250-
uint32_t maxStateSlot = 0;
251-
uint32_t maxViewSlot = 0;
252251

253252
StateStacks stateStacks;
254253

@@ -257,7 +256,7 @@ namespace vsg
257256
MatrixStack projectionMatrixStack{0};
258257
MatrixStack modelviewMatrixStack{64};
259258

260-
void reserve(uint32_t in_maxStateSlot, uint32_t in_maxViewSlot);
259+
void reserve(const Slots& in_maxSlots);
261260

262261
void reset();
263262

@@ -299,7 +298,7 @@ namespace vsg
299298
}
300299

301300
// reset the active maxslot to the minimum required
302-
activeMaxStateSlot = maxStateSlot;
301+
activeMaxStateSlot = maxSlots.state;
303302

304303
projectionMatrixStack.record(*_commandBuffer);
305304
modelviewMatrixStack.record(*_commandBuffer);

src/vsg/app/CommandGraph.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ ref_ptr<RecordTraversal> CommandGraph::getOrCreateRecordTraversal()
6666
{
6767
//CPU_INSTRUMENTATION_L1(instrumentation);
6868
if (!recordTraversal)
69-
recordTraversal = RecordTraversal::create(maxStateSlot, maxViewSlot);
69+
recordTraversal = RecordTraversal::create(maxSlots);
7070
else
71-
recordTraversal->getState()->reserve(maxStateSlot, maxViewSlot);
71+
recordTraversal->getState()->reserve(maxSlots);
7272

7373
return recordTraversal;
7474
}

src/vsg/app/CompileManager.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ using namespace vsg;
2424
void CompileResult::reset()
2525
{
2626
result = VK_INCOMPLETE;
27-
maxStateSlot = 0;
28-
maxViewSlot = 0;
27+
maxSlots = {};
2928
containsPagedLOD = false;
3029
views.clear();
3130
dynamicData.clear();
@@ -38,8 +37,8 @@ void CompileResult::add(const CompileResult& cr)
3837
result = cr.result;
3938
}
4039

41-
if (cr.maxStateSlot > maxStateSlot) maxStateSlot = cr.maxStateSlot;
42-
if (cr.maxViewSlot > maxViewSlot) maxViewSlot = cr.maxViewSlot;
40+
maxSlots.merge(cr.maxSlots);
41+
4342
if (!containsPagedLOD) containsPagedLOD = cr.containsPagedLOD;
4443

4544
for (auto& [src_view, src_binDetails] : cr.views)
@@ -177,8 +176,7 @@ CompileResult CompileManager::compile(ref_ptr<Object> object, ContextSelectionFu
177176
auto& viewDetailsStack = requirements.viewDetailsStack;
178177

179178
CompileResult result;
180-
result.maxStateSlot = requirements.maxStateSlot;
181-
result.maxViewSlot = requirements.maxViewSlot;
179+
result.maxSlots = requirements.maxSlots;
182180
result.containsPagedLOD = requirements.containsPagedLOD;
183181
result.views = requirements.views;
184182
result.dynamicData = requirements.dynamicData;

0 commit comments

Comments
 (0)