From 38a45d0bc5e5f4f5ec83ac57195e98cab8fcd75a Mon Sep 17 00:00:00 2001 From: Robert Konrad Date: Thu, 5 Oct 2023 02:50:52 +0200 Subject: [PATCH] Mostly adjust G4onG5 for Kong --- .../Sources/kinc/backend/graphics4/G4.c.h | 66 +++++++++++++++++++ .../kinc/backend/graphics4/constantbuffer.c.h | 35 ++++++++++ .../kinc/backend/graphics4/constantbuffer.h | 11 ++++ .../kinc/backend/graphics4/g4ong5unit.c | 1 + .../kinc/backend/graphics4/pipeline.c.h | 2 + 5 files changed, 115 insertions(+) create mode 100644 Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/constantbuffer.c.h create mode 100644 Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/constantbuffer.h 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 b733c238d..d375678dc 100644 --- a/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/G4.c.h +++ b/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/G4.c.h @@ -621,6 +621,38 @@ void kinc_g4_set_index_buffer(kinc_g4_index_buffer_t *buffer) { kinc_g5_command_list_set_index_buffer(&commandList, g5_index_buffer); } +#ifdef KINC_KONG +void kinc_g4_set_texture(uint32_t unit, kinc_g4_texture_t *texture) { + if (!texture->impl._uploaded) { + kinc_g5_command_list_upload_texture(&commandList, &texture->impl._texture); + texture->impl._uploaded = true; + } + + assert(KINC_G4_SHADER_TYPE_COUNT == KINC_G5_SHADER_TYPE_COUNT); + kinc_g5_texture_unit_t g5_unit; + for (int i = 0; i < KINC_G5_SHADER_TYPE_COUNT; ++i) { + g5_unit.stages[i] = unit; + } + + bool found = false; + for (int i = 0; i < current_state.texture_count; ++i) { + if (kinc_g5_texture_unit_equals(¤t_state.texture_units[i], &g5_unit)) { + current_state.textures[i] = &texture->impl._texture; + current_state.texture_units[i] = g5_unit; + found = true; + break; + } + } + if (!found) { + assert(current_state.texture_count < MAX_TEXTURES); + current_state.textures[current_state.texture_count] = &texture->impl._texture; + current_state.texture_units[current_state.texture_count] = g5_unit; + current_state.texture_count += 1; + } + + kinc_g5_command_list_set_texture(&commandList, g5_unit, &texture->impl._texture); +} +#else void kinc_g4_set_texture(kinc_g4_texture_unit_t unit, kinc_g4_texture_t *texture) { if (!texture->impl._uploaded) { kinc_g5_command_list_upload_texture(&commandList, &texture->impl._texture); @@ -649,6 +681,7 @@ void kinc_g4_set_texture(kinc_g4_texture_unit_t unit, kinc_g4_texture_t *texture kinc_g5_command_list_set_texture(&commandList, g5_unit, &texture->impl._texture); } +#endif void kinc_g4_set_image_texture(kinc_g4_texture_unit_t unit, kinc_g4_texture_t *texture) {} @@ -709,6 +742,38 @@ bool kinc_g4_render_targets_inverted_y(void) { return kinc_g5_render_targets_inverted_y(); } +#ifdef KINC_KONG +void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *render_target, uint32_t unit) { + if (render_target->impl.state != KINC_INTERNAL_RENDER_TARGET_STATE_TEXTURE) { + kinc_g5_command_list_render_target_to_texture_barrier(&commandList, &render_target->impl._renderTarget); + render_target->impl.state = KINC_INTERNAL_RENDER_TARGET_STATE_TEXTURE; + } + + assert(KINC_G4_SHADER_TYPE_COUNT == KINC_G5_SHADER_TYPE_COUNT); + kinc_g5_texture_unit_t g5_unit; + for (int i = 0; i < KINC_G5_SHADER_TYPE_COUNT; ++i) { + g5_unit.stages[i] = unit; + } + + bool found = false; + for (int i = 0; i < current_state.render_target_count; ++i) { + if (kinc_g5_texture_unit_equals(¤t_state.render_target_units[i], &g5_unit)) { + current_state.render_targets[i] = &render_target->impl._renderTarget; + current_state.render_target_units[i] = g5_unit; + found = true; + break; + } + } + if (!found) { + assert(current_state.render_target_count < MAX_TEXTURES); + current_state.render_targets[current_state.render_target_count] = &render_target->impl._renderTarget; + current_state.render_target_units[current_state.render_target_count] = g5_unit; + current_state.render_target_count += 1; + } + + kinc_g5_command_list_set_texture_from_render_target(&commandList, g5_unit, &render_target->impl._renderTarget); +} +#else void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *render_target, kinc_g4_texture_unit_t unit) { if (render_target->impl.state != KINC_INTERNAL_RENDER_TARGET_STATE_TEXTURE) { kinc_g5_command_list_render_target_to_texture_barrier(&commandList, &render_target->impl._renderTarget); @@ -737,6 +802,7 @@ void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *render_ kinc_g5_command_list_set_texture_from_render_target(&commandList, g5_unit, &render_target->impl._renderTarget); } +#endif void kinc_g4_render_target_use_depth_as_texture(kinc_g4_render_target_t *render_target, kinc_g4_texture_unit_t unit) { if (render_target->impl.state != KINC_INTERNAL_RENDER_TARGET_STATE_TEXTURE) { diff --git a/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/constantbuffer.c.h b/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/constantbuffer.c.h new file mode 100644 index 000000000..ff6d9d00e --- /dev/null +++ b/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/constantbuffer.c.h @@ -0,0 +1,35 @@ +#ifdef KINC_KONG + +#include + +void kinc_g4_constant_buffer_init(kinc_g4_constant_buffer *buffer, size_t size) { + kinc_g5_constant_buffer_init(&buffer->impl.buffer, (int)size); +} + +void kinc_g4_constant_buffer_destroy(kinc_g4_constant_buffer *buffer) { + kinc_g5_constant_buffer_destroy(&buffer->impl.buffer); +} + +uint8_t *kinc_g4_constant_buffer_lock_all(kinc_g4_constant_buffer *buffer) { + kinc_g5_constant_buffer_lock_all(&buffer->impl.buffer); + return buffer->impl.buffer.data; +} + +uint8_t *kinc_g4_constant_buffer_lock(kinc_g4_constant_buffer *buffer, size_t start, size_t size) { + kinc_g5_constant_buffer_lock(&buffer->impl.buffer, (int)start, (int)size); + return buffer->impl.buffer.data; +} + +void kinc_g4_constant_buffer_unlock_all(kinc_g4_constant_buffer *buffer) { + kinc_g5_constant_buffer_unlock(&buffer->impl.buffer); +} + +void kinc_g4_constant_buffer_unlock(kinc_g4_constant_buffer *buffer, size_t count) { + kinc_g5_constant_buffer_unlock(&buffer->impl.buffer); +} + +size_t kinc_g4_constant_buffer_size(kinc_g4_constant_buffer *buffer) { + return kinc_g5_constant_buffer_size(&buffer->impl.buffer); +} + +#endif diff --git a/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/constantbuffer.h b/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/constantbuffer.h new file mode 100644 index 000000000..f42b62062 --- /dev/null +++ b/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/constantbuffer.h @@ -0,0 +1,11 @@ +#pragma once + +#ifdef KINC_KONG + +#include + +typedef struct kinc_g4_constant_buffer_impl { + kinc_g5_constant_buffer_t buffer; +} kinc_g4_constant_buffer_impl; + +#endif diff --git a/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/g4ong5unit.c b/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/g4ong5unit.c index f30b53021..76911e5a8 100644 --- a/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/g4ong5unit.c +++ b/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/g4ong5unit.c @@ -1,6 +1,7 @@ #include "samplers.c.h" #include "G4.c.h" +#include "constantbuffer.c.h" #include "indexbuffer.c.h" #include "pipeline.c.h" #include "rendertarget.c.h" diff --git a/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/pipeline.c.h b/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/pipeline.c.h index d73a6503f..5aac59c23 100644 --- a/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/pipeline.c.h +++ b/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/pipeline.c.h @@ -13,6 +13,7 @@ void kinc_g4_pipeline_destroy(kinc_g4_pipeline_t *pipe) { kinc_g5_pipeline_destroy(&pipe->impl._pipeline); } +#ifndef KINC_KONG kinc_g4_constant_location_t kinc_g4_pipeline_get_constant_location(kinc_g4_pipeline_t *pipe, const char *name) { kinc_g4_constant_location_t location; location.impl._location = kinc_g5_pipeline_get_constant_location(&pipe->impl._pipeline, name); @@ -28,6 +29,7 @@ kinc_g4_texture_unit_t kinc_g4_pipeline_get_texture_unit(kinc_g4_pipeline_t *pip return g4_unit; } +#endif void kinc_g4_pipeline_compile(kinc_g4_pipeline_t *pipe) { for (int i = 0; i < 16; ++i) {