@@ -91,11 +91,11 @@ struct D3DShaderResourceAttribs
9191 // 4 4 24
9292 // bit | 0 1 2 3 | 4 5 6 7 | 8 9 10 ... 31 |
9393 // | | | |
94- // | InputType | SRV Dim | SamplerOrTexSRVIdBits |
95- static constexpr const Uint32 ShaderInputTypeBits = 4 ;
96- static constexpr const Uint32 SRVDimBits = 4 ;
97- static constexpr const Uint32 SamplerOrTexSRVIdBits = 24 ;
98- static_assert (ShaderInputTypeBits + SRVDimBits + SamplerOrTexSRVIdBits == 32 , " Attributes are better be packed into 32 bits" );
94+ // | InputType | SRV Dim | ExtraDataBits |
95+ static constexpr const Uint32 ShaderInputTypeBits = 4 ;
96+ static constexpr const Uint32 SRVDimBits = 4 ;
97+ static constexpr const Uint32 ExtraDataBits = 24 ;
98+ static_assert (ShaderInputTypeBits + SRVDimBits + ExtraDataBits == 32 , " Attributes are better be packed into 32 bits" );
9999
100100 static_assert (D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER < (1 << ShaderInputTypeBits), " Not enough bits to represent D3D_SHADER_INPUT_TYPE" );
101101 static_assert (D3D_SRV_DIMENSION_BUFFEREX < (1 << SRVDimBits), " Not enough bits to represent D3D_SRV_DIMENSION" );
@@ -105,17 +105,17 @@ struct D3DShaderResourceAttribs
105105 // There originally was a problem when the type of InputType was D3D_SHADER_INPUT_TYPE:
106106 // the value of D3D_SIT_UAV_RWBYTEADDRESS (8) was interpreted as -8 (as the underlying enum type
107107 // is signed) causing errors
108- /* 20.0*/ const Uint32 InputType : ShaderInputTypeBits; // Max value: D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER == 11
109- /* 20.4*/ const Uint32 SRVDimension : SRVDimBits; // Max value: D3D_SRV_DIMENSION_BUFFEREX == 11
110- /* 21.0*/ Uint32 SamplerOrTexSRVId : SamplerOrTexSRVIdBits; // Max value: 2^24-1
108+ /* 20.0*/ const Uint32 InputType : ShaderInputTypeBits; // Max value: D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER == 11
109+ /* 20.4*/ const Uint32 SRVDimension : SRVDimBits; // Max value: D3D_SRV_DIMENSION_BUFFEREX == 11
110+ /* 21.0*/ Uint32 ExtraData : ExtraDataBits; // Max value: 2^24-1
111111/* 24 */ // End of structure
112112
113113 // clang-format on
114114
115115public:
116- static constexpr const Uint32 InvalidSamplerId = (1U << SamplerOrTexSRVIdBits ) - 1U ;
116+ static constexpr const Uint32 InvalidSamplerId = (1U << ExtraDataBits ) - 1U ;
117117 static constexpr const Uint32 MaxSamplerId = InvalidSamplerId - 1 ;
118- static constexpr const Uint32 InvalidTexSRVId = (1U << SamplerOrTexSRVIdBits ) - 1U ;
118+ static constexpr const Uint32 InvalidTexSRVId = (1U << ExtraDataBits ) - 1U ;
119119 static constexpr const auto InvalidBindPoint = std::numeric_limits<decltype (BindPoint)>::max();
120120
121121
@@ -127,20 +127,20 @@ struct D3DShaderResourceAttribs
127127 D3D_SRV_DIMENSION _SRVDimension,
128128 Uint32 _SamplerId) noexcept :
129129 // clang-format off
130- Name {_Name},
131- BindPoint {_BindPoint},
132- BindCount {_BindCount},
133- Space {_Space},
134- InputType {static_cast <decltype (InputType)> (_InputType) },
135- SRVDimension {static_cast <decltype (SRVDimension)>(_SRVDimension)},
136- SamplerOrTexSRVId {_SamplerId}
130+ Name {_Name},
131+ BindPoint {_BindPoint},
132+ BindCount {_BindCount},
133+ Space {_Space},
134+ InputType {static_cast <decltype (InputType)> (_InputType) },
135+ SRVDimension{static_cast <decltype (SRVDimension)>(_SRVDimension)},
136+ ExtraData {_SamplerId}
137137 // clang-format on
138138 {
139139#ifdef DILIGENT_DEBUG
140140 // clang-format off
141- VERIFY (_InputType < (1 << ShaderInputTypeBits), " Shader input type is out of expected range" );
142- VERIFY (_SRVDimension < (1 << SRVDimBits), " SRV dimensions is out of expected range" );
143- VERIFY (_SamplerId < (1 << SamplerOrTexSRVIdBits ), " SamplerOrTexSRVId is out of representable range" );
141+ VERIFY (_InputType < (1 << ShaderInputTypeBits), " Shader input type is out of expected range" );
142+ VERIFY (_SRVDimension < (1 << SRVDimBits), " SRV dimensions is out of expected range" );
143+ VERIFY (_SamplerId < (1 << ExtraDataBits ), " SamplerId is out of representable range" );
144144 // clang-format on
145145
146146 if (_InputType == D3D_SIT_TEXTURE && _SRVDimension != D3D_SRV_DIMENSION_BUFFER)
@@ -178,7 +178,7 @@ struct D3DShaderResourceAttribs
178178 rhs.Space ,
179179 rhs.GetInputType (),
180180 rhs.GetSRVDimension (),
181- rhs.SamplerOrTexSRVId
181+ rhs.ExtraData
182182 }
183183 // clang-format on
184184 {
@@ -210,7 +210,7 @@ struct D3DShaderResourceAttribs
210210
211211 bool IsCombinedWithSampler () const
212212 {
213- return GetInputType () == D3D_SIT_TEXTURE && SamplerOrTexSRVId != InvalidSamplerId;
213+ return GetInputType () == D3D_SIT_TEXTURE && ExtraData != InvalidSamplerId;
214214 }
215215
216216 bool IsCombinedWithTexSRV () const
@@ -230,12 +230,12 @@ struct D3DShaderResourceAttribs
230230 Space == Attribs.Space &&
231231 InputType == Attribs.InputType &&
232232 SRVDimension == Attribs.SRVDimension &&
233- SamplerOrTexSRVId == Attribs.SamplerOrTexSRVId ;
233+ ExtraData == Attribs.ExtraData ;
234234 }
235235
236236 size_t GetHash () const
237237 {
238- return ComputeHash (BindPoint, BindCount, Space, InputType, SRVDimension, SamplerOrTexSRVId );
238+ return ComputeHash (BindPoint, BindCount, Space, InputType, SRVDimension, ExtraData );
239239 }
240240
241241 HLSLShaderResourceDesc GetHLSLResourceDesc () const
@@ -253,7 +253,13 @@ struct D3DShaderResourceAttribs
253253 Uint32 GetCombinedSamplerId () const
254254 {
255255 VERIFY (GetInputType () == D3D_SIT_TEXTURE && GetSRVDimension () != D3D_SRV_DIMENSION_BUFFER, " Invalid input type: D3D_SIT_TEXTURE is expected" );
256- return SamplerOrTexSRVId;
256+ return ExtraData;
257+ }
258+
259+ Uint32 GetConstantBufferSize () const
260+ {
261+ VERIFY (GetInputType () == D3D_SIT_CBUFFER, " Invalid input type: D3D_SIT_CBUFFER is expected" );
262+ return ExtraData;
257263 }
258264
259265 SHADER_RESOURCE_TYPE GetShaderResourceType () const ;
@@ -265,14 +271,20 @@ struct D3DShaderResourceAttribs
265271 void SetTexSRVId (Uint32 TexSRVId)
266272 {
267273 VERIFY (GetInputType () == D3D_SIT_SAMPLER, " Invalid input type: D3D_SIT_SAMPLER is expected" );
268- VERIFY (TexSRVId < (1 << SamplerOrTexSRVIdBits ), " TexSRVId (" , TexSRVId, " ) is out of representable range" );
269- SamplerOrTexSRVId = TexSRVId;
274+ VERIFY (TexSRVId < (1 << ExtraDataBits ), " TexSRVId (" , TexSRVId, " ) is out of representable range" );
275+ ExtraData = TexSRVId;
270276 }
271277
272278 Uint32 GetCombinedTexSRVId () const
273279 {
274280 VERIFY (GetInputType () == D3D_SIT_SAMPLER, " Invalid input type: D3D_SIT_SAMPLER is expected" );
275- return SamplerOrTexSRVId;
281+ return ExtraData;
282+ }
283+
284+ void SetConstantBufferSize (Uint32 Size)
285+ {
286+ VERIFY (GetInputType () == D3D_SIT_CBUFFER, " Invalid input type: D3D_SIT_CBUFFER is expected" );
287+ ExtraData = Size;
276288 }
277289};
278290static_assert (sizeof (D3DShaderResourceAttribs) == sizeof (void *) + sizeof (Uint32) * 4 , " Unexpected sizeof(D3DShaderResourceAttribs)" );
@@ -543,6 +555,7 @@ void ShaderResources::Initialize(TShaderReflection* pShaderReflection,
543555 {
544556 VERIFY_EXPR (CBAttribs.GetInputType () == D3D_SIT_CBUFFER);
545557 D3DShaderResourceAttribs* pNewCB = new (&GetCB (CurrCB++)) D3DShaderResourceAttribs{ResourceNamesPool, CBAttribs};
558+ pNewCB->SetConstantBufferSize (CBReflection.Size );
546559 NewResHandler.OnNewCB (*pNewCB);
547560 if (LoadConstantBufferReflection)
548561 CBReflections.emplace_back (std::move (CBReflection));
0 commit comments