commit cce41b7e434d14c0513926a99640110dfd00f61c
parent 67ded6763e5e2bc346b68c8d65956a6332a9078e
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 23 Aug 2022 12:31:54 +0200
Still preparing building multiple octrees
Diffstat:
3 files changed, 30 insertions(+), 11 deletions(-)
diff --git a/src/rnatm_octree.c b/src/rnatm_octree.c
@@ -224,7 +224,8 @@ compute_nquad_pts(const struct rnatm* atm, const size_t bands[2])
nbands = bands[1] - bands[0] + 1;
FOR_EACH(i, 0, nbands) {
struct sck_band band;
- SCK(get_band(atm->gas.ck, bands[i], &band));
+ const size_t iband = bands[0] + i;
+ SCK(get_band(atm->gas.ck, iband, &band));
nquad_pts += band.quad_pts_count;
}
return nquad_pts;
@@ -258,7 +259,7 @@ setup_accel_structs
nbands = bands[1] - bands[0] + 1;
FOR_EACH(i, 0, nbands) {
struct sck_band band;
- const size_t iband = bands[i];
+ const size_t iband = bands[0] + i;
size_t iquad_pt;
SCK(get_band(atm->gas.ck, iband, &band));
@@ -562,6 +563,8 @@ voxelize_batch(struct rnatm* atm, const struct voxelize_batch_args* args)
ATOMIC res = RES_OK;
ASSERT(atm && check_voxelize_batch_args(atm, args) == RES_OK);
+ pool_reset(args->pool);
+
/* Print status message */
#define LOG_MSG "voxelize atmosphere: %3d%%\r"
log_info(atm, LOG_MSG, 0);
@@ -630,7 +633,7 @@ voxelize_batch(struct rnatm* atm, const struct voxelize_batch_args* args)
voxelize_args.batch_size = args->batch_size;
res_local = voxelize_partition(atm, &voxelize_args);
if(res_local == RES_OK) {
- partition_commit(part);
+ partition_commit(part, args->batch_size);
} else {
partition_free(part);
ATOMIC_SET(&res, res_local);
diff --git a/src/rnatm_voxel_partition.c b/src/rnatm_voxel_partition.c
@@ -43,10 +43,9 @@ struct partition {
struct tile* tile; /* Set of voxels */
struct pool* pool;
- /* Number of references on the partition. When the partition is commited, its
- * reference count is set to the width of the voxel. Once fetched, a
- * reference is given to the caller that it releases by calling
- * partition_free */
+ /* Number of references on the partition. Its initial value is set when the
+ * partition is commited. Once fetched, a reference is given to the caller
+ * that it then released by calling partition_free */
ATOMIC ref;
};
@@ -286,16 +285,17 @@ partition_empty(struct partition* partition)
}
void
-partition_commit(struct partition* partition)
+partition_commit(struct partition* partition, const size_t refs_count)
{
struct list_node* node = NULL;
struct pool* pool = NULL;
ASSERT(partition);
+ ASSERT(refs_count && refs_count <= partition->pool->voxel_width);
pool = partition->pool;
/* Setup the number of partition references */
- partition->ref = (ATOMIC)partition->pool->voxel_width;
+ partition->ref = (ATOMIC)refs_count;
/* Committed partitions are sorted in ascending order of their id. We are
* therefore looking for the partition whose id is less than the id of the
@@ -563,3 +563,12 @@ pool_invalidate(struct pool* pool)
cond_broadcast(pool->cond_fetch);
cond_broadcast(pool->cond_tile);
}
+
+void
+pool_reset(struct pool* pool)
+{
+ ASSERT(pool);
+ mutex_lock(pool->mutex);
+ pool->next_part_id = 0;
+ mutex_unlock(pool->mutex);
+}
diff --git a/src/rnatm_voxel_partition.h b/src/rnatm_voxel_partition.h
@@ -50,10 +50,12 @@ extern LOCAL_SYM void
partition_free
(struct partition* partition);
-/* Commit the partitition, i.e. it can be fetched from the pool */
+/* Commit the partitition, i.e. it can be fetched from the pool up to N times
+ * where N is defined by ref_count */
extern LOCAL_SYM void
partition_commit
- (struct partition* partition);
+ (struct partition* partition,
+ const size_t ref_count);
extern LOCAL_SYM size_t
partition_get_id
@@ -134,4 +136,9 @@ extern LOCAL_SYM void
pool_invalidate
(struct pool* pool);
+/* Reset the next partition to fetch to 0 */
+extern LOCAL_SYM void
+pool_reset
+ (struct pool* pool);
+
#endif /* RNATM_VOXEL_PARTITION_H */