Loading...
Searching...
No Matches
generativeProcedural.h
1//
2// Copyright 2022 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_IMAGING_HD_GP_GENERATIVE_PROCEDURAL_H
8#define PXR_IMAGING_HD_GP_GENERATIVE_PROCEDURAL_H
9
10#include "pxr/pxr.h"
11#include "pxr/imaging/hdGp/api.h"
12#include "pxr/imaging/hd/sceneIndex.h"
14
15PXR_NAMESPACE_OPEN_SCOPE
16
17#define HDGPGENERATIVEPROCEDURAL_TOKENS \
18 ((generativeProcedural, "hydraGenerativeProcedural")) \
19 ((resolvedGenerativeProcedural, "resolvedHydraGenerativeProcedural")) \
20 ((skippedGenerativeProcedural, "skippedHydraGenerativeProcedural")) \
21 ((proceduralType, "hdGp:proceduralType")) \
22 ((anyProceduralType, "*"))
23
24TF_DECLARE_PUBLIC_TOKENS(HdGpGenerativeProceduralTokens,
25 HDGPGENERATIVEPROCEDURAL_TOKENS);
26
37{
38public:
39 HDGP_API
40 HdGpGenerativeProcedural(const SdfPath &proceduralPrimPath);
41
42 HDGP_API
44
45 using DependencyMap =
47
48 using ChildPrimTypeMap =
50
51 // Given access to the input scene (specifically the primvars serving as
52 // arguments on the procedural's own prim), return what other data sources
53 // of what other prims we depend upon and should be given the opportunity
54 // to update in response their changes.
55 //
56 // For a single instance, UpdateDependencies will not be called from
57 // multiple threads -- nor concurrent to Update
58 HDGP_API
59 virtual DependencyMap UpdateDependencies(
60 const HdSceneIndexBaseRefPtr &inputScene) = 0;
61
62 // This is the primary "cook" method called when a procedural is initially
63 // resolved or invalidated. The result is a map of child prim paths and
64 // their hydra scene prim types. Because a cook/recook can add, remove or
65 // dirty child prims, the returned ChildPrimTypeMap must always contain
66 // the full set of child prims. It is interpreted in this way:
67 // 1) Prims which did not exist in the result of
68 // of previous calls to this method will be added.
69 // 2) Prims which existed in the results of previous calls but not in this
70 // result will be removed.
71 // 3) Prims whose type has changed between calls to this method will be
72 // re-added.
73 //
74 // Prims which exist in both (and have not changed type) are not considered
75 // dirty unless added to the outputDirtiedPrims vector. Because each entry
76 // in that vector contains an HdDataSourceLocatorSet, invalidation can be
77 // as broad or specific as possible. In order to reduce the amount of
78 // bookkeeping for the procedural itself, previousResult contains the
79 // result of the previous call to this method.
80 //
81 // dirtiedDependencies contains the prim paths and locator sets of
82 // declared dependencies which have been dirtied since the last cook. For
83 // initial cooks (and in response to things like removal of prims previously
84 // dependeded upon), the full set of declared dependencies is sent here. A
85 // procedural may choose to cache values previously queried from the input
86 // scene and invalidate based on the contents of dirtiedDependencies.
87 //
88 // NOTE: For initial cooks, changes to the procedural's own prim will not
89 // be included within dirtiedDependencies. (TODO: reconsider this.)
90 //
91 // ALSO NOTE: Because this method is responsible only for describing the
92 // presence and type (and potential dirtiness) of its child
93 // prims -- and not the data sources for those prims -- it may
94 // choose to defer some computation of values to happen within
95 // data sources returned by GetChildPrim.
96 //
97 // For a single instance, Update will not be called from
98 // multiple threads -- nor concurrent to UpdateDependencies
99 HDGP_API
100 virtual ChildPrimTypeMap Update(
101 const HdSceneIndexBaseRefPtr &inputScene,
102 const ChildPrimTypeMap &previousResult,
103 const DependencyMap &dirtiedDependencies,
104 HdSceneIndexObserver::DirtiedPrimEntries *outputDirtiedPrims) = 0;
105
106 // Returns the type and prim-level data source for a child prim previously
107 // added or invalidated from the Update method.
108 //
109 // This should expect to be called from multiple threads
110 HDGP_API
111 virtual HdSceneIndexPrim GetChildPrim(
112 const HdSceneIndexBaseRefPtr &inputScene,
113 const SdfPath &childPrimPath) = 0;
114
115 // Returns a locator which can be used in the UpdateDependencies result to
116 // declare a dependency on the set of immediate children for a prim path.
117 HDGP_API
118 static const HdDataSourceLocator &GetChildNamesDependencyKey();
119
120
121 // ------------------------------------------------------------------------
122 // Asynchronous API
123 // ------------------------------------------------------------------------
124
125 // Called to inform a procedural instance whether asychronous evaluation
126 // is possible.
127 //
128 // If asyncEnabled is true, a procedural which makes use of asynchronous
129 // processing should return true to indicate that it wants to receive
130 // AsyncUpdate calls. If asyncEnabled is false, the procedural is expected
131 // to do its work as normal.
132 //
133 // Procedurals which have previously declined async updates (or have
134 // indicated that they are finished via a return value from AsyncUpdate)
135 // are given an opportunity begin asynchronous processing (via receiving
136 // another call to this method) following any call to UpdateDependencies.
137 HDGP_API
138 virtual bool AsyncBegin(bool asyncEnabled);
139
140 enum AsyncState
141 {
142 Continuing = 0, // nothing new, continue checking
143 Finished, // nothing new, stop checking
144 ContinuingWithNewChanges, // new stuff, but continue checking
145 FinishedWithNewChanges, // new stuff, but stop checking
146 };
147
148 // When asynchronous evaluation is enabled, a procedural will be polled (
149 // at a frequency determined by the host application) to discover any
150 // changes to child prim state.
151 //
152 // This is similar to the standard Update call but differs in these ways:
153 // 1) The input scene is not provided. Any information needed from it for
154 // the sake of asychronous processing should be retrieved during the
155 // standard Update call.
156 // 2) Filling in the provided outputPrimTypes is equivalent to the return
157 // value of the standard Update. If no child prim presence or type
158 // changes (or dirtying) are available, no action is required.
159 // 3) It should not be used to do significant work but rather just to
160 // synchronize the results of work completed by threads or processes
161 // managed by the procedural.
162 //
163 // Changes are only considered following a return value of
164 // ContinuingWithNewChanges or FinishedWithNewChanges. In that case,
165 // outputPrimTypes must be filled in full (similar to the result of standard
166 // Update). As with Update, the previous child prim type map is provided
167 // for convenience.
168 //
169 // Return values of Finished or FinishedWithNewChanges will prevent this
170 // method from being called again until another call to AsyncBegin(true)
171 // returns a true value. This allows a procedural to indicate when it is
172 // finished and then restarted itself in response to declared dependenices
173 // changing. Should a procedural wish to continue receiving the AsyncUpdate
174 // call regardless of whether declared dependencies are dirtied, it should
175 // return Continuing or ContinuingWithNewChanges;
176 HDGP_API
177 virtual AsyncState AsyncUpdate(
178 const ChildPrimTypeMap &previousResult,
179 ChildPrimTypeMap *outputPrimTypes,
180 HdSceneIndexObserver::DirtiedPrimEntries *outputDirtiedPrims);
181
182protected:
183 HDGP_API
184 const SdfPath &_GetProceduralPrimPath();
185
186private:
187 const SdfPath _proceduralPrimPath;
188};
189
190PXR_NAMESPACE_CLOSE_SCOPE
191
192#endif
Represents an object that can identify the location of a data source.
HdGpGenerativeProcedural is the base class for procedurals which have full access to an input scene i...
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:92
Small struct representing a 'prim' in the Hydra scene index.
Definition: sceneIndex.h:35