| OpenSubdiv

Loading...
Searching...
No Matches
d3d11ComputeEvaluator.h
Go to the documentation of this file.
1//
2// Copyright 2015 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://opensubdiv.org/license.
6//
7
8#ifndef OPENSUBDIV3_OSD_D3D11_COMPUTE_EVALUATOR_H
9#define OPENSUBDIV3_OSD_D3D11_COMPUTE_EVALUATOR_H
10
11#include "../version.h"
12
13 struct ID3D11DeviceContext;
14 struct ID3D11Buffer;
15 struct ID3D11ComputeShader;
16 struct ID3D11ClassLinkage;
17 struct ID3D11ClassInstance;
18 struct ID3D11ShaderResourceView;
19 struct ID3D11UnorderedAccessView;
20
21#include "../osd/bufferDescriptor.h"
22
23 namespace OpenSubdiv {
24 namespace OPENSUBDIV_VERSION {
25
26 namespace Far {
27 class StencilTable;
28}
29
30 namespace Osd {
31
39 class D3D11StencilTable {
40 public:
41 template <typename DEVICE_CONTEXT>
42 static D3D11StencilTable *Create(Far::StencilTable const *stencilTable,
43 DEVICE_CONTEXT context) {
44 return new D3D11StencilTable(stencilTable, context->GetDeviceContext());
45 }
46
47 static D3D11StencilTable *Create(Far::StencilTable const *stencilTable,
48 ID3D11DeviceContext *deviceContext) {
49 return new D3D11StencilTable(stencilTable, deviceContext);
50 }
51
52 D3D11StencilTable(Far::StencilTable const *stencilTable,
53 ID3D11DeviceContext *deviceContext);
54
55 ~D3D11StencilTable();
56
57 // interfaces needed for D3D11ComputeEvaluator
58 ID3D11ShaderResourceView *GetSizesSRV() const { return _sizes; }
59 ID3D11ShaderResourceView *GetOffsetsSRV() const { return _offsets; }
60 ID3D11ShaderResourceView *GetIndicesSRV() const { return _indices; }
61 ID3D11ShaderResourceView *GetWeightsSRV() const { return _weights; }
62 int GetNumStencils() const { return _numStencils; }
63
64 private:
65 ID3D11ShaderResourceView *_sizes;
66 ID3D11ShaderResourceView *_offsets;
67 ID3D11ShaderResourceView *_indices;
68 ID3D11ShaderResourceView *_weights;
69 ID3D11Buffer *_sizesBuffer;
70 ID3D11Buffer *_offsetsBuffer;
71 ID3D11Buffer *_indicesBuffer;
72 ID3D11Buffer *_weightsBuffer;
73
74 int _numStencils;
75};
76
77// ---------------------------------------------------------------------------
78
79 class D3D11ComputeEvaluator {
80 public:
81 using Instantiatable = bool; // Enable compiled kernel evaluator cache
82
83 static D3D11ComputeEvaluator * Create(BufferDescriptor const &srcDesc,
84 BufferDescriptor const &dstDesc,
85 BufferDescriptor const &duDesc,
86 BufferDescriptor const &dvDesc,
87 ID3D11DeviceContext *deviceContext);
88
89 static D3D11ComputeEvaluator * Create(BufferDescriptor const &srcDesc,
90 BufferDescriptor const &dstDesc,
91 BufferDescriptor const &duDesc,
92 BufferDescriptor const &dvDesc,
93 BufferDescriptor const &duuDesc,
94 BufferDescriptor const &duvDesc,
95 BufferDescriptor const &dvvDesc,
96 ID3D11DeviceContext *deviceContext);
97
99 D3D11ComputeEvaluator();
100
102 ~D3D11ComputeEvaluator();
103
131 template <typename SRC_BUFFER, typename DST_BUFFER, typename STENCIL_TABLE>
132 static bool EvalStencils(
133 SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc,
134 DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc,
135 STENCIL_TABLE const *stencilTable,
136 D3D11ComputeEvaluator const *instance,
137 ID3D11DeviceContext * deviceContext) {
138 if (instance) {
139 return instance->EvalStencils(srcBuffer, srcDesc,
140 dstBuffer, dstDesc,
141 stencilTable,
142 deviceContext);
143 } else {
144 // Create an instance on demand (slow)
145 (void)deviceContext; // unused
146 instance = Create(srcDesc, dstDesc,
147 BufferDescriptor(),
148 BufferDescriptor(),
149 deviceContext);
150 if (instance) {
151 bool r = instance->EvalStencils(srcBuffer, srcDesc,
152 dstBuffer, dstDesc,
153 stencilTable,
154 deviceContext);
155 delete instance;
156 return r;
157 }
158 return false;
159 }
160 }
161
164 template <typename SRC_BUFFER, typename DST_BUFFER, typename STENCIL_TABLE>
165 bool EvalStencils(
166 SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc,
167 DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc,
168 STENCIL_TABLE const *stencilTable,
169 ID3D11DeviceContext *deviceContext) const {
170 return EvalStencils(srcBuffer->BindD3D11UAV(deviceContext), srcDesc,
171 dstBuffer->BindD3D11UAV(deviceContext), dstDesc,
172 stencilTable->GetSizesSRV(),
173 stencilTable->GetOffsetsSRV(),
174 stencilTable->GetIndicesSRV(),
175 stencilTable->GetWeightsSRV(),
176 /* start = */ 0,
177 /* end = */ stencilTable->GetNumStencils(),
178 deviceContext);
179 }
180
183 bool EvalStencils(ID3D11UnorderedAccessView *srcSRV,
184 BufferDescriptor const &srcDesc,
185 ID3D11UnorderedAccessView *dstUAV,
186 BufferDescriptor const &dstDesc,
187 ID3D11ShaderResourceView *sizesSRV,
188 ID3D11ShaderResourceView *offsetsSRV,
189 ID3D11ShaderResourceView *indicesSRV,
190 ID3D11ShaderResourceView *weightsSRV,
191 int start,
192 int end,
193 ID3D11DeviceContext *deviceContext) const;
194
196 bool Compile(BufferDescriptor const &srcDesc,
197 BufferDescriptor const &dstDesc,
198 ID3D11DeviceContext *deviceContext);
199
201 static void Synchronize(ID3D11DeviceContext *deviceContext);
202
203 private:
204 ID3D11ComputeShader * _computeShader;
205 ID3D11ClassLinkage * _classLinkage;
206 ID3D11ClassInstance * _singleBufferKernel;
207 ID3D11ClassInstance * _separateBufferKernel;
208 ID3D11Buffer * _uniformArgs; // uniform parameters for kernels
209
210 int _workGroupSize;
211};
212
213} // end namespace Osd
214
215} // end namespace OPENSUBDIV_VERSION
216 using namespace OPENSUBDIV_VERSION;
217
218} // end namespace OpenSubdiv
219
220
221#endif // OPENSUBDIV3_OSD_D3D11_COMPUTE_EVALUATOR_H
bufferDescriptor.h
OpenSubdiv
Definition limits.h:15
OpenSubdiv::OPENSUBDIV_VERSION
Definition limits.h:16
OpenSubdiv::OPENSUBDIV_VERSION::Far
Definition refinerSurfaceFactory.h:19
OpenSubdiv::OPENSUBDIV_VERSION::Osd
Definition bufferDescriptor.h:17
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTable
Stencil table class wrapping the template for compatibility.
Definition stencilTable.h:256
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor
BufferDescriptor is a struct which describes buffer elements in interleaved data buffers....
Definition bufferDescriptor.h:44
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11StencilTable::Create
static D3D11StencilTable * Create(Far::StencilTable const *stencilTable, DEVICE_CONTEXT context)
Definition d3d11ComputeEvaluator.h:42
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11StencilTable::GetOffsetsSRV
ID3D11ShaderResourceView * GetOffsetsSRV() const
Definition d3d11ComputeEvaluator.h:59
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11StencilTable::GetNumStencils
int GetNumStencils() const
Definition d3d11ComputeEvaluator.h:62
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11StencilTable::GetIndicesSRV
ID3D11ShaderResourceView * GetIndicesSRV() const
Definition d3d11ComputeEvaluator.h:60
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:47
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11StencilTable::GetSizesSRV
ID3D11ShaderResourceView * GetSizesSRV() const
Definition d3d11ComputeEvaluator.h:58
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11StencilTable::GetWeightsSRV
ID3D11ShaderResourceView * GetWeightsSRV() const
Definition d3d11ComputeEvaluator.h:61
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:132
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::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:165
OpenSubdiv::OPENSUBDIV_VERSION::Osd::D3D11ComputeEvaluator::Instantiatable
bool Instantiatable
Definition d3d11ComputeEvaluator.h:81
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