Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
Pipeline.cpp
Go to the documentation of this file.
1
2
3#include "Headers/Pipeline.h"
4
7
8namespace Divide {
9size_t GetHash( const PipelineDescriptor& descriptor )
10{
11 size_t hash = GetHash(descriptor._stateBlock);
12 Util::Hash_combine( hash, descriptor._multiSampleCount,
13 descriptor._shaderProgramHandle._generation,
14 descriptor._shaderProgramHandle._index,
15 descriptor._primitiveTopology,
16 descriptor._alphaToCoverage );
17
18 for ( U8 i = 0u; i < to_base( ShaderType::COUNT ); ++i )
19 {
20 Util::Hash_combine( hash, i );
21 }
22
23 Util::Hash_combine( hash, GetHash( descriptor._blendStates ) );
24 Util::Hash_combine( hash, GetHash( descriptor._vertexFormat ) );
25
26 return hash;
27}
28
29bool operator==(const PipelineDescriptor& lhs, const PipelineDescriptor& rhs) {
30 return lhs._primitiveTopology == rhs._primitiveTopology &&
33 lhs._blendStates == rhs._blendStates &&
34 lhs._vertexFormat == rhs._vertexFormat &&
35 lhs._stateBlock == rhs._stateBlock;
36}
37
38bool operator!=(const PipelineDescriptor& lhs, const PipelineDescriptor& rhs) {
39 return lhs._primitiveTopology != rhs._primitiveTopology ||
42 lhs._blendStates != rhs._blendStates ||
43 lhs._vertexFormat != rhs._vertexFormat ||
44 lhs._stateBlock != rhs._stateBlock;
45}
46
47namespace
48{
49 size_t GetFullStateHash( const Pipeline& pipeline, const size_t compiledStateHash, const size_t blendStateHash )
50 {
51 size_t hash = compiledStateHash;
52
53 Util::Hash_combine( hash, blendStateHash ); //VK_DYNAMIC_STATE_COLOR_BLEND_ENABLE_EXT + VK_DYNAMIC_STATE_COLOR_BLEND_EQUATION_EXT + VK_DYNAMIC_STATE_COLOR_WRITE_MASK_EXT
54
55 const RenderStateBlock& block = pipeline.descriptor()._stateBlock;
57 to_U32( std::floor( block._zBias * 1000.0f + 0.5f ) ), //VK_DYNAMIC_STATE_DEPTH_BIAS
58 to_U32( std::floor( block._zUnits * 1000.0f + 0.5f ) ), //VK_DYNAMIC_STATE_DEPTH_BIAS
59 to_U32( block._cullMode ), //VK_DYNAMIC_STATE_CULL_MODE
60 block._scissorTestEnabled, //VK_DYNAMIC_STATE_SCISSOR
61 block._frontFaceCCW, //VK_DYNAMIC_STATE_FRONT_FACE
62 block._stencilRef, //VK_DYNAMIC_STATE_STENCIL_REFERENCE
63 block._stencilMask, //VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK
64 block._stencilWriteMask, //VK_DYNAMIC_STATE_STENCIL_WRITE_MASK
65 block._stencilEnabled, //VK_DYNAMIC_STATE_STENCIL_TEST_ENABLE
66 to_U32( block._stencilFailOp ), //VK_DYNAMIC_STATE_STENCIL_OP
67 to_U32( block._stencilZFailOp ), //VK_DYNAMIC_STATE_STENCIL_OP
68 to_U32( block._stencilPassOp ), //VK_DYNAMIC_STATE_STENCIL_OP
69 to_U32( block._stencilFunc ), //VK_DYNAMIC_STATE_STENCIL_OP
70 to_U32( block._zFunc ), //VK_DYNAMIC_STATE_DEPTH_COMPARE_OP
71 block._rasterizationEnabled, //VK_DYNAMIC_STATE_RASTERIZER_DISCARD_ENABLE
72 block._primitiveRestartEnabled, //VK_DYNAMIC_STATE_PRIMITIVE_RESTART_ENABLE
73 block._depthWriteEnabled, //VK_DYNAMIC_STATE_DEPTH_WRITE_ENABLE
74 block._depthTestEnabled); //VK_DYNAMIC_STATE_DEPTH_TEST_ENABLE
75 return hash;
76 }
77
78 size_t GetVulkanPipelineHash( const Pipeline& pipeline, const size_t vertexFormatHash )
79 {
80 const auto& descriptor = pipeline.descriptor();
81
82 size_t hash = vertexFormatHash;
83 for ( U8 i = 0u; i < to_base( ShaderType::COUNT ); ++i )
84 {
85 Util::Hash_combine( hash, i );
86 }
87
89 descriptor._multiSampleCount,
90 descriptor._shaderProgramHandle._generation,
91 descriptor._shaderProgramHandle._index,
92 descriptor._primitiveTopology,
93 descriptor._alphaToCoverage);
94
95 const RenderStateBlock& block = descriptor._stateBlock;
97 //to_U32( std::floor( block._zBias * 1000.0f + 0.5f ) ), //VK_DYNAMIC_STATE_DEPTH_BIAS
98 //to_U32( std::floor( block._zUnits * 1000.0f + 0.5f ) ), //VK_DYNAMIC_STATE_DEPTH_BIAS
99 //to_U32( block._cullMode ), //VK_DYNAMIC_STATE_CULL_MODE
100 //block._frontFaceCCW, //VK_DYNAMIC_STATE_FRONT_FACE
101 //block._depthTestEnabled, //VK_DYNAMIC_STATE_DEPTH_TEST_ENABLE
102 //block._depthWriteEnabled, //VK_DYNAMIC_STATE_DEPTH_WRITE_ENABLE
103 //to_U32( block._zFunc ), //VK_DYNAMIC_STATE_DEPTH_COMPARE_OP
104 //block._scissorTestEnabled, //VK_DYNAMIC_STATE_SCISSOR
105 //block._stencilEnabled, //VK_DYNAMIC_STATE_STENCIL_TEST_ENABLE
106 //block._stencilRef, //VK_DYNAMIC_STATE_STENCIL_REFERENCE
107 //block._stencilMask, //VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK
108 //block._stencilWriteMask, //VK_DYNAMIC_STATE_STENCIL_WRITE_MASK
109 //to_U32( block._stencilFailOp ), //VK_DYNAMIC_STATE_STENCIL_OP
110 //to_U32( block._stencilZFailOp ), //VK_DYNAMIC_STATE_STENCIL_OP
111 //to_U32( block._stencilPassOp ), //VK_DYNAMIC_STATE_STENCIL_OP
112 //to_U32( block._stencilFunc ), //VK_DYNAMIC_STATE_STENCIL_OP
113 //block._rasterizationEnabled, //VK_DYNAMIC_STATE_RASTERIZER_DISCARD_ENABLE
114 //block._primitiveRestartEnabled, //VK_DYNAMIC_STATE_PRIMITIVE_RESTART_ENABLE
115 block._colourWrite.i,
116 to_U32( block._fillMode ),
117 block._tessControlPoints );
118
119 return hash;
120 }
121};
122
124 : _descriptor(descriptor)
125 , _blendStateHash( GetHash( descriptor._blendStates ) )
126{
127 _vertexFormatHash = GetHash( descriptor._vertexFormat );
128 _compiledPipelineHash = GetVulkanPipelineHash(*this, _vertexFormatHash );
129 _stateHash = GetFullStateHash(*this, _compiledPipelineHash, _blendStateHash );
130}
131
132bool operator==(const Pipeline& lhs, const Pipeline& rhs) noexcept {
133 return lhs.stateHash() == rhs.stateHash();
134}
135
136bool operator!=(const Pipeline& lhs, const Pipeline& rhs) noexcept {
137 return lhs.stateHash() != rhs.stateHash();
138}
139
140} //namespace Divide
Pipeline(const PipelineDescriptor &descriptor)
Definition: Pipeline.cpp:123
void Hash_combine(size_t &seed, const T &v, const Rest &... rest) noexcept
a la Boost
Definition: MathHelper.inl:799
size_t GetFullStateHash(const Pipeline &pipeline, const size_t compiledStateHash, const size_t blendStateHash)
Definition: Pipeline.cpp:49
size_t GetVulkanPipelineHash(const Pipeline &pipeline, const size_t vertexFormatHash)
Definition: Pipeline.cpp:78
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
FORCE_INLINE bool operator!=(const GUIDWrapper &lhs, const GUIDWrapper &rhs) noexcept
Definition: GUIDWrapper.h:67
constexpr U32 to_U32(const T value)
uint8_t U8
size_t GetHash(const PropertyDescriptor< T > &descriptor) noexcept
Definition: Resource.inl:40
bool operator==(const DisplayManager::OutputDisplayProperties &lhs, const DisplayManager::OutputDisplayProperties &rhs) noexcept
Definition: Application.inl:37
constexpr auto to_base(const Type value) -> Type
PrimitiveTopology _primitiveTopology
Definition: Pipeline.h:48
AttributeMap _vertexFormat
Definition: Pipeline.h:49
Handle< ShaderProgram > _shaderProgramHandle
Definition: Pipeline.h:47
RTBlendStates _blendStates
Definition: Pipeline.h:45
RenderStateBlock _stateBlock
Definition: Pipeline.h:46
StencilOperation _stencilZFailOp
StencilOperation _stencilFailOp
ComparisonFunction _stencilFunc
StencilOperation _stencilPassOp
ComparisonFunction _zFunc