opensubdiv/osd/d3d11ComputeEvaluator.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
d3d11ComputeEvaluator.h
Go to the documentation of this file.
1 //
2 // Copyright 2015 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 OPENSUBDIV3_OSD_D3D11_COMPUTE_EVALUATOR_H
26 #define OPENSUBDIV3_OSD_D3D11_COMPUTE_EVALUATOR_H
27
28 #include "../version.h"
29
30 struct ID3D11DeviceContext;
31 struct ID3D11Buffer;
32 struct ID3D11ComputeShader;
33 struct ID3D11ClassLinkage;
34 struct ID3D11ClassInstance;
35 struct ID3D11ShaderResourceView;
36 struct ID3D11UnorderedAccessView;
37
38 #include "../osd/bufferDescriptor.h"
39
40 namespace OpenSubdiv {
41 namespace OPENSUBDIV_VERSION {
42
43 namespace Far {
44 class StencilTable;
45 }
46
47 namespace Osd {
48
56 class D3D11StencilTable {
57 public:
58 template <typename DEVICE_CONTEXT>
59 static D3D11StencilTable *Create(Far::StencilTable const *stencilTable,
60 DEVICE_CONTEXT context) {
61 return new D3D11StencilTable(stencilTable, context->GetDeviceContext());
62 }
63
64 static D3D11StencilTable *Create(Far::StencilTable const *stencilTable,
65 ID3D11DeviceContext *deviceContext) {
66 return new D3D11StencilTable(stencilTable, deviceContext);
67 }
68
69 D3D11StencilTable(Far::StencilTable const *stencilTable,
70 ID3D11DeviceContext *deviceContext);
71
72 ~D3D11StencilTable();
73
74 // interfaces needed for D3D11ComputeEvaluator
75 ID3D11ShaderResourceView *GetSizesSRV() const { return _sizes; }
76 ID3D11ShaderResourceView *GetOffsetsSRV() const { return _offsets; }
77 ID3D11ShaderResourceView *GetIndicesSRV() const { return _indices; }
78 ID3D11ShaderResourceView *GetWeightsSRV() const { return _weights; }
79 int GetNumStencils() const { return _numStencils; }
80
81 private:
82 ID3D11ShaderResourceView *_sizes;
83 ID3D11ShaderResourceView *_offsets;
84 ID3D11ShaderResourceView *_indices;
85 ID3D11ShaderResourceView *_weights;
86 ID3D11Buffer *_sizesBuffer;
87 ID3D11Buffer *_offsetsBuffer;
88 ID3D11Buffer *_indicesBuffer;
89 ID3D11Buffer *_weightsBuffer;
90
91 int _numStencils;
92 };
93
94 // ---------------------------------------------------------------------------
95
96 class D3D11ComputeEvaluator {
97 public:
98 typedef bool Instantiatable;
99 static D3D11ComputeEvaluator * Create(BufferDescriptor const &srcDesc,
100 BufferDescriptor const &dstDesc,
101 BufferDescriptor const &duDesc,
102 BufferDescriptor const &dvDesc,
103 ID3D11DeviceContext *deviceContext);
104
106 D3D11ComputeEvaluator();
107
109 ~D3D11ComputeEvaluator();
110
138 template <typename SRC_BUFFER, typename DST_BUFFER, typename STENCIL_TABLE>
139 static bool EvalStencils(
140 SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc,
141 DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc,
142 STENCIL_TABLE const *stencilTable,
143 D3D11ComputeEvaluator const *instance,
144 ID3D11DeviceContext * deviceContext) {
145 if (instance) {
146 return instance->EvalStencils(srcBuffer, srcDesc,
147 dstBuffer, dstDesc,
148 stencilTable,
149 deviceContext);
150 } else {
151 // Create an instace on demand (slow)
152 (void)deviceContext; // unused
153 instance = Create(srcDesc, dstDesc,
154 BufferDescriptor(),
155 BufferDescriptor(),
156 deviceContext);
157 if (instance) {
158 bool r = instance->EvalStencils(srcBuffer, srcDesc,
159 dstBuffer, dstDesc,
160 stencilTable,
161 deviceContext);
162 delete instance;
163 return r;
164 }
165 return false;
166 }
167 }
168
171 template <typename SRC_BUFFER, typename DST_BUFFER, typename STENCIL_TABLE>
172 bool EvalStencils(
173 SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc,
174 DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc,
175 STENCIL_TABLE const *stencilTable,
176 ID3D11DeviceContext *deviceContext) const {
177 return EvalStencils(srcBuffer->BindD3D11UAV(deviceContext), srcDesc,
178 dstBuffer->BindD3D11UAV(deviceContext), dstDesc,
179 stencilTable->GetSizesSRV(),
180 stencilTable->GetOffsetsSRV(),
181 stencilTable->GetIndicesSRV(),
182 stencilTable->GetWeightsSRV(),
183 /* start = */ 0,
184 /* end = */ stencilTable->GetNumStencils(),
185 deviceContext);
186 }
187
190 bool EvalStencils(ID3D11UnorderedAccessView *srcSRV,
191 BufferDescriptor const &srcDesc,
192 ID3D11UnorderedAccessView *dstUAV,
193 BufferDescriptor const &dstDesc,
194 ID3D11ShaderResourceView *sizesSRV,
195 ID3D11ShaderResourceView *offsetsSRV,
196 ID3D11ShaderResourceView *indicesSRV,
197 ID3D11ShaderResourceView *weightsSRV,
198 int start,
199 int end,
200 ID3D11DeviceContext *deviceContext) const;
201
203 bool Compile(BufferDescriptor const &srcDesc,
204 BufferDescriptor const &dstDesc,
205 ID3D11DeviceContext *deviceContext);
206
208 static void Synchronize(ID3D11DeviceContext *deviceContext);
209
210 private:
211 ID3D11ComputeShader * _computeShader;
212 ID3D11ClassLinkage * _classLinkage;
213 ID3D11ClassInstance * _singleBufferKernel;
214 ID3D11ClassInstance * _separateBufferKernel;
215 ID3D11Buffer * _uniformArgs; // uniform paramaeters for kernels
216
217 int _workGroupSize;
218 };
219
220 } // end namespace Osd
221
222 } // end namespace OPENSUBDIV_VERSION
223 using namespace OPENSUBDIV_VERSION;
224
225 } // end namespace OpenSubdiv
226
227
228 #endif // OPENSUBDIV3_OSD_D3D11_COMPUTE_EVALUATOR_H
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11StencilTable::~D3D11StencilTable
~D3D11StencilTable()
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11ComputeEvaluator
Definition: d3d11ComputeEvaluator.h:96
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor
BufferDescriptor is a struct which describes buffer elements in interleaved data buffers. Almost all Osd Evaluator APIs take BufferDescriptors along with device-specific buffer objects.
Definition: bufferDescriptor.h:61
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11StencilTable::Create
static D3D11StencilTable * Create(Far::StencilTable const *stencilTable, ID3D11DeviceContext *deviceContext)
Definition: d3d11ComputeEvaluator.h:64
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11ComputeEvaluator::EvalStencils
bool EvalStencils(SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc, DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc, STENCIL_TABLE const *stencilTable, ID3D11DeviceContext *deviceContext) const
Definition: d3d11ComputeEvaluator.h:172
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11StencilTable::D3D11StencilTable
D3D11StencilTable(Far::StencilTable const *stencilTable, ID3D11DeviceContext *deviceContext)
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11ComputeEvaluator::Create
static D3D11ComputeEvaluator * Create(BufferDescriptor const &srcDesc, BufferDescriptor const &dstDesc, BufferDescriptor const &duDesc, BufferDescriptor const &dvDesc, ID3D11DeviceContext *deviceContext)
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11StencilTable::GetWeightsSRV
ID3D11ShaderResourceView * GetWeightsSRV() const
Definition: d3d11ComputeEvaluator.h:78
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11StencilTable::GetNumStencils
int GetNumStencils() const
Definition: d3d11ComputeEvaluator.h:79
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTable
Table of subdivision stencils.
Definition: stencilTable.h:125
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11StencilTable::GetOffsetsSRV
ID3D11ShaderResourceView * GetOffsetsSRV() const
Definition: d3d11ComputeEvaluator.h:76
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11ComputeEvaluator::Synchronize
static void Synchronize(ID3D11DeviceContext *deviceContext)
Wait the dispatched kernel finishes.
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11ComputeEvaluator::D3D11ComputeEvaluator
D3D11ComputeEvaluator()
Constructor.
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11StencilTable
D3D11 stencil table.
Definition: d3d11ComputeEvaluator.h:56
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11ComputeEvaluator::Instantiatable
bool Instantiatable
Definition: d3d11ComputeEvaluator.h:98
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11StencilTable::GetSizesSRV
ID3D11ShaderResourceView * GetSizesSRV() const
Definition: d3d11ComputeEvaluator.h:75
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11StencilTable::GetIndicesSRV
ID3D11ShaderResourceView * GetIndicesSRV() const
Definition: d3d11ComputeEvaluator.h:77
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11StencilTable::Create
static D3D11StencilTable * Create(Far::StencilTable const *stencilTable, DEVICE_CONTEXT context)
Definition: d3d11ComputeEvaluator.h:59
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11ComputeEvaluator::Compile
bool Compile(BufferDescriptor const &srcDesc, BufferDescriptor const &dstDesc, ID3D11DeviceContext *deviceContext)
Configure DX kernel. Returns false if it fails to compile the kernel.
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11ComputeEvaluator::EvalStencils
static bool EvalStencils(SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc, DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc, STENCIL_TABLE const *stencilTable, D3D11ComputeEvaluator const *instance, ID3D11DeviceContext *deviceContext)
Generic static compute function. This function has a same signature as other device kernels have so t...
Definition: d3d11ComputeEvaluator.h:139
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11ComputeEvaluator::~D3D11ComputeEvaluator
~D3D11ComputeEvaluator()
Destructor.