Files
UnrealEngine/Engine/Plugins/PCG/Shaders/Private/PCGShaderUtilsInternal.ush
2025-05-18 13:04:45 +08:00

65 lines
2.7 KiB
HLSL

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
// Must match C++ constants in PCGComputeCommon.h
#ifndef PCG_NUM_RESERVED_ATTRS
#define PCG_NUM_RESERVED_ATTRS 32
#endif
#ifndef PCG_MAX_NUM_ATTRS
#define PCG_MAX_NUM_ATTRS 128
#endif
// TODO pass in attribute IDs to copy?
#define PCG_COPY_ATTRIBUTES_TO_OUTPUT(TargetPin, SourcePin, Target_DataIndex, Target_ElementIndex, Source_DataIndex, Source_ElementIndex, bMetadataOnly, bInitNonCopiedAttributes) \
{ \
const uint NumAttributes = TargetPin##_GetDataNumAttributesInternal(Target_DataIndex); \
uint NumAttributesProcessed = 0; \
\
const int FirstAttributeId = (bMetadataOnly) ? PCG_NUM_RESERVED_ATTRS : 0; \
\
for (int AttributeId = FirstAttributeId; AttributeId < PCG_MAX_NUM_ATTRS; ++AttributeId) \
{ \
const uint Target_Stride = TargetPin##_GetAttributeStrideInternal(Target_DataIndex, AttributeId); \
\
if (Target_Stride == 0) \
{ \
/* No output attribute to write to. */ \
continue; \
} \
\
const uint Source_Stride = SourcePin##_GetAttributeStrideInternal(Source_DataIndex, AttributeId); \
const uint Target_ElementAddress = TargetPin##_GetElementAddressInternal(Target_DataIndex, Target_ElementIndex, AttributeId); \
\
if (Source_Stride == Target_Stride) \
{ \
const uint Source_ElementAddress = SourcePin##_GetElementAddressInternal(Source_DataIndex, Source_ElementIndex, AttributeId); \
\
for (uint Offset = 0; Offset < Target_Stride; Offset += 4) \
{ \
TargetPin##_StoreBufferInternal(Target_ElementAddress + Offset, SourcePin##_LoadBufferInternal(Source_ElementAddress + Offset)); \
} \
} \
else if (bInitNonCopiedAttributes) \
{ \
for (uint Offset = 0; Offset < Target_Stride; Offset += 4) \
{ \
/* Initialize output data (only header part of buffer will be initialized). */ \
TargetPin##_StoreBufferInternal(Target_ElementAddress + Offset, 0u); \
} \
} \
\
if (++NumAttributesProcessed >= NumAttributes) \
{ \
/* We can early-out when we've looked at all the possible attributes. */ \
break; \
} \
} \
}
#define PCG_COPY_METADATA_ATTRIBUTES_TO_OUTPUT(TargetPin, SourcePin, Target_DataIndex, Target_ElementIndex, Source_DataIndex, Source_ElementIndex) \
PCG_COPY_ATTRIBUTES_TO_OUTPUT(TargetPin, SourcePin, Target_DataIndex, Target_ElementIndex, Source_DataIndex, Source_ElementIndex, /*bMetadataOnly=*/true, /*bInitNonCopiedAttributes=*/true)
#define PCG_COPY_ALL_ATTRIBUTES_TO_OUTPUT(TargetPin, SourcePin, Target_DataIndex, Target_ElementIndex, Source_DataIndex, Source_ElementIndex) \
PCG_COPY_ATTRIBUTES_TO_OUTPUT(TargetPin, SourcePin, Target_DataIndex, Target_ElementIndex, Source_DataIndex, Source_ElementIndex, /*bMetadataOnly=*/false, /*bInitNonCopiedAttributes=*/true)