Blender  V3.3
gl_shader.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2020 Blender Foundation. All rights reserved. */
3 
8 #include "BKE_global.h"
9 
10 #include "BLI_string.h"
11 #include "BLI_vector.hh"
12 
13 #include "GPU_capabilities.h"
14 #include "GPU_platform.h"
15 
16 #include "gl_debug.hh"
17 #include "gl_vertex_buffer.hh"
18 
19 #include "gl_shader.hh"
20 #include "gl_shader_interface.hh"
21 
22 using namespace blender;
23 using namespace blender::gpu;
24 using namespace blender::gpu::shader;
25 
27 
28 /* -------------------------------------------------------------------- */
32 GLShader::GLShader(const char *name) : Shader(name)
33 {
34 #if 0 /* Would be nice to have, but for now the Deferred compilation \
35  * does not have a GPUContext. */
36  BLI_assert(GLContext::get() != nullptr);
37 #endif
38  shader_program_ = glCreateProgram();
39 
40  debug::object_label(GL_PROGRAM, shader_program_, name);
41 }
42 
44 {
45 #if 0 /* Would be nice to have, but for now the Deferred compilation \
46  * does not have a GPUContext. */
47  BLI_assert(GLContext::get() != nullptr);
48 #endif
49  /* Invalid handles are silently ignored. */
50  glDeleteShader(vert_shader_);
51  glDeleteShader(geom_shader_);
52  glDeleteShader(frag_shader_);
53  glDeleteShader(compute_shader_);
54  glDeleteProgram(shader_program_);
55 }
56 
59 /* -------------------------------------------------------------------- */
63 static const char *to_string(const Interpolation &interp)
64 {
65  switch (interp) {
66  case Interpolation::SMOOTH:
67  return "smooth";
68  case Interpolation::FLAT:
69  return "flat";
70  case Interpolation::NO_PERSPECTIVE:
71  return "noperspective";
72  default:
73  return "unknown";
74  }
75 }
76 
77 static const char *to_string(const Type &type)
78 {
79  switch (type) {
80  case Type::FLOAT:
81  return "float";
82  case Type::VEC2:
83  return "vec2";
84  case Type::VEC3:
85  return "vec3";
86  case Type::VEC4:
87  return "vec4";
88  case Type::MAT3:
89  return "mat3";
90  case Type::MAT4:
91  return "mat4";
92  case Type::UINT:
93  return "uint";
94  case Type::UVEC2:
95  return "uvec2";
96  case Type::UVEC3:
97  return "uvec3";
98  case Type::UVEC4:
99  return "uvec4";
100  case Type::INT:
101  return "int";
102  case Type::IVEC2:
103  return "ivec2";
104  case Type::IVEC3:
105  return "ivec3";
106  case Type::IVEC4:
107  return "ivec4";
108  case Type::BOOL:
109  return "bool";
110  default:
111  return "unknown";
112  }
113 }
114 
115 static const char *to_string(const eGPUTextureFormat &type)
116 {
117  switch (type) {
118  case GPU_RGBA8UI:
119  return "rgba8ui";
120  case GPU_RGBA8I:
121  return "rgba8i";
122  case GPU_RGBA8:
123  return "rgba8";
124  case GPU_RGBA32UI:
125  return "rgba32ui";
126  case GPU_RGBA32I:
127  return "rgba32i";
128  case GPU_RGBA32F:
129  return "rgba32f";
130  case GPU_RGBA16UI:
131  return "rgba16ui";
132  case GPU_RGBA16I:
133  return "rgba16i";
134  case GPU_RGBA16F:
135  return "rgba16f";
136  case GPU_RGBA16:
137  return "rgba16";
138  case GPU_RG8UI:
139  return "rg8ui";
140  case GPU_RG8I:
141  return "rg8i";
142  case GPU_RG8:
143  return "rg8";
144  case GPU_RG32UI:
145  return "rg32ui";
146  case GPU_RG32I:
147  return "rg32i";
148  case GPU_RG32F:
149  return "rg32f";
150  case GPU_RG16UI:
151  return "rg16ui";
152  case GPU_RG16I:
153  return "rg16i";
154  case GPU_RG16F:
155  return "rg16f";
156  case GPU_RG16:
157  return "rg16";
158  case GPU_R8UI:
159  return "r8ui";
160  case GPU_R8I:
161  return "r8i";
162  case GPU_R8:
163  return "r8";
164  case GPU_R32UI:
165  return "r32ui";
166  case GPU_R32I:
167  return "r32i";
168  case GPU_R32F:
169  return "r32f";
170  case GPU_R16UI:
171  return "r16ui";
172  case GPU_R16I:
173  return "r16i";
174  case GPU_R16F:
175  return "r16f";
176  case GPU_R16:
177  return "r16";
178  case GPU_R11F_G11F_B10F:
179  return "r11f_g11f_b10f";
180  case GPU_RGB10_A2:
181  return "rgb10_a2";
182  default:
183  return "unknown";
184  }
185 }
186 
187 static const char *to_string(const PrimitiveIn &layout)
188 {
189  switch (layout) {
190  case PrimitiveIn::POINTS:
191  return "points";
192  case PrimitiveIn::LINES:
193  return "lines";
194  case PrimitiveIn::LINES_ADJACENCY:
195  return "lines_adjacency";
196  case PrimitiveIn::TRIANGLES:
197  return "triangles";
198  case PrimitiveIn::TRIANGLES_ADJACENCY:
199  return "triangles_adjacency";
200  default:
201  return "unknown";
202  }
203 }
204 
205 static const char *to_string(const PrimitiveOut &layout)
206 {
207  switch (layout) {
208  case PrimitiveOut::POINTS:
209  return "points";
210  case PrimitiveOut::LINE_STRIP:
211  return "line_strip";
212  case PrimitiveOut::TRIANGLE_STRIP:
213  return "triangle_strip";
214  default:
215  return "unknown";
216  }
217 }
218 
219 static const char *to_string(const DepthWrite &value)
220 {
221  switch (value) {
222  case DepthWrite::ANY:
223  return "depth_any";
224  case DepthWrite::GREATER:
225  return "depth_greater";
226  case DepthWrite::LESS:
227  return "depth_less";
228  default:
229  return "depth_unchanged";
230  }
231 }
232 
233 static void print_image_type(std::ostream &os,
234  const ImageType &type,
235  const ShaderCreateInfo::Resource::BindType bind_type)
236 {
237  switch (type) {
238  case ImageType::INT_BUFFER:
239  case ImageType::INT_1D:
240  case ImageType::INT_1D_ARRAY:
241  case ImageType::INT_2D:
242  case ImageType::INT_2D_ARRAY:
243  case ImageType::INT_3D:
244  case ImageType::INT_CUBE:
245  case ImageType::INT_CUBE_ARRAY:
246  os << "i";
247  break;
248  case ImageType::UINT_BUFFER:
249  case ImageType::UINT_1D:
250  case ImageType::UINT_1D_ARRAY:
251  case ImageType::UINT_2D:
252  case ImageType::UINT_2D_ARRAY:
253  case ImageType::UINT_3D:
254  case ImageType::UINT_CUBE:
255  case ImageType::UINT_CUBE_ARRAY:
256  os << "u";
257  break;
258  default:
259  break;
260  }
261 
262  if (bind_type == ShaderCreateInfo::Resource::BindType::IMAGE) {
263  os << "image";
264  }
265  else {
266  os << "sampler";
267  }
268 
269  switch (type) {
270  case ImageType::FLOAT_BUFFER:
271  case ImageType::INT_BUFFER:
272  case ImageType::UINT_BUFFER:
273  os << "Buffer";
274  break;
275  case ImageType::FLOAT_1D:
276  case ImageType::FLOAT_1D_ARRAY:
277  case ImageType::INT_1D:
278  case ImageType::INT_1D_ARRAY:
279  case ImageType::UINT_1D:
280  case ImageType::UINT_1D_ARRAY:
281  os << "1D";
282  break;
283  case ImageType::FLOAT_2D:
284  case ImageType::FLOAT_2D_ARRAY:
285  case ImageType::INT_2D:
286  case ImageType::INT_2D_ARRAY:
287  case ImageType::UINT_2D:
288  case ImageType::UINT_2D_ARRAY:
289  case ImageType::SHADOW_2D:
290  case ImageType::SHADOW_2D_ARRAY:
291  case ImageType::DEPTH_2D:
292  case ImageType::DEPTH_2D_ARRAY:
293  os << "2D";
294  break;
295  case ImageType::FLOAT_3D:
296  case ImageType::INT_3D:
297  case ImageType::UINT_3D:
298  os << "3D";
299  break;
300  case ImageType::FLOAT_CUBE:
301  case ImageType::FLOAT_CUBE_ARRAY:
302  case ImageType::INT_CUBE:
303  case ImageType::INT_CUBE_ARRAY:
304  case ImageType::UINT_CUBE:
305  case ImageType::UINT_CUBE_ARRAY:
306  case ImageType::SHADOW_CUBE:
307  case ImageType::SHADOW_CUBE_ARRAY:
308  case ImageType::DEPTH_CUBE:
309  case ImageType::DEPTH_CUBE_ARRAY:
310  os << "Cube";
311  break;
312  default:
313  break;
314  }
315 
316  switch (type) {
317  case ImageType::FLOAT_1D_ARRAY:
318  case ImageType::FLOAT_2D_ARRAY:
319  case ImageType::FLOAT_CUBE_ARRAY:
320  case ImageType::INT_1D_ARRAY:
321  case ImageType::INT_2D_ARRAY:
322  case ImageType::INT_CUBE_ARRAY:
323  case ImageType::UINT_1D_ARRAY:
324  case ImageType::UINT_2D_ARRAY:
325  case ImageType::UINT_CUBE_ARRAY:
326  case ImageType::SHADOW_2D_ARRAY:
327  case ImageType::SHADOW_CUBE_ARRAY:
328  case ImageType::DEPTH_2D_ARRAY:
329  case ImageType::DEPTH_CUBE_ARRAY:
330  os << "Array";
331  break;
332  default:
333  break;
334  }
335 
336  switch (type) {
337  case ImageType::SHADOW_2D:
338  case ImageType::SHADOW_2D_ARRAY:
339  case ImageType::SHADOW_CUBE:
340  case ImageType::SHADOW_CUBE_ARRAY:
341  os << "Shadow";
342  break;
343  default:
344  break;
345  }
346  os << " ";
347 }
348 
349 static std::ostream &print_qualifier(std::ostream &os, const Qualifier &qualifiers)
350 {
351  if (bool(qualifiers & Qualifier::NO_RESTRICT) == false) {
352  os << "restrict ";
353  }
354  if (bool(qualifiers & Qualifier::READ) == false) {
355  os << "writeonly ";
356  }
357  if (bool(qualifiers & Qualifier::WRITE) == false) {
358  os << "readonly ";
359  }
360  return os;
361 }
362 
363 static void print_resource(std::ostream &os, const ShaderCreateInfo::Resource &res)
364 {
366  os << "layout(binding = " << res.slot;
367  if (res.bind_type == ShaderCreateInfo::Resource::BindType::IMAGE) {
368  os << ", " << to_string(res.image.format);
369  }
370  else if (res.bind_type == ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER) {
371  os << ", std140";
372  }
373  else if (res.bind_type == ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER) {
374  os << ", std430";
375  }
376  os << ") ";
377  }
378  else if (res.bind_type == ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER) {
379  os << "layout(std140) ";
380  }
381 
382  int64_t array_offset;
383  StringRef name_no_array;
384 
385  switch (res.bind_type) {
386  case ShaderCreateInfo::Resource::BindType::SAMPLER:
387  os << "uniform ";
388  print_image_type(os, res.sampler.type, res.bind_type);
389  os << res.sampler.name << ";\n";
390  break;
391  case ShaderCreateInfo::Resource::BindType::IMAGE:
392  os << "uniform ";
394  print_image_type(os, res.image.type, res.bind_type);
395  os << res.image.name << ";\n";
396  break;
397  case ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER:
398  array_offset = res.uniformbuf.name.find_first_of("[");
399  name_no_array = (array_offset == -1) ? res.uniformbuf.name :
400  StringRef(res.uniformbuf.name.c_str(), array_offset);
401  os << "uniform " << name_no_array << " { " << res.uniformbuf.type_name << " _"
402  << res.uniformbuf.name << "; };\n";
403  break;
404  case ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER:
405  array_offset = res.storagebuf.name.find_first_of("[");
406  name_no_array = (array_offset == -1) ? res.storagebuf.name :
407  StringRef(res.storagebuf.name.c_str(), array_offset);
408  print_qualifier(os, res.storagebuf.qualifiers);
409  os << "buffer ";
410  os << name_no_array << " { " << res.storagebuf.type_name << " _" << res.storagebuf.name
411  << "; };\n";
412  break;
413  }
414 }
415 
416 static void print_resource_alias(std::ostream &os, const ShaderCreateInfo::Resource &res)
417 {
418  int64_t array_offset;
419  StringRef name_no_array;
420 
421  switch (res.bind_type) {
422  case ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER:
423  array_offset = res.uniformbuf.name.find_first_of("[");
424  name_no_array = (array_offset == -1) ? res.uniformbuf.name :
425  StringRef(res.uniformbuf.name.c_str(), array_offset);
426  os << "#define " << name_no_array << " (_" << name_no_array << ")\n";
427  break;
428  case ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER:
429  array_offset = res.storagebuf.name.find_first_of("[");
430  name_no_array = (array_offset == -1) ? res.storagebuf.name :
431  StringRef(res.storagebuf.name.c_str(), array_offset);
432  os << "#define " << name_no_array << " (_" << name_no_array << ")\n";
433  break;
434  default:
435  break;
436  }
437 }
438 
439 static void print_interface(std::ostream &os,
440  const StringRefNull &prefix,
441  const StageInterfaceInfo &iface,
442  const StringRefNull &suffix = "")
443 {
444  /* TODO(@fclem): Move that to interface check. */
445  // if (iface.instance_name.is_empty()) {
446  // BLI_assert_msg(0, "Interfaces require an instance name for geometry shader.");
447  // std::cout << iface.name << ": Interfaces require an instance name for geometry shader.\n";
448  // continue;
449  // }
450  os << prefix << " " << iface.name << "{" << std::endl;
451  for (const StageInterfaceInfo::InOut &inout : iface.inouts) {
452  os << " " << to_string(inout.interp) << " " << to_string(inout.type) << " " << inout.name
453  << ";\n";
454  }
455  os << "}";
456  os << (iface.instance_name.is_empty() ? "" : "\n") << iface.instance_name << suffix << ";\n";
457 }
458 
459 std::string GLShader::resources_declare(const ShaderCreateInfo &info) const
460 {
461  std::stringstream ss;
462 
463  /* NOTE: We define macros in GLSL to trigger compilation error if the resource names
464  * are reused for local variables. This is to match other backend behavior which needs accessors
465  * macros. */
466 
467  ss << "\n/* Pass Resources. */\n";
468  for (const ShaderCreateInfo::Resource &res : info.pass_resources_) {
469  print_resource(ss, res);
470  }
471  for (const ShaderCreateInfo::Resource &res : info.pass_resources_) {
472  print_resource_alias(ss, res);
473  }
474  ss << "\n/* Batch Resources. */\n";
475  for (const ShaderCreateInfo::Resource &res : info.batch_resources_) {
476  print_resource(ss, res);
477  }
478  for (const ShaderCreateInfo::Resource &res : info.batch_resources_) {
479  print_resource_alias(ss, res);
480  }
481  ss << "\n/* Push Constants. */\n";
482  for (const ShaderCreateInfo::PushConst &uniform : info.push_constants_) {
483  ss << "uniform " << to_string(uniform.type) << " " << uniform.name;
484  if (uniform.array_size > 0) {
485  ss << "[" << uniform.array_size << "]";
486  }
487  ss << ";\n";
488  }
489 #if 0 /* T95278: This is not be enough to prevent some compilers think it is recursive. */
490  for (const ShaderCreateInfo::PushConst &uniform : info.push_constants_) {
491  /* T95278: Double macro to avoid some compilers think it is recursive. */
492  ss << "#define " << uniform.name << "_ " << uniform.name << "\n";
493  ss << "#define " << uniform.name << " (" << uniform.name << "_)\n";
494  }
495 #endif
496  ss << "\n";
497  return ss.str();
498 }
499 
500 static std::string main_function_wrapper(std::string &pre_main, std::string &post_main)
501 {
502  std::stringstream ss;
503  /* Prototype for the original main. */
504  ss << "\n";
505  ss << "void main_function_();\n";
506  /* Wrapper to the main function in order to inject code processing on globals. */
507  ss << "void main() {\n";
508  ss << pre_main;
509  ss << " main_function_();\n";
510  ss << post_main;
511  ss << "}\n";
512  /* Rename the original main. */
513  ss << "#define main main_function_\n";
514  ss << "\n";
515  return ss.str();
516 }
517 
519 {
520  std::stringstream ss;
521  std::string post_main;
522 
523  ss << "\n/* Inputs. */\n";
524  for (const ShaderCreateInfo::VertIn &attr : info.vertex_inputs_) {
526  /* Fix issue with AMDGPU-PRO + workbench_prepass_mesh_vert.glsl being quantized. */
528  ss << "layout(location = " << attr.index << ") ";
529  }
530  ss << "in " << to_string(attr.type) << " " << attr.name << ";\n";
531  }
532  /* NOTE(D4490): Fix a bug where shader without any vertex attributes do not behave correctly. */
534  info.vertex_inputs_.is_empty()) {
535  ss << "in float gpu_dummy_workaround;\n";
536  }
537  ss << "\n/* Interfaces. */\n";
538  for (const StageInterfaceInfo *iface : info.vertex_out_interfaces_) {
539  print_interface(ss, "out", *iface);
540  }
541  if (!GLContext::layered_rendering_support && bool(info.builtins_ & BuiltinBits::LAYER)) {
542  ss << "out int gpu_Layer;\n";
543  }
544  if (bool(info.builtins_ & BuiltinBits::BARYCENTRIC_COORD)) {
546  /* Disabled or unsupported. */
547  }
548  else if (GLEW_AMD_shader_explicit_vertex_parameter) {
549  /* Need this for stable barycentric. */
550  ss << "flat out vec4 gpu_pos_flat;\n";
551  ss << "out vec4 gpu_pos;\n";
552 
553  post_main += " gpu_pos = gpu_pos_flat = gl_Position;\n";
554  }
555  }
556  ss << "\n";
557 
558  if (post_main.empty() == false) {
559  std::string pre_main;
560  ss << main_function_wrapper(pre_main, post_main);
561  }
562  return ss.str();
563 }
564 
566 {
567  std::stringstream ss;
568  std::string pre_main;
569 
570  ss << "\n/* Interfaces. */\n";
571  const Vector<StageInterfaceInfo *> &in_interfaces = (info.geometry_source_.is_empty()) ?
574  for (const StageInterfaceInfo *iface : in_interfaces) {
575  print_interface(ss, "in", *iface);
576  }
577  if (bool(info.builtins_ & BuiltinBits::BARYCENTRIC_COORD)) {
579  ss << "flat in vec4 gpu_pos[3];\n";
580  ss << "smooth in vec3 gpu_BaryCoord;\n";
581  ss << "noperspective in vec3 gpu_BaryCoordNoPersp;\n";
582  ss << "#define gpu_position_at_vertex(v) gpu_pos[v]\n";
583  }
584  else if (GLEW_AMD_shader_explicit_vertex_parameter) {
585  std::cout << "native" << std::endl;
586  /* NOTE(fclem): This won't work with geometry shader. Hopefully, we don't need geometry
587  * shader workaround if this extension/feature is detected. */
588  ss << "\n/* Stable Barycentric Coordinates. */\n";
589  ss << "flat in vec4 gpu_pos_flat;\n";
590  ss << "__explicitInterpAMD in vec4 gpu_pos;\n";
591  /* Globals. */
592  ss << "vec3 gpu_BaryCoord;\n";
593  ss << "vec3 gpu_BaryCoordNoPersp;\n";
594  ss << "\n";
595  ss << "vec2 stable_bary_(vec2 in_bary) {\n";
596  ss << " vec3 bary = vec3(in_bary, 1.0 - in_bary.x - in_bary.y);\n";
597  ss << " if (interpolateAtVertexAMD(gpu_pos, 0) == gpu_pos_flat) { return bary.zxy; }\n";
598  ss << " if (interpolateAtVertexAMD(gpu_pos, 2) == gpu_pos_flat) { return bary.yzx; }\n";
599  ss << " return bary.xyz;\n";
600  ss << "}\n";
601  ss << "\n";
602  ss << "vec4 gpu_position_at_vertex(int v) {\n";
603  ss << " if (interpolateAtVertexAMD(gpu_pos, 0) == gpu_pos_flat) { v = (v + 2) % 3; }\n";
604  ss << " if (interpolateAtVertexAMD(gpu_pos, 2) == gpu_pos_flat) { v = (v + 1) % 3; }\n";
605  ss << " return interpolateAtVertexAMD(gpu_pos, v);\n";
606  ss << "}\n";
607 
608  pre_main += " gpu_BaryCoord = stable_bary_(gl_BaryCoordSmoothAMD);\n";
609  pre_main += " gpu_BaryCoordNoPersp = stable_bary_(gl_BaryCoordNoPerspAMD);\n";
610  }
611  }
612  if (info.early_fragment_test_) {
613  ss << "layout(early_fragment_tests) in;\n";
614  }
615  if (GLEW_ARB_conservative_depth) {
616  ss << "layout(" << to_string(info.depth_write_) << ") out float gl_FragDepth;\n";
617  }
618  ss << "\n/* Outputs. */\n";
620  ss << "layout(location = " << output.index;
621  switch (output.blend) {
622  case DualBlend::SRC_0:
623  ss << ", index = 0";
624  break;
625  case DualBlend::SRC_1:
626  ss << ", index = 1";
627  break;
628  default:
629  break;
630  }
631  ss << ") ";
632  ss << "out " << to_string(output.type) << " " << output.name << ";\n";
633  }
634  ss << "\n";
635 
636  if (pre_main.empty() == false) {
637  std::string post_main;
638  ss << main_function_wrapper(pre_main, post_main);
639  }
640  return ss.str();
641 }
642 
644 {
645  int max_verts = info.geometry_layout_.max_vertices;
646  int invocations = info.geometry_layout_.invocations;
647 
648  if (GLContext::geometry_shader_invocations == false && invocations != -1) {
649  max_verts *= invocations;
650  invocations = -1;
651  }
652 
653  std::stringstream ss;
654  ss << "\n/* Geometry Layout. */\n";
655  ss << "layout(" << to_string(info.geometry_layout_.primitive_in);
656  if (invocations != -1) {
657  ss << ", invocations = " << invocations;
658  }
659  ss << ") in;\n";
660 
661  ss << "layout(" << to_string(info.geometry_layout_.primitive_out)
662  << ", max_vertices = " << max_verts << ") out;\n";
663  ss << "\n";
664  return ss.str();
665 }
666 
668  const StringRefNull &name)
669 {
670  for (auto *iface : ifaces) {
671  if (iface->instance_name == name) {
672  return iface;
673  }
674  }
675  return nullptr;
676 }
677 
679 {
680  std::stringstream ss;
681 
682  ss << "\n/* Interfaces. */\n";
683  for (const StageInterfaceInfo *iface : info.vertex_out_interfaces_) {
684  bool has_matching_output_iface = find_interface_by_name(info.geometry_out_interfaces_,
685  iface->instance_name) != nullptr;
686  const char *suffix = (has_matching_output_iface) ? "_in[]" : "[]";
687  print_interface(ss, "in", *iface, suffix);
688  }
689  ss << "\n";
690  for (const StageInterfaceInfo *iface : info.geometry_out_interfaces_) {
691  bool has_matching_input_iface = find_interface_by_name(info.vertex_out_interfaces_,
692  iface->instance_name) != nullptr;
693  const char *suffix = (has_matching_input_iface) ? "_out" : "";
694  print_interface(ss, "out", *iface, suffix);
695  }
696  ss << "\n";
697  return ss.str();
698 }
699 
701 {
702  std::stringstream ss;
703  ss << "\n/* Compute Layout. */\n";
704  ss << "layout(local_size_x = " << info.compute_layout_.local_size_x;
705  if (info.compute_layout_.local_size_y != -1) {
706  ss << ", local_size_y = " << info.compute_layout_.local_size_y;
707  }
708  if (info.compute_layout_.local_size_z != -1) {
709  ss << ", local_size_z = " << info.compute_layout_.local_size_z;
710  }
711  ss << ") in;\n";
712  ss << "\n";
713  return ss.str();
714 }
717 /* -------------------------------------------------------------------- */
722 std::string GLShader::workaround_geometry_shader_source_create(
723  const shader::ShaderCreateInfo &info)
724 {
725  std::stringstream ss;
726 
727  const bool do_layer_workaround = !GLContext::layered_rendering_support &&
728  bool(info.builtins_ & BuiltinBits::LAYER);
729  const bool do_barycentric_workaround = !GLContext::native_barycentric_support &&
730  bool(info.builtins_ & BuiltinBits::BARYCENTRIC_COORD);
731 
732  shader::ShaderCreateInfo info_modified = info;
733  info_modified.geometry_out_interfaces_ = info_modified.vertex_out_interfaces_;
738  info_modified.geometry_layout(PrimitiveIn::TRIANGLES, PrimitiveOut::TRIANGLE_STRIP, 3);
739 
740  ss << geometry_layout_declare(info_modified);
741  ss << geometry_interface_declare(info_modified);
742  if (do_layer_workaround) {
743  ss << "in int gpu_Layer[];\n";
744  }
745  if (do_barycentric_workaround) {
746  ss << "flat out vec4 gpu_pos[3];\n";
747  ss << "smooth out vec3 gpu_BaryCoord;\n";
748  ss << "noperspective out vec3 gpu_BaryCoordNoPersp;\n";
749  }
750  ss << "\n";
751 
752  ss << "void main()\n";
753  ss << "{\n";
754  if (do_layer_workaround) {
755  ss << " gl_Layer = gpu_Layer[0];\n";
756  }
757  if (do_barycentric_workaround) {
758  ss << " gpu_pos[0] = gl_in[0].gl_Position;\n";
759  ss << " gpu_pos[1] = gl_in[1].gl_Position;\n";
760  ss << " gpu_pos[2] = gl_in[2].gl_Position;\n";
761  }
762  for (auto i : IndexRange(3)) {
763  for (StageInterfaceInfo *iface : info_modified.vertex_out_interfaces_) {
764  for (auto &inout : iface->inouts) {
765  ss << " " << iface->instance_name << "_out." << inout.name;
766  ss << " = " << iface->instance_name << "_in[" << i << "]." << inout.name << ";\n";
767  }
768  }
769  if (do_barycentric_workaround) {
770  ss << " gpu_BaryCoordNoPersp = gpu_BaryCoord =";
771  ss << " vec3(" << int(i == 0) << ", " << int(i == 1) << ", " << int(i == 2) << ");\n";
772  }
773  ss << " gl_Position = gl_in[" << i << "].gl_Position;\n";
774  ss << " EmitVertex();\n";
775  }
776  ss << "}\n";
777  return ss.str();
778 }
779 
780 bool GLShader::do_geometry_shader_injection(const shader::ShaderCreateInfo *info)
781 {
782  BuiltinBits builtins = info->builtins_;
783  if (!GLContext::native_barycentric_support && bool(builtins & BuiltinBits::BARYCENTRIC_COORD)) {
784  return true;
785  }
786  if (!GLContext::layered_rendering_support && bool(builtins & BuiltinBits::LAYER)) {
787  return true;
788  }
789  return false;
790 }
791 
794 /* -------------------------------------------------------------------- */
799 {
801  static char patch[2048] = "\0";
802  if (patch[0] != '\0') {
803  return patch;
804  }
805 
806  size_t slen = 0;
807  /* Version need to go first. */
808  if (GLEW_VERSION_4_3) {
809  STR_CONCAT(patch, slen, "#version 430\n");
810  }
811  else {
812  STR_CONCAT(patch, slen, "#version 330\n");
813  }
814 
815  /* Enable extensions for features that are not part of our base GLSL version
816  * don't use an extension for something already available! */
818  STR_CONCAT(patch, slen, "#extension GL_ARB_texture_gather: enable\n");
819  /* Some drivers don't agree on GLEW_ARB_texture_gather and the actual support in the
820  * shader so double check the preprocessor define (see T56544). */
821  STR_CONCAT(patch, slen, "#ifdef GL_ARB_texture_gather\n");
822  STR_CONCAT(patch, slen, "# define GPU_ARB_texture_gather\n");
823  STR_CONCAT(patch, slen, "#endif\n");
824  }
826  STR_CONCAT(patch, slen, "#extension GL_ARB_shader_draw_parameters : enable\n");
827  STR_CONCAT(patch, slen, "#define GPU_ARB_shader_draw_parameters\n");
828  STR_CONCAT(patch, slen, "#define gpu_BaseInstance gl_BaseInstanceARB\n");
829  }
831  STR_CONCAT(patch, slen, "#extension GL_ARB_gpu_shader5 : enable\n");
832  STR_CONCAT(patch, slen, "#define GPU_ARB_gpu_shader5\n");
833  }
835  STR_CONCAT(patch, slen, "#extension GL_ARB_texture_cube_map_array : enable\n");
836  STR_CONCAT(patch, slen, "#define GPU_ARB_texture_cube_map_array\n");
837  }
838  if (GLEW_ARB_conservative_depth) {
839  STR_CONCAT(patch, slen, "#extension GL_ARB_conservative_depth : enable\n");
840  }
842  STR_CONCAT(patch, slen, "#extension GL_ARB_shader_image_load_store: enable\n");
843  STR_CONCAT(patch, slen, "#extension GL_ARB_shading_language_420pack: enable\n");
844  }
846  STR_CONCAT(patch, slen, "#extension GL_AMD_vertex_shader_layer: enable\n");
847  STR_CONCAT(patch, slen, "#define gpu_Layer gl_Layer\n");
848  }
850  STR_CONCAT(patch, slen, "#extension GL_AMD_shader_explicit_vertex_parameter: enable\n");
851  }
852 
853  /* Fallbacks. */
855  STR_CONCAT(patch, slen, "uniform int gpu_BaseInstance;\n");
856  }
857 
858  /* Vulkan GLSL compat. */
859  STR_CONCAT(patch, slen, "#define gpu_InstanceIndex (gl_InstanceID + gpu_BaseInstance)\n");
860 
861  /* Array compat. */
862  STR_CONCAT(patch, slen, "#define gpu_Array(_type) _type[]\n");
863 
864  /* Derivative sign can change depending on implementation. */
865  STR_CONCATF(patch, slen, "#define DFDX_SIGN %1.1f\n", GLContext::derivative_signs[0]);
866  STR_CONCATF(patch, slen, "#define DFDY_SIGN %1.1f\n", GLContext::derivative_signs[1]);
867 
868  /* GLSL Backend Lib. */
870 
871  BLI_assert(slen < sizeof(patch));
872  return patch;
873 }
874 
876 {
878  static char patch[2048] = "\0";
879  if (patch[0] != '\0') {
880  return patch;
881  }
882 
883  size_t slen = 0;
884  /* Version need to go first. */
885  STR_CONCAT(patch, slen, "#version 430\n");
886  STR_CONCAT(patch, slen, "#extension GL_ARB_compute_shader :enable\n");
887 
888  /* Array compat. */
889  STR_CONCAT(patch, slen, "#define gpu_Array(_type) _type[]\n");
890 
892 
893  BLI_assert(slen < sizeof(patch));
894  return patch;
895 }
896 
897 char *GLShader::glsl_patch_get(GLenum gl_stage)
898 {
899  if (gl_stage == GL_COMPUTE_SHADER) {
900  return glsl_patch_compute_get();
901  }
902  return glsl_patch_default_get();
903 }
904 
905 GLuint GLShader::create_shader_stage(GLenum gl_stage, MutableSpan<const char *> sources)
906 {
907  GLuint shader = glCreateShader(gl_stage);
908  if (shader == 0) {
909  fprintf(stderr, "GLShader: Error: Could not create shader object.\n");
910  return 0;
911  }
912 
913  /* Patch the shader code using the first source slot. */
914  sources[0] = glsl_patch_get(gl_stage);
915 
916  glShaderSource(shader, sources.size(), sources.data(), nullptr);
917  glCompileShader(shader);
918 
919  GLint status;
920  glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
921  if (!status || (G.debug & G_DEBUG_GPU)) {
922  char log[5000] = "";
923  glGetShaderInfoLog(shader, sizeof(log), nullptr, log);
924  if (log[0] != '\0') {
925  GLLogParser parser;
926  switch (gl_stage) {
927  case GL_VERTEX_SHADER:
928  this->print_log(sources, log, "VertShader", !status, &parser);
929  break;
930  case GL_GEOMETRY_SHADER:
931  this->print_log(sources, log, "GeomShader", !status, &parser);
932  break;
933  case GL_FRAGMENT_SHADER:
934  this->print_log(sources, log, "FragShader", !status, &parser);
935  break;
936  case GL_COMPUTE_SHADER:
937  this->print_log(sources, log, "ComputeShader", !status, &parser);
938  break;
939  }
940  }
941  }
942  if (!status) {
943  glDeleteShader(shader);
944  compilation_failed_ = true;
945  return 0;
946  }
947 
948  debug::object_label(gl_stage, shader, name);
949 
950  glAttachShader(shader_program_, shader);
951  return shader;
952 }
953 
955 {
956  vert_shader_ = this->create_shader_stage(GL_VERTEX_SHADER, sources);
957 }
958 
960 {
961  geom_shader_ = this->create_shader_stage(GL_GEOMETRY_SHADER, sources);
962 }
963 
965 {
966  frag_shader_ = this->create_shader_stage(GL_FRAGMENT_SHADER, sources);
967 }
968 
970 {
971  compute_shader_ = this->create_shader_stage(GL_COMPUTE_SHADER, sources);
972 }
973 
975 {
976  if (compilation_failed_) {
977  return false;
978  }
979 
980  if (info && do_geometry_shader_injection(info)) {
981  std::string source = workaround_geometry_shader_source_create(*info);
982  Vector<const char *> sources;
983  sources.append("version");
984  sources.append(source.c_str());
985  geometry_shader_from_glsl(sources);
986  }
987 
988  glLinkProgram(shader_program_);
989 
990  GLint status;
991  glGetProgramiv(shader_program_, GL_LINK_STATUS, &status);
992  if (!status) {
993  char log[5000];
994  glGetProgramInfoLog(shader_program_, sizeof(log), nullptr, log);
995  Span<const char *> sources;
996  GLLogParser parser;
997  this->print_log(sources, log, "Linking", true, &parser);
998  return false;
999  }
1000 
1001  if (info != nullptr && info->legacy_resource_location_ == false) {
1002  interface = new GLShaderInterface(shader_program_, *info);
1003  }
1004  else {
1005  interface = new GLShaderInterface(shader_program_);
1006  }
1007 
1008  return true;
1009 }
1010 
1013 /* -------------------------------------------------------------------- */
1018 {
1019  BLI_assert(shader_program_ != 0);
1020  glUseProgram(shader_program_);
1021 }
1022 
1024 {
1025 #ifndef NDEBUG
1026  glUseProgram(0);
1027 #endif
1028 }
1029 
1032 /* -------------------------------------------------------------------- */
1039  const eGPUShaderTFBType geom_type)
1040 {
1041  glTransformFeedbackVaryings(
1042  shader_program_, name_list.size(), name_list.data(), GL_INTERLEAVED_ATTRIBS);
1043  transform_feedback_type_ = geom_type;
1044 }
1045 
1047 {
1048  if (transform_feedback_type_ == GPU_SHADER_TFB_NONE) {
1049  return false;
1050  }
1051 
1052  GLVertBuf *buf = static_cast<GLVertBuf *>(unwrap(buf_));
1053 
1054  BLI_assert(buf->vbo_id_ != 0);
1055 
1056  glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf->vbo_id_);
1057 
1058  switch (transform_feedback_type_) {
1059  case GPU_SHADER_TFB_POINTS:
1060  glBeginTransformFeedback(GL_POINTS);
1061  break;
1062  case GPU_SHADER_TFB_LINES:
1063  glBeginTransformFeedback(GL_LINES);
1064  break;
1066  glBeginTransformFeedback(GL_TRIANGLES);
1067  break;
1068  default:
1069  return false;
1070  }
1071  return true;
1072 }
1073 
1075 {
1076  glEndTransformFeedback();
1077 }
1078 
1081 /* -------------------------------------------------------------------- */
1085 void GLShader::uniform_float(int location, int comp_len, int array_size, const float *data)
1086 {
1087  switch (comp_len) {
1088  case 1:
1089  glUniform1fv(location, array_size, data);
1090  break;
1091  case 2:
1092  glUniform2fv(location, array_size, data);
1093  break;
1094  case 3:
1095  glUniform3fv(location, array_size, data);
1096  break;
1097  case 4:
1098  glUniform4fv(location, array_size, data);
1099  break;
1100  case 9:
1101  glUniformMatrix3fv(location, array_size, 0, data);
1102  break;
1103  case 16:
1104  glUniformMatrix4fv(location, array_size, 0, data);
1105  break;
1106  default:
1107  BLI_assert(0);
1108  break;
1109  }
1110 }
1111 
1112 void GLShader::uniform_int(int location, int comp_len, int array_size, const int *data)
1113 {
1114  switch (comp_len) {
1115  case 1:
1116  glUniform1iv(location, array_size, data);
1117  break;
1118  case 2:
1119  glUniform2iv(location, array_size, data);
1120  break;
1121  case 3:
1122  glUniform3iv(location, array_size, data);
1123  break;
1124  case 4:
1125  glUniform4iv(location, array_size, data);
1126  break;
1127  default:
1128  BLI_assert(0);
1129  break;
1130  }
1131 }
1132 
1135 /* -------------------------------------------------------------------- */
1139 static uint calc_component_size(const GLenum gl_type)
1140 {
1141  switch (gl_type) {
1142  case GL_FLOAT_VEC2:
1143  case GL_INT_VEC2:
1144  case GL_UNSIGNED_INT_VEC2:
1145  return 2;
1146  case GL_FLOAT_VEC3:
1147  case GL_INT_VEC3:
1148  case GL_UNSIGNED_INT_VEC3:
1149  return 3;
1150  case GL_FLOAT_VEC4:
1151  case GL_FLOAT_MAT2:
1152  case GL_INT_VEC4:
1153  case GL_UNSIGNED_INT_VEC4:
1154  return 4;
1155  case GL_FLOAT_MAT3:
1156  return 9;
1157  case GL_FLOAT_MAT4:
1158  return 16;
1159  case GL_FLOAT_MAT2x3:
1160  case GL_FLOAT_MAT3x2:
1161  return 6;
1162  case GL_FLOAT_MAT2x4:
1163  case GL_FLOAT_MAT4x2:
1164  return 8;
1165  case GL_FLOAT_MAT3x4:
1166  case GL_FLOAT_MAT4x3:
1167  return 12;
1168  default:
1169  return 1;
1170  }
1171 }
1172 
1173 static void get_fetch_mode_and_comp_type(int gl_type,
1174  GPUVertCompType *r_comp_type,
1175  GPUVertFetchMode *r_fetch_mode)
1176 {
1177  switch (gl_type) {
1178  case GL_FLOAT:
1179  case GL_FLOAT_VEC2:
1180  case GL_FLOAT_VEC3:
1181  case GL_FLOAT_VEC4:
1182  case GL_FLOAT_MAT2:
1183  case GL_FLOAT_MAT3:
1184  case GL_FLOAT_MAT4:
1185  case GL_FLOAT_MAT2x3:
1186  case GL_FLOAT_MAT2x4:
1187  case GL_FLOAT_MAT3x2:
1188  case GL_FLOAT_MAT3x4:
1189  case GL_FLOAT_MAT4x2:
1190  case GL_FLOAT_MAT4x3:
1191  *r_comp_type = GPU_COMP_F32;
1192  *r_fetch_mode = GPU_FETCH_FLOAT;
1193  break;
1194  case GL_INT:
1195  case GL_INT_VEC2:
1196  case GL_INT_VEC3:
1197  case GL_INT_VEC4:
1198  *r_comp_type = GPU_COMP_I32;
1199  *r_fetch_mode = GPU_FETCH_INT;
1200  break;
1201  case GL_UNSIGNED_INT:
1202  case GL_UNSIGNED_INT_VEC2:
1203  case GL_UNSIGNED_INT_VEC3:
1204  case GL_UNSIGNED_INT_VEC4:
1205  *r_comp_type = GPU_COMP_U32;
1206  *r_fetch_mode = GPU_FETCH_INT;
1207  break;
1208  default:
1209  BLI_assert(0);
1210  }
1211 }
1212 
1214 {
1216 
1217  GLint attr_len;
1218  glGetProgramiv(shader_program_, GL_ACTIVE_ATTRIBUTES, &attr_len);
1219 
1220  for (int i = 0; i < attr_len; i++) {
1221  char name[256];
1222  GLenum gl_type;
1223  GLint size;
1224  glGetActiveAttrib(shader_program_, i, sizeof(name), nullptr, &size, &gl_type, name);
1225 
1226  /* Ignore OpenGL names like `gl_BaseInstanceARB`, `gl_InstanceID` and `gl_VertexID`. */
1227  if (glGetAttribLocation(shader_program_, name) == -1) {
1228  continue;
1229  }
1230 
1231  GPUVertCompType comp_type;
1232  GPUVertFetchMode fetch_mode;
1233  get_fetch_mode_and_comp_type(gl_type, &comp_type, &fetch_mode);
1234 
1235  int comp_len = calc_component_size(gl_type) * size;
1236 
1237  GPU_vertformat_attr_add(format, name, comp_type, comp_len, fetch_mode);
1238  }
1239 }
1240 
1242 {
1243  return (int)this->shader_program_;
1244 }
1245 
@ G_DEBUG_GPU
Definition: BKE_global.h:193
#define BLI_assert(a)
Definition: BLI_assert.h:46
KDTree *BLI_kdtree_nd_() new(unsigned int maxsize)
Definition: kdtree_impl.h:85
#define STR_CONCATF(dst, len, format,...)
Definition: BLI_string.h:490
#define STR_CONCAT(dst, len, suffix)
Definition: BLI_string.h:488
unsigned int uint
Definition: BLI_sys_types.h:67
typedef UINT(API *GHOST_WIN32_GetDpiForWindow)(HWND)
bool GPU_shader_image_load_store_support(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 type
@ GPU_BACKEND_OPENGL
Definition: GPU_platform.h:17
@ GPU_DRIVER_ANY
Definition: GPU_platform.h:47
@ GPU_DRIVER_OFFICIAL
Definition: GPU_platform.h:44
bool GPU_type_matches_ex(eGPUDeviceType device, eGPUOSType os, eGPUDriverType driver, eGPUBackendType backend)
@ 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_APPLE
Definition: GPU_platform.h:28
bool GPU_type_matches(eGPUDeviceType device, eGPUOSType os, eGPUDriverType driver)
eGPUShaderTFBType
Definition: GPU_shader.h:22
@ GPU_SHADER_TFB_TRIANGLES
Definition: GPU_shader.h:26
@ GPU_SHADER_TFB_NONE
Definition: GPU_shader.h:23
@ GPU_SHADER_TFB_LINES
Definition: GPU_shader.h:25
@ GPU_SHADER_TFB_POINTS
Definition: GPU_shader.h:24
eGPUTextureFormat
Definition: GPU_texture.h:83
@ GPU_R16UI
Definition: GPU_texture.h:111
@ GPU_RG16F
Definition: GPU_texture.h:103
@ GPU_R16I
Definition: GPU_texture.h:112
@ GPU_RGB10_A2
Definition: GPU_texture.h:117
@ GPU_R32I
Definition: GPU_texture.h:109
@ GPU_RG8UI
Definition: GPU_texture.h:95
@ GPU_R16F
Definition: GPU_texture.h:113
@ GPU_RG8I
Definition: GPU_texture.h:96
@ GPU_RG16I
Definition: GPU_texture.h:102
@ GPU_RG32UI
Definition: GPU_texture.h:98
@ GPU_RGBA32F
Definition: GPU_texture.h:90
@ GPU_RG8
Definition: GPU_texture.h:97
@ GPU_RG32I
Definition: GPU_texture.h:99
@ GPU_RG16
Definition: GPU_texture.h:104
@ GPU_RGBA32UI
Definition: GPU_texture.h:88
@ GPU_R8I
Definition: GPU_texture.h:106
@ GPU_R16
Definition: GPU_texture.h:114
@ GPU_RG16UI
Definition: GPU_texture.h:101
@ GPU_RGBA8I
Definition: GPU_texture.h:86
@ GPU_RGBA8UI
Definition: GPU_texture.h:85
@ GPU_RGBA16UI
Definition: GPU_texture.h:91
@ GPU_RGBA16I
Definition: GPU_texture.h:92
@ GPU_R8UI
Definition: GPU_texture.h:105
@ GPU_RGBA16
Definition: GPU_texture.h:94
@ GPU_RG32F
Definition: GPU_texture.h:100
@ GPU_R8
Definition: GPU_texture.h:107
@ GPU_R32UI
Definition: GPU_texture.h:108
@ GPU_RGBA32I
Definition: GPU_texture.h:89
@ GPU_R11F_G11F_B10F
Definition: GPU_texture.h:118
@ GPU_RGBA8
Definition: GPU_texture.h:87
struct GPUVertBuf GPUVertBuf
GPUVertFetchMode
@ GPU_FETCH_FLOAT
@ GPU_FETCH_INT
uint GPU_vertformat_attr_add(GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
void GPU_vertformat_clear(GPUVertFormat *)
GPUVertCompType
@ GPU_COMP_F32
@ GPU_COMP_I32
@ GPU_COMP_U32
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
constexpr int64_t size() const
Definition: BLI_span.hh:511
constexpr T * data() const
Definition: BLI_span.hh:548
constexpr const T * data() const
Definition: BLI_span.hh:203
constexpr int64_t size() const
Definition: BLI_span.hh:240
constexpr bool is_empty() const
void append(const T &value)
Definition: BLI_vector.hh:433
static bool geometry_shader_invocations
Definition: gl_context.hh:59
static bool layered_rendering_support
Definition: gl_context.hh:61
static bool shader_draw_parameters_support
Definition: gl_context.hh:65
static bool explicit_location_support
Definition: gl_context.hh:58
static float derivative_signs[2]
Definition: gl_context.hh:78
static bool texture_gather_support
Definition: gl_context.hh:69
static GLContext * get()
Definition: gl_context.hh:117
static bool texture_cube_map_array_support
Definition: gl_context.hh:67
static bool native_barycentric_support
Definition: gl_context.hh:62
std::string geometry_layout_declare(const shader::ShaderCreateInfo &info) const override
Definition: gl_shader.cc:643
std::string vertex_interface_declare(const shader::ShaderCreateInfo &info) const override
Definition: gl_shader.cc:518
std::string geometry_interface_declare(const shader::ShaderCreateInfo &info) const override
Definition: gl_shader.cc:678
void fragment_shader_from_glsl(MutableSpan< const char * > sources) override
Definition: gl_shader.cc:964
void unbind() override
Definition: gl_shader.cc:1023
void uniform_float(int location, int comp_len, int array_size, const float *data) override
Definition: gl_shader.cc:1085
void transform_feedback_names_set(Span< const char * > name_list, eGPUShaderTFBType geom_type) override
Definition: gl_shader.cc:1038
bool transform_feedback_enable(GPUVertBuf *buf) override
Definition: gl_shader.cc:1046
GLShader(const char *name)
Definition: gl_shader.cc:32
void bind() override
Definition: gl_shader.cc:1017
void compute_shader_from_glsl(MutableSpan< const char * > sources) override
Definition: gl_shader.cc:969
std::string compute_layout_declare(const shader::ShaderCreateInfo &info) const override
Definition: gl_shader.cc:700
int program_handle_get() const override
Definition: gl_shader.cc:1241
std::string resources_declare(const shader::ShaderCreateInfo &info) const override
Definition: gl_shader.cc:459
void vertformat_from_shader(GPUVertFormat *format) const override
Definition: gl_shader.cc:1213
void uniform_int(int location, int comp_len, int array_size, const int *data) override
Definition: gl_shader.cc:1112
std::string fragment_interface_declare(const shader::ShaderCreateInfo &info) const override
Definition: gl_shader.cc:565
bool finalize(const shader::ShaderCreateInfo *info=nullptr) override
Definition: gl_shader.cc:974
void geometry_shader_from_glsl(MutableSpan< const char * > sources) override
Definition: gl_shader.cc:959
void vertex_shader_from_glsl(MutableSpan< const char * > sources) override
Definition: gl_shader.cc:954
void transform_feedback_disable() override
Definition: gl_shader.cc:1074
void print_log(Span< const char * > sources, char *log, const char *stage, bool error, GPULogParser *parser)
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img GPU_RGBA16F
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx GPU_R32F
static void print_interface(std::ostream &os, const StringRefNull &prefix, const StageInterfaceInfo &iface, const StringRefNull &suffix="")
Definition: gl_shader.cc:439
static StageInterfaceInfo * find_interface_by_name(const Vector< StageInterfaceInfo * > &ifaces, const StringRefNull &name)
Definition: gl_shader.cc:667
static void print_resource(std::ostream &os, const ShaderCreateInfo::Resource &res)
Definition: gl_shader.cc:363
static void print_resource_alias(std::ostream &os, const ShaderCreateInfo::Resource &res)
Definition: gl_shader.cc:416
static const char * to_string(const Interpolation &interp)
Definition: gl_shader.cc:63
static void print_image_type(std::ostream &os, const ImageType &type, const ShaderCreateInfo::Resource::BindType bind_type)
Definition: gl_shader.cc:233
static uint calc_component_size(const GLenum gl_type)
Definition: gl_shader.cc:1139
static std::ostream & print_qualifier(std::ostream &os, const Qualifier &qualifiers)
Definition: gl_shader.cc:349
static std::string main_function_wrapper(std::string &pre_main, std::string &post_main)
Definition: gl_shader.cc:500
static char * glsl_patch_compute_get()
Definition: gl_shader.cc:875
char datatoc_glsl_shader_defines_glsl[]
Definition: gl_shader.cc:26
static void get_fetch_mode_and_comp_type(int gl_type, GPUVertCompType *r_comp_type, GPUVertFetchMode *r_fetch_mode)
Definition: gl_shader.cc:1173
static char * glsl_patch_default_get()
Definition: gl_shader.cc:798
ccl_global KernelShaderEvalInput ccl_global float * output
format
Definition: logImageCore.h:38
ccl_device_inline float2 interp(const float2 &a, const float2 &b, float t)
Definition: math_float2.h:232
ccl_device_inline float3 log(float3 v)
Definition: math_float3.h:397
#define G(x, y, z)
void object_label(GLenum type, GLuint object, const char *name)
Definition: gl_debug.cc:328
static Context * unwrap(GPUContext *ctx)
@ FLOAT
__int64 int64_t
Definition: stdint.h:89
Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correc...
Vector< StageInterfaceInfo * > vertex_out_interfaces_
Vector< StageInterfaceInfo * > geometry_out_interfaces_
Self & geometry_layout(PrimitiveIn prim_in, PrimitiveOut prim_out, int max_vertices, int invocations=-1)