Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAYA-106930 CPU UsdSkel support for MayaUSD. #1992

Merged
merged 3 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions lib/mayaUsd/render/vp2RenderDelegate/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

#include <pxr/base/gf/matrix4d.h>
#include <pxr/base/tf/getenv.h>
#include <pxr/imaging/hd/extCompCpuComputation.h>
#include <pxr/imaging/hd/extCompPrimvarBufferSource.h>
#include <pxr/imaging/hd/extComputation.h>
#include <pxr/imaging/hd/meshUtil.h>
#include <pxr/imaging/hd/sceneDelegate.h>
#include <pxr/imaging/hd/smoothNormals.h>
Expand Down Expand Up @@ -2739,6 +2742,56 @@ void HdVP2Mesh::_UpdatePrimvarSources(
}
}
}

// At this point we've searched the primvars for the required primvars.
// check to see if there are any HdExtComputation which should replace
// primvar data or fill in for a missing primvar.
HdExtComputationPrimvarDescriptorVector compPrimvars
= sceneDelegate->GetExtComputationPrimvarDescriptors(id, HdInterpolationVertex);
const HdRenderIndex& renderIndex = sceneDelegate->GetRenderIndex();
for (const auto& primvarName : requiredPrimvars) {
// The compPrimvars are a description of the link between the compute system and
// what we need to draw.
auto result
= std::find_if(compPrimvars.begin(), compPrimvars.end(), [&](const auto& compPrimvar) {
return compPrimvar.name == primvarName;
});
// if there is no compute for the given required primvar then we're done!
if (result == compPrimvars.end())
continue;
HdExtComputationPrimvarDescriptor compPrimvar = *result;
// Create the HdExtCompCpuComputation objects necessary to resolve the computation
HdExtComputation const* sourceComp
= static_cast<HdExtComputation const*>(renderIndex.GetSprim(
HdPrimTypeTokens->extComputation, compPrimvar.sourceComputationId));
if (!sourceComp || sourceComp->GetElementCount() <= 0)
continue;

// This compPrimvar is telling me that the primvar with "name" comes from compute.
// The compPrimvar has the Id of the compute the data comes from, and the output
// of the compute which contains the data
HdExtCompCpuComputationSharedPtr cpuComputation;
HdBufferSourceSharedPtrVector sources;
// There is a possible data race calling CreateComputation, see
// https://github.com/PixarAnimationStudios/USD/issues/1742
cpuComputation
= HdExtCompCpuComputation::CreateComputation(sceneDelegate, *sourceComp, &sources);

// Immediately resolve the computation so we can fill _meshSharedData._primvarInfo
for (HdBufferSourceSharedPtr& source : sources) {
source->Resolve();
}

// Pull the result out of the compute and save it into our local primvar info.
size_t outputIndex
= cpuComputation->GetOutputIndex(compPrimvar.sourceComputationOutputName);
// INVALID_OUTPUT_INDEX is declared static in USD, can't access here so re-declare
constexpr size_t INVALID_OUTPUT_INDEX = std::numeric_limits<size_t>::max();
if (INVALID_OUTPUT_INDEX != outputIndex) {
updatePrimvarInfo(
primvarName, cpuComputation->GetOutputByIndex(outputIndex), HdInterpolationVertex);
}
}
}

#ifndef MAYA_NEW_POINT_SNAPPING_SUPPORT
Expand Down
11 changes: 10 additions & 1 deletion lib/mayaUsd/render/vp2RenderDelegate/render_delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include <pxr/imaging/hd/bprim.h>
#include <pxr/imaging/hd/camera.h>
#include <pxr/imaging/hd/extComputation.h>
#include <pxr/imaging/hd/instancer.h>
#include <pxr/imaging/hd/resourceRegistry.h>
#include <pxr/imaging/hd/rprim.h>
Expand Down Expand Up @@ -56,7 +57,9 @@ inline const TfTokenVector& _SupportedRprimTypes()
*/
inline const TfTokenVector& _SupportedSprimTypes()
{
static const TfTokenVector r { HdPrimTypeTokens->material, HdPrimTypeTokens->camera };
static const TfTokenVector r { HdPrimTypeTokens->material,
HdPrimTypeTokens->camera,
HdPrimTypeTokens->extComputation };
return r;
}

