forked from AcademySoftwareFoundation/OpenShadingLanguage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatched_rendservices.cpp
More file actions
352 lines (290 loc) · 12.1 KB
/
Copy pathbatched_rendservices.cpp
File metadata and controls
352 lines (290 loc) · 12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
// Copyright Contributors to the Open Shading Language project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage
#include <cstdio>
#include <string>
#include "oslexec_pvt.h"
#include <OSL/batched_rendererservices.h>
using namespace OSL;
using namespace OSL::pvt;
OSL_NAMESPACE_ENTER
#ifdef OIIO_TEXTURESYSTEM_CREATE_SHARED
namespace {
std::mutex shared_texturesys_mutex;
std::shared_ptr<TextureSystem> shared_texturesys;
} // namespace
#endif
template<int WidthT>
BatchedRendererServices<WidthT>::BatchedRendererServices(TextureSystem* texsys)
: m_texturesys(texsys)
{
if (!m_texturesys) {
#if OSL_NO_DEFAULT_TEXTURESYSTEM
// This build option instructs OSL to never create a TextureSystem
// itself. (Most likely reason: this build of OSL is for a renderer
// that replaces OIIO's TextureSystem with its own, and therefore
// wouldn't want to accidentally make an OIIO one here.
OSL_ASSERT(
0 && "RendererServices was not passed a working TextureSystem*");
#else
# ifdef OIIO_TEXTURESYSTEM_CREATE_SHARED
{
std::lock_guard<std::mutex> lock(shared_texturesys_mutex);
if (!shared_texturesys) {
shared_texturesys = TextureSystem::create(true /* shared */);
}
m_texturesys = shared_texturesys.get();
}
# else
m_texturesys = TextureSystem::create(true /* shared */);
# endif
// Make some good guesses about default options
m_texturesys->attribute("automip", 1);
m_texturesys->attribute("autotile", 64);
#endif
}
}
template<int WidthT>
Mask<WidthT>
BatchedRendererServices<WidthT>::get_matrix(BatchedShaderGlobals* bsg,
Masked<Matrix44> wresult,
Wide<const ustringhash> wfrom,
Wide<const float> wtime)
{
OSL_ASSERT(
0
&& "UNREACHABLE: BatchedRendererServices<WidthT>::get_matrix calls should be overridden or the target specific version in wide_opmatrix.cpp should be called");
return Mask(false);
}
template<int WidthT>
Mask<WidthT>
BatchedRendererServices<WidthT>::get_inverse_matrix(
BatchedShaderGlobals* bsg, Masked<Matrix44> wresult,
Wide<const TransformationPtr> wxform, Wide<const float> wtime)
{
OSL_ASSERT(
0
&& "UNREACHABLE: BatchedRendererServices<WidthT>::get_inverse_matrix calls should be overridden or the target specific version in wide_opmatrix.cpp should be called");
return Mask(false);
}
template<int WidthT>
Mask<WidthT>
BatchedRendererServices<WidthT>::get_inverse_matrix(BatchedShaderGlobals* bsg,
Masked<Matrix44> wresult,
ustringhash to,
Wide<const float> wtime)
{
OSL_ASSERT(
0
&& "UNREACHABLE: BatchedRendererServices<WidthT>::get_inverse_matrix calls should be overridden or the target specific version in wide_opmatrix.cpp should be called");
return Mask(false);
}
template<int WidthT>
Mask<WidthT>
BatchedRendererServices<WidthT>::get_inverse_matrix(BatchedShaderGlobals* bsg,
Masked<Matrix44> wresult,
Wide<const ustringhash> wto,
Wide<const float> wtime)
{
OSL_ASSERT(
0
&& "UNREACHABLE: BatchedRendererServices<WidthT>::get_inverse_matrix calls should be overridden or the target specific version in wide_opmatrix.cpp should be called");
return Mask(false);
}
template<int WidthT>
TextureSystem*
BatchedRendererServices<WidthT>::texturesys() const
{
return m_texturesys;
}
template<int WidthT>
TextureSystem::TextureHandle*
BatchedRendererServices<WidthT>::resolve_udim_uniform(
BatchedShaderGlobals* bsg, TexturePerthread* texture_thread_info,
ustringhash filename, TextureSystem::TextureHandle* texture_handle, float S,
float T)
{
if (!texture_thread_info)
texture_thread_info = bsg->uniform.context->texture_thread_info();
if (!texture_handle)
texture_handle = texturesys()->get_texture_handle(ustring_from(filename),
texture_thread_info);
if (texturesys()->is_udim(texture_handle)) {
// Newer versions of the TextureSystem interface are able to determine the
// specific UDIM tile we're using.
TextureSystem::TextureHandle* udim_handle
= texturesys()->resolve_udim(texture_handle, texture_thread_info, S,
T);
// NOTE: udim_handle may be nullptr if no corresponding texture exists
if (udim_handle == nullptr) {
// Optimization to just reuse the <udim> texture handle vs.
// forcing get_texture_info_uniform to redo the lookup we have already done.
udim_handle = texture_handle;
}
return udim_handle;
} else {
return texture_handle;
}
}
template<int WidthT>
void
BatchedRendererServices<WidthT>::resolve_udim(
BatchedShaderGlobals* bsg, TexturePerthread* texture_thread_info,
ustringhash filename, TextureSystem::TextureHandle* texture_handle,
Wide<const float> wS, Wide<const float> wT,
Masked<TextureSystem::TextureHandle*> wresult)
{
if (!texture_thread_info)
texture_thread_info = bsg->uniform.context->texture_thread_info();
if (!texture_handle)
texture_handle = texturesys()->get_texture_handle(ustring_from(filename),
texture_thread_info);
if (texturesys()->is_udim(texture_handle)) {
// Newer versions of the TextureSystem interface are able to determine the
// specific UDIM tile we're using.
wresult.mask().foreach ([&](ActiveLane l) -> void {
TextureSystem::TextureHandle* udim_handle
= texturesys()->resolve_udim(texture_handle,
texture_thread_info, wS[l], wT[l]);
// NOTE: udim_handle may be nullptr if no corresponding texture exists
if (udim_handle == nullptr) {
// Optimization to just reuse the <udim> texture handle vs.
// forcing get_texture_info_uniform to redo the lookup we have already done.
udim_handle = texture_handle;
}
wresult[l] = udim_handle;
});
} else {
assign_all(wresult, texture_handle);
}
}
template<int WidthT>
bool
BatchedRendererServices<WidthT>::get_texture_info_uniform(
BatchedShaderGlobals* bsg, TexturePerthread* texture_thread_info,
ustringhash filename, TextureSystem::TextureHandle* texture_handle,
int subimage, ustringhash dataname, RefData val)
{
if (!texture_thread_info)
texture_thread_info = bsg->uniform.context->texture_thread_info();
if (!texture_handle)
texture_handle = texturesys()->get_texture_handle(ustring_from(filename),
texture_thread_info);
bool status = texturesys()->get_texture_info(texture_handle, NULL, subimage,
ustring_from(dataname),
val.type(), val.ptr());
if (!status) {
std::string err = texturesys()->geterror();
if (err.size() && bsg) {
bsg->uniform.context->errorfmt(
"[RendererServices::get_texture_info] {}", err);
}
}
return status;
}
template<int WidthT>
Mask<WidthT>
BatchedRendererServices<WidthT>::texture(
ustringhash filename, TextureSystem::TextureHandle* texture_handle,
TextureSystem::Perthread* texture_thread_info,
const BatchedTextureOptions& options, BatchedShaderGlobals* bsg,
Wide<const float> ws, Wide<const float> wt, Wide<const float> wdsdx,
Wide<const float> wdtdx, Wide<const float> wdsdy, Wide<const float> wdtdy,
BatchedTextureOutputs& outputs)
{
OSL_ASSERT(
0
&& "UNREACHABLE: BatchedRendererServices<WidthT>::texture calls should be overridden or the target specific version in wide_optexture.cpp should be called");
return Mask(false);
}
template<int WidthT>
Mask<WidthT>
BatchedRendererServices<WidthT>::texture3d(
ustringhash filename, TextureSystem::TextureHandle* texture_handle,
TextureSystem::Perthread* texture_thread_info,
const BatchedTextureOptions& options, BatchedShaderGlobals* bsg,
Wide<const Vec3> wP, Wide<const Vec3> wdPdx, Wide<const Vec3> wdPdy,
Wide<const Vec3> wdPdz, BatchedTextureOutputs& outputs)
{
OSL_ASSERT(
0
&& "UNREACHABLE: BatchedRendererServices<WidthT>::texture calls should be overridden or the target specific version in wide_optexture.cpp should be called");
return Mask(false);
}
template<int WidthT>
Mask<WidthT>
BatchedRendererServices<WidthT>::environment(
ustringhash filename, TextureSystem::TextureHandle* texture_handle,
TextureSystem::Perthread* texture_thread_info,
const BatchedTextureOptions& options, BatchedShaderGlobals* bsg,
Wide<const Vec3> wR, Wide<const Vec3> wdRdx, Wide<const Vec3> wdRdy,
BatchedTextureOutputs& outputs)
{
OSL_ASSERT(
0
&& "UNREACHABLE: BatchedRendererServices<WidthT>::environment calls should be overridden or the target specific version in wide_optexture.cpp should be called");
return Mask(false);
}
template<int WidthT>
void
BatchedRendererServices<WidthT>::pointcloud_search(
BatchedShaderGlobals* bsg, ustringhash filename, const void* wcenter,
Wide<const float> wradius, int max_points, bool sort,
PointCloudSearchResults& results)
{
OSL_ASSERT(
0
&& "UNREACHABLE: BatchedRendererServices<WidthT>::pointcloud_search calls should be overridden or the target specific version in wide_oppointcloud.cpp should be called");
}
template<int WidthT>
Mask<WidthT>
BatchedRendererServices<WidthT>::pointcloud_get(
BatchedShaderGlobals* bsg, ustringhash filename, Wide<const int[]> windices,
Wide<const int> wnum_points, ustringhash attr_name, MaskedData wout_data)
{
OSL_ASSERT(
0
&& "UNREACHABLE: BatchedRendererServices<WidthT>::pointcloud_get calls should be overridden or the target specific version in wide_oppointcloud.cpp should be called");
return Mask(false);
}
template<int WidthT>
Mask<WidthT>
BatchedRendererServices<WidthT>::pointcloud_write(
BatchedShaderGlobals* bsg, ustringhash filename, Wide<const OSL::Vec3> wpos,
int nattribs, const ustring* attr_names, const TypeDesc* attr_types,
const void** pointers_to_wide_attr_value, Mask mask)
{
OSL_ASSERT(
0
&& "UNREACHABLE: BatchedRendererServices<WidthT>::pointcloud_write calls should be overridden or the target specific version in wide_oppointcloud.cpp should be called");
return Mask(false);
}
template<int WidthT>
void
BatchedRendererServices<WidthT>::trace(
TraceOpt& options, BatchedShaderGlobals* bsg, Masked<int> wresult,
Wide<const Vec3> wP, Wide<const Vec3> wdPdx, Wide<const Vec3> wdPdy,
Wide<const Vec3> wR, Wide<const Vec3> wdRdx, Wide<const Vec3> wdRdy)
{
for (int lane = 0; lane < WidthT; ++lane) {
wresult[lane] = 0;
}
}
template<int WidthT>
void
BatchedRendererServices<WidthT>::getmessage(BatchedShaderGlobals* bsg,
Masked<int> wresult,
ustringhash source,
ustringhash name, MaskedData wval)
{
// Currently this code path should only be followed when source == "trace"
OSL_DASSERT(wresult.mask() == wval.mask());
for (int lane = 0; lane < WidthT; ++lane) {
wresult[lane] = 0;
}
}
// Explicitly instantiate BatchedRendererServices template
template class OSLEXECPUBLIC BatchedRendererServices<16>;
template class OSLEXECPUBLIC BatchedRendererServices<8>;
template class OSLEXECPUBLIC BatchedRendererServices<4>;
OSL_NAMESPACE_EXIT