34 #define TRIM_NVIDIA_BUFFER_INFO 1
36 #define TRIM_SHADER_STATS_INFO 1
49 # define APIENTRY __stdcall
59 const GLchar *message,
60 const GLvoid *
UNUSED(userParm))
62 if (
ELEM(
type, GL_DEBUG_TYPE_PUSH_GROUP, GL_DEBUG_TYPE_POP_GROUP)) {
84 if (
ELEM(severity, GL_DEBUG_SEVERITY_LOW, GL_DEBUG_SEVERITY_NOTIFICATION)) {
86 const char *
format = use_color ?
"\033[2m%s\033[0m" :
"%s";
91 char debug_groups[512] =
"";
101 case GL_DEBUG_TYPE_ERROR:
102 case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
103 case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
106 case GL_DEBUG_TYPE_PORTABILITY:
107 case GL_DEBUG_TYPE_PERFORMANCE:
108 case GL_DEBUG_TYPE_OTHER:
109 case GL_DEBUG_TYPE_MARKER:
117 if (severity == GL_DEBUG_SEVERITY_HIGH) {
120 fprintf(stderr,
"\033[2m");
124 fprintf(stderr,
"\033[0m\n");
139 const char format[] =
"Successfully hooked OpenGL debug callback using %s";
141 if (GLEW_VERSION_4_3 || GLEW_KHR_debug) {
142 SNPRINTF(msg,
format, GLEW_VERSION_4_3 ?
"OpenGL 4.3" :
"KHR_debug extension");
144 glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
146 glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0,
nullptr, GL_TRUE);
147 glDebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION,
148 GL_DEBUG_TYPE_MARKER,
150 GL_DEBUG_SEVERITY_NOTIFICATION,
154 else if (GLEW_ARB_debug_output) {
156 glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
157 glDebugMessageCallbackARB((GLDEBUGPROCARB)
debug_callback,
nullptr);
158 glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0,
nullptr, GL_TRUE);
159 glDebugMessageInsertARB(GL_DEBUG_SOURCE_APPLICATION_ARB,
160 GL_DEBUG_TYPE_OTHER_ARB,
162 GL_DEBUG_SEVERITY_LOW_ARB,
167 CLOG_STR_WARN(&
LOG,
"Failed to hook OpenGL debug callback. Use fallback debug layer.");
186 GLenum
error = glGetError();
188 #define ERROR_CASE(err) \
191 SNPRINTF(msg, "%s : %s", #err, info); \
192 debug_callback(0, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, 0, msg, nullptr); \
209 debug_callback(0, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, 0, msg,
nullptr);
224 uint16_t ubo_needed = interface->enabled_ubo_mask_;
228 uint64_t tex_needed = interface->enabled_tex_mask_;
229 tex_needed &= ~
GLContext::state_manager_active_get()->bound_texture_slots();
232 uint8_t ima_needed = interface->enabled_ima_mask_;
233 ima_needed &= ~
GLContext::state_manager_active_get()->bound_image_slots();
235 if (ubo_needed == 0 && tex_needed == 0 && ima_needed == 0) {
239 for (
int i = 0; ubo_needed != 0; i++, ubo_needed >>= 1) {
240 if ((ubo_needed & 1) != 0) {
241 const ShaderInput *ubo_input = interface->ubo_get(i);
242 const char *ubo_name = interface->input_name_get(ubo_input);
245 SNPRINTF(msg,
"Missing UBO bind at slot %d : %s > %s : %s", i, sh_name, ubo_name, info);
246 debug_callback(0, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, 0, msg,
nullptr);
250 for (
int i = 0; tex_needed != 0; i++, tex_needed >>= 1) {
251 if ((tex_needed & 1) != 0) {
254 const char *tex_name = interface->input_name_get(
tex_input);
257 SNPRINTF(msg,
"Missing Texture bind at slot %d : %s > %s : %s", i, sh_name, tex_name, info);
258 debug_callback(0, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, 0, msg,
nullptr);
262 for (
int i = 0; ima_needed != 0; i++, ima_needed >>= 1) {
263 if ((ima_needed & 1) != 0) {
266 const char *tex_name = interface->input_name_get(
tex_input);
269 SNPRINTF(msg,
"Missing Image bind at slot %d : %s > %s : %s", i, sh_name, tex_name, info);
270 debug_callback(0, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, 0, msg,
nullptr);
277 debug_callback(0, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, 0, info,
nullptr);
292 case GL_FRAGMENT_SHADER:
293 case GL_GEOMETRY_SHADER:
294 case GL_VERTEX_SHADER:
304 case GL_VERTEX_ARRAY:
306 case GL_UNIFORM_BUFFER:
317 case GL_FRAGMENT_SHADER:
319 case GL_GEOMETRY_SHADER:
321 case GL_VERTEX_SHADER:
330 if ((
G.debug &
G_DEBUG_GPU) && (GLEW_VERSION_4_3 || GLEW_KHR_debug)) {
335 case GL_FRAGMENT_SHADER:
336 case GL_GEOMETRY_SHADER:
337 case GL_VERTEX_SHADER:
338 case GL_COMPUTE_SHADER:
341 case GL_UNIFORM_BUFFER:
342 case GL_SHADER_STORAGE_BUFFER:
343 case GL_ARRAY_BUFFER:
344 case GL_ELEMENT_ARRAY_BUFFER:
368 if ((
G.debug &
G_DEBUG_GPU) && (GLEW_VERSION_4_3 || GLEW_KHR_debug)) {
371 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, index, -1, name);
377 if ((
G.debug &
G_DEBUG_GPU) && (GLEW_VERSION_4_3 || GLEW_KHR_debug)) {
#define SNPRINTF(dst, format,...)
void BLI_system_backtrace(FILE *fp)
void void CLG_logf(CLG_LogType *lg, enum CLG_Severity severity, const char *file_line, const char *fn, const char *format,...) _CLOG_ATTR_NONNULL(1
#define CLOG_ENSURE(clg_ref)
#define CLOG_STR_WARN(clg_ref, str)
int CLG_color_support_get(CLG_LogRef *clg_ref)
bool GPU_debug_group_match(const char *ref)
void GPU_debug_get_groups_names(int name_buf_len, char *r_name_buf)
#define GPU_DEBUG_SHADER_COMPILATION_GROUP
_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
void debug_group_begin(const char *name, int index) override
void debug_group_end() override
const char *const name_get() const
#define TRIM_NVIDIA_BUFFER_INFO
#define TRIM_SHADER_STATS_INFO
static void error(const char *str)
void check_gl_resources(const char *info)
static void APIENTRY debug_callback(GLenum UNUSED(source), GLenum type, GLuint UNUSED(id), GLenum severity, GLsizei UNUSED(length), const GLchar *message, const GLvoid *UNUSED(userParm))
void raise_gl_error(const char *info)
static const char * to_str_prefix(GLenum type)
void check_gl_error(const char *info)
static const char * to_str_suffix(GLenum type)
void object_label(GLenum type, GLuint object, const char *name)
T length(const vec_base< T, Size > &a)
static void tex_input(float *out, int num, bNodeStack *in, TexParams *params, short thread)
unsigned __int64 uint64_t