forked from RichDavisonNCL/VulkanRendering
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVulkanPipelineBuilderBase.h
83 lines (68 loc) · 2.17 KB
/
VulkanPipelineBuilderBase.h
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
/******************************************************************************
This file is part of the Newcastle Vulkan Tutorial Series
Author:Rich Davison
Contact:[email protected]
License: MIT (see LICENSE file at the top of the source tree)
*//////////////////////////////////////////////////////////////////////////////
#pragma once
#include "VulkanPipeline.h"
#include "VulkanUtils.h"
namespace NCL::Rendering::Vulkan {
class VulkanRenderer;
class VulkanShader;
struct VulkanVertexSpecification;
template <class T, class P>
class PipelineBuilderBase {
public:
T& WithLayout(vk::PipelineLayout pipeLayout) {
layout = pipeLayout;
pipelineCreate.setLayout(pipeLayout);
return (T&)*this;
}
T& WithDescriptorSetLayout(uint32_t setIndex, vk::DescriptorSetLayout layout) {
assert(setIndex < 32);
if (setIndex >= userLayouts.size()) {
vk::DescriptorSetLayout nullLayout = Vulkan::GetNullDescriptor(sourceDevice);
while (userLayouts.size() <= setIndex) {
userLayouts.push_back(nullLayout);
}
}
userLayouts[setIndex] = layout;
return (T&)*this;
}
T& WithDescriptorSetLayout(uint32_t setIndex, const vk::UniqueDescriptorSetLayout& layout) {
return WithDescriptorSetLayout(setIndex, *layout);
}
T& WithDescriptorBuffers() {
pipelineCreate.flags |= vk::PipelineCreateFlagBits::eDescriptorBufferEXT;
return (T&)*this;
}
P& GetCreateInfo() {
return pipelineCreate;
}
protected:
PipelineBuilderBase(vk::Device device) {
sourceDevice = device;
}
~PipelineBuilderBase() {}
void FinaliseDescriptorLayouts() {
allLayouts.clear();
for (int i = 0; i < reflectionLayouts.size(); ++i) {
if (userLayouts.size() > i && userLayouts[i] != Vulkan::GetNullDescriptor(sourceDevice)) {
allLayouts.push_back(userLayouts[i]);
}
else {
allLayouts.push_back(reflectionLayouts[i]);
}
}
}
protected:
P pipelineCreate;
vk::PipelineLayout layout;
vk::Device sourceDevice;
std::vector< vk::DescriptorSetLayout> allLayouts;
std::vector< vk::DescriptorSetLayout> reflectionLayouts;
std::vector< vk::DescriptorSetLayout> userLayouts;
std::vector< vk::PushConstantRange> allPushConstants;
};
}