Skip to content

Commit

Permalink
Remove primvars from value cache
Browse files Browse the repository at this point in the history
(Internal change: 2099954)
  • Loading branch information
poljere authored and pixar-oss committed Sep 29, 2020
1 parent 1ff4122 commit b373237
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 165 deletions.
6 changes: 2 additions & 4 deletions pxr/usdImaging/usdImaging/basisCurvesAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ UsdImagingBasisCurvesAdapter::UpdateForTime(
}

if (pv) {
_ComputeAndMergePrimvar(
prim, cachePath, pv, time, nullptr, &primvars);
_ComputeAndMergePrimvar(prim, pv, time, &primvars);
} else {
UsdGeomBasisCurves curves(prim);
HdInterpolation interpolation;
Expand All @@ -207,8 +206,7 @@ UsdImagingBasisCurvesAdapter::UpdateForTime(
}

if (pv) {
_ComputeAndMergePrimvar(
prim, cachePath, pv, time, nullptr, &primvars);
_ComputeAndMergePrimvar(prim, pv, time, &primvars);
} else {
UsdGeomBasisCurves curves(prim);
VtVec3fArray normals;
Expand Down
24 changes: 9 additions & 15 deletions pxr/usdImaging/usdImaging/delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2365,17 +2365,16 @@ UsdImagingDelegate::Get(SdfPath const& id, TfToken const& key)
SdfPath cachePath = ConvertIndexPathToCachePath(id);
VtValue value;

if (!_valueCache.ExtractPrimvar(cachePath, key, &value)) {
_HdPrimInfo const *primInfo = _GetHdPrimInfo(cachePath);
if (!TF_VERIFY(primInfo)) {
return value;
}
UsdPrim const & prim = primInfo->usdPrim;
if (!TF_VERIFY(prim)) {
return value;
}
value = primInfo->adapter->Get(prim, cachePath, key, _time);
_HdPrimInfo const *primInfo = _GetHdPrimInfo(cachePath);
if (!TF_VERIFY(primInfo)) {
return value;
}

UsdPrim const & prim = primInfo->usdPrim;
if (!TF_VERIFY(prim)) {
return value;
}
value = primInfo->adapter->Get(prim, cachePath, key, _time);

if (value.IsEmpty()) {
TF_WARN("Empty VtValue: <%s> %s\n", id.GetText(), key.GetText());
Expand Down Expand Up @@ -2418,11 +2417,6 @@ UsdImagingDelegate::SamplePrimvar(SdfPath const& id,
size_t nSamples = primInfo->adapter
->SamplePrimvar(primInfo->usdPrim, cachePath, key,
_time, maxNumSamples, sampleTimes, sampleValues);
// Make sure to clear the primvar out of the value cache so we don't
// leak memory...
VtValue value;
_valueCache.ExtractPrimvar(cachePath, key, &value);

return nSamples;
}
return 0;
Expand Down
44 changes: 25 additions & 19 deletions pxr/usdImaging/usdImaging/gprimAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,6 @@ UsdImagingGprimAdapter::UpdateForTime(UsdPrim const& prim,
HdTokens->velocities,
HdInterpolationVertex,
HdPrimvarRoleTokens->vector);
valueCache->GetPrimvar(cachePath, HdTokens->velocities) =
VtValue(velocities);
}

// Acceleration information is expected to be authored at the same sample
Expand All @@ -322,8 +320,6 @@ UsdImagingGprimAdapter::UpdateForTime(UsdPrim const& prim,
HdTokens->accelerations,
HdInterpolationVertex,
HdPrimvarRoleTokens->vector);
valueCache->GetPrimvar(cachePath, HdTokens->accelerations) =
VtValue(accelerations);
}
}

Expand Down Expand Up @@ -356,8 +352,7 @@ UsdImagingGprimAdapter::UpdateForTime(UsdPrim const& prim,
UsdGeomPrimvar pv =
_GetInheritedPrimvar(prim, HdTokens->displayColor);
if (pv) {
_ComputeAndMergePrimvar(
prim, cachePath, pv, time, nullptr, &vPrimvars);
_ComputeAndMergePrimvar(prim, pv, time, &vPrimvars);
}
}

Expand All @@ -372,8 +367,7 @@ UsdImagingGprimAdapter::UpdateForTime(UsdPrim const& prim,
UsdGeomPrimvar pv =
_GetInheritedPrimvar(prim, HdTokens->displayOpacity);
if (pv) {
_ComputeAndMergePrimvar(
prim, cachePath, pv, time, nullptr, &vPrimvars);
_ComputeAndMergePrimvar(prim, pv, time, &vPrimvars);
}
}

Expand Down Expand Up @@ -419,11 +413,9 @@ UsdImagingGprimAdapter::UpdateForTime(UsdPrim const& prim,
continue;
}

_ComputeAndMergePrimvar(
prim, cachePath, pv, time, valueCache, &vPrimvars);
_ComputeAndMergePrimvar(prim, pv, time, &vPrimvars);
}
}

}