Expand Down Expand Up @@ -705,6 +708,9 @@ HdSprim* HdVP2RenderDelegate::CreateSprim(const TfToken& typeId, const SdfPath&
if (typeId == HdPrimTypeTokens->camera) {
return new HdCamera(sprimId);
}
if (typeId == HdPrimTypeTokens->extComputation) {
return new HdExtComputation(sprimId);
}
/*
if (typeId == HdPrimTypeTokens->sphereLight) {
return HdVP2Light::CreatePointLight(this, sprimId);
Expand Down Expand Up @@ -746,6 +752,9 @@ HdSprim* HdVP2RenderDelegate::CreateFallbackSprim(const TfToken& typeId)
if (typeId == HdPrimTypeTokens->camera) {
return new HdCamera(SdfPath::EmptyPath());
}
if (typeId == HdPrimTypeTokens->extComputation) {
return new HdExtComputation(SdfPath::EmptyPath());
}
/*
if (typeId == HdPrimTypeTokens->sphereLight) {
return HdVP2Light::CreatePointLight(this, SdfPath::EmptyPath());
Expand Down
1 change: 1 addition & 0 deletions test/lib/mayaUsd/render/vp2RenderDelegate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ endif()
if (MAYA_APP_VERSION VERSION_GREATER 2022)
list(APPEND TEST_SCRIPT_FILES
testVP2RenderDelegateSelection.py
testVP2RenderDelegateUsdSkel.py
)
endif()

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env mayapy
#
# Copyright 2021 Autodesk
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import fixturesUtils
import imageUtils
import mayaUtils
import usdUtils
import testUtils

from mayaUsd import lib as mayaUsdLib
from mayaUsd import ufe as mayaUsdUfe

from maya import cmds

import ufe

import os


class testVP2RenderDelegateUsdSkel(imageUtils.ImageDiffingTestCase):
"""
Tests imaging using the Viewport 2.0 render delegate when using per-instance
inherited data on instances.
"""

@classmethod
def setUpClass(cls):
# The test USD data is authored Z-up, so make sure Maya is configured
# that way too.
cmds.upAxis(axis='z')

inputPath = fixturesUtils.setUpClass(__file__,
initializeStandalone=False, loadPlugin=False)

cls._baselineDir = os.path.join(inputPath,
'VP2RenderDelegateUsdSkelTest', 'baseline')

cls._testDir = os.path.abspath('.')

def assertSnapshotClose(self, imageName):
baselineImage = os.path.join(self._baselineDir, imageName)
snapshotImage = os.path.join(self._testDir, imageName)
imageUtils.snapshot(snapshotImage, width=960, height=540)
return self.assertImagesClose(baselineImage, snapshotImage)

def _StartTest(self, testName):
self._testName = testName
testFile = testUtils.getTestScene("UsdSkel", self._testName + ".usda")
mayaUtils.createProxyFromFile(testFile)
globalSelection = ufe.GlobalSelection.get()
globalSelection.clear()
cmds.currentTime(0)
self.assertSnapshotClose('%s_0.png' % self._testName)
cmds.currentTime(50)
self.assertSnapshotClose('%s_50.png' % self._testName)
cmds.currentTime(100)
self.assertSnapshotClose('%s_100.png' % self._testName)

def testPerInstanceInheritedData(self):
mayaUtils.loadPlugin("mayaUsdPlugin")

cmds.file(force=True, new=True)
cmds.move(-8, 15, 6, 'persp')
cmds.rotate(70, 0, -160, 'persp')
self._StartTest('skinCluster')

cmds.file(force=True, new=True)
cmds.move(180, -525, 225, 'persp')
cmds.rotate(75, 0, 0, 'persp')
self._StartTest('HIK_Export')



if __name__ == '__main__':
fixturesUtils.runTests(globals())
Loading