| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2005 Blender Foundation. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup gpu | 
					
						
							| 
									
										
										
										
											2018-08-30 01:56:08 +10:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-23 19:29:27 +02:00
										 |  |  | #include "BLI_dynstr.h"
 | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | #include "BLI_math_base.h"
 | 
					
						
							|  |  |  | #include "BLI_math_vector.h"
 | 
					
						
							| 
									
										
										
										
											2017-09-27 18:03:00 +02:00
										 |  |  | #include "BLI_path_util.h"
 | 
					
						
							| 
									
										
										
										
											2018-08-02 18:31:38 +02:00
										 |  |  | #include "BLI_string.h"
 | 
					
						
							| 
									
										
										
										
											2019-02-06 09:15:16 +11:00
										 |  |  | #include "BLI_string_utils.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  | #include "BLI_vector.hh"
 | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-27 18:03:00 +02:00
										 |  |  | #include "BKE_appdir.h"
 | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | #include "BKE_global.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-27 18:03:00 +02:00
										 |  |  | #include "DNA_space_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-07 19:35:56 +02:00
										 |  |  | #include "GPU_capabilities.h"
 | 
					
						
							| 
									
										
										
										
											2017-04-18 16:30:13 +02:00
										 |  |  | #include "GPU_matrix.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "GPU_platform.h"
 | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | #include "GPU_shader.h"
 | 
					
						
							|  |  |  | #include "GPU_texture.h"
 | 
					
						
							| 
									
										
										
										
											2020-08-20 23:09:37 +02:00
										 |  |  | #include "GPU_uniform_buffer.h"
 | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  | #include "gpu_backend.hh"
 | 
					
						
							| 
									
										
										
										
											2020-08-09 00:52:45 +02:00
										 |  |  | #include "gpu_context_private.hh"
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  | #include "gpu_shader_private.hh"
 | 
					
						
							| 
									
										
										
										
											2016-09-16 17:18:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-23 19:29:27 +02:00
										 |  |  | #include "CLG_log.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-29 16:07:51 +02:00
										 |  |  | extern "C" char datatoc_gpu_shader_colorspace_lib_glsl[]; | 
					
						
							| 
									
										
										
										
											2020-07-28 20:04:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-23 19:29:27 +02:00
										 |  |  | static CLG_LogRef LOG = {"gpu.shader"}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  | using namespace blender; | 
					
						
							|  |  |  | using namespace blender::gpu; | 
					
						
							| 
									
										
										
										
											2018-08-02 18:31:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-02 00:09:43 +10:00
										 |  |  | static bool gpu_shader_srgb_uniform_dirty_get(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 20:04:15 +02:00
										 |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  | /** \name Debug functions
 | 
					
						
							| 
									
										
										
										
											2020-07-28 20:04:15 +02:00
										 |  |  |  * \{ */ | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-23 19:29:27 +02:00
										 |  |  | void Shader::print_log(Span<const char *> sources, char *log, const char *stage, const bool error) | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-14 18:13:23 +02:00
										 |  |  |   const char line_prefix[] = "      | "; | 
					
						
							| 
									
										
										
										
											2020-10-23 19:29:27 +02:00
										 |  |  |   char err_col[] = "\033[31;1m"; | 
					
						
							|  |  |  |   char warn_col[] = "\033[33;1m"; | 
					
						
							|  |  |  |   char info_col[] = "\033[0;2m"; | 
					
						
							|  |  |  |   char reset_col[] = "\033[0;0m"; | 
					
						
							| 
									
										
										
										
											2020-08-14 18:13:23 +02:00
										 |  |  |   char *sources_combined = BLI_string_join_arrayN((const char **)sources.data(), sources.size()); | 
					
						
							| 
									
										
										
										
											2020-10-23 19:29:27 +02:00
										 |  |  |   DynStr *dynstr = BLI_dynstr_new(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!CLG_color_support_get(&LOG)) { | 
					
						
							|  |  |  |     err_col[0] = warn_col[0] = info_col[0] = reset_col[0] = '\0'; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-23 19:29:27 +02:00
										 |  |  |   BLI_dynstr_appendf(dynstr, "\n"); | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 18:13:23 +02:00
										 |  |  |   char *log_line = log, *line_end; | 
					
						
							|  |  |  |   char *error_line_number_end; | 
					
						
							|  |  |  |   int error_line, error_char, last_error_line = -2, last_error_char = -1; | 
					
						
							|  |  |  |   bool found_line_id = false; | 
					
						
							|  |  |  |   while ((line_end = strchr(log_line, '\n'))) { | 
					
						
							|  |  |  |     /* Skip empty lines. */ | 
					
						
							|  |  |  |     if (line_end == log_line) { | 
					
						
							|  |  |  |       log_line++; | 
					
						
							|  |  |  |       continue; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-30 13:08:59 +02:00
										 |  |  |     /* 0 = error, 1 = warning. */ | 
					
						
							|  |  |  |     int type = -1; | 
					
						
							| 
									
										
										
										
											2020-08-14 18:13:23 +02:00
										 |  |  |     /* Skip ERROR: or WARNING:. */ | 
					
						
							|  |  |  |     const char *prefix[] = {"ERROR", "WARNING"}; | 
					
						
							|  |  |  |     for (int i = 0; i < ARRAY_SIZE(prefix); i++) { | 
					
						
							|  |  |  |       if (STREQLEN(log_line, prefix[i], strlen(prefix[i]))) { | 
					
						
							|  |  |  |         log_line += strlen(prefix[i]); | 
					
						
							| 
									
										
										
										
											2020-08-30 13:08:59 +02:00
										 |  |  |         type = i; | 
					
						
							| 
									
										
										
										
											2020-08-14 18:13:23 +02:00
										 |  |  |         break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-30 13:08:59 +02:00
										 |  |  |     /* Skip whitespaces and separators. */ | 
					
						
							|  |  |  |     while (ELEM(log_line[0], ':', '(', ' ')) { | 
					
						
							|  |  |  |       log_line++; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     /* Parse error line & char numbers. */ | 
					
						
							| 
									
										
										
										
											2020-08-14 18:13:23 +02:00
										 |  |  |     error_line = error_char = -1; | 
					
						
							| 
									
										
										
										
											2020-08-30 13:08:59 +02:00
										 |  |  |     if (log_line[0] >= '0' && log_line[0] <= '9') { | 
					
						
							|  |  |  |       error_line = (int)strtol(log_line, &error_line_number_end, 10); | 
					
						
							| 
									
										
										
										
											2021-02-05 16:23:34 +11:00
										 |  |  |       /* Try to fetch the error character (not always available). */ | 
					
						
							| 
									
										
										
										
											2020-08-30 13:08:59 +02:00
										 |  |  |       if (ELEM(error_line_number_end[0], '(', ':') && error_line_number_end[1] != ' ') { | 
					
						
							|  |  |  |         error_char = (int)strtol(error_line_number_end + 1, &log_line, 10); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							|  |  |  |         log_line = error_line_number_end; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       /* There can be a 3rd number (case of mesa driver). */ | 
					
						
							|  |  |  |       if (ELEM(log_line[0], '(', ':') && log_line[1] >= '0' && log_line[1] <= '9') { | 
					
						
							|  |  |  |         error_line = error_char; | 
					
						
							|  |  |  |         error_char = (int)strtol(log_line + 1, &error_line_number_end, 10); | 
					
						
							|  |  |  |         log_line = error_line_number_end; | 
					
						
							| 
									
										
										
										
											2020-08-14 18:13:23 +02:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-30 13:08:59 +02:00
										 |  |  |     /* Skip whitespaces and separators. */ | 
					
						
							|  |  |  |     while (ELEM(log_line[0], ':', ')', ' ')) { | 
					
						
							|  |  |  |       log_line++; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-19 11:57:28 +02:00
										 |  |  |     if (error_line == -1) { | 
					
						
							| 
									
										
										
										
											2020-08-14 18:13:23 +02:00
										 |  |  |       found_line_id = false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     const char *src_line = sources_combined; | 
					
						
							| 
									
										
										
										
											2020-08-30 13:08:59 +02:00
										 |  |  |     if ((error_line != -1) && (error_char != -1)) { | 
					
						
							|  |  |  |       if (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_UNIX, GPU_DRIVER_OFFICIAL)) { | 
					
						
							|  |  |  |         /* source:line */ | 
					
						
							|  |  |  |         int error_source = error_line; | 
					
						
							|  |  |  |         if (error_source < sources.size()) { | 
					
						
							|  |  |  |           src_line = sources[error_source]; | 
					
						
							|  |  |  |           error_line = error_char; | 
					
						
							|  |  |  |           error_char = -1; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       else if (GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_ANY, GPU_DRIVER_OFFICIAL) || | 
					
						
							|  |  |  |                GPU_type_matches(GPU_DEVICE_INTEL, GPU_OS_MAC, GPU_DRIVER_OFFICIAL)) { | 
					
						
							|  |  |  |         /* 0:line */ | 
					
						
							| 
									
										
										
										
											2020-08-14 18:13:23 +02:00
										 |  |  |         error_line = error_char; | 
					
						
							|  |  |  |         error_char = -1; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-08-30 13:08:59 +02:00
										 |  |  |       else { | 
					
						
							|  |  |  |         /* line:char */ | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-08-14 18:13:23 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     /* Separate from previous block. */ | 
					
						
							|  |  |  |     if (last_error_line != error_line) { | 
					
						
							| 
									
										
										
										
											2020-10-23 19:29:27 +02:00
										 |  |  |       BLI_dynstr_appendf(dynstr, "%s%s%s\n", info_col, line_prefix, reset_col); | 
					
						
							| 
									
										
										
										
											2020-08-30 13:08:59 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     else if (error_char != last_error_char) { | 
					
						
							| 
									
										
										
										
											2020-10-23 19:29:27 +02:00
										 |  |  |       BLI_dynstr_appendf(dynstr, "%s\n", line_prefix); | 
					
						
							| 
									
										
										
										
											2020-08-14 18:13:23 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     /* Print line from the source file that is producing the error. */ | 
					
						
							|  |  |  |     if ((error_line != -1) && (error_line != last_error_line || error_char != last_error_char)) { | 
					
						
							|  |  |  |       const char *src_line_end = src_line; | 
					
						
							|  |  |  |       found_line_id = false; | 
					
						
							|  |  |  |       /* error_line is 1 based in this case. */ | 
					
						
							|  |  |  |       int src_line_index = 1; | 
					
						
							|  |  |  |       while ((src_line_end = strchr(src_line, '\n'))) { | 
					
						
							|  |  |  |         if (src_line_index == error_line) { | 
					
						
							|  |  |  |           found_line_id = true; | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-02-20 17:02:52 +01:00
										 |  |  | /* TODO(fclem) Make this an option to display N lines before error. */ | 
					
						
							|  |  |  | #if 0 /* Uncomment to print shader file up to the error line to have more context. */
 | 
					
						
							|  |  |  |         BLI_dynstr_appendf(dynstr, "%5d | ", src_line_index); | 
					
						
							|  |  |  |         BLI_dynstr_nappend(dynstr, src_line, (src_line_end + 1) - src_line); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-08-14 18:13:23 +02:00
										 |  |  |         /* Continue to next line. */ | 
					
						
							|  |  |  |         src_line = src_line_end + 1; | 
					
						
							|  |  |  |         src_line_index++; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       /* Print error source. */ | 
					
						
							|  |  |  |       if (found_line_id) { | 
					
						
							| 
									
										
										
										
											2020-08-30 13:08:59 +02:00
										 |  |  |         if (error_line != last_error_line) { | 
					
						
							| 
									
										
										
										
											2020-10-23 19:29:27 +02:00
										 |  |  |           BLI_dynstr_appendf(dynstr, "%5d | ", src_line_index); | 
					
						
							| 
									
										
										
										
											2020-08-30 13:08:59 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							| 
									
										
										
										
											2020-10-23 19:29:27 +02:00
										 |  |  |           BLI_dynstr_appendf(dynstr, line_prefix); | 
					
						
							| 
									
										
										
										
											2020-08-30 13:08:59 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-10-23 19:29:27 +02:00
										 |  |  |         BLI_dynstr_nappend(dynstr, src_line, (src_line_end + 1) - src_line); | 
					
						
							| 
									
										
										
										
											2020-08-14 18:13:23 +02:00
										 |  |  |         /* Print char offset. */ | 
					
						
							| 
									
										
										
										
											2020-10-23 19:29:27 +02:00
										 |  |  |         BLI_dynstr_appendf(dynstr, line_prefix); | 
					
						
							| 
									
										
										
										
											2020-08-14 18:13:23 +02:00
										 |  |  |         if (error_char != -1) { | 
					
						
							|  |  |  |           for (int i = 0; i < error_char; i++) { | 
					
						
							| 
									
										
										
										
											2020-10-23 19:29:27 +02:00
										 |  |  |             BLI_dynstr_appendf(dynstr, " "); | 
					
						
							| 
									
										
										
										
											2020-08-14 18:13:23 +02:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2020-10-23 19:29:27 +02:00
										 |  |  |           BLI_dynstr_appendf(dynstr, "^"); | 
					
						
							| 
									
										
										
										
											2020-08-14 18:13:23 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-10-23 19:29:27 +02:00
										 |  |  |         BLI_dynstr_appendf(dynstr, "\n"); | 
					
						
							| 
									
										
										
										
											2020-08-14 18:13:23 +02:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-10-23 19:29:27 +02:00
										 |  |  |     BLI_dynstr_appendf(dynstr, line_prefix); | 
					
						
							| 
									
										
										
										
											2020-08-30 13:08:59 +02:00
										 |  |  |     /* Skip to message. Avoid redundant info. */ | 
					
						
							|  |  |  |     const char *keywords[] = {"error", "warning"}; | 
					
						
							|  |  |  |     for (int i = 0; i < ARRAY_SIZE(prefix); i++) { | 
					
						
							|  |  |  |       if (STREQLEN(log_line, keywords[i], strlen(keywords[i]))) { | 
					
						
							|  |  |  |         log_line += strlen(keywords[i]); | 
					
						
							|  |  |  |         type = i; | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2020-08-14 18:13:23 +02:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-30 13:08:59 +02:00
										 |  |  |     /* Skip and separators. */ | 
					
						
							|  |  |  |     while (ELEM(log_line[0], ':', ')')) { | 
					
						
							|  |  |  |       log_line++; | 
					
						
							| 
									
										
										
										
											2020-08-14 18:13:23 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-30 13:08:59 +02:00
										 |  |  |     if (type == 0) { | 
					
						
							| 
									
										
										
										
											2020-10-23 19:29:27 +02:00
										 |  |  |       BLI_dynstr_appendf(dynstr, "%s%s%s: ", err_col, "Error", info_col); | 
					
						
							| 
									
										
										
										
											2020-08-14 18:13:23 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-30 13:08:59 +02:00
										 |  |  |     else if (type == 1) { | 
					
						
							| 
									
										
										
										
											2020-10-23 19:29:27 +02:00
										 |  |  |       BLI_dynstr_appendf(dynstr, "%s%s%s: ", warn_col, "Warning", info_col); | 
					
						
							| 
									
										
										
										
											2020-08-30 13:08:59 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     /* Print the error itself. */ | 
					
						
							| 
									
										
										
										
											2020-10-26 12:01:59 +01:00
										 |  |  |     BLI_dynstr_append(dynstr, info_col); | 
					
						
							| 
									
										
										
										
											2020-10-23 19:29:27 +02:00
										 |  |  |     BLI_dynstr_nappend(dynstr, log_line, (line_end + 1) - log_line); | 
					
						
							| 
									
										
										
										
											2020-10-26 12:01:59 +01:00
										 |  |  |     BLI_dynstr_append(dynstr, reset_col); | 
					
						
							| 
									
										
										
										
											2020-08-14 18:13:23 +02:00
										 |  |  |     /* Continue to next line. */ | 
					
						
							|  |  |  |     log_line = line_end + 1; | 
					
						
							|  |  |  |     last_error_line = error_line; | 
					
						
							|  |  |  |     last_error_char = error_char; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   MEM_freeN(sources_combined); | 
					
						
							| 
									
										
										
										
											2020-10-23 19:29:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   CLG_Severity severity = error ? CLG_SEVERITY_ERROR : CLG_SEVERITY_WARN; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (((LOG.type->flag & CLG_FLAG_USE) && (LOG.type->level >= 0)) || | 
					
						
							|  |  |  |       (severity >= CLG_SEVERITY_WARN)) { | 
					
						
							|  |  |  |     const char *_str = BLI_dynstr_get_cstring(dynstr); | 
					
						
							|  |  |  |     CLG_log_str(LOG.type, severity, this->name, stage, _str); | 
					
						
							|  |  |  |     MEM_freeN((void *)_str); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   BLI_dynstr_free(dynstr); | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Creation / Destruction
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Shader::Shader(const char *sh_name) | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |   BLI_strncpy(this->name, sh_name, sizeof(this->name)); | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  | Shader::~Shader() | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-20 13:32:51 -04:00
										 |  |  |   delete interface; | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  | static void standard_defines(Vector<const char *> &sources) | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |   BLI_assert(sources.size() == 0); | 
					
						
							|  |  |  |   /* Version needs to be first. Exact values will be added by implementation. */ | 
					
						
							|  |  |  |   sources.append("version"); | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  |   /* some useful defines to detect GPU type */ | 
					
						
							| 
									
										
										
										
											2019-04-22 09:32:37 +10:00
										 |  |  |   if (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY)) { | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |     sources.append("#define GPU_ATI\n"); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:32:37 +10:00
										 |  |  |   } | 
					
						
							|  |  |  |   else if (GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_ANY, GPU_DRIVER_ANY)) { | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |     sources.append("#define GPU_NVIDIA\n"); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:32:37 +10:00
										 |  |  |   } | 
					
						
							|  |  |  |   else if (GPU_type_matches(GPU_DEVICE_INTEL, GPU_OS_ANY, GPU_DRIVER_ANY)) { | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |     sources.append("#define GPU_INTEL\n"); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:32:37 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-03-09 16:42:44 +01:00
										 |  |  |   /* some useful defines to detect OS type */ | 
					
						
							| 
									
										
										
										
											2019-04-22 09:32:37 +10:00
										 |  |  |   if (GPU_type_matches(GPU_DEVICE_ANY, GPU_OS_WIN, GPU_DRIVER_ANY)) { | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |     sources.append("#define OS_WIN\n"); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:32:37 +10:00
										 |  |  |   } | 
					
						
							|  |  |  |   else if (GPU_type_matches(GPU_DEVICE_ANY, GPU_OS_MAC, GPU_DRIVER_ANY)) { | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |     sources.append("#define OS_MAC\n"); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:32:37 +10:00
										 |  |  |   } | 
					
						
							|  |  |  |   else if (GPU_type_matches(GPU_DEVICE_ANY, GPU_OS_UNIX, GPU_DRIVER_ANY)) { | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |     sources.append("#define OS_UNIX\n"); | 
					
						
							| 
									
										
										
										
											2020-07-28 20:04:15 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |   if (GPU_crappy_amd_driver()) { | 
					
						
							|  |  |  |     sources.append("#define GPU_DEPRECATED_AMD_DRIVER\n"); | 
					
						
							| 
									
										
										
										
											2020-04-14 20:44:45 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  | GPUShader *GPU_shader_create_ex(const char *vertcode, | 
					
						
							| 
									
										
										
										
											2018-07-18 23:09:31 +10:00
										 |  |  |                                 const char *fragcode, | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |                                 const char *geomcode, | 
					
						
							| 
									
										
										
										
											2018-07-18 23:09:31 +10:00
										 |  |  |                                 const char *libcode, | 
					
						
							|  |  |  |                                 const char *defines, | 
					
						
							| 
									
										
										
										
											2019-01-23 14:15:43 +11:00
										 |  |  |                                 const eGPUShaderTFBType tf_type, | 
					
						
							| 
									
										
										
										
											2018-07-18 23:09:31 +10:00
										 |  |  |                                 const char **tf_names, | 
					
						
							| 
									
										
										
										
											2018-08-02 18:31:38 +02:00
										 |  |  |                                 const int tf_count, | 
					
						
							|  |  |  |                                 const char *shname) | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-12-07 04:07:56 +01:00
										 |  |  |   /* At least a vertex shader and a fragment shader are required. */ | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |   BLI_assert((fragcode != nullptr) && (vertcode != nullptr)); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |   Shader *shader = GPUBackend::get()->shader_alloc(shname); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |   if (vertcode) { | 
					
						
							|  |  |  |     Vector<const char *> sources; | 
					
						
							|  |  |  |     standard_defines(sources); | 
					
						
							|  |  |  |     sources.append("#define GPU_VERTEX_SHADER\n"); | 
					
						
							|  |  |  |     sources.append("#define IN_OUT out\n"); | 
					
						
							|  |  |  |     if (geomcode) { | 
					
						
							|  |  |  |       sources.append("#define USE_GEOMETRY_SHADER\n"); | 
					
						
							| 
									
										
										
										
											2020-07-30 13:55:13 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-22 09:32:37 +10:00
										 |  |  |     if (defines) { | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |       sources.append(defines); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:32:37 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |     sources.append(vertcode); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |     shader->vertex_shader_from_glsl(sources); | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  |   if (fragcode) { | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |     Vector<const char *> sources; | 
					
						
							|  |  |  |     standard_defines(sources); | 
					
						
							|  |  |  |     sources.append("#define GPU_FRAGMENT_SHADER\n"); | 
					
						
							|  |  |  |     sources.append("#define IN_OUT in\n"); | 
					
						
							|  |  |  |     if (geomcode) { | 
					
						
							|  |  |  |       sources.append("#define USE_GEOMETRY_SHADER\n"); | 
					
						
							| 
									
										
										
										
											2020-07-30 13:55:13 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-22 09:32:37 +10:00
										 |  |  |     if (defines) { | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |       sources.append(defines); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:32:37 +10:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (libcode) { | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |       sources.append(libcode); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:32:37 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |     sources.append(fragcode); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |     shader->fragment_shader_from_glsl(sources); | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |   if (geomcode) { | 
					
						
							|  |  |  |     Vector<const char *> sources; | 
					
						
							|  |  |  |     standard_defines(sources); | 
					
						
							|  |  |  |     sources.append("#define GPU_GEOMETRY_SHADER\n"); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:32:37 +10:00
										 |  |  |     if (defines) { | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |       sources.append(defines); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:32:37 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |     sources.append(geomcode); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |     shader->geometry_shader_from_glsl(sources); | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |   if (tf_names != nullptr && tf_count > 0) { | 
					
						
							| 
									
										
										
										
											2018-05-16 12:47:15 +02:00
										 |  |  |     BLI_assert(tf_type != GPU_SHADER_TFB_NONE); | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |     shader->transform_feedback_names_set(Span<const char *>(tf_names, tf_count), tf_type); | 
					
						
							| 
									
										
										
										
											2018-05-16 12:47:15 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |   if (!shader->finalize()) { | 
					
						
							|  |  |  |     delete shader; | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |     return nullptr; | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-08 03:34:47 +02:00
										 |  |  |   return wrap(shader); | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  | void GPU_shader_free(GPUShader *shader) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-08 03:34:47 +02:00
										 |  |  |   delete unwrap(shader); | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  | /** \} */ | 
					
						
							| 
									
										
										
										
											2017-09-27 18:03:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Creation utils
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GPUShader *GPU_shader_create(const char *vertcode, | 
					
						
							|  |  |  |                              const char *fragcode, | 
					
						
							|  |  |  |                              const char *geomcode, | 
					
						
							|  |  |  |                              const char *libcode, | 
					
						
							|  |  |  |                              const char *defines, | 
					
						
							|  |  |  |                              const char *shname) | 
					
						
							| 
									
										
										
										
											2020-07-28 20:04:15 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |   return GPU_shader_create_ex( | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |       vertcode, fragcode, geomcode, libcode, defines, GPU_SHADER_TFB_NONE, nullptr, 0, shname); | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-07-28 20:04:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  | GPUShader *GPU_shader_create_from_python(const char *vertcode, | 
					
						
							|  |  |  |                                          const char *fragcode, | 
					
						
							|  |  |  |                                          const char *geomcode, | 
					
						
							|  |  |  |                                          const char *libcode, | 
					
						
							|  |  |  |                                          const char *defines) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |   char *libcodecat = nullptr; | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |   if (libcode == nullptr) { | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |     libcode = datatoc_gpu_shader_colorspace_lib_glsl; | 
					
						
							| 
									
										
										
										
											2020-07-28 20:04:15 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |   else { | 
					
						
							|  |  |  |     libcode = libcodecat = BLI_strdupcat(libcode, datatoc_gpu_shader_colorspace_lib_glsl); | 
					
						
							| 
									
										
										
										
											2020-07-28 20:04:15 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |   GPUShader *sh = GPU_shader_create_ex(vertcode, | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |                                        fragcode, | 
					
						
							|  |  |  |                                        geomcode, | 
					
						
							|  |  |  |                                        libcode, | 
					
						
							|  |  |  |                                        defines, | 
					
						
							|  |  |  |                                        GPU_SHADER_TFB_NONE, | 
					
						
							|  |  |  |                                        nullptr, | 
					
						
							|  |  |  |                                        0, | 
					
						
							|  |  |  |                                        "pyGPUShader"); | 
					
						
							| 
									
										
										
										
											2020-07-28 20:04:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |   MEM_SAFE_FREE(libcodecat); | 
					
						
							|  |  |  |   return sh; | 
					
						
							| 
									
										
										
										
											2020-07-28 20:04:15 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-06 09:15:16 +11:00
										 |  |  | static const char *string_join_array_maybe_alloc(const char **str_arr, bool *r_is_alloc) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   bool is_alloc = false; | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |   if (str_arr == nullptr) { | 
					
						
							| 
									
										
										
										
											2019-02-06 09:15:16 +11:00
										 |  |  |     *r_is_alloc = false; | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |     return nullptr; | 
					
						
							| 
									
										
										
										
											2019-02-06 09:15:16 +11:00
										 |  |  |   } | 
					
						
							|  |  |  |   /* Skip empty strings (avoid alloc if we can). */ | 
					
						
							|  |  |  |   while (str_arr[0] && str_arr[0][0] == '\0') { | 
					
						
							|  |  |  |     str_arr++; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   int i; | 
					
						
							|  |  |  |   for (i = 0; str_arr[i]; i++) { | 
					
						
							|  |  |  |     if (i != 0 && str_arr[i][0] != '\0') { | 
					
						
							|  |  |  |       is_alloc = true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   *r_is_alloc = is_alloc; | 
					
						
							|  |  |  |   if (is_alloc) { | 
					
						
							|  |  |  |     return BLI_string_join_arrayN(str_arr, i); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:39:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return str_arr[0]; | 
					
						
							| 
									
										
										
										
											2019-02-06 09:15:16 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Use via #GPU_shader_create_from_arrays macro (avoids passing in param). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Similar to #DRW_shader_create_with_lib with the ability to include libs for each type of shader. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * It has the advantage that each item can be conditionally included | 
					
						
							|  |  |  |  * without having to build the string inline, then free it. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param params: NULL terminated arrays of strings. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Example: | 
					
						
							|  |  |  |  * \code{.c} | 
					
						
							|  |  |  |  * sh = GPU_shader_create_from_arrays({ | 
					
						
							| 
									
										
										
										
											2019-04-22 01:45:43 +10:00
										 |  |  |  *     .vert = (const char *[]){shader_lib_glsl, shader_vert_glsl, NULL}, | 
					
						
							|  |  |  |  *     .geom = (const char *[]){shader_geom_glsl, NULL}, | 
					
						
							|  |  |  |  *     .frag = (const char *[]){shader_frag_glsl, NULL}, | 
					
						
							|  |  |  |  *     .defs = (const char *[]){"#define DEFINE\n", test ? "#define OTHER_DEFINE\n" : "", NULL}, | 
					
						
							| 
									
										
										
										
											2019-02-06 09:15:16 +11:00
										 |  |  |  * }); | 
					
						
							|  |  |  |  * \endcode | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | struct GPUShader *GPU_shader_create_from_arrays_impl( | 
					
						
							| 
									
										
										
										
											2020-08-14 19:11:30 +02:00
										 |  |  |     const struct GPU_ShaderCreateFromArray_Params *params, const char *func, int line) | 
					
						
							| 
									
										
										
										
											2019-02-06 09:15:16 +11:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-16 19:48:28 +01:00
										 |  |  |   struct { | 
					
						
							|  |  |  |     const char *str; | 
					
						
							|  |  |  |     bool is_alloc; | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |   } str_dst[4] = {{nullptr}}; | 
					
						
							| 
									
										
										
										
											2019-02-06 09:15:16 +11:00
										 |  |  |   const char **str_src[4] = {params->vert, params->frag, params->geom, params->defs}; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-06 09:15:16 +11:00
										 |  |  |   for (int i = 0; i < ARRAY_SIZE(str_src); i++) { | 
					
						
							|  |  |  |     str_dst[i].str = string_join_array_maybe_alloc(str_src[i], &str_dst[i].is_alloc); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 19:11:30 +02:00
										 |  |  |   char name[64]; | 
					
						
							|  |  |  |   BLI_snprintf(name, sizeof(name), "%s_%d", func, line); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-06 09:15:16 +11:00
										 |  |  |   GPUShader *sh = GPU_shader_create( | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |       str_dst[0].str, str_dst[1].str, str_dst[2].str, nullptr, str_dst[3].str, name); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-07 12:21:11 +01:00
										 |  |  |   for (auto &i : str_dst) { | 
					
						
							|  |  |  |     if (i.is_alloc) { | 
					
						
							|  |  |  |       MEM_freeN((void *)i.str); | 
					
						
							| 
									
										
										
										
											2019-02-06 09:15:16 +11:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return sh; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 20:04:15 +02:00
										 |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Binding
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  | void GPU_shader_bind(GPUShader *gpu_shader) | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-08 03:34:47 +02:00
										 |  |  |   Shader *shader = unwrap(gpu_shader); | 
					
						
							| 
									
										
										
										
											2016-09-27 19:38:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-08 04:12:12 +02:00
										 |  |  |   Context *ctx = Context::get(); | 
					
						
							| 
									
										
										
										
											2020-08-09 00:52:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (ctx->shader != shader) { | 
					
						
							|  |  |  |     ctx->shader = shader; | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |     shader->bind(); | 
					
						
							| 
									
										
										
										
											2020-08-21 13:48:34 +02:00
										 |  |  |     GPU_matrix_bind(gpu_shader); | 
					
						
							|  |  |  |     GPU_shader_set_srgb_uniform(gpu_shader); | 
					
						
							| 
									
										
										
										
											2020-08-09 00:52:45 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-05-02 00:09:43 +10:00
										 |  |  |   else { | 
					
						
							|  |  |  |     if (gpu_shader_srgb_uniform_dirty_get()) { | 
					
						
							|  |  |  |       GPU_shader_set_srgb_uniform(gpu_shader); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (GPU_matrix_dirty_get()) { | 
					
						
							|  |  |  |       GPU_matrix_bind(gpu_shader); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-11 01:31:40 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GPU_shader_unbind(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-09 00:52:45 +02:00
										 |  |  | #ifndef NDEBUG
 | 
					
						
							| 
									
										
										
										
											2020-09-08 04:12:12 +02:00
										 |  |  |   Context *ctx = Context::get(); | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |   if (ctx->shader) { | 
					
						
							| 
									
										
										
										
											2020-09-08 03:34:47 +02:00
										 |  |  |     ctx->shader->unbind(); | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |   ctx->shader = nullptr; | 
					
						
							| 
									
										
										
										
											2020-08-09 00:52:45 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 20:04:15 +02:00
										 |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Transform feedback
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2020-09-19 14:32:41 +10:00
										 |  |  |  * TODO(fclem): Should be replaced by compute shaders. | 
					
						
							| 
									
										
										
										
											2020-07-28 20:04:15 +02:00
										 |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  | bool GPU_shader_transform_feedback_enable(GPUShader *shader, GPUVertBuf *vertbuf) | 
					
						
							| 
									
										
										
										
											2018-05-16 12:47:15 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-08 03:34:47 +02:00
										 |  |  |   return unwrap(shader)->transform_feedback_enable(vertbuf); | 
					
						
							| 
									
										
										
										
											2018-05-16 12:47:15 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  | void GPU_shader_transform_feedback_disable(GPUShader *shader) | 
					
						
							| 
									
										
										
										
											2018-05-16 12:47:15 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-08 03:34:47 +02:00
										 |  |  |   unwrap(shader)->transform_feedback_disable(); | 
					
						
							| 
									
										
										
										
											2018-05-16 12:47:15 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 20:04:15 +02:00
										 |  |  | /** \} */ | 
					
						
							| 
									
										
										
										
											2017-03-02 21:46:54 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 20:04:15 +02:00
										 |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Uniforms / Resource location
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | int GPU_shader_get_uniform(GPUShader *shader, const char *name) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-08 03:34:47 +02:00
										 |  |  |   ShaderInterface *interface = unwrap(shader)->interface; | 
					
						
							| 
									
										
										
										
											2020-08-20 13:05:22 +02:00
										 |  |  |   const ShaderInput *uniform = interface->uniform_get(name); | 
					
						
							| 
									
										
										
										
											2017-04-13 18:37:26 -04:00
										 |  |  |   return uniform ? uniform->location : -1; | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-08 15:49:25 +02:00
										 |  |  | int GPU_shader_get_builtin_uniform(GPUShader *shader, int builtin) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-08 03:34:47 +02:00
										 |  |  |   ShaderInterface *interface = unwrap(shader)->interface; | 
					
						
							| 
									
										
										
										
											2020-08-20 13:05:22 +02:00
										 |  |  |   return interface->uniform_builtin((GPUUniformBuiltin)builtin); | 
					
						
							| 
									
										
										
										
											2020-06-04 13:43:28 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int GPU_shader_get_builtin_block(GPUShader *shader, int builtin) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-08 03:34:47 +02:00
										 |  |  |   ShaderInterface *interface = unwrap(shader)->interface; | 
					
						
							| 
									
										
										
										
											2020-08-20 13:05:22 +02:00
										 |  |  |   return interface->ubo_builtin((GPUUniformBlockBuiltin)builtin); | 
					
						
							| 
									
										
										
										
											2017-10-08 15:49:25 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-20 13:05:22 +02:00
										 |  |  | /* DEPRECATED. */ | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | int GPU_shader_get_uniform_block(GPUShader *shader, const char *name) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-08 03:34:47 +02:00
										 |  |  |   ShaderInterface *interface = unwrap(shader)->interface; | 
					
						
							| 
									
										
										
										
											2020-08-20 13:05:22 +02:00
										 |  |  |   const ShaderInput *ubo = interface->ubo_get(name); | 
					
						
							| 
									
										
										
										
											2017-10-06 14:57:21 +02:00
										 |  |  |   return ubo ? ubo->location : -1; | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-02 18:14:28 +02:00
										 |  |  | int GPU_shader_get_uniform_block_binding(GPUShader *shader, const char *name) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-08 03:34:47 +02:00
										 |  |  |   ShaderInterface *interface = unwrap(shader)->interface; | 
					
						
							| 
									
										
										
										
											2020-08-20 13:05:22 +02:00
										 |  |  |   const ShaderInput *ubo = interface->ubo_get(name); | 
					
						
							| 
									
										
										
										
											2020-06-02 18:14:28 +02:00
										 |  |  |   return ubo ? ubo->binding : -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int GPU_shader_get_texture_binding(GPUShader *shader, const char *name) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-08 03:34:47 +02:00
										 |  |  |   ShaderInterface *interface = unwrap(shader)->interface; | 
					
						
							| 
									
										
										
										
											2020-08-20 13:05:22 +02:00
										 |  |  |   const ShaderInput *tex = interface->uniform_get(name); | 
					
						
							| 
									
										
										
										
											2020-06-02 18:14:28 +02:00
										 |  |  |   return tex ? tex->binding : -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 20:04:15 +02:00
										 |  |  | int GPU_shader_get_attribute(GPUShader *shader, const char *name) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-08 03:34:47 +02:00
										 |  |  |   ShaderInterface *interface = unwrap(shader)->interface; | 
					
						
							| 
									
										
										
										
											2020-08-20 13:05:22 +02:00
										 |  |  |   const ShaderInput *attr = interface->attr_get(name); | 
					
						
							| 
									
										
										
										
											2020-07-28 20:04:15 +02:00
										 |  |  |   return attr ? attr->location : -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Getters
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 14:52:46 +01:00
										 |  |  | /* DEPRECATED: Kept only because of BGL API */ | 
					
						
							|  |  |  | int GPU_shader_get_program(GPUShader *shader) | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-30 14:52:46 +01:00
										 |  |  |   return unwrap(shader)->program_handle_get(); | 
					
						
							| 
									
										
										
										
											2017-02-07 11:20:15 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 20:04:15 +02:00
										 |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Uniforms setters
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | void GPU_shader_uniform_vector( | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |     GPUShader *shader, int loc, int len, int arraysize, const float *value) | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-08 03:34:47 +02:00
										 |  |  |   unwrap(shader)->uniform_float(loc, len, arraysize, value); | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GPU_shader_uniform_vector_int( | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |     GPUShader *shader, int loc, int len, int arraysize, const int *value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-08 03:34:47 +02:00
										 |  |  |   unwrap(shader)->uniform_int(loc, len, arraysize, value); | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-11 15:59:02 +02:00
										 |  |  | void GPU_shader_uniform_int(GPUShader *shader, int location, int value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GPU_shader_uniform_vector_int(shader, location, 1, 1, &value); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GPU_shader_uniform_float(GPUShader *shader, int location, float value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GPU_shader_uniform_vector(shader, location, 1, 1, &value); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-20 12:26:29 +02:00
										 |  |  |   const int loc = GPU_shader_get_uniform(sh, name); | 
					
						
							|  |  |  |   GPU_shader_uniform_int(sh, loc, value); | 
					
						
							| 
									
										
										
										
											2020-08-11 15:59:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GPU_shader_uniform_1b(GPUShader *sh, const char *name, bool value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GPU_shader_uniform_1i(sh, name, value ? 1 : 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GPU_shader_uniform_2f(GPUShader *sh, const char *name, float x, float y) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   const float data[2] = {x, y}; | 
					
						
							|  |  |  |   GPU_shader_uniform_2fv(sh, name, data); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GPU_shader_uniform_3f(GPUShader *sh, const char *name, float x, float y, float z) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   const float data[3] = {x, y, z}; | 
					
						
							|  |  |  |   GPU_shader_uniform_3fv(sh, name, data); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GPU_shader_uniform_4f(GPUShader *sh, const char *name, float x, float y, float z, float w) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   const float data[4] = {x, y, z, w}; | 
					
						
							|  |  |  |   GPU_shader_uniform_4fv(sh, name, data); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-04 20:59:13 +02:00
										 |  |  | void GPU_shader_uniform_1f(GPUShader *sh, const char *name, float value) | 
					
						
							| 
									
										
										
										
											2020-08-11 15:59:02 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-20 12:26:29 +02:00
										 |  |  |   const int loc = GPU_shader_get_uniform(sh, name); | 
					
						
							| 
									
										
										
										
											2020-09-04 20:59:13 +02:00
										 |  |  |   GPU_shader_uniform_float(sh, loc, value); | 
					
						
							| 
									
										
										
										
											2020-08-11 15:59:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GPU_shader_uniform_2fv(GPUShader *sh, const char *name, const float data[2]) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-20 12:26:29 +02:00
										 |  |  |   const int loc = GPU_shader_get_uniform(sh, name); | 
					
						
							|  |  |  |   GPU_shader_uniform_vector(sh, loc, 2, 1, data); | 
					
						
							| 
									
										
										
										
											2020-08-11 15:59:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GPU_shader_uniform_3fv(GPUShader *sh, const char *name, const float data[3]) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-20 12:26:29 +02:00
										 |  |  |   const int loc = GPU_shader_get_uniform(sh, name); | 
					
						
							|  |  |  |   GPU_shader_uniform_vector(sh, loc, 3, 1, data); | 
					
						
							| 
									
										
										
										
											2020-08-11 15:59:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GPU_shader_uniform_4fv(GPUShader *sh, const char *name, const float data[4]) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-20 12:26:29 +02:00
										 |  |  |   const int loc = GPU_shader_get_uniform(sh, name); | 
					
						
							|  |  |  |   GPU_shader_uniform_vector(sh, loc, 4, 1, data); | 
					
						
							| 
									
										
										
										
											2020-08-11 15:59:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GPU_shader_uniform_mat4(GPUShader *sh, const char *name, const float data[4][4]) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-20 12:26:29 +02:00
										 |  |  |   const int loc = GPU_shader_get_uniform(sh, name); | 
					
						
							|  |  |  |   GPU_shader_uniform_vector(sh, loc, 16, 1, (const float *)data); | 
					
						
							| 
									
										
										
										
											2020-08-11 15:59:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GPU_shader_uniform_2fv_array(GPUShader *sh, const char *name, int len, const float (*val)[2]) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-20 12:26:29 +02:00
										 |  |  |   const int loc = GPU_shader_get_uniform(sh, name); | 
					
						
							|  |  |  |   GPU_shader_uniform_vector(sh, loc, 2, len, (const float *)val); | 
					
						
							| 
									
										
										
										
											2020-08-11 15:59:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GPU_shader_uniform_4fv_array(GPUShader *sh, const char *name, int len, const float (*val)[4]) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-20 12:26:29 +02:00
										 |  |  |   const int loc = GPU_shader_get_uniform(sh, name); | 
					
						
							|  |  |  |   GPU_shader_uniform_vector(sh, loc, 4, len, (const float *)val); | 
					
						
							| 
									
										
										
										
											2020-08-11 15:59:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 20:04:15 +02:00
										 |  |  | /** \} */ | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 20:04:15 +02:00
										 |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							| 
									
										
										
										
											2020-07-30 08:31:25 +10:00
										 |  |  | /** \name sRGB Rendering Workaround
 | 
					
						
							| 
									
										
										
										
											2020-07-28 20:04:15 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2020-07-30 08:31:25 +10:00
										 |  |  |  * The viewport overlay frame-buffer is sRGB and will expect shaders to output display referred | 
					
						
							|  |  |  |  * Linear colors. But other frame-buffers (i.e: the area frame-buffers) are not sRGB and require | 
					
						
							|  |  |  |  * the shader output color to be in sRGB space | 
					
						
							|  |  |  |  * (assumed display encoded color-space as the time of writing). | 
					
						
							| 
									
										
										
										
											2020-07-28 20:04:15 +02:00
										 |  |  |  * For this reason we have a uniform to switch the transform on and off depending on the current | 
					
						
							| 
									
										
										
										
											2020-07-30 08:31:25 +10:00
										 |  |  |  * frame-buffer color-space. | 
					
						
							| 
									
										
										
										
											2020-07-28 20:04:15 +02:00
										 |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int g_shader_builtin_srgb_transform = 0; | 
					
						
							| 
									
										
										
										
											2021-05-02 00:09:43 +10:00
										 |  |  | static bool g_shader_builtin_srgb_is_dirty = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-03 10:22:12 +02:00
										 |  |  | static bool gpu_shader_srgb_uniform_dirty_get() | 
					
						
							| 
									
										
										
										
											2021-05-02 00:09:43 +10:00
										 |  |  | { | 
					
						
							|  |  |  |   return g_shader_builtin_srgb_is_dirty; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-12-06 21:20:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  | void GPU_shader_set_srgb_uniform(GPUShader *shader) | 
					
						
							| 
									
										
										
										
											2020-04-14 20:44:45 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-20 12:26:29 +02:00
										 |  |  |   int32_t loc = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_SRGB_TRANSFORM); | 
					
						
							| 
									
										
										
										
											2020-06-04 14:15:25 +02:00
										 |  |  |   if (loc != -1) { | 
					
						
							| 
									
										
										
										
											2020-08-14 15:20:35 +02:00
										 |  |  |     GPU_shader_uniform_vector_int(shader, loc, 1, 1, &g_shader_builtin_srgb_transform); | 
					
						
							| 
									
										
										
										
											2020-04-14 20:44:45 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-05-02 00:09:43 +10:00
										 |  |  |   g_shader_builtin_srgb_is_dirty = false; | 
					
						
							| 
									
										
										
										
											2020-04-14 20:44:45 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GPU_shader_set_framebuffer_srgb_target(int use_srgb_to_linear) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-05-02 00:09:43 +10:00
										 |  |  |   if (g_shader_builtin_srgb_transform != use_srgb_to_linear) { | 
					
						
							|  |  |  |     g_shader_builtin_srgb_transform = use_srgb_to_linear; | 
					
						
							|  |  |  |     g_shader_builtin_srgb_is_dirty = true; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-04-14 20:44:45 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 20:04:15 +02:00
										 |  |  | /** \} */ |