$darkmode
Suckless OGL 1.0.0
A lean, high-performance C11 PBR Renderer
async_loader.c File Reference
#include "async_loader.h"
#include "log.h"
#include "perf_timer.h"
#include "profiler.h"
#include "simd_utils.h"
#include "texture.h"
#include "tracy_manager.h"
#include "utils.h"
#include <pthread.h>
#include <stb_image.h>
#include <stdbool.h>
#include <string.h>
Include dependency graph for async_loader.c:

Data Structures

struct  AsyncLoader
 Opaque handle to the asynchronous loader context. More...
 

Macros

#define transition_tracy_state(s)    tracy_manager_async_transition(loader->tracy_mgr, s)
 
#define cleanup_tracy_states()   tracy_manager_async_end(loader->tracy_mgr)
 

Enumerations

enum  { MSG_BUF_SIZE = 128 }
 

Functions

static bool async_load_data (const char *path, float **out_data, int *width, int *height, int *channels)
 
static void async_perform_conversion (AsyncLoader *loader)
 
static void async_handle_io (AsyncLoader *loader, char *path_to_load)
 
static void * async_worker_func (void *arg)
 
AsyncLoaderasync_loader_create (struct TracyManager *mgr)
 Creates and initializes a new async loader instance. More...
 
void async_loader_destroy (AsyncLoader *loader)
 Destroys the async loader and frees resources. More...
 
bool async_loader_request (AsyncLoader *loader, const char *path)
 Submits a new file path for background loading. More...
 
bool async_loader_poll (AsyncLoader *loader, AsyncRequest *out_req)
 Polls the loader for any completed requests. More...
 
void async_loader_provide_pbo (AsyncLoader *loader, void *mapped_ptr, GLuint pbo_id)
 Provides a mapped PBO pointer to the async loader for conversion. More...
 
void async_loader_cancel (AsyncLoader *loader)
 Cancels the current request if it is waiting for a PBO. More...
 

Macro Definition Documentation

◆ cleanup_tracy_states

#define cleanup_tracy_states ( )    tracy_manager_async_end(loader->tracy_mgr)

◆ transition_tracy_state

#define transition_tracy_state (   s)     tracy_manager_async_transition(loader->tracy_mgr, s)

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
MSG_BUF_SIZE 

Function Documentation

◆ async_handle_io()

static void async_handle_io ( AsyncLoader loader,
char *  path_to_load 
)
static
Here is the call graph for this function:

◆ async_load_data()

static bool async_load_data ( const char *  path,
float **  out_data,
int *  width,
int *  height,
int *  channels 
)
static
Here is the call graph for this function:

◆ async_loader_cancel()

void async_loader_cancel ( AsyncLoader loader)

Cancels the current request if it is waiting for a PBO.

Use this if the main thread fails to map a PBO and cannot proceed.

Parameters
loaderThe loader instance.

◆ async_loader_create()

AsyncLoader* async_loader_create ( struct TracyManager mgr)

Creates and initializes a new async loader instance.

Parameters
mgrThe Tracy instrumentation manager.
Returns
Pointer to the new loader, or NULL on failure.
Here is the call graph for this function:

◆ async_loader_destroy()

void async_loader_destroy ( AsyncLoader loader)

Destroys the async loader and frees resources.

Parameters
loaderThe loader instance to destroy.

◆ async_loader_poll()

bool async_loader_poll ( AsyncLoader loader,
AsyncRequest out_req 
)

Polls the loader for any completed requests.

This should be called from the main (OpenGL) thread once per frame.

Parameters
loaderThe loader instance.
[out]out_reqPointer to store the successfully loaded data.
Returns
true if data was retrieved, false otherwise.

◆ async_loader_provide_pbo()

void async_loader_provide_pbo ( AsyncLoader loader,
void *  mapped_ptr,
GLuint  pbo_id 
)

Provides a mapped PBO pointer to the async loader for conversion.

Call this when async_loader_poll returns a request in ASYNC_WAITING_FOR_PBO state.

Parameters
loaderThe loader instance.
mapped_ptrPointer to the mapped PBO memory.
pbo_idID of the PBO being used.

◆ async_loader_request()

bool async_loader_request ( AsyncLoader loader,
const char *  path 
)

Submits a new file path for background loading.

Parameters
loaderThe loader instance.
pathThe absolute path to the HDR/texture file.
Returns
true if the request was successfully queued, false if queue is full.
Here is the call graph for this function:

◆ async_perform_conversion()

static void async_perform_conversion ( AsyncLoader loader)
static
Here is the call graph for this function:

◆ async_worker_func()

static void* async_worker_func ( void *  arg)
static
Here is the call graph for this function: