commit 20d16c1f590b9f43b8ace2f39a49c53b92336aaa
parent 2bb9edf0c7fbe273d57c69b48af7b4ef39f46ddf
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 21 Jul 2016 09:50:33 +0200
Update the memory layout of the scene geometry cache
The key of a cache entry is no more the shape but its client side
identifier.
Diffstat:
2 files changed, 33 insertions(+), 13 deletions(-)
diff --git a/src/s3d_scene.c b/src/s3d_scene.c
@@ -279,13 +279,15 @@ scene_register_mesh
struct geometry** pgeom = NULL;
struct geometry* geom = NULL;
size_t iattr;
+ unsigned shape_id;
char upd_pos, upd_ids;
res_T res = RES_OK;
ASSERT(shape && shape->type == GEOM_MESH);
/* Retrieve the cached geometry */
- pgeom = htable_geom_find(&scn->cached_geoms, &shape);
+ S3D(shape_get_id(shape, &shape_id));
+ pgeom = htable_geom_find(&scn->cached_geoms, &shape_id);
if(pgeom) {
geom = *pgeom;
} else {
@@ -294,7 +296,7 @@ scene_register_mesh
res = mesh_create(scn->dev, &geom->data.mesh);
if(res != RES_OK) goto error;
geom->type = GEOM_MESH;
- res = htable_geom_set(&scn->cached_geoms, &shape, &geom);
+ res = htable_geom_set(&scn->cached_geoms, &shape_id, &geom);
if(res != RES_OK) goto error;
geom->name = shape->id.index;
}
@@ -384,6 +386,7 @@ scene_register_instance
{
struct geometry** pgeom = NULL;
struct geometry* geom = NULL;
+ unsigned shape_id;
res_T res = RES_OK;
ASSERT(scn && shape && shape->type == GEOM_INSTANCE);
@@ -392,7 +395,8 @@ scene_register_instance
session_mask|S3D_INSTANCE);
if(res != RES_OK) goto error;
- pgeom = htable_geom_find(&scn->cached_geoms, &shape);
+ S3D(shape_get_id(shape, &shape_id));
+ pgeom = htable_geom_find(&scn->cached_geoms, &shape_id);
/* Create the scene instance of the geometry if necessary */
if(pgeom) {
geom = *pgeom;
@@ -402,7 +406,7 @@ scene_register_instance
geom->type = GEOM_INSTANCE;
res = instance_create(shape->data.instance->scene, &geom->data.instance);
if(res != RES_OK) goto error;
- res = htable_geom_set(&scn->cached_geoms, &shape, &geom);
+ res = htable_geom_set(&scn->cached_geoms, &shape_id, &geom);
if(res != RES_OK) goto error;
geom->name = shape->id.index;
}
@@ -447,12 +451,15 @@ scene_detach_shape
(struct s3d_scene* scn, struct s3d_shape* shape, const char* caller_name)
{
struct geometry** pgeom;
+ unsigned shape_id;
ASSERT(scn && shape && !is_list_empty(&shape->scene_attachment));
ASSERT(shape->type == GEOM_MESH || shape->type == GEOM_INSTANCE);
- pgeom = htable_geom_find(&scn->cached_geoms, &shape);
+ S3D(shape_get_id(shape, &shape_id));
+ pgeom = htable_geom_find(&scn->cached_geoms, &shape_id);
if(pgeom) { /* Remove the cached shape mesh */
struct geometry* geom = *pgeom;
+ size_t nerased; (void)nerased;
if(scn->session_mask != 0) {
log_error(scn->dev,
"%s: the shape is currently used in a scene session.\n", caller_name);
@@ -465,7 +472,8 @@ scene_detach_shape
scn->is_rtc_scn_outdated = 1;
}
geometry_ref_put(geom);
- htable_geom_erase(&scn->cached_geoms, &shape);
+ nerased = htable_geom_erase(&scn->cached_geoms, &shape_id);
+ ASSERT(nerased == 1);
}
list_del(&shape->scene_attachment);
@@ -493,8 +501,10 @@ scene_compute_cdf(struct s3d_scene* scn)
darray_fltui_clear(&scn->cdf);
LIST_FOR_EACH(node, &scn->shapes) {
+ unsigned shape_id;
shape = CONTAINER_OF(node, struct s3d_shape, scene_attachment);
- pgeom = htable_geom_find(&scn->cached_geoms, &shape);
+ S3D(shape_get_id(shape, &shape_id));
+ pgeom = htable_geom_find(&scn->cached_geoms, &shape_id);
ASSERT(pgeom != NULL);
geom = *pgeom;
struct fltui fltui;
@@ -549,8 +559,10 @@ scene_compute_aabb(struct s3d_scene* scn)
f3_splat(scn->upper,-FLT_MAX);
LIST_FOR_EACH(node, &scn->shapes) {
+ unsigned shape_id;
shape = CONTAINER_OF(node, struct s3d_shape, scene_attachment);
- pgeom = htable_geom_find(&scn->cached_geoms, &shape);
+ S3D(shape_get_id(shape, &shape_id));
+ pgeom = htable_geom_find(&scn->cached_geoms, &shape_id);
ASSERT(pgeom != NULL);
geom = *pgeom;
@@ -602,8 +614,10 @@ scene_compute_nprims_cdf
nprims = 0;
LIST_FOR_EACH(node, &scn->shapes) {
+ unsigned shape_id;
shape = CONTAINER_OF(node, struct s3d_shape, scene_attachment);
- pgeom = htable_geom_find(&scn->cached_geoms, &shape);
+ S3D(shape_get_id(shape, &shape_id));
+ pgeom = htable_geom_find(&scn->cached_geoms, &shape_id);
ASSERT(pgeom != NULL);
geom = *pgeom;
struct nprims_cdf cdf;
@@ -1261,8 +1275,10 @@ s3d_scene_primitives_count(struct s3d_scene* scn, size_t* prims_count)
size_t inst_count;
*prims_count = 0;
LIST_FOR_EACH(node, &scn->shapes) {
+ unsigned shape_id;
shape = CONTAINER_OF(node, struct s3d_shape, scene_attachment);
- pgeom = htable_geom_find(&scn->cached_geoms, &shape);
+ S3D(shape_get_id(shape, &shape_id));
+ pgeom = htable_geom_find(&scn->cached_geoms, &shape_id);
ASSERT(pgeom != NULL);
geom = *pgeom;
@@ -1322,8 +1338,10 @@ s3d_scene_compute_area(struct s3d_scene* scn, float* out_area)
area = 0.f;
LIST_FOR_EACH(node, &scn->shapes) {
+ unsigned shape_id;
shape = CONTAINER_OF(node, struct s3d_shape, scene_attachment);
- pgeom = htable_geom_find(&scn->cached_geoms, &shape);
+ S3D(shape_get_id(shape, &shape_id));
+ pgeom = htable_geom_find(&scn->cached_geoms, &shape_id);
ASSERT(pgeom != NULL);
geom = *pgeom;
@@ -1374,8 +1392,10 @@ s3d_scene_compute_volume(struct s3d_scene* scn, float* out_volume)
volume = 0.f;
LIST_FOR_EACH(node, &scn->shapes) {
+ unsigned shape_id;
shape = CONTAINER_OF(node, struct s3d_shape, scene_attachment);
- pgeom = htable_geom_find(&scn->cached_geoms, &shape);
+ S3D(shape_get_id(shape, &shape_id));
+ pgeom = htable_geom_find(&scn->cached_geoms, &shape_id);
ASSERT(pgeom != NULL);
geom = *pgeom;
diff --git a/src/s3d_scene_c.h b/src/s3d_scene_c.h
@@ -59,7 +59,7 @@ geom_ptr_init__(struct mem_allocator* alloc, struct geometry** geom)
/* Generate the htable_geom hash table */
#define HTABLE_NAME geom
#define HTABLE_DATA struct geometry*
-#define HTABLE_KEY struct s3d_shape*
+#define HTABLE_KEY unsigned /* Id of the shape */
#include <rsys/hash_table.h>
/* Generate the darray_fltui dynamic array */