$darkmode
Suckless OGL 1.0.0
A lean, high-performance C11 PBR Renderer
ibl_coordinator.c File Reference

Implementation of the IBL generation state machine. More...

#include "ibl_coordinator.h"
#include "app_settings.h"
#include "log.h"
#include "pbr.h"
#include "utils.h"
#include <float.h>
#include <math.h>
#include <string.h>
Include dependency graph for ibl_coordinator.c:

Functions

static bool is_software_renderer (void)
 
static int ibl_irradiance_slices (void)
 
static int ibl_specular_mip0_slices (void)
 
static int ibl_specular_mip1_slices (void)
 
static int ibl_specular_mips_grouping_start (void)
 
static void ibl_stats_reset (IBLCoordinator *ctx)
 Reset stage timing statistics for a new IBL stage. More...
 
static void ibl_stats_accumulate (IBLCoordinator *ctx, double gpu_ms)
 Accumulate a slice's GPU timing into the stage statistics. More...
 
static void ibl_stats_log_summary (IBLCoordinator *ctx, uint64_t frame, const char *stage_name)
 Log a single INFO summary line for a completed IBL stage. More...
 
void ibl_coordinator_init (IBLCoordinator *coord, GLuint shader_spmap, GLuint shader_irmap, GLuint shader_lum_pass1, GLuint shader_lum_pass2)
 Initializes the IBL coordinator with necessary shader resources. More...
 
void ibl_coordinator_cleanup (IBLCoordinator *coord)
 Cleanups any pending resources held by the coordinator. More...
 
void ibl_coordinator_reset (IBLCoordinator *coord)
 Resets the coordinator to IDLE state. More...
 
void ibl_coordinator_start (IBLCoordinator *coord, GLuint hdr_tex, int width, int height)
 Starts the IBL generation process for a new HDR texture. More...
 
static IBLState process_luminance (IBLCoordinator *coord, unsigned long long frame)
 
static IBLState process_luminance_wait (IBLCoordinator *coord, unsigned long long frame)
 
static IBLState process_specular_init (IBLCoordinator *coord, unsigned long long frame)
 
static IBLState process_specular_mips (IBLCoordinator *coord, unsigned long long frame)
 
static IBLState process_irradiance (IBLCoordinator *coord, unsigned long long frame)
 
IBLState ibl_coordinator_update (IBLCoordinator *coord, uint64_t frame_count)
 Advances the state machine by one step (slice or pass). More...
 
int ibl_coordinator_get_results (IBLCoordinator *coord, GLuint *out_hdr_tex, GLuint *out_spec_tex, GLuint *out_irr_tex, float *out_threshold)
 Retrieves the results of the IBL generation. More...
 

Variables

static const int IBL_SOFTWARE_FALLBACK_SLICES = 1
 Default slice count for software renderers (no slicing). Slicing is disabled to avoid the massive overhead of multiple draw calls on CPU-bound renderers (llvmpipe, etc.). More...
 
static const int IBL_IRRADIANCE_HARDWARE_SLICES = 12
 Number of slices for irradiance convolution on hardware (GPU). More...
 
static const int IBL_SPECULAR_MIP0_HARDWARE_SLICES = 24
 Number of slices for the largest specular mip (Mip 0) on hardware. More...
 
static const int IBL_SPECULAR_MIP1_HARDWARE_SLICES = 8
 Number of slices for the second specular mip (Mip 1) on hardware. More...
 
static const int IBL_SPECULAR_MIP_GROUPING_START_MIP = 3
 Mip level from which specular mips are grouped in a single frame. More...
 
static const int IBL_SOFTWARE_MIP_GROUPING_START_MIP = 0
 Mip level for software grouping (all mips at once). More...
 
static const float IBL_THRESHOLD_FALLBACK_MIN = 1.0F
 
static const int IBL_LOG_LABEL_SIZE = 128
 

Detailed Description

Implementation of the IBL generation state machine.

Function Documentation

◆ ibl_coordinator_cleanup()

void ibl_coordinator_cleanup ( IBLCoordinator coord)

Cleanups any pending resources held by the coordinator.

Parameters
coordPointer to the coordinator instance.
Here is the call graph for this function:

◆ ibl_coordinator_get_results()

int ibl_coordinator_get_results ( IBLCoordinator coord,
GLuint *  out_hdr_tex,
GLuint *  out_spec_tex,
GLuint *  out_irr_tex,
float *  out_threshold 
)

Retrieves the results of the IBL generation.

Parameters
coordPointer to the coordinator instance.
out_hdr_texPointer to receive the HDR texture handle.
out_spec_texPointer to receive the specular texture handle.
out_irr_texPointer to receive the irradiance texture handle.
out_thresholdPointer to receive the computed luminance threshold.
Returns
1 if results were retrieved (state was DONE), 0 otherwise.

◆ ibl_coordinator_init()

void ibl_coordinator_init ( IBLCoordinator coord,
GLuint  shader_spmap,
GLuint  shader_irmap,
GLuint  shader_lum_pass1,
GLuint  shader_lum_pass2 
)

