Suckless OGL 1.0.0
A lean, high-performance C11 PBR Renderer
Loading...
Searching...
No Matches
adaptive_sampler.h
Go to the documentation of this file.
1
9#ifndef ADAPTIVE_SAMPLER_H
10#define ADAPTIVE_SAMPLER_H
11
12#include <stddef.h> // size_t
13#include <stdint.h> // uint64_t
14
19typedef struct {
20 float timestamp;
21 float value;
22 uint64_t frame_index;
24
29typedef struct {
30 uint64_t state;
31 uint64_t inc;
32} Pcg32;
33
38typedef struct {
39 /* RNG State */
41
42 /* Configuration */
43 float
48 /* State */
54 float avg_dt;
55 float alpha;
57 /* Buffer (Dynamic) */
59 size_t capacity;
60 size_t count;
63
71void adaptive_sampler_add(AdaptiveSampler* sampler, float value,
72 uint64_t frame_index);
73
81void adaptive_sampler_init(AdaptiveSampler* sampler, float window_duration,
82 size_t target_samples, float initial_fps_guess);
83
93int adaptive_sampler_should_sample(AdaptiveSampler* sampler, float delta_time,
94 double current_time, uint64_t frame_index);
95
103 double current_time);
104
111
118
126 uint64_t* start_frame,
127 uint64_t* end_frame);
128
137 uint64_t* out_indices,
138 size_t max_count);
139
145void adaptive_sampler_reset(AdaptiveSampler* sampler, double current_time);
146
152
153#endif /* ADAPTIVE_SAMPLER_H */
size_t adaptive_sampler_get_sample_count(const AdaptiveSampler *sampler)
Returns the number of samples currently in the buffer.
Definition adaptive_sampler.c:251
void adaptive_sampler_cleanup(AdaptiveSampler *sampler)
Frees all dynamic memory associated with the sampler.
Definition adaptive_sampler.c:291
void adaptive_sampler_init(AdaptiveSampler *sampler, float window_duration, size_t target_samples, float initial_fps_guess)
Initializes the adaptive sampler.
Definition adaptive_sampler.c:51
void adaptive_sampler_get_window_range(const AdaptiveSampler *sampler, uint64_t *start_frame, uint64_t *end_frame)
Retrieves the frame index range covered by the current window.
Definition adaptive_sampler.c:256
void adaptive_sampler_reset(AdaptiveSampler *sampler, double current_time)
Resets the sampler state for a new window.
Definition adaptive_sampler.c:89
size_t adaptive_sampler_get_sample_indices(const AdaptiveSampler *sampler, uint64_t *out_indices, size_t max_count)
Retrieves the list of frame indices for all collected samples.
Definition adaptive_sampler.c:271
int adaptive_sampler_is_finished(const AdaptiveSampler *sampler, double current_time)
Checks if the current sampling window has concluded.
Definition adaptive_sampler.c:229
void adaptive_sampler_add(AdaptiveSampler *sampler, float value, uint64_t frame_index)
Manually adds a sample to the sampler (e.g. from external source like GPU profiler).
Definition adaptive_sampler.c:190
float adaptive_sampler_get_average(const AdaptiveSampler *sampler)
Calculates the arithmetic mean of all samples in the current window.
Definition adaptive_sampler.c:239
int adaptive_sampler_should_sample(AdaptiveSampler *sampler, float delta_time, double current_time, uint64_t frame_index)
Determines if a sample should be taken this frame based on probability.
Definition adaptive_sampler.c:99
Represents a single data point in the sampler.
Definition adaptive_sampler.h:19
float value
Definition adaptive_sampler.h:21
float timestamp
Definition adaptive_sampler.h:20
uint64_t frame_index
Definition adaptive_sampler.h:22
Collector for performance samples within a rolling or fixed window.
Definition adaptive_sampler.h:38
double window_start_time
Definition adaptive_sampler.h:50
size_t capacity
Definition adaptive_sampler.h:59
uint64_t window_start_frame
Definition adaptive_sampler.h:52
uint64_t window_end_frame
Definition adaptive_sampler.h:53
Pcg32 rng
Definition adaptive_sampler.h:40
size_t target_samples
Definition adaptive_sampler.h:45
AdaptiveSampleItem * samples
Definition adaptive_sampler.h:58
size_t count
Definition adaptive_sampler.h:60
size_t samples_taken
Definition adaptive_sampler.h:49
float window_duration
Definition adaptive_sampler.h:44
float alpha
Definition adaptive_sampler.h:55
float avg_dt
Definition adaptive_sampler.h:54
State for a Permuted Congruential Generator (PCG) RNG.
Definition adaptive_sampler.h:29
uint64_t inc
Definition adaptive_sampler.h:31
uint64_t state
Definition adaptive_sampler.h:30