[Bf-blender-cvs] [4bb6be01ed9] tmp-drw-callbatching: DRW: Fix eevee shaders and promote DRAW_ID to builtin uniform
Clément Foucault
noreply at git.blender.org
Sat Aug 17 14:49:24 CEST 2019
Commit: 4bb6be01ed934a155096073c470af926d13a2ee0
Author: Clément Foucault
Date: Sat Jun 1 18:21:52 2019 +0200
Branches: tmp-drw-callbatching
https://developer.blender.org/rB4bb6be01ed934a155096073c470af926d13a2ee0
DRW: Fix eevee shaders and promote DRAW_ID to builtin uniform
Also rename DRAWID to BASE_INSTANCE
The Base instance uniform is necessary because fragment shaders
does not have the gl_BaseInstance builtin input variable.
So we need a workaround for those
===================================================================
M source/blender/draw/intern/draw_manager.h
M source/blender/draw/intern/draw_manager_data.c
M source/blender/draw/intern/draw_manager_exec.c
M source/blender/draw/modes/shaders/common_view_lib.glsl
M source/blender/gpu/GPU_shader_interface.h
M source/blender/gpu/intern/gpu_shader_interface.c
===================================================================
diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h
index c75fbb33e7c..ba84660ff53 100644
--- a/source/blender/draw/intern/draw_manager.h
+++ b/source/blender/draw/intern/draw_manager.h
@@ -114,8 +114,10 @@ typedef struct DRWCullingState {
} while (0)
/* Minimum max UBO size is 64KiB. We take the largest
- * UBO struct and alloc the max number. */
-#define DRW_RESOURCE_CHUNK_LEN ((1 << 16) / sizeof(DRWObjectMatrix))
+ * UBO struct and alloc the max number.
+ * ((1 << 16) / sizeof(DRWObjectMatrix)) = 512
+ * Keep in sync with common_view_lib.glsl */
+#define DRW_RESOURCE_CHUNK_LEN 512
typedef struct DRWResourceHandle {
uint32_t id : 9;
@@ -173,7 +175,7 @@ typedef enum {
/** Per drawcall uniforms/UBO */
DRW_UNIFORM_BLOCK_OBMATS,
DRW_UNIFORM_BLOCK_OBINFOS,
- DRW_UNIFORM_DRAWID,
+ DRW_UNIFORM_BASE_INSTANCE,
} DRWUniformType;
struct DRWUniform {
diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c
index 9a08b050047..1a00e0604e2 100644
--- a/source/blender/draw/intern/draw_manager_data.c
+++ b/source/blender/draw/intern/draw_manager_data.c
@@ -864,14 +864,10 @@ static void drw_shgroup_init(DRWShadingGroup *shgroup, GPUShader *shader)
int view_ubo_location = GPU_shader_get_uniform_block(shader, "viewBlock");
int model_ubo_location = GPU_shader_get_uniform_block(shader, "modelBlock");
int info_ubo_location = GPU_shader_get_uniform_block(shader, "infoBlock");
- int drawid_location = -1;
-
- if (!GLEW_ARB_shader_draw_parameters) {
- drawid_location = GPU_shader_get_uniform_ensure(shader, "drawID");
- }
+ int drawid_location = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_BASE_INSTANCE);
if (drawid_location != -1) {
- drw_shgroup_uniform_create_ex(shgroup, drawid_location, DRW_UNIFORM_DRAWID, NULL, 0, 1);
+ drw_shgroup_uniform_create_ex(shgroup, drawid_location, DRW_UNIFORM_BASE_INSTANCE, NULL, 0, 1);
}
if (model_ubo_location != -1) {
diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c
index 863b1343070..58839beac74 100644
--- a/source/blender/draw/intern/draw_manager_exec.c
+++ b/source/blender/draw/intern/draw_manager_exec.c
@@ -880,7 +880,7 @@ static void draw_update_uniforms(DRWShadingGroup *shgroup,
GPU_uniformbuffer_bind(ubo, 1);
GPU_shader_uniform_buffer(shgroup->shader, uni->location, ubo);
break;
- case DRW_UNIFORM_DRAWID:
+ case DRW_UNIFORM_BASE_INSTANCE:
*drawid_loc = uni->location;
break;
}
diff --git a/source/blender/draw/modes/shaders/common_view_lib.glsl b/source/blender/draw/modes/shaders/common_view_lib.glsl
index e235262b572..df51cf98b0d 100644
--- a/source/blender/draw/modes/shaders/common_view_lib.glsl
+++ b/source/blender/draw/modes/shaders/common_view_lib.glsl
@@ -1,4 +1,5 @@
#define COMMON_VIEW_LIB
+#define DRW_RESOURCE_CHUNK_LEN 512
/* keep in sync with DRWManager.view_data */
layout(std140) uniform viewBlock
@@ -23,10 +24,18 @@ layout(std140) uniform viewBlock
_world_clip_planes_calc_clip_distance(p, clipPlanes)
#endif
-#ifdef GL_ARB_shader_draw_parameters
-# define drawID gl_BaseInstanceARB
+#if defined(GL_ARB_shader_draw_parameters) && defined(GPU_VERTEX_SHADER)
+# define resource_id (gl_BaseInstanceARB + gl_InstanceID)
#else
-uniform int drawID = 0;
+uniform int baseInstance = 0;
+# ifdef GPU_VERTEX_SHADER
+# define resource_id (baseInstance + gl_InstanceID)
+# else
+/* This is a fallback when using it in a fragement/geometry shader.
+ * In this case, we cannot do drawcall merging and we must disable
+ * it explicitly in the shading group. */
+# define resource_id baseInstance
+# endif
#endif
struct ObjectMatrices {
@@ -36,11 +45,11 @@ struct ObjectMatrices {
layout(std140) uniform modelBlock
{
- ObjectMatrices drw_matrices[512];
+ ObjectMatrices drw_matrices[DRW_RESOURCE_CHUNK_LEN];
};
-#define ModelMatrix (drw_matrices[drawID + gl_InstanceID].drw_modelMatrix)
-#define ModelMatrixInverse (drw_matrices[drawID + gl_InstanceID].drw_modelMatrixInverse)
+#define ModelMatrix (drw_matrices[resource_id].drw_modelMatrix)
+#define ModelMatrixInverse (drw_matrices[resource_id].drw_modelMatrixInverse)
/** Transform shortcuts. */
/* Rule of thumb: Try to reuse world positions and normals because converting though viewspace
diff --git a/source/blender/gpu/GPU_shader_interface.h b/source/blender/gpu/GPU_shader_interface.h
index bfa5d53ed1e..36c4875105d 100644
--- a/source/blender/gpu/GPU_shader_interface.h
+++ b/source/blender/gpu/GPU_shader_interface.h
@@ -48,9 +48,10 @@ typedef enum {
GPU_UNIFORM_ORCO, /* vec4 OrcoTexCoFactors[] */
GPU_UNIFORM_CLIPPLANES, /* vec4 WorldClipPlanes[] */
- GPU_UNIFORM_COLOR, /* vec4 color */
- GPU_UNIFORM_CALLID, /* int callId */
- GPU_UNIFORM_OBJECT_INFO, /* vec3 objectInfo */
+ GPU_UNIFORM_COLOR, /* vec4 color */
+ GPU_UNIFORM_CALLID, /* int callId */
+ GPU_UNIFORM_BASE_INSTANCE, /* int baseInstance */
+ GPU_UNIFORM_OBJECT_INFO, /* vec3 objectInfo */
GPU_UNIFORM_CUSTOM, /* custom uniform, not one of the above built-ins */
diff --git a/source/blender/gpu/intern/gpu_shader_interface.c b/source/blender/gpu/intern/gpu_shader_interface.c
index e34c6e23024..0dfcdeefc20 100644
--- a/source/blender/gpu/intern/gpu_shader_interface.c
+++ b/source/blender/gpu/intern/gpu_shader_interface.c
@@ -66,6 +66,7 @@ static const char *BuiltinUniform_name(GPUUniformBuiltin u)
[GPU_UNIFORM_COLOR] = "color",
[GPU_UNIFORM_CALLID] = "callId",
+ [GPU_UNIFORM_BASE_INSTANCE] = "baseInstance",
[GPU_UNIFORM_OBJECT_INFO] = "unfobjectinfo",
[GPU_UNIFORM_CUSTOM] = NULL,
More information about the Bf-blender-cvs
mailing list