[Bf-blender-cvs] [7e02d33] blender2.8: OpenGL: don't poll for errors, rely on KHR_debug

Mike Erwin noreply at git.blender.org
Fri Aug 19 06:53:21 CEST 2016


Commit: 7e02d335c0ce9e88fb08d1e499b6563980d0d8e9
Author: Mike Erwin
Date:   Fri Aug 19 00:52:52 2016 -0400
Branches: blender2.8
https://developer.blender.org/rB7e02d335c0ce9e88fb08d1e499b6563980d0d8e9

OpenGL: don't poll for errors, rely on KHR_debug

Errors are caught & reported by our GL debug callback. This gives us way more useful information than sporadic calls to glGetError.

I removed almost all use of glGetError, including our own GPU_ASSERT_NO_GL_ERRORS and GPU_CHECK_ERRORS_AROUND macros.

Still used in rna_Image_gl_load because it passes unvalidated input to OpenGL functions.

Still used in gpu_state_print_fl_ex as an exception handling hack -- will rewrite this soon.

The optimism embodied by this commit will not prevent OpenGL errors. We need to analyze what would cause GL to fail at certain points and proactively intercept these failures. Or guarantee they can't happen.

===================================================================

M	source/blender/editors/interface/interface_icons.c
M	source/blender/gpu/GPU_debug.h
M	source/blender/gpu/GPU_framebuffer.h
M	source/blender/gpu/intern/gpu_compositing.c
M	source/blender/gpu/intern/gpu_debug.c
M	source/blender/gpu/intern/gpu_framebuffer.c
M	source/blender/gpu/intern/gpu_material.c
M	source/blender/gpu/intern/gpu_shader.c
M	source/blender/gpu/intern/gpu_texture.c
M	source/blender/makesrna/intern/rna_image_api.c
M	source/blender/windowmanager/intern/wm_draw.c
M	source/blender/windowmanager/intern/wm_event_system.c

===================================================================

diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index 646260b..f96a270 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -757,11 +757,6 @@ static void init_internal_icons(void)
 				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 				
 				glBindTexture(GL_TEXTURE_2D, 0);
-				
-				if (glGetError() == GL_OUT_OF_MEMORY) {
-					glDeleteTextures(1, &icongltex.id);
-					icongltex.id = 0;
-				}
 			}
 		}
 	}
diff --git a/source/blender/gpu/GPU_debug.h b/source/blender/gpu/GPU_debug.h
index 61b2bc5..921deaa 100644
--- a/source/blender/gpu/GPU_debug.h
+++ b/source/blender/gpu/GPU_debug.h
@@ -41,24 +41,9 @@ extern "C" {
 /* prints something if debug mode is active only */
 void GPU_print_error_debug(const char *str);
 
-/* replacement for gluErrorString */
-const char *gpuErrorString(GLenum err);
-
 /* prints current OpenGL state */
 void GPU_state_print(void);
 
-void GPU_assert_no_gl_errors(const char *file, int line, const char *str);
-
-#  define GPU_ASSERT_NO_GL_ERRORS(str) GPU_assert_no_gl_errors(__FILE__, __LINE__, (str))
-
-#  define GPU_CHECK_ERRORS_AROUND(glProcCall)                      \
-       (                                             \
-       GPU_ASSERT_NO_GL_ERRORS("Pre: "  #glProcCall), \
-       (glProcCall),                                 \
-       GPU_ASSERT_NO_GL_ERRORS("Post: " #glProcCall)  \
-       )
-
-
 /* inserts a debug marker message for the debug context messaging system */
 void GPU_string_marker(const char *str);
 
diff --git a/source/blender/gpu/GPU_framebuffer.h b/source/blender/gpu/GPU_framebuffer.h
index 2719b8f..989b874 100644
--- a/source/blender/gpu/GPU_framebuffer.h
+++ b/source/blender/gpu/GPU_framebuffer.h
@@ -50,7 +50,7 @@ struct GPUTexture;
 void GPU_texture_bind_as_framebuffer(struct GPUTexture *tex);
 
 GPUFrameBuffer *GPU_framebuffer_create(void);
-int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, struct GPUTexture *tex, int slot, char err_out[256]);
+bool GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, struct GPUTexture *tex, int slot);
 void GPU_framebuffer_texture_detach(struct GPUTexture *tex);
 void GPU_framebuffer_slots_bind(GPUFrameBuffer *fb, int slot);
 void GPU_framebuffer_texture_unbind(GPUFrameBuffer *fb, struct GPUTexture *tex);
diff --git a/source/blender/gpu/intern/gpu_compositing.c b/source/blender/gpu/intern/gpu_compositing.c
index aabe96d..13596f2 100644
--- a/source/blender/gpu/intern/gpu_compositing.c
+++ b/source/blender/gpu/intern/gpu_compositing.c
@@ -582,11 +582,8 @@ bool GPU_fx_compositor_initialize_passes(
 	/* bind the buffers */
 
 	/* first depth buffer, because system assumes read/write buffers */
-	if (!GPU_framebuffer_texture_attach(fx->gbuffer, fx->depth_buffer, 0, err_out))
-		printf("%.256s\n", err_out);
-
-	if (!GPU_framebuffer_texture_attach(fx->gbuffer, fx->color_buffer, 0, err_out))
-		printf("%.256s\n", err_out);
+	GPU_framebuffer_texture_attach(fx->gbuffer, fx->depth_buffer, 0);
+	GPU_framebuffer_texture_attach(fx->gbuffer, fx->color_buffer, 0);
 
 	if (!GPU_framebuffer_check_valid(fx->gbuffer, err_out))
 		printf("%.256s\n", err_out);
@@ -631,7 +628,7 @@ static void gpu_fx_bind_render_target(int *passes_left, GPUFX *fx, struct GPUOff
 	}
 	else {
 		/* bind the ping buffer to the color buffer */
-		GPU_framebuffer_texture_attach(fx->gbuffer, target, 0, NULL);
+		GPU_framebuffer_texture_attach(fx->gbuffer, target, 0);
 	}
 }
 
@@ -660,8 +657,7 @@ void GPU_fx_compositor_setup_XRay_pass(GPUFX *fx, bool do_xray)
 	GPU_framebuffer_texture_detach(fx->depth_buffer);
 
 	/* first depth buffer, because system assumes read/write buffers */
-	if (!GPU_framebuffer_texture_attach(fx->gbuffer, fx->depth_buffer_xray, 0, err_out))
-		printf("%.256s\n", err_out);
+	GPU_framebuffer_texture_attach(fx->gbuffer, fx->depth_buffer_xray, 0);
 }
 
 