Initializes the IBL coordinator with necessary shader resources.

Parameters
coordPointer to the coordinator instance.
shader_spmapHandle to the specular pre-filter shader.
shader_irmapHandle to the irradiance convolution shader.
shader_lum_pass1Handle to luminance pass 1 shader.
shader_lum_pass2Handle to luminance pass 2 shader.
Here is the call graph for this function:

◆ ibl_coordinator_reset()

void ibl_coordinator_reset ( IBLCoordinator coord)

Resets the coordinator to IDLE state.

Parameters
coordPointer to the coordinator instance.

◆ ibl_coordinator_start()

void ibl_coordinator_start ( IBLCoordinator coord,
GLuint  hdr_tex,
int  width,
int  height 
)

Starts the IBL generation process for a new HDR texture.

Parameters
coordPointer to the coordinator instance.
hdr_texHandle to the source HDR texture (must be valid).
widthWidth of the HDR texture.
heightHeight of the HDR texture.
Here is the call graph for this function:

◆ ibl_coordinator_update()

IBLState ibl_coordinator_update ( IBLCoordinator coord,
uint64_t  frame_count 
)

Advances the state machine by one step (slice or pass).

Parameters
coordPointer to the coordinator instance.
frame_countCurrent frame number (for logging purposes).
Returns
IBLState The new state after the update.
Here is the call graph for this function:

◆ ibl_irradiance_slices()

static int ibl_irradiance_slices ( void  )
static
Here is the call graph for this function:

◆ ibl_specular_mip0_slices()

static int ibl_specular_mip0_slices ( void  )
static
Here is the call graph for this function:

◆ ibl_specular_mip1_slices()

static int ibl_specular_mip1_slices ( void  )
static
Here is the call graph for this function:

◆ ibl_specular_mips_grouping_start()

static int ibl_specular_mips_grouping_start ( void  )
static
Here is the call graph for this function:

◆ ibl_stats_accumulate()

static void ibl_stats_accumulate ( IBLCoordinator ctx,
double  gpu_ms 
)
static

Accumulate a slice's GPU timing into the stage statistics.

◆ ibl_stats_log_summary()

static void ibl_stats_log_summary ( IBLCoordinator ctx,
uint64_t  frame,
const char *  stage_name 
)
static

Log a single INFO summary line for a completed IBL stage.

Here is the call graph for this function:

◆ ibl_stats_reset()

static void ibl_stats_reset ( IBLCoordinator ctx)
static

Reset stage timing statistics for a new IBL stage.

Here is the call graph for this function:

◆ is_software_renderer()

static bool is_software_renderer ( void  )
static

◆ process_irradiance()

static IBLState process_irradiance ( IBLCoordinator coord,
unsigned long long  frame 
)
static
Here is the call graph for this function:

◆ process_luminance()

static IBLState process_luminance ( IBLCoordinator coord,
unsigned long long  frame 
)
static
Here is the call graph for this function:

◆ process_luminance_wait()

static IBLState process_luminance_wait ( IBLCoordinator coord,
unsigned long long  frame 
)
static
Here is the call graph for this function:

◆ process_specular_init()

static IBLState process_specular_init ( IBLCoordinator coord,
unsigned long long  frame 
)
static
Here is the call graph for this function:

◆ process_specular_mips()

static IBLState process_specular_mips ( IBLCoordinator coord,
unsigned long long  frame 
)
static
Here is the call graph for this function:

Variable Documentation

◆ IBL_IRRADIANCE_HARDWARE_SLICES

const int IBL_IRRADIANCE_HARDWARE_SLICES = 12
static

Number of slices for irradiance convolution on hardware (GPU).

◆ IBL_LOG_LABEL_SIZE

const int IBL_LOG_LABEL_SIZE = 128
static

◆ IBL_SOFTWARE_FALLBACK_SLICES

const int IBL_SOFTWARE_FALLBACK_SLICES = 1
static

Default slice count for software renderers (no slicing). Slicing is disabled to avoid the massive overhead of multiple draw calls on CPU-bound renderers (llvmpipe, etc.).

◆ IBL_SOFTWARE_MIP_GROUPING_START_MIP

const int IBL_SOFTWARE_MIP_GROUPING_START_MIP = 0
static

Mip level for software grouping (all mips at once).

◆ IBL_SPECULAR_MIP0_HARDWARE_SLICES

const int IBL_SPECULAR_MIP0_HARDWARE_SLICES = 24
static

Number of slices for the largest specular mip (Mip 0) on hardware.

◆ IBL_SPECULAR_MIP1_HARDWARE_SLICES

const int IBL_SPECULAR_MIP1_HARDWARE_SLICES = 8
static

Number of slices for the second specular mip (Mip 1) on hardware.

◆ IBL_SPECULAR_MIP_GROUPING_START_MIP

const int IBL_SPECULAR_MIP_GROUPING_START_MIP = 3
static

Mip level from which specular mips are grouped in a single frame.

◆ IBL_THRESHOLD_FALLBACK_MIN

const float IBL_THRESHOLD_FALLBACK_MIN = 1.0F
static