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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
|
#define _CRT_SECURE_NO_WARNINGS 1
#include "cpu-compute-util.h"
#include "../../slang-com-helper.h"
#include "../../source/core/slang-std-writers.h"
#include "../../source/core/slang-token-reader.h"
#include "bind-location.h"
#define SLANG_PRELUDE_NAMESPACE CPPPrelude
#include "../../prelude/slang-cpp-types.h"
namespace renderer_test {
using namespace Slang;
template <int COUNT>
struct ValueTextureCube : public CPUComputeUtil::Resource, public CPPPrelude::ITextureCube
{
void set(void* out)
{
float* dst = (float*)out;
for (int i = 0; i < COUNT; ++i)
{
dst[i] = m_value;
}
}
virtual void Sample(CPPPrelude::SamplerState samplerState, const CPPPrelude::float3& loc, void* out) SLANG_OVERRIDE
{
set(out);
}
virtual void SampleLevel(CPPPrelude::SamplerState samplerState, const CPPPrelude::float3& loc, float level, void* out) SLANG_OVERRIDE
{
set(out);
}
ValueTextureCube(float value) :
m_value(value)
{
m_interface = static_cast<CPPPrelude::ITextureCube*>(this);
}
float m_value;
};
template <int COUNT>
struct ValueTexture3D : public CPUComputeUtil::Resource, public CPPPrelude::ITexture3D
{
void set(void* out)
{
float* dst = (float*)out;
for (int i = 0; i < COUNT; ++i)
{
dst[i] = m_value;
}
}
virtual void Load(const CPPPrelude::int4& v, void* out) SLANG_OVERRIDE
{
set(out);
}
virtual void Sample(CPPPrelude::SamplerState samplerState, const CPPPrelude::float3& loc, void* out) SLANG_OVERRIDE
{
set(out);
}
virtual void SampleLevel(CPPPrelude::SamplerState samplerState, const CPPPrelude::float3& loc, float level, void* out) SLANG_OVERRIDE
{
set(out);
}
ValueTexture3D(float value) :
m_value(value)
{
m_interface = static_cast<CPPPrelude::ITexture3D*>(this);
}
float m_value;
};
template <int COUNT>
struct ValueTexture2D : public CPUComputeUtil::Resource, public CPPPrelude::ITexture2D
{
void set(void* out)
{
float* dst = (float*)out;
for (int i = 0; i < COUNT; ++i)
{
dst[i] = m_value;
}
}
virtual void Load(const CPPPrelude::int3& v, void* out) SLANG_OVERRIDE
{
set(out);
}
virtual void Sample(CPPPrelude::SamplerState samplerState, const CPPPrelude::float2& loc, void* out) SLANG_OVERRIDE
{
set(out);
}
virtual void SampleLevel(CPPPrelude::SamplerState samplerState, const CPPPrelude::float2& loc, float level, void* out) SLANG_OVERRIDE
{
set(out);
}
ValueTexture2D(float value):
m_value(value)
{
m_interface = static_cast<CPPPrelude::ITexture2D*>(this);
}
float m_value;
};
template <int COUNT>
struct ValueTexture1D : public CPUComputeUtil::Resource, public CPPPrelude::ITexture1D
{
void set(void* out)
{
float* dst = (float*)out;
for (int i = 0; i < COUNT; ++i)
{
dst[i] = m_value;
}
}
virtual void Load(const CPPPrelude::int2& v, void* out) SLANG_OVERRIDE
{
set(out);
}
virtual void Sample(CPPPrelude::SamplerState samplerState, float loc, void* out) SLANG_OVERRIDE
{
set(out);
}
virtual void SampleLevel(CPPPrelude::SamplerState samplerState, float loc, float level, void* out) SLANG_OVERRIDE
{
set(out);
}
ValueTexture1D(float value) :
m_value(value)
{
m_interface = static_cast<CPPPrelude::ITexture1D*>(this);
}
float m_value;
};
template <int COUNT>
struct ValueTexture1DArray : public CPUComputeUtil::Resource, public CPPPrelude::ITexture1DArray
{
void set(void* out)
{
float* dst = (float*)out;
for (int i = 0; i < COUNT; ++i)
{
dst[i] = m_value;
}
}
virtual void Load(const CPPPrelude::int3& v, void* out) SLANG_OVERRIDE
{
set(out);
}
virtual void Sample(CPPPrelude::SamplerState samplerState, const CPPPrelude::float2& loc, void* out) SLANG_OVERRIDE
{
set(out);
}
virtual void SampleLevel(CPPPrelude::SamplerState samplerState, const CPPPrelude::float2& loc, float level, void* out) SLANG_OVERRIDE
{
set(out);
}
ValueTexture1DArray(float value) :
m_value(value)
{
m_interface = static_cast<CPPPrelude::ITexture1DArray*>(this);
}
float m_value;
};
template <int COUNT>
struct ValueTexture2DArray : public CPUComputeUtil::Resource, public CPPPrelude::ITexture2DArray
{
void set(void* out)
{
float* dst = (float*)out;
for (int i = 0; i < COUNT; ++i)
{
dst[i] = m_value;
}
}
virtual void Load(const CPPPrelude::int4& v, void* out) SLANG_OVERRIDE
{
set(out);
}
virtual void Sample(CPPPrelude::SamplerState samplerState, const CPPPrelude::float3& loc, void* out) SLANG_OVERRIDE
{
set(out);
}
virtual void SampleLevel(CPPPrelude::SamplerState samplerState, const CPPPrelude::float3& loc, float level, void* out) SLANG_OVERRIDE
{
set(out);
}
ValueTexture2DArray(float value) :
m_value(value)
{
m_interface = static_cast<CPPPrelude::ITexture2DArray*>(this);
}
float m_value;
};
template <int COUNT>
struct ValueTextureCubeArray : public CPUComputeUtil::Resource, public CPPPrelude::ITextureCubeArray
{
void set(void* out)
{
float* dst = (float*)out;
for (int i = 0; i < COUNT; ++i)
{
dst[i] = m_value;
}
}
virtual void Sample(CPPPrelude::SamplerState samplerState, const CPPPrelude::float4& loc, void* out) SLANG_OVERRIDE
{
set(out);
}
virtual void SampleLevel(CPPPrelude::SamplerState samplerState, const CPPPrelude::float4& loc, float level, void* out) SLANG_OVERRIDE
{
set(out);
}
ValueTextureCubeArray(float value) :
m_value(value)
{
m_interface = static_cast<CPPPrelude::ITextureCubeArray*>(this);
}
float m_value;
};
static CPUComputeUtil::Resource* _newValueTexture(SlangResourceShape shape, int elemCount, float value)
{
switch (shape)
{
case SLANG_TEXTURE_1D:
{
switch (elemCount)
{
case 1: return new ValueTexture1D<1>(value);
case 2: return new ValueTexture1D<2>(value);
case 3: return new ValueTexture1D<3>(value);
case 4: return new ValueTexture1D<4>(value);
default: break;
}
break;
}
case SLANG_TEXTURE_2D:
{
switch (elemCount)
{
case 1: return new ValueTexture2D<1>(value);
case 2: return new ValueTexture2D<2>(value);
case 3: return new ValueTexture2D<3>(value);
case 4: return new ValueTexture2D<4>(value);
default: break;
}
}
case SLANG_TEXTURE_3D:
{
switch (elemCount)
{
case 1: return new ValueTexture3D<1>(value);
case 2: return new ValueTexture3D<2>(value);
case 3: return new ValueTexture3D<3>(value);
case 4: return new ValueTexture3D<4>(value);
default: break;
}
}
case SLANG_TEXTURE_CUBE:
{
switch (elemCount)
{
case 1: return new ValueTextureCube<1>(value);
case 2: return new ValueTextureCube<2>(value);
case 3: return new ValueTextureCube<3>(value);
case 4: return new ValueTextureCube<4>(value);
default: break;
}
}
case SLANG_TEXTURE_1D_ARRAY:
{
switch (elemCount)
{
case 1: return new ValueTexture1DArray<1>(value);
case 2: return new ValueTexture1DArray<2>(value);
case 3: return new ValueTexture1DArray<3>(value);
case 4: return new ValueTexture1DArray<4>(value);
default: break;
}
break;
}
case SLANG_TEXTURE_2D_ARRAY:
{
switch (elemCount)
{
case 1: return new ValueTexture2DArray<1>(value);
case 2: return new ValueTexture2DArray<2>(value);
case 3: return new ValueTexture2DArray<3>(value);
case 4: return new ValueTexture2DArray<4>(value);
default: break;
}
break;
}
case SLANG_TEXTURE_CUBE_ARRAY:
{
switch (elemCount)
{
case 1: return new ValueTextureCubeArray<1>(value);
case 2: return new ValueTextureCubeArray<2>(value);
case 3: return new ValueTextureCubeArray<3>(value);
case 4: return new ValueTextureCubeArray<4>(value);
default: break;
}
break;
}
default: break;
}
return nullptr;
}
/* static */SlangResult CPUComputeUtil::calcBindings(const ShaderCompilerUtil::OutputAndLayout& compilationAndLayout, Context& outContext)
{
auto request = compilationAndLayout.output.request;
auto reflection = (slang::ShaderReflection*) spGetReflection(request);
const auto& sourcePath = compilationAndLayout.sourcePath;
outContext.m_bindRoot.init(&outContext.m_bindSet, reflection, 0);
// This will set up constant buffer that are contained from the roots
outContext.m_bindRoot.addDefaultValues();
// Okay lets iterate adding buffers
auto outStream = StdWriters::getOut();
SLANG_RETURN_ON_FAIL(ShaderInputLayout::addBindSetValues(compilationAndLayout.layout.entries, compilationAndLayout.sourcePath, outStream, outContext.m_bindRoot));
ShaderInputLayout::getValueBuffers(compilationAndLayout.layout.entries, outContext.m_bindSet, outContext.m_buffers);
// Okay we need to find all of the bindings and match up to those in the layout
const ShaderInputLayout& layout = compilationAndLayout.layout;
// The final stage is to actual set up the CPU based variables
{
// First create all of the resources for the values
// We don't need to create anything backed by a buffer on CPU, as the memory buffer as provided
// by BindSet::Resource can just be used
{
const auto& values = outContext.m_bindSet.getValues();
for (BindSet::Value* value : values)
{
auto typeLayout = value->m_type;
if (typeLayout == nullptr)
{
// We need type layout here to create anything
continue;
}
// TODO(JS):
// Here we should be using information about what textures hold to create appropriate
// textures. For now we only support 2d textures that always return 1.
const auto kind = typeLayout->getKind();
switch (kind)
{
case slang::TypeReflection::Kind::Resource:
{
auto type = typeLayout->getType();
auto shape = type->getResourceShape();
//auto access = type->getResourceAccess();
auto baseShape = shape & SLANG_RESOURCE_BASE_SHAPE_MASK;
switch (baseShape)
{
case SLANG_TEXTURE_1D:
case SLANG_TEXTURE_2D:
case SLANG_TEXTURE_3D:
case SLANG_TEXTURE_CUBE:
{
SLANG_ASSERT(value->m_userIndex >= 0);
auto& srcEntry = layout.entries[value->m_userIndex];
// TODO(JS): Currently we support only textures who's content is either
// 0 or 1. This is because this is easy to implement.
// Will need to do something better in the future..
slang::TypeReflection* typeReflection = typeLayout->getResourceResultType();
int count = 1;
if (typeReflection->getKind() == slang::TypeReflection::Kind::Vector)
{
count = int(typeReflection->getElementCount());
}
switch (srcEntry.textureDesc.content)
{
case InputTextureContent::One:
{
value->m_target = _newValueTexture(shape, count, 1.0f);
break;
}
case InputTextureContent::Zero:
{
value->m_target = _newValueTexture(shape, count, 0.0f);
break;
}
default: break;
}
if (value->m_target == nullptr)
{
SLANG_ASSERT(!"Couldn't construct resource type");
return SLANG_FAIL;
}
break;
}
case SLANG_TEXTURE_BUFFER:
{
// Need a CPU impl for these...
// For now we can just leave as target will just be nullptr
break;
}
case SLANG_BYTE_ADDRESS_BUFFER:
case SLANG_STRUCTURED_BUFFER:
{
// On CPU we just use the memory in the BindSet buffer, so don't need to create anything
break;
}
}
}
default: break;
}
}
}
// Now we need to go through all of the bindings and set the appropriate data
{
List<BindLocation> locations;
List<BindSet::Value*> values;
outContext.m_bindSet.getBindings(locations, values);
for (Index i = 0; i < locations.getCount(); ++i)
{
const auto& location = locations[i];
BindSet::Value* value = values[i];
// Okay now we need to set up the actual handles that CPU will follow.
auto typeLayout = location.getTypeLayout();
const auto kind = typeLayout->getKind();
switch (kind)
{
case slang::TypeReflection::Kind::Array:
{
auto elementCount = int(typeLayout->getElementCount());
if (elementCount == 0)
{
CPPPrelude::Array<uint8_t>* array = location.getUniform<CPPPrelude::Array<uint8_t> >();
// If set, we setup the data needed for array on CPU side
if (value && array)
{
array->data = value->m_data;
array->count = value->m_elementCount;
}
}
break;
}
case slang::TypeReflection::Kind::ConstantBuffer:
case slang::TypeReflection::Kind::ParameterBlock:
{
// These map down to pointers. In our case the contents of the resource
void* data = value ? value->m_data : nullptr;
location.setUniform(&data, sizeof(data));
break;
}
case slang::TypeReflection::Kind::Resource:
{
auto type = typeLayout->getType();
auto shape = type->getResourceShape();
//auto access = type->getResourceAccess();
switch (shape & SLANG_RESOURCE_BASE_SHAPE_MASK)
{
default:
assert(!"unhandled case");
break;
case SLANG_TEXTURE_1D:
case SLANG_TEXTURE_2D:
case SLANG_TEXTURE_3D:
case SLANG_TEXTURE_CUBE:
case SLANG_TEXTURE_BUFFER:
{
Resource* targetResource = value ? static_cast<Resource*>(value->m_target.Ptr()) : nullptr;
void* intf = targetResource ? targetResource->getInterface() : nullptr;
*location.getUniform<void*>() = intf;
break;
}
case SLANG_STRUCTURED_BUFFER:
{
if (value)
{
auto& dstBuf = *location.getUniform<CPPPrelude::StructuredBuffer<uint8_t> >();
dstBuf.data = (uint8_t*)value->m_data;
dstBuf.count = value->m_elementCount;
}
break;
}
case SLANG_BYTE_ADDRESS_BUFFER:
{
if (value)
{
auto& dstBuf = *location.getUniform<CPPPrelude::ByteAddressBuffer>();
dstBuf.data = (uint32_t*)value->m_data;
dstBuf.sizeInBytes = value->m_sizeInBytes;
}
break;
}
}
}
}
}
}
}
return SLANG_OK;
}
/* static */SlangResult CPUComputeUtil::calcExecuteInfo(ExecuteStyle style, ISlangSharedLibrary* sharedLib, const uint32_t dispatchSize[3], const ShaderCompilerUtil::OutputAndLayout& compilationAndLayout, Context& context, ExecuteInfo& out)
{
auto request = compilationAndLayout.output.request;
auto reflection = (slang::ShaderReflection*) spGetReflection(request);
slang::EntryPointReflection* entryPoint = nullptr;
auto entryPointCount = reflection->getEntryPointCount();
SLANG_ASSERT(entryPointCount == 1);
entryPoint = reflection->getEntryPointByIndex(0);
const char* entryPointName = entryPoint->getName();
// Copy dispatch size
for (int i = 0; i < 3; ++i)
{
out.m_dispatchSize[i] = dispatchSize[i];
}
out.m_style = style;
out.m_uniformState = (void*)context.m_bindRoot.getRootData();
out.m_uniformEntryPointParams = (void*)context.m_bindRoot.getEntryPointData();
switch (style)
{
case ExecuteStyle::Group:
{
StringBuilder groupEntryPointName;
groupEntryPointName << entryPointName << "_Group";
CPPPrelude::ComputeFunc groupFunc = (CPPPrelude::ComputeFunc)sharedLib->findFuncByName(groupEntryPointName.getBuffer());
if (!groupFunc)
{
return SLANG_FAIL;
}
out.m_func = (ExecuteInfo::Func)groupFunc;
break;
}
case ExecuteStyle::GroupRange:
{
CPPPrelude::ComputeFunc groupRangeFunc = nullptr;
groupRangeFunc = (CPPPrelude::ComputeFunc)sharedLib->findFuncByName(entryPointName);
if (!groupRangeFunc)
{
return SLANG_FAIL;
}
out.m_func = (ExecuteInfo::Func)groupRangeFunc;
break;
}
case ExecuteStyle::Thread:
{
StringBuilder threadEntryPointName;
threadEntryPointName << entryPointName << "_Thread";
CPPPrelude::ComputeThreadFunc threadFunc = (CPPPrelude::ComputeThreadFunc)sharedLib->findFuncByName(threadEntryPointName.getBuffer());
if (!threadFunc)
{
return SLANG_FAIL;
}
SlangUInt numThreadsPerAxis[3];
entryPoint->getComputeThreadGroupSize(3, numThreadsPerAxis);
for (int i = 0; i < 3; ++i)
{
out.m_numThreadsPerAxis[i] = uint32_t(numThreadsPerAxis[i]);
}
out.m_func = (ExecuteInfo::Func)threadFunc;
break;
}
default:
{
return SLANG_FAIL;
}
}
return SLANG_OK;
}
/* static */SlangResult CPUComputeUtil::execute(const ExecuteInfo& info)
{
CPPPrelude::UniformState* uniformState = (CPPPrelude::UniformState*)info.m_uniformState;
CPPPrelude::UniformEntryPointParams* uniformEntryPointParams = (CPPPrelude::UniformEntryPointParams*)info.m_uniformEntryPointParams;
switch (info.m_style)
{
case ExecuteStyle::Group:
{
CPPPrelude::ComputeFunc groupFunc = (CPPPrelude::ComputeFunc)info.m_func;
CPPPrelude::ComputeVaryingInput varying;
const uint32_t groupXCount = info.m_dispatchSize[0];
const uint32_t groupYCount = info.m_dispatchSize[1];
const uint32_t groupZCount = info.m_dispatchSize[2];
for (uint32_t groupZ = 0; groupZ < groupZCount; ++groupZ)
{
for (uint32_t groupY = 0; groupY < groupYCount; ++groupY)
{
for (uint32_t groupX = 0; groupX < groupXCount; ++groupX)
{
varying.startGroupID = { groupX, groupY, groupZ };
groupFunc(&varying, uniformEntryPointParams, uniformState);
}
}
}
break;
}
case ExecuteStyle::GroupRange:
{
CPPPrelude::ComputeFunc groupRangeFunc = (CPPPrelude::ComputeFunc)info.m_func;
CPPPrelude::ComputeVaryingInput varying;
varying.startGroupID = {};
varying.endGroupID = { info.m_dispatchSize[0], info.m_dispatchSize[1], info.m_dispatchSize[2] };
groupRangeFunc(&varying, uniformEntryPointParams, uniformState);
break;
}
case ExecuteStyle::Thread:
{
CPPPrelude::ComputeThreadFunc threadFunc = (CPPPrelude::ComputeThreadFunc)info.m_func;
CPPPrelude::ComputeThreadVaryingInput varying;
const uint32_t groupXCount = info.m_dispatchSize[0];
const uint32_t groupYCount = info.m_dispatchSize[1];
const uint32_t groupZCount = info.m_dispatchSize[2];
const uint32_t threadXCount = uint32_t(info.m_numThreadsPerAxis[0]);
const uint32_t threadYCount = uint32_t(info.m_numThreadsPerAxis[1]);
const uint32_t threadZCount = uint32_t(info.m_numThreadsPerAxis[2]);
for (uint32_t groupZ = 0; groupZ < groupZCount; ++groupZ)
{
for (uint32_t groupY = 0; groupY < groupYCount; ++groupY)
{
for (uint32_t groupX = 0; groupX < groupXCount; ++groupX)
{
varying.groupID = { groupX, groupY, groupZ };
for (uint32_t z = 0; z < threadZCount; ++z)
{
varying.groupThreadID.z = z;
for (uint32_t y = 0; y < threadYCount; ++y)
{
varying.groupThreadID.y = y;
for (uint32_t x = 0; x < threadXCount; ++x)
{
varying.groupThreadID.x = x;
threadFunc(&varying, uniformEntryPointParams, uniformState);
}
}
}
}
}
}
break;
}
default: return SLANG_FAIL;
}
return SLANG_OK;
}
/* static */ SlangResult CPUComputeUtil::checkStyleConsistency(ISlangSharedLibrary* sharedLib, const uint32_t dispatchSize[3], const ShaderCompilerUtil::OutputAndLayout& compilationAndLayout)
{
Context context;
SLANG_RETURN_ON_FAIL(CPUComputeUtil::calcBindings(compilationAndLayout, context));
// Run the thread style to test against
{
ExecuteInfo info;
SLANG_RETURN_ON_FAIL(calcExecuteInfo(ExecuteStyle::Thread, sharedLib, dispatchSize, compilationAndLayout, context, info));
SLANG_RETURN_ON_FAIL(execute(info));
}
ExecuteStyle styles[] = { ExecuteStyle::Group, ExecuteStyle::GroupRange };
for (auto style: styles)
{
Context checkContext;
SLANG_RETURN_ON_FAIL(CPUComputeUtil::calcBindings(compilationAndLayout, checkContext));
ExecuteInfo info;
SLANG_RETURN_ON_FAIL(calcExecuteInfo(style, sharedLib, dispatchSize, compilationAndLayout, checkContext, info));
SLANG_RETURN_ON_FAIL(execute(info));
// Make sure the out buffers are all the same
const auto& entries = compilationAndLayout.layout.entries;
for (int i = 0; i < entries.getCount(); ++i)
{
const auto& entry = entries[i];
if (entry.isOutput)
{
BindSet::Value* buffer = context.m_buffers[i];
BindSet::Value* checkBuffer = checkContext.m_buffers[i];
if (buffer->m_sizeInBytes != checkBuffer->m_sizeInBytes ||
::memcmp(buffer->m_data, checkBuffer->m_data, buffer->m_sizeInBytes) != 0)
{
return SLANG_FAIL;
}
}
}
}
return SLANG_OK;
}
} // renderer_test
|