All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
quadrangulate.h
1 //
2 // Copyright 2016 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 HDST_QUADRANGULATE_H
25 #define HDST_QUADRANGULATE_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/version.h"
29 #include "pxr/imaging/hd/bufferSource.h"
30 #include "pxr/imaging/hd/computation.h"
31 #include "pxr/imaging/hd/perfLog.h"
32 #include "pxr/imaging/hd/tokens.h"
33 
34 #include "pxr/base/vt/array.h"
35 #include "pxr/base/tf/token.h"
36 #include "pxr/usd/sdf/path.h"
37 
38 #include <boost/shared_ptr.hpp>
39 
40 PXR_NAMESPACE_OPEN_SCOPE
41 
42 
43 typedef boost::shared_ptr<class HdSt_QuadInfoBuilderComputation>
44  HdSt_QuadInfoBuilderComputationSharedPtr;
45 
46 class HdSt_MeshTopology;
47 
48 /*
49  Computation classes for quadrangulation.
50 
51  *CPU quadrangulation
52 
53  (buffersource)
54  QuadIndexBuilderComputation (quad indices)
55  |
56  +--QuadrangulateComputation (primvar quadrangulation)
57 
58  note: QuadrangulateComputation also copies the original primvars.
59  no need to transfer the original primvars to GPU separately.
60 
61  +--------------------+
62  CPU | original primvars |
63  +--------------------+
64  |
65  v
66  +--------------------+-------------------------+
67  CPU | original primvars | quadrangulated primvars |
68  +--------------------+-------------------------+
69  <---------------------------------------------->
70  filled by computation
71  |
72  v
73  GPU
74 
75  *GPU quadrangulation
76 
77  (buffersource)
78  QuadIndexBuilderComputation (quad indices)
79  |
80  +--QuadrangulateTableComputation (quadrangulate table on GPU)
81 
82  (computation)
83  QuadrangulateComputationGPU (primvar quadrangulation)
84 
85  note: QuadrangulateComputationGPU just fills quadrangulated primvars.
86  the original primvars has to be transfered before the computation.
87 
88  +--------------------+
89  CPU | original primvars |
90  +--------------------+
91  |
92  v
93  GPU
94  |
95  v
96  +--------------------+-------------------------+
97  GPU | original primvars | quadrangulated primvars |
98  +--------------------+-------------------------+
99  <------------------------->
100  filled by computation
101 
102  *Computation dependencies
103 
104  Topology ---> QuadInfo ---> QuadIndices
105  ---> QuadrangulateComputation(CPU)
106  ---> QuadrangulateTable --->
107  ----------------------------> QuadrangulateComputationGPU
108  */
109 
114 class HdSt_QuadInfoBuilderComputation : public HdNullBufferSource {
115 public:
116  HdSt_QuadInfoBuilderComputation(HdSt_MeshTopology *topology, SdfPath const &id);
117  virtual bool Resolve() override;
118 
119 protected:
120  virtual bool _CheckValid() const override;
121 
122 private:
123  SdfPath const _id;
124  HdSt_MeshTopology *_topology;
125 };
126 
131 
132 // Index quadrangulation generates a mapping from triangle ID to authored
133 // face index domain, called primitiveParams. The primitive params are
134 // stored alongisde topology index buffers, so that the same aggregation
135 // locators can be used for such an additional buffer as well. This change
136 // transforms index buffer from int array to int[3] array or int[4] array at
137 // first. Thanks to the heterogenius non-interleaved buffer aggregation ability
138 // in hd, we'll get this kind of buffer layout:
139 //
140 // ----+-----------+-----------+------
141 // ... |i0 i1 i2 i3|i4 i5 i6 i7| ... index buffer (for quads)
142 // ----+-----------+-----------+------
143 // ... | m0 | m1 | ... primitive param buffer (coarse face index)
144 // ----+-----------+-----------+------
145 
146 class HdSt_QuadIndexBuilderComputation : public HdComputedBufferSource {
147 public:
148  HdSt_QuadIndexBuilderComputation(
149  HdSt_MeshTopology *topology,
150  HdSt_QuadInfoBuilderComputationSharedPtr const &quadInfoBuilder,
151  SdfPath const &id);
152  virtual void GetBufferSpecs(HdBufferSpecVector *specs) const override;
153  virtual bool Resolve() override;
154 
155  virtual bool HasChainedBuffer() const override;
156  virtual HdBufferSourceVector GetChainedBuffers() const override;
157 
158 protected:
159  virtual bool _CheckValid() const override;
160 
161 private:
162  SdfPath const _id;
163  HdSt_MeshTopology *_topology;
164  HdSt_QuadInfoBuilderComputationSharedPtr _quadInfoBuilder;
165  HdBufferSourceSharedPtr _primitiveParam;
166  HdBufferSourceSharedPtr _quadsEdgeIndices;
167 };
168 
173 class HdSt_QuadrangulateTableComputation : public HdComputedBufferSource {
174 public:
175  HdSt_QuadrangulateTableComputation(
176  HdSt_MeshTopology *topology,
177  HdBufferSourceSharedPtr const &quadInfoBuilder);
178  virtual void GetBufferSpecs(HdBufferSpecVector *specs) const override;
179  virtual bool Resolve() override;
180 
181 protected:
182  virtual bool _CheckValid() const override;
183 
184 private:
185  SdfPath const _id;
186  HdSt_MeshTopology *_topology;
187  HdBufferSourceSharedPtr _quadInfoBuilder;
188 };
189 
194 class HdSt_QuadrangulateComputation : public HdComputedBufferSource {
195 public:
196  HdSt_QuadrangulateComputation(HdSt_MeshTopology *topology,
197  HdBufferSourceSharedPtr const &source,
198  HdBufferSourceSharedPtr const &quadInfoBuilder,
199  SdfPath const &id);
200  virtual void GetBufferSpecs(HdBufferSpecVector *specs) const override;
201  virtual bool Resolve() override;
202  virtual HdTupleType GetTupleType() const override;
203 
204  virtual bool HasPreChainedBuffer() const override;
205  virtual HdBufferSourceSharedPtr GetPreChainedBuffer() const override;
206 
207 
208 protected:
209  virtual bool _CheckValid() const override;
210 
211 private:
212  SdfPath const _id;
213  HdSt_MeshTopology *_topology;
214  HdBufferSourceSharedPtr _source;
215  HdBufferSourceSharedPtr _quadInfoBuilder;
216 };
217 
222 class HdSt_QuadrangulateFaceVaryingComputation : public HdComputedBufferSource {
223 public:
224  HdSt_QuadrangulateFaceVaryingComputation(HdSt_MeshTopology *topolgoy,
225  HdBufferSourceSharedPtr const &source,
226  SdfPath const &id);
227 
228  virtual void GetBufferSpecs(HdBufferSpecVector *specs) const override;
229  virtual bool Resolve() override;
230 
231 protected:
232  virtual bool _CheckValid() const override;
233 
234 private:
235  SdfPath const _id;
236  HdSt_MeshTopology *_topology;
237  HdBufferSourceSharedPtr _source;
238 };
239 
244 class HdSt_QuadrangulateComputationGPU : public HdComputation {
245 public:
247  HdSt_QuadrangulateComputationGPU(HdSt_MeshTopology *topology,
248  TfToken const &sourceName,
249  HdType dataType,
250  SdfPath const &id);
251  virtual void Execute(HdBufferArrayRangeSharedPtr const &range,
252  HdResourceRegistry *resourceRegistry) override;
253  virtual void GetBufferSpecs(HdBufferSpecVector *specs) const override;
254  virtual int GetNumOutputElements() const override;
255 
256 private:
257  SdfPath const _id;
258  HdSt_MeshTopology *_topology;
259  TfToken _name;
260  HdType _dataType;
261 };
262 
263 
264 
265 PXR_NAMESPACE_CLOSE_SCOPE
266 
267 #endif // HDST_QUADRANGULATE_H
virtual int GetNumOutputElements() const =0
Returns the size of its destination buffer (located by range argument of Execute()).
virtual void GetBufferSpecs(HdBufferSpecVector *specs) const =0
Add the buffer spec for this buffer source into given bufferspec vector.
HdTupleType represents zero, one, or more values of the same HdType.
Definition: types.h:239
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
virtual HD_API HdBufferSourceSharedPtr GetPreChainedBuffer() const
Returns the pre-chained buffer.
A abstract base class for pure cpu computation.
Definition: bufferSource.h:235
virtual HD_API bool HasPreChainedBuffer() const
Returns true if this buffer has a pre-chained buffer.
A central registry of all GPU resources.
virtual bool _CheckValid() const =0
Checks the validity of the source buffer.
virtual HD_API bool HasChainedBuffer() const
Returns true if this buffer has any chained buffer(s)
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
virtual void Execute(HdBufferArrayRangeSharedPtr const &range, HdResourceRegistry *resourceRegistry)=0
Execute computation.
An interface class for GPU computation.
Definition: computation.h:50
virtual HD_API HdBufferSourceVector GetChainedBuffers() const
Returns the vector of chained buffers.
virtual HD_API HdTupleType GetTupleType() const override
Returns the data type and count (array size) for this buffer source.
virtual void GetBufferSpecs(HdBufferSpecVector *specs) const =0
Add the buffer spec for this computation into given bufferspec vector.
virtual bool Resolve()=0
Prepare the access of GetData().
A abstract base class for cpu computation followed by buffer transfer to the GPU. ...
Definition: bufferSource.h:210