Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2019-06-01 22:38:11 +0300
committerClément Foucault <foucault.clem@gmail.com>2019-08-17 15:48:48 +0300
commit516cb160def30daf83b15790fd3c733b1d50c172 (patch)
treeb73da83155b9ca079cb58799b4eb05505ac1ec84
parent1112b6cd733aba763930546005f2133ea346ada8 (diff)
DRW: Remove DRWCallSate in favor of DRWResourceHandle
-rw-r--r--source/blender/draw/intern/draw_manager.c21
-rw-r--r--source/blender/draw/intern/draw_manager.h25
-rw-r--r--source/blender/draw/intern/draw_manager_data.c47
-rw-r--r--source/blender/draw/intern/draw_manager_exec.c8
-rw-r--r--source/blender/gpu/GPU_viewport.h1
-rw-r--r--source/blender/gpu/intern/gpu_viewport.c3
6 files changed, 47 insertions, 58 deletions
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->calls, call);
- call->state = drw_call_state_object(shgroup, NULL, NULL);
+ call->handle = drw_call_handle_object(shgroup, NULL, NULL);
GPUVertBuf *buf = DRW_temp_buffer_request(DST.idatalist, format, &call->vert_count);
call->batch = DRW_temp_batch_request(DST.idatalist, buf, prim_type);
call->vert_first = 0;
@@ -801,7 +802,7 @@ DRWCallBuffer *DRW_shgroup_call_buffer_instance(DRWShadingGroup *shgroup,
DRWCall *call = BLI_memblock_alloc(DST.vmempool->calls);
BLI_LINKS_APPEND(&shgroup->calls, call);
- call->state = drw_call_state_object(shgroup, NULL, NULL);
+ call->handle = drw_call_handle_object(shgroup, NULL, NULL);
GPUVertBuf *buf = DRW_temp_buffer_request(DST.idatalist, format, &call->inst_count);
call->batch = DRW_temp_batch_instance_request(DST.idatalist, buf, geom);
call->vert_first = 0;
@@ -1645,9 +1646,9 @@ static int pass_shgroup_dist_sort(void *thunk, const void *a, const void *b)
/** XXX(fclem) This is extremely inefficient. To revisit. */
DRWObjectMatrix *a_ob_mats = BLI_memblock_elem_get(
- DST.vmempool->obmats, call_a->state->handle.chunk, call_a->state->handle.id);
+ DST.vmempool->obmats, call_a->handle.chunk, call_a->handle.id);
DRWObjectMatrix *b_ob_mats = BLI_memblock_elem_get(
- DST.vmempool->obmats, call_a->state->handle.chunk, call_b->state->handle.id);
+ DST.vmempool->obmats, call_a->handle.chunk, call_b->handle.id);
float tmp[3];
sub_v3_v3v3(tmp, zsortdata->origin, a_ob_mats->model[3]);
diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c
index 0290136e2ac..19bfd3d6e16 100644
--- a/source/blender/draw/intern/draw_manager_exec.c
+++ b/source/blender/draw/intern/draw_manager_exec.c
@@ -394,7 +394,7 @@ void DRW_state_reset(void)
static bool draw_call_is_culled(DRWCall *call, DRWView *view)
{
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);
return (culling->mask & view->culling_mask) != 0;
}
@@ -577,7 +577,7 @@ static void draw_compute_culling(DRWView *view)
BLI_INLINE void draw_geometry_prepare(DRWShadingGroup *shgroup, DRWCall *call)
{
BLI_assert(call);
- DRWResourceHandle handle = call->state->handle;
+ DRWResourceHandle handle = call->handle;
if (shgroup->model != -1 || shgroup->modelinverse != -1 || shgroup->modelviewprojection != -1) {
DRWObjectMatrix *ob_mats = BLI_memblock_elem_get(
@@ -976,7 +976,7 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
uint base_inst = 0;
int callid = 0;
for (DRWCall *call = shgroup->calls.first; call; call = call->next) {
- DRWResourceHandle handle = call->state->handle;
+ DRWResourceHandle handle = call->handle;
if (draw_call_is_culled(call, DST.view_active)) {
continue;
@@ -989,7 +989,7 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
}
/* Negative scale objects */
- bool neg_scale = call->state->flag & DRW_CALL_NEGSCALE;
+ bool neg_scale = call->handle.negative_scale;
if (neg_scale != prev_neg_scale) {
glFrontFace((neg_scale) ? GL_CW : GL_CCW);
prev_neg_scale = neg_scale;
diff --git a/source/blender/gpu/GPU_viewport.h b/source/blender/gpu/GPU_viewport.h
index 8e95e90dce4..1ca1555affe 100644
--- a/source/blender/gpu/GPU_viewport.h
+++ b/source/blender/gpu/GPU_viewport.h
@@ -38,7 +38,6 @@ typedef struct GPUViewport GPUViewport;
/* Contains memory pools information */
typedef struct ViewportMemoryPool {
struct BLI_memblock *calls;
- struct BLI_memblock *states;
struct BLI_memblock *obmats;
struct BLI_memblock *obinfos;
struct BLI_memblock *cullstates;
diff --git a/source/blender/gpu/intern/gpu_viewport.c b/source/blender/gpu/intern/gpu_viewport.c
index c3aa633e706..2571caf7f4b 100644
--- a/source/blender/gpu/intern/gpu_viewport.c
+++ b/source/blender/gpu/intern/gpu_viewport.c
@@ -624,9 +624,6 @@ void GPU_viewport_free(GPUViewport *viewport)
if (viewport->vmempool.calls != NULL) {
BLI_memblock_destroy(viewport->vmempool.calls, NULL);
}
- if (viewport->vmempool.states != NULL) {
- BLI_memblock_destroy(viewport->vmempool.states, NULL);
- }
if (viewport->vmempool.obmats != NULL) {
BLI_memblock_destroy(viewport->vmempool.obmats, NULL);
}