HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
generativeProcedural.h
Go to the documentation of this file.
1 //
2 // Copyright 2022 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_IMAGING_HD_GP_GENERATIVE_PROCEDURAL_H
25 #define PXR_IMAGING_HD_GP_GENERATIVE_PROCEDURAL_H
26 
27 #include "pxr/imaging/hdGp/api.h"
30 
32 
33 #define HDGPGENERATIVEPROCEDURAL_TOKENS \
34  ((generativeProcedural, "hydraGenerativeProcedural")) \
35  ((proceduralType, "hdGp:proceduralType")) \
36 
37 TF_DECLARE_PUBLIC_TOKENS(HdGpGenerativeProceduralTokens,
39 
40 /// \class HdGpGenerativeProcedural
41 ///
42 /// HdGpGenerativeProcedural is the base class for procedurals which have
43 /// full access to an input scene in order to create and update a hierarchy
44 /// of child prims within a hydra scene index.
45 ///
46 /// They are registered for use via a corresponding
47 /// HdGpGenerativeProceduralPlugin.
48 ///
50 {
51 public:
52  HDGP_API
53  HdGpGenerativeProcedural(const SdfPath &proceduralPrimPath);
54 
55  HDGP_API
56  virtual ~HdGpGenerativeProcedural();
57 
58  using DependencyMap =
60 
61  using ChildPrimTypeMap =
63 
64  // Given access to the input scene (specifically the primvars serving as
65  // arguments on the procedural's own prim), return what other data sources
66  // of what other prims we depend upon and should be given the opportunity
67  // to update in response their changes.
68  //
69  // For a single instance, UpdateDependencies will not be called from
70  // multiple threads -- nor concurrent to Update
72  const HdSceneIndexBaseRefPtr &inputScene) = 0;
73 
74  // This is the primary "cook" method called when a procedural is initially
75  // resolved or invalidated. The result is a map of child prim paths and
76  // their hydra scene prim types. Because a cook/recook can add, remove or
77  // dirty child prims, the returned ChildPrimTypeMap must always contain
78  // the full set of child prims. It is interpreted in this way:
79  // 1) Prims which did not exist in the result of
80  // of previous calls to this method will be added.
81  // 2) Prims which existed in the results of previous calls but not in this
82  // result will be removed.
83  // 3) Prims whose type has changed between calls to this method will be
84  // re-added.
85  //
86  // Prims which exist in both (and have not changed type) are not considered
87  // dirty unless added to the outputDirtiedPrims vector. Because each entry
88  // in that vector contains an HdDataSourceLocatorSet, invalidation can be
89  // as broad or specific as possible. In order to reduce the amount of
90  // bookkeeping for the procedural itself, previousResult contains the
91  // result of the previous call to this method.
92  //
93  // dirtiedDependencies contains the prim paths and locator sets of
94  // declared dependencies which have been dirtied since the last cook. For
95  // initial cooks (and in response to things like removal of prims previously
96  // dependeded upon), the full set of declared dependencies is sent here. A
97  // procedural may choose to cache values previously queried from the input
98  // scene and invalidate based on the contents of dirtiedDependencies.
99  //
100  // NOTE: For initial cooks, changes to the procedural's own prim will not
101  // be included within dirtiedDependencies. (TODO: reconsider this.)
102  //
103  // ALSO NOTE: Because this method is responsible only for describing the
104  // presence and type (and potential dirtiness) of its child
105  // prims -- and not the data sources for those prims -- it may
106  // choose to defer some computation of values to happen within
107  // data sources returned by GetChildPrim.
108  //
109  // For a single instance, Update will not be called from
110  // multiple threads -- nor concurrent to UpdateDependencies
111  virtual ChildPrimTypeMap Update(
112  const HdSceneIndexBaseRefPtr &inputScene,
113  const ChildPrimTypeMap &previousResult,
114  const DependencyMap &dirtiedDependencies,
115  HdSceneIndexObserver::DirtiedPrimEntries *outputDirtiedPrims) = 0;
116 
117  // Returns the type and prim-level data source for a child prim previously
118  // added or invalidated from the Update method.
119  //
120  // This should expect to be called from multiple threads
122  const HdSceneIndexBaseRefPtr &inputScene,
123  const SdfPath &childPrimPath) = 0;
124 
125  // Returns a locator which can be used in the UpdateDependencies result to
126  // declare a dependency on the set of immediate children for a prim path.
128 
129 
130  // ------------------------------------------------------------------------
131  // Asynchronous API
132  // ------------------------------------------------------------------------
133 
134  // Called to inform a procedural instance whether asychronous evaluation
135  // is possible.
136  //
137  // If asyncEnabled is true, a procedural which makes use of asynchronous
138  // processing should return true to indicate that it wants to receive
139  // AsyncUpdate calls. If asyncEnabled is false, the procedural is expected
140  // to do its work as normal.
141  //
142  // Procedurals which have previously declined async updates (or have
143  // indicated that they are finished via a return value from AsyncUpdate)
144  // are given an opportunity begin asynchronous processing (via receiving
145  // another call to this method) following any call to UpdateDependencies.
146  virtual bool AsyncBegin(bool asyncEnabled);
147 
148 
150  {
151  Continuing = 0, // nothing new, continue checking
152  Finished, // nothing new, stop checking
153  ContinuingWithNewChanges, // new stuff, but continue checking
154  FinishedWithNewChanges, // new stuff, but stop checking
155  };
156 
157  // When asynchronous evaluation is enabled, a procedural will be polled (
158  // at a frequency determined by the host application) to discover any
159  // changes to child prim state.
160  //
161  // This is similar to the standard Update call but differs in these ways:
162  // 1) The input scene is not provided. Any information needed from it for
163  // the sake of asychronous processing should be retrieved during the
164  // standard Update call.
165  // 2) Filling in the provided outputPrimTypes is equivalent to the return
166  // value of the standard Update. If no child prim presence or type
167  // changes (or dirtying) are available, no action is required.
168  // 3) It should not be used to do significant work but rather just to
169  // synchronize the results of work completed by threads or processes
170  // managed by the procedural.
171  //
172  // Changes are only considered following a return value of
173  // ContinuingWithNewChanges or FinishedWithNewChanges. In that case,
174  // outputPrimTypes must be filled in full (similar to the result of standard
175  // Update). As with Update, the previous child prim type map is provided
176  // for convenience.
177  //
178  // Return values of Finished or FinishedWithNewChanges will prevent this
179  // method from being called again until another call to AsyncBegin(true)
180  // returns a true value. This allows a procedural to indicate when it is
181  // finished and then restarted itself in response to declared dependenices
182  // changing. Should a procedural wish to continue receiving the AsyncUpdate
183  // call regardless of whether declared dependencies are dirtied, it should
184  // return Continuing or ContinuingWithNewChanges;
185  virtual AsyncState AsyncUpdate(
186  const ChildPrimTypeMap &previousResult,
187  ChildPrimTypeMap *outputPrimTypes,
188  HdSceneIndexObserver::DirtiedPrimEntries *outputDirtiedPrims);
189 
190 
191 
192 protected:
193  HDGP_API
195 
196 private:
197  const SdfPath _proceduralPrimPath;
198 };
199 
201 
202 #endif
#define HDGP_API
Definition: api.h:40
virtual HDGP_API ~HdGpGenerativeProcedural()
#define HDGPGENERATIVEPROCEDURAL_TOKENS
TF_DECLARE_PUBLIC_TOKENS(HdGpGenerativeProceduralTokens, HDGPGENERATIVEPROCEDURAL_TOKENS)
HDGP_API HdGpGenerativeProcedural(const SdfPath &proceduralPrimPath)
virtual HdSceneIndexPrim GetChildPrim(const HdSceneIndexBaseRefPtr &inputScene, const SdfPath &childPrimPath)=0
virtual ChildPrimTypeMap Update(const HdSceneIndexBaseRefPtr &inputScene, const ChildPrimTypeMap &previousResult, const DependencyMap &dirtiedDependencies, HdSceneIndexObserver::DirtiedPrimEntries *outputDirtiedPrims)=0
Definition: path.h:290
static const HdDataSourceLocator & GetChildNamesDependencyKey()
virtual DependencyMap UpdateDependencies(const HdSceneIndexBaseRefPtr &inputScene)=0
TfDenseHashMap< SdfPath, TfToken, TfHash > ChildPrimTypeMap
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
virtual AsyncState AsyncUpdate(const ChildPrimTypeMap &previousResult, ChildPrimTypeMap *outputPrimTypes, HdSceneIndexObserver::DirtiedPrimEntries *outputDirtiedPrims)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
virtual bool AsyncBegin(bool asyncEnabled)
HDGP_API const SdfPath & _GetProceduralPrimPath()