Commit: ec0ecbe795200f9f7e3a8c0154f4e37d8be9527e
Author: Clément Foucault
Date: Mon Feb 26 23:39:09 2018 +0100
Branches: blender2.8
https://developer.blender.org/rBec0ecbe795200f9f7e3a8c0154f4e37d8be9527e
DRW: Refactor / Cleanup Builtin uniforms.
-Make the view and object dependant matrices calculation isolated and
separated, avoiding non-needed calculation.
-Adding a per drawcall matrix cache so that we can precompute these in advance
in the future.
-Replaced integer uniform location of only view dependant builtins by
DRWUniforms that are only updated once per shgroup.
===================================================================
M source/blender/draw/intern/draw_manager.c
===================================================================
diff --git a/source/blender/draw/intern/draw_manager.c
b/source/blender/draw/intern/draw_manager.c
index 72edc8d788d..d9c564fd137 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -171,8 +171,6 @@ typedef enum {
DRW_UNIFORM_FLOAT,
DRW_UNIFORM_TEXTURE,
DRW_UNIFORM_BUFFER,
- DRW_UNIFORM_MAT3,
- DRW_UNIFORM_MAT4,
DRW_UNIFORM_BLOCK
} DRWUniformType;
@@ -205,19 +203,13 @@ struct DRWInterface {
int modelinverse;
int modelview;
int modelviewinverse;
- int projection;
- int projectioninverse;
- int view;
- int viewinverse;
int modelviewprojection;
- int viewprojection;
- int viewprojectioninverse;
- int normal;
- int worldnormal;
- int camtexfac;
+ int normalview;
+ int normalworld;
int orcotexfac;
int eye;
- int clipplanes;
+ /* Matrices needed */
+ uint16_t matflag;
};
struct DRWPass {
@@ -231,56 +223,94 @@ struct DRWPass {
typedef struct DRWCallHeader {
void *prev;
-
#ifdef USE_GPU_SELECT
int select_id;
#endif
- uchar type;
+ unsigned char type, state;
+ uint16_t matflag;
+ /* Culling: Using Bounding Sphere for now for faster culling.
+ * Not ideal for planes. */
+ struct {
+ float loc[3], rad; /* Bypassed if radius is < 0.0. */
+ } bsphere;
+ /* Matrices */
+ float model[4][4];
+ float modelinverse[4][4];
+ float modelview[4][4];
+ float modelviewinverse[4][4];
+ float modelviewprojection[4][4];
+ float normalview[3][3];
+ float normalworld[3][3]; /* Not view dependant */
+ float orcotexfac[2][3]; /* Not view dependant */
+ float eyevec[3];
} DRWCallHeader;
typedef struct DRWCall {
DRWCallHeader head;
- float obmat[4][4];
Gwn_Batch *geometry;
-
- Object *ob; /* Optional */
- ID *ob_data; /* Optional. */
} DRWCall;
typedef struct DRWCallGenerate {
DRWCallHeader head;
- float obmat[4][4];
-
DRWCallGenerateFn *geometry_fn;
void *user_data;
} DRWCallGenerate;
+/* Used by DRWCall.flag */
+enum {
+ DRW_CALL_SINGLE, /* A single batch */
+ DRW_CALL_GENERATE, /* Uses a callback to draw with any
number of batches. */
+};
+
+/* Used by DRWCall.state */
+enum {
+ DRW_CALL_CULLED = (1 << 0),
+ DRW_CALL_NEGSCALE = (1 << 1),
+};
+
+/* Used by DRWCall.flag */
+enum {
+ DRW_CALL_MODELINVERSE = (1 << 0),
+ DRW_CALL_MODELVIEW = (1 << 1),
+ DRW_CALL_MODELVIEWINVERSE = (1 << 2),
+ DRW_CALL_MODELVIEWPROJECTION = (1 << 3),
+ DRW_CALL_NORMALVIEW = (1 << 4),
+ DRW_CALL_NORMALWORLD = (1 << 5),
+ DRW_CALL_ORCOTEXFAC = (1 << 6),
+ DRW_CALL_EYEVEC = (1 << 7),
+ /* 8 bit flag! */
+};
+
struct DRWShadingGroup {
struct DRWShadingGroup *next;
-
+#ifdef USE_GPU_SELECT
+ /* backlink to pass we're in */
+ DRWPass *pass_parent;
+#endif
GPUShader *shader; /* Shader to bind */
DRWInterface interface; /* Uniforms pointers */
-
- /* DRWCall or DRWCallDynamic depending of type */
- void *calls;
- void *calls_first; /* To be able to traverse the list in the order of
addition */
-
DRWState state_extra; /* State changes for this batch only
(or'd with the pass's state) */
DRWState state_extra_disable; /* State changes for this batch only
(and'd with the pass's state) */
unsigned int stencil_mask; /* Stencil mask to use for stencil
test / write operations */
int type;
- ID *instance_data; /* Object->data to instance */
- Gwn_Batch *instance_geom; /* Geometry to instance */
- Gwn_Batch *instancing_geom;/* Instances attributes */
- Gwn_Batch *batch_geom; /* Result of call batching */
-
-#ifdef USE_GPU_SELECT
- /* backlink to pass we're in */
- DRWPass *pass_parent;
-#endif
+ /* Watch this! Can be nasty for debugging. */
+ union {
+ struct { /* DRW_SHG_NORMAL */
+ void *calls; /* DRWCall or
DRWCallDynamic depending of type */
+ void *calls_first; /* To be able to traverse
the list in the order of addition */
+ };
+ struct { /* DRW_SHG_***_BATCH */
+ Gwn_Batch *batch_geom; /* Result of call batching */
+ };
+ struct { /* DRW_SHG_INSTANCE[_EXTERNAL] */
+ Gwn_Batch *instance_geom; /* Geometry to instance */
+ Gwn_Batch *instancing_geom;/* Instances attributes */
+ float instance_orcofac[2][3]; /* TODO find a better
place. */
+ };
+ };
};
/* Used by DRWShadingGroup.type */
@@ -293,16 +323,6 @@ enum {
DRW_SHG_INSTANCE_EXTERNAL,
};
-/* Used by DRWCall.type */
-enum {
- /* A single batch */
- DRW_CALL_SINGLE,
- /* Uses a callback to draw with any number of batches. */
- DRW_CALL_GENERATE,
- /* Arbitrary number of multiple args. */
- DRW_CALL_DYNAMIC,
-};
-
/** Render State: No persistent data between draw calls. */
static struct DRWGlobalState {
/* Cache generation */
@@ -367,9 +387,13 @@ static struct DRWResourceState {
} RST = {NULL};
static struct DRWMatrixOveride {
+ float original_mat[6][4][4];
float mat[6][4][4];
bool override[6];
-} viewport_matrix_override = {{{{0}}}};
+} viewport_matrices = {{{{0}}}};
+
+/* TODO View Ubo */
+static float viewcamtexcofac[4] = {0};
ListBase DRW_engines = {NULL, NULL};
@@ -645,25 +669,57 @@ void DRW_shader_free(GPUShader *shader)
/** \name Interface (DRW_interface)
* \{ */
-static void drw_interface_init(DRWInterface *interface, GPUShader *shader)
+static void drw_interface_builtin_uniform(
+ DRWShadingGroup *shgroup, int builtin, const void *value, int length,
int arraysize)
{
+ int loc = GPU_shader_get_builtin_uniform(shgroup->shader, builtin);
+
+ if (loc == -1)
+ return;
+
+ DRWUniform *uni = BLI_mempool_alloc(DST.vmempool->uniforms);
+ uni->location = loc;
+ uni->type = DRW_UNIFORM_FLOAT;
+ uni->value = value;
+ uni->length = length;
+ uni->arraysize = arraysize;
+
+ /* Prepend */
+ uni->next = shgroup->interface.uniforms;
+ shgroup->interface.uniforms = uni;
+}
+
+static void drw_interface_init(DRWShadingGroup *shgroup, GPUShader *shader)
+{
+ DRWInterface *interface = &shgroup->interface;
interface->model = GPU_shader_get_builtin_uniform(shader,
GWN_UNIFORM_MODEL);
interface->modelinverse = GPU_shader_get_builtin_uniform(shader,
GWN_UNIFORM_MODEL_INV);
interface->modelview = GPU_shader_get_builtin_uniform(shader,
GWN_UNIFORM_MODELVIEW);
interface->modelviewinverse = GPU_shader_get_builtin_uniform(shader,
GWN_UNIFORM_MODELVIEW_INV);
- interface->projection = GPU_shader_get_builtin_uniform(shader,
GWN_UNIFORM_PROJECTION);
- interface->projectioninverse = GPU_shader_get_builtin_uniform(shader,
GWN_UNIFORM_PROJECTION_INV);
- interface->view = GPU_shader_get_builtin_uniform(shader,
GWN_UNIFORM_VIEW);
- interface->viewinverse = GPU_shader_get_builtin_uniform(shader,
GWN_UNIFORM_VIEW_INV);
- interface->viewprojection = GPU_shader_get_builtin_uniform(shader,
GWN_UNIFORM_VIEWPROJECTION);
- interface->viewprojectioninverse =
GPU_shader_get_builtin_uniform(shader, GWN_UNIFORM_VIEWPROJECTION_INV);
interface->modelviewprojection = GPU_shader_get_builtin_uniform(shader,
GWN_UNIFORM_MVP);
- interface->normal = GPU_shader_get_builtin_uniform(shader,
GWN_UNIFORM_NORMAL);
- interface->worldnormal = GPU_shader_get_builtin_uniform(shader,
GWN_UNIFORM_WORLDNORMAL);
- interface->camtexfac = GPU_shader_get_builtin_uniform(shader,
GWN_UNIFORM_CAMERATEXCO);
+ interface->normalview = GPU_shader_get_builtin_uniform(shader,
GWN_UNIFORM_NORMAL);
+ interface->normalworld = GPU_shader_get_builtin_uniform(shader,
GWN_UNIFORM_WORLDNORMAL);
interface->orcotexfac = GPU_shader_get_builtin_uniform(shader,
GWN_UNIFORM_ORCO);
- interface->clipplanes = GPU_shader_get_builtin_uniform(shader,
GWN_UNIFORM_CLIPPLANES);
interface->eye = GPU_shader_get_builtin_uniform(shader,
GWN_UNIFORM_EYE);
+
+ interface->matflag = 0;
+ if (interface->modelinverse > -1)
+ interface->matflag |= DRW_CALL_MODELINVERSE;
+ if (interface->modelview > -1)
+ interface->matflag |= DRW_CALL_MODELVIEW;
+ if (interface->modelviewinverse > -1)
+ interface->matflag |= DRW_CALL_MODELVIEWINVERSE;
+ if (interface->modelviewprojection > -1)
+ interface->matflag |= DRW_CALL_MODELVIEWPROJECTION;
+ if (interface->normalview > -1)
+ interface->matflag |= DRW_CALL_NORMALVIEW;
+ if (interface->normalworld > -1)
+ interface->matflag |= DRW_CALL_NORMALWORLD;
+ if (interface->orcotexfac > -1)
+ interface->matflag |= DRW_CALL_ORCOTEXFAC;
+ if (interface->eye > -1)
+ interface->matflag |= DRW_CALL_EYEVEC;
+
interface->instance_count = 0;
#ifndef NDEBUG
interface->attribs_count = 0;
@@ -673,13 +729,23 @@ static void drw_interface_init(DRWInterface *interface,
GPUShader *shader)
interface->inst_selectid = NULL;
interface->override_selectid = -1;
#endif
+
+ /* TODO : They should be grouped inside a UBO updated once per redraw.
*/
+ drw_interface_builtin_uniform(shgroup, GWN_UNIFORM_VIEW,
viewport_matrices.mat[DRW_MAT_VIEW], 16, 1);
+ drw_interface_builtin_uniform(shgroup, GWN_UNIFORM_VIEW_INV,
viewport_matrices.mat[DRW_MAT_VIEWINV], 16, 1);
+ drw_interface_builtin_uniform(shgroup, GWN_UNIFORM_VIEWPROJECTION,
viewport_matrices.mat[DRW_MAT_PERS], 16, 1);
+ drw_interface_builtin_uniform(shgroup, GWN_UNIFORM_VIEWPROJECTION_INV,
viewport_matrices.mat[DRW_MAT_PERSINV], 16, 1);
+ drw_interface_builtin_uniform(shgroup, GWN_UNIFORM_PROJECTION,
viewport_matrices.mat[DRW_MAT_WIN], 16, 1);
+ drw_interface_builtin_uniform(shgroup, GWN_UNIFORM_PROJECTION_INV,
viewport_matrices.mat[DRW_MAT_WININV], 16, 1);
+ drw_interface_builtin_uniform(shgroup, GWN_UNIFORM_CAMERATEXCO,
viewcamtexcofac, 3, 2);
+ drw_interface_builtin_uniform(shgroup, GWN_UNIFORM_CLIPPLANES,
DST.clip_planes_eq, 4, 1); /* TO REMOVE */
}
static void drw_interface_instance_init(
DRWShadingGroup *shgroup, GPUShader *shader, Gwn_Batch *batch,
Gwn_VertFormat *format)
{
DRWInterface *interface = &shgroup->interface;
- drw_interface_init(interface, shader);
+ drw_interface_init(shgroup, shader);
#ifndef NDEBUG
interface->attribs_count = (format != NULL) ? format->attrib_ct : 0;
@@ -697,7 +763,7 @@ static void drw_interface_batching_init(
DRWShadingGroup *shgroup, GPUShader *shader, Gwn_VertFormat *format)
{
DRWInterface *interface = &shgroup->interface;
- drw_interface_init(interface, shader);
+ drw_interface_init(shgroup, s
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs