Added host mirrors of UI data for logic

main
noah metz 2024-10-21 13:39:12 -06:00
parent 6d60a3394f
commit 130c6538b2
4 changed files with 18 additions and 1 deletions

@ -73,6 +73,7 @@ typedef struct UIStringStruct {
float size; float size;
uint32_t offset; uint32_t offset;
uint32_t length; uint32_t length;
uint32_t id;
} UIString; } UIString;
typedef struct UIDrawableStruct { typedef struct UIDrawableStruct {
@ -81,6 +82,7 @@ typedef struct UIDrawableStruct {
vec4 color; vec4 color;
uint32_t type; uint32_t type;
uint32_t code; uint32_t code;
uint32_t id;
} UIDrawable; } UIDrawable;
typedef struct UILayerStruct { typedef struct UILayerStruct {
@ -114,6 +116,10 @@ typedef struct UIlayerStorageStruct {
VkDeviceAddress address; VkDeviceAddress address;
UIDrawable* drawables_buffer;
UIString* strings_buffer;
uint32_t* codes_buffer;
UILayer data; UILayer data;
} UILayerStorage; } UILayerStorage;

@ -44,6 +44,7 @@ struct String {
float size; float size;
uint offset; uint offset;
uint len; uint len;
uint id;
}; };
layout(std430, buffer_reference) readonly buffer StringList { layout(std430, buffer_reference) readonly buffer StringList {
@ -60,6 +61,7 @@ struct Drawable {
vec4 color; vec4 color;
uint type; uint type;
uint code; uint code;
uint id;
}; };
layout(std430, buffer_reference) readonly buffer DrawableList { layout(std430, buffer_reference) readonly buffer DrawableList {

@ -44,6 +44,7 @@ VkResult render_thread(GLFWwindow* window, RenderContext* render) {
.color = {1.0, 1.0, 1.0, 1.0}, .color = {1.0, 1.0, 1.0, 1.0},
.type = 2, .type = 2,
.code = 0, .code = 0,
.id = 0x01,
}; };
UIDrawable rect = { UIDrawable rect = {
@ -51,6 +52,7 @@ VkResult render_thread(GLFWwindow* window, RenderContext* render) {
.size = {100.0, 200.0}, .size = {100.0, 200.0},
.color = {1.0, 0.0, 0.0, 1.0}, .color = {1.0, 0.0, 0.0, 1.0},
.type = 0, .type = 0,
.id = 0x02,
}; };
UIString string = { UIString string = {
@ -59,6 +61,7 @@ VkResult render_thread(GLFWwindow* window, RenderContext* render) {
.size = 32.0, .size = 32.0,
.length = strlen("Hello, World!"), .length = strlen("Hello, World!"),
.offset = 0, .offset = 0,
.id = 0x03,
}; };
UILayerInput layers[] = { UILayerInput layers[] = {

@ -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)); 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) { 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) { 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)); 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) { 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)); 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; VkBuffer transfer;
@ -379,6 +382,7 @@ VkResult create_layer(
UIString* strings = (UIString*)(mapped + sizeof(UILayer)); UIString* strings = (UIString*)(mapped + sizeof(UILayer));
for(uint32_t i = 0; i < input->num_strings; i++) { for(uint32_t i = 0; i < input->num_strings; i++) {
memcpy(&strings[i], &input->strings[i], sizeof(UIString)); 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); 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); UIDrawable* drawables = (UIDrawable*)(mapped + sizeof(UILayer) + sizeof(UIString)*input->num_strings);
for(uint32_t i = 0; i < input->num_drawables; i++) { for(uint32_t i = 0; i < input->num_drawables; i++) {
memcpy(&drawables[i], &input->drawables[i], sizeof(UIDrawable)); 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); 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); 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++) { for(uint32_t i = 0; i < input->num_codes; i++) {
codes[i] = input->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); 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); 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);