-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathIGraphicsPipeline.h
More file actions
119 lines (92 loc) · 4.66 KB
/
IGraphicsPipeline.h
File metadata and controls
119 lines (92 loc) · 4.66 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
#ifndef _NBL_ASSET_I_GRAPHICS_PIPELINE_H_INCLUDED_
#define _NBL_ASSET_I_GRAPHICS_PIPELINE_H_INCLUDED_
#include "nbl/asset/IShader.h"
#include "nbl/asset/RasterizationStates.h"
#include "nbl/asset/IPipeline.h"
#include "nbl/asset/IRenderpass.h"
#include "nbl/asset/IRasterizationPipeline.h"
#include <span>
namespace nbl::asset
{
struct SVertexInputAttribParams
{
inline auto operator<=>(const SVertexInputAttribParams& rhs) const = default;
uint32_t binding : 4 = 0;
uint32_t format : 8 = EF_UNKNOWN; // asset::E_FORMAT
uint32_t relativeOffset : 13 = 0; // assuming max=2048
};
static_assert(sizeof(SVertexInputAttribParams)==4u, "Unexpected size!");
struct SVertexInputBindingParams
{
enum E_VERTEX_INPUT_RATE : uint32_t
{
EVIR_PER_VERTEX = 0,
EVIR_PER_INSTANCE = 1
};
inline auto operator<=>(const SVertexInputBindingParams& rhs) const = default;
uint32_t stride : 31 = 0u;
E_VERTEX_INPUT_RATE inputRate : 1 = EVIR_PER_VERTEX;
};
static_assert(sizeof(SVertexInputBindingParams)==4u, "Unexpected size!");
struct SVertexInputParams
{
constexpr static inline size_t MAX_VERTEX_ATTRIB_COUNT = 16u;
constexpr static inline size_t MAX_ATTR_BUF_BINDING_COUNT = 16u;
inline auto operator<=>(const SVertexInputParams& rhs) const = default;
uint16_t enabledAttribFlags = 0u;
uint16_t enabledBindingFlags = 0u;
//! index in array denotes location (attribute ID)
SVertexInputAttribParams attributes[MAX_VERTEX_ATTRIB_COUNT] = {};
//! index in array denotes binding number
SVertexInputBindingParams bindings[MAX_ATTR_BUF_BINDING_COUNT] = {};
};
static_assert(sizeof(SVertexInputParams)==(sizeof(uint16_t)*2u+SVertexInputParams::MAX_VERTEX_ATTRIB_COUNT*sizeof(SVertexInputAttribParams)+SVertexInputParams::MAX_ATTR_BUF_BINDING_COUNT*sizeof(SVertexInputBindingParams)),"Unexpected size!");
struct SPrimitiveAssemblyParams
{
inline auto operator<=>(const SPrimitiveAssemblyParams& other) const = default;
E_PRIMITIVE_TOPOLOGY primitiveType : 5 = EPT_TRIANGLE_LIST;
uint16_t primitiveRestartEnable : 1 = false;
uint16_t tessPatchVertCount : 10 = 3u;
};
static_assert(sizeof(SPrimitiveAssemblyParams)==2u, "Unexpected size!");
class IGraphicsPipelineBase : public virtual core::IReferenceCounted
{
public:
constexpr static inline uint8_t GRAPHICS_SHADER_STAGE_COUNT = 5u;
struct SCachedCreationParams final : public IRasterizationPipelineBase::SCachedCreationParams
{
SVertexInputParams vertexInput = {};
SPrimitiveAssemblyParams primitiveAssembly = {};
};
};
template<typename PipelineLayoutType, typename RenderpassType>
class IGraphicsPipeline : public IRasterizationPipeline<PipelineLayoutType, RenderpassType>, public IGraphicsPipelineBase
{
protected:
using renderpass_t = RenderpassType;
public:
inline const SCachedCreationParams& getCachedCreationParams() const {return m_params;}
static inline bool hasRequiredStages(const core::bitflag<hlsl::ShaderStage>& stagePresence, E_PRIMITIVE_TOPOLOGY primitiveType)
{
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkGraphicsPipelineCreateInfo.html#VUID-VkGraphicsPipelineCreateInfo-stage-02096
if (!stagePresence.hasFlags(hlsl::ShaderStage::ESS_VERTEX))
return false;
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkGraphicsPipelineCreateInfo.html#VUID-VkGraphicsPipelineCreateInfo-pStages-00729
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkGraphicsPipelineCreateInfo.html#VUID-VkGraphicsPipelineCreateInfo-pStages-00730
if (stagePresence.hasFlags(hlsl::ShaderStage::ESS_TESSELLATION_CONTROL)!=stagePresence.hasFlags(hlsl::ShaderStage::ESS_TESSELLATION_EVALUATION))
return false;
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkGraphicsPipelineCreateInfo.html#VUID-VkGraphicsPipelineCreateInfo-pStages-08888
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkGraphicsPipelineCreateInfo.html#VUID-VkGraphicsPipelineCreateInfo-topology-08889
if (stagePresence.hasFlags(hlsl::ShaderStage::ESS_TESSELLATION_EVALUATION)!=(primitiveType==asset::EPT_PATCH_LIST))
return false;
return true;
}
protected:
explicit IGraphicsPipeline(PipelineLayoutType* layout, const SCachedCreationParams& cachedParams, renderpass_t* renderpass) :
IRasterizationPipeline<PipelineLayoutType, renderpass_t>(layout, renderpass),
m_params(cachedParams)
{}
SCachedCreationParams m_params = {};
};
}
#endif