Skip to content

Commit c5ffe02

Browse files
Pipeline state and resource signature: added CopyStaticResources method (API252008)
1 parent 0df2df2 commit c5ffe02

23 files changed

+420
-44
lines changed

Graphics/Archiver/include/SerializedPipelineStateImpl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class SerializedPipelineStateImpl final : public ObjectBase<ISerializedPipelineS
8282

8383
UNSUPPORTED_METHOD (void, CreateShaderResourceBinding, IShaderResourceBinding** ppShaderResourceBinding, bool InitStaticResources)
8484
UNSUPPORTED_CONST_METHOD(void, InitializeStaticSRBResources, IShaderResourceBinding* pShaderResourceBinding)
85+
UNSUPPORTED_CONST_METHOD(void, CopyStaticResources, IPipelineState* pPSO)
8586
UNSUPPORTED_CONST_METHOD(bool, IsCompatibleWith, const IPipelineState* pPSO)
8687

8788
UNSUPPORTED_CONST_METHOD(Uint32, GetResourceSignatureCount)

Graphics/Archiver/include/SerializedResourceSignatureImpl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class SerializedResourceSignatureImpl final : public ObjectBase<IPipelineResourc
7474
UNSUPPORTED_METHOD (IShaderResourceVariable*, GetStaticVariableByIndex, SHADER_TYPE ShaderType, Uint32 Index)
7575
UNSUPPORTED_CONST_METHOD(Uint32, GetStaticVariableCount, SHADER_TYPE ShaderType)
7676
UNSUPPORTED_CONST_METHOD(void, InitializeStaticSRBResources, IShaderResourceBinding* pShaderResourceBinding)
77+
UNSUPPORTED_CONST_METHOD(void, CopyStaticResources, IPipelineResourceSignature* pPRS)
7778
UNSUPPORTED_CONST_METHOD(bool, IsCompatibleWith, const IPipelineResourceSignature* pPRS)
7879
UNSUPPORTED_CONST_METHOD(Int32, GetUniqueID)
7980
UNSUPPORTED_METHOD (void, SetUserData, IObject* pUserData)

Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,33 @@ class PipelineResourceSignatureBase : public DeviceObjectBase<typename EngineImp
523523
pSRBImpl->SetStaticResourcesInitialized();
524524
}
525525

526+
/// Implementation of IPipelineResourceSignature::CopyStaticResources.
527+
virtual void DILIGENT_CALL_TYPE CopyStaticResources(IPipelineResourceSignature* pDstSignature) const override final
528+
{
529+
if (pDstSignature == nullptr)
530+
{
531+
DEV_ERROR("Destination signature must not be null");
532+
return;
533+
}
534+
535+
if (pDstSignature == this)
536+
{
537+
DEV_ERROR("Source and destination signatures must be different");
538+
return;
539+
}
540+
541+
const auto* const pThisImpl = static_cast<const PipelineResourceSignatureImplType*>(this);
542+
auto* const pDstSignImpl = static_cast<const PipelineResourceSignatureImplType*>(pDstSignature);
543+
if (!pDstSignImpl->IsCompatibleWith(pThisImpl))
544+
{
545+
LOG_ERROR_MESSAGE("Can't copy static resources: destination pipeline resource signature '", pDstSignImpl->m_Desc.Name,
546+
"' is not compatible with the source signature '", pThisImpl->m_Desc.Name, "'.");
547+
return;
548+
}
549+
550+
pThisImpl->CopyStaticResources(*pDstSignImpl->m_pStaticResCache);
551+
}
552+
526553
/// Implementation of IPipelineResourceSignature::IsCompatibleWith.
527554
virtual bool DILIGENT_CALL_TYPE IsCompatibleWith(const IPipelineResourceSignature* pPRS) const override final
528555
{

Graphics/GraphicsEngine/include/PipelineStateBase.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,31 @@ class PipelineStateBase : public DeviceObjectBase<typename EngineImplTraits::Pip
460460
return this->GetResourceSignature(0)->InitializeStaticSRBResources(pSRB);
461461
}
462462

