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
|
/*
* Copyright 2019-2021 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* In no event and under no legal theory, whether in tort (including negligence),
* contract, or otherwise, unless required by applicable law (such as deliberate
* and grossly negligent acts) or agreed to in writing, shall any Contributor be
* liable for any damages, including any direct, indirect, special, incidental,
* or consequential damages of any character arising as a result of this License or
* out of the use or inability to use the software (including but not limited to damages
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and
* all other commercial damages or losses), even if such Contributor has been advised
* of the possibility of such damages.
*/
#include "pch.h"
#include "ShaderResourcesGL.hpp"
#include <unordered_set>
#include "RenderDeviceGLImpl.hpp"
#include "GLContextState.hpp"
#include "ShaderResourceVariableBase.hpp"
#include "Align.hpp"
#include "GLTypeConversions.hpp"
namespace Diligent
{
ShaderResourcesGL::ShaderResourcesGL(ShaderResourcesGL&& Program) noexcept :
// clang-format off
m_ShaderStages {Program.m_ShaderStages },
m_UniformBuffers {Program.m_UniformBuffers },
m_Textures {Program.m_Textures },
m_Images {Program.m_Images },
m_StorageBlocks {Program.m_StorageBlocks },
m_NumUniformBuffers{Program.m_NumUniformBuffers },
m_NumTextures {Program.m_NumTextures },
m_NumImages {Program.m_NumImages },
m_NumStorageBlocks {Program.m_NumStorageBlocks }
// clang-format on
{
Program.m_UniformBuffers = nullptr;
Program.m_Textures = nullptr;
Program.m_Images = nullptr;
Program.m_StorageBlocks = nullptr;
Program.m_NumUniformBuffers = 0;
Program.m_NumTextures = 0;
Program.m_NumImages = 0;
Program.m_NumStorageBlocks = 0;
}
inline void RemoveArrayBrackets(char* Str)
{
auto* OpenBacketPtr = strchr(Str, '[');
if (OpenBacketPtr != nullptr)
*OpenBacketPtr = 0;
}
void ShaderResourcesGL::AllocateResources(std::vector<UniformBufferInfo>& UniformBlocks,
std::vector<TextureInfo>& Textures,
std::vector<ImageInfo>& Images,
std::vector<StorageBlockInfo>& StorageBlocks)
{
VERIFY(m_UniformBuffers == nullptr, "Resources have already been allocated!");
m_NumUniformBuffers = static_cast<Uint32>(UniformBlocks.size());
m_NumTextures = static_cast<Uint32>(Textures.size());
m_NumImages = static_cast<Uint32>(Images.size());
m_NumStorageBlocks = static_cast<Uint32>(StorageBlocks.size());
size_t StringPoolDataSize = 0;
for (const auto& ub : UniformBlocks)
{
StringPoolDataSize += strlen(ub.Name) + 1;
}
for (const auto& sam : Textures)
{
StringPoolDataSize += strlen(sam.Name) + 1;
}
for (const auto& img : Images)
{
StringPoolDataSize += strlen(img.Name) + 1;
}
for (const auto& sb : StorageBlocks)
{
StringPoolDataSize += strlen(sb.Name) + 1;
}
auto AlignedStringPoolDataSize = AlignUp(StringPoolDataSize, sizeof(void*));
// clang-format off
size_t TotalMemorySize =
m_NumUniformBuffers * sizeof(UniformBufferInfo) +
m_NumTextures * sizeof(TextureInfo) +
m_NumImages * sizeof(ImageInfo) +
m_NumStorageBlocks * sizeof(StorageBlockInfo);
// clang-format on
if (TotalMemorySize == 0)
{
m_UniformBuffers = nullptr;
m_Textures = nullptr;
m_Images = nullptr;
m_StorageBlocks = nullptr;
m_NumUniformBuffers = 0;
m_NumTextures = 0;
m_NumImages = 0;
m_NumStorageBlocks = 0;
return;
}
TotalMemorySize += AlignedStringPoolDataSize * sizeof(Char);
auto& MemAllocator = GetRawAllocator();
void* RawMemory = ALLOCATE_RAW(MemAllocator, "Memory buffer for ShaderResourcesGL", TotalMemorySize);
// clang-format off
m_UniformBuffers = reinterpret_cast<UniformBufferInfo*>(RawMemory);
m_Textures = reinterpret_cast<TextureInfo*> (m_UniformBuffers + m_NumUniformBuffers);
m_Images = reinterpret_cast<ImageInfo*> (m_Textures + m_NumTextures);
m_StorageBlocks = reinterpret_cast<StorageBlockInfo*>(m_Images + m_NumImages);
void* EndOfResourceData = m_StorageBlocks + m_NumStorageBlocks;
Char* StringPoolData = reinterpret_cast<Char*>(EndOfResourceData);
// clang-format on
// The pool is only needed to facilitate string allocation.
StringPool TmpStringPool;
TmpStringPool.AssignMemory(StringPoolData, StringPoolDataSize);
for (Uint32 ub = 0; ub < m_NumUniformBuffers; ++ub)
{
auto& SrcUB = UniformBlocks[ub];
new (m_UniformBuffers + ub) UniformBufferInfo{SrcUB, TmpStringPool};
}
for (Uint32 s = 0; s < m_NumTextures; ++s)
{
auto& SrcSam = Textures[s];
new (m_Textures + s) TextureInfo{SrcSam, TmpStringPool};
}
for (Uint32 img = 0; img < m_NumImages; ++img)
{
auto& SrcImg = Images[img];
new (m_Images + img) ImageInfo{SrcImg, TmpStringPool};
}
for (Uint32 sb = 0; sb < m_NumStorageBlocks; ++sb)
{
auto& SrcSB = StorageBlocks[sb];
new (m_StorageBlocks + sb) StorageBlockInfo{SrcSB, TmpStringPool};
}
VERIFY_EXPR(TmpStringPool.GetRemainingSize() == 0);
}
ShaderResourcesGL::~ShaderResourcesGL()
{
// clang-format off
ProcessResources(
[&](UniformBufferInfo& UB)
{
UB.~UniformBufferInfo();
},
[&](TextureInfo& Sam)
{
Sam.~TextureInfo();
},
[&](ImageInfo& Img)
{
Img.~ImageInfo();
},
[&](StorageBlockInfo& SB)
{
SB.~StorageBlockInfo();
}
);
// clang-format on
void* RawMemory = m_UniformBuffers;
if (RawMemory != nullptr)
{
auto& MemAllocator = GetRawAllocator();
MemAllocator.Free(RawMemory);
}
}
void ShaderResourcesGL::LoadUniforms(SHADER_TYPE ShaderStages,
const GLObjectWrappers::GLProgramObj& GLProgram,
GLContextState& State)
{
// Load uniforms to temporary arrays. We will then pack all variables into a single chunk of memory.
std::vector<UniformBufferInfo> UniformBlocks;
std::vector<TextureInfo> Textures;
std::vector<ImageInfo> Images;
std::vector<StorageBlockInfo> StorageBlocks;
std::unordered_set<String> NamesPool;
VERIFY(GLProgram != 0, "Null GL program");
State.SetProgram(GLProgram);
m_ShaderStages = ShaderStages;
GLint numActiveUniforms = 0;
glGetProgramiv(GLProgram, GL_ACTIVE_UNIFORMS, &numActiveUniforms);
CHECK_GL_ERROR_AND_THROW("Unable to get the number of active uniforms\n");
// Query the maximum name length of the active uniform (including null terminator)
GLint activeUniformMaxLength = 0;
glGetProgramiv(GLProgram, GL_ACTIVE_UNIFORM_MAX_LENGTH, &activeUniformMaxLength);
CHECK_GL_ERROR_AND_THROW("Unable to get the maximum uniform name length\n");
GLint numActiveUniformBlocks = 0;
glGetProgramiv(GLProgram, GL_ACTIVE_UNIFORM_BLOCKS, &numActiveUniformBlocks);
CHECK_GL_ERROR_AND_THROW("Unable to get the number of active uniform blocks\n");
//
// #### This parameter is currently unsupported by Intel OGL drivers.
//
// Query the maximum name length of the active uniform block (including null terminator)
GLint activeUniformBlockMaxLength = 0;
// On Intel driver, this call might fail:
glGetProgramiv(GLProgram, GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH, &activeUniformBlockMaxLength);
//CHECK_GL_ERROR_AND_THROW("Unable to get the maximum uniform block name length\n");
if (glGetError() != GL_NO_ERROR)
{
LOG_WARNING_MESSAGE("Unable to get the maximum uniform block name length. Using 1024 as a workaround\n");
activeUniformBlockMaxLength = 1024;
}
auto MaxNameLength = std::max(activeUniformMaxLength, activeUniformBlockMaxLength);
#if GL_ARB_program_interface_query
GLint numActiveShaderStorageBlocks = 0;
if (glGetProgramInterfaceiv)
{
glGetProgramInterfaceiv(GLProgram, GL_SHADER_STORAGE_BLOCK, GL_ACTIVE_RESOURCES, &numActiveShaderStorageBlocks);
CHECK_GL_ERROR_AND_THROW("Unable to get the number of shader storage blocks blocks\n");
// Query the maximum name length of the active shader storage block (including null terminator)
GLint MaxShaderStorageBlockNameLen = 0;
glGetProgramInterfaceiv(GLProgram, GL_SHADER_STORAGE_BLOCK, GL_MAX_NAME_LENGTH, &MaxShaderStorageBlockNameLen);
CHECK_GL_ERROR_AND_THROW("Unable to get the maximum shader storage block name length\n");
MaxNameLength = std::max(MaxNameLength, MaxShaderStorageBlockNameLen);
}
#endif
MaxNameLength = std::max(MaxNameLength, 512);
std::vector<GLchar> Name(MaxNameLength + 1);
for (int i = 0; i < numActiveUniforms; i++)
{
GLenum dataType = 0;
GLint size = 0;
GLint NameLen = 0;
// If one or more elements of an array are active, the name of the array is returned in 'name',
// the type is returned in 'type', and the 'size' parameter returns the highest array element index used,
// plus one, as determined by the compiler and/or linker.
// Only one active uniform variable will be reported for a uniform array.
// Uniform variables other than arrays will have a size of 1
glGetActiveUniform(GLProgram, i, MaxNameLength, &NameLen, &size, &dataType, Name.data());
CHECK_GL_ERROR_AND_THROW("Unable to get active uniform\n");
VERIFY(NameLen < MaxNameLength && static_cast<size_t>(NameLen) == strlen(Name.data()), "Incorrect uniform name");
VERIFY(size >= 1, "Size is expected to be at least 1");
// Note that
// glGetActiveUniform( program, index, bufSize, length, size, type, name );
//
// is equivalent to
//
// const enum props[] = { ARRAY_SIZE, TYPE };
// glGetProgramResourceName( program, UNIFORM, index, bufSize, length, name );
// glGetProgramResourceiv( program, GL_UNIFORM, index, 1, &props[0], 1, NULL, size );
// glGetProgramResourceiv( program, GL_UNIFORM, index, 1, &props[1], 1, NULL, (int *)type );
//
// The latter is only available in GL 4.4 and GLES 3.1
RESOURCE_DIMENSION ResDim;
bool IsMS;
GLTextureTypeToResourceDim(dataType, ResDim, IsMS);
switch (dataType)
{
case GL_SAMPLER_1D:
case GL_SAMPLER_2D:
case GL_SAMPLER_3D:
case GL_SAMPLER_CUBE:
case GL_SAMPLER_1D_SHADOW:
case GL_SAMPLER_2D_SHADOW:
case GL_SAMPLER_1D_ARRAY:
case GL_SAMPLER_2D_ARRAY:
case GL_SAMPLER_1D_ARRAY_SHADOW:
case GL_SAMPLER_2D_ARRAY_SHADOW:
case GL_SAMPLER_CUBE_SHADOW:
case GL_SAMPLER_EXTERNAL_OES:
case GL_INT_SAMPLER_1D:
case GL_INT_SAMPLER_2D:
case GL_INT_SAMPLER_3D:
case GL_INT_SAMPLER_CUBE:
case GL_INT_SAMPLER_1D_ARRAY:
case GL_INT_SAMPLER_2D_ARRAY:
case GL_UNSIGNED_INT_SAMPLER_1D:
case GL_UNSIGNED_INT_SAMPLER_2D:
case GL_UNSIGNED_INT_SAMPLER_3D:
case GL_UNSIGNED_INT_SAMPLER_CUBE:
case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY:
case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
case GL_SAMPLER_CUBE_MAP_ARRAY:
case GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW:
case GL_INT_SAMPLER_CUBE_MAP_ARRAY:
case GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY:
case GL_SAMPLER_2D_MULTISAMPLE:
case GL_INT_SAMPLER_2D_MULTISAMPLE:
case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
case GL_SAMPLER_2D_MULTISAMPLE_ARRAY:
case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
case GL_SAMPLER_BUFFER:
case GL_INT_SAMPLER_BUFFER:
case GL_UNSIGNED_INT_SAMPLER_BUFFER:
{
// clang-format off
const auto ResourceType =
dataType == GL_SAMPLER_BUFFER ||
dataType == GL_INT_SAMPLER_BUFFER ||
dataType == GL_UNSIGNED_INT_SAMPLER_BUFFER ?
SHADER_RESOURCE_TYPE_BUFFER_SRV :
SHADER_RESOURCE_TYPE_TEXTURE_SRV;
// clang-format on
RemoveArrayBrackets(Name.data());
Textures.emplace_back(
NamesPool.emplace(Name.data()).first->c_str(),
ShaderStages,
ResourceType,
static_cast<Uint32>(size),
dataType,
ResDim,
IsMS //
);
break;
}
#if GL_ARB_shader_image_load_store
case GL_IMAGE_1D:
case GL_IMAGE_2D:
case GL_IMAGE_3D:
case GL_IMAGE_2D_RECT:
case GL_IMAGE_CUBE:
case GL_IMAGE_BUFFER:
case GL_IMAGE_1D_ARRAY:
case GL_IMAGE_2D_ARRAY:
case GL_IMAGE_CUBE_MAP_ARRAY:
case GL_IMAGE_2D_MULTISAMPLE:
case GL_IMAGE_2D_MULTISAMPLE_ARRAY:
case GL_INT_IMAGE_1D:
case GL_INT_IMAGE_2D:
case GL_INT_IMAGE_3D:
case GL_INT_IMAGE_2D_RECT:
case GL_INT_IMAGE_CUBE:
case GL_INT_IMAGE_BUFFER:
case GL_INT_IMAGE_1D_ARRAY:
case GL_INT_IMAGE_2D_ARRAY:
case GL_INT_IMAGE_CUBE_MAP_ARRAY:
case GL_INT_IMAGE_2D_MULTISAMPLE:
case GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY:
case GL_UNSIGNED_INT_IMAGE_1D:
case GL_UNSIGNED_INT_IMAGE_2D:
case GL_UNSIGNED_INT_IMAGE_3D:
case GL_UNSIGNED_INT_IMAGE_2D_RECT:
case GL_UNSIGNED_INT_IMAGE_CUBE:
case GL_UNSIGNED_INT_IMAGE_BUFFER:
case GL_UNSIGNED_INT_IMAGE_1D_ARRAY:
case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:
case GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY:
case GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE:
case GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY:
{
// clang-format off
const auto ResourceType =
dataType == GL_IMAGE_BUFFER ||
dataType == GL_INT_IMAGE_BUFFER ||
dataType == GL_UNSIGNED_INT_IMAGE_BUFFER ?
SHADER_RESOURCE_TYPE_BUFFER_UAV :
SHADER_RESOURCE_TYPE_TEXTURE_UAV;
// clang-format on
RemoveArrayBrackets(Name.data());
Images.emplace_back(
NamesPool.emplace(Name.data()).first->c_str(),
ShaderStages,
ResourceType,
static_cast<Uint32>(size),
dataType,
ResDim,
IsMS //
);
break;
}
#endif
default:
// Some other uniform type like scalar, matrix etc.
break;
}
}
for (int i = 0; i < numActiveUniformBlocks; i++)
{
// In contrast to shader uniforms, every element in uniform block array is enumerated individually
GLsizei NameLen = 0;
glGetActiveUniformBlockName(GLProgram, i, MaxNameLength, &NameLen, Name.data());
CHECK_GL_ERROR_AND_THROW("Unable to get active uniform block name\n");
VERIFY(NameLen < MaxNameLength && static_cast<size_t>(NameLen) == strlen(Name.data()), "Incorrect uniform block name");
// glGetActiveUniformBlockName( program, uniformBlockIndex, bufSize, length, uniformBlockName );
// is equivalent to
// glGetProgramResourceName(program, GL_UNIFORM_BLOCK, uniformBlockIndex, bufSize, length, uniformBlockName);
auto UniformBlockIndex = glGetUniformBlockIndex(GLProgram, Name.data());
CHECK_GL_ERROR_AND_THROW("Unable to get active uniform block index\n");
// glGetUniformBlockIndex( program, uniformBlockName );
// is equivalent to
// glGetProgramResourceIndex( program, GL_UNIFORM_BLOCK, uniformBlockName );
bool IsNewBlock = true;
GLint ArraySize = 1;
auto* OpenBacketPtr = strchr(Name.data(), '[');
if (OpenBacketPtr != nullptr)
{
auto Ind = atoi(OpenBacketPtr + 1);
ArraySize = std::max(ArraySize, Ind + 1);
*OpenBacketPtr = 0;
if (!UniformBlocks.empty())
{
// Look at previous uniform block to check if it is the same array
auto& LastBlock = UniformBlocks.back();
if (strcmp(LastBlock.Name, Name.data()) == 0)
{
ArraySize = std::max(ArraySize, static_cast<GLint>(LastBlock.ArraySize));
VERIFY(UniformBlockIndex == LastBlock.UBIndex + Ind, "Uniform block indices are expected to be continuous");
LastBlock.ArraySize = ArraySize;
IsNewBlock = false;
}
else
{
#ifdef DILIGENT_DEBUG
for (const auto& ub : UniformBlocks)
VERIFY(strcmp(ub.Name, Name.data()) != 0, "Uniform block with the name '", ub.Name, "' has already been enumerated");
#endif
}
}
}
if (IsNewBlock)
{
UniformBlocks.emplace_back(
NamesPool.emplace(Name.data()).first->c_str(),
ShaderStages,
SHADER_RESOURCE_TYPE_CONSTANT_BUFFER,
static_cast<Uint32>(ArraySize),
UniformBlockIndex //
);
}
}
#if GL_ARB_shader_storage_buffer_object
for (int i = 0; i < numActiveShaderStorageBlocks; ++i)
{
GLsizei Length = 0;
glGetProgramResourceName(GLProgram, GL_SHADER_STORAGE_BLOCK, i, MaxNameLength, &Length, Name.data());
CHECK_GL_ERROR_AND_THROW("Unable to get shader storage block name\n");
VERIFY(Length < MaxNameLength && static_cast<size_t>(Length) == strlen(Name.data()), "Incorrect shader storage block name");
auto SBIndex = glGetProgramResourceIndex(GLProgram, GL_SHADER_STORAGE_BLOCK, Name.data());
CHECK_GL_ERROR_AND_THROW("Unable to get shader storage block index\n");
bool IsNewBlock = true;
Int32 ArraySize = 1;
auto* OpenBacketPtr = strchr(Name.data(), '[');
if (OpenBacketPtr != nullptr)
{
auto Ind = atoi(OpenBacketPtr + 1);
ArraySize = std::max(ArraySize, Ind + 1);
*OpenBacketPtr = 0;
if (!StorageBlocks.empty())
{
// Look at previous storage block to check if it is the same array
auto& LastBlock = StorageBlocks.back();
if (strcmp(LastBlock.Name, Name.data()) == 0)
{
ArraySize = std::max(ArraySize, static_cast<GLint>(LastBlock.ArraySize));
VERIFY(static_cast<GLint>(SBIndex) == LastBlock.SBIndex + Ind, "Storage block indices are expected to be continuous");
LastBlock.ArraySize = ArraySize;
IsNewBlock = false;
}
else
{
# ifdef DILIGENT_DEBUG
for (const auto& sb : StorageBlocks)
VERIFY(strcmp(sb.Name, Name.data()) != 0, "Storage block with the name \"", sb.Name, "\" has already been enumerated");
# endif
}
}
}
if (IsNewBlock)
{
StorageBlocks.emplace_back(
NamesPool.emplace(Name.data()).first->c_str(),
ShaderStages,
SHADER_RESOURCE_TYPE_BUFFER_UAV,
static_cast<Uint32>(ArraySize),
SBIndex //
);
}
}
#endif
State.SetProgram(GLObjectWrappers::GLProgramObj::Null());
AllocateResources(UniformBlocks, Textures, Images, StorageBlocks);
}
ShaderResourceDesc ShaderResourcesGL::GetResourceDesc(Uint32 Index) const
{
if (Index < m_NumUniformBuffers)
return GetUniformBuffer(Index).GetResourceDesc();
else
Index -= m_NumUniformBuffers;
if (Index < m_NumTextures)
return GetTexture(Index).GetResourceDesc();
else
Index -= m_NumTextures;
if (Index < m_NumImages)
return GetImage(Index).GetResourceDesc();
else
Index -= m_NumImages;
if (Index < m_NumStorageBlocks)
return GetStorageBlock(Index).GetResourceDesc();
else
Index -= m_NumStorageBlocks;
LOG_ERROR_MESSAGE("Resource index ", Index + GetVariableCount(), " is invalid");
return ShaderResourceDesc{};
}
} // namespace Diligent
|