[Bf-blender-cvs] [fa010ddddac] draw-colormanagement: DRW: Use Batch API instead of IMM for color managment
Clément Foucault
noreply at git.blender.org
Wed Jan 22 19:39:41 CET 2020
Commit: fa010ddddac81af1e0e6422c7066461799361a39
Author: Clément Foucault
Date: Wed Jan 22 16:59:26 2020 +0100
Branches: draw-colormanagement
https://developer.blender.org/rBfa010ddddac81af1e0e6422c7066461799361a39
DRW: Use Batch API instead of IMM for color managment
A little cleanup that should avoid some state changes and pipeline stall.
===================================================================
M source/blender/draw/intern/draw_manager.c
M source/blender/gpu/GPU_batch.h
M source/blender/gpu/intern/gpu_batch.c
M source/blender/gpu/intern/gpu_immediate.c
M source/blender/gpu/intern/gpu_shader_private.h
===================================================================
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 2fbb0a740cf..99dc640158a 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -271,14 +271,15 @@ void DRW_transform_to_display(GPUTexture *tex, bool use_view_transform, bool use
{
drw_state_set(DRW_STATE_WRITE_COLOR);
- GPUVertFormat *vert_format = immVertexFormat();
- uint pos = GPU_vertformat_attr_add(vert_format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- uint texco = GPU_vertformat_attr_add(vert_format, "texCoord", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ GPUBatch *geom = DRW_cache_fullscreen_quad_get();
const float dither = 1.0f;
bool use_ocio = false;
+ GPU_matrix_identity_set();
+ GPU_matrix_identity_projection_set();
+
/* Should we apply the view transform */
if (DRW_state_do_color_management()) {
Scene *scene = DST.draw_ctx.scene;
@@ -305,44 +306,26 @@ void DRW_transform_to_display(GPUTexture *tex, bool use_view_transform, bool use
&view_settings, display_settings, NULL, dither, false);
}
- if (!use_ocio) {
+ if (use_ocio) {
+ GPU_batch_program_set_imm_shader(geom);
+ /* End IMM session. */
+ IMB_colormanagement_finish_glsl_draw();
+ }
+ else {
/* View transform is already applied for offscreen, don't apply again, see: T52046 */
if (DST.options.is_image_render && !DST.options.is_scene_render) {
- immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR);
- immUniformColor4f(1.0f, 1.0f, 1.0f, 1.0f);
+ GPU_batch_program_set_builtin(geom, GPU_SHADER_2D_IMAGE_COLOR);
+ GPU_batch_uniform_4f(geom, "color", 1.0f, 1.0f, 1.0f, 1.0f);
}
else {
- immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_LINEAR_TO_SRGB);
+ GPU_batch_program_set_builtin(geom, GPU_SHADER_2D_IMAGE_LINEAR_TO_SRGB);
}
- immUniform1i("image", 0);
+ GPU_batch_uniform_1i(geom, "image", 0);
}
GPU_texture_bind(tex, 0); /* OCIO texture bind point is 0 */
-
- float mat[4][4];
- unit_m4(mat);
- immUniformMatrix4fv("ModelViewProjectionMatrix", mat);
-
- /* Full screen triangle */
- immBegin(GPU_PRIM_TRIS, 3);
- immAttr2f(texco, 0.0f, 0.0f);
- immVertex2f(pos, -1.0f, -1.0f);
-
- immAttr2f(texco, 2.0f, 0.0f);
- immVertex2f(pos, 3.0f, -1.0f);
-
- immAttr2f(texco, 0.0f, 2.0f);
- immVertex2f(pos, -1.0f, 3.0f);
- immEnd();
-
+ GPU_batch_draw(geom);
GPU_texture_unbind(tex);
-
- if (use_ocio) {
- IMB_colormanagement_finish_glsl_draw();
- }
- else {
- immUnbindProgram();
- }
}
/* Draw texture to framebuffer without any color transforms */
diff --git a/source/blender/gpu/GPU_batch.h b/source/blender/gpu/GPU_batch.h
index 3616189e673..fc7dff5d99b 100644
--- a/source/blender/gpu/GPU_batch.h
+++ b/source/blender/gpu/GPU_batch.h
@@ -126,6 +126,7 @@ int GPU_batch_vertbuf_add_ex(GPUBatch *, GPUVertBuf *, bool own_vbo);
void GPU_batch_program_set_no_use(GPUBatch *, uint32_t program, const GPUShaderInterface *);
void GPU_batch_program_set(GPUBatch *, uint32_t program, const GPUShaderInterface *);
void GPU_batch_program_set_shader(GPUBatch *, GPUShader *shader);
+void GPU_batch_program_set_imm_shader(GPUBatch *batch);
void GPU_batch_program_set_builtin(GPUBatch *batch, eGPUBuiltinShader shader_id);
void GPU_batch_program_set_builtin_with_config(GPUBatch *batch,
eGPUBuiltinShader shader_id,
diff --git a/source/blender/gpu/intern/gpu_batch.c b/source/blender/gpu/intern/gpu_batch.c
index 717983f94d8..c20fc2172d1 100644
--- a/source/blender/gpu/intern/gpu_batch.c
+++ b/source/blender/gpu/intern/gpu_batch.c
@@ -982,6 +982,17 @@ void GPU_batch_program_set_builtin(GPUBatch *batch, eGPUBuiltinShader shader_id)
GPU_batch_program_set_builtin_with_config(batch, shader_id, GPU_SHADER_CFG_DEFAULT);
}
+/* Bind program bound to IMM to the batch.
+ * XXX Use this with much care. Drawing with the GPUBatch API is not compatible with IMM.
+ * DO NOT DRAW WITH THE BATCH BEFORE CALLING immUnbindProgram. */
+void GPU_batch_program_set_imm_shader(GPUBatch *batch)
+{
+ GLuint program;
+ GPUShaderInterface *interface;
+ immGetProgram(&program, &interface);
+ GPU_batch_program_set(batch, program, interface);
+}
+
/** \} */
/* -------------------------------------------------------------------- */
diff --git a/source/blender/gpu/intern/gpu_immediate.c b/source/blender/gpu/intern/gpu_immediate.c
index bed7ab25bb9..bd3de96d636 100644
--- a/source/blender/gpu/intern/gpu_immediate.c
+++ b/source/blender/gpu/intern/gpu_immediate.c
@@ -168,6 +168,13 @@ void immUnbindProgram(void)
imm.bound_program = 0;
}
+/* XXX do not use it. Special hack to use OCIO with batch API. */
+void immGetProgram(GLuint *program, GPUShaderInterface **shaderface)
+{
+ *program = imm.bound_program;
+ *shaderface = (GPUShaderInterface *)imm.shader_interface;
+}
+
#if TRUST_NO_ONE
static bool vertex_count_makes_sense_for_primitive(uint vertex_len, GPUPrimType prim_type)
{
diff --git a/source/blender/gpu/intern/gpu_shader_private.h b/source/blender/gpu/intern/gpu_shader_private.h
index 856a14c6868..e4443e79a8d 100644
--- a/source/blender/gpu/intern/gpu_shader_private.h
+++ b/source/blender/gpu/intern/gpu_shader_private.h
@@ -44,4 +44,7 @@ struct GPUShader {
#endif
};
+/* XXX do not use it. Special hack to use OCIO with batch API. */
+void immGetProgram(GLuint *program, GPUShaderInterface **shaderface);
+
#endif /* __GPU_SHADER_PRIVATE_H__ */
More information about the Bf-blender-cvs
mailing list