45 glGetActiveUniformsiv(program, 1, &uniform_index, GL_UNIFORM_TYPE, &type);
52 case GL_SAMPLER_CUBE_MAP_ARRAY_ARB:
53 case GL_SAMPLER_1D_SHADOW:
54 case GL_SAMPLER_2D_SHADOW:
55 case GL_SAMPLER_1D_ARRAY:
56 case GL_SAMPLER_2D_ARRAY:
57 case GL_SAMPLER_1D_ARRAY_SHADOW:
58 case GL_SAMPLER_2D_ARRAY_SHADOW:
59 case GL_SAMPLER_2D_MULTISAMPLE:
60 case GL_SAMPLER_2D_MULTISAMPLE_ARRAY:
61 case GL_SAMPLER_CUBE_SHADOW:
62 case GL_SAMPLER_BUFFER:
63 case GL_INT_SAMPLER_1D:
64 case GL_INT_SAMPLER_2D:
65 case GL_INT_SAMPLER_3D:
66 case GL_INT_SAMPLER_CUBE:
67 case GL_INT_SAMPLER_1D_ARRAY:
68 case GL_INT_SAMPLER_2D_ARRAY:
69 case GL_INT_SAMPLER_2D_MULTISAMPLE:
70 case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
71 case GL_INT_SAMPLER_BUFFER:
72 case GL_UNSIGNED_INT_SAMPLER_1D:
73 case GL_UNSIGNED_INT_SAMPLER_2D:
74 case GL_UNSIGNED_INT_SAMPLER_3D:
75 case GL_UNSIGNED_INT_SAMPLER_CUBE:
76 case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY:
77 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
78 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
79 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
80 case GL_UNSIGNED_INT_SAMPLER_BUFFER: {
83 int binding = *sampler_len;
84 glUniform1i(uniform_location, binding);
205 glGetIntegerv(GL_CURRENT_PROGRAM, (GLint *)&last_program);
208 glUseProgram(program);
210 GLint max_attr_name_len = 0, attr_len = 0;
211 glGetProgramiv(program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_attr_name_len);
212 glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &attr_len);
214 GLint max_ubo_name_len = 0, ubo_len = 0;
215 glGetProgramiv(program, GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH, &max_ubo_name_len);
216 glGetProgramiv(program, GL_ACTIVE_UNIFORM_BLOCKS, &ubo_len);
218 GLint max_uniform_name_len = 0, active_uniform_len = 0, uniform_len = 0;
219 glGetProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_uniform_name_len);
220 glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &active_uniform_len);
221 uniform_len = active_uniform_len;
223 GLint max_ssbo_name_len = 0, ssbo_len = 0;
224 glGetProgramInterfaceiv(program, GL_SHADER_STORAGE_BLOCK, GL_ACTIVE_RESOURCES, &ssbo_len);
225 glGetProgramInterfaceiv(
226 program, GL_SHADER_STORAGE_BLOCK, GL_MAX_NAME_LENGTH, &max_ssbo_name_len);
232 if (attr_len > 0 && max_attr_name_len == 0) {
233 max_attr_name_len = 256;
235 if (ubo_len > 0 && max_ubo_name_len == 0) {
236 max_ubo_name_len = 256;
238 if (uniform_len > 0 && max_uniform_name_len == 0) {
239 max_uniform_name_len = 256;
241 if (ssbo_len > 0 && max_ssbo_name_len == 0) {
242 max_ssbo_name_len = 256;
247 GLint max_ubo_uni_len = 0;
248 for (
int i = 0; i < ubo_len; i++) {
250 glGetActiveUniformBlockiv(program, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, &ubo_uni_len);
251 max_ubo_uni_len =
max_ii(max_ubo_uni_len, ubo_uni_len);
252 uniform_len -= ubo_uni_len;
257 GLint *ubo_uni_ids = (GLint *)
MEM_mallocN(
sizeof(GLint) * max_ubo_uni_len, __func__);
258 for (
int i = 0; i < ubo_len; i++) {
260 glGetActiveUniformBlockiv(program, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, &ubo_uni_len);
261 glGetActiveUniformBlockiv(program, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES, ubo_uni_ids);
262 for (
int u = 0; u < ubo_uni_len; u++) {
268 int input_tot_len = attr_len + ubo_len + uniform_len + ssbo_len;
271 const uint32_t name_buffer_len = attr_len * max_attr_name_len + ubo_len * max_ubo_name_len +
272 uniform_len * max_uniform_name_len +
273 ssbo_len * max_ssbo_name_len;
279 for (
int i = 0; i < attr_len; i++) {
281 GLsizei remaining_buffer = name_buffer_len - name_buffer_offset;
282 GLsizei name_len = 0;
286 glGetActiveAttrib(program, i, remaining_buffer, &name_len, &size, &type, name);
287 GLint location = glGetAttribLocation(program, name);
289 if (location == -1) {
294 input->
location = input->binding = location;
304 for (
int i = 0; i < ubo_len; i++) {
306 GLsizei remaining_buffer = name_buffer_len - name_buffer_offset;
307 GLsizei name_len = 0;
309 glGetActiveUniformBlockName(program, i, remaining_buffer, &name_len, name);
314 name_buffer_offset += this->
set_input_name(input, name, name_len);
319 for (
int i = 0,
sampler = 0, image = 0; i < active_uniform_len; i++) {
324 GLsizei remaining_buffer = name_buffer_len - name_buffer_offset;
325 GLsizei name_len = 0;
327 glGetActiveUniformName(program, i, remaining_buffer, &name_len, name);
330 input->
location = glGetUniformLocation(program, name);
333 name_buffer_offset += this->
set_input_name(input, name, name_len);
336 if (input->binding == -1) {
337 input->binding =
image_binding(program, i, input->location, &image);
344 for (
int i = 0; i < ssbo_len; i++) {
346 GLsizei remaining_buffer = name_buffer_len - name_buffer_offset;
347 GLsizei name_len = 0;
348 glGetProgramResourceName(
349 program, GL_SHADER_STORAGE_BLOCK, i, remaining_buffer, &name_len, name);
354 input->
binding = input->location = binding;
356 name_buffer_offset += this->
set_input_name(input, name, name_len);
376 if (name_buffer_offset < name_buffer_len) {
384 glUseProgram(last_program);
400 switch (res.bind_type) {
401 case ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER:
404 case ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER:
407 case ShaderCreateInfo::Resource::BindType::SAMPLER:
410 case ShaderCreateInfo::Resource::BindType::IMAGE:
416 size_t workaround_names_size = 0;
418 auto check_enabled_uniform = [&](
const char *uniform_name) {
419 if (glGetUniformLocation(program, uniform_name) != -1) {
420 workaround_uniform_names.
append(uniform_name);
427 check_enabled_uniform(
"gpu_BaseInstance");
442 glGetIntegerv(GL_CURRENT_PROGRAM, (GLint *)&last_program);
444 glUseProgram(program);
450 input->location = input->binding = glGetAttribLocation(program, attr.name.c_str());
453 input->location = input->binding = attr.index;
455 if (input->location != -1) {
467 if (res.bind_type == ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER) {
470 input->location = glGetUniformBlockIndex(program,
name_buffer_ + input->name_offset);
471 glUniformBlockBinding(program, input->location, res.slot);
473 input->binding = res.slot;
481 if (res.bind_type == ShaderCreateInfo::Resource::BindType::SAMPLER) {
486 input->location = glGetUniformLocation(program, res.sampler.name.c_str());
487 glUniform1i(input->location, res.slot);
489 input->binding = res.slot;
493 else if (res.bind_type == ShaderCreateInfo::Resource::BindType::IMAGE) {
497 input->location = glGetUniformLocation(program, res.image.name.c_str());
498 glUniform1i(input->location, res.slot);
500 input->binding = res.slot;
507 input->location = glGetUniformLocation(program,
name_buffer_ + input->name_offset);
513 for (
auto &name : workaround_uniform_names) {
515 input->location = glGetUniformLocation(program,
name_buffer_ + input->name_offset);
522 if (res.bind_type == ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER) {
524 input->location = input->binding = res.slot;
531 if (res.bind_type == ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER) {
535 BLI_assert_msg(0,
"Resource type is not supported for Geometry frequency");
543 input->location = constant_id++;
566 glUseProgram(last_program);