463+
virtual void DILIGENT_CALL_TYPE CopyStaticResources(IPipelineState* pDstPipeline) const override final
464+
{
465+
if (pDstPipeline == nullptr)
466+
{
467+
DEV_ERROR("Destination pipeline must not be null");
468+
return;
469+
}
470+
471+
if (pDstPipeline == this)
472+
{
473+
DEV_ERROR("Source and destination pipelines must be different");
474+
return;
475+
}
476+
477+
if (!m_UsingImplicitSignature)
478+
{
479+
LOG_ERROR_MESSAGE("IPipelineState::CopyStaticResources is not allowed for pipelines that use explicit "
480+
"resource signatures. Use IPipelineResourceSignature::CopyStaticResources instead.");
481+
return;
482+
}
483+
484+
auto* pDstSign = static_cast<PipelineStateImplType*>(pDstPipeline)->GetResourceSignature(0);
485+
return this->GetResourceSignature(0)->CopyStaticResources(pDstSign);
486+
}
487+
463488
/// Implementation of IPipelineState::GetResourceSignatureCount().
464489
virtual Uint32 DILIGENT_CALL_TYPE GetResourceSignatureCount() const override final
465490
{

Graphics/GraphicsEngine/interface/APIInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
/// \file
3131
/// Diligent API information
3232

33-
#define DILIGENT_API_VERSION 252007
33+
#define DILIGENT_API_VERSION 252008
3434

3535
#include "../../../Primitives/interface/BasicTypes.h"
3636

Graphics/GraphicsEngine/interface/PipelineResourceSignature.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,14 @@ DILIGENT_BEGIN_INTERFACE(IPipelineResourceSignature, IDeviceObject)
408408
VIRTUAL void METHOD(InitializeStaticSRBResources)(THIS_
409409
struct IShaderResourceBinding* pShaderResourceBinding) CONST PURE;
410410

411+
/// Copies static resource bindings to the destination signature.
412+
413+
/// \param [in] pDstSignature - Destination pipeline resource signature.
414+
///
415+
/// \note Destination signature must be compatible with this signature.
416+
VIRTUAL void METHOD(CopyStaticResources)(THIS_
417+
IPipelineResourceSignature* pDstSignature) CONST PURE;
418+
411419
/// Returns true if the signature is compatible with another one.
412420

413421
/// \remarks Two signatures are compatible if they contain identical resources and immutabke samplers,
@@ -431,6 +439,7 @@ DILIGENT_END_INTERFACE
431439
# define IPipelineResourceSignature_GetStaticVariableByIndex(This, ...) CALL_IFACE_METHOD(PipelineResourceSignature, GetStaticVariableByIndex, This, __VA_ARGS__)
432440
# define IPipelineResourceSignature_GetStaticVariableCount(This, ...) CALL_IFACE_METHOD(PipelineResourceSignature, GetStaticVariableCount, This, __VA_ARGS__)
433441
# define IPipelineResourceSignature_InitializeStaticSRBResources(This, ...) CALL_IFACE_METHOD(PipelineResourceSignature, InitializeStaticSRBResources,This, __VA_ARGS__)
442+
# define IPipelineResourceSignature_CopyStaticResources(This, ...) CALL_IFACE_METHOD(PipelineResourceSignature, CopyStaticResources, This, __VA_ARGS__)
434443
# define IPipelineResourceSignature_IsCompatibleWith(This, ...) CALL_IFACE_METHOD(PipelineResourceSignature, IsCompatibleWith, This, __VA_ARGS__)
435444

436445
// clang-format on

Graphics/GraphicsEngine/interface/PipelineState.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,20 @@ DILIGENT_BEGIN_INTERFACE(IPipelineState, IDeviceObject)
10941094
struct IShaderResourceBinding* pShaderResourceBinding) CONST PURE;
10951095

10961096

