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