OpenSubdiv: opensubdiv/osd/d3d11ComputeEvaluator.h Source File

| OpenSubdiv

Loading...
Searching...
No Matches
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
30struct ID3D11DeviceContext;
31struct ID3D11Buffer;
32struct ID3D11ComputeShader;
33struct ID3D11ClassLinkage;
34struct ID3D11ClassInstance;
35struct ID3D11ShaderResourceView;
36struct ID3D11UnorderedAccessView;
37
38#include "../osd/bufferDescriptor.h"
39
40namespace OpenSubdiv {
41namespace OPENSUBDIV_VERSION {
42
43namespace Far {
44 class StencilTable;
45}
46
47namespace Osd {
48
56 class D3D11StencilTable {
57public:
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
81private:
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 {
97public:
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
105 static D3D11ComputeEvaluator * Create(BufferDescriptor const &srcDesc,
106 BufferDescriptor const &dstDesc,
107 BufferDescriptor const &duDesc,
108 BufferDescriptor const &dvDesc,
109 BufferDescriptor const &duuDesc,
110 BufferDescriptor const &duvDesc,
111 BufferDescriptor const &dvvDesc,
112 ID3D11DeviceContext *deviceContext);
113
115 D3D11ComputeEvaluator();
116
118 ~D3D11ComputeEvaluator();
119
147 template <typename SRC_BUFFER, typename DST_BUFFER, typename STENCIL_TABLE>
148 static bool EvalStencils(
149 SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc,
150 DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc,
151 STENCIL_TABLE const *stencilTable,
152 D3D11ComputeEvaluator const *instance,
153 ID3D11DeviceContext * deviceContext) {
154 if (instance) {
155 return instance->EvalStencils(srcBuffer, srcDesc,
156 dstBuffer, dstDesc,
157 stencilTable,
158 deviceContext);
159 } else {
160 // Create an instance on demand (slow)
161 (void)deviceContext; // unused
162 instance = Create(srcDesc, dstDesc,
163 BufferDescriptor(),
164 BufferDescriptor(),
165 deviceContext);
166 if (instance) {
167 bool r = instance->EvalStencils(srcBuffer, srcDesc,
168 dstBuffer, dstDesc,
169 stencilTable,
170 deviceContext);
171 delete instance;
172 return r;
173 }
174 return false;
175 }
176 }
177
180 template <typename SRC_BUFFER, typename DST_BUFFER, typename STENCIL_TABLE>
181 bool EvalStencils(
182 SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc,
183 DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc,
184 STENCIL_TABLE const *stencilTable,
185 ID3D11DeviceContext *deviceContext) const {
186 return EvalStencils(srcBuffer->BindD3D11UAV(deviceContext), srcDesc,
187 dstBuffer->BindD3D11UAV(deviceContext), dstDesc,
188 stencilTable->GetSizesSRV(),
189 stencilTable->GetOffsetsSRV(),
190 stencilTable->GetIndicesSRV(),
191 stencilTable->GetWeightsSRV(),
192 /* start = */ 0,
193 /* end = */ stencilTable->GetNumStencils(),
194 deviceContext);
195 }
196
199 bool EvalStencils(ID3D11UnorderedAccessView *srcSRV,
200 BufferDescriptor const &srcDesc,
201 ID3D11UnorderedAccessView *dstUAV,
202 BufferDescriptor const &dstDesc,
203 ID3D11ShaderResourceView *sizesSRV,
204 ID3D11ShaderResourceView *offsetsSRV,
205 ID3D11ShaderResourceView *indicesSRV,
206 ID3D11ShaderResourceView *weightsSRV,
207 int start,
208 int end,
209 ID3D11DeviceContext *deviceContext) const;
210
212 bool Compile(BufferDescriptor const &srcDesc,
213 BufferDescriptor const &dstDesc,
214 ID3D11DeviceContext *deviceContext);
215
217 static void Synchronize(ID3D11DeviceContext *deviceContext);
218
219private:
220 ID3D11ComputeShader * _computeShader;
221 ID3D11ClassLinkage * _classLinkage;
222 ID3D11ClassInstance * _singleBufferKernel;
223 ID3D11ClassInstance * _separateBufferKernel;
224 ID3D11Buffer * _uniformArgs; // uniform parameters for kernels
225
226 int _workGroupSize;
227};
228
229} // end namespace Osd
230
231} // end namespace OPENSUBDIV_VERSION
232using namespace OPENSUBDIV_VERSION;
233
234} // end namespace OpenSubdiv
235
236
237#endif // OPENSUBDIV3_OSD_D3D11_COMPUTE_EVALUATOR_H
bufferDescriptor.h
OpenSubdiv
Definition limits.h:32
OpenSubdiv::OPENSUBDIV_VERSION
Definition limits.h:33
OpenSubdiv::OPENSUBDIV_VERSION::Far
Definition refinerSurfaceFactory.h:36
OpenSubdiv::OPENSUBDIV_VERSION::Osd
Definition bufferDescriptor.h:34
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTable
Stencil table class wrapping the template for compatibility.
Definition stencilTable.h:273
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor
BufferDescriptor is a struct which describes buffer elements in interleaved data buffers....
Definition bufferDescriptor.h:61
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11StencilTable::Create
static D3D11StencilTable * Create(Far::StencilTable const *stencilTable, DEVICE_CONTEXT context)
Definition d3d11ComputeEvaluator.h:59
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11StencilTable::GetOffsetsSRV
ID3D11ShaderResourceView * GetOffsetsSRV() const
Definition d3d11ComputeEvaluator.h:76
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11StencilTable::GetNumStencils
int GetNumStencils() const
Definition d3d11ComputeEvaluator.h:79
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11StencilTable::GetIndicesSRV
ID3D11ShaderResourceView * GetIndicesSRV() const
Definition d3d11ComputeEvaluator.h:77
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11StencilTable::~D3D11StencilTable
~D3D11StencilTable()
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11StencilTable::D3D11StencilTable
D3D11StencilTable(Far::StencilTable const *stencilTable, ID3D11DeviceContext *deviceContext)
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11StencilTable::Create
static D3D11StencilTable * Create(Far::StencilTable const *stencilTable, ID3D11DeviceContext *deviceContext)
Definition d3d11ComputeEvaluator.h:64
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11StencilTable::GetSizesSRV
ID3D11ShaderResourceView * GetSizesSRV() const
Definition d3d11ComputeEvaluator.h:75
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11StencilTable::GetWeightsSRV
ID3D11ShaderResourceView * GetWeightsSRV() const
Definition d3d11ComputeEvaluator.h:78
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::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:148
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11ComputeEvaluator::Create
static D3D11ComputeEvaluator * Create(BufferDescriptor const &srcDesc, BufferDescriptor const &dstDesc, BufferDescriptor const &duDesc, BufferDescriptor const &dvDesc, BufferDescriptor const &duuDesc, BufferDescriptor const &duvDesc, BufferDescriptor const &dvvDesc, ID3D11DeviceContext *deviceContext)
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11ComputeEvaluator::Instantiatable
bool Instantiatable
Definition d3d11ComputeEvaluator.h:98
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11ComputeEvaluator::Synchronize
static void Synchronize(ID3D11DeviceContext *deviceContext)
Wait the dispatched kernel finishes.
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:181
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::D3D11ComputeEvaluator
D3D11ComputeEvaluator()
Constructor.
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11ComputeEvaluator::~D3D11ComputeEvaluator
~D3D11ComputeEvaluator()
Destructor.
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11ComputeEvaluator::EvalStencils
bool EvalStencils(ID3D11UnorderedAccessView *srcSRV, BufferDescriptor const &srcDesc, ID3D11UnorderedAccessView *dstUAV, BufferDescriptor const &dstDesc, ID3D11ShaderResourceView *sizesSRV, ID3D11ShaderResourceView *offsetsSRV, ID3D11ShaderResourceView *indicesSRV, ID3D11ShaderResourceView *weightsSRV, int start, int end, ID3D11DeviceContext *deviceContext) const