Skip to content
modkitv0.2

shader.h

#include <modkit/shader.h>21 functions · 6 structs · 1 enums · 5 typedefs · 7 macros

Shader and uniform abstraction.

GPU shader programs and uniforms. Uses generational handles for use-after-free detection. For low-level GPU interop, include modkit.h for escape hatch accessors.

Functions

mk_shader_destroyfunction

void mk_shader_destroy(mk_shader_t shader)

Get underlying GPU program handle (escape hatch).

Requires modkit.h. Destroy shader and release resources.

ParameterTypeDescription
shadermk_shader_tValue for shader.

mk_shader_is_validfunction

bool mk_shader_is_valid(mk_shader_t shader)

Check if a shader is publicly valid and not pending destruction.

ParameterTypeDescription
shadermk_shader_tValue for shader.

Returns True when the condition holds.

mk_shader_loadfunction

mk_shader_t mk_shader_load(const char *vs_path, const char *fs_path)

Load shader program from binary files.

ParameterTypeDescription
vs_pathconst char *Path to vertex shader .bin file
fs_pathconst char *Path to fragment shader .bin file

Returns Shader handle or MK_SHADER_INVALID on failure

mk_shader_load_computefunction

mk_shader_t mk_shader_load_compute(const char *cs_path)

Load a COMPUTE program from a binary file.

A compute program is a single shader (no vertex/fragment). The returned mk_shader_t is used with mk_dispatch()/mk_encoder_dispatch().

ParameterTypeDescription
cs_pathconst char *Path to compute shader .bin file

Returns Shader handle or MK_SHADER_INVALID on failure

mk_shader_load_compute_descfunction

mk_shader_t mk_shader_load_compute_desc(const mk_compute_shader_desc *desc)

Load a compute program with uniforms created before the program links.

Uniform ownership and lookup are identical to mk_shader_load_desc().

ParameterTypeDescription
descconst mk_compute_shader_desc *Configuration descriptor.

Returns The resulting handle or value.

mk_shader_load_compute_memfunction

mk_shader_t mk_shader_load_compute_mem(const void *cs_data, uint32_t cs_size)

Load a COMPUTE program from memory (embedded data).

ParameterTypeDescription
cs_dataconst void *Compute shader data
cs_sizeuint32_tCompute shader size

Returns Shader handle or MK_SHADER_INVALID on failure

mk_shader_load_descfunction

mk_shader_t mk_shader_load_desc(const mk_shader_desc *desc)

Load a shader program, creating the declared uniforms BEFORE the program links (see block comment above).

The uniforms are owned by the shader: look them up with mk_shader_uniform() and do NOT destroy them yourself mk_shader_destroy() releases them.

ParameterTypeDescription
descconst mk_shader_desc *Shader descriptor.

Returns Shader handle or MK_SHADER_INVALID on failure.

mk_shader_load_memfunction

mk_shader_t mk_shader_load_mem(const void *vs_data, uint32_t vs_size, const void *fs_data, uint32_t fs_size)

Load shader program from memory (embedded data).

ParameterTypeDescription
vs_dataconst void *Vertex shader data
vs_sizeuint32_tVertex shader size
fs_dataconst void *Fragment shader data
fs_sizeuint32_tFragment shader size

Returns Shader handle or MK_SHADER_INVALID on failure

mk_shader_pinfunction

bool mk_shader_pin(mk_shader_t shader)

Perform the shader pin operation.

ParameterTypeDescription
shadermk_shader_tValue for shader.

Returns True when the operation succeeds.

mk_shader_replace_compute_memfunction

mk_result mk_shader_replace_compute_mem(mk_shader_t shader, const void *cs_data, uint32_t cs_size)

Compute equivalent of mk_shader_replace_mem().

ParameterTypeDescription
shadermk_shader_tValue for shader.
cs_dataconst void *Value for cs data.
cs_sizeuint32_tCs size in bytes.

Returns MK_SUCCESS or an error result.

mk_shader_replace_memfunction

mk_result mk_shader_replace_mem(mk_shader_t shader, const void *vs_data, uint32_t vs_size, const void *fs_data, uint32_t fs_size)

Replace a graphics program without changing its public mk_shader_t handle.

Existing pipelines/materials resolve the new program automatically. The previous program remains active if the replacement cannot be created.

ParameterTypeDescription
shadermk_shader_tValue for shader.
vs_dataconst void *Value for vs data.
vs_sizeuint32_tVs size in bytes.
fs_dataconst void *Value for fs data.
fs_sizeuint32_tFs size in bytes.

Returns MK_SUCCESS or an error result.

mk_shader_system_initfunction

void mk_shader_system_init(void)

Initialize the shader system.

mk_shader_system_shutdownfunction

void mk_shader_system_shutdown(void)

Perform the shader system shutdown operation.

mk_shader_uniformfunction

mk_uniform_t mk_shader_uniform(mk_shader_t shader, const char *name)

Look up a uniform declared in the mk_shader_desc this shader was loaded with.

Returns MK_UNIFORM_INVALID for unknown names or shaders not loaded via mk_shader_load_desc().

ParameterTypeDescription
shadermk_shader_tValue for shader.
nameconst char *Stable name.

Returns The resulting handle or value.

mk_shader_unpinfunction

void mk_shader_unpin(mk_shader_t shader)

Perform the shader unpin operation.

ParameterTypeDescription
shadermk_shader_tValue for shader.

mk_uniform_createfunction

mk_uniform_t mk_uniform_create(const char *name, mk_uniform_type_t type, uint16_t count)

Create uniform.

ParameterTypeDescription
nameconst char *Uniform name (must match shader)
typemk_uniform_type_tUniform type
countuint16_tArray count (1 for non-arrays)

