Skip to content

Commit

Permalink
[hdsi] Avoid unnecessary data access in HdsiPinnedCurveExpandingScene…
Browse files Browse the repository at this point in the history
…Index

Ensure HdsiPinnedCurveExpandingSceneIndex does not pull
on the basisCurves schema when asked for unrelated
keys.

(Internal change: 2328958)
  • Loading branch information
blevin authored and pixar-oss committed May 29, 2024
1 parent 637f8ab commit 3ecaaed
Showing 1 changed file with 56 additions and 54 deletions.
110 changes: 56 additions & 54 deletions pxr/imaging/hdsi/pinnedCurveExpandingSceneIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,63 +754,65 @@ class _PrimDataSource : public HdContainerDataSource
Get(const TfToken &name) override
{
HdDataSourceBaseHandle result = _input->Get(name);
if (result) {
HdBasisCurvesSchema bcs =
HdBasisCurvesSchema::GetFromParent(_input);

if (!bcs) {
return result;
}

HdBasisCurvesTopologySchema ts = bcs.GetTopology();
if (!ts) {
return result;
}
if (!result) {
return HdDataSourceBaseHandle();
}
if (name != HdBasisCurvesSchemaTokens->basisCurves &&
name != HdPrimvarsSchemaTokens->primvars) {
return result;
}
HdBasisCurvesSchema bcs = HdBasisCurvesSchema::GetFromParent(_input);
if (!bcs) {
return result;
}
HdBasisCurvesTopologySchema ts = bcs.GetTopology();
if (!ts) {
return result;
}

// TODO: Avoid sampling sampled sources here!
const TfToken wrap =
_SafeGetTypedValue<TfToken>(ts.GetWrap());
const TfToken basis =
_SafeGetTypedValue<TfToken>(ts.GetBasis());

if (wrap == HdTokens->pinned &&
(basis == HdTokens->bspline ||
basis == HdTokens->catmullRom ||
basis == HdTokens->centripetalCatmullRom)) {

// Add 2 additional end points for bspline and
// 1 for catmullRom|centripetalCatmullRom.
const size_t numExtraEnds =
(basis == HdTokens->bspline)? 2 : 1;

// Need to cache the per-curve vertex counts since the
// expansion is per-curve.
const VtIntArray curveVertexCounts =
_SafeGetTypedValue<VtIntArray>(
ts.GetCurveVertexCounts());

if (name == HdBasisCurvesSchemaTokens->basisCurves) {
if (HdContainerDataSourceHandle bcc =
HdContainerDataSource::Cast(result)) {
return _BasisCurvesDataSource::New(
bcc, curveVertexCounts, numExtraEnds);
}
// TODO: Avoid sampling sampled sources here!
const TfToken wrap =
_SafeGetTypedValue<TfToken>(ts.GetWrap());
const TfToken basis =
_SafeGetTypedValue<TfToken>(ts.GetBasis());

if (wrap == HdTokens->pinned &&
(basis == HdTokens->bspline ||
basis == HdTokens->catmullRom ||
basis == HdTokens->centripetalCatmullRom)) {

// Add 2 additional end points for bspline and
// 1 for catmullRom|centripetalCatmullRom.
const size_t numExtraEnds =
(basis == HdTokens->bspline)? 2 : 1;

// Need to cache the per-curve vertex counts since the
// expansion is per-curve.
const VtIntArray curveVertexCounts =
_SafeGetTypedValue<VtIntArray>(
ts.GetCurveVertexCounts());

if (name == HdBasisCurvesSchemaTokens->basisCurves) {
if (HdContainerDataSourceHandle bcc =
HdContainerDataSource::Cast(result)) {
return _BasisCurvesDataSource::New(
bcc, curveVertexCounts, numExtraEnds);
}
}

if (name == HdPrimvarsSchemaTokens->primvars) {
// If we have authored curve indices, we can avoid expanding
// vertex primvars by expanding the curve indices instead.
// Note that varying primvars would still need to be
// expanded due to the additional curve segments.
VtIntArray curveIndices =
_SafeGetTypedValue<VtIntArray>(ts.GetCurveIndices());

if (HdContainerDataSourceHandle pc =
HdContainerDataSource::Cast(result)) {
return _PrimvarsDataSource::New(
pc, curveVertexCounts, numExtraEnds,
!curveIndices.empty());
}
if (name == HdPrimvarsSchemaTokens->primvars) {
// If we have authored curve indices, we can avoid expanding
// vertex primvars by expanding the curve indices instead.
// Note that varying primvars would still need to be
// expanded due to the additional curve segments.
VtIntArray curveIndices =
_SafeGetTypedValue<VtIntArray>(ts.GetCurveIndices());

if (HdContainerDataSourceHandle pc =
HdContainerDataSource::Cast(result)) {
return _PrimvarsDataSource::New(
pc, curveVertexCounts, numExtraEnds,
!curveIndices.empty());
}
}
}
Expand Down

0 comments on commit 3ecaaed

Please sign in to comment.