[Bf-blender-cvs] [516cb160def] tmp-drw-callbatching: DRW: Remove DRWCallSate in favor of DRWResourceHandle
Clément Foucault
noreply at git.blender.org
Sat Aug 17 14:49:29 CEST 2019
Commit: 516cb160def30daf83b15790fd3c733b1d50c172
Author: Clément Foucault
Date: Sat Jun 1 21:38:11 2019 +0200
Branches: tmp-drw-callbatching
https://developer.blender.org/rB516cb160def30daf83b15790fd3c733b1d50c172
DRW: Remove DRWCallSate in favor of DRWResourceHandle
===================================================================
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
M source/blender/gpu/GPU_viewport.h
M source/blender/gpu/intern/gpu_viewport.c
===================================================================
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index b03700557e9..0ee572f3f15 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -541,7 +541,6 @@ static void drw_viewport_cache_resize(void)
}
BLI_memblock_clear(DST.vmempool->calls, NULL);
- BLI_memblock_clear(DST.vmempool->states, NULL);
BLI_memblock_clear(DST.vmempool->obmats, NULL);
BLI_memblock_clear(DST.vmempool->obinfos, NULL);
BLI_memblock_clear(DST.vmempool->cullstates, NULL);
@@ -591,13 +590,11 @@ static void drw_context_state_init(void)
}
}
-static DRWCallState *draw_unit_state_create(void)
+static void draw_unit_state_create(void)
{
- DRWCallState *state = BLI_memblock_alloc(DST.vmempool->states);
DRWObjectInfos *infos = BLI_memblock_alloc(DST.vmempool->obinfos);
DRWObjectMatrix *mats = BLI_memblock_alloc(DST.vmempool->obmats);
DRWCullingState *culling = BLI_memblock_alloc(DST.vmempool->cullstates);
- state->flag = 0;
unit_m4(mats->model);
unit_m4(mats->modelinverse);
@@ -614,8 +611,6 @@ static DRWCallState *draw_unit_state_create(void)
culling->user_data = NULL;
INCREMENT_RESOURCE_HANDLE(DST.resource_handle);
-
- return state;
}
/* It also stores viewport variable to an immutable place: DST
@@ -643,9 +638,6 @@ static void drw_viewport_var_init(void)
if (DST.vmempool->calls == NULL) {
DST.vmempool->calls = BLI_memblock_create(sizeof(DRWCall));
}
- if (DST.vmempool->states == NULL) {
- DST.vmempool->states = BLI_memblock_create(sizeof(DRWCallState));
- }
if (DST.vmempool->obmats == NULL) {
uint chunk_len = sizeof(DRWObjectMatrix) * DRW_RESOURCE_CHUNK_LEN;
DST.vmempool->obmats = BLI_memblock_create_ex(sizeof(DRWObjectMatrix), chunk_len);
@@ -674,10 +666,9 @@ static void drw_viewport_var_init(void)
DST.vmempool->images = BLI_memblock_create(sizeof(GPUTexture *));
}
- DST.resource_handle.id = 0;
- DST.resource_handle.chunk = 0;
+ DST.resource_handle.value = 0;
- DST.unit_state = draw_unit_state_create();
+ draw_unit_state_create();
DST.idatalist = GPU_viewport_instance_data_list_get(DST.viewport);
DRW_instance_data_list_reset(DST.idatalist);
@@ -691,8 +682,6 @@ static void drw_viewport_var_init(void)
DST.default_framebuffer = NULL;
DST.vmempool = NULL;
-
- DST.unit_state = NULL;
}
DST.primary_view_ct = 0;
@@ -1118,7 +1107,7 @@ static void drw_engines_world_update(Scene *scene)
static void drw_engines_cache_populate(Object *ob)
{
- DST.ob_state = NULL;
+ DST.ob_handle.value = 0;
/* HACK: DrawData is copied by COW from the duplicated object.
* This is valid for IDs that cannot be instantiated but this
@@ -2082,7 +2071,7 @@ void DRW_render_object_iter(
if ((object_type_exclude_viewport & (1 << ob->type)) == 0) {
DST.dupli_parent = data_.dupli_parent;
DST.dupli_source = data_.dupli_object_current;
- DST.ob_state = NULL;
+ DST.ob_handle.value = 0;
drw_duplidata_load(DST.dupli_source);
if (!DST.dupli_source) {
diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h
index ba84660ff53..9dfd4d9d0bf 100644
--- a/source/blender/draw/intern/draw_manager.h
+++ b/source/blender/draw/intern/draw_manager.h
@@ -120,8 +120,17 @@ typedef struct DRWCullingState {
#define DRW_RESOURCE_CHUNK_LEN 512
typedef struct DRWResourceHandle {
- uint32_t id : 9;
- uint32_t chunk : 23;
+ union {
+ struct {
+ uint32_t negative_scale : 1;
+ uint32_t id : 9;
+ uint32_t chunk : 22;
+ };
+ /** Use this to read the whole handle value as one 32bit uint.
+ * Useful for sorting and test.
+ */
+ uint32_t value;
+ };
} DRWResourceHandle;
typedef struct DRWObjectMatrix {
@@ -140,20 +149,16 @@ typedef struct DRWObjectInfos {
BLI_STATIC_ASSERT_ALIGN(DRWObjectMatrix, 16)
BLI_STATIC_ASSERT_ALIGN(DRWObjectInfos, 16)
-typedef struct DRWCallState {
- uchar flag;
- DRWResourceHandle handle;
-} DRWCallState;
-
typedef struct DRWCall {
struct DRWCall *next;
- DRWCallState *state;
GPUBatch *batch;
uint vert_first;
uint vert_count;
uint inst_count;
+ DRWResourceHandle handle;
+
#ifdef USE_GPU_SELECT
/* TODO(fclem) remove once we have a dedicated selection engine. */
int select_id;
@@ -309,10 +314,8 @@ typedef struct DRWManager {
/* Cache generation */
ViewportMemoryPool *vmempool;
DRWInstanceDataList *idatalist;
- /* Default Unit model matrix state without culling. */
- DRWCallState *unit_state;
/* State of the object being evaluated if already allocated. */
- DRWCallState *ob_state;
+ DRWResourceHandle ob_handle;
/** True if current DST.ob_state has its matching DRWObjectInfos init. */
bool ob_state_obinfo_init;
/** Handle of current object resource in object resource arrays (DRWObjectMatrices/Infos). */
diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c
index 1a00e0604e2..6ff3e709df3 100644
--- a/source/blender/draw/intern/draw_manager_data.c
+++ b/source/blender/draw/intern/draw_manager_data.c
@@ -443,42 +443,43 @@ static void drw_call_culling_init(DRWCullingState *cull, Object *ob)
cull->user_data = NULL;
}
-static DRWCallState *drw_call_state_create(float (*obmat)[4], Object *ob)
+static DRWResourceHandle drw_call_state_create(float (*obmat)[4], Object *ob)
{
- DRWCallState *state = BLI_memblock_alloc(DST.vmempool->states);
DRWCullingState *culling = BLI_memblock_alloc(DST.vmempool->cullstates);
DRWObjectMatrix *ob_mats = BLI_memblock_alloc(DST.vmempool->obmats);
- /* FIXME Meh, not always needed byt can be accessed after creation.
+ /* FIXME Meh, not always needed but can be accessed after creation.
* Also it needs to have the same resource handle. */
DRWObjectInfos *ob_infos = BLI_memblock_alloc(DST.vmempool->obinfos);
UNUSED_VARS(ob_infos);
- SET_FLAG_FROM_TEST(state->flag, (ob && (ob->transflag & OB_NEG_SCALE)), DRW_CALL_NEGSCALE);
-
- state->handle = DST.resource_handle;
+ DRWResourceHandle handle = DST.resource_handle;
INCREMENT_RESOURCE_HANDLE(DST.resource_handle);
+ handle.negative_scale = (ob && (ob->transflag & OB_NEG_SCALE)) ? 1 : 0;
+
drw_call_matrix_init(ob_mats, ob, obmat);
drw_call_culling_init(culling, ob);
/* ob_infos is init only if needed. */
- return state;
+ return handle;
}
-static DRWCallState *drw_call_state_object(DRWShadingGroup *shgroup, float (*obmat)[4], Object *ob)
+static DRWResourceHandle drw_call_handle_object(DRWShadingGroup *shgroup,
+ float (*obmat)[4],
+ Object *ob)
{
if (ob == NULL) {
if (obmat == NULL) {
- BLI_assert(DST.unit_state);
- return DST.unit_state;
+ DRWResourceHandle handle = {.value = 0};
+ return handle;
}
else {
return drw_call_state_create(obmat, NULL);
}
}
else {
- if (DST.ob_state == NULL) {
- DST.ob_state = drw_call_state_create(obmat, ob);
+ if (DST.ob_handle.value == 0) {
+ DST.ob_handle = drw_call_state_create(obmat, ob);
DST.ob_state_obinfo_init = false;
}
@@ -487,13 +488,13 @@ static DRWCallState *drw_call_state_object(DRWShadingGroup *shgroup, float (*obm
DST.ob_state_obinfo_init = true;
DRWObjectInfos *ob_infos = BLI_memblock_elem_get(
- DST.vmempool->obinfos, DST.ob_state->handle.chunk, DST.ob_state->handle.id);
+ DST.vmempool->obinfos, DST.ob_handle.chunk, DST.ob_handle.id);
drw_call_obinfos_init(ob_infos, ob);
}
}
- return DST.ob_state;
+ return DST.ob_handle;
}
}
@@ -511,7 +512,7 @@ void DRW_shgroup_call_ex(DRWShadingGroup *shgroup,
DRWCall *call = BLI_memblock_alloc(DST.vmempool->calls);
BLI_LINKS_APPEND(&shgroup->calls, call);
- call->state = drw_call_state_object(shgroup, ob ? ob->obmat : obmat, ob);
+ call->handle = drw_call_handle_object(shgroup, ob ? ob->obmat : obmat, ob);
call->batch = geom;
call->vert_first = v_sta;
call->vert_count = v_ct; /* 0 means auto from batch. */
@@ -523,7 +524,7 @@ void DRW_shgroup_call_ex(DRWShadingGroup *shgroup,
/* Culling data. */
if (user_data || bypass_culling) {
DRWCullingState *culling = BLI_memblock_elem_get(
- DST.vmempool->cullstates, call->state->handle.chunk, call->state->handle.id);
+ DST.vmempool->cullstates, call->handle.chunk, call->handle.id);
if (user_data) {
culling->user_data = user_data;
@@ -544,7 +545,7 @@ static void drw_shgroup_call_procedural_add_ex(DRWShadingGroup *shgroup,
DRWCall *call = BLI_memblock_alloc(DST.vmempool->calls);
BLI_LINKS_APPEND(&shgroup->calls, call);
- call->state = drw_call_state_object(shgroup, ob ? ob->obmat : NULL, ob);
+ call->handle = drw_call_handle_object(shgroup, ob ? ob->obmat : NULL, ob);
call->batch = geom;
call->vert_first = 0;
call->vert_count = vert_count;
@@ -583,7 +584,7 @@ void DRW_shgroup_call_instances(DRWShadingGroup *shgroup,
DRWCall *call = BLI_memblock_alloc(DST.vmempool->calls);
BLI_LINKS_APPEND(&shgroup->calls, call);
- call->state = drw_call_state_object(shgroup, ob ? ob->obmat : NULL, ob);
+ call->handle = drw_call_handle_object(shgroup, ob ? ob->obmat : NULL, ob);
call->batch = geom;
call->vert_first = 0;
call->vert_count = 0; /* Auto from batch. */
@@ -607,7 +608,7 @@ void DRW_shgroup_call_instances_with_attribs(DRWShadingGroup *shgroup,
DRWCall *call = BLI_memblock_alloc(DST.vmempool->calls);
BLI_LINKS_APPEND(&shgroup->calls, call);
- call->state = drw_call_state_object(shgroup, ob ? ob->obmat : NULL, ob);
+ call->handle = drw_call_handle_object(shgroup, ob ? ob->obmat : NULL, ob);
call->batch = DRW_temp_batch_instance_request(DST.idatalist, buf_inst, geom);
call->vert_first = 0;
call->vert_count = 0; /* Auto from batch. */
@@ -771,7 +772,7 @@ DRWCallBuffer *DRW_shgroup_call_buffer(DRWShadingGroup *shgroup,
DRWCall *call = BLI_memblock_alloc(DST.vmempool->calls);
BLI_LINKS_APPEND(&shgroup-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list