@@ -671,7 +667,7 @@ void GPU_fx_compositor_XRay_resolve(GPUFX *fx)
 	GPU_framebuffer_texture_detach(fx->depth_buffer_xray);
 
 	/* attach regular framebuffer */
-	GPU_framebuffer_texture_attach(fx->gbuffer, fx->depth_buffer, 0, NULL);
+	GPU_framebuffer_texture_attach(fx->gbuffer, fx->depth_buffer, 0);
 
 	/* full screen quad where we will always write to depth buffer */
 	glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_SCISSOR_BIT);
@@ -919,9 +915,9 @@ bool GPU_fx_do_composite_pass(
 				GPU_shader_uniform_texture(dof_shader_pass2, interface->color_uniform, src);
 
 				/* target is the downsampled coc buffer */
-				GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_half_downsampled_near, 0, NULL);
-				GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_half_downsampled_far, 1, NULL);
-				GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_nearfar_coc, 2, NULL);
+				GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_half_downsampled_near, 0);
+				GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_half_downsampled_far, 1);
+				GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_nearfar_coc, 2);
 				/* binding takes care of setting the viewport to the downsampled size */
 				GPU_framebuffer_slots_bind(fx->gbuffer, 0);
 
@@ -965,7 +961,7 @@ bool GPU_fx_do_composite_pass(
 				GPU_texture_filter_mode(fx->dof_half_downsampled_far, false, false);
 
 				/* target is the downsampled coc buffer */
-				GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_far_blur, 0, NULL);
+				GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_far_blur, 0);
 				GPU_texture_bind_as_framebuffer(fx->dof_far_blur);
 
 				glDisable(GL_DEPTH_TEST);
@@ -989,7 +985,7 @@ bool GPU_fx_do_composite_pass(
 
 				GPU_shader_uniform_vector(dof_shader_pass2, interface->select_uniform, 2, 1, selection);
 
-				GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_blur, 0, NULL);
+				GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_blur, 0);
 				/* have to clear the buffer unfortunately */
 				glClear(GL_COLOR_BUFFER_BIT);
 				/* the draw call we all waited for, draw a point per pixel, scaled per circle of confusion */
@@ -1108,7 +1104,7 @@ bool GPU_fx_do_composite_pass(
 				GPU_shader_uniform_texture(dof_shader_pass1, interface->depth_uniform, fx->depth_buffer);
 
 				/* target is the downsampled coc buffer */
-				GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_buffer, 0, NULL);
+				GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_buffer, 0);
 				/* binding takes care of setting the viewport to the downsampled size */
 				GPU_texture_bind_as_framebuffer(fx->dof_near_coc_buffer);
 
@@ -1148,7 +1144,7 @@ bool GPU_fx_do_composite_pass(
 				GPU_shader_uniform_texture(dof_shader_pass2, interface->color_uniform, fx->dof_near_coc_buffer);
 
 				/* use final buffer as a temp here */
-				GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_final_buffer, 0, NULL);
+				GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_final_buffer, 0);
 
 				/* Drawing quad */
 				glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
@@ -1165,7 +1161,7 @@ bool GPU_fx_do_composite_pass(
 				GPU_texture_bind(fx->dof_near_coc_final_buffer, numslots++);
 				GPU_shader_uniform_texture(dof_shader_pass2, interface->color_uniform, fx->dof_near_coc_final_buffer);
 
-				GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_blurred_buffer, 0, NULL);
+				GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_blurred_buffer, 0);
 				glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
 
 				/* *unbind/detach */
@@ -1192,7 +1188,7 @@ bool GPU_fx_do_composite_pass(
 				GPU_texture_bind(fx->dof_near_coc_blurred_buffer, numslots++);
 				GPU_shader_uniform_texture(dof_shader_pass3, interface->near_coc_blurred, fx->dof_near_coc_blurred_buffer);
 
-				GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_final_buffer, 0, NULL);
+				GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_final_buffer, 0);
 
 				glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
 				/* disable bindings */
@@ -1218,7 +1214,7 @@ bool GPU_fx_do_composite_pass(
 				GPU_shader_uniform_texture(dof_shader_pass4, interface->near_coc_downsampled, fx->dof_near_coc_final_buffer);
 				GPU_shader_uniform_vector(dof_shader_pass4, interface->invrendertargetdim_uniform, 2, 1, invrendertargetdim);
 
-				GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_buffer, 0, NULL);
+				GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_buffer, 0);
 
 				glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
 				/* disable bindings */
diff --git a/source/blender/gpu/intern/gpu_debug.c b/source/blender/gpu/intern/gpu_debug.c
index 614fdeb..c25103d 100644
--- a/source/blender/gpu/intern/gpu_debug.c
+++ b/source/blender/gpu/intern/gpu_debug.c
@@ -43,113 +43,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-#define CASE_CODE_RETURN_STR(code) case code: return #code;
-
-static const char *gpu_gl_error_symbol(GLenum err)
-{
-	switch (err) {
-		CASE_CODE_RETURN_STR(GL_NO_ERROR)
-		CASE_CODE_RETURN_STR(GL_INVALID_ENUM)
-		CASE_CODE_RETURN_STR(GL_INVALID_VALUE)
-		CASE_CODE_RETURN_STR(GL_INVALID_OPERATION)
-		CASE_CODE_RETURN_STR(GL_STACK_OVERFLOW)
-		CASE_CODE_RETURN_STR(GL_STACK_UNDERFLOW)
-		CASE_CODE_RETURN_STR(GL_OUT_OF_MEMORY)
-
-#if GL_ARB_imaging
-		CASE_CODE_RETURN_STR(GL_TABLE_TOO_LARGE)
-#endif
-
-#if defined(WITH_GLU)
-		CASE_CODE_RETURN_STR(GLU_INVALID_ENUM)
-		CASE_CODE_RETURN_STR(GLU_INVALID_VALUE)
-		CASE_CODE_RETURN_STR(GLU_OUT_OF_MEMORY)
-#endif
-
-		default:
-			return "<unknown error>";
-	}
-}
-
-#undef CASE_CODE_RETURN_STR
-
-
-static bool gpu_report_gl_errors(const char *file, int line, const char *str)
-{
-	GLenum gl_error = glGetError();
-
-	if (gl_error == GL_NO_ERROR) {
-		return true;
-	}
-	else {
-		/* glGetError should have cleared the error flag, so if we get the
-		 * same flag twice that means glGetError itself probably triggered
-		 * the error. This happens on Windows if the GL context is invalid.
-		 */
-		{
-			GLenum new_error = glGetError();
-			if (gl_error == new_error) {
-				fprintf(stderr, "GL: Possible context invalidation issue\n");
-				return false;
-			}
-		}
-
-		fprintf(stderr,
-		        "%s:%d: ``%s'' -> GL Error (0x%04X - %s): %s\n",
-		        file, line, str, gl_error,
-		   

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list