void Hd_VtExtractor::Extract(const VtValue &value) { // Type dispatch to _Extractor. // // Iterate over each acceptable type T, calling typeChecker<T>(), which // internally calls value.IsHolding<T>(); if the VtValue IS holding a T, // then pass the held value to _Extractor::Extract<T>(value). _Extractor e; boost::mpl::for_each<_AcceptedTypes>(_TypeChecker<_Extractor>(value, e)); // Guarantee that the _Extractor::Extract method was called exactly once // and issue a runtime error otherwise. (The only case where Extract wont // be called is when the VtValue is holding an unacceptable type). if (e.GetNumComponents() == 0) { TF_RUNTIME_ERROR("Trying to extract a VtValue holding " "unacceptable type: %s", value.GetType().GetTypeName().c_str()); return; } const _GLDataType &glDataType = e.GetGLDataType(); _glComponentType = glDataType.componentType; _glElementType = glDataType.elementType; _size = e.GetSize(); _numComponents = e.GetNumComponents(); _data = e.GetData(); }
static bool _GetMetadataUnchecked( const MFnDependencyNode& node, const TfToken& key, VtValue* value) { VtValue fallback = SdfSchema::GetInstance().GetFallback(key); if (fallback.IsEmpty()) { return false; } std::string mayaAttrName = _GetMayaAttrNameForMetadataKey(key); MPlug plug = node.findPlug(mayaAttrName.c_str()); if (plug.isNull()) { return false; } TfType ty = fallback.GetType(); VtValue result = UsdMayaWriteUtil::GetVtValue(plug, ty, TfToken()); if (result.IsEmpty()) { TF_RUNTIME_ERROR( "Cannot convert plug '%s' into metadata '%s' (%s)", plug.name().asChar(), key.GetText(), ty.GetTypeName().c_str()); return false; } *value = result; return true; }
bool UsdMayaAdaptor::SetMetadata( const TfToken& key, const VtValue& value, MDGModifier& modifier) { if (!*this) { TF_CODING_ERROR("Adaptor is not valid"); return false; } VtValue fallback; if (!SdfSchema::GetInstance().IsRegistered(key, &fallback)) { TF_CODING_ERROR("Metadata key '%s' is not registered", key.GetText()); return false; } if (fallback.IsEmpty()) { return false; } VtValue castValue = VtValue::CastToTypeOf(value, fallback); if (castValue.IsEmpty()) { TF_CODING_ERROR("Can't cast value to type '%s'", fallback.GetTypeName().c_str()); return false; } std::string mayaAttrName = _GetMayaAttrNameForMetadataKey(key); std::string mayaNiceAttrName = key.GetText(); MFnDependencyNode node(_handle.object()); TfType ty = fallback.GetType(); MObject attrObj = UsdMayaReadUtil::FindOrCreateMayaAttr( ty, TfToken(), SdfVariabilityUniform, node, mayaAttrName, mayaNiceAttrName, modifier); if (attrObj.isNull()) { return false; } MPlug plug = node.findPlug(attrObj); if (!UsdMayaReadUtil::SetMayaAttr(plug, castValue, modifier)) { return false; } return true; }
void HdStExtComputation::Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) { HD_TRACE_FUNCTION(); HF_MALLOC_TAG_FUNCTION(); TF_DEBUG(HD_EXT_COMPUTATION_UPDATED).Msg( "HdStExtComputation::Sync %s\n", GetId().GetText()); HdExtComputation::_Sync(sceneDelegate, renderParam, dirtyBits); // We only commit GPU resources when directly executing a GPU computation // or when aggregating inputs for a downstream computation. if (GetGpuKernelSource().empty() && !IsInputAggregation()) { return; } HdRenderIndex &renderIndex = sceneDelegate->GetRenderIndex(); HdStResourceRegistrySharedPtr const & resourceRegistry = boost::dynamic_pointer_cast<HdStResourceRegistry>( renderIndex.GetResourceRegistry()); HdBufferSourceVector inputs; for (TfToken const & inputName: GetSceneInputNames()) { VtValue inputValue = sceneDelegate->GetExtComputationInput( GetId(), inputName); size_t arraySize = inputValue.IsArrayValued() ? inputValue.GetArraySize() : 1; HdBufferSourceSharedPtr inputSource = HdBufferSourceSharedPtr( new HdVtBufferSource(inputName, inputValue, arraySize)); if (inputSource->IsValid()) { inputs.push_back(inputSource); } else { TF_WARN("Unsupported type %s for source %s in extComputation %s.", inputValue.GetType().GetTypeName().c_str(), inputName.GetText(), GetId().GetText()); } } _inputRange.reset(); if (!inputs.empty()) { if (_IsEnabledSharedExtComputationData() && IsInputAggregation()) { uint64_t inputId = _ComputeSharedComputationInputId(0, inputs); HdInstance<uint64_t, HdBufferArrayRangeSharedPtr> barInstance; std::unique_lock<std::mutex> regLog = resourceRegistry->RegisterExtComputationDataRange(inputId, &barInstance); if (barInstance.IsFirstInstance()) { // Allocate the first buffer range for this input key _inputRange = _AllocateComputationDataRange(inputs, resourceRegistry); barInstance.SetValue(_inputRange); TF_DEBUG(HD_SHARED_EXT_COMPUTATION_DATA).Msg( "Allocated shared ExtComputation buffer range: %s: %p\n", GetId().GetText(), (void *)_inputRange.get()); } else { // Share the existing buffer range for this input key _inputRange = barInstance.GetValue(); TF_DEBUG(HD_SHARED_EXT_COMPUTATION_DATA).Msg( "Reused shared ExtComputation buffer range: %s: %p\n", GetId().GetText(), (void *)_inputRange.get()); } } else { // We're not sharing, so go ahead and allocate new buffer range. _inputRange = _AllocateComputationDataRange(inputs, resourceRegistry); } // Make sure that we also release any stale input range data renderIndex.GetChangeTracker().SetGarbageCollectionNeeded(); } }