-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDescriptorSetBuilder.h
More file actions
150 lines (97 loc) · 3.41 KB
/
DescriptorSetBuilder.h
File metadata and controls
150 lines (97 loc) · 3.41 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#pragma once
#include"VulkanCore.h"
#include"DescriptorSetLayoutFactory.h"
#include"GpuBufferFactory.h"
#include"TextureFactory.h"
struct DescriptorSetBufferProperty
{
uint32_t binding;
VkDescriptorType type;
std::shared_ptr<GpuBuffer> buffer;
VkDescriptorBufferInfo bufferInfo;
void initProperty()
{
binding = 0;
type = VkDescriptorType{};
buffer = nullptr;
bufferInfo = VkDescriptorBufferInfo{};
}
};
struct DescriptorSetImageProperty
{
uint32_t binding;
VkDescriptorType type;
std::shared_ptr<Texture> texture;
VkDescriptorImageInfo imageInfo;
void initProperty()
{
binding = 0;
type = VkDescriptorType{};
texture = nullptr;
imageInfo = VkDescriptorImageInfo{};
}
};
struct DescriptorSetProperty
{
VkDescriptorSetAllocateInfo allocateInfo;
uint32_t infoIndex;
std::shared_ptr<DescriptorSetLayout> layout;
std::vector<DescriptorSetBufferProperty> buffer;
std::vector<DescriptorSetImageProperty> texture;
void initProperty(VkDescriptorPool& pool)
{
allocateInfo = VkDescriptorSetAllocateInfo{};
allocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
allocateInfo.descriptorPool = pool;
buffer.clear();
texture.clear();
}
};
class DescriptorSetBuilder : public std::enable_shared_from_this<DescriptorSetBuilder>
{
private:
VkDevice device;
VkDescriptorPool descriptorPool;
DescriptorSetBufferProperty bufferProperty;
DescriptorSetImageProperty imageProperty;
DescriptorSetProperty property;
//VkDescriptorSetPoolの作成
void createDescriptorPool();
public:
DescriptorSetBuilder(VkDevice& d);
~DescriptorSetBuilder()
{
// プールから確保したすべてのVkDescriptorSetをまとめて破棄する
vkResetDescriptorPool(device, descriptorPool, 0);
vkDestroyDescriptorPool(device, descriptorPool, nullptr);
#ifdef _DEBUG
std::cout << "DescriptorSetBuilder :: デストラクタ" << std::endl;
#endif
}
VkDescriptorPool& getPool()
{
return descriptorPool;
}
DescriptorSetProperty Build();
void Create(const DescriptorSetProperty& property, VkDescriptorSet& descriptorSet);
//プロパティの初期化
std::shared_ptr<DescriptorSetBuilder> initProperty();
//VkDescriptorSetLayoutの設定
std::shared_ptr<DescriptorSetBuilder> withDescriptorSetLayout(const std::shared_ptr<DescriptorSetLayout>& layout);
//VkDescriptorSetの個数の設定
std::shared_ptr<DescriptorSetBuilder> withDescriptorSetCount(const uint32_t& count);
//VkDescriptorBufferInfoの設定///////
std::shared_ptr<DescriptorSetBuilder> withBindingBuffer(const uint32_t& binding);
std::shared_ptr<DescriptorSetBuilder> withTypeBuffer(const VkDescriptorType& type);
std::shared_ptr<DescriptorSetBuilder> withBuffer(const std::shared_ptr<GpuBuffer>& buffer);
std::shared_ptr<DescriptorSetBuilder> withOffset(const uint32_t& offset);
std::shared_ptr<DescriptorSetBuilder> withRange(const uint32_t& range);
std::shared_ptr<DescriptorSetBuilder> addBufferInfo();
//VkDescriptorImageInfo/////////
std::shared_ptr<DescriptorSetBuilder> withBindingImage(const uint32_t& binding);
std::shared_ptr<DescriptorSetBuilder> withTypeImage(const VkDescriptorType& type);
std::shared_ptr<DescriptorSetBuilder> withImageLayout(const VkImageLayout& layout);
std::shared_ptr<DescriptorSetBuilder> withTexture(const std::shared_ptr<Texture> texture);
std::shared_ptr<DescriptorSetBuilder> withTexture(const std::shared_ptr<Texture> texture, const uint32_t targetLayer);
std::shared_ptr<DescriptorSetBuilder> addImageInfo();
};