Diligent Engine  v.2.4.g
PipelineResourceAttribsVk.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019-2021 Diligent Graphics LLC
3  * Copyright 2015-2019 Egor Yusov
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * In no event and under no legal theory, whether in tort (including negligence),
18  * contract, or otherwise, unless required by applicable law (such as deliberate
19  * and grossly negligent acts) or agreed to in writing, shall any Contributor be
20  * liable for any damages, including any direct, indirect, special, incidental,
21  * or consequential damages of any character arising as a result of this License or
22  * out of the use or inability to use the software (including but not limited to damages
23  * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
24  * all other commercial damages or losses), even if such Contributor has been advised
25  * of the possibility of such damages.
26  */
27 
28 #pragma once
29 
32 
33 #include "BasicTypes.h"
35 #include "PrivateConstants.h"
36 #include "DebugUtilities.hpp"
37 #include "HashUtils.hpp"
38 
39 namespace Diligent
40 {
41 
42 enum class DescriptorType : Uint8
43 {
44  Sampler,
59  Count,
60  Unknown = 0xFF,
61 };
62 
63 
64 // sizeof(PipelineResourceAttribsVk) == 16, x64
66 {
67 private:
68  static constexpr Uint32 _BindingIndexBits = 16;
69  static constexpr Uint32 _SamplerIndBits = 16;
70  static constexpr Uint32 _ArraySizeBits = 26;
71  static constexpr Uint32 _DescrTypeBits = 4;
72  static constexpr Uint32 _DescrSetBits = 1;
73  static constexpr Uint32 _SamplerAssignedBits = 1;
74 
75  static_assert((_BindingIndexBits + _ArraySizeBits + _SamplerIndBits + _DescrTypeBits + _DescrSetBits + _SamplerAssignedBits) % 32 == 0, "Bits are not optimally packed");
76 
77  // clang-format off
78  static_assert((1u << _DescrTypeBits) >= static_cast<Uint32>(DescriptorType::Count), "Not enough bits to store DescriptorType values");
79  static_assert((1u << _BindingIndexBits) >= MAX_RESOURCES_IN_SIGNATURE, "Not enough bits to store resource binding index");
80  static_assert((1u << _SamplerIndBits) >= MAX_RESOURCES_IN_SIGNATURE, "Not enough bits to store sampler resource index");
81  // clang-format on
82 
83 public:
84  static constexpr Uint32 MaxDescriptorSets = (1u << _DescrSetBits);
85  static constexpr Uint32 InvalidSamplerInd = (1u << _SamplerIndBits) - 1;
86 
87  // clang-format off
88  const Uint32 BindingIndex : _BindingIndexBits; // Binding in the descriptor set
89  const Uint32 SamplerInd : _SamplerIndBits; // Index of the assigned sampler in m_Desc.Resources and m_pPipelineResourceAttribsVk
90  const Uint32 ArraySize : _ArraySizeBits; // Array size
91  const Uint32 DescrType : _DescrTypeBits; // Descriptor type (DescriptorType)
92  const Uint32 DescrSet : _DescrSetBits; // Descriptor set (0 or 1)
93  const Uint32 ImtblSamplerAssigned : _SamplerAssignedBits; // Immutable sampler flag
94 
95  const Uint32 SRBCacheOffset; // Offset in the SRB resource cache
96  const Uint32 StaticCacheOffset; // Offset in the static resource cache
97  // clang-format on
98 
100  Uint32 _SamplerInd,
101  Uint32 _ArraySize,
102  DescriptorType _DescrType,
103  Uint32 _DescrSet,
104  bool _ImtblSamplerAssigned,
105  Uint32 _SRBCacheOffset,
106  Uint32 _StaticCacheOffset) noexcept :
107  // clang-format off
108  BindingIndex {_BindingIndex },
109  SamplerInd {_SamplerInd },
110  ArraySize {_ArraySize },
111  DescrType {static_cast<Uint32>(_DescrType)},
112  DescrSet {_DescrSet },
113  ImtblSamplerAssigned {_ImtblSamplerAssigned ? 1u : 0u},
114  SRBCacheOffset {_SRBCacheOffset },
115  StaticCacheOffset {_StaticCacheOffset }
116  // clang-format on
117  {
118  // clang-format off
119  VERIFY(BindingIndex == _BindingIndex, "Binding index (", _BindingIndex, ") exceeds maximum representable value");
120  VERIFY(ArraySize == _ArraySize, "Array size (", _ArraySize, ") exceeds maximum representable value");
121  VERIFY(SamplerInd == _SamplerInd, "Sampler index (", _SamplerInd, ") exceeds maximum representable value");
122  VERIFY(GetDescriptorType() == _DescrType, "Descriptor type (", static_cast<Uint32>(_DescrType), ") exceeds maximum representable value");
123  VERIFY(DescrSet == _DescrSet, "Descriptor set (", _DescrSet, ") exceeds maximum representable value");
124  // clang-format on
125  }
126 
128  {
130  }
131 
133  {
134  return static_cast<DescriptorType>(DescrType);
135  }
136 
138  {
139  return ImtblSamplerAssigned != 0;
140  }
141 
143  {
144  return SamplerInd != InvalidSamplerInd;
145  }
146 
148  {
149  // Ignore sampler index and cache offsets.
150  // clang-format off
151  return BindingIndex == rhs.BindingIndex &&
152  ArraySize == rhs.ArraySize &&
153  DescrType == rhs.DescrType &&
154  DescrSet == rhs.DescrSet &&
156  // clang-format on
157  }
158 
159  size_t GetHash() const
160  {
162  }
163 };
164 
166 {
167  static_assert(static_cast<Uint32>(DescriptorType::Count) == 15, "Please update the switch below to handle the new descriptor type");
168  switch (Type)
169  {
170  // clang-format off
171  case DescriptorType::Sampler: return VK_DESCRIPTOR_TYPE_SAMPLER;
172  case DescriptorType::CombinedImageSampler: return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
173  case DescriptorType::SeparateImage: return VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
174  case DescriptorType::StorageImage: return VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
175  case DescriptorType::UniformTexelBuffer: return VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
176  case DescriptorType::StorageTexelBuffer: return VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
177  case DescriptorType::StorageTexelBuffer_ReadOnly: return VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
178  case DescriptorType::UniformBuffer: return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
179  case DescriptorType::UniformBufferDynamic: return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
180  case DescriptorType::StorageBuffer: return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
181  case DescriptorType::StorageBuffer_ReadOnly: return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
182  case DescriptorType::StorageBufferDynamic: return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC;
183  case DescriptorType::StorageBufferDynamic_ReadOnly: return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC;
184  case DescriptorType::InputAttachment: return VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
185  case DescriptorType::AccelerationStructure: return VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR;
186  // clang-format on
187  default:
188  UNEXPECTED("Unknown descriptor type");
189  return VK_DESCRIPTOR_TYPE_MAX_ENUM;
190  }
191 }
192 
193 
194 } // namespace Diligent
Diligent::ResourceCacheContentType
ResourceCacheContentType
The type of the content that is stored in the shader resource cache.
Definition: ShaderResourceCacheCommon.hpp:39
ShaderResourceCacheCommon.hpp
Diligent::PipelineResourceAttribsVk::MaxDescriptorSets
static constexpr Uint32 MaxDescriptorSets
Definition: PipelineResourceAttribsVk.hpp:84
Diligent::PipelineResourceAttribsVk::IsCompatibleWith
bool IsCompatibleWith(const PipelineResourceAttribsVk &rhs) const
Definition: PipelineResourceAttribsVk.hpp:147
Diligent::DescriptorType::StorageBufferDynamic_ReadOnly
@ StorageBufferDynamic_ReadOnly
Diligent::PipelineResourceAttribsVk::DescrType
const Uint32 DescrType
Definition: PipelineResourceAttribsVk.hpp:91
Diligent::PipelineResourceAttribsVk::DescrSet
const Uint32 DescrSet
Definition: PipelineResourceAttribsVk.hpp:92
Diligent::PipelineResourceAttribsVk::SamplerInd
const Uint32 SamplerInd
Definition: PipelineResourceAttribsVk.hpp:89
UNEXPECTED
#define UNEXPECTED(...)
Definition: DebugUtilities.hpp:77
Diligent::PipelineResourceAttribsVk::ImtblSamplerAssigned
const Uint32 ImtblSamplerAssigned
Definition: PipelineResourceAttribsVk.hpp:93
Diligent::PipelineResourceAttribsVk::StaticCacheOffset
const Uint32 StaticCacheOffset
Definition: PipelineResourceAttribsVk.hpp:96
PrivateConstants.h
DebugUtilities.hpp
Diligent::DescriptorType::StorageImage
@ StorageImage
Diligent::PipelineResourceAttribsVk::GetHash
size_t GetHash() const
Definition: PipelineResourceAttribsVk.hpp:159
Diligent::DescriptorType::UniformBufferDynamic
@ UniformBufferDynamic
Diligent::DescriptorTypeToVkDescriptorType
VkDescriptorType DescriptorTypeToVkDescriptorType(DescriptorType Type)
Definition: PipelineResourceAttribsVk.hpp:165
Diligent::PipelineResourceAttribsVk::ArraySize
const Uint32 ArraySize
Definition: PipelineResourceAttribsVk.hpp:90
Diligent::DescriptorType::Count
@ Count
Diligent::DescriptorType::StorageTexelBuffer
@ StorageTexelBuffer
Diligent::PipelineResourceAttribsVk::IsImmutableSamplerAssigned
bool IsImmutableSamplerAssigned() const
Definition: PipelineResourceAttribsVk.hpp:137
Diligent::PipelineResourceAttribsVk::IsCombinedWithSampler
bool IsCombinedWithSampler() const
Definition: PipelineResourceAttribsVk.hpp:142
Diligent::PipelineResourceAttribsVk::PipelineResourceAttribsVk
PipelineResourceAttribsVk(Uint32 _BindingIndex, Uint32 _SamplerInd, Uint32 _ArraySize, DescriptorType _DescrType, Uint32 _DescrSet, bool _ImtblSamplerAssigned, Uint32 _SRBCacheOffset, Uint32 _StaticCacheOffset) noexcept
Definition: PipelineResourceAttribsVk.hpp:99
Diligent::DescriptorType::StorageBuffer
@ StorageBuffer
BasicTypes.h
Diligent::DescriptorType::Unknown
@ Unknown
Type
const D3D12_PIPELINE_STATE_SUBOBJECT_TYPE Type
Definition: PipelineStateD3D12Impl.cpp:69
Diligent::Uint32
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
Diligent::ComputeHash
std::size_t ComputeHash(const ArgsType &... Args)
Definition: HashUtils.hpp:57
Diligent::DescriptorType::InputAttachment
@ InputAttachment
Diligent::DescriptorType::StorageBufferDynamic
@ StorageBufferDynamic
Diligent::PipelineResourceAttribsVk::BindingIndex
const Uint32 BindingIndex
Definition: PipelineResourceAttribsVk.hpp:88
Diligent::DescriptorType::UniformTexelBuffer
@ UniformTexelBuffer
Diligent::DescriptorType::SeparateImage
@ SeparateImage
Diligent::PipelineResourceAttribsVk::GetDescriptorType
DescriptorType GetDescriptorType() const
Definition: PipelineResourceAttribsVk.hpp:132
Diligent::ResourceCacheContentType::SRB
@ SRB
Resources of a shader resource binding.
Diligent::DescriptorType
DescriptorType
Definition: PipelineResourceAttribsVk.hpp:42
Diligent::DescriptorType::Sampler
@ Sampler
Diligent::PipelineResourceAttribsVk::SRBCacheOffset
const Uint32 SRBCacheOffset
Definition: PipelineResourceAttribsVk.hpp:95
Diligent::DescriptorType::StorageTexelBuffer_ReadOnly
@ StorageTexelBuffer_ReadOnly
HashUtils.hpp
Diligent::Uint8
uint8_t Uint8
8-bit unsigned integer
Definition: BasicTypes.h:53
Diligent::DescriptorType::StorageBuffer_ReadOnly
@ StorageBuffer_ReadOnly
VERIFY
#define VERIFY(...)
Definition: DebugUtilities.hpp:76
Diligent::DescriptorType::CombinedImageSampler
@ CombinedImageSampler
Diligent::PipelineResourceAttribsVk::InvalidSamplerInd
static constexpr Uint32 InvalidSamplerInd
Definition: PipelineResourceAttribsVk.hpp:85
Diligent::PipelineResourceAttribsVk
Definition: PipelineResourceAttribsVk.hpp:65
Diligent::DescriptorType::AccelerationStructure
@ AccelerationStructure
Diligent::PipelineResourceAttribsVk::CacheOffset
Uint32 CacheOffset(ResourceCacheContentType CacheType) const
Definition: PipelineResourceAttribsVk.hpp:127
Diligent
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37
Diligent::DescriptorType::UniformBuffer
@ UniformBuffer