Returns Uniform handle or MK_UNIFORM_INVALID on failure

mk_uniform_destroyfunction

void mk_uniform_destroy(mk_uniform_t uniform)

Get underlying GPU uniform handle (escape hatch).

Requires modkit.h. Destroy uniform and release resources.

ParameterTypeDescription
uniformmk_uniform_tValue for uniform.

mk_uniform_infofunction

bool mk_uniform_info(mk_uniform_t uniform, mk_uniform_info_t *out_info)

Query a uniform's name/type/array-count.

Returns false for an invalid handle.

ParameterTypeDescription
uniformmk_uniform_tValue for uniform.
out_infomk_uniform_info_t *Receives the info.

Returns True when the operation succeeds.

mk_uniform_is_validfunction

bool mk_uniform_is_valid(mk_uniform_t uniform)

Check if uniform handle is valid.

ParameterTypeDescription
uniformmk_uniform_tValue for uniform.

Returns True when the condition holds.

mk_uniform_pinfunction

bool mk_uniform_pin(mk_uniform_t uniform)

Retain/release an internal reference.

New retains reject pending handles.

ParameterTypeDescription
uniformmk_uniform_tValue for uniform.

Returns True when the operation succeeds.

mk_uniform_unpinfunction

void mk_uniform_unpin(mk_uniform_t uniform)

Perform the uniform unpin operation.

ParameterTypeDescription
uniformmk_uniform_tValue for uniform.

Structs

mk_compute_shader_descstruct

Compute shader descriptor.

Uniform declarations follow the same ownership rules as mk_shader_desc: they are created before linking and destroyed with the returned shader handle.

FieldTypeDescription
nameconst char *Debug name (optional, NULL ok).
cs_dataconst void *Compute shader binary.
cs_sizeuint32_tThe cs size.
uniformsmk_shader_uniform_declThe uniforms.
uniform_countuint8_t0 => count non-NULL names

mk_shader_descstruct

Shader descriptor.

Zero-init = sane defaults. uniform_count 0 => entries are counted up to the first NULL name.

FieldTypeDescription
nameconst char *Debug name (optional, NULL ok).
vs_dataconst void *Vertex shader binary.
vs_sizeuint32_tThe vs size.
fs_dataconst void *Fragment shader binary.
fs_sizeuint32_tThe fs size.
uniformsmk_shader_uniform_declThe uniforms.
uniform_countuint8_t0 => count non-NULL names

mk_shader_tstruct

Data for shader.

FieldTypeDescription
iduint32_tThe ID.

mk_shader_uniform_declstruct

A uniform declaration: created before the program links.

FieldTypeDescription
nameconst char *Uniform name (must match the shader).
typemk_uniform_type_tSAMPLER / VEC4 / MAT3 / MAT4.
countuint16_tArray count; 0 => 1.

mk_uniform_infostruct

Uniform reflection info.

FieldTypeDescription
namecharuniform name as seen by the shader
typemk_uniform_type_tuniform type
countuint16_tarray element count

mk_uniform_tstruct

Data for uniform.

FieldTypeDescription
iduint32_tThe ID.

Enums

mk_uniform_typeenum

Uniform types.

ValueDescription
MK_UNIFORM_SAMPLERTexture sampler.
MK_UNIFORM_VEC44 floats
MK_UNIFORM_MAT33x3 matrix
MK_UNIFORM_MAT44x4 matrix

Typedefs

mk_compute_shader_desctypedef

typedef struct mk_compute_shader_desc mk_compute_shader_desc

Compute shader descriptor.

Uniform declarations follow the same ownership rules as mk_shader_desc: they are created before linking and destroyed with the returned shader handle.

mk_shader_desctypedef

typedef struct mk_shader_desc mk_shader_desc

Shader descriptor.

Zero-init = sane defaults. uniform_count 0 => entries are counted up to the first NULL name.

mk_shader_uniform_decltypedef

typedef struct mk_shader_uniform_decl mk_shader_uniform_decl

A uniform declaration: created before the program links.

mk_uniform_info_ttypedef

typedef struct mk_uniform_info mk_uniform_info_t

Uniform reflection info.

mk_uniform_type_ttypedef

typedef enum mk_uniform_type mk_uniform_type_t

Uniform types.

Macros

MK_SHADER_INVALIDdefine

MK_SHADER_INVALID

Invalid sentinel for shader.

mk_shader_load_compute_multidefine

mk_shader_load_compute_multi(cs)

Helper macro for loading a multi-profile compute shader (runtime renderer selection).

Works with a cs_*.sc compiled via modkit_add_shaders_multi(). Usage: mk_shader_load_compute_multi(cs_plasma)

mk_shader_load_embeddeddefine

mk_shader_load_embedded(vs, fs)

Helper macro for loading shader from embedded data (single profile).

Usage: mk_shader_load_embedded(vs_array, fs_array)

mk_shader_load_multidefine

mk_shader_load_multi(vs, fs)

Helper macro for loading multi-profile shaders (runtime renderer selection).

Works with shaders compiled using modkit_add_shaders_multi(). The _data() and _size() functions are auto-generated in the shader header. Usage: mk_shader_load_multi(vs_name, fs_name) Example: mk_shader_load_multi(vs_cube, fs_cube)

MK_SHADER_MAX_UNIFORMSdefine

MK_SHADER_MAX_UNIFORMS

Maximum supported shader uniforms.

MK_SHADER_MULTIdefine

MK_SHADER_MULTI(vs, fs)

Initialize a desc's vs/fs fields from multi-profile embedded shaders (modkit_add_shaders_multi).

Use inside a mk_shader_desc initializer.

MK_UNIFORM_INVALIDdefine

MK_UNIFORM_INVALID

Invalid sentinel for uniform.