Skip to content

Commit 4df96e5

Browse files
jloypixar-oss
authored andcommitted
exec: prevent VtArray from being used as a computation result type
To help avoid confusion around Vdf's array flattening behavior, prevent plugin authors from defining computations that return VtArray values or registering VtArray types with execution. (Internal change: 2368583)
1 parent 0e532b8 commit 4df96e5

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

pxr/exec/exec/computationBuilders.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "pxr/base/tf/token.h"
2828
#include "pxr/base/tf/type.h"
29+
#include "pxr/base/vt/traits.h"
2930
#include "pxr/exec/vdf/context.h"
3031
#include "pxr/usd/sdf/path.h"
3132

@@ -844,6 +845,9 @@ Exec_PrimComputationBuilder&
844845
Exec_PrimComputationBuilder::Callback(
845846
ExecCallbackFn &&callback)
846847
{
848+
static_assert(!VtIsArray<ResultType>::value,
849+
"VtArray is not a supported result type");
850+
847851
_AddCallback(
848852
std::move(callback),
849853
ExecTypeRegistry::GetInstance().CheckForRegistration<ResultType>());
@@ -860,6 +864,9 @@ Exec_PrimComputationBuilder::Callback(
860864
{
861865
static_assert(!std::is_reference_v<ResultType>,
862866
"Callback functions must return by value");
867+
static_assert(!VtIsArray<ResultType>::value,
868+
"VtArray is not a supported result type");
869+
863870
_AddCallback(
864871
[callback](const VdfContext& ctx) { ctx.SetOutput(callback(ctx)); },
865872
ExecTypeRegistry::GetInstance().CheckForRegistration<ResultType>());

pxr/exec/exec/testenv/testExecTypeRegistration.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ TestBasicRegistration()
6262

6363
reg.RegisterType(TestExecTypeRegistrationValue{});
6464
reg.CheckForRegistration<TestExecTypeRegistrationValue>();
65-
66-
reg.RegisterType(VtArray<TestExecTypeRegistrationValue>{});
67-
reg.CheckForRegistration<VtArray<TestExecTypeRegistrationValue>>();
6865
}
6966

7067
static void
@@ -189,23 +186,6 @@ TestCreateVector()
189186
// define only what is necessary for VtValue & VdfVector.
190187
TF_AXIOM(accessor[0] == TestExecTypeRegistrationValue{});
191188
}
192-
193-
// VtArray<TestExecTypeRegistrationValue> is not known to Vt and is not an
194-
// Sdf value type.
195-
{
196-
static_assert(!VtIsKnownValueType<
197-
VtArray<TestExecTypeRegistrationValue>>());
198-
static_assert(!SdfValueTypeTraits<
199-
VtArray<TestExecTypeRegistrationValue>>::IsValueType);
200-
const VtArray<TestExecTypeRegistrationValue> arr = { {}, {} };
201-
const VdfVector vec = reg.CreateVector(VtValue(arr));
202-
TF_AXIOM(vec.Holds<TestExecTypeRegistrationValue>());
203-
const auto accessor = vec.GetReadAccessor<
204-
TestExecTypeRegistrationValue>();
205-
ASSERT_EQ(accessor.GetNumValues(), 2);
206-
TF_AXIOM(accessor[0] == arr[0]);
207-
TF_AXIOM(accessor[1] == arr[1]);
208-
}
209189
}
210190

211191
static void

pxr/exec/exec/typeRegistry.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ class ExecTypeRegistry
7575
///
7676
template <typename ValueType>
7777
static void RegisterType(const ValueType &fallback) {
78+
static_assert(!VtIsArray<ValueType>::value,
79+
"VtArray is not a supported execution value type");
7880
_GetInstanceForRegistration()._RegisterType(fallback);
7981
}
8082

0 commit comments

Comments
 (0)