1097+
/// Copies static resource bindings to the destination pipeline.
1098+
1099+
/// \param [in] pDstPipeline - Destination pipeline state.
1100+
///
1101+
/// \note Destination pipeline state must be compatible with this pipeline.
1102+
///
1103+
/// \remarks This method is only allowed for pipelines that use implicit resource signature
1104+
/// (e.g. shader resources are defined through ResourceLayout member of the pipeline desc).
1105+
/// For pipelines that use explicit resource signatures, use
1106+
/// IPipelineResourceSignature::CopyStaticResources() method.
1107+
VIRTUAL void METHOD(CopyStaticResources)(THIS_
1108+
IPipelineState* pDstPipeline) CONST PURE;
1109+
1110+
10971111
/// Checks if this pipeline state object is compatible with another PSO
10981112

10991113
/// If two pipeline state objects are compatible, they can use shader resource binding
@@ -1155,6 +1169,7 @@ DILIGENT_END_INTERFACE
11551169
# define IPipelineState_GetStaticVariableByIndex(This, ...) CALL_IFACE_METHOD(PipelineState, GetStaticVariableByIndex, This, __VA_ARGS__)
11561170
# define IPipelineState_CreateShaderResourceBinding(This, ...) CALL_IFACE_METHOD(PipelineState, CreateShaderResourceBinding, This, __VA_ARGS__)
11571171
# define IPipelineState_InitializeStaticSRBResources(This, ...) CALL_IFACE_METHOD(PipelineState, InitializeStaticSRBResources, This, __VA_ARGS__)
1172+
# define IPipelineState_CopyStaticResources(This, ...) CALL_IFACE_METHOD(PipelineState, CopyStaticResources, This, __VA_ARGS__)
11581173
# define IPipelineState_IsCompatibleWith(This, ...) CALL_IFACE_METHOD(PipelineState, IsCompatibleWith, This, __VA_ARGS__)
11591174
# define IPipelineState_GetResourceSignatureCount(This) CALL_IFACE_METHOD(PipelineState, GetResourceSignatureCount, This)
11601175
# define IPipelineState_GetResourceSignature(This, ...) CALL_IFACE_METHOD(PipelineState, GetResourceSignature, This, __VA_ARGS__)

Graphics/GraphicsEngineD3D11/include/PipelineResourceSignatureD3D11Impl.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ class PipelineResourceSignatureD3D11Impl final : public PipelineResourceSignatur
126126

127127
// Copies static resources from the static resource cache to the destination cache
128128
void CopyStaticResources(ShaderResourceCacheD3D11& ResourceCache) const;
129+
// Make the base class method visible
130+
using TPipelineResourceSignatureBase::CopyStaticResources;
129131

130132
PipelineResourceSignatureInternalDataD3D11 GetInternalData() const;
131133

Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.hpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -767,13 +767,17 @@ bool ShaderResourceCacheD3D11::CopyResource(const ShaderResourceCacheD3D11& SrcC
767767
const Uint32 Binding = BindPoints[ShaderInd];
768768
VERIFY(Binding < GetResourceCount<ResRange>(ShaderInd), "Index is out of range");
769769
VERIFY(Binding < SrcCache.GetResourceCount<ResRange>(ShaderInd), "Index is out of range");
770-
if (!SrcResArrays.first[Binding])
771-
IsBound = false;
772-
773-
DstResArrays.first[Binding] = SrcResArrays.first[Binding];
774-
DstResArrays.second[Binding] = SrcResArrays.second[Binding];
770+
if (SrcResArrays.first[Binding])
771+
{
772+
DstResArrays.first[Binding] = SrcResArrays.first[Binding];
773+
DstResArrays.second[Binding] = SrcResArrays.second[Binding];
775774

776-
UpdateDynamicCBOffsetFlag<ResRange>(DstResArrays.first[Binding], ShaderInd, Binding);
775+
UpdateDynamicCBOffsetFlag<ResRange>(DstResArrays.first[Binding], ShaderInd, Binding);
776+
}
777+
else if (!DstResArrays.first[Binding])
778+
{
779+
IsBound = false;
780+
}
777781
}
778782

779783
this->UpdateRevision();

