commit 5cd319ac4579a25a88a8dc4b3d0c86e892602e23
parent bddd7fdd86dfbbeb73ef43b974ef6384538ce0ff
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 17 Apr 2019 11:15:32 +0200
Clean up the way the pixel memory layout is defined
Diffstat:
3 files changed, 42 insertions(+), 28 deletions(-)
diff --git a/src/htrdr.c b/src/htrdr.c
@@ -113,12 +113,12 @@ dump_accum_buffer
(void)stream_name;
htrdr_buffer_get_layout(buf, &layout);
- if(layout.elmt_size != sizeof(struct htrdr_accum[4])/*#channels*/
- || layout.alignment < ALIGNOF(struct htrdr_accum[4])) {
+ if(layout.elmt_size != sizeof(struct htrdr_accum[HTRDR_ESTIMATES_COUNT__])
+ || layout.alignment < ALIGNOF(struct htrdr_accum[HTRDR_ESTIMATES_COUNT__])) {
htrdr_log_err(htrdr,
"%s: invalid buffer layout. "
- "The pixel size must be the size of 4 accumulators.\n",
- FUNC_NAME);
+ "The pixel size must be the size of %lu accumulators.\n",
+ FUNC_NAME, (unsigned long)HTRDR_ESTIMATES_COUNT__);
res = RES_BAD_ARG;
goto error;
}
@@ -130,16 +130,16 @@ dump_accum_buffer
FOR_EACH(x, 0, layout.width) {
const struct htrdr_accum* accums = htrdr_buffer_at(buf, x, y);
int i;
- FOR_EACH(i, 0, 4) {
+ FOR_EACH(i, 0, HTRDR_ESTIMATES_COUNT__) {
double E, SE;
htrdr_accum_get_estimation(&accums[i], &E, &SE);
fprintf(stream, "%g %g ", E, SE);
}
if(time_acc) {
- time_acc->sum_weights += accums[3].sum_weights;
- time_acc->sum_weights_sqr += accums[3].sum_weights_sqr;
- time_acc->nweights += accums[3].nweights;
+ time_acc->sum_weights += accums[HTRDR_ESTIMATE_TIME].sum_weights;
+ time_acc->sum_weights_sqr += accums[HTRDR_ESTIMATE_TIME].sum_weights_sqr;
+ time_acc->nweights += accums[HTRDR_ESTIMATE_TIME].nweights;
}
fprintf(stream, "\n");
}
@@ -529,8 +529,8 @@ htrdr_init
* rendered by the processes are gathered onto the master process. */
if(!htrdr->dump_vtk && htrdr->mpi_rank == 0) {
/* 4 accums: X, Y, Z components and one more for the per realisation time */
- const size_t pixsz = sizeof(struct htrdr_accum[4]);
- const size_t pixal = ALIGNOF(struct htrdr_accum[4]);
+ const size_t pixsz = sizeof(struct htrdr_accum[HTRDR_ESTIMATES_COUNT__]);
+ const size_t pixal = ALIGNOF(struct htrdr_accum[HTRDR_ESTIMATES_COUNT__]);
res = htrdr_buffer_create(htrdr,
args->image.definition[0], /* Width */
args->image.definition[1], /* Height */
diff --git a/src/htrdr_c.h b/src/htrdr_c.h
@@ -32,6 +32,14 @@ enum htrdr_mpi_message {
HTRDR_MPI_TILE_DATA
};
+enum htrdr_estimate {
+ HTRDR_ESTIMATE_X,
+ HTRDR_ESTIMATE_Y,
+ HTRDR_ESTIMATE_Z,
+ HTRDR_ESTIMATE_TIME, /* Time per realisation */
+ HTRDR_ESTIMATES_COUNT__
+};
+
struct htrdr;
#define SW_WAVELENGTH_MIN 380 /* In nanometer */
diff --git a/src/htrdr_draw_radiance_sw.c b/src/htrdr_draw_radiance_sw.c
@@ -92,7 +92,7 @@ tile_create(struct mem_allocator* allocator)
const size_t tile_sz =
sizeof(struct tile) - sizeof(struct htrdr_accum)/*rm dummy accum*/;
const size_t buf_sz = /* Flexiblbe array element */
- TILE_SIZE*TILE_SIZE*sizeof(struct htrdr_accum[4/*#channels*/]);
+ TILE_SIZE*TILE_SIZE*sizeof(struct htrdr_accum[HTRDR_ESTIMATES_COUNT__]);
ASSERT(allocator);
tile = MEM_ALLOC(allocator, tile_sz+buf_sz);
@@ -135,7 +135,7 @@ tile_at
const size_t y) /* In tile space */
{
ASSERT(tile && x < TILE_SIZE && y < TILE_SIZE);
- return tile->data.accums + (y*TILE_SIZE + x)*4/*#channels*/;
+ return tile->data.accums + (y*TILE_SIZE + x) * HTRDR_ESTIMATES_COUNT__;
}
static void
@@ -150,8 +150,7 @@ write_tile_data(struct htrdr_buffer* buf, const struct tile_data* tile_data)
htrdr_buffer_get_layout(buf, &layout);
buf_mem = htrdr_buffer_get_data(buf);
- ASSERT(layout.elmt_size == sizeof(struct htrdr_accum[4]));
-
+ ASSERT(layout.elmt_size == sizeof(struct htrdr_accum[HTRDR_ESTIMATES_COUNT__]));
/* Compute the row/column of the tile origin into the buffer */
icol = tile_data->x * (size_t)TILE_SIZE;
@@ -165,9 +164,9 @@ write_tile_data(struct htrdr_buffer* buf, const struct tile_data* tile_data)
FOR_EACH(irow_tile, 0, nrows_tile) {
char* buf_row = buf_mem + (irow + irow_tile) * layout.pitch;
const struct htrdr_accum* tile_row =
- tile_data->accums + irow_tile*TILE_SIZE*4/*#channels*/;
- memcpy(buf_row + icol*sizeof(struct htrdr_accum[4/*#channels*/]), tile_row,
- ncols_tile*sizeof(struct htrdr_accum[4/*#channels*/]));
+ tile_data->accums + irow_tile*TILE_SIZE*HTRDR_ESTIMATES_COUNT__;
+ memcpy(buf_row + icol*sizeof(struct htrdr_accum[HTRDR_ESTIMATES_COUNT__]),
+ tile_row, ncols_tile*sizeof(struct htrdr_accum[HTRDR_ESTIMATES_COUNT__]));
}
}
@@ -393,7 +392,7 @@ mpi_gather_tiles
/* Compute the size of the tile_data */
const size_t msg_sz =
sizeof(struct tile_data) - sizeof(struct htrdr_accum)/*dummy*/
- + TILE_SIZE*TILE_SIZE*sizeof(struct htrdr_accum[4/*#channels*/]);
+ + TILE_SIZE*TILE_SIZE*sizeof(struct htrdr_accum[HTRDR_ESTIMATES_COUNT__]);
struct list_node* node = NULL;
struct tile* tile = NULL;
@@ -482,16 +481,23 @@ draw_tile
/* Fetch and reset the pixel accumulator */
pix_accums = tile_at(tile, ipix_tile[0], ipix_tile[1]);
- pix_accums[3] = HTRDR_ACCUM_NULL; /* Reset time per radiative path */
-
+ pix_accums[HTRDR_ESTIMATE_TIME] = HTRDR_ACCUM_NULL; /* Reset time per radiative path */
+
/* Compute the pixel coordinate */
ipix[0] = tile_org[0] + ipix_tile[0];
ipix[1] = tile_org[1] + ipix_tile[1];
FOR_EACH(ichannel, 0, 3) {
+ /* Check that the X, Y and Z estimates are stored in accumulators 0, 1 et
+ * 2, respectively */
+ STATIC_ASSERT
+ ( HTRDR_ESTIMATE_X == 0
+ && HTRDR_ESTIMATE_Y == 1
+ && HTRDR_ESTIMATE_Z == 2,
+ Unexpected_htrdr_estimate_enumerate);
size_t isamp;
- pix_accums[ichannel] = HTRDR_ACCUM_NULL;
+ pix_accums[ichannel] = HTRDR_ACCUM_NULL;
FOR_EACH(isamp, 0, spp) {
struct time t0, t1;
double pix_samp[2];
@@ -541,9 +547,9 @@ draw_tile
pix_accums[ichannel].nweights += 1;
/* Update the pixel accumulator of per realisation time */
- pix_accums[3].sum_weights += usec;
- pix_accums[3].sum_weights_sqr += usec*usec;
- pix_accums[3].nweights += 1;
+ pix_accums[HTRDR_ESTIMATE_TIME].sum_weights += usec;
+ pix_accums[HTRDR_ESTIMATE_TIME].sum_weights_sqr += usec*usec;
+ pix_accums[HTRDR_ESTIMATE_TIME].nweights += 1;
}
}
}
@@ -737,12 +743,12 @@ htrdr_draw_radiance_sw
ASSERT(layout.width || layout.height || layout.elmt_size);
ASSERT(layout.width == width && layout.height == height);
- if(layout.elmt_size != sizeof(struct htrdr_accum[4])/*#channels*/
- || layout.alignment < ALIGNOF(struct htrdr_accum[4])) {
+ if(layout.elmt_size != sizeof(struct htrdr_accum[HTRDR_ESTIMATES_COUNT__])
+ || layout.alignment < ALIGNOF(struct htrdr_accum[HTRDR_ESTIMATES_COUNT__])) {
htrdr_log_err(htrdr,
"%s: invalid buffer layout. "
- "The pixel size must be the size of 4 accumulators.\n",
- FUNC_NAME);
+ "The pixel size must be the size of %lu accumulators.\n",
+ FUNC_NAME, (unsigned long)HTRDR_ESTIMATES_COUNT__);
res = RES_BAD_ARG;
goto error;
}