Skip to content

Commit

Permalink
Merge pull request #2058 from cameronwhite/dev_extcomp_dependencymap
Browse files Browse the repository at this point in the history
Fix bug in HdExtComputationUtils::_GenerateDependencyMap() with multiple input computations

(Internal change: 2256749)
  • Loading branch information
pixar-oss committed Dec 8, 2022
2 parents ab0ef74 + faa5eda commit c0aed8a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pxr/imaging/hd/extComputationUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ HdExtComputationUtils::_GenerateDependencyMap(
HdExtComputationUtils::ComputationDependencyMap cdm;
while (!computations.empty()) {
// Pop head entry and skip if already processed.
HdExtComputation const * curComp = computations.back();
HdExtComputation const * curComp = computations.front();
computations.pop_front();
if (cdm.find(curComp) != cdm.end()) {
continue;
Expand Down
48 changes: 33 additions & 15 deletions pxr/imaging/hd/testenv/testHdExtComputationUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,20 @@
PXR_NAMESPACE_USING_DIRECTIVE

static const SdfPath pathA("/path/to/A");
static const SdfPath compA("/path/to/A/computation");
static const SdfPath compA("/path/to/A/computationA");
static const SdfPath compB("/path/to/A/computationB");
static const SdfPath compC("/path/to/A/computationC");
static const TfToken input1("input1");
static const TfToken input2("input2");
static const TfToken primvarName("outputPV");
static const TfToken compOutputName("compOutput");

// Delegate that implements a simple computation (adding together two inputs).
// Delegate that implements a simple computation, which adds together inputs
// from two aggregate computations:
//
// computationA -> computationB -> input1
// \-> computationC -> input2
//
class ExtComputationTestDelegate : public HdUnitTestDelegate {
public:
ExtComputationTestDelegate(HdRenderIndex *parentIndex)
Expand Down Expand Up @@ -71,13 +78,26 @@ class ExtComputationTestDelegate : public HdUnitTestDelegate {

virtual TfTokenVector
GetExtComputationSceneInputNames(SdfPath const& computationId) override {
if (computationId == compA) {
return {input1, input2};
if (computationId == compB) {
return {input1};
} else if (computationId == compC) {
return {input2};
}

return {};
}

virtual HdExtComputationInputDescriptorVector
GetExtComputationInputDescriptors(SdfPath const& computationId) override {
HdExtComputationInputDescriptorVector inputs;
if (computationId == compA) {
inputs.emplace_back(input1, compB, input1);
inputs.emplace_back(input2, compC, input2);
}

return inputs;
}

virtual HdExtComputationOutputDescriptorVector
GetExtComputationOutputDescriptors(SdfPath const& computationId) override {
HdExtComputationOutputDescriptorVector outputs;
Expand All @@ -96,21 +116,17 @@ class ExtComputationTestDelegate : public HdUnitTestDelegate {
size_t maxSampleCount,
float *sampleTimes,
VtValue *sampleValues) override {
if (computationId != compA) {
return 0;
}

const size_t numSamples = std::min(size_t(4), maxSampleCount);

// The two inputs have different sample times (0,1,2,3 and 0,2,4,6).
if (input == input1) {
if (computationId == compB && input == input1) {
for (size_t i = 0; i < numSamples; ++i) {
sampleTimes[i] = i;
sampleValues[i] = VtValue(double(i));
}
return numSamples;
}
else if (input == input2) {
else if (computationId == compC && input == input2) {
for (size_t i = 0; i < numSamples; ++i) {
sampleTimes[i] = i * 2;
sampleValues[i] = VtValue(double(i));
Expand Down Expand Up @@ -218,11 +234,13 @@ void RunTest()
HdRenderIndex::New(&renderDelegate, {}));
ExtComputationTestDelegate delegate(index.get());

// Create an sprim for the computation.
index->InsertSprim(HdPrimTypeTokens->extComputation, &delegate, compA);
auto sprim = index->GetSprim(HdPrimTypeTokens->extComputation, compA);
HdDirtyBits dirty = HdExtComputation::DirtyBits::AllDirty;
sprim->Sync(&delegate, nullptr, &dirty);
// Create an sprim for each computation.
for (const SdfPath &comp : {compA, compB, compC}) {
index->InsertSprim(HdPrimTypeTokens->extComputation, &delegate, comp);
auto sprim = index->GetSprim(HdPrimTypeTokens->extComputation, comp);
HdDirtyBits dirty = HdExtComputation::DirtyBits::AllDirty;
sprim->Sync(&delegate, nullptr, &dirty);
}

auto compPrimvars = delegate.GetExtComputationPrimvarDescriptors(
pathA, HdInterpolationConstant);
Expand Down

0 comments on commit c0aed8a

Please sign in to comment.