From 881171ec18eb07766721eace1d4f356f3cca3c10 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Thu, 11 Jun 2026 17:33:19 +0200 Subject: [PATCH] base: handle bigger data --- base/sources/backends/vulkan_gpu.c | 31 ++++++++++----------- base/sources/iron_gpu.c | 18 ++++++------ base/sources/iron_gpu.h | 44 +++++++++++++++--------------- 3 files changed, 46 insertions(+), 47 deletions(-) diff --git a/base/sources/backends/vulkan_gpu.c b/base/sources/backends/vulkan_gpu.c index 180a5d35..c9f668b6 100644 --- a/base/sources/backends/vulkan_gpu.c +++ b/base/sources/backends/vulkan_gpu.c @@ -11,7 +11,7 @@ #include #include -extern int constant_buffer_index; +extern uint32_t constant_buffer_index; static VkSemaphore framebuffer_available_semaphore; static VkSemaphore rendering_finished_semaphores[GPU_FRAMEBUFFER_COUNT]; @@ -58,7 +58,7 @@ static VkBuffer readback_buffer; static int readback_buffer_size = 0; static VkDeviceMemory readback_mem; static VkBuffer upload_buffer; -static int upload_buffer_size = 0; +static uint32_t upload_buffer_size = 0; static VkDeviceMemory upload_mem; static bool is_amd = false; #ifdef IRON_ANDROID @@ -383,7 +383,7 @@ static void gpu_cleanup_internal() { } } -void gpu_render_target_init2(gpu_texture_t *target, int width, int height, gpu_texture_format_t format, int framebuffer_index) { +void gpu_render_target_init2(gpu_texture_t *target, uint32_t width, uint32_t height, gpu_texture_format_t format, int framebuffer_index) { target->width = width; target->height = height; target->format = format; @@ -1031,7 +1031,7 @@ bool iron_vulkan_get_size(int *width, int *height) { return false; } -void gpu_begin_internal(gpu_clear_t flags, unsigned color, float depth) { +void gpu_begin_internal(gpu_clear_t flags, uint32_t color, float depth) { if (!framebuffer_acquired) { acquire_next_image(); framebuffer_acquired = true; @@ -1374,13 +1374,13 @@ static VkDescriptorSet get_descriptor_set(VkBuffer buffer) { return descriptor_set; } -void gpu_set_constant_buffer(gpu_buffer_t *buffer, int offset, size_t size) { +void gpu_set_constant_buffer(gpu_buffer_t *buffer, uint32_t offset, size_t size) { VkDescriptorSet descriptor_set = get_descriptor_set(buffer->impl.buf); uint32_t offsets[1] = {offset}; vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, current_pipeline->impl.pipeline_layout, 0, 1, &descriptor_set, 1, offsets); } -void gpu_set_texture(int unit, gpu_texture_t *texture) { +void gpu_set_texture(uint32_t unit, gpu_texture_t *texture) { current_textures[unit] = texture; } @@ -1593,7 +1593,7 @@ void gpu_shader_destroy(gpu_shader_t *shader) { shader->impl.source = NULL; } -void gpu_texture_init_from_bytes(gpu_texture_t *texture, void *data, int width, int height, gpu_texture_format_t format) { +void gpu_texture_init_from_bytes(gpu_texture_t *texture, void *data, uint32_t width, uint32_t height, gpu_texture_format_t format) { texture->width = width; texture->height = height; texture->format = format; @@ -1605,7 +1605,7 @@ void gpu_texture_init_from_bytes(gpu_texture_t *texture, void *data, int width, vk_format = VK_FORMAT_R8G8B8A8_UNORM; } - VkDeviceSize _upload_size = width * height * gpu_texture_format_size(format); + VkDeviceSize _upload_size = width * height * (VkDeviceSize)gpu_texture_format_size(format); void *original_data = data; #ifdef WITH_BC7 @@ -1617,7 +1617,7 @@ void gpu_texture_init_from_bytes(gpu_texture_t *texture, void *data, int width, } #endif - int new_upload_buffer_size = _upload_size; + uint32_t new_upload_buffer_size = _upload_size; if (new_upload_buffer_size < (1024 * 1024 * 4)) { new_upload_buffer_size = (1024 * 1024 * 4); } @@ -1773,11 +1773,11 @@ void gpu_texture_destroy_internal(gpu_texture_t *target) { } } -void gpu_render_target_init(gpu_texture_t *target, int width, int height, gpu_texture_format_t format) { +void gpu_render_target_init(gpu_texture_t *target, uint32_t width, uint32_t height, gpu_texture_format_t format) { gpu_render_target_init2(target, width, height, format, -1); } -void _gpu_buffer_init(VkBuffer *buf, VkDeviceMemory *mem, int size, int usage, int memory_requirements) { +void _gpu_buffer_init(VkBuffer *buf, VkDeviceMemory *mem, uint32_t size, uint32_t usage, uint32_t memory_requirements) { if (buf != NULL && *buf != NULL) { assert(buffers_to_destroy_count < 512); buffers_to_destroy[buffers_to_destroy_count] = *buf; @@ -1848,7 +1848,7 @@ void _gpu_buffer_copy(VkBuffer dest, VkBuffer source, uint32_t size) { } } -void gpu_vertex_buffer_init(gpu_buffer_t *buffer, int count, gpu_vertex_structure_t *structure) { +void gpu_vertex_buffer_init(gpu_buffer_t *buffer, uint32_t count, gpu_vertex_structure_t *structure) { buffer->count = count; buffer->stride = 0; for (int i = 0; i < structure->size; ++i) { @@ -1861,7 +1861,6 @@ void gpu_vertex_buffer_init(gpu_buffer_t *buffer, int count, gpu_vertex_structur } void *gpu_vertex_buffer_lock(gpu_buffer_t *buffer) { - if (unified_memory && buffer->cpu_write) { if (buffer->impl.buf == NULL) { _gpu_buffer_init(&buffer->impl.buf, &buffer->impl.mem, buffer->count * buffer->stride, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, @@ -1905,7 +1904,7 @@ void gpu_vertex_buffer_unlock(gpu_buffer_t *buffer) { } } -void gpu_index_buffer_init(gpu_buffer_t *buffer, int count) { +void gpu_index_buffer_init(gpu_buffer_t *buffer, uint32_t count) { buffer->count = count; buffer->stride = sizeof(uint32_t); buffer->cpu_write = false; @@ -1929,7 +1928,7 @@ void gpu_index_buffer_unlock(gpu_buffer_t *buffer) { _gpu_buffer_copy(buffer->impl.buf, upload_buffer, buffer->count * buffer->stride); } -void gpu_constant_buffer_init(gpu_buffer_t *buffer, int size) { +void gpu_constant_buffer_init(gpu_buffer_t *buffer, uint32_t size) { buffer->count = size; buffer->data = NULL; buffer->cpu_write = false; @@ -1939,7 +1938,7 @@ void gpu_constant_buffer_init(gpu_buffer_t *buffer, int size) { VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); } -void gpu_constant_buffer_lock(gpu_buffer_t *buffer, int start, int count) { +void gpu_constant_buffer_lock(gpu_buffer_t *buffer, uint32_t start, uint32_t count) { vkMapMemory(device, buffer->impl.mem, start, count, 0, (void **)&buffer->data); } diff --git a/base/sources/iron_gpu.c b/base/sources/iron_gpu.c index 6e59d3b4..ad3b3d9e 100644 --- a/base/sources/iron_gpu.c +++ b/base/sources/iron_gpu.c @@ -13,18 +13,18 @@ static int buffers_to_destroy_count = 0; static int pipelines_to_destroy_count = 0; extern int draw_vb_index; -int constant_buffer_index = 0; -int draw_calls = 0; -int draw_calls_last = 0; +uint32_t constant_buffer_index = 0; +uint32_t draw_calls = 0; +uint32_t draw_calls_last = 0; bool gpu_in_use = false; gpu_texture_t *current_textures[GPU_MAX_TEXTURES] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; gpu_texture_t *current_render_targets[8] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; -int current_render_targets_count = 0; +uint32_t current_render_targets_count = 0; gpu_texture_t *current_depth_buffer = NULL; gpu_pipeline_t *current_pipeline = NULL; gpu_texture_t framebuffers[GPU_FRAMEBUFFER_COUNT]; gpu_texture_t framebuffer_depth; -int framebuffer_index = 0; +uint32_t framebuffer_index = 0; void gpu_init(int depth_buffer_bits, bool vsync) { gpu_init_internal(depth_buffer_bits, vsync); @@ -300,7 +300,7 @@ void gpu_buffer_destroy(gpu_buffer_t *buffer) { } } -int gpu_vertex_data_size(gpu_vertex_data_t data) { +uint32_t gpu_vertex_data_size(gpu_vertex_data_t data) { switch (data) { case GPU_VERTEX_DATA_F32_1X: return 1 * 4; @@ -317,15 +317,15 @@ int gpu_vertex_data_size(gpu_vertex_data_t data) { } } -int gpu_vertex_struct_size(gpu_vertex_structure_t *s) { - int size = 0; +uint32_t gpu_vertex_struct_size(gpu_vertex_structure_t *s) { + uint32_t size = 0; for (int i = 0; i < s->size; ++i) { size += gpu_vertex_data_size(s->elements[i].data); } return size; } -int gpu_texture_format_size(gpu_texture_format_t format) { +uint32_t gpu_texture_format_size(gpu_texture_format_t format) { switch (format) { case GPU_TEXTURE_FORMAT_RGBA128: return 16; diff --git a/base/sources/iron_gpu.h b/base/sources/iron_gpu.h index f28f0957..8b2d2aae 100644 --- a/base/sources/iron_gpu.h +++ b/base/sources/iron_gpu.h @@ -97,8 +97,8 @@ typedef enum { } gpu_compare_mode_t; typedef struct gpu_texture { - int width; - int height; + uint32_t width; + uint32_t height; gpu_texture_format_t format; gpu_texture_compression_t compression; gpu_texture_state_t state; @@ -108,8 +108,8 @@ typedef struct gpu_texture { } gpu_texture_t; typedef struct gpu_buffer { - int count; - int stride; + uint32_t count; + uint32_t stride; uint8_t *data; // constant buffer data bool cpu_write; gpu_buffer_impl_t impl; @@ -122,7 +122,7 @@ typedef struct gpu_vertex_element { typedef struct gpu_vertex_structure { gpu_vertex_element_t elements[GPU_MAX_VERTEX_ELEMENTS]; - int size; + uint32_t size; } gpu_vertex_structure_t; typedef struct gpu_shader { @@ -145,8 +145,8 @@ typedef struct gpu_pipeline { bool color_write_mask_blue[8]; bool color_write_mask_alpha[8]; gpu_texture_format_t color_attachment[8]; - int color_attachment_count; - int depth_attachment_bits; + uint32_t color_attachment_count; + uint32_t depth_attachment_bits; gpu_pipeline_impl_t impl; } gpu_pipeline_t; @@ -191,18 +191,18 @@ void gpu_set_mat3(int location, mat3_t value); void gpu_set_mat4(int location, mat4_t value); void gpu_vertex_structure_add(gpu_vertex_structure_t *structure, const char *name, gpu_vertex_data_t data); -void gpu_texture_init_from_bytes(gpu_texture_t *texture, void *data, int width, int height, gpu_texture_format_t format); +void gpu_texture_init_from_bytes(gpu_texture_t *texture, void *data, uint32_t width, uint32_t height, gpu_texture_format_t format); void gpu_texture_destroy(gpu_texture_t *texture); void gpu_texture_destroy_internal(gpu_texture_t *texture); -void gpu_render_target_init(gpu_texture_t *target, int width, int height, gpu_texture_format_t format); -void gpu_render_target_init2(gpu_texture_t *render_target, int width, int height, gpu_texture_format_t format, int framebuffer_index); -void gpu_vertex_buffer_init(gpu_buffer_t *buffer, int count, gpu_vertex_structure_t *structure); +void gpu_render_target_init(gpu_texture_t *target, uint32_t width, uint32_t height, gpu_texture_format_t format); +void gpu_render_target_init2(gpu_texture_t *render_target, uint32_t width, uint32_t height, gpu_texture_format_t format, int framebuffer_index); +void gpu_vertex_buffer_init(gpu_buffer_t *buffer, uint32_t count, gpu_vertex_structure_t *structure); void *gpu_vertex_buffer_lock(gpu_buffer_t *buffer); void gpu_vertex_buffer_unlock(gpu_buffer_t *buffer); -void gpu_constant_buffer_init(gpu_buffer_t *buffer, int size); -void gpu_constant_buffer_lock(gpu_buffer_t *buffer, int start, int count); +void gpu_constant_buffer_init(gpu_buffer_t *buffer, uint32_t size); +void gpu_constant_buffer_lock(gpu_buffer_t *buffer, uint32_t start, uint32_t count); void gpu_constant_buffer_unlock(gpu_buffer_t *buffer); -void gpu_index_buffer_init(gpu_buffer_t *buffer, int count); +void gpu_index_buffer_init(gpu_buffer_t *buffer, uint32_t count); void gpu_buffer_destroy(gpu_buffer_t *buffer); void gpu_buffer_destroy_internal(gpu_buffer_t *buffer); void *gpu_index_buffer_lock(gpu_buffer_t *buffer); @@ -223,9 +223,9 @@ void gpu_set_pipeline(gpu_pipeline_t *pipeline); void gpu_set_pipeline_internal(gpu_pipeline_t *pipeline); void gpu_set_vertex_buffer(gpu_buffer_t *buffer); void gpu_set_index_buffer(gpu_buffer_t *buffer); -void gpu_set_constant_buffer(gpu_buffer_t *buffer, int offset, size_t size); +void gpu_set_constant_buffer(gpu_buffer_t *buffer, uint32_t offset, size_t size); void gpu_get_render_target_pixels(gpu_texture_t *render_target, uint8_t *data); -void gpu_set_texture(int unit, gpu_texture_t *texture); +void gpu_set_texture(uint32_t unit, gpu_texture_t *texture); void gpu_use_linear_sampling(bool b); char *gpu_device_name(); bool gpu_bc7_supported(int width, int height, gpu_texture_format_t format); @@ -256,17 +256,17 @@ void gpu_raytrace_set_textures(gpu_texture_t *tex0, gpu_texture_t *tex1, gpu_tex gpu_texture_t *texscramble, gpu_texture_t *texrank); void _gpu_raytrace_dispatch_rays(gpu_texture_t *render_target, buffer_t *buffer); -int gpu_vertex_data_size(gpu_vertex_data_t data); -int gpu_vertex_struct_size(gpu_vertex_structure_t *s); -int gpu_texture_format_size(gpu_texture_format_t format); +uint32_t gpu_vertex_data_size(gpu_vertex_data_t data); +uint32_t gpu_vertex_struct_size(gpu_vertex_structure_t *s); +uint32_t gpu_texture_format_size(gpu_texture_format_t format); extern bool gpu_in_use; extern gpu_texture_t *current_textures[GPU_MAX_TEXTURES]; extern gpu_texture_t *current_render_targets[8]; -extern int current_render_targets_count; +extern uint32_t current_render_targets_count; extern gpu_texture_t *current_depth_buffer; extern gpu_pipeline_t *current_pipeline; -extern int constant_buffer_index; +extern uint32_t constant_buffer_index; extern gpu_texture_t framebuffers[GPU_FRAMEBUFFER_COUNT]; extern gpu_texture_t framebuffer_depth; -extern int framebuffer_index; +extern uint32_t framebuffer_index;