Diligent Engine  v.2.4.g
PipelineResourceAttribsD3D12.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"
34 #include "PrivateConstants.h"
36 #include "DebugUtilities.hpp"
37 #include "HashUtils.hpp"
38 
39 namespace Diligent
40 {
41 
42 // sizeof(ResourceAttribs) == 16, x64
44 {
45 private:
46  static constexpr Uint32 _RegisterBits = 16;
47  static constexpr Uint32 _SRBRootIndexBits = 16;
48  static constexpr Uint32 _SamplerIndBits = 16;
49  static constexpr Uint32 _SpaceBits = 8;
50  static constexpr Uint32 _SigRootIndexBits = 3;
51  static constexpr Uint32 _SamplerAssignedBits = 1;
52  static constexpr Uint32 _RootParamTypeBits = 3;
53 
54  // clang-format off
55  static_assert((1u << _RegisterBits) >= MAX_RESOURCES_IN_SIGNATURE, "Not enough bits to store shader register");
56  static_assert((1u << _SamplerIndBits) >= MAX_RESOURCES_IN_SIGNATURE, "Not enough bits to store sampler resource index");
57  static_assert((1u << _RootParamTypeBits) > D3D12_ROOT_PARAMETER_TYPE_UAV + 1, "Not enough bits to store D3D12_ROOT_PARAMETER_TYPE");
58  // clang-format on
59 
60 public:
61  static constexpr Uint32 InvalidSamplerInd = (1u << _SamplerIndBits) - 1;
62  static constexpr Uint32 InvalidSRBRootIndex = (1u << _SRBRootIndexBits) - 1;
63  static constexpr Uint32 InvalidSigRootIndex = (1u << _SigRootIndexBits) - 1;
64  static constexpr Uint32 InvalidRegister = (1u << _RegisterBits) - 1;
65  static constexpr Uint32 InvalidOffset = ~0u;
66 
67  // clang-format off
68 /* 0 */const Uint32 Register : _RegisterBits; // Shader register
69 /* 2 */const Uint32 SRBRootIndex : _SRBRootIndexBits; // Root view/table index in the SRB
70 /* 4 */const Uint32 SamplerInd : _SamplerIndBits; // Assigned sampler index in m_Desc.Resources and m_pResourceAttribs
71 /* 6 */const Uint32 Space : _SpaceBits; // Shader register space
72 /* 7.0*/const Uint32 SigRootIndex : _SigRootIndexBits; // Root table index for signature (static resources only)
73 /* 7.3*/const Uint32 ImtblSamplerAssigned : _SamplerAssignedBits; // Immutable sampler flag for Texture SRVs and Samplers
74 /* 7.4*/const Uint32 RootParamType : _RootParamTypeBits; // Root parameter type (D3D12_ROOT_PARAMETER_TYPE)
75 /* 8 */const Uint32 SigOffsetFromTableStart; // Offset in the root table for signature (static only)
76 /* 12 */const Uint32 SRBOffsetFromTableStart; // Offset in the root table for SRB
77 /* 16 */
78  // clang-format on
79 
81  Uint32 _Space,
82  Uint32 _SamplerInd,
83  Uint32 _SRBRootIndex,
84  Uint32 _SRBOffsetFromTableStart,
85  Uint32 _SigRootIndex,
86  Uint32 _SigOffsetFromTableStart,
87  bool _ImtblSamplerAssigned,
88  D3D12_ROOT_PARAMETER_TYPE _RootParamType) noexcept :
89  // clang-format off
90  Register {_Register },
91  SRBRootIndex {_SRBRootIndex },
92  SamplerInd {_SamplerInd },
93  SigRootIndex {_SigRootIndex },
94  Space {_Space },
95  ImtblSamplerAssigned {_ImtblSamplerAssigned ? 1u : 0u },
96  RootParamType {static_cast<Uint32>(_RootParamType)},
97  SigOffsetFromTableStart{_SigOffsetFromTableStart },
98  SRBOffsetFromTableStart{_SRBOffsetFromTableStart }
99  // clang-format on
100  {
101  VERIFY(Register == _Register, "Shader register (", _Register, ") exceeds maximum representable value");
102  VERIFY(SRBRootIndex == _SRBRootIndex, "SRB Root index (", _SRBRootIndex, ") exceeds maximum representable value");
103  VERIFY(SigRootIndex == _SigRootIndex, "Signature Root index (", _SigRootIndex, ") exceeds maximum representable value");
104  VERIFY(SamplerInd == _SamplerInd, "Sampler index (", _SamplerInd, ") exceeds maximum representable value");
105  VERIFY(Space == _Space, "Space (", _Space, ") exceeds maximum representable value");
106  VERIFY(GetD3D12RootParamType() == _RootParamType, "Not enough bits to represent root parameter type");
107  }
108 
110  {
111  return ImtblSamplerAssigned != 0;
112  }
114  {
115  return SamplerInd != InvalidSamplerInd;
116  }
117 
119  {
121  }
123  {
125  }
126 
127  D3D12_ROOT_PARAMETER_TYPE GetD3D12RootParamType() const { return static_cast<D3D12_ROOT_PARAMETER_TYPE>(RootParamType); }
128 
129  bool IsRootView() const
130  {
131  return (GetD3D12RootParamType() == D3D12_ROOT_PARAMETER_TYPE_CBV ||
132  GetD3D12RootParamType() == D3D12_ROOT_PARAMETER_TYPE_SRV ||
133  GetD3D12RootParamType() == D3D12_ROOT_PARAMETER_TYPE_UAV);
134  }
135 
137  {
138  // Ignore sampler index, signature root index & offset.
139  // clang-format off
140  return Register == rhs.Register &&
141  Space == rhs.Space &&
142  SRBRootIndex == rhs.SRBRootIndex &&
146  // clang-format on
147  }
148 
149  size_t GetHash() const
150  {
152  }
153 };
154 
155 } // 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::PipelineResourceAttribsD3D12::PipelineResourceAttribsD3D12
PipelineResourceAttribsD3D12(Uint32 _Register, Uint32 _Space, Uint32 _SamplerInd, Uint32 _SRBRootIndex, Uint32 _SRBOffsetFromTableStart, Uint32 _SigRootIndex, Uint32 _SigOffsetFromTableStart, bool _ImtblSamplerAssigned, D3D12_ROOT_PARAMETER_TYPE _RootParamType) noexcept
Definition: PipelineResourceAttribsD3D12.hpp:80
Diligent::PipelineResourceAttribsD3D12::InvalidSRBRootIndex
static constexpr Uint32 InvalidSRBRootIndex
Definition: PipelineResourceAttribsD3D12.hpp:62
Diligent::PipelineResourceAttribsD3D12::SRBRootIndex
const Uint32 SRBRootIndex
Definition: PipelineResourceAttribsD3D12.hpp:69
Diligent::PipelineResourceAttribsD3D12::SamplerInd
const Uint32 SamplerInd
Definition: PipelineResourceAttribsD3D12.hpp:70
Diligent::PipelineResourceAttribsD3D12::IsRootView
bool IsRootView() const
Definition: PipelineResourceAttribsD3D12.hpp:129
Diligent::PipelineResourceAttribsD3D12::IsImmutableSamplerAssigned
bool IsImmutableSamplerAssigned() const
Definition: PipelineResourceAttribsD3D12.hpp:109
Diligent::PipelineResourceAttribsD3D12
Definition: PipelineResourceAttribsD3D12.hpp:43
PrivateConstants.h
DebugUtilities.hpp
Diligent::PipelineResourceAttribsD3D12::InvalidSigRootIndex
static constexpr Uint32 InvalidSigRootIndex
Definition: PipelineResourceAttribsD3D12.hpp:63
Diligent::PipelineResourceAttribsD3D12::InvalidOffset
static constexpr Uint32 InvalidOffset
Definition: PipelineResourceAttribsD3D12.hpp:65
Diligent::PipelineResourceAttribsD3D12::IsCompatibleWith
bool IsCompatibleWith(const PipelineResourceAttribsD3D12 &rhs) const
Definition: PipelineResourceAttribsD3D12.hpp:136
Diligent::PipelineResourceAttribsD3D12::SigRootIndex
const Uint32 SigRootIndex
Definition: PipelineResourceAttribsD3D12.hpp:72
Diligent::PipelineResourceAttribsD3D12::Space
const Uint32 Space
Definition: PipelineResourceAttribsD3D12.hpp:71
Diligent::PipelineResourceAttribsD3D12::GetD3D12RootParamType
D3D12_ROOT_PARAMETER_TYPE GetD3D12RootParamType() const
Definition: PipelineResourceAttribsD3D12.hpp:127
Diligent::PipelineResourceAttribsD3D12::InvalidRegister
static constexpr Uint32 InvalidRegister
Definition: PipelineResourceAttribsD3D12.hpp:64
Diligent::PipelineResourceAttribsD3D12::RootIndex
Uint32 RootIndex(ResourceCacheContentType Type) const
Definition: PipelineResourceAttribsD3D12.hpp:118
BasicTypes.h
Diligent::PipelineResourceAttribsD3D12::RootParamType
const Uint32 RootParamType
Definition: PipelineResourceAttribsD3D12.hpp:74
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::PipelineResourceAttribsD3D12::IsCombinedWithSampler
bool IsCombinedWithSampler() const
Definition: PipelineResourceAttribsD3D12.hpp:113
Diligent::PipelineResourceAttribsD3D12::OffsetFromTableStart
Uint32 OffsetFromTableStart(ResourceCacheContentType Type) const
Definition: PipelineResourceAttribsD3D12.hpp:122
Diligent::ResourceCacheContentType::SRB
@ SRB
Resources of a shader resource binding.
Diligent::PipelineResourceAttribsD3D12::Register
const Uint32 Register
Definition: PipelineResourceAttribsD3D12.hpp:68
HashUtils.hpp
Diligent::PipelineResourceAttribsD3D12::InvalidSamplerInd
static constexpr Uint32 InvalidSamplerInd
Definition: PipelineResourceAttribsD3D12.hpp:61
VERIFY
#define VERIFY(...)
Definition: DebugUtilities.hpp:76
Diligent::PipelineResourceAttribsD3D12::SigOffsetFromTableStart
const Uint32 SigOffsetFromTableStart
Definition: PipelineResourceAttribsD3D12.hpp:75
Diligent::PipelineResourceAttribsD3D12::GetHash
size_t GetHash() const
Definition: PipelineResourceAttribsD3D12.hpp:149
Diligent::PipelineResourceAttribsD3D12::SRBOffsetFromTableStart
const Uint32 SRBOffsetFromTableStart
Definition: PipelineResourceAttribsD3D12.hpp:76
Diligent
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37
Diligent::PipelineResourceAttribsD3D12::ImtblSamplerAssigned
const Uint32 ImtblSamplerAssigned
Definition: PipelineResourceAttribsD3D12.hpp:73