Graphics/GraphicsEngineD3D11/src/PipelineResourceSignatureD3D11Impl.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,11 @@ void PipelineResourceSignatureD3D11Impl::CopyStaticResources(ShaderResourceCache
292292
return;
293293

294294
// SrcResourceCache contains only static resources.
295-
// DstResourceCache contains static, mutable and dynamic resources.
295+
// In case of SRB, DstResourceCache contains static, mutable and dynamic resources.
296+
// In case of Signature, DstResourceCache contains only static resources.
296297
const auto& SrcResourceCache = *m_pStaticResCache;
297298
VERIFY_EXPR(SrcResourceCache.GetContentType() == ResourceCacheContentType::Signature);
298-
VERIFY_EXPR(DstResourceCache.GetContentType() == ResourceCacheContentType::SRB);
299+
const auto DstCacheType = DstResourceCache.GetContentType();
299300

300301
const auto ResIdxRange = GetResourceIndexRange(SHADER_RESOURCE_VARIABLE_TYPE_STATIC);
301302
for (Uint32 r = ResIdxRange.first; r < ResIdxRange.second; ++r)
@@ -311,14 +312,20 @@ void PipelineResourceSignatureD3D11Impl::CopyStaticResources(ShaderResourceCache
311312
for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
312313
{
313314
if (!DstResourceCache.CopyResource<D3D11_RESOURCE_RANGE_CBV>(SrcResourceCache, ResAttr.BindPoints + ArrInd))
314-
LOG_ERROR_MESSAGE("No resource is assigned to static shader variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in pipeline resource signature '", m_Desc.Name, "'.");
315+
{
316+
if (DstCacheType == ResourceCacheContentType::SRB)
317+
LOG_ERROR_MESSAGE("No resource is assigned to static shader variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in pipeline resource signature '", m_Desc.Name, "'.");
318+
}
315319
}
316320
break;
317321
case D3D11_RESOURCE_RANGE_SRV:
318322
for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
319323
{
320324
if (!DstResourceCache.CopyResource<D3D11_RESOURCE_RANGE_SRV>(SrcResourceCache, ResAttr.BindPoints + ArrInd))
321-
LOG_ERROR_MESSAGE("No resource is assigned to static shader variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in pipeline resource signature '", m_Desc.Name, "'.");
325+
{
326+
if (DstCacheType == ResourceCacheContentType::SRB)
327+
LOG_ERROR_MESSAGE("No resource is assigned to static shader variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in pipeline resource signature '", m_Desc.Name, "'.");
328+
}
322329
}
323330
break;
324331
case D3D11_RESOURCE_RANGE_SAMPLER:
@@ -327,11 +334,14 @@ void PipelineResourceSignatureD3D11Impl::CopyStaticResources(ShaderResourceCache
327334
for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
328335
{
329336
if (!DstResourceCache.CopyResource<D3D11_RESOURCE_RANGE_SAMPLER>(SrcResourceCache, ResAttr.BindPoints + ArrInd))
330-
LOG_ERROR_MESSAGE("No resource is assigned to static shader variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in pipeline resource signature '", m_Desc.Name, "'.");
337+
{
338+
if (DstCacheType == ResourceCacheContentType::SRB)
339+
LOG_ERROR_MESSAGE("No resource is assigned to static shader variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in pipeline resource signature '", m_Desc.Name, "'.");
340+
}
331341
}
332342
}
333343
#ifdef DILIGENT_DEBUG
334-
else
344+
else if (DstCacheType == ResourceCacheContentType::SRB)
335345
{
336346
for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
337347
{
@@ -345,7 +355,10 @@ void PipelineResourceSignatureD3D11Impl::CopyStaticResources(ShaderResourceCache
345355
for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
346356
{
347357
if (!DstResourceCache.CopyResource<D3D11_RESOURCE_RANGE_UAV>(SrcResourceCache, ResAttr.BindPoints + ArrInd))
348-
LOG_ERROR_MESSAGE("No resource is assigned to static shader variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in pipeline resource signature '", m_Desc.Name, "'.");
358+
{
359+
if (DstCacheType == ResourceCacheContentType::SRB)
360+
LOG_ERROR_MESSAGE("No resource is assigned to static shader variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in pipeline resource signature '", m_Desc.Name, "'.");
361+
}
349362
}
350363
break;
351364
default:

0 commit comments

Comments
 (0)