diff --git a/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/G4.c.h b/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/G4.c.h index f265f3980..05dadbe2e 100644 --- a/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/G4.c.h +++ b/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/G4.c.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -901,3 +902,15 @@ void kinc_g4_set_constant_buffer(uint32_t id, struct kinc_g4_constant_buffer *bu kinc_g5_command_list_set_vertex_constant_buffer(&commandList, &buffer->impl.buffer, 0, kinc_g5_constant_buffer_size(&buffer->impl.buffer)); } #endif + +void kinc_g4_set_compute_shader(kinc_g4_compute_shader *shader) { + kinc_g5_compute_shader *g5_shader = &shader->impl.shader; + current_state.compute_shader = g5_shader; + kinc_g5_command_list_set_compute_shader(&commandList, g5_shader); +} + +void kinc_g4_compute(int x, int y, int z) { + startDraw(true); + kinc_g5_command_list_compute(&commandList, x, y, z); + endDraw(true); +} diff --git a/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/compute.c.h b/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/compute.c.h index 43bdb5140..cfc687b2f 100644 --- a/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/compute.c.h +++ b/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/compute.c.h @@ -19,6 +19,7 @@ void kinc_g4_compute_shader_destroy(kinc_g4_compute_shader *shader) { kinc_g5_compute_shader_destroy(&shader->impl.shader); } +#ifndef KINC_KONG kinc_g4_constant_location_t kinc_g4_compute_shader_get_constant_location(kinc_g4_compute_shader *shader, const char *name) { kinc_g4_constant_location_t location; location.impl._location = kinc_g5_compute_shader_get_constant_location(&shader->impl.shader, name); @@ -33,15 +34,4 @@ kinc_g4_texture_unit_t kinc_g4_compute_shader_get_texture_unit(kinc_g4_compute_s } return g4_unit; } - -void kinc_g4_set_compute_shader(kinc_g4_compute_shader *shader) { - kinc_g5_compute_shader *g5_shader = &shader->impl.shader; - current_state.compute_shader = g5_shader; - kinc_g5_command_list_set_compute_shader(&commandList, g5_shader); -} - -void kinc_g4_compute(int x, int y, int z) { - startDraw(true); - kinc_g5_command_list_compute(&commandList, x, y, z); - endDraw(true); -} +#endif diff --git a/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/compute.c.h b/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/compute.c.h index faf6174e5..0ce647c57 100644 --- a/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/compute.c.h +++ b/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/compute.c.h @@ -171,7 +171,7 @@ kinc_g4_texture_unit_t kinc_g4_compute_shader_get_texture_unit(kinc_g4_compute_s return unit; } -void kinc_g4_compute_set_buffer(kinc_shader_storage_buffer_t *buffer, int index) { +void kinc_g4_set_shader_storage_buffer(kinc_shader_storage_buffer_t *buffer, int index) { #ifdef HAS_COMPUTE glBindBufferBase(GL_SHADER_STORAGE_BUFFER, index, buffer->impl.bufferId); glCheckErrors(); diff --git a/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/commandlist.c.h b/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/commandlist.c.h index be77628e4..91e6f4322 100644 --- a/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/commandlist.c.h +++ b/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/commandlist.c.h @@ -396,3 +396,7 @@ bool kinc_g5_command_list_are_query_results_available(kinc_g5_command_list_t *li } void kinc_g5_command_list_get_query_result(kinc_g5_command_list_t *list, unsigned occlusionQuery, unsigned *pixelCount) {} + +void kinc_g5_command_list_set_compute_shader(kinc_g5_command_list_t *list, struct kinc_g5_compute_shader *shader) {} + +void kinc_g5_command_list_compute(kinc_g5_command_list_t *list, int x, int y, int z) {} diff --git a/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/compute.c b/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/compute.c new file mode 100644 index 000000000..58d887fed --- /dev/null +++ b/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/compute.c @@ -0,0 +1,30 @@ +#include +#include + +#include + +void kinc_g5_compute_shader_init(kinc_g5_compute_shader *shader, void *source, int length) { + kinc_g4_compute_shader_init(&shader->impl.g4, source, length); +} + +void kinc_g5_compute_shader_destroy(kinc_g5_compute_shader *shader) { + kinc_g4_compute_shader_destroy(&shader->impl.g4); +} + +#ifndef KINC_KONG +kinc_g5_constant_location_t kinc_g5_compute_shader_get_constant_location(kinc_g5_compute_shader *shader, const char *name) { + kinc_g5_constant_location_t location = {0}; + location.impl.location = kinc_g4_compute_shader_get_constant_location(&shader->impl.g4, name); + return location; +} + +kinc_g5_texture_unit_t kinc_g5_compute_shader_get_texture_unit(kinc_g5_compute_shader *shader, const char *name) { + kinc_g5_texture_unit_t g5_unit = {0}; + kinc_g4_texture_unit_t g4_unit = kinc_g4_compute_shader_get_texture_unit(&shader->impl.g4, name); + assert(KINC_G4_SHADER_TYPE_COUNT == KINC_G5_SHADER_TYPE_COUNT); + for (int i = 0; i < KINC_G4_SHADER_TYPE_COUNT; ++i) { + g5_unit.stages[i] = g4_unit.stages[i]; + } + return g5_unit; +} +#endif diff --git a/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/compute.h b/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/compute.h new file mode 100644 index 000000000..59a278980 --- /dev/null +++ b/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/compute.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +typedef struct kinc_g5_compute_shader_impl { + kinc_g4_compute_shader g4; +} kinc_g5_compute_shader_impl; diff --git a/Sources/kinc/graphics4/compute.h b/Sources/kinc/graphics4/compute.h index a0c06b869..8951054ac 100644 --- a/Sources/kinc/graphics4/compute.h +++ b/Sources/kinc/graphics4/compute.h @@ -69,24 +69,6 @@ KINC_FUNC int kinc_shader_storage_buffer_count(kinc_shader_storage_buffer_t *buf KINC_FUNC void kinc_shader_storage_buffer_internal_set(kinc_shader_storage_buffer_t *buffer); #endif -#ifdef KORE_OPENGL -KINC_FUNC void kinc_g4_compute_set_buffer(kinc_shader_storage_buffer_t *buffer, int index); -#endif - -/// -/// Sets a shader for the next compute-run. -/// -/// The shader to use -KINC_FUNC void kinc_g4_set_compute_shader(kinc_g4_compute_shader *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_g4_compute(int x, int y, int z); - #ifdef __cplusplus } #endif diff --git a/Sources/kinc/graphics4/graphics.h b/Sources/kinc/graphics4/graphics.h index 1731b4cb7..c09c87362 100644 --- a/Sources/kinc/graphics4/graphics.h +++ b/Sources/kinc/graphics4/graphics.h @@ -16,10 +16,14 @@ extern "C" { #endif +struct kinc_g4_compute_shader; struct kinc_g4_pipeline; struct kinc_g4_render_target; struct kinc_g4_texture; struct kinc_g4_texture_array; +#ifdef KORE_OPENGL +struct kinc_shader_storage_buffer; +#endif #ifdef KINC_KONG struct kinc_g4_constant_buffer; #endif @@ -420,6 +424,27 @@ KINC_FUNC int kinc_g4_antialiasing_samples(void); /// The number of samples KINC_FUNC void kinc_g4_set_antialiasing_samples(int samples); +#ifdef KORE_OPENGL +/// +/// Old, hack thing, do not use. +/// +KINC_FUNC void kinc_g4_set_shader_storage_buffer(struct kinc_shader_storage_buffer *buffer, int index); +#endif + +/// +/// Sets a shader for the next compute-run. +/// +/// The shader to use +KINC_FUNC void kinc_g4_set_compute_shader(struct kinc_g4_compute_shader *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_g4_compute(int x, int y, int z); + #ifndef KINC_DOCS void kinc_g4_internal_init(void); void kinc_g4_internal_init_window(int window, int depth_buffer_bits, int stencil_buffer_bits, bool vsync); diff --git a/Sources/kinc/graphics5/compute.h b/Sources/kinc/graphics5/compute.h index 9ef164757..4fff79e82 100644 --- a/Sources/kinc/graphics5/compute.h +++ b/Sources/kinc/graphics5/compute.h @@ -33,6 +33,7 @@ KINC_FUNC void kinc_g5_compute_shader_init(kinc_g5_compute_shader *shader, void /// The shader-object to destroy KINC_FUNC void kinc_g5_compute_shader_destroy(kinc_g5_compute_shader *shader); +#ifndef KINC_KONG /// /// Finds the location of a constant/uniform inside of a shader. /// @@ -48,6 +49,7 @@ KINC_FUNC kinc_g5_constant_location_t kinc_g5_compute_shader_get_constant_locati /// The texture-name to look for /// The found texture-unit KINC_FUNC kinc_g5_texture_unit_t kinc_g5_compute_shader_get_texture_unit(kinc_g5_compute_shader *shader, const char *name); +#endif #ifdef __cplusplus }