@@ -443,27 +443,47 @@ void PipelineResourceSignatureD3D12Impl::CopyStaticResources(ShaderResourceCache
443443
444444 Uint32 SrcCacheOffset = Attr.OffsetFromTableStart (SrcCacheType);
445445 Uint32 DstCacheOffset = Attr.OffsetFromTableStart (DstCacheType);
446- for (Uint32 ArrInd = 0 ; ArrInd < ResDesc.ArraySize ; ++ArrInd, ++SrcCacheOffset, ++DstCacheOffset )
446+ if ( ResDesc.Flags & PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS )
447447 {
448- const ShaderResourceCacheD3D12::Resource& SrcRes = SrcRootTable.GetResource (SrcCacheOffset);
449- if (!SrcRes.pObject )
450- {
451- if (DstCacheType == ResourceCacheContentType::SRB)
452- LOG_ERROR_MESSAGE (" No resource is assigned to static shader variable '" , GetShaderResourcePrintName (ResDesc, ArrInd), " ' in pipeline resource signature '" , m_Desc.Name , " '." );
453- continue ;
454- }
448+ VERIFY (ResDesc.ResourceType == SHADER_RESOURCE_TYPE_CONSTANT_BUFFER, " Only constant buffers can be marked as INLINE_CONSTANTS." );
455449
450+ const ShaderResourceCacheD3D12::Resource& SrcRes = SrcRootTable.GetResource (SrcCacheOffset);
456451 const ShaderResourceCacheD3D12::Resource& DstRes = DstRootTable.GetResource (DstCacheOffset);
457- if (DstRes.pObject != SrcRes.pObject )
458- {
459- DEV_CHECK_ERR (DstRes.pObject == nullptr , " Static resource has already been initialized, and the new resource does not match previously assigned resource." );
460- DstResourceCache.CopyResource (d3d12Device, DstRootIndex, DstCacheOffset, SrcRes);
461- }
462- else
452+ VERIFY (SrcRes.CPUDescriptorHandle .ptr != 0 , " Inline constant resource must have valid CPU descriptor handle." );
453+ VERIFY (DstRes.CPUDescriptorHandle .ptr != 0 , " Inline constant resource must have valid CPU descriptor handle." );
454+
455+ // For inline constants, array size is the number of 4-byte constant values
456+ const Uint32 NumConstantValues = ResDesc.ArraySize ;
457+ // Copy the actual constant values.
458+ // For inline constants, CPUDescriptorHandle.ptr stores the pointer to the constant values buffer.
459+ memcpy (reinterpret_cast <void *>(DstRes.CPUDescriptorHandle .ptr ),
460+ reinterpret_cast <const void *>(SrcRes.CPUDescriptorHandle .ptr ),
461+ NumConstantValues * sizeof (Uint32));
462+ }
463+ else
464+ {
465+ for (Uint32 ArrInd = 0 ; ArrInd < ResDesc.ArraySize ; ++ArrInd, ++SrcCacheOffset, ++DstCacheOffset)
463466 {
464- VERIFY_EXPR (DstRes.pObject == SrcRes.pObject );
465- VERIFY_EXPR (DstRes.Type == SrcRes.Type );
466- VERIFY_EXPR (DstRes.CPUDescriptorHandle .ptr == SrcRes.CPUDescriptorHandle .ptr );
467+ const ShaderResourceCacheD3D12::Resource& SrcRes = SrcRootTable.GetResource (SrcCacheOffset);
468+ if (!SrcRes.pObject )
469+ {
470+ if (DstCacheType == ResourceCacheContentType::SRB)
471+ LOG_ERROR_MESSAGE (" No resource is assigned to static shader variable '" , GetShaderResourcePrintName (ResDesc, ArrInd), " ' in pipeline resource signature '" , m_Desc.Name , " '." );
472+ continue ;
473+ }
474+
475+ const ShaderResourceCacheD3D12::Resource& DstRes = DstRootTable.GetResource (DstCacheOffset);
476+ if (DstRes.pObject != SrcRes.pObject )
477+ {
478+ DEV_CHECK_ERR (DstRes.pObject == nullptr , " Static resource has already been initialized, and the new resource does not match previously assigned resource." );
479+ DstResourceCache.CopyResource (d3d12Device, DstRootIndex, DstCacheOffset, SrcRes);
480+ }
481+ else
482+ {
483+ VERIFY_EXPR (DstRes.pObject == SrcRes.pObject );
484+ VERIFY_EXPR (DstRes.Type == SrcRes.Type );
485+ VERIFY_EXPR (DstRes.CPUDescriptorHandle .ptr == SrcRes.CPUDescriptorHandle .ptr );
486+ }
467487 }
468488 }
469489 }
0 commit comments