#pragma once #include #include #ifdef KORE_OPENGL #include #endif #include #include #include /*! \file compute.h \brief Provides support for running compute-shaders. */ #ifdef __cplusplus extern "C" { #endif struct kinc_g4_texture; struct kinc_g4_render_target; typedef struct kinc_compute_constant_location { kinc_compute_constant_location_impl_t impl; } kinc_compute_constant_location_t; typedef struct kinc_compute_texture_unit { kinc_compute_texture_unit_impl_t impl; } kinc_compute_texture_unit_t; typedef struct kinc_compute_shader { kinc_compute_shader_impl_t impl; } kinc_compute_shader_t; /// /// Initialize a compute-shader from system-specific shader-data. /// /// The shader-object to initialize /// A pointer to system-specific shader-data /// Length of the shader-data in bytes KINC_FUNC void kinc_compute_shader_init(kinc_compute_shader_t *shader, void *source, int length); /// /// Destroy a shader-object /// /// The shader-object to destroy KINC_FUNC void kinc_compute_shader_destroy(kinc_compute_shader_t *shader); #ifndef KINC_KONG /// /// Finds the location of a constant/uniform inside of a shader. /// /// The shader to look into /// The constant/uniform-name to look for /// The found constant-location KINC_FUNC kinc_compute_constant_location_t kinc_compute_shader_get_constant_location(kinc_compute_shader_t *shader, const char *name); /// /// Finds a texture-unit inside of a shader. /// /// The shader to look into /// The texture-name to look for /// The found texture-unit KINC_FUNC kinc_compute_texture_unit_t kinc_compute_shader_get_texture_unit(kinc_compute_shader_t *shader, const char *name); #endif #ifdef KORE_OPENGL typedef struct kinc_shader_storage_buffer { kinc_compute_shader_storage_buffer_impl_t impl; } kinc_shader_storage_buffer_t; KINC_FUNC void kinc_shader_storage_buffer_init(kinc_shader_storage_buffer_t *buffer, int count, kinc_g4_vertex_data_t type); KINC_FUNC void kinc_shader_storage_buffer_destroy(kinc_shader_storage_buffer_t *buffer); KINC_FUNC int *kinc_shader_storage_buffer_lock(kinc_shader_storage_buffer_t *buffer); KINC_FUNC void kinc_shader_storage_buffer_unlock(kinc_shader_storage_buffer_t *buffer); KINC_FUNC int kinc_shader_storage_buffer_count(kinc_shader_storage_buffer_t *buffer); KINC_FUNC void kinc_shader_storage_buffer_internal_set(kinc_shader_storage_buffer_t *buffer); #endif typedef enum kinc_compute_access { KINC_COMPUTE_ACCESS_READ, KINC_COMPUTE_ACCESS_WRITE, KINC_COMPUTE_ACCESS_READ_WRITE } kinc_compute_access_t; /// /// Assigns a bool-value to a constant/uniform. The constant/uniform has to be declared as a bool in the shader. /// /// The location to set /// The value to set the location to KINC_FUNC void kinc_compute_set_bool(kinc_compute_constant_location_t location, bool value); /// /// Assigns an int-value to a constant/uniform. The constant/uniform has to be declared as an int in the shader. /// /// The location to set /// The value to set the location to KINC_FUNC void kinc_compute_set_int(kinc_compute_constant_location_t location, int value); /// /// Assigns a float-value to a constant/uniform. The constant/uniform has to be declared as a float in the shader. /// /// The location to set /// The value to set the location to KINC_FUNC void kinc_compute_set_float(kinc_compute_constant_location_t location, float value); /// /// Assigns two float-values to a constant/uniform. The constant/uniform has to be declared as a vec2 in the shader. /// /// The location to set KINC_FUNC void kinc_compute_set_float2(kinc_compute_constant_location_t location, float value1, float value2); /// /// Assigns three float-values to a constant/uniform. The constant/uniform has to be declared as a vec3 in the shader. /// /// The location to set KINC_FUNC void kinc_compute_set_float3(kinc_compute_constant_location_t location, float value1, float value2, float value3); /// /// Assigns four float-values to a constant/uniform. The constant/uniform has to be declared as a vec4 in the shader. /// /// The location to set KINC_FUNC void kinc_compute_set_float4(kinc_compute_constant_location_t location, float value1, float value2, float value3, float value4); /// /// Assigns an array of float-values to a constant/uniform. The constant/uniform has to be declared as a float-array in the shader. /// /// The location to set KINC_FUNC void kinc_compute_set_floats(kinc_compute_constant_location_t location, float *values, int count); /// /// Assigns a 4x4-matrix-value to a constant/uniform. The constant/uniform has to be declared as a mat4 in the shader. /// /// The location to set KINC_FUNC void kinc_compute_set_matrix4(kinc_compute_constant_location_t location, kinc_matrix4x4_t *value); /// /// Assigns a 3x3-matrix-value to a constant/uniform. The constant/uniform has to be declared as a mat3 in the shader. /// /// The location to set KINC_FUNC void kinc_compute_set_matrix3(kinc_compute_constant_location_t location, kinc_matrix3x3_t *value); #ifdef KORE_OPENGL KINC_FUNC void kinc_compute_set_buffer(kinc_shader_storage_buffer_t *buffer, int index); #endif /// /// Assigns a texture to a texture-unit for direct access. /// KINC_FUNC void kinc_compute_set_texture(kinc_compute_texture_unit_t unit, struct kinc_g4_texture *texture, kinc_compute_access_t access); /// /// Assigns a render-target to a texture-unit for direct access. /// KINC_FUNC void kinc_compute_set_render_target(kinc_compute_texture_unit_t unit, struct kinc_g4_render_target *texture, kinc_compute_access_t access); /// /// Assigns a texture to a texture-unit for samples access. /// KINC_FUNC void kinc_compute_set_sampled_texture(kinc_compute_texture_unit_t unit, struct kinc_g4_texture *texture); /// /// Assigns a render-target to a texture-unit for samples access. /// KINC_FUNC void kinc_compute_set_sampled_render_target(kinc_compute_texture_unit_t unit, struct kinc_g4_render_target *target); /// /// Assigns the depth-component of a render-target to a texture-unit for samples access. /// KINC_FUNC void kinc_compute_set_sampled_depth_from_render_target(kinc_compute_texture_unit_t unit, struct kinc_g4_render_target *target); /// /// Assigns the mode for accessing a texture outside of the 0 to 1-range for a texture-unit. /// KINC_FUNC void kinc_compute_set_texture_addressing(kinc_compute_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing); /// /// Sets the magnification-mode for a texture-unit. /// KINC_FUNC void kinc_compute_set_texture_magnification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter); /// /// Sets the minification-mode for a texture-unit. /// KINC_FUNC void kinc_compute_set_texture_minification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter); /// /// Sets the mipmap-mode for a texture-unit. /// KINC_FUNC void kinc_compute_set_texture_mipmap_filter(kinc_compute_texture_unit_t unit, kinc_g4_mipmap_filter_t filter); /// /// Assigns the mode for accessing a texture outside of the 0 to 1-range for a texture-unit. /// KINC_FUNC void kinc_compute_set_texture3d_addressing(kinc_compute_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing); /// /// Sets the magnification-mode for a texture-unit. /// KINC_FUNC void kinc_compute_set_texture3d_magnification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter); /// /// Sets the minification-mode for a texture-unit. /// KINC_FUNC void kinc_compute_set_texture3d_minification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter); /// /// Sets the mipmap-mode for a texture-unit. /// KINC_FUNC void kinc_compute_set_texture3d_mipmap_filter(kinc_compute_texture_unit_t unit, kinc_g4_mipmap_filter_t filter); /// /// Sets a shader for the next compute-run. /// /// The shader to use KINC_FUNC void kinc_compute_set_shader(kinc_compute_shader_t *shader); /// /// Fire off a compute-run on x * y * z elements. /// /// The x-size for the compute-run /// The y-size for the compute-run /// The z-size for the compute-run KINC_FUNC void kinc_compute(int x, int y, int z); #ifdef __cplusplus } #endif