commit 56b6f2b61cf556c1719af160f91071cd67863ac4
parent c0fa813813cb5c34128e99991b8f2a7b60fe688f
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 24 Mar 2021 18:35:44 +0100
Pre-allocate per thread RDG-FA phase functions in the combustion command
Diffstat:
2 files changed, 72 insertions(+), 0 deletions(-)
diff --git a/src/combustion/htrdr_combustion.c b/src/combustion/htrdr_combustion.c
@@ -29,12 +29,33 @@
#include <astoria/atrstm.h>
+#include <star/ssf.h>
+
#include <rsys/cstr.h>
#include <rsys/mem_allocator.h>
/*******************************************************************************
* Helper functions
******************************************************************************/
+static void
+release_rdgfa(struct htrdr_combustion* cmd)
+{
+ size_t i;
+ ASSERT(cmd);
+
+ if(!cmd->rdgfa_phase_functions) return; /* Nothing to release */
+
+
+ FOR_EACH(i, 0, htrdr_get_threads_count(cmd->htrdr)) {
+ if(cmd->rdgfa_phase_functions[i]) {
+ SSF(phase_ref_put(cmd->rdgfa_phase_functions[i]));
+ }
+ }
+
+ MEM_RM(htrdr_get_allocator(cmd->htrdr), cmd->rdgfa_phase_functions);
+ cmd->rdgfa_phase_functions = NULL;
+}
+
static res_T
setup_output
(struct htrdr_combustion* cmd,
@@ -145,6 +166,50 @@ setup_laser
}
static res_T
+setup_rdgfa
+ (struct htrdr_combustion* cmd,
+ const struct htrdr_combustion_args* args)
+{
+ struct mem_allocator* allocator = NULL;
+ size_t nthreads;
+ size_t i;
+ res_T res = RES_OK;
+ ASSERT(cmd);
+ (void)args; /* Not use */
+
+ nthreads = htrdr_get_threads_count(cmd->htrdr);
+ allocator = htrdr_get_allocator(cmd->htrdr);
+
+ /* Allocate the list of per thread RDG-FA */
+ cmd->rdgfa_phase_functions = MEM_CALLOC
+ (allocator, nthreads, sizeof(*cmd->rdgfa_phase_functions));
+ if(!cmd->rdgfa_phase_functions) {
+ htrdr_log_err(cmd->htrdr,
+ "Could not allocate the per thread RDG-FA phase function.\n");
+ res = RES_MEM_ERR;
+ goto error;
+ }
+
+ /* Create the per thread RDG-FA */
+ FOR_EACH(i, 0, nthreads) {
+ res = ssf_phase_create
+ (allocator, &ssf_phase_rdgfa, cmd->rdgfa_phase_functions + i);
+ if(res != RES_OK) {
+ htrdr_log_err(cmd->htrdr,
+ "Could not create the RDG-FA phase function for the thread %lu -- %s.\n",
+ (unsigned long)i, res_to_cstr(res));
+ goto error;
+ }
+ }
+
+exit:
+ return res;
+error:
+ release_rdgfa(cmd);
+ goto exit;
+}
+
+static res_T
setup_buffer
(struct htrdr_combustion* cmd,
const struct htrdr_combustion_args* args)
@@ -267,6 +332,7 @@ combustion_release(ref_T* ref)
if(cmd->laser) htrdr_combustion_laser_ref_put(cmd->laser);
if(cmd->buf) htrdr_buffer_ref_put(cmd->buf);
if(cmd->output && cmd->output != stdout) CHK(fclose(cmd->output) == 0);
+ release_rdgfa(cmd);
str_release(&cmd->output_name);
htrdr = cmd->htrdr;
@@ -312,6 +378,8 @@ htrdr_combustion_create
if(res != RES_OK) goto error;
res = setup_laser(cmd, args);
if(res != RES_OK) goto error;
+ res = setup_rdgfa(cmd, args);
+ if(res != RES_OK) goto error;
res = setup_buffer(cmd, args);
if(res != RES_OK) goto error;
res = setup_medium(cmd, args);
diff --git a/src/combustion/htrdr_combustion_c.h b/src/combustion/htrdr_combustion_c.h
@@ -33,6 +33,7 @@ struct htrdr_combustion_laser;
struct htrdr_geometry;
struct htrdr_materials;
struct htrdr_rectangle;
+struct ssf_phase;
struct ssp_rng;
struct combustion_pixel {
@@ -55,6 +56,8 @@ struct htrdr_combustion {
struct htrdr_combustion_laser* laser; /* Laser sheet */
double wavelength; /* Wavelength of the laser in nanometer */
+ struct ssf_phase** rdgfa_phase_functions; /* Per thread RDG-FA phase func */
+
struct htrdr_buffer_layout buf_layout;
struct htrdr_buffer* buf; /* NULL on non master processes */
size_t spp; /* #samples per pixel */
@@ -63,6 +66,7 @@ struct htrdr_combustion {
struct str output_name; /* Name of the output stream */
int dump_volumetric_acceleration_structure;
+
ref_T ref;
struct htrdr* htrdr;
};