NAP
pipelinekey.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // Local Includes
8 #include "materialcommon.h"
9 #include "mesh.h"
10 
11 namespace nap
12 {
13  // Forward Declares
14  class Shader;
15  class ComputeShader;
16  class MaterialInstance;
17  class ComputeMaterialInstance;
18 
24  struct NAPAPI PipelineKey
25  {
30  (
31  const Shader& shader,
32  EDrawMode drawMode,
33  EDepthMode depthMode,
34  EBlendMode blendMode,
35  ShaderConstantHash constantHash,
36  ECullWindingOrder cullWindingOrder,
37  VkFormat colorFormat,
38  VkFormat depthFormat,
39  VkSampleCountFlagBits sampleCount,
40  bool sampleShading,
41  ECullMode cullMode,
42  EPolygonMode polygonMode
43  );
44 
45  // TODO: Concatenate all properties into single / multiple 64bit values
46  bool operator==(const PipelineKey& rhs) const;
47 
48  const Shader* mShader = nullptr;
53  VkFormat mColorFormat = VK_FORMAT_UNDEFINED;
54  VkFormat mDepthFormat = VK_FORMAT_UNDEFINED;
55  VkSampleCountFlagBits mSampleCount = VK_SAMPLE_COUNT_1_BIT;
56  bool mSampleShading = false;
59  ShaderConstantHash mConstantHash = 0;
60  };
61 
62 
68  struct NAPAPI ComputePipelineKey
69  {
73  ComputePipelineKey(const ComputeShader& computeShader, ShaderConstantHash constantHash);
74 
75  bool operator==(const ComputePipelineKey& rhs) const;
76 
77  const ComputeShader* mShader = nullptr;
78  ShaderConstantHash mConstantHash = 0;
79  };
80 }
81 
82 namespace std
83 {
90  template<>
91  struct hash<nap::PipelineKey>
92  {
93  size_t operator()(const nap::PipelineKey& key) const
94  {
95  size_t shader_hash = hash<size_t>{}((size_t)key.mShader);
96  size_t draw_mode_hash = hash<size_t>{}((size_t)key.mDrawMode);
97  size_t depth_mode_hash = hash<size_t>{}((size_t)key.mDepthMode);
98  size_t blend_mode_hash = hash<size_t>{}((size_t)key.mBlendMode);
99  size_t cull_winding_hash = hash<size_t>{}((size_t)key.mCullWindingOrder);
100  size_t color_format_hash = hash<size_t>{}((size_t)key.mColorFormat);
101  size_t depth_format_hash = hash<size_t>{}((size_t)key.mDepthFormat);
102  size_t sample_count_hash = hash<size_t>{}((size_t)key.mSampleCount);
103  size_t sample_shading_hash = hash<size_t>{}((size_t)key.mSampleShading);
104  size_t cull_mode_hash = hash<size_t>{}((size_t)key.mCullMode);
105  size_t poly_mode_hash = hash<size_t>{}((size_t)key.mPolygonMode);
106  size_t constant_hash = hash<size_t>{}((size_t)key.mConstantHash);
107  return shader_hash ^ draw_mode_hash ^ depth_mode_hash ^ blend_mode_hash ^ cull_winding_hash ^ color_format_hash ^ depth_format_hash ^ sample_count_hash ^ sample_shading_hash ^ cull_mode_hash ^ poly_mode_hash ^ constant_hash;
108  }
109  };
110 
111 
112  template<>
113  struct hash<nap::ComputePipelineKey>
114  {
115  size_t operator()(const nap::ComputePipelineKey& key) const
116  {
117  size_t shader_hash = hash<size_t>{}((size_t)key.mShader);
118  size_t constant_hash = hash<size_t>{}((size_t)key.mConstantHash);
119  return shader_hash ^ constant_hash;
120  }
121  };
122 }
123 
nap::ComputeShader
Definition: shader.h:176
nap::ECullWindingOrder::Clockwise
@ Clockwise
nap::PipelineKey::mCullMode
ECullMode mCullMode
Definition: pipelinekey.h:57
nap::ShaderConstantHash
uint ShaderConstantHash
Definition: materialcommon.h:71
nap::PipelineKey::mCullWindingOrder
ECullWindingOrder mCullWindingOrder
Definition: pipelinekey.h:52
nap::PipelineKey::mBlendMode
EBlendMode mBlendMode
Definition: pipelinekey.h:51
nap::EPolygonMode
EPolygonMode
Definition: mesh.h:55
nap::PipelineKey::mPolygonMode
EPolygonMode mPolygonMode
Definition: pipelinekey.h:58
nap::EBlendMode
EBlendMode
Definition: materialcommon.h:18
nap::PipelineKey::mSampleShading
bool mSampleShading
Definition: pipelinekey.h:56
nap::ComputePipelineKey::mShader
const ComputeShader * mShader
Definition: pipelinekey.h:77
nap::ECullMode
ECullMode
Definition: mesh.h:43
nap::EDepthMode
EDepthMode
Definition: materialcommon.h:40
nap::ECullWindingOrder
ECullWindingOrder
Definition: materialcommon.h:30
nap::PipelineKey::mShader
const Shader * mShader
Definition: pipelinekey.h:48
nap::PipelineKey
Definition: pipelinekey.h:24
nap::ComputePipelineKey
Definition: pipelinekey.h:68
nap::EDepthMode::NotSet
@ NotSet
Default value for MaterialInstances, means that the Material's blend is used instead.
nap::PipelineKey::mSampleCount
VkSampleCountFlagBits mSampleCount
Definition: pipelinekey.h:55
nap::rtti::EPropertyFileType::ComputeShader
@ ComputeShader
Points to a .comp file, must be used with EPropertyMetaData::FileLink.
nap::Shader
Definition: shader.h:105
nap::PipelineKey::mDrawMode
EDrawMode mDrawMode
Definition: pipelinekey.h:49
nap::EBlendMode::NotSet
@ NotSet
Default value for MaterialInstances, means that the Material's blend mode is used instead.
nap::PipelineKey::mDepthMode
EDepthMode mDepthMode
Definition: pipelinekey.h:50
nap::ECullMode::Back
@ Back
Cull back facing triangles.
nap::EPolygonMode::Fill
@ Fill
Polygons are interpreted and rendered using the specified 'EDrawMode'.
nap::EDrawMode::Triangles
@ Triangles
Interpret the vertex data as a set of triangles.
nap
Definition: templateapp.h:17
nap::PipelineKey::mConstantHash
ShaderConstantHash mConstantHash
Definition: pipelinekey.h:59
nap::PipelineKey::mDepthFormat
VkFormat mDepthFormat
Definition: pipelinekey.h:54
nap::EDrawMode
EDrawMode
Definition: mesh.h:28
nap::PipelineKey::mColorFormat
VkFormat mColorFormat
Definition: pipelinekey.h:53
nap::ComputePipelineKey::mConstantHash
ShaderConstantHash mConstantHash
Definition: pipelinekey.h:78