From 130c6538b22db87d4501c5584ac6f09a631d94c1 Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Mon, 21 Oct 2024 13:39:12 -0600 Subject: [PATCH] Added host mirrors of UI data for logic --- client/include/ui.h | 6 ++++++ client/shader_src/ui_common.glsl | 2 ++ client/src/main.c | 3 +++ client/src/ui.c | 8 +++++++- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/client/include/ui.h b/client/include/ui.h index 6239d89..8ffd7ed 100644 --- a/client/include/ui.h +++ b/client/include/ui.h @@ -73,6 +73,7 @@ typedef struct UIStringStruct { float size; uint32_t offset; uint32_t length; + uint32_t id; } UIString; typedef struct UIDrawableStruct { @@ -81,6 +82,7 @@ typedef struct UIDrawableStruct { vec4 color; uint32_t type; uint32_t code; + uint32_t id; } UIDrawable; typedef struct UILayerStruct { @@ -114,6 +116,10 @@ typedef struct UIlayerStorageStruct { VkDeviceAddress address; + UIDrawable* drawables_buffer; + UIString* strings_buffer; + uint32_t* codes_buffer; + UILayer data; } UILayerStorage; diff --git a/client/shader_src/ui_common.glsl b/client/shader_src/ui_common.glsl index ac43abf..f739d3c 100644 --- a/client/shader_src/ui_common.glsl +++ b/client/shader_src/ui_common.glsl @@ -44,6 +44,7 @@ struct String { float size; uint offset; uint len; + uint id; }; layout(std430, buffer_reference) readonly buffer StringList { @@ -60,6 +61,7 @@ struct Drawable { vec4 color; uint type; uint code; + uint id; }; layout(std430, buffer_reference) readonly buffer DrawableList { diff --git a/client/src/main.c b/client/src/main.c index 30bb996..b825bd9 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -44,6 +44,7 @@ VkResult render_thread(GLFWwindow* window, RenderContext* render) { .color = {1.0, 1.0, 1.0, 1.0}, .type = 2, .code = 0, + .id = 0x01, }; UIDrawable rect = { @@ -51,6 +52,7 @@ VkResult render_thread(GLFWwindow* window, RenderContext* render) { .size = {100.0, 200.0}, .color = {1.0, 0.0, 0.0, 1.0}, .type = 0, + .id = 0x02, }; UIString string = { @@ -59,6 +61,7 @@ VkResult render_thread(GLFWwindow* window, RenderContext* render) { .size = 32.0, .length = strlen("Hello, World!"), .offset = 0, + .id = 0x03, }; UILayerInput layers[] = { diff --git a/client/src/ui.c b/client/src/ui.c index 114a7d8..4d803b2 100644 --- a/client/src/ui.c +++ b/client/src/ui.c @@ -324,13 +324,16 @@ VkResult create_layer( VK_RESULT(create_storage_buffer(gpu->allocator, VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT, sizeof(UILayer), &container->layers[index].layer, &container->layers[index].layer_memory)); if(input->num_strings > 0) { - VK_RESULT(create_storage_buffer(gpu->allocator, 0, sizeof(UIString)*input->num_strings, &container->layers[index].strings, &container->layers[index].strings_memory)) + VK_RESULT(create_storage_buffer(gpu->allocator, 0, sizeof(UIString)*input->num_strings, &container->layers[index].strings, &container->layers[index].strings_memory)); + container->layers[index].strings_buffer = malloc(sizeof(UIString)*input->num_strings); } if(input->num_codes + input->num_drawables > 0) { VK_RESULT(create_storage_buffer(gpu->allocator, 0, sizeof(UIDrawable)*(input->num_drawables + input->num_codes), &container->layers[index].drawables, &container->layers[index].drawables_memory)); + container->layers[index].drawables_buffer = malloc(sizeof(UIDrawable)*input->num_drawables); } if(input->num_codes > 0) { VK_RESULT(create_storage_buffer(gpu->allocator, 0, sizeof(uint32_t)*input->num_codes, &container->layers[index].codes, &container->layers[index].codes_memory)); + container->layers[index].codes_buffer = malloc(sizeof(uint32_t)*input->num_codes); } VkBuffer transfer; @@ -379,6 +382,7 @@ VkResult create_layer( UIString* strings = (UIString*)(mapped + sizeof(UILayer)); for(uint32_t i = 0; i < input->num_strings; i++) { memcpy(&strings[i], &input->strings[i], sizeof(UIString)); + memcpy(&container->layers[index].strings_buffer[i], &input->strings[i], sizeof(UIString)); } command_copy_buffer(command_buffer, transfer, container->layers[index].strings, sizeof(UILayer), 0, sizeof(UIString)*input->num_strings); } @@ -387,6 +391,7 @@ VkResult create_layer( UIDrawable* drawables = (UIDrawable*)(mapped + sizeof(UILayer) + sizeof(UIString)*input->num_strings); for(uint32_t i = 0; i < input->num_drawables; i++) { memcpy(&drawables[i], &input->drawables[i], sizeof(UIDrawable)); + memcpy(&container->layers[index].drawables_buffer[i], &input->drawables[i], sizeof(UIDrawable)); } command_copy_buffer(command_buffer, transfer, container->layers[index].drawables, sizeof(UILayer) + sizeof(UIString)*input->num_strings, 0, sizeof(UIDrawable)*input->num_drawables); } @@ -395,6 +400,7 @@ VkResult create_layer( uint32_t* codes = (uint32_t*)(mapped + sizeof(UILayer) + sizeof(UIString)*input->num_strings + sizeof(UIDrawable)*input->num_drawables); for(uint32_t i = 0; i < input->num_codes; i++) { codes[i] = input->codes[i]; + container->layers[index].codes_buffer[i] = input->codes[i]; } vkCmdFillBuffer(command_buffer, container->layers[index].codes, sizeof(UIDrawable)*input->num_drawables, sizeof(UIDrawable)*input->num_codes, 0x00000000); command_copy_buffer(command_buffer, transfer, container->layers[index].codes, sizeof(UILayer) + sizeof(UIString)*input->num_strings + sizeof(UIDrawable)*input->num_drawables, 0, sizeof(uint32_t)*input->num_codes);