All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
kernelBatchDispatcher.h
Go to the documentation of this file.
1 //
2 // Copyright 2013 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 
25 #ifndef FAR_KERNELBATCH_DISPATCHER_H
26 #define FAR_KERNELBATCH_DISPATCHER_H
27 
28 #include "../version.h"
29 
30 #include "../far/kernelBatch.h"
31 #include "../far/stencilTables.h"
32 
33 #include <cassert>
34 
35 namespace OpenSubdiv {
36 namespace OPENSUBDIV_VERSION {
37 
38 namespace Far {
39 
55 public:
56 
69  template <class CONTROLLER, class CONTEXT> static void Apply(
70  CONTROLLER *controller, CONTEXT *context, KernelBatchVector const & batches, int maxlevel);
71 
72 protected:
73 
83  template <class CONTROLLER, class CONTEXT> static bool ApplyKernel(
84  CONTROLLER *controller, CONTEXT *context, KernelBatch const &batch);
85 
86 };
87 
94 public:
95 
96  template <class CONTEXT> void ApplyStencilTableKernel(
97  KernelBatch const &batch, CONTEXT *context) const;
98 
99 };
100 
101 
102 // Launches the processing of a kernel batch
103 template <class CONTROLLER, class CONTEXT> bool
104 KernelBatchDispatcher::ApplyKernel(CONTROLLER *controller, CONTEXT *context,
105  KernelBatch const &batch) {
106 
107  if (batch.end==0) {
108  return true;
109  }
110 
111  switch(batch.kernelType) {
112 
114  assert(0);
115 
117  controller->ApplyStencilTableKernel(batch, context);
118  break;
119 
120  default: // user defined kernel type
121  return false;
122  }
123 
124  return true;
125 }
126 
127 // Launches the processing of a vector of kernel batches
128 template <class CONTROLLER, class CONTEXT> void
129 KernelBatchDispatcher::Apply(CONTROLLER *controller, CONTEXT *context,
130  KernelBatchVector const & batches, int maxlevel) {
131 
132  for (int i = 0; i < (int)batches.size(); ++i) {
133 
134  const KernelBatch &batch = batches[i];
135 
136  if (maxlevel>=0 and batch.level>=maxlevel) {
137  continue;
138  }
139 
140  ApplyKernel(controller, context, batch);
141  }
142 }
143 
144 template <class CONTEXT> void
146  KernelBatch const &batch, CONTEXT *context) const {
147 
148  StencilTables const * stencilTables = context->GetStencilTables();
149  assert(stencilTables);
150 
151  typename CONTEXT::VertexType *vsrc = &context->GetVertices().at(0),
152  *vdst = vsrc + batch.start + stencilTables->GetNumControlVertices();
153 
154  stencilTables->UpdateValues(vsrc, vdst, batch.start, batch.end);
155 }
156 
157 } // end namespace Far
158 
159 } // end namespace OPENSUBDIV_VERSION
160 using namespace OPENSUBDIV_VERSION;
161 
162 } // end namespace OpenSubdiv
163 
164 #endif /* FAR_KERNELBATCH_DISPATCHER_H */
165 
static bool ApplyKernel(CONTROLLER *controller, CONTEXT *context, KernelBatch const &batch)
Launches the processing of a kernel batch returns true if the batch is handled, otherwise returns fal...
A GP Compute Kernel descriptor.
Definition: kernelBatch.h:44
std::vector< KernelBatch > KernelBatchVector
Definition: kernelBatch.h:73
void UpdateValues(T const *controlValues, T *values, int start=-1, int end=-1) const
Updates point values based on the control values.
void ApplyStencilTableKernel(KernelBatch const &batch, CONTEXT *context) const
static void Apply(CONTROLLER *controller, CONTEXT *context, KernelBatchVector const &batches, int maxlevel)
Launches the processing of a vector of kernel batches this is a convenient API for controllers which ...
Subdivision refinement encapsulation layer.