Blender  V3.3
gpu_shader.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2005 Blender Foundation. All rights reserved. */
3 
8 #include "MEM_guardedalloc.h"
9 
10 #include "BLI_string_utils.h"
11 
12 #include "GPU_capabilities.h"
13 #include "GPU_debug.h"
14 #include "GPU_matrix.h"
15 #include "GPU_platform.h"
16 
17 #include "gpu_backend.hh"
18 #include "gpu_context_private.hh"
22 #include "gpu_shader_private.hh"
23 
24 #include <string>
25 
27 
28 namespace blender::gpu {
29 
30 std::string Shader::defines_declare(const shader::ShaderCreateInfo &info) const
31 {
32  std::string defines;
33  for (const auto &def : info.defines_) {
34  defines += "#define ";
35  defines += def[0];
36  defines += " ";
37  defines += def[1];
38  defines += "\n";
39  }
40  return defines;
41 }
42 
43 } // namespace blender::gpu
44 
45 using namespace blender;
46 using namespace blender::gpu;
47 
49 
50 /* -------------------------------------------------------------------- */
54 Shader::Shader(const char *sh_name)
55 {
56  BLI_strncpy(this->name, sh_name, sizeof(this->name));
57 }
58 
60 {
61  delete interface;
62 }
63 
65 {
66  BLI_assert(sources.size() == 0);
67  /* Version needs to be first. Exact values will be added by implementation. */
68  sources.append("version");
69  /* Define to identify code usage in shading language. */
70  sources.append("#define GPU_SHADER\n");
71  /* some useful defines to detect GPU type */
73  sources.append("#define GPU_ATI\n");
74  }
76  sources.append("#define GPU_NVIDIA\n");
77  }
79  sources.append("#define GPU_INTEL\n");
80  }
81  /* some useful defines to detect OS type */
83  sources.append("#define OS_WIN\n");
84  }
86  sources.append("#define OS_MAC\n");
87  }
89  sources.append("#define OS_UNIX\n");
90  }
91  /* API Definition */
93  switch (backend) {
94  case GPU_BACKEND_OPENGL:
95  sources.append("#define GPU_OPENGL\n");
96  break;
97  default:
98  BLI_assert(false && "Invalid GPU Backend Type");
99  break;
100  }
101 
102  if (GPU_crappy_amd_driver()) {
103  sources.append("#define GPU_DEPRECATED_AMD_DRIVER\n");
104  }
105 }
106 
107 GPUShader *GPU_shader_create_ex(const char *vertcode,
108  const char *fragcode,
109  const char *geomcode,
110  const char *computecode,
111  const char *libcode,
112  const char *defines,
113  const eGPUShaderTFBType tf_type,
114  const char **tf_names,
115  const int tf_count,
116  const char *shname)
117 {
118  /* At least a vertex shader and a fragment shader are required, or only a compute shader. */
119  BLI_assert(((fragcode != nullptr) && (vertcode != nullptr) && (computecode == nullptr)) ||
120  ((fragcode == nullptr) && (vertcode == nullptr) && (geomcode == nullptr) &&
121  (computecode != nullptr)));
122 
123  Shader *shader = GPUBackend::get()->shader_alloc(shname);
124 
125  if (vertcode) {
126  Vector<const char *> sources;
127  standard_defines(sources);
128  sources.append("#define GPU_VERTEX_SHADER\n");
129  sources.append("#define IN_OUT out\n");
130  if (geomcode) {
131  sources.append("#define USE_GEOMETRY_SHADER\n");
132  }
133  if (defines) {
134  sources.append(defines);
135  }
136  sources.append(vertcode);
137 
138  shader->vertex_shader_from_glsl(sources);
139  }
140 
141  if (fragcode) {
142  Vector<const char *> sources;
143  standard_defines(sources);
144  sources.append("#define GPU_FRAGMENT_SHADER\n");
145  sources.append("#define IN_OUT in\n");
146  if (geomcode) {
147  sources.append("#define USE_GEOMETRY_SHADER\n");
148  }
149  if (defines) {
150  sources.append(defines);
151  }
152  if (libcode) {
153  sources.append(libcode);
154  }
155  sources.append(fragcode);
156 
157  shader->fragment_shader_from_glsl(sources);
158  }
159 
160  if (geomcode) {
161  Vector<const char *> sources;
162  standard_defines(sources);
163  sources.append("#define GPU_GEOMETRY_SHADER\n");
164  if (defines) {
165  sources.append(defines);
166  }
167  sources.append(geomcode);
168 
169  shader->geometry_shader_from_glsl(sources);
170  }
171 
172  if (computecode) {
173  Vector<const char *> sources;
174  standard_defines(sources);
175  sources.append("#define GPU_COMPUTE_SHADER\n");
176  if (defines) {
177  sources.append(defines);
178  }
179  if (libcode) {
180  sources.append(libcode);
181  }
182  sources.append(computecode);
183 
184  shader->compute_shader_from_glsl(sources);
185  }
186 
187  if (tf_names != nullptr && tf_count > 0) {
188  BLI_assert(tf_type != GPU_SHADER_TFB_NONE);
189  shader->transform_feedback_names_set(Span<const char *>(tf_names, tf_count), tf_type);
190  }
191 
192  if (!shader->finalize()) {
193  delete shader;
194  return nullptr;
195  };
196 
197  return wrap(shader);
198 }
199 
201 {
202  delete unwrap(shader);
203 }
204 
207 /* -------------------------------------------------------------------- */
211 GPUShader *GPU_shader_create(const char *vertcode,
212  const char *fragcode,
213  const char *geomcode,
214  const char *libcode,
215  const char *defines,
216  const char *shname)
217 {
218  return GPU_shader_create_ex(vertcode,
219  fragcode,
220  geomcode,
221  nullptr,
222  libcode,
223  defines,
225  nullptr,
226  0,
227  shname);
228 }
229 
230 GPUShader *GPU_shader_create_compute(const char *computecode,
231  const char *libcode,
232  const char *defines,
233  const char *shname)
234 {
235  return GPU_shader_create_ex(nullptr,
236  nullptr,
237  nullptr,
238  computecode,
239  libcode,
240  defines,
242  nullptr,
243  0,
244  shname);
245 }
246 
247 const GPUShaderCreateInfo *GPU_shader_create_info_get(const char *info_name)
248 {
249  return gpu_shader_create_info_get(info_name);
250 }
251 
252 bool GPU_shader_create_info_check_error(const GPUShaderCreateInfo *_info, char r_error[128])
253 {
254  using namespace blender::gpu::shader;
255  const ShaderCreateInfo &info = *reinterpret_cast<const ShaderCreateInfo *>(_info);
256  std::string error = info.check_error();
257  if (error.length() == 0) {
258  return true;
259  }
260 
261  BLI_strncpy(r_error, error.c_str(), 128);
262  return false;
263 }
264 
266 {
267  using namespace blender::gpu::shader;
268  const GPUShaderCreateInfo *_info = gpu_shader_create_info_get(info_name);
269  const ShaderCreateInfo &info = *reinterpret_cast<const ShaderCreateInfo *>(_info);
270  if (!info.do_static_compilation_) {
271  printf("Warning: Trying to compile \"%s\" which was not marked for static compilation.\n",
272  info.name_.c_str());
273  }
274  return GPU_shader_create_from_info(_info);
275 }
276 
278 {
279  using namespace blender::gpu::shader;
280  const ShaderCreateInfo &info = *reinterpret_cast<const ShaderCreateInfo *>(_info);
281 
282  const_cast<ShaderCreateInfo &>(info).finalize();
283 
285 
286  const std::string error = info.check_error();
287  if (!error.empty()) {
288  printf("%s\n", error.c_str());
289  BLI_assert(false);
290  }
291 
292  Shader *shader = GPUBackend::get()->shader_alloc(info.name_.c_str());
293 
294  std::string defines = shader->defines_declare(info);
295  std::string resources = shader->resources_declare(info);
296 
297  if (info.legacy_resource_location_ == false) {
298  defines += "#define USE_GPU_SHADER_CREATE_INFO\n";
299  }
300 
301  Vector<const char *> typedefs;
302  if (!info.typedef_sources_.is_empty() || !info.typedef_source_generated.empty()) {
303  typedefs.append(gpu_shader_dependency_get_source("GPU_shader_shared_utils.h").c_str());
304  }
305  if (!info.typedef_source_generated.empty()) {
306  typedefs.append(info.typedef_source_generated.c_str());
307  }
308  for (auto filename : info.typedef_sources_) {
309  typedefs.append(gpu_shader_dependency_get_source(filename).c_str());
310  }
311 
312  if (!info.vertex_source_.is_empty()) {
314  std::string interface = shader->vertex_interface_declare(info);
315 
316  Vector<const char *> sources;
317  standard_defines(sources);
318  sources.append("#define GPU_VERTEX_SHADER\n");
319  if (!info.geometry_source_.is_empty()) {
320  sources.append("#define USE_GEOMETRY_SHADER\n");
321  }
322  sources.append(defines.c_str());
323  sources.extend(typedefs);
324  sources.append(resources.c_str());
325  sources.append(interface.c_str());
326  sources.extend(code);
327  sources.extend(info.dependencies_generated);
328  sources.append(info.vertex_source_generated.c_str());
329 
330  shader->vertex_shader_from_glsl(sources);
331  }
332 
333  if (!info.fragment_source_.is_empty()) {
335  std::string interface = shader->fragment_interface_declare(info);
336 
337  Vector<const char *> sources;
338  standard_defines(sources);
339  sources.append("#define GPU_FRAGMENT_SHADER\n");
340  if (!info.geometry_source_.is_empty()) {
341  sources.append("#define USE_GEOMETRY_SHADER\n");
342  }
343  sources.append(defines.c_str());
344  sources.extend(typedefs);
345  sources.append(resources.c_str());
346  sources.append(interface.c_str());
347  sources.extend(code);
348  sources.extend(info.dependencies_generated);
349  sources.append(info.fragment_source_generated.c_str());
350 
351  shader->fragment_shader_from_glsl(sources);
352  }
353 
354  if (!info.geometry_source_.is_empty()) {
356  std::string layout = shader->geometry_layout_declare(info);
357  std::string interface = shader->geometry_interface_declare(info);
358 
359  Vector<const char *> sources;
360  standard_defines(sources);
361  sources.append("#define GPU_GEOMETRY_SHADER\n");
362  sources.append(defines.c_str());
363  sources.extend(typedefs);
364  sources.append(resources.c_str());
365  sources.append(layout.c_str());
366  sources.append(interface.c_str());
367  sources.append(info.geometry_source_generated.c_str());
368  sources.extend(code);
369 
370  shader->geometry_shader_from_glsl(sources);
371  }
372 
373  if (!info.compute_source_.is_empty()) {
375  std::string layout = shader->compute_layout_declare(info);
376 
377  Vector<const char *> sources;
378  standard_defines(sources);
379  sources.append("#define GPU_COMPUTE_SHADER\n");
380  sources.append(defines.c_str());
381  sources.extend(typedefs);
382  sources.append(resources.c_str());
383  sources.append(layout.c_str());
384  sources.extend(code);
385 
386  shader->compute_shader_from_glsl(sources);
387  }
388 
389  if (!shader->finalize(&info)) {
390  delete shader;
392  return nullptr;
393  }
394 
396  return wrap(shader);
397 }
398 
400  const char *fragcode,
401  const char *geomcode,
402  const char *libcode,
403  const char *defines,
404  const char *name)
405 {
406  char *libcodecat = nullptr;
407 
408  if (libcode == nullptr) {
410  }
411  else {
412  libcode = libcodecat = BLI_strdupcat(libcode, datatoc_gpu_shader_colorspace_lib_glsl);
413  }
414 
415  /* Use pyGPUShader as default name for shader. */
416  const char *shname = name != nullptr ? name : "pyGPUShader";
417 
418  GPUShader *sh = GPU_shader_create_ex(vertcode,
419  fragcode,
420  geomcode,
421  nullptr,
422  libcode,
423  defines,
425  nullptr,
426  0,
427  shname);
428 
429  MEM_SAFE_FREE(libcodecat);
430  return sh;
431 }
432 
433 static const char *string_join_array_maybe_alloc(const char **str_arr, bool *r_is_alloc)
434 {
435  bool is_alloc = false;
436  if (str_arr == nullptr) {
437  *r_is_alloc = false;
438  return nullptr;
439  }
440  /* Skip empty strings (avoid alloc if we can). */
441  while (str_arr[0] && str_arr[0][0] == '\0') {
442  str_arr++;
443  }
444  int i;
445  for (i = 0; str_arr[i]; i++) {
446  if (i != 0 && str_arr[i][0] != '\0') {
447  is_alloc = true;
448  }
449  }
450  *r_is_alloc = is_alloc;
451  if (is_alloc) {
452  return BLI_string_join_arrayN(str_arr, i);
453  }
454 
455  return str_arr[0];
456 }
457 
459  const struct GPU_ShaderCreateFromArray_Params *params, const char *func, int line)
460 {
461  struct {
462  const char *str;
463  bool is_alloc;
464  } str_dst[4] = {{nullptr}};
465  const char **str_src[4] = {params->vert, params->frag, params->geom, params->defs};
466 
467  for (int i = 0; i < ARRAY_SIZE(str_src); i++) {
468  str_dst[i].str = string_join_array_maybe_alloc(str_src[i], &str_dst[i].is_alloc);
469  }
470 
471  char name[64];
472  BLI_snprintf(name, sizeof(name), "%s_%d", func, line);
473 
475  str_dst[0].str, str_dst[1].str, str_dst[2].str, nullptr, str_dst[3].str, name);
476 
477  for (auto &i : str_dst) {
478  if (i.is_alloc) {
479  MEM_freeN((void *)i.str);
480  }
481  }
482  return sh;
483 }
484 
487 /* -------------------------------------------------------------------- */
491 void GPU_shader_bind(GPUShader *gpu_shader)
492 {
493  Shader *shader = unwrap(gpu_shader);
494 
495  Context *ctx = Context::get();
496 
497  if (ctx->shader != shader) {
498  ctx->shader = shader;
499  shader->bind();
500  GPU_matrix_bind(gpu_shader);
501  GPU_shader_set_srgb_uniform(gpu_shader);
502  }
503  else {
505  GPU_shader_set_srgb_uniform(gpu_shader);
506  }
507  if (GPU_matrix_dirty_get()) {
508  GPU_matrix_bind(gpu_shader);
509  }
510  }
511 }
512 
514 {
515 #ifndef NDEBUG
516  Context *ctx = Context::get();
517  if (ctx->shader) {
518  ctx->shader->unbind();
519  }
520  ctx->shader = nullptr;
521 #endif
522 }
523 
526 /* -------------------------------------------------------------------- */
530 const char *GPU_shader_get_name(GPUShader *shader)
531 {
532  return unwrap(shader)->name_get();
533 }
534 
537 /* -------------------------------------------------------------------- */
544 {
545  return unwrap(shader)->transform_feedback_enable(vertbuf);
546 }
547 
549 {
550  unwrap(shader)->transform_feedback_disable();
551 }
552 
555 /* -------------------------------------------------------------------- */
559 int GPU_shader_get_uniform(GPUShader *shader, const char *name)
560 {
561  ShaderInterface *interface = unwrap(shader)->interface;
562  const ShaderInput *uniform = interface->uniform_get(name);
563  return uniform ? uniform->location : -1;
564 }
565 
566 int GPU_shader_get_builtin_uniform(GPUShader *shader, int builtin)
567 {
568  ShaderInterface *interface = unwrap(shader)->interface;
569  return interface->uniform_builtin((GPUUniformBuiltin)builtin);
570 }
571 
572 int GPU_shader_get_builtin_block(GPUShader *shader, int builtin)
573 {
574  ShaderInterface *interface = unwrap(shader)->interface;
575  return interface->ubo_builtin((GPUUniformBlockBuiltin)builtin);
576 }
577 
578 int GPU_shader_get_ssbo(GPUShader *shader, const char *name)
579 {
580  ShaderInterface *interface = unwrap(shader)->interface;
581  const ShaderInput *ssbo = interface->ssbo_get(name);
582  return ssbo ? ssbo->location : -1;
583 }
584 
585 int GPU_shader_get_uniform_block(GPUShader *shader, const char *name)
586 {
587  ShaderInterface *interface = unwrap(shader)->interface;
588  const ShaderInput *ubo = interface->ubo_get(name);
589  return ubo ? ubo->location : -1;
590 }
591 
592 int GPU_shader_get_uniform_block_binding(GPUShader *shader, const char *name)
593 {
594  ShaderInterface *interface = unwrap(shader)->interface;
595  const ShaderInput *ubo = interface->ubo_get(name);
596  return ubo ? ubo->binding : -1;
597 }
598 
599 int GPU_shader_get_texture_binding(GPUShader *shader, const char *name)
600 {
601  ShaderInterface *interface = unwrap(shader)->interface;
602  const ShaderInput *tex = interface->uniform_get(name);
603  return tex ? tex->binding : -1;
604 }
605 
606 int GPU_shader_get_attribute(GPUShader *shader, const char *name)
607 {
608  ShaderInterface *interface = unwrap(shader)->interface;
609  const ShaderInput *attr = interface->attr_get(name);
610  return attr ? attr->location : -1;
611 }
612 
615 /* -------------------------------------------------------------------- */
620 {
621  return unwrap(shader)->program_handle_get();
622 }
623 
626 /* -------------------------------------------------------------------- */
631  GPUShader *shader, int loc, int len, int arraysize, const float *value)
632 {
633  unwrap(shader)->uniform_float(loc, len, arraysize, value);
634 }
635 
637  GPUShader *shader, int loc, int len, int arraysize, const int *value)
638 {
639  unwrap(shader)->uniform_int(loc, len, arraysize, value);
640 }
641 
642 void GPU_shader_uniform_int(GPUShader *shader, int location, int value)
643 {
644  GPU_shader_uniform_vector_int(shader, location, 1, 1, &value);
645 }
646 
647 void GPU_shader_uniform_float(GPUShader *shader, int location, float value)
648 {
649  GPU_shader_uniform_vector(shader, location, 1, 1, &value);
650 }
651 
652 void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value)
653 {
654  const int loc = GPU_shader_get_uniform(sh, name);
655  GPU_shader_uniform_int(sh, loc, value);
656 }
657 
658 void GPU_shader_uniform_1b(GPUShader *sh, const char *name, bool value)
659 {
660  GPU_shader_uniform_1i(sh, name, value ? 1 : 0);
661 }
662 
663 void GPU_shader_uniform_2f(GPUShader *sh, const char *name, float x, float y)
664 {
665  const float data[2] = {x, y};
667 }
668 
669 void GPU_shader_uniform_3f(GPUShader *sh, const char *name, float x, float y, float z)
670 {
671  const float data[3] = {x, y, z};
673 }
674 
675 void GPU_shader_uniform_4f(GPUShader *sh, const char *name, float x, float y, float z, float w)
676 {
677  const float data[4] = {x, y, z, w};
679 }
680 
681 void GPU_shader_uniform_1f(GPUShader *sh, const char *name, float value)
682 {
683  const int loc = GPU_shader_get_uniform(sh, name);
684  GPU_shader_uniform_float(sh, loc, value);
685 }
686 
687 void GPU_shader_uniform_2fv(GPUShader *sh, const char *name, const float data[2])
688 {
689  const int loc = GPU_shader_get_uniform(sh, name);
690  GPU_shader_uniform_vector(sh, loc, 2, 1, data);
691 }
692 
693 void GPU_shader_uniform_3fv(GPUShader *sh, const char *name, const float data[3])
694 {
695  const int loc = GPU_shader_get_uniform(sh, name);
696  GPU_shader_uniform_vector(sh, loc, 3, 1, data);
697 }
698 
699 void GPU_shader_uniform_4fv(GPUShader *sh, const char *name, const float data[4])
700 {
701  const int loc = GPU_shader_get_uniform(sh, name);
702  GPU_shader_uniform_vector(sh, loc, 4, 1, data);
703 }
704 
705 void GPU_shader_uniform_mat4(GPUShader *sh, const char *name, const float data[4][4])
706 {
707  const int loc = GPU_shader_get_uniform(sh, name);
708  GPU_shader_uniform_vector(sh, loc, 16, 1, (const float *)data);
709 }
710 
711 void GPU_shader_uniform_2fv_array(GPUShader *sh, const char *name, int len, const float (*val)[2])
712 {
713  const int loc = GPU_shader_get_uniform(sh, name);
714  GPU_shader_uniform_vector(sh, loc, 2, len, (const float *)val);
715 }
716 
717 void GPU_shader_uniform_4fv_array(GPUShader *sh, const char *name, int len, const float (*val)[4])
718 {
719  const int loc = GPU_shader_get_uniform(sh, name);
720  GPU_shader_uniform_vector(sh, loc, 4, len, (const float *)val);
721 }
722 
725 /* -------------------------------------------------------------------- */
737 static bool g_shader_builtin_srgb_is_dirty = false;
738 
740 {
742 }
743 
745 {
747  if (loc != -1) {
749  }
751 }
752 
753 void GPU_shader_set_framebuffer_srgb_target(int use_srgb_to_linear)
754 {
755  if (g_shader_builtin_srgb_transform != use_srgb_to_linear) {
756  g_shader_builtin_srgb_transform = use_srgb_to_linear;
758  }
759 }
760 
#define BLI_assert(a)
Definition: BLI_assert.h:46
char * BLI_strdupcat(const char *__restrict str1, const char *__restrict str2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
Definition: string.c:47
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
Definition: string.c:64
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
char * BLI_string_join_arrayN(const char *strings[], uint strings_len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: string_utils.c:384
#define ARRAY_SIZE(arr)
bool GPU_crappy_amd_driver(void)
eGPUBackendType GPU_backend_get_type(void)
Definition: gpu_context.cc:274
void GPU_debug_group_end(void)
Definition: gpu_debug.cc:32
void GPU_debug_group_begin(const char *name)
Definition: gpu_debug.cc:21
#define GPU_DEBUG_SHADER_COMPILATION_GROUP
Definition: GPU_debug.h:18
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble z
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
bool GPU_matrix_dirty_get(void)
Definition: gpu_matrix.cc:655
void GPU_matrix_bind(struct GPUShader *shader)
Definition: gpu_matrix.cc:611
eGPUBackendType
Definition: GPU_platform.h:15
@ GPU_BACKEND_OPENGL
Definition: GPU_platform.h:17
@ GPU_DRIVER_ANY
Definition: GPU_platform.h:47
@ GPU_OS_WIN
Definition: GPU_platform.h:37
@ GPU_OS_UNIX
Definition: GPU_platform.h:39
@ GPU_OS_ANY
Definition: GPU_platform.h:40
@ GPU_OS_MAC
Definition: GPU_platform.h:38
@ GPU_DEVICE_ATI
Definition: GPU_platform.h:25
@ GPU_DEVICE_NVIDIA
Definition: GPU_platform.h:24
@ GPU_DEVICE_ANY
Definition: GPU_platform.h:31
@ GPU_DEVICE_INTEL
Definition: GPU_platform.h:26
bool GPU_type_matches(eGPUDeviceType device, eGPUOSType os, eGPUDriverType driver)
struct GPUShader GPUShader
Definition: GPU_shader.h:20
eGPUShaderTFBType
Definition: GPU_shader.h:22
@ GPU_SHADER_TFB_NONE
Definition: GPU_shader.h:23
GPUUniformBuiltin
Definition: GPU_shader.h:111
@ GPU_UNIFORM_SRGB_TRANSFORM
Definition: GPU_shader.h:133
struct GPUShaderCreateInfo GPUShaderCreateInfo
Definition: GPU_shader.h:18
GPUUniformBlockBuiltin
Definition: GPU_shader.h:138
struct GPUVertBuf GPUVertBuf
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
constexpr bool is_empty() const
constexpr const char * c_str() const
int64_t size() const
Definition: BLI_vector.hh:694
void append(const T &value)
Definition: BLI_vector.hh:433
void extend(Span< T > array)
Definition: BLI_vector.hh:530
static Context * get()
Definition: gpu_context.cc:82
static GPUBackend * get()
Definition: gpu_context.cc:292
virtual Shader * shader_alloc(const char *name)=0
int32_t uniform_builtin(const GPUUniformBuiltin builtin) const
int32_t ubo_builtin(const GPUUniformBlockBuiltin builtin) const
virtual void unbind()=0
virtual void transform_feedback_names_set(Span< const char * > name_list, eGPUShaderTFBType geom_type)=0
std::string defines_declare(const shader::ShaderCreateInfo &info) const
Definition: gpu_shader.cc:30
virtual void fragment_shader_from_glsl(MutableSpan< const char * > sources)=0
virtual std::string compute_layout_declare(const shader::ShaderCreateInfo &info) const =0
ShaderInterface * interface
virtual bool finalize(const shader::ShaderCreateInfo *info=nullptr)=0
virtual std::string resources_declare(const shader::ShaderCreateInfo &info) const =0
virtual void vertex_shader_from_glsl(MutableSpan< const char * > sources)=0
virtual void compute_shader_from_glsl(MutableSpan< const char * > sources)=0
virtual void geometry_shader_from_glsl(MutableSpan< const char * > sources)=0
virtual void bind()=0
virtual std::string geometry_layout_declare(const shader::ShaderCreateInfo &info) const =0
Shader(const char *name)
Definition: gpu_shader.cc:54
int len
Definition: draw_manager.c:108
#define str(s)
GPUShader * GPU_shader_create(const char *vertcode, const char *fragcode, const char *geomcode, const char *libcode, const char *defines, const char *shname)
Definition: gpu_shader.cc:211
int GPU_shader_get_uniform(GPUShader *shader, const char *name)
Definition: gpu_shader.cc:559
void GPU_shader_uniform_vector_int(GPUShader *shader, int loc, int len, int arraysize, const int *value)
Definition: gpu_shader.cc:636
void GPU_shader_uniform_2fv(GPUShader *sh, const char *name, const float data[2])
Definition: gpu_shader.cc:687
void GPU_shader_set_srgb_uniform(GPUShader *shader)
Definition: gpu_shader.cc:744
GPUShader * GPU_shader_create_from_python(const char *vertcode, const char *fragcode, const char *geomcode, const char *libcode, const char *defines, const char *name)
Definition: gpu_shader.cc:399
static bool gpu_shader_srgb_uniform_dirty_get()
Definition: gpu_shader.cc:739
static const char * string_join_array_maybe_alloc(const char **str_arr, bool *r_is_alloc)
Definition: gpu_shader.cc:433
void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value)
Definition: gpu_shader.cc:652
static int g_shader_builtin_srgb_transform
Definition: gpu_shader.cc:736
void GPU_shader_uniform_3f(GPUShader *sh, const char *name, float x, float y, float z)
Definition: gpu_shader.cc:669
void GPU_shader_uniform_2f(GPUShader *sh, const char *name, float x, float y)
Definition: gpu_shader.cc:663
void GPU_shader_uniform_2fv_array(GPUShader *sh, const char *name, int len, const float(*val)[2])
Definition: gpu_shader.cc:711
void GPU_shader_set_framebuffer_srgb_target(int use_srgb_to_linear)
Definition: gpu_shader.cc:753
void GPU_shader_uniform_1f(GPUShader *sh, const char *name, float value)
Definition: gpu_shader.cc:681
void GPU_shader_bind(GPUShader *gpu_shader)
Definition: gpu_shader.cc:491
static void standard_defines(Vector< const char * > &sources)
Definition: gpu_shader.cc:64
void GPU_shader_uniform_3fv(GPUShader *sh, const char *name, const float data[3])
Definition: gpu_shader.cc:693
GPUShader * GPU_shader_create_from_info_name(const char *info_name)
Definition: gpu_shader.cc:265
void GPU_shader_uniform_vector(GPUShader *shader, int loc, int len, int arraysize, const float *value)
Definition: gpu_shader.cc:630
int GPU_shader_get_attribute(GPUShader *shader, const char *name)
Definition: gpu_shader.cc:606
GPUShader * GPU_shader_create_ex(const char *vertcode, const char *fragcode, const char *geomcode, const char *computecode, const char *libcode, const char *defines, const eGPUShaderTFBType tf_type, const char **tf_names, const int tf_count, const char *shname)
Definition: gpu_shader.cc:107
void GPU_shader_uniform_4fv_array(GPUShader *sh, const char *name, int len, const float(*val)[4])
Definition: gpu_shader.cc:717
char datatoc_gpu_shader_colorspace_lib_glsl[]
Definition: gpu_shader.cc:26
void GPU_shader_uniform_int(GPUShader *shader, int location, int value)
Definition: gpu_shader.cc:642
int GPU_shader_get_builtin_block(GPUShader *shader, int builtin)
Definition: gpu_shader.cc:572
int GPU_shader_get_uniform_block_binding(GPUShader *shader, const char *name)
Definition: gpu_shader.cc:592
void GPU_shader_transform_feedback_disable(GPUShader *shader)
Definition: gpu_shader.cc:548
int GPU_shader_get_program(GPUShader *shader)
Definition: gpu_shader.cc:619
void GPU_shader_uniform_1b(GPUShader *sh, const char *name, bool value)
Definition: gpu_shader.cc:658
const char * GPU_shader_get_name(GPUShader *shader)
Definition: gpu_shader.cc:530
void GPU_shader_uniform_4fv(GPUShader *sh, const char *name, const float data[4])
Definition: gpu_shader.cc:699
GPUShader * GPU_shader_create_compute(const char *computecode, const char *libcode, const char *defines, const char *shname)
Definition: gpu_shader.cc:230
void GPU_shader_uniform_4f(GPUShader *sh, const char *name, float x, float y, float z, float w)
Definition: gpu_shader.cc:675
int GPU_shader_get_uniform_block(GPUShader *shader, const char *name)
Definition: gpu_shader.cc:585
void GPU_shader_uniform_mat4(GPUShader *sh, const char *name, const float data[4][4])
Definition: gpu_shader.cc:705
int GPU_shader_get_texture_binding(GPUShader *shader, const char *name)
Definition: gpu_shader.cc:599
int GPU_shader_get_builtin_uniform(GPUShader *shader, int builtin)
Definition: gpu_shader.cc:566
void GPU_shader_free(GPUShader *shader)
Definition: gpu_shader.cc:200
void GPU_shader_uniform_float(GPUShader *shader, int location, float value)
Definition: gpu_shader.cc:647
bool GPU_shader_create_info_check_error(const GPUShaderCreateInfo *_info, char r_error[128])
Definition: gpu_shader.cc:252
static bool g_shader_builtin_srgb_is_dirty
Definition: gpu_shader.cc:737
void GPU_shader_unbind()
Definition: gpu_shader.cc:513
bool GPU_shader_transform_feedback_enable(GPUShader *shader, GPUVertBuf *vertbuf)
Definition: gpu_shader.cc:543
int GPU_shader_get_ssbo(GPUShader *shader, const char *name)
Definition: gpu_shader.cc:578
const GPUShaderCreateInfo * GPU_shader_create_info_get(const char *info_name)
Definition: gpu_shader.cc:247
struct GPUShader * GPU_shader_create_from_arrays_impl(const struct GPU_ShaderCreateFromArray_Params *params, const char *func, int line)
Definition: gpu_shader.cc:458
GPUShader * GPU_shader_create_from_info(const GPUShaderCreateInfo *_info)
Definition: gpu_shader.cc:277
const GPUShaderCreateInfo * gpu_shader_create_info_get(const char *info_name)
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
ccl_gpu_kernel_postfix ccl_global float int int int int sh
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
static void error(const char *str)
Definition: meshlaplacian.c:51
StringRefNull gpu_shader_dependency_get_source(const StringRefNull shader_source_name)
Vector< const char * > gpu_shader_dependency_get_resolved_source(const StringRefNull shader_source_name)
static GPUContext * wrap(Context *ctx)
static Context * unwrap(GPUContext *ctx)
signed int int32_t
Definition: stdint.h:77
Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correc...
Vector< std::array< StringRefNull, 2 > > defines_