68 const char line_prefix[] =
" | ";
69 char err_col[] =
"\033[31;1m";
70 char warn_col[] =
"\033[33;1m";
71 char info_col[] =
"\033[0;2m";
72 char reset_col[] =
"\033[0;0m";
77 err_col[0] = warn_col[0] = info_col[0] = reset_col[0] =
'\0';
82 char *log_line =
log, *line_end;
83 char *error_line_number_end;
84 int error_line, error_char, last_error_line = -2, last_error_char = -1;
85 bool found_line_id =
false;
86 while ((line_end = strchr(log_line,
'\n'))) {
88 if (line_end == log_line) {
95 const char *prefix[] = {
"ERROR",
"WARNING"};
97 if (
STREQLEN(log_line, prefix[i], strlen(prefix[i]))) {
98 log_line += strlen(prefix[i]);
104 while (
ELEM(log_line[0],
':',
'(',
' ')) {
108 error_line = error_char = -1;
109 if (log_line[0] >=
'0' && log_line[0] <=
'9') {
110 error_line = (int)strtol(log_line, &error_line_number_end, 10);
112 if (
ELEM(error_line_number_end[0],
'(',
':') && error_line_number_end[1] !=
' ') {
113 error_char = (int)strtol(error_line_number_end + 1, &log_line, 10);
116 log_line = error_line_number_end;
119 if (
ELEM(log_line[0],
'(',
':') && log_line[1] >=
'0' && log_line[1] <=
'9') {
120 error_line = error_char;
121 error_char = (int)strtol(log_line + 1, &error_line_number_end, 10);
122 log_line = error_line_number_end;
126 while (
ELEM(log_line[0],
':',
')',
' ')) {
129 if (error_line == -1) {
130 found_line_id =
false;
132 const char *src_line = sources_combined;
133 if ((error_line != -1) && (error_char != -1)) {
136 int error_source = error_line;
137 if (error_source < sources.
size()) {
138 src_line = sources[error_source];
139 error_line = error_char;
146 error_line = error_char;
154 if (last_error_line != error_line) {
157 else if (error_char != last_error_char) {
161 if ((error_line != -1) && (error_line != last_error_line || error_char != last_error_char)) {
162 const char *src_line_end = src_line;
163 found_line_id =
false;
165 int src_line_index = 1;
166 while ((src_line_end = strchr(src_line,
'\n'))) {
167 if (src_line_index == error_line) {
168 found_line_id =
true;
177 src_line = src_line_end + 1;
182 if (error_line != last_error_line) {
191 if (error_char != -1) {
192 for (
int i = 0; i < error_char; i++) {
202 const char *keywords[] = {
"error",
"warning"};
203 for (
int i = 0; i <
ARRAY_SIZE(prefix); i++) {
204 if (
STREQLEN(log_line, keywords[i], strlen(keywords[i]))) {
205 log_line += strlen(keywords[i]);
211 while (
ELEM(log_line[0],
':',
')')) {
217 else if (
type == 1) {
225 log_line = line_end + 1;
226 last_error_line = error_line;
227 last_error_char = error_char;
263 sources.
append(
"version");
266 sources.
append(
"#define GPU_ATI\n");
269 sources.
append(
"#define GPU_NVIDIA\n");
272 sources.
append(
"#define GPU_INTEL\n");
276 sources.
append(
"#define OS_WIN\n");
279 sources.
append(
"#define OS_MAC\n");
282 sources.
append(
"#define OS_UNIX\n");
286 sources.
append(
"#define GPU_DEPRECATED_AMD_DRIVER\n");
291 const char *fragcode,
292 const char *geomcode,
296 const char **tf_names,
301 BLI_assert((fragcode !=
nullptr) && (vertcode !=
nullptr));
308 sources.
append(
"#define GPU_VERTEX_SHADER\n");
309 sources.
append(
"#define IN_OUT out\n");
311 sources.
append(
"#define USE_GEOMETRY_SHADER\n");
318 shader->vertex_shader_from_glsl(sources);
324 sources.
append(
"#define GPU_FRAGMENT_SHADER\n");
325 sources.
append(
"#define IN_OUT in\n");
327 sources.
append(
"#define USE_GEOMETRY_SHADER\n");
337 shader->fragment_shader_from_glsl(sources);
343 sources.
append(
"#define GPU_GEOMETRY_SHADER\n");
349 shader->geometry_shader_from_glsl(sources);
352 if (tf_names !=
nullptr && tf_count > 0) {
357 if (!
shader->finalize()) {
377 const char *fragcode,
378 const char *geomcode,
388 const char *fragcode,
389 const char *geomcode,
393 char *libcodecat =
nullptr;
395 if (libcode ==
nullptr) {
418 bool is_alloc =
false;
419 if (str_arr ==
nullptr) {
424 while (str_arr[0] && str_arr[0][0] ==
'\0') {
428 for (i = 0; str_arr[i]; i++) {
429 if (i != 0 && str_arr[i][0] !=
'\0') {
433 *r_is_alloc = is_alloc;
467 } str_dst[4] = {{
nullptr}};
470 for (
int i = 0; i <
ARRAY_SIZE(str_src); i++) {
478 str_dst[0].
str, str_dst[1].
str, str_dst[2].
str,
nullptr, str_dst[3].
str, name);
480 for (
auto &i : str_dst) {
537 return unwrap(
shader)->transform_feedback_enable(vertbuf);
554 const ShaderInput *uniform = interface->uniform_get(name);
555 return uniform ? uniform->
location : -1;
582 return ubo ? ubo->
binding : -1;
589 return tex ?
tex->binding : -1;
595 const ShaderInput *attr = interface->attr_get(name);
652 const float data[2] = {
x,
y};
658 const float data[3] = {
x,
y,
z};
A dynamically sized string ADT.
DynStr * BLI_dynstr_new(void) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void BLI_dynstr_nappend(DynStr *__restrict ds, const char *cstr, int len) ATTR_NONNULL()
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
void BLI_dynstr_appendf(DynStr *__restrict ds, const char *__restrict format,...) ATTR_PRINTF_FORMAT(2
char * BLI_dynstr_get_cstring(DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
char * BLI_strdupcat(const char *__restrict str1, const char *__restrict str2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
char * BLI_string_join_arrayN(const char *strings[], uint strings_len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
#define STREQLEN(a, b, n)
void CLG_log_str(CLG_LogType *lg, enum CLG_Severity severity, const char *file_line, const char *fn, const char *message) _CLOG_ATTR_NONNULL(1
int CLG_color_support_get(CLG_LogRef *clg_ref)
bool GPU_crappy_amd_driver(void)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble z
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
bool GPU_matrix_dirty_get(void)
void GPU_matrix_bind(struct GPUShader *shader)
struct GPUShader GPUShader
@ GPU_UNIFORM_SRGB_TRANSFORM
struct GPUVertBuf GPUVertBuf
Read Guarded memory(de)allocation.
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
constexpr const T * data() const
constexpr int64_t size() const
void append(const T &value)
static Context * get(void)
static GPUBackend * get(void)
virtual Shader * shader_alloc(const char *name)=0
int32_t uniform_builtin(const GPUUniformBuiltin builtin) const
int32_t ubo_builtin(const GPUUniformBlockBuiltin builtin) const
void print_log(Span< const char * > sources, char *log, const char *stage, const bool error)
ShaderInterface * interface
virtual void unbind(void)=0
GPUShader * GPU_shader_create(const char *vertcode, const char *fragcode, const char *geomcode, const char *libcode, const char *defines, const char *shname)
void GPU_shader_unbind(void)
int GPU_shader_get_uniform(GPUShader *shader, const char *name)
void GPU_shader_uniform_vector_int(GPUShader *shader, int loc, int len, int arraysize, const int *value)
void GPU_shader_uniform_2fv(GPUShader *sh, const char *name, const float data[2])
void GPU_shader_set_srgb_uniform(GPUShader *shader)
static bool gpu_shader_srgb_uniform_dirty_get()
static const char * string_join_array_maybe_alloc(const char **str_arr, bool *r_is_alloc)
void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value)
static int g_shader_builtin_srgb_transform
void GPU_shader_uniform_3f(GPUShader *sh, const char *name, float x, float y, float z)
void GPU_shader_uniform_2f(GPUShader *sh, const char *name, float x, float y)
void GPU_shader_uniform_2fv_array(GPUShader *sh, const char *name, int len, const float(*val)[2])
void GPU_shader_set_framebuffer_srgb_target(int use_srgb_to_linear)
void GPU_shader_uniform_1f(GPUShader *sh, const char *name, float value)
GPUShader * GPU_shader_create_ex(const char *vertcode, const char *fragcode, const char *geomcode, const char *libcode, const char *defines, const eGPUShaderTFBType tf_type, const char **tf_names, const int tf_count, const char *shname)
void GPU_shader_bind(GPUShader *gpu_shader)
static void standard_defines(Vector< const char * > &sources)
void GPU_shader_uniform_3fv(GPUShader *sh, const char *name, const float data[3])
void GPU_shader_uniform_vector(GPUShader *shader, int loc, int len, int arraysize, const float *value)
int GPU_shader_get_attribute(GPUShader *shader, const char *name)
void GPU_shader_uniform_4fv_array(GPUShader *sh, const char *name, int len, const float(*val)[4])
char datatoc_gpu_shader_colorspace_lib_glsl[]
void GPU_shader_uniform_int(GPUShader *shader, int location, int value)
int GPU_shader_get_builtin_block(GPUShader *shader, int builtin)
int GPU_shader_get_uniform_block_binding(GPUShader *shader, const char *name)
GPUShader * GPU_shader_create_from_python(const char *vertcode, const char *fragcode, const char *geomcode, const char *libcode, const char *defines)
void GPU_shader_transform_feedback_disable(GPUShader *shader)
int GPU_shader_get_program(GPUShader *shader)
void GPU_shader_uniform_1b(GPUShader *sh, const char *name, bool value)
void GPU_shader_uniform_4fv(GPUShader *sh, const char *name, const float data[4])
void GPU_shader_uniform_4f(GPUShader *sh, const char *name, float x, float y, float z, float w)
int GPU_shader_get_uniform_block(GPUShader *shader, const char *name)
void GPU_shader_uniform_mat4(GPUShader *sh, const char *name, const float data[4][4])
int GPU_shader_get_texture_binding(GPUShader *shader, const char *name)
int GPU_shader_get_builtin_uniform(GPUShader *shader, int builtin)
void GPU_shader_free(GPUShader *shader)
void GPU_shader_uniform_float(GPUShader *shader, int location, float value)
static bool g_shader_builtin_srgb_is_dirty
bool GPU_shader_transform_feedback_enable(GPUShader *shader, GPUVertBuf *vertbuf)
struct GPUShader * GPU_shader_create_from_arrays_impl(const struct GPU_ShaderCreateFromArray_Params *params, const char *func, int line)
void KERNEL_FUNCTION_FULL_NAME() shader(KernelGlobals *kg, uint4 *input, float4 *output, int type, int filter, int i, int offset, int sample)
void(* MEM_freeN)(void *vmemh)
static void error(const char *str)
INLINE Rall1d< T, V, S > log(const Rall1d< T, V, S > &arg)
static GPUContext * wrap(Context *ctx)
static Context * unwrap(GPUContext *ctx)