Skip to content

Commit

Permalink
Merge branch 'main' of ssh://github.com/Kode/Kinc
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Jan 20, 2024
2 parents 2dd10a1 + 158486b commit d2b44f6
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 31 deletions.
13 changes: 13 additions & 0 deletions Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/G4.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <kinc/backend/graphics4/pipeline.h>
#include <kinc/backend/graphics4/vertexbuffer.h>
#include <kinc/color.h>
#include <kinc/graphics4/compute.h>
#include <kinc/graphics4/constantbuffer.h>
#include <kinc/graphics4/indexbuffer.h>
#include <kinc/graphics4/pipeline.h>
Expand Down Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
30 changes: 30 additions & 0 deletions Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/compute.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <kinc/graphics5/compute.h>
#include <kinc/math/core.h>

#include <assert.h>

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include <kinc/graphics4/compute.h>

typedef struct kinc_g5_compute_shader_impl {
kinc_g4_compute_shader g4;
} kinc_g5_compute_shader_impl;
18 changes: 0 additions & 18 deletions Sources/kinc/graphics4/compute.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/// <summary>
/// Sets a shader for the next compute-run.
/// </summary>
/// <param name="shader">The shader to use</param>
KINC_FUNC void kinc_g4_set_compute_shader(kinc_g4_compute_shader *shader);

/// <summary>
/// Fire off a compute-run on x * y * z elements.
/// </summary>
/// <param name="x">The x-size for the compute-run</param>
/// <param name="y">The y-size for the compute-run</param>
/// <param name="z">The z-size for the compute-run</param>
KINC_FUNC void kinc_g4_compute(int x, int y, int z);

#ifdef __cplusplus
}
#endif
25 changes: 25 additions & 0 deletions Sources/kinc/graphics4/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -420,6 +424,27 @@ KINC_FUNC int kinc_g4_antialiasing_samples(void);
/// <param name="samples">The number of samples</param>
KINC_FUNC void kinc_g4_set_antialiasing_samples(int samples);

#ifdef KORE_OPENGL
/// <summary>
/// Old, hack thing, do not use.
/// </summary>
KINC_FUNC void kinc_g4_set_shader_storage_buffer(struct kinc_shader_storage_buffer *buffer, int index);
#endif

/// <summary>
/// Sets a shader for the next compute-run.
/// </summary>
/// <param name="shader">The shader to use</param>
KINC_FUNC void kinc_g4_set_compute_shader(struct kinc_g4_compute_shader *shader);

/// <summary>
/// Fire off a compute-run on x * y * z elements.
/// </summary>
/// <param name="x">The x-size for the compute-run</param>
/// <param name="y">The y-size for the compute-run</param>
/// <param name="z">The z-size for the compute-run</param>
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);
Expand Down
2 changes: 2 additions & 0 deletions Sources/kinc/graphics5/compute.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ KINC_FUNC void kinc_g5_compute_shader_init(kinc_g5_compute_shader *shader, void
/// <param name="shader">The shader-object to destroy</param>
KINC_FUNC void kinc_g5_compute_shader_destroy(kinc_g5_compute_shader *shader);

#ifndef KINC_KONG
/// <summary>
/// Finds the location of a constant/uniform inside of a shader.
/// </summary>
Expand All @@ -48,6 +49,7 @@ KINC_FUNC kinc_g5_constant_location_t kinc_g5_compute_shader_get_constant_locati
/// <param name="name">The texture-name to look for</param>
/// <returns>The found texture-unit</returns>
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
}
Expand Down

0 comments on commit d2b44f6

Please sign in to comment.