24 #ifndef PXR_IMAGING_HD_EXT_COMPUTATION_UTILS_H
25 #define PXR_IMAGING_HD_EXT_COMPUTATION_UTILS_H
36 #include <unordered_map>
53 std::unordered_map<TfToken, VtValue, TfToken::HashFunctor>;
65 template <
unsigned int CAPACITY>
67 std::unordered_map<TfToken, HdTimeSampleArray<VtValue, CAPACITY>,
74 template <
unsigned int CAPACITY>
79 size_t maxSampleCount,
104 _GenerateDependencyMap(
108 template <
unsigned int CAPACITY>
110 _ExecuteSampledComputations(
113 size_t maxSampleCount,
120 _LimitTimeSamples(
size_t maxSampleCount, std::vector<double>* times);
137 template <
unsigned int CAPACITY>
142 size_t maxSampleCount,
150 _GenerateDependencyMap(compPrimvars, sceneDelegate);
161 _ExecuteSampledComputations<CAPACITY>(sortedComputations, sceneDelegate,
162 maxSampleCount, &valueStore);
165 for (
auto const& pv : compPrimvars) {
166 TfToken const& compOutputName = pv.sourceComputationOutputName;
167 (*computedPrimvarValueStore)[pv.name] = valueStore[compOutputName];
171 template <
unsigned int CAPACITY>
173 HdExtComputationUtils::_ExecuteSampledComputations(
176 size_t maxSampleCount,
177 SampledValueStore<CAPACITY> *valueStore
182 for (
auto const& comp : computations) {
183 SdfPath const& compId = comp->GetId();
185 TfTokenVector const& sceneInputNames = comp->GetSceneInputNames();
187 comp->GetComputationInputs();
189 comp->GetComputationOutputs();
192 std::vector<double> times;
193 for (
TfToken const& input : sceneInputNames) {
194 auto &
samples = (*valueStore)[input];
197 for (
size_t i = 0; i <
samples.count; ++i)
198 times.push_back(
samples.times[i]);
201 if (comp->IsInputAggregation()) {
208 for (
auto const& computedInput : compInputs) {
210 valueStore->at(computedInput.sourceComputationOutputName);
211 for (
size_t i = 0; i <
samples.count; ++i) {
212 times.push_back(
samples.times[i]);
217 _LimitTimeSamples(maxSampleCount, ×);
222 auto &output_samples = (*valueStore)[
name];
223 output_samples.Resize(times.size());
224 output_samples.count = 0;
228 sceneInputValues.
reserve(sceneInputNames.size());
231 compInputValues.
reserve(compInputs.size());
236 for (
double t : times) {
240 sceneInputValues.
clear();
241 for (
auto const& sceneInput : comp->GetSceneInputNames()) {
242 auto const&
samples = valueStore->at(sceneInput);
246 compInputValues.
clear();
247 for (
auto const& computedInput : compInputs) {
249 valueStore->at(computedInput.sourceComputationOutputName);
253 compOutputValues.
resize(compOutputs.size());
254 if (!_InvokeComputation(*sceneDelegate, *comp,
265 for (
size_t i = 0; i < compOutputValues.
size(); ++i) {
266 auto &output_samples = (*valueStore)[compOutputs[i].name];
268 output_samples.times[output_samples.count] =
t;
269 output_samples.values[output_samples.count] =
270 std::move(compOutputValues[i]);
271 ++output_samples.count;
280 #endif // PXR_IMAGING_HD_EXT_COMPUTATION_UTILS_H
std::unordered_map< TfToken, HdTimeSampleArray< VtValue, CAPACITY >, TfToken::HashFunctor > SampledValueStore
void push_back(const value_type &v)
void resize(size_type newSize, const value_type &v=value_type())
void reserve(size_type newCapacity)
std::vector< HdExtComputationInputDescriptor > HdExtComputationInputDescriptorVector
static HD_API void PrintDependencyMap(ComputationDependencyMap const &cdm)
Functor to use for hash maps from tokens to other things.
std::vector< HdExtComputationOutputDescriptor > HdExtComputationOutputDescriptorVector
std::unordered_map< HdExtComputation const *, HdExtComputationConstPtrVector > ComputationDependencyMap
static HD_API ValueStore GetComputedPrimvarValues(HdExtComputationPrimvarDescriptorVector const &compPrimvars, HdSceneDelegate *sceneDelegate)
#define HD_TRACE_FUNCTION()
std::vector< TfToken > TfTokenVector
Convenience types.
GLuint const GLchar * name
static void SampleComputedPrimvarValues(HdExtComputationPrimvarDescriptorVector const &compPrimvars, HdSceneDelegate *sceneDelegate, size_t maxSampleCount, SampledValueStore< CAPACITY > *computedPrimvarValueStore)
virtual HD_API size_t SampleExtComputationInput(SdfPath const &computationId, TfToken const &input, size_t maxSampleCount, float *sampleTimes, VtValue *sampleValues)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
std::unordered_map< TfToken, VtValue, TfToken::HashFunctor > ValueStore
TfSpan< typename Container::value_type > TfMakeSpan(Container &cont)
Helper for constructing a non-const TfSpan from a container.
#define PXR_NAMESPACE_CLOSE_SCOPE
static HD_API bool DependencySort(ComputationDependencyMap cdm, HdExtComputationConstPtrVector *sortedComps)
std::vector< HdExtComputationConstPtr > HdExtComputationConstPtrVector
HdExtComputation const * HdExtComputationConstPtr
std::vector< HdExtComputationPrimvarDescriptor > HdExtComputationPrimvarDescriptorVector