2022-09-26 15:12:13 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
2022-10-01 02:06:09 -04:00
|
|
|
#include "MuT/ASTOpInstanceAdd.h"
|
2022-10-02 10:56:02 -04:00
|
|
|
|
|
|
|
|
#include "Misc/AssertionMacros.h"
|
|
|
|
|
#include "MuR/ModelPrivate.h"
|
|
|
|
|
#include "MuR/ParametersPrivate.h"
|
|
|
|
|
#include "MuR/RefCounted.h"
|
|
|
|
|
#include "MuR/Types.h"
|
2022-10-01 02:04:57 -04:00
|
|
|
#include "MuT/CodeOptimiser.h"
|
2022-09-26 15:12:13 -04:00
|
|
|
|
|
|
|
|
|
2022-10-18 04:42:25 -04:00
|
|
|
namespace mu
|
2022-09-26 15:12:13 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
2022-10-18 04:42:25 -04:00
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
|
|
ASTOpInstanceAdd::ASTOpInstanceAdd()
|
|
|
|
|
: instance(this)
|
|
|
|
|
, value(this)
|
|
|
|
|
{
|
|
|
|
|
}
|
2022-09-26 15:12:13 -04:00
|
|
|
|
|
|
|
|
|
2022-10-18 04:42:25 -04:00
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
|
|
ASTOpInstanceAdd::~ASTOpInstanceAdd()
|
|
|
|
|
{
|
|
|
|
|
// Explicit call needed to avoid recursive destruction
|
|
|
|
|
ASTOp::RemoveChildren();
|
|
|
|
|
}
|
2022-09-26 15:12:13 -04:00
|
|
|
|
|
|
|
|
|
2022-10-18 04:42:25 -04:00
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
|
|
bool ASTOpInstanceAdd::IsEqual(const ASTOp& otherUntyped) const
|
|
|
|
|
{
|
2024-01-18 03:27:38 -05:00
|
|
|
if (otherUntyped.GetOpType()==GetOpType())
|
2022-10-18 04:42:25 -04:00
|
|
|
{
|
2024-01-18 03:27:38 -05:00
|
|
|
const ASTOpInstanceAdd* other = static_cast<const ASTOpInstanceAdd*>(&otherUntyped);
|
2022-10-18 04:42:25 -04:00
|
|
|
return type == other->type &&
|
|
|
|
|
instance == other->instance &&
|
|
|
|
|
value == other->value &&
|
|
|
|
|
id == other->id &&
|
2023-05-10 08:29:50 -04:00
|
|
|
ExternalId == other->ExternalId &&
|
|
|
|
|
SharedSurfaceId == other->SharedSurfaceId &&
|
2022-10-18 04:42:25 -04:00
|
|
|
name == other->name;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-09-26 15:12:13 -04:00
|
|
|
|
|
|
|
|
|
2022-10-18 04:42:25 -04:00
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
|
|
mu::Ptr<ASTOp> ASTOpInstanceAdd::Clone(MapChildFuncRef mapChild) const
|
|
|
|
|
{
|
|
|
|
|
Ptr<ASTOpInstanceAdd> n = new ASTOpInstanceAdd();
|
|
|
|
|
n->type = type;
|
|
|
|
|
n->instance = mapChild(instance.child());
|
|
|
|
|
n->value = mapChild(value.child());
|
|
|
|
|
n->id = id;
|
2023-05-10 08:29:50 -04:00
|
|
|
n->ExternalId = ExternalId;
|
|
|
|
|
n->SharedSurfaceId = SharedSurfaceId;
|
2022-10-18 04:42:25 -04:00
|
|
|
n->name = name;
|
|
|
|
|
return n;
|
|
|
|
|
}
|
2022-09-26 15:12:13 -04:00
|
|
|
|
|
|
|
|
|
2022-10-18 04:42:25 -04:00
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
|
|
uint64 ASTOpInstanceAdd::Hash() const
|
|
|
|
|
{
|
|
|
|
|
uint64 res = std::hash<size_t>()(size_t(type));
|
|
|
|
|
hash_combine(res, instance.child().get());
|
|
|
|
|
hash_combine(res, value.child().get());
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2022-09-26 15:12:13 -04:00
|
|
|
|
|
|
|
|
|
2022-10-18 04:42:25 -04:00
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
|
|
void ASTOpInstanceAdd::Assert()
|
|
|
|
|
{
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case OP_TYPE::IN_ADDMESH:
|
|
|
|
|
case OP_TYPE::IN_ADDIMAGE:
|
|
|
|
|
case OP_TYPE::IN_ADDVECTOR:
|
|
|
|
|
case OP_TYPE::IN_ADDSCALAR:
|
|
|
|
|
case OP_TYPE::IN_ADDSTRING:
|
|
|
|
|
case OP_TYPE::IN_ADDSURFACE:
|
|
|
|
|
case OP_TYPE::IN_ADDCOMPONENT:
|
|
|
|
|
case OP_TYPE::IN_ADDLOD:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
// Unexpected type
|
|
|
|
|
check(false);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ASTOp::Assert();
|
|
|
|
|
}
|
2022-09-26 15:12:13 -04:00
|
|
|
|
|
|
|
|
|
2022-10-18 04:42:25 -04:00
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
|
|
void ASTOpInstanceAdd::ForEachChild(const TFunctionRef<void(ASTChild&)> f)
|
|
|
|
|
{
|
|
|
|
|
f(instance);
|
|
|
|
|
f(value);
|
|
|
|
|
}
|
2022-09-26 15:12:13 -04:00
|
|
|
|
|
|
|
|
|
2022-10-18 04:42:25 -04:00
|
|
|
//-------------------------------------------------------------------------------------------------
|
2023-07-28 04:00:17 -04:00
|
|
|
void ASTOpInstanceAdd::Link(FProgram& program, FLinkerOptions*)
|
2022-10-18 04:42:25 -04:00
|
|
|
{
|
|
|
|
|
// Already linked?
|
|
|
|
|
if (!linkedAddress)
|
|
|
|
|
{
|
|
|
|
|
OP::InstanceAddArgs args;
|
2023-09-26 04:43:37 -04:00
|
|
|
FMemory::Memzero(&args, sizeof(args));
|
2022-10-18 04:42:25 -04:00
|
|
|
args.id = id;
|
2023-05-10 08:29:50 -04:00
|
|
|
args.ExternalId = ExternalId;
|
|
|
|
|
args.SharedSurfaceId = SharedSurfaceId;
|
2022-10-18 04:42:25 -04:00
|
|
|
args.name = program.AddConstant(name);
|
2022-09-26 15:12:13 -04:00
|
|
|
|
2022-10-18 04:42:25 -04:00
|
|
|
if (instance) args.instance = instance->linkedAddress;
|
|
|
|
|
if (value) args.value = value->linkedAddress;
|
2022-09-26 15:12:13 -04:00
|
|
|
|
2022-10-18 04:42:25 -04:00
|
|
|
if (type == OP_TYPE::IN_ADDIMAGE ||
|
|
|
|
|
type == OP_TYPE::IN_ADDMESH)
|
|
|
|
|
{
|
|
|
|
|
// Find out relevant parameters. \todo: this may be optimised by reusing partial
|
|
|
|
|
// values in a LINK_CONTEXT or similar
|
|
|
|
|
SubtreeRelevantParametersVisitorAST visitor;
|
|
|
|
|
visitor.Run(value.child());
|
2022-09-26 15:12:13 -04:00
|
|
|
|
2022-10-18 04:42:25 -04:00
|
|
|
TArray<uint16> params;
|
2023-09-26 04:43:37 -04:00
|
|
|
for (const FString& paramName : visitor.m_params)
|
2022-10-18 04:42:25 -04:00
|
|
|
{
|
|
|
|
|
for (int32 i = 0; i < program.m_parameters.Num(); ++i)
|
|
|
|
|
{
|
|
|
|
|
const auto& param = program.m_parameters[i];
|
|
|
|
|
if (param.m_name == paramName)
|
|
|
|
|
{
|
|
|
|
|
params.Add(uint16(i));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-26 15:12:13 -04:00
|
|
|
|
2022-10-18 04:42:25 -04:00
|
|
|
params.Sort();
|
2022-09-26 15:12:13 -04:00
|
|
|
|
2022-10-18 04:42:25 -04:00
|
|
|
auto it = program.m_parameterLists.Find(params);
|
|
|
|
|
|
|
|
|
|
if (it != INDEX_NONE)
|
|
|
|
|
{
|
|
|
|
|
args.relevantParametersListIndex = it;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
args.relevantParametersListIndex = uint32_t(program.m_parameterLists.Num());
|
|
|
|
|
program.m_parameterLists.Add(params);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
linkedAddress = (OP::ADDRESS)program.m_opAddress.Num();
|
|
|
|
|
program.m_opAddress.Add((uint32_t)program.m_byteCode.Num());
|
|
|
|
|
AppendCode(program.m_byteCode, type);
|
|
|
|
|
AppendCode(program.m_byteCode, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2022-09-26 15:12:13 -04:00
|
|
|
|
|
|
|
|
}
|