[Bf-blender-cvs] [bd2a41c30ae] tmp-drw-callbatching: DRW: Use a DRWResourceHandle to reference the parent DRWPass ...
Clément Foucault
noreply at git.blender.org
Sat Aug 17 14:51:00 CEST 2019
Commit: bd2a41c30ae09ccaf15573fed1b57933b0858c75
Author: Clément Foucault
Date: Sun Jun 23 11:35:58 2019 +0200
Branches: tmp-drw-callbatching
https://developer.blender.org/rBbd2a41c30ae09ccaf15573fed1b57933b0858c75
DRW: Use a DRWResourceHandle to reference the parent DRWPass ...
... inside a DRWShadingGroup
===================================================================
M source/blender/draw/intern/draw_manager.c
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
===================================================================
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index be66a9a1a32..66defdb6c89 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -668,13 +668,15 @@ static void drw_viewport_var_init(void)
DST.vmempool->views = BLI_memblock_create(sizeof(DRWView));
}
if (DST.vmempool->passes == NULL) {
- DST.vmempool->passes = BLI_memblock_create(sizeof(DRWPass));
+ uint chunk_len = sizeof(DRWPass) * DRW_RESOURCE_CHUNK_LEN;
+ DST.vmempool->passes = BLI_memblock_create_ex(sizeof(DRWPass), chunk_len);
}
if (DST.vmempool->images == NULL) {
DST.vmempool->images = BLI_memblock_create(sizeof(GPUTexture *));
}
DST.resource_handle.value = 0;
+ DST.pass_handle.value = 0;
draw_unit_state_create();
diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h
index ee8b29ae401..d9ef67346ee 100644
--- a/source/blender/draw/intern/draw_manager.h
+++ b/source/blender/draw/intern/draw_manager.h
@@ -155,12 +155,16 @@ typedef enum {
DRW_CMD_DRAW_RANGE = 1,
DRW_CMD_DRAW_INSTANCE = 2,
DRW_CMD_DRAW_PROCEDURAL = 3,
+ /* First 2 bits are for draw commands.
+ * DRW_shgroup_is_empty uses this fact. */
/* Other Commands */
- DRW_CMD_STENCIL = 14,
- DRW_CMD_SELECTID = 15,
+ DRW_CMD_STENCIL = 2 << 2,
+ DRW_CMD_SELECTID = 3 << 2,
/* Needs to fit in 4bits */
} eDRWCommandType;
+#define DRW_MAX_DRAW_CMD_TYPE DRW_CMD_DRAW_PROCEDURAL
+
typedef struct DRWCommandDraw {
GPUBatch *batch;
DRWResourceHandle handle;
@@ -259,8 +263,6 @@ struct DRWShadingGroup {
GPUShader *shader; /* Shader to bind */
struct DRWUniformChunk *uniforms; /* Uniforms pointers */
- int objectinfo;
-
struct {
/* Chunks of draw calls. */
struct DRWCommandChunk *first, *last;
@@ -270,8 +272,16 @@ struct DRWShadingGroup {
DRWState state_extra;
/** State changes for this batch only (and'd with the pass's state) */
DRWState state_extra_disable;
-
- DRWPass *pass_parent; /* backlink to pass we're in */
+ union {
+ struct {
+ int objectinfo; /* Equal to 1 if the shader needs obinfos. */
+ DRWResourceHandle pass_handle; /* Memblock key to parent pass. */
+ };
+ struct {
+ float distance; /* Distance from camera. */
+ uint original_index; /* Original position inside the shgroup list. */
+ } z_sorting;
+ };
};
#define MAX_PASS_NAME 32
@@ -283,6 +293,7 @@ struct DRWPass {
DRWShadingGroup *last;
} shgroups;
+ DRWResourceHandle handle;
DRWState state;
char name[MAX_PASS_NAME];
};
@@ -396,6 +407,8 @@ typedef struct DRWManager {
bool ob_state_obinfo_init;
/** Handle of current object resource in object resource arrays (DRWObjectMatrices/Infos). */
DRWResourceHandle resource_handle;
+ /** Handle of next DRWPass to be allocated. */
+ DRWResourceHandle pass_handle;
/** Dupli state. NULL if not dupli. */
struct DupliObject *dupli_source;
diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c
index 4f1fe6a27c6..e8045dbc044 100644
--- a/source/blender/draw/intern/draw_manager_data.c
+++ b/source/blender/draw/intern/draw_manager_data.c
@@ -568,7 +568,7 @@ static DRWResourceHandle drw_resource_handle(DRWShadingGroup *shgroup,
DST.ob_state_obinfo_init = false;
}
- if (shgroup->objectinfo != -1) {
+ if (shgroup->objectinfo) {
if (!DST.ob_state_obinfo_init) {
DST.ob_state_obinfo_init = true;
@@ -601,6 +601,7 @@ static void *drw_command_create(DRWShadingGroup *shgroup, eDRWCommandType type)
DRWCommandSmallChunk *smallchunk = BLI_memblock_alloc(DST.vmempool->commands_small);
smallchunk->command_len = ARRAY_SIZE(smallchunk->commands);
smallchunk->command_used = 0;
+ smallchunk->command_type[0] = 0x0lu;
chunk = (DRWCommandChunk *)smallchunk;
BLI_LINKS_APPEND(&shgroup->cmd, chunk);
}
@@ -1056,7 +1057,7 @@ static void drw_shgroup_init(DRWShadingGroup *shgroup, GPUShader *shader)
shgroup->objectinfo = 1;
}
else {
- shgroup->objectinfo = -1;
+ shgroup->objectinfo = 0;
}
if (view_ubo_location != -1) {
@@ -1093,7 +1094,7 @@ static DRWShadingGroup *drw_shgroup_create_ex(struct GPUShader *shader, DRWPass
shgroup->state_extra_disable = ~0x0;
shgroup->cmd.first = NULL;
shgroup->cmd.last = NULL;
- shgroup->pass_parent = pass;
+ shgroup->pass_handle = pass->handle;
return shgroup;
}
@@ -1219,7 +1220,15 @@ void DRW_shgroup_stencil_mask(DRWShadingGroup *shgroup, uint mask)
bool DRW_shgroup_is_empty(DRWShadingGroup *shgroup)
{
- return shgroup->cmd.first == NULL;
+ DRWCommandChunk *chunk = shgroup->cmd.first;
+ for (; chunk; chunk = chunk->next) {
+ for (int i = 0; i < chunk->command_used; i++) {
+ if (command_type_get(chunk->command_type, i) <= DRW_MAX_DRAW_CMD_TYPE) {
+ return false;
+ }
+ }
+ }
+ return true;
}
/* This is a workaround function waiting for the clearing operation to be available inside the
@@ -1246,7 +1255,10 @@ DRWShadingGroup *DRW_shgroup_create_sub(DRWShadingGroup *shgroup)
shgroup_new->cmd.first = NULL;
shgroup_new->cmd.last = NULL;
- BLI_LINKS_INSERT_AFTER(&shgroup->pass_parent->shgroups, shgroup, shgroup_new);
+ DRWPass *parent_pass = BLI_memblock_elem_get(
+ DST.vmempool->passes, shgroup->pass_handle.chunk, shgroup->pass_handle.id);
+
+ BLI_LINKS_INSERT_AFTER(&parent_pass->shgroups, shgroup, shgroup_new);
return shgroup_new;
}
@@ -1741,6 +1753,8 @@ DRWPass *DRW_pass_create(const char *name, DRWState state)
pass->shgroups.first = NULL;
pass->shgroups.last = NULL;
+ pass->handle = DST.pass_handle;
+ INCREMENT_RESOURCE_HANDLE(DST.pass_handle);
return pass;
}
diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c
index 532d31fb2ed..a2d6f6f9155 100644
--- a/source/blender/draw/intern/draw_manager_exec.c
+++ b/source/blender/draw/intern/draw_manager_exec.c
@@ -829,8 +829,12 @@ static bool ubo_bindings_validate(DRWShadingGroup *shgroup)
printf("Trying to draw with missing UBO binding.\n");
valid = false;
}
+
+ DRWPass *parent_pass = BLI_memblock_elem_get(
+ DST.vmempool->passes, shgroup->pass_handle.chunk, shgroup->pass_handle.id);
+
printf("Pass : %s, Shader : %s, Block : %s\n",
- shgroup->pass_parent->name,
+ parent_pass->name,
shgroup->shader->name,
blockname);
}
More information about the Bf-blender-cvs
mailing list