HdDirtyBits
Expand Down Expand Up @@ -677,15 +669,29 @@ UsdImagingGprimAdapter::Get(UsdPrim const& prim,
} else if (key == HdTokens->points) {
return GetPoints(prim, time);

} else if (key == HdTokens->velocities) {
UsdGeomPointBased pointBased(prim);
VtVec3fArray velocities;
if (pointBased.GetVelocitiesAttr() &&
pointBased.GetVelocitiesAttr().Get(&velocities, time)) {
return VtValue(velocities);
}

} else if (key == HdTokens->accelerations) {
// Acceleration information is expected to be authored @ the same sample
// rate as points data, so use the points dirty bit to let us know when
// to publish accelerations.
UsdGeomPointBased pointBased(prim);
VtVec3fArray accelerations;
if (pointBased.GetAccelerationsAttr() &&
pointBased.GetAccelerationsAttr().Get(&accelerations, time)) {
return VtValue(accelerations);
}

} else if (UsdGeomPrimvar pv = gprim.GetPrimvar(key)) {
// XXX : We use cachePath directly as usdPath above,
// but should do the proper transformation. Maybe we can use
// the primInfo.usdPrim?
// Note here that Hydra requested "color" (e.g.) and we've converted
// it to primvars:color automatically by virtue of UsdGeomPrimvar.
TF_VERIFY(pv.ComputeFlattened(&value, time), "%s, %s\n",
prim.GetPath().GetText(), key.GetText());
return value;
if (pv.ComputeFlattened(&value, time)) {
return value;
}
}

return BaseAdapter::Get(prim, cachePath, key, time);
Expand Down
24 changes: 20 additions & 4 deletions pxr/usdImaging/usdImaging/instanceAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1242,9 +1242,6 @@ UsdImagingInstanceAdapter::UpdateForTime(UsdPrim const& prim,
if (requestedBits & HdChangeTracker::DirtyPrimvar) {
VtMatrix4dArray instanceXforms;
if (_ComputeInstanceTransforms(prim, &instanceXforms, time)) {
valueCache->GetPrimvar(
cachePath,
HdInstancerTokens->instanceTransform) = instanceXforms;
_MergePrimvar(
&valueCache->GetPrimvars(cachePath),
HdInstancerTokens->instanceTransform,
Expand All @@ -1254,7 +1251,6 @@ UsdImagingInstanceAdapter::UpdateForTime(UsdPrim const& prim,
VtValue val;
if (_ComputeInheritedPrimvar(prim, ipv.name, ipv.type,
&val, time)) {
valueCache->GetPrimvar(cachePath, ipv.name) = val;
_MergePrimvar(&valueCache->GetPrimvars(cachePath),
ipv.name, HdInterpolationInstance,
_UsdToHdRole(ipv.type.GetRole()));
Expand Down Expand Up @@ -1899,6 +1895,8 @@ UsdImagingInstanceAdapter::Get(UsdPrim const& usdPrim,
TfToken const &key,
UsdTimeCode time) const
{
TRACE_FUNCTION();

if (_IsChildPrim(usdPrim, cachePath)) {
UsdImagingInstancerContext instancerContext;
_ProtoPrim const& proto = _GetProtoPrim(usdPrim.GetPath(),
Expand All @@ -1909,6 +1907,24 @@ UsdImagingInstanceAdapter::Get(UsdPrim const& usdPrim,
}
return proto.adapter->Get(
_GetPrim(proto.path), cachePath, key, time);
} else if (_InstancerData const* instrData =
TfMapLookupPtr(_instancerData, usdPrim.GetPath())) {

if (key == HdInstancerTokens->instanceTransform) {
VtMatrix4dArray instanceXforms;
if (_ComputeInstanceTransforms(usdPrim, &instanceXforms, time)) {
return VtValue(instanceXforms);
}
}

for (auto const& ipv : instrData->inheritedPrimvars) {
VtValue val;
if (_ComputeInheritedPrimvar(usdPrim, ipv.name, ipv.type,
&val, time)) {
return val;
}
}

}
return BaseAdapter::Get(usdPrim, cachePath, key, time);
}
Expand Down
6 changes: 2 additions & 4 deletions pxr/usdImaging/usdImaging/lightAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ UsdImagingLightAdapter::TrackVariability(UsdPrim const& prim,
// prims with the DirtyCollections flag.
}

// XXX Cache primvars for lights. Note that this does not yet support
// animated lights, since we do not call UpdateForTime() for sprims.
// XXX Cache primvars for lights.
{
// Establish a valueCache entry.
HdPrimvarDescriptorVector& vPrimvars =
Expand All @@ -121,8 +120,7 @@ UsdImagingLightAdapter::TrackVariability(UsdPrim const& prim,
std::vector<UsdGeomPrimvar> local = primvarsAPI.GetPrimvarsWithValues();
primvars.insert(primvars.end(), local.begin(), local.end());
for (auto const &pv : primvars) {
_ComputeAndMergePrimvar(
prim, cachePath, pv, UsdTimeCode(), valueCache, &vPrimvars);
_ComputeAndMergePrimvar(prim, pv, UsdTimeCode(), &vPrimvars);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions pxr/usdImaging/usdImaging/meshAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ UsdImagingMeshAdapter::UpdateForTime(UsdPrim const& prim,
}

if (pv) {
_ComputeAndMergePrimvar(
prim, cachePath, pv, time, nullptr, &primvars);
_ComputeAndMergePrimvar(prim, pv, time, &primvars);
} else {
UsdGeomMesh mesh(prim);
VtVec3fArray normals;
Expand Down
6 changes: 2 additions & 4 deletions pxr/usdImaging/usdImaging/nurbsCurvesAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ UsdImagingNurbsCurvesAdapter::UpdateForTime(UsdPrim const& prim,
}

if (pv) {
_ComputeAndMergePrimvar(
prim, cachePath, pv, time, nullptr, &primvars);
_ComputeAndMergePrimvar(prim, pv, time, &primvars);
} else {
UsdGeomNurbsCurves curves(prim);
HdInterpolation interpolation;
Expand All @@ -208,8 +207,7 @@ UsdImagingNurbsCurvesAdapter::UpdateForTime(UsdPrim const& prim,
}

if (pv) {
_ComputeAndMergePrimvar(
prim, cachePath, pv, time, nullptr, &primvars);
_ComputeAndMergePrimvar(prim, pv, time, &primvars);
} else {
UsdGeomNurbsCurves curves(prim);
VtVec3fArray normals;
Expand Down
81 changes: 54 additions & 27 deletions pxr/usdImaging/usdImaging/pointInstancerAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,6 @@ UsdImagingPointInstancerAdapter::UpdateForTime(UsdPrim const& prim,
// sent to the GPU on every frame.
VtVec3fArray positions;
if (instancer.GetPositionsAttr().Get(&positions, time)) {
valueCache->GetPrimvar(cachePath, _tokens->translate) =
positions;
_MergePrimvar(
&vPrimvars,
_tokens->translate,
Expand All @@ -645,21 +643,6 @@ UsdImagingPointInstancerAdapter::UpdateForTime(UsdPrim const& prim,

VtQuathArray orientations;
if (instancer.GetOrientationsAttr().Get(&orientations, time)) {
// convert to Vec4Array that hydra instancer requires.
// Also note that hydra's instancer takes GfQuaterion layout
// (real, imaginary) which differs from GfQuath's
// (imaginary, real)
VtVec4fArray rotations;
rotations.reserve(orientations.size());
for (const GfQuath& orientation : orientations) {
rotations.push_back(
GfVec4f(orientation.GetReal(),
orientation.GetImaginary()[0],
orientation.GetImaginary()[1],
orientation.GetImaginary()[2]));
}

valueCache->GetPrimvar(cachePath, _tokens->rotate) = rotations;
_MergePrimvar(
&vPrimvars,
_tokens->rotate,
Expand All @@ -668,7 +651,6 @@ UsdImagingPointInstancerAdapter::UpdateForTime(UsdPrim const& prim,

VtVec3fArray scales;
if (instancer.GetScalesAttr().Get(&scales, time)) {
valueCache->GetPrimvar(cachePath, _tokens->scale) = scales;
_MergePrimvar(
&vPrimvars,
_tokens->scale,
Expand All @@ -685,14 +667,7 @@ UsdImagingPointInstancerAdapter::UpdateForTime(UsdPrim const& prim,
if (interp != UsdGeomTokens->constant &&
interp != UsdGeomTokens->uniform) {
HdInterpolation interp = HdInterpolationInstance;
_ComputeAndMergePrimvar(
prim,
cachePath,
pv,
time,
valueCache,
&vPrimvars,
&interp);
_ComputeAndMergePrimvar(prim, pv, time, &vPrimvars, &interp);
}
}
}
Expand Down Expand Up @@ -1848,15 +1823,67 @@ UsdImagingPointInstancerAdapter::GetMaterialId(UsdPrim const& usdPrim,
VtValue
UsdImagingPointInstancerAdapter::Get(UsdPrim const& usdPrim,
SdfPath const& cachePath,
TfToken const &key,
TfToken const& key,
UsdTimeCode time) const
{
TRACE_FUNCTION();

if (IsChildPath(cachePath)) {
// Delegate to prototype adapter and USD prim.
_ProtoPrim const& proto = _GetProtoPrim(usdPrim.GetPath(), cachePath);
UsdPrim protoPrim = _GetProtoUsdPrim(proto);
return proto.adapter->Get(protoPrim, cachePath, key, time);

} else if (_InstancerData const* instrData =
TfMapLookupPtr(_instancerData, cachePath)) {
TF_UNUSED(instrData);

if (key == _tokens->translate) {
UsdGeomPointInstancer instancer(usdPrim);
VtVec3fArray positions;
if (instancer.GetPositionsAttr().Get(&positions, time)) {
return VtValue(positions);
}

} else if (key == _tokens->rotate) {
UsdGeomPointInstancer instancer(usdPrim);
VtQuathArray orientations;
if (instancer.GetOrientationsAttr().Get(&orientations, time)) {
// convert to Vec4Array that hydra instancer requires.
// Also note that hydra's instancer takes GfQuaterion layout
// (real, imaginary) which differs from GfQuath's
// (imaginary, real)
VtVec4fArray rotations;
rotations.reserve(orientations.size());
for (const GfQuath& orientation : orientations) {
rotations.push_back(
GfVec4f(orientation.GetReal(),
orientation.GetImaginary()[0],
orientation.GetImaginary()[1],
orientation.GetImaginary()[2]));
}
return VtValue(rotations);
}

} else if (key == _tokens->scale) {
UsdGeomPointInstancer instancer(usdPrim);
VtVec3fArray scales;
if (instancer.GetScalesAttr().Get(&scales, time)) {
return VtValue(scales);
}

} else {
UsdGeomPointInstancer instancer(usdPrim);
UsdGeomPrimvarsAPI primvars(instancer);
UsdGeomPrimvar pv = primvars.GetPrimvar(key);
VtValue value;
if (pv) {
pv.ComputeFlattened(&value, time);
}
return value;
}
}

return BaseAdapter::Get(usdPrim, cachePath, key, time);
}

Expand Down
6 changes: 2 additions & 4 deletions pxr/usdImaging/usdImaging/pointsAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ UsdImagingPointsAdapter::UpdateForTime(UsdPrim const& prim,
}

if (pv) {
_ComputeAndMergePrimvar(
prim, cachePath, pv, time, nullptr, &primvars);
_ComputeAndMergePrimvar(prim, pv, time, &primvars);
} else {
UsdGeomPoints points(prim);
VtFloatArray widths;
Expand All @@ -194,8 +193,7 @@ UsdImagingPointsAdapter::UpdateForTime(UsdPrim const& prim,
}

if (pv) {
_ComputeAndMergePrimvar(
prim, cachePath, pv, time, nullptr, &primvars);
_ComputeAndMergePrimvar(prim, pv, time, &primvars);
} else {
UsdGeomPoints points(prim);
VtVec3fArray normals;
Expand Down
Loading

0 comments on commit b373237

Please sign in to comment.