-
Notifications
You must be signed in to change notification settings - Fork 270
Expand file tree
/
Copy pathCommandBuffer.h
More file actions
104 lines (75 loc) · 4.14 KB
/
CommandBuffer.h
File metadata and controls
104 lines (75 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#pragma once
/* <editor-fold desc="MIT License">
Copyright(c) 2018 Robert Osfield
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:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
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.
</editor-fold> */
#include <vsg/core/ScratchMemory.h>
#include <vsg/state/PipelineLayout.h>
#include <vsg/vk/CommandPool.h>
namespace vsg
{
// forward declare
class ViewDependentState;
class GPUStatsCollection;
class State;
/// CommandBuffer encapsulates VkCommandBuffer
class VSG_DECLSPEC CommandBuffer : public Inherit<Object, CommandBuffer>
{
public:
const VkCommandBuffer* data() const { return &_commandBuffer; }
operator VkCommandBuffer() const { return _commandBuffer; }
VkCommandBuffer vk() const { return _commandBuffer; }
std::atomic_uint& numDependentSubmissions() { return _numDependentSubmissions; }
const uint32_t deviceID;
uint32_t viewID = 0;
Mask traversalMask = MASK_ALL;
Mask overrideMask = MASK_OFF;
ViewDependentState* viewDependentState = nullptr;
State* state = nullptr;
ref_ptr<GPUStatsCollection> gpuStats;
VkCommandBufferLevel level() const { return _level; }
/// reset the CommandBuffer for the new frame.
void reset();
Device* getDevice() { return _device; }
const Device* getDevice() const { return _device; }
CommandPool* getCommandPool() { return _commandPool; }
const CommandPool* getCommandPool() const { return _commandPool; }
void setCurrentPipelineLayout(const PipelineLayout* pipelineLayout);
VkPipelineLayout getCurrentPipelineLayout() const { return _currentPipelineLayout; }
const std::vector<bool>& getCurrentDescriptorSetSlots() const { return _currentDescriptorSetSlots; }
VkShaderStageFlags getCurrentPushConstantStageFlags() const { return _currentPushConstantStageFlags; }
ref_ptr<ScratchMemory> scratchMemory;
protected:
friend CommandPool;
CommandBuffer(CommandPool* commandPool, VkCommandBuffer commandBuffer, VkCommandBufferLevel level);
virtual ~CommandBuffer();
VkCommandBuffer _commandBuffer;
VkCommandBufferLevel _level;
std::atomic_uint _numDependentSubmissions{0};
ref_ptr<Device> _device;
ref_ptr<CommandPool> _commandPool;
VkPipelineLayout _currentPipelineLayout;
std::vector<bool> _currentDescriptorSetSlots;
VkShaderStageFlags _currentPushConstantStageFlags;
};
VSG_type_name(vsg::CommandBuffer);
using CommandBuffers = std::vector<ref_ptr<CommandBuffer>>;
/// Thread safe container class
class RecordedCommandBuffers : public Inherit<Object, RecordedCommandBuffers>
{
public:
ref_ptr<RecordedCommandBuffers> getOrCreateRecordedCommandBuffers(int submitOrder);
void clear();
void add(int order, ref_ptr<CommandBuffer> commandGraph);
bool empty() const;
CommandBuffers buffers() const;
protected:
virtual ~RecordedCommandBuffers();
mutable std::mutex _mutex;
std::map<int, ref_ptr<RecordedCommandBuffers>> _orderedCommandBuffers;
CommandBuffers _commandBuffers;
};
VSG_type_name(vsg::RecordedCommandBuffers);
} // namespace vsg