Blender  V2.93
gpu_shader.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2005 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "MEM_guardedalloc.h"
25 
26 #include "BLI_dynstr.h"
27 #include "BLI_math_base.h"
28 #include "BLI_math_vector.h"
29 #include "BLI_path_util.h"
30 #include "BLI_string.h"
31 #include "BLI_string_utils.h"
32 #include "BLI_utildefines.h"
33 #include "BLI_vector.hh"
34 
35 #include "BKE_appdir.h"
36 #include "BKE_global.h"
37 
38 #include "DNA_space_types.h"
39 
40 #include "GPU_capabilities.h"
41 #include "GPU_matrix.h"
42 #include "GPU_platform.h"
43 #include "GPU_shader.h"
44 #include "GPU_texture.h"
45 #include "GPU_uniform_buffer.h"
46 
47 #include "gpu_backend.hh"
48 #include "gpu_context_private.hh"
49 #include "gpu_shader_private.hh"
50 
51 #include "CLG_log.h"
52 
54 
55 static CLG_LogRef LOG = {"gpu.shader"};
56 
57 using namespace blender;
58 using namespace blender::gpu;
59 
61 
62 /* -------------------------------------------------------------------- */
66 void Shader::print_log(Span<const char *> sources, char *log, const char *stage, const bool error)
67 {
68  const char line_prefix[] = " | ";
69  char err_col[] = "\033[31;1m";
70  char warn_col[] = "\033[33;1m";
71  char info_col[] = "\033[0;2m";
72  char reset_col[] = "\033[0;0m";
73  char *sources_combined = BLI_string_join_arrayN((const char **)sources.data(), sources.size());
74  DynStr *dynstr = BLI_dynstr_new();
75 
76  if (!CLG_color_support_get(&LOG)) {
77  err_col[0] = warn_col[0] = info_col[0] = reset_col[0] = '\0';
78  }
79 
80  BLI_dynstr_appendf(dynstr, "\n");
81 
82  char *log_line = log, *line_end;
83  char *error_line_number_end;
84  int error_line, error_char, last_error_line = -2, last_error_char = -1;
85  bool found_line_id = false;
86  while ((line_end = strchr(log_line, '\n'))) {
87  /* Skip empty lines. */
88  if (line_end == log_line) {
89  log_line++;
90  continue;
91  }
92  /* 0 = error, 1 = warning. */
93  int type = -1;
94  /* Skip ERROR: or WARNING:. */
95  const char *prefix[] = {"ERROR", "WARNING"};
96  for (int i = 0; i < ARRAY_SIZE(prefix); i++) {
97  if (STREQLEN(log_line, prefix[i], strlen(prefix[i]))) {
98  log_line += strlen(prefix[i]);
99  type = i;
100  break;
101  }
102  }
103  /* Skip whitespaces and separators. */
104  while (ELEM(log_line[0], ':', '(', ' ')) {
105  log_line++;
106  }
107  /* Parse error line & char numbers. */
108  error_line = error_char = -1;
109  if (log_line[0] >= '0' && log_line[0] <= '9') {
110  error_line = (int)strtol(log_line, &error_line_number_end, 10);
111  /* Try to fetch the error character (not always available). */
112  if (ELEM(error_line_number_end[0], '(', ':') && error_line_number_end[1] != ' ') {
113  error_char = (int)strtol(error_line_number_end + 1, &log_line, 10);
114  }
115  else {
116  log_line = error_line_number_end;
117  }
118  /* There can be a 3rd number (case of mesa driver). */
119  if (ELEM(log_line[0], '(', ':') && log_line[1] >= '0' && log_line[1] <= '9') {
120  error_line = error_char;
121  error_char = (int)strtol(log_line + 1, &error_line_number_end, 10);
122  log_line = error_line_number_end;
123  }
124  }
125  /* Skip whitespaces and separators. */
126  while (ELEM(log_line[0], ':', ')', ' ')) {
127  log_line++;
128  }
129  if (error_line == -1) {
130  found_line_id = false;
131  }
132  const char *src_line = sources_combined;
133  if ((error_line != -1) && (error_char != -1)) {
135  /* source:line */
136  int error_source = error_line;
137  if (error_source < sources.size()) {
138  src_line = sources[error_source];
139  error_line = error_char;
140  error_char = -1;
141  }
142  }
145  /* 0:line */
146  error_line = error_char;
147  error_char = -1;
148  }
149  else {
150  /* line:char */
151  }
152  }
153  /* Separate from previous block. */
154  if (last_error_line != error_line) {
155  BLI_dynstr_appendf(dynstr, "%s%s%s\n", info_col, line_prefix, reset_col);
156  }
157  else if (error_char != last_error_char) {
158  BLI_dynstr_appendf(dynstr, "%s\n", line_prefix);
159  }
160  /* Print line from the source file that is producing the error. */
161  if ((error_line != -1) && (error_line != last_error_line || error_char != last_error_char)) {
162  const char *src_line_end = src_line;
163  found_line_id = false;
164  /* error_line is 1 based in this case. */
165  int src_line_index = 1;
166  while ((src_line_end = strchr(src_line, '\n'))) {
167  if (src_line_index == error_line) {
168  found_line_id = true;
169  break;
170  }
171 /* TODO(fclem) Make this an option to display N lines before error. */
172 #if 0 /* Uncomment to print shader file up to the error line to have more context. */
173  BLI_dynstr_appendf(dynstr, "%5d | ", src_line_index);
174  BLI_dynstr_nappend(dynstr, src_line, (src_line_end + 1) - src_line);
175 #endif
176  /* Continue to next line. */
177  src_line = src_line_end + 1;
178  src_line_index++;
179  }
180  /* Print error source. */
181  if (found_line_id) {
182  if (error_line != last_error_line) {
183  BLI_dynstr_appendf(dynstr, "%5d | ", src_line_index);
184  }
185  else {
186  BLI_dynstr_appendf(dynstr, line_prefix);
187  }
188  BLI_dynstr_nappend(dynstr, src_line, (src_line_end + 1) - src_line);
189  /* Print char offset. */
190  BLI_dynstr_appendf(dynstr, line_prefix);
191  if (error_char != -1) {
192  for (int i = 0; i < error_char; i++) {
193  BLI_dynstr_appendf(dynstr, " ");
194  }
195  BLI_dynstr_appendf(dynstr, "^");
196  }
197  BLI_dynstr_appendf(dynstr, "\n");
198  }
199  }
200  BLI_dynstr_appendf(dynstr, line_prefix);
201  /* Skip to message. Avoid redundant info. */
202  const char *keywords[] = {"error", "warning"};
203  for (int i = 0; i < ARRAY_SIZE(prefix); i++) {
204  if (STREQLEN(log_line, keywords[i], strlen(keywords[i]))) {
205  log_line += strlen(keywords[i]);
206  type = i;
207  break;
208  }
209  }
210  /* Skip and separators. */
211  while (ELEM(log_line[0], ':', ')')) {
212  log_line++;
213  }
214  if (type == 0) {
215  BLI_dynstr_appendf(dynstr, "%s%s%s: ", err_col, "Error", info_col);
216  }
217  else if (type == 1) {
218  BLI_dynstr_appendf(dynstr, "%s%s%s: ", warn_col, "Warning", info_col);
219  }
220  /* Print the error itself. */
221  BLI_dynstr_append(dynstr, info_col);
222  BLI_dynstr_nappend(dynstr, log_line, (line_end + 1) - log_line);
223  BLI_dynstr_append(dynstr, reset_col);
224  /* Continue to next line. */
225  log_line = line_end + 1;
226  last_error_line = error_line;
227  last_error_char = error_char;
228  }
229  MEM_freeN(sources_combined);
230 
232 
233  if (((LOG.type->flag & CLG_FLAG_USE) && (LOG.type->level >= 0)) ||
234  (severity >= CLG_SEVERITY_WARN)) {
235  const char *_str = BLI_dynstr_get_cstring(dynstr);
236  CLG_log_str(LOG.type, severity, this->name, stage, _str);
237  MEM_freeN((void *)_str);
238  }
239 
240  BLI_dynstr_free(dynstr);
241 }
242 
245 /* -------------------------------------------------------------------- */
249 Shader::Shader(const char *sh_name)
250 {
251  BLI_strncpy(this->name, sh_name, sizeof(this->name));
252 }
253 
255 {
256  delete interface;
257 }
258 
260 {
261  BLI_assert(sources.size() == 0);
262  /* Version needs to be first. Exact values will be added by implementation. */
263  sources.append("version");
264  /* some useful defines to detect GPU type */
266  sources.append("#define GPU_ATI\n");
267  }
269  sources.append("#define GPU_NVIDIA\n");
270  }
272  sources.append("#define GPU_INTEL\n");
273  }
274  /* some useful defines to detect OS type */
276  sources.append("#define OS_WIN\n");
277  }
279  sources.append("#define OS_MAC\n");
280  }
282  sources.append("#define OS_UNIX\n");
283  }
284 
285  if (GPU_crappy_amd_driver()) {
286  sources.append("#define GPU_DEPRECATED_AMD_DRIVER\n");
287  }
288 }
289 
290 GPUShader *GPU_shader_create_ex(const char *vertcode,
291  const char *fragcode,
292  const char *geomcode,
293  const char *libcode,
294  const char *defines,
295  const eGPUShaderTFBType tf_type,
296  const char **tf_names,
297  const int tf_count,
298  const char *shname)
299 {
300  /* At least a vertex shader and a fragment shader are required. */
301  BLI_assert((fragcode != nullptr) && (vertcode != nullptr));
302 
304 
305  if (vertcode) {
306  Vector<const char *> sources;
307  standard_defines(sources);
308  sources.append("#define GPU_VERTEX_SHADER\n");
309  sources.append("#define IN_OUT out\n");
310  if (geomcode) {
311  sources.append("#define USE_GEOMETRY_SHADER\n");
312  }
313  if (defines) {
314  sources.append(defines);
315  }
316  sources.append(vertcode);
317 
318  shader->vertex_shader_from_glsl(sources);
319  }
320 
321  if (fragcode) {
322  Vector<const char *> sources;
323  standard_defines(sources);
324  sources.append("#define GPU_FRAGMENT_SHADER\n");
325  sources.append("#define IN_OUT in\n");
326  if (geomcode) {
327  sources.append("#define USE_GEOMETRY_SHADER\n");
328  }
329  if (defines) {
330  sources.append(defines);
331  }
332  if (libcode) {
333  sources.append(libcode);
334  }
335  sources.append(fragcode);
336 
337  shader->fragment_shader_from_glsl(sources);
338  }
339 
340  if (geomcode) {
341  Vector<const char *> sources;
342  standard_defines(sources);
343  sources.append("#define GPU_GEOMETRY_SHADER\n");
344  if (defines) {
345  sources.append(defines);
346  }
347  sources.append(geomcode);
348 
349  shader->geometry_shader_from_glsl(sources);
350  }
351 
352  if (tf_names != nullptr && tf_count > 0) {
353  BLI_assert(tf_type != GPU_SHADER_TFB_NONE);
354  shader->transform_feedback_names_set(Span<const char *>(tf_names, tf_count), tf_type);
355  }
356 
357  if (!shader->finalize()) {
358  delete shader;
359  return nullptr;
360  };
361 
362  return wrap(shader);
363 }
364 
366 {
367  delete unwrap(shader);
368 }
369 
372 /* -------------------------------------------------------------------- */
376 GPUShader *GPU_shader_create(const char *vertcode,
377  const char *fragcode,
378  const char *geomcode,
379  const char *libcode,
380  const char *defines,
381  const char *shname)
382 {
383  return GPU_shader_create_ex(
384  vertcode, fragcode, geomcode, libcode, defines, GPU_SHADER_TFB_NONE, nullptr, 0, shname);
385 }
386 
388  const char *fragcode,
389  const char *geomcode,
390  const char *libcode,
391  const char *defines)
392 {
393  char *libcodecat = nullptr;
394 
395  if (libcode == nullptr) {
397  }
398  else {
399  libcode = libcodecat = BLI_strdupcat(libcode, datatoc_gpu_shader_colorspace_lib_glsl);
400  }
401 
402  GPUShader *sh = GPU_shader_create_ex(vertcode,
403  fragcode,
404  geomcode,
405  libcode,
406  defines,
408  nullptr,
409  0,
410  "pyGPUShader");
411 
412  MEM_SAFE_FREE(libcodecat);
413  return sh;
414 }
415 
416 static const char *string_join_array_maybe_alloc(const char **str_arr, bool *r_is_alloc)
417 {
418  bool is_alloc = false;
419  if (str_arr == nullptr) {
420  *r_is_alloc = false;
421  return nullptr;
422  }
423  /* Skip empty strings (avoid alloc if we can). */
424  while (str_arr[0] && str_arr[0][0] == '\0') {
425  str_arr++;
426  }
427  int i;
428  for (i = 0; str_arr[i]; i++) {
429  if (i != 0 && str_arr[i][0] != '\0') {
430  is_alloc = true;
431  }
432  }
433  *r_is_alloc = is_alloc;
434  if (is_alloc) {
435  return BLI_string_join_arrayN(str_arr, i);
436  }
437 
438  return str_arr[0];
439 }
440 
462  const struct GPU_ShaderCreateFromArray_Params *params, const char *func, int line)
463 {
464  struct {
465  const char *str;
466  bool is_alloc;
467  } str_dst[4] = {{nullptr}};
468  const char **str_src[4] = {params->vert, params->frag, params->geom, params->defs};
469 
470  for (int i = 0; i < ARRAY_SIZE(str_src); i++) {
471  str_dst[i].str = string_join_array_maybe_alloc(str_src[i], &str_dst[i].is_alloc);
472  }
473 
474  char name[64];
475  BLI_snprintf(name, sizeof(name), "%s_%d", func, line);
476 
478  str_dst[0].str, str_dst[1].str, str_dst[2].str, nullptr, str_dst[3].str, name);
479 
480  for (auto &i : str_dst) {
481  if (i.is_alloc) {
482  MEM_freeN((void *)i.str);
483  }
484  }
485  return sh;
486 }
487 
490 /* -------------------------------------------------------------------- */
494 void GPU_shader_bind(GPUShader *gpu_shader)
495 {
496  Shader *shader = unwrap(gpu_shader);
497 
498  Context *ctx = Context::get();
499 
500  if (ctx->shader != shader) {
501  ctx->shader = shader;
502  shader->bind();
503  GPU_matrix_bind(gpu_shader);
504  GPU_shader_set_srgb_uniform(gpu_shader);
505  }
506  else {
508  GPU_shader_set_srgb_uniform(gpu_shader);
509  }
510  if (GPU_matrix_dirty_get()) {
511  GPU_matrix_bind(gpu_shader);
512  }
513  }
514 }
515 
517 {
518 #ifndef NDEBUG
519  Context *ctx = Context::get();
520  if (ctx->shader) {
521  ctx->shader->unbind();
522  }
523  ctx->shader = nullptr;
524 #endif
525 }
526 
529 /* -------------------------------------------------------------------- */
536 {
537  return unwrap(shader)->transform_feedback_enable(vertbuf);
538 }
539 
541 {
542  unwrap(shader)->transform_feedback_disable();
543 }
544 
547 /* -------------------------------------------------------------------- */
551 int GPU_shader_get_uniform(GPUShader *shader, const char *name)
552 {
553  ShaderInterface *interface = unwrap(shader)->interface;
554  const ShaderInput *uniform = interface->uniform_get(name);
555  return uniform ? uniform->location : -1;
556 }
557 
559 {
560  ShaderInterface *interface = unwrap(shader)->interface;
561  return interface->uniform_builtin((GPUUniformBuiltin)builtin);
562 }
563 
565 {
566  ShaderInterface *interface = unwrap(shader)->interface;
567  return interface->ubo_builtin((GPUUniformBlockBuiltin)builtin);
568 }
569 
570 /* DEPRECATED. */
572 {
573  ShaderInterface *interface = unwrap(shader)->interface;
574  const ShaderInput *ubo = interface->ubo_get(name);
575  return ubo ? ubo->location : -1;
576 }
577 
579 {
580  ShaderInterface *interface = unwrap(shader)->interface;
581  const ShaderInput *ubo = interface->ubo_get(name);
582  return ubo ? ubo->binding : -1;
583 }
584 
586 {
587  ShaderInterface *interface = unwrap(shader)->interface;
588  const ShaderInput *tex = interface->uniform_get(name);
589  return tex ? tex->binding : -1;
590 }
591 
593 {
594  ShaderInterface *interface = unwrap(shader)->interface;
595  const ShaderInput *attr = interface->attr_get(name);
596  return attr ? attr->location : -1;
597 }
598 
601 /* -------------------------------------------------------------------- */
605 /* DEPRECATED: Kept only because of BGL API */
607 {
608  return unwrap(shader)->program_handle_get();
609 }
610 
613 /* -------------------------------------------------------------------- */
618  GPUShader *shader, int loc, int len, int arraysize, const float *value)
619 {
620  unwrap(shader)->uniform_float(loc, len, arraysize, value);
621 }
622 
624  GPUShader *shader, int loc, int len, int arraysize, const int *value)
625 {
626  unwrap(shader)->uniform_int(loc, len, arraysize, value);
627 }
628 
629 void GPU_shader_uniform_int(GPUShader *shader, int location, int value)
630 {
631  GPU_shader_uniform_vector_int(shader, location, 1, 1, &value);
632 }
633 
634 void GPU_shader_uniform_float(GPUShader *shader, int location, float value)
635 {
636  GPU_shader_uniform_vector(shader, location, 1, 1, &value);
637 }
638 
639 void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value)
640 {
641  const int loc = GPU_shader_get_uniform(sh, name);
642  GPU_shader_uniform_int(sh, loc, value);
643 }
644 
645 void GPU_shader_uniform_1b(GPUShader *sh, const char *name, bool value)
646 {
647  GPU_shader_uniform_1i(sh, name, value ? 1 : 0);
648 }
649 
650 void GPU_shader_uniform_2f(GPUShader *sh, const char *name, float x, float y)
651 {
652  const float data[2] = {x, y};
653  GPU_shader_uniform_2fv(sh, name, data);
654 }
655 
656 void GPU_shader_uniform_3f(GPUShader *sh, const char *name, float x, float y, float z)
657 {
658  const float data[3] = {x, y, z};
659  GPU_shader_uniform_3fv(sh, name, data);
660 }
661 
662 void GPU_shader_uniform_4f(GPUShader *sh, const char *name, float x, float y, float z, float w)
663 {
664  const float data[4] = {x, y, z, w};
665  GPU_shader_uniform_4fv(sh, name, data);
666 }
667 
668 void GPU_shader_uniform_1f(GPUShader *sh, const char *name, float value)
669 {
670  const int loc = GPU_shader_get_uniform(sh, name);
671  GPU_shader_uniform_float(sh, loc, value);
672 }
673 
674 void GPU_shader_uniform_2fv(GPUShader *sh, const char *name, const float data[2])
675 {
676  const int loc = GPU_shader_get_uniform(sh, name);
677  GPU_shader_uniform_vector(sh, loc, 2, 1, data);
678 }
679 
680 void GPU_shader_uniform_3fv(GPUShader *sh, const char *name, const float data[3])
681 {
682  const int loc = GPU_shader_get_uniform(sh, name);
683  GPU_shader_uniform_vector(sh, loc, 3, 1, data);
684 }
685 
686 void GPU_shader_uniform_4fv(GPUShader *sh, const char *name, const float data[4])
687 {
688  const int loc = GPU_shader_get_uniform(sh, name);
689  GPU_shader_uniform_vector(sh, loc, 4, 1, data);
690 }
691 
692 void GPU_shader_uniform_mat4(GPUShader *sh, const char *name, const float data[4][4])
693 {
694  const int loc = GPU_shader_get_uniform(sh, name);
695  GPU_shader_uniform_vector(sh, loc, 16, 1, (const float *)data);
696 }
697 
698 void GPU_shader_uniform_2fv_array(GPUShader *sh, const char *name, int len, const float (*val)[2])
699 {
700  const int loc = GPU_shader_get_uniform(sh, name);
701  GPU_shader_uniform_vector(sh, loc, 2, len, (const float *)val);
702 }
703 
704 void GPU_shader_uniform_4fv_array(GPUShader *sh, const char *name, int len, const float (*val)[4])
705 {
706  const int loc = GPU_shader_get_uniform(sh, name);
707  GPU_shader_uniform_vector(sh, loc, 4, len, (const float *)val);
708 }
709 
712 /* -------------------------------------------------------------------- */
724 static bool g_shader_builtin_srgb_is_dirty = false;
725 
727 {
729 }
730 
732 {
734  if (loc != -1) {
736  }
738 }
739 
740 void GPU_shader_set_framebuffer_srgb_target(int use_srgb_to_linear)
741 {
742  if (g_shader_builtin_srgb_transform != use_srgb_to_linear) {
743  g_shader_builtin_srgb_transform = use_srgb_to_linear;
745  }
746 }
747 
#define BLI_assert(a)
Definition: BLI_assert.h:58
A dynamically sized string ADT.
DynStr * BLI_dynstr_new(void) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: BLI_dynstr.c:71
void BLI_dynstr_nappend(DynStr *__restrict ds, const char *cstr, int len) ATTR_NONNULL()
Definition: BLI_dynstr.c:133
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
Definition: BLI_dynstr.c:358
void BLI_dynstr_appendf(DynStr *__restrict ds, const char *__restrict format,...) ATTR_PRINTF_FORMAT(2
char * BLI_dynstr_get_cstring(DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: BLI_dynstr.c:323
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
Definition: BLI_dynstr.c:107
char * BLI_strdupcat(const char *__restrict str1, const char *__restrict str2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
Definition: string.c:81
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
Definition: string.c:108
char * BLI_string_join_arrayN(const char *strings[], uint strings_len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: string_utils.c:462
#define ARRAY_SIZE(arr)
#define STREQLEN(a, b, n)
#define ELEM(...)
CLG_Severity
Definition: CLG_log.h:99
@ CLG_SEVERITY_WARN
Definition: CLG_log.h:101
@ CLG_SEVERITY_ERROR
Definition: CLG_log.h:102
@ CLG_FLAG_USE
Definition: CLG_log.h:96
void CLG_log_str(CLG_LogType *lg, enum CLG_Severity severity, const char *file_line, const char *fn, const char *message) _CLOG_ATTR_NONNULL(1
int CLG_color_support_get(CLG_LogRef *clg_ref)
Definition: clog.c:799
bool GPU_crappy_amd_driver(void)
_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 type
_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:690
void GPU_matrix_bind(struct GPUShader *shader)
Definition: gpu_matrix.cc:646
@ GPU_DRIVER_ANY
Definition: GPU_platform.h:56
@ GPU_DRIVER_OFFICIAL
Definition: GPU_platform.h:53
@ GPU_OS_WIN
Definition: GPU_platform.h:46
@ GPU_OS_UNIX
Definition: GPU_platform.h:48
@ GPU_OS_ANY
Definition: GPU_platform.h:49
@ GPU_OS_MAC
Definition: GPU_platform.h:47
@ GPU_DEVICE_ATI
Definition: GPU_platform.h:34
@ GPU_DEVICE_NVIDIA
Definition: GPU_platform.h:33
@ GPU_DEVICE_ANY
Definition: GPU_platform.h:40
@ GPU_DEVICE_INTEL
Definition: GPU_platform.h:35
bool GPU_type_matches(eGPUDeviceType device, eGPUOSType os, eGPUDriverType driver)
struct GPUShader GPUShader
Definition: GPU_shader.h:33
eGPUShaderTFBType
Definition: GPU_shader.h:35
@ GPU_SHADER_TFB_NONE
Definition: GPU_shader.h:36
GPUUniformBuiltin
Definition: GPU_shader.h:88
@ GPU_UNIFORM_SRGB_TRANSFORM
Definition: GPU_shader.h:110
GPUUniformBlockBuiltin
Definition: GPU_shader.h:115
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 const T * data() const
Definition: BLI_span.hh:217
constexpr int64_t size() const
Definition: BLI_span.hh:254
int64_t size() const
Definition: BLI_vector.hh:662
void append(const T &value)
Definition: BLI_vector.hh:438
static Context * get(void)
Definition: gpu_context.cc:88
static GPUBackend * get(void)
Definition: gpu_context.cc:191
virtual Shader * shader_alloc(const char *name)=0
int32_t uniform_builtin(const GPUUniformBuiltin builtin) const
int32_t ubo_builtin(const GPUUniformBlockBuiltin builtin) const
void print_log(Span< const char * > sources, char *log, const char *stage, const bool error)
Definition: gpu_shader.cc:66
ShaderInterface * interface
virtual void unbind(void)=0
Shader(const char *name)
Definition: gpu_shader.cc:249
EvaluationStage stage
Definition: deg_eval.cc:96
#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:376
void GPU_shader_unbind(void)
Definition: gpu_shader.cc:516
int GPU_shader_get_uniform(GPUShader *shader, const char *name)
Definition: gpu_shader.cc:551
void GPU_shader_uniform_vector_int(GPUShader *shader, int loc, int len, int arraysize, const int *value)
Definition: gpu_shader.cc:623
void GPU_shader_uniform_2fv(GPUShader *sh, const char *name, const float data[2])
Definition: gpu_shader.cc:674
void GPU_shader_set_srgb_uniform(GPUShader *shader)
Definition: gpu_shader.cc:731
static bool gpu_shader_srgb_uniform_dirty_get()
Definition: gpu_shader.cc:726
static const char * string_join_array_maybe_alloc(const char **str_arr, bool *r_is_alloc)
Definition: gpu_shader.cc:416
void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value)
Definition: gpu_shader.cc:639
static int g_shader_builtin_srgb_transform
Definition: gpu_shader.cc:723
void GPU_shader_uniform_3f(GPUShader *sh, const char *name, float x, float y, float z)
Definition: gpu_shader.cc:656
void GPU_shader_uniform_2f(GPUShader *sh, const char *name, float x, float y)
Definition: gpu_shader.cc:650
void GPU_shader_uniform_2fv_array(GPUShader *sh, const char *name, int len, const float(*val)[2])
Definition: gpu_shader.cc:698
void GPU_shader_set_framebuffer_srgb_target(int use_srgb_to_linear)
Definition: gpu_shader.cc:740
void GPU_shader_uniform_1f(GPUShader *sh, const char *name, float value)
Definition: gpu_shader.cc:668
GPUShader * GPU_shader_create_ex(const char *vertcode, const char *fragcode, const char *geomcode, 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:290
void GPU_shader_bind(GPUShader *gpu_shader)
Definition: gpu_shader.cc:494
static void standard_defines(Vector< const char * > &sources)
Definition: gpu_shader.cc:259
void GPU_shader_uniform_3fv(GPUShader *sh, const char *name, const float data[3])
Definition: gpu_shader.cc:680
void GPU_shader_uniform_vector(GPUShader *shader, int loc, int len, int arraysize, const float *value)
Definition: gpu_shader.cc:617
int GPU_shader_get_attribute(GPUShader *shader, const char *name)
Definition: gpu_shader.cc:592
void GPU_shader_uniform_4fv_array(GPUShader *sh, const char *name, int len, const float(*val)[4])
Definition: gpu_shader.cc:704
char datatoc_gpu_shader_colorspace_lib_glsl[]
Definition: gpu_shader.cc:53
void GPU_shader_uniform_int(GPUShader *shader, int location, int value)
Definition: gpu_shader.cc:629
int GPU_shader_get_builtin_block(GPUShader *shader, int builtin)
Definition: gpu_shader.cc:564
int GPU_shader_get_uniform_block_binding(GPUShader *shader, const char *name)
Definition: gpu_shader.cc:578
GPUShader * GPU_shader_create_from_python(const char *vertcode, const char *fragcode, const char *geomcode, const char *libcode, const char *defines)
Definition: gpu_shader.cc:387
void GPU_shader_transform_feedback_disable(GPUShader *shader)
Definition: gpu_shader.cc:540
int GPU_shader_get_program(GPUShader *shader)
Definition: gpu_shader.cc:606
void GPU_shader_uniform_1b(GPUShader *sh, const char *name, bool value)
Definition: gpu_shader.cc:645
void GPU_shader_uniform_4fv(GPUShader *sh, const char *name, const float data[4])
Definition: gpu_shader.cc:686
void GPU_shader_uniform_4f(GPUShader *sh, const char *name, float x, float y, float z, float w)
Definition: gpu_shader.cc:662
int GPU_shader_get_uniform_block(GPUShader *shader, const char *name)
Definition: gpu_shader.cc:571
void GPU_shader_uniform_mat4(GPUShader *sh, const char *name, const float data[4][4])
Definition: gpu_shader.cc:692
int GPU_shader_get_texture_binding(GPUShader *shader, const char *name)
Definition: gpu_shader.cc:585
static CLG_LogRef LOG
Definition: gpu_shader.cc:55
int GPU_shader_get_builtin_uniform(GPUShader *shader, int builtin)
Definition: gpu_shader.cc:558
void GPU_shader_free(GPUShader *shader)
Definition: gpu_shader.cc:365
void GPU_shader_uniform_float(GPUShader *shader, int location, float value)
Definition: gpu_shader.cc:634
static bool g_shader_builtin_srgb_is_dirty
Definition: gpu_shader.cc:724
bool GPU_shader_transform_feedback_enable(GPUShader *shader, GPUVertBuf *vertbuf)
Definition: gpu_shader.cc:535
struct GPUShader * GPU_shader_create_from_arrays_impl(const struct GPU_ShaderCreateFromArray_Params *params, const char *func, int line)
Definition: gpu_shader.cc:461
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void KERNEL_FUNCTION_FULL_NAME() shader(KernelGlobals *kg, uint4 *input, float4 *output, int type, int filter, int i, int offset, int sample)
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
static void error(const char *str)
Definition: meshlaplacian.c:65
INLINE Rall1d< T, V, S > log(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:303
static GPUContext * wrap(Context *ctx)
static Context * unwrap(GPUContext *ctx)
signed int int32_t
Definition: stdint.h:80
CLG_LogType * type
Definition: CLG_log.h:120
enum CLG_LogFlag flag
Definition: CLG_log.h:115
int level
Definition: CLG_log.h:114
uint len