Skip to content
modkitv0.2

shader_compiler.h

#include <modkit/shader_compiler.h>8 functions · 5 structs · 1 enums · 5 typedefs · 1 macros

Optional runtime compilation of portable bgfx .sc shader source.

Runtime compilation is enabled with MODKIT_ENABLE_RUNTIME_SHADERS. Native desktop/mobile applications use this C API; browser applications use the isolated Modkit web compiler provider. Both accept the same portable source and virtual-file model. MK_RENDERER_AUTO targets the active native renderer.

Functions

mk_shader_compilation_freefunction

void mk_shader_compilation_free(mk_shader_compilation *compilation)

Release all allocations owned by a compilation result.

ParameterTypeDescription
compilationmk_shader_compilation *Value for compilation.

mk_shader_compilefunction

mk_result mk_shader_compile(const mk_shader_compile_desc *desc, mk_shader_compilation *out_compilation)

Blocking compiler entry point.

ParameterTypeDescription
descconst mk_shader_compile_desc *Configuration descriptor.
out_compilationmk_shader_compilation *Receives the compilation.

Returns MK_SUCCESS or an error result.

mk_shader_compile_asyncfunction

mk_shader_compile_request_t mk_shader_compile_async(const mk_shader_compile_desc *desc)

Queue a compilation after copying all descriptor data.

ParameterTypeDescription
descconst mk_shader_compile_desc *Configuration descriptor.

Returns The resulting handle or value.

mk_shader_compile_cancelfunction

void mk_shader_compile_cancel(mk_shader_compile_request_t request)

Request cancellation.

ParameterTypeDescription
requestmk_shader_compile_request_tValue for request.

mk_shader_compile_pollfunction

mk_shader_compile_state_t mk_shader_compile_poll(mk_shader_compile_request_t request)

Query without blocking.

ParameterTypeDescription
requestmk_shader_compile_request_tValue for request.

Returns The resulting handle or value.

mk_shader_compile_request_destroyfunction

void mk_shader_compile_request_destroy(mk_shader_compile_request_t request)

Release a queued/completed request without taking its result.

ParameterTypeDescription
requestmk_shader_compile_request_tValue for request.

mk_shader_compile_take_resultfunction

mk_result mk_shader_compile_take_result(mk_shader_compile_request_t request, mk_shader_compilation *out_compilation)

Move a completed result to the caller and invalidate the request.

Failed compilations still return their owned diagnostic string.

ParameterTypeDescription
requestmk_shader_compile_request_tValue for request.
out_compilationmk_shader_compilation *Receives the compilation.

Returns MK_SUCCESS or an error result.

mk_shader_compiler_availablefunction

bool mk_shader_compiler_available(void)

True when this build contains a compiler provider for its target.

Returns True when the operation succeeds.

Structs

mk_shader_compilationstruct

Owned result.

Release with mk_shader_compilation_free().

FieldTypeDescription
renderermk_renderer_type_tThe renderer.
vertexmk_shader_compiled_blobThe vertex.
fragmentmk_shader_compiled_blobThe fragment.
computemk_shader_compiled_blobThe compute.
diagnosticschar *The diagnostics.

mk_shader_compile_descstruct

A graphics program supplies vertex + fragment source.

A compute program supplies compute source and leaves vertex/fragment NULL.

FieldTypeDescription
nameconst char *The name.
renderermk_renderer_type_tAUTO selects the active renderer.
vertex_pathconst char *The vertex path.
vertex_sourceconst void *The vertex source.
vertex_sizeuint32_tThe vertex size.
fragment_pathconst char *The fragment path.
fragment_sourceconst void *The fragment source.
fragment_sizeuint32_tThe fragment size.
compute_pathconst char *The compute path.
compute_sourceconst void *The compute source.
compute_sizeuint32_tThe compute size.
varying_pathconst char *The varying path.
varying_sourceconst void *The varying source.
varying_sizeuint32_tThe varying size.
filesconst mk_shader_source_file *The files.
file_countuint32_tThe file count.
definesconst char *const *The defines.
define_countuint32_tThe define count.
optimization_leveluint8_t0 selects default 3; 1..3 are explicit.
debug_informationboolThe debug information.
warnings_are_errorsboolThe warnings are errors.

mk_shader_compile_request_tstruct

Data for shader compile request.

FieldTypeDescription
iduint32_tThe ID.

mk_shader_compiled_blobstruct

Data for shader compiled blob.

FieldTypeDescription
datavoid *The data.
sizeuint32_tThe size.

mk_shader_source_filestruct

One file visible to shader include directives.

Paths must be relative.

FieldTypeDescription
pathconst char *The path.
dataconst void *The data.
sizeuint32_tZero treats data as a null-terminated UTF-8 string.

Enums

mk_shader_compile_stateenum

Values for shader compile state.

ValueDescription
MK_SHADER_COMPILE_INVALIDSelects invalid.
MK_SHADER_COMPILE_QUEUEDSelects queued.
MK_SHADER_COMPILE_RUNNINGSelects running.
MK_SHADER_COMPILE_SUCCEEDEDSelects succeeded.
MK_SHADER_COMPILE_FAILEDSelects failed.
MK_SHADER_COMPILE_CANCELLEDSelects cancelled.

Typedefs

mk_shader_compilationtypedef

typedef struct mk_shader_compilation mk_shader_compilation

Owned result.

Release with mk_shader_compilation_free().

mk_shader_compile_desctypedef

typedef struct mk_shader_compile_desc mk_shader_compile_desc

A graphics program supplies vertex + fragment source.

A compute program supplies compute source and leaves vertex/fragment NULL.

mk_shader_compile_state_ttypedef

typedef enum mk_shader_compile_state mk_shader_compile_state_t

Values for shader compile state.

mk_shader_compiled_blobtypedef

typedef struct mk_shader_compiled_blob mk_shader_compiled_blob

Data for shader compiled blob.

mk_shader_source_filetypedef

typedef struct mk_shader_source_file mk_shader_source_file

One file visible to shader include directives.

Paths must be relative.

Macros

MK_SHADER_COMPILE_REQUEST_INVALIDdefine

MK_SHADER_COMPILE_REQUEST_INVALID

Invalid sentinel for shader compile request.