|
|
|
|
@ -322,23 +322,37 @@ VkResult create_layer(
|
|
|
|
|
VkResult result;
|
|
|
|
|
|
|
|
|
|
uint32_t max_strings = (input->num_strings > input->max_strings) ? input->num_strings : input->max_strings;
|
|
|
|
|
uint32_t max_codes = (input->num_codes > input->max_codes) ? input->num_codes : input->max_codes;
|
|
|
|
|
uint32_t max_drawables = (input->num_drawables > input->max_drawables) ? input->num_drawables : input->max_drawables;
|
|
|
|
|
|
|
|
|
|
uint32_t total_max_codes = 0;
|
|
|
|
|
for(uint32_t s = 0; s < input->num_strings; s++) {
|
|
|
|
|
total_max_codes += input->strings[s].max_length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(max_strings > 0) {
|
|
|
|
|
container->layers[index].strings_buffer = malloc(sizeof(GPUString)*max_strings);
|
|
|
|
|
container->layers[index].string_resources = malloc(sizeof(StringResources)*max_strings);
|
|
|
|
|
memset(container->layers[index].string_resources, 0, sizeof(StringResources)*max_strings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(max_drawables > 0) {
|
|
|
|
|
container->layers[index].drawables_buffer = malloc(sizeof(GPUDrawable)*max_drawables);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(max_codes > 0) {
|
|
|
|
|
container->layers[index].codes_buffer = malloc(sizeof(uint32_t)*max_codes);
|
|
|
|
|
for(uint32_t s = 0; s < input->num_strings; s++) {
|
|
|
|
|
uint32_t max_len = input->strings[s].max_length;
|
|
|
|
|
if(max_len == 0) continue;
|
|
|
|
|
uint32_t codes_size = ((max_len + 3) / 4) * sizeof(uint32_t);
|
|
|
|
|
container->layers[index].string_resources[s].codes_buffer = malloc(codes_size);
|
|
|
|
|
memset(container->layers[index].string_resources[s].codes_buffer, 0, codes_size);
|
|
|
|
|
for(uint32_t f = 0; f < MAX_FRAMES_IN_FLIGHT; f++) {
|
|
|
|
|
VK_RESULT(create_storage_buffer(gpu->allocator, 0, codes_size,
|
|
|
|
|
&container->layers[index].string_resources[s].codes[f],
|
|
|
|
|
&container->layers[index].string_resources[s].codes_memory[f]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(uint32_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
|
|
|
|
|
|
|
|
|
|
VK_RESULT(create_storage_buffer(gpu->allocator, VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT, sizeof(GPULayer), &container->layers[index].layer[i], &container->layers[index].layer_memory[i]));
|
|
|
|
|
if(max_strings > 0) {
|
|
|
|
|
VK_RESULT(create_storage_buffer(gpu->allocator, 0, sizeof(GPUString)*max_strings, &container->layers[index].strings[i], &container->layers[index].strings_memory[i]));
|
|
|
|
|
@ -351,8 +365,8 @@ VkResult create_layer(
|
|
|
|
|
i,
|
|
|
|
|
gpu);
|
|
|
|
|
}
|
|
|
|
|
if(max_codes + max_drawables > 0) {
|
|
|
|
|
VK_RESULT(create_storage_buffer(gpu->allocator, 0, sizeof(GPUDrawable)*(max_drawables + max_codes), &container->layers[index].drawables[i], &container->layers[index].drawables_memory[i]));
|
|
|
|
|
if(total_max_codes + max_drawables > 0) {
|
|
|
|
|
VK_RESULT(create_storage_buffer(gpu->allocator, 0, sizeof(GPUDrawable)*(max_drawables + total_max_codes), &container->layers[index].drawables[i], &container->layers[index].drawables_memory[i]));
|
|
|
|
|
VkDeviceAddress address = buffer_address(gpu->device, container->layers[index].drawables[i]);
|
|
|
|
|
add_transfer(
|
|
|
|
|
&address,
|
|
|
|
|
@ -362,17 +376,6 @@ VkResult create_layer(
|
|
|
|
|
i,
|
|
|
|
|
gpu);
|
|
|
|
|
}
|
|
|
|
|
if(max_codes > 0) {
|
|
|
|
|
VK_RESULT(create_storage_buffer(gpu->allocator, 0, sizeof(uint32_t)*max_codes, &container->layers[index].codes[i], &container->layers[index].codes_memory[i]));
|
|
|
|
|
VkDeviceAddress address = buffer_address(gpu->device, container->layers[index].codes[i]);
|
|
|
|
|
add_transfer(
|
|
|
|
|
&address,
|
|
|
|
|
container->layers[index].layer[i],
|
|
|
|
|
offsetof(GPULayer, codes),
|
|
|
|
|
sizeof(VkDeviceAddress),
|
|
|
|
|
i,
|
|
|
|
|
gpu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
container->layers[index].address[i] = buffer_address(gpu->device, container->layers[index].layer[i]);
|
|
|
|
|
}
|
|
|
|
|
@ -396,15 +399,31 @@ VkResult create_layer(
|
|
|
|
|
container->layers[index].data.dispatch_strings.y = 1;
|
|
|
|
|
container->layers[index].data.dispatch_strings.z = 1;
|
|
|
|
|
|
|
|
|
|
container->layers[index].data.max_drawables = max_drawables + max_codes;
|
|
|
|
|
container->layers[index].data.max_drawables = max_drawables + total_max_codes;
|
|
|
|
|
container->layers[index].data.max_strings = max_strings;
|
|
|
|
|
container->layers[index].data.max_codes = max_codes;
|
|
|
|
|
container->layers[index].data.num_drawables = max_drawables;
|
|
|
|
|
add_transfers(&container->layers[index].data, container->layers[index].layer, 0, sizeof(GPULayer)-4*sizeof(VkDeviceAddress), gpu);
|
|
|
|
|
add_transfers(&container->layers[index].data, container->layers[index].layer, 0, sizeof(GPULayer)-3*sizeof(VkDeviceAddress), gpu);
|
|
|
|
|
|
|
|
|
|
if(input->num_strings > 0) {
|
|
|
|
|
memcpy(container->layers[index].strings_buffer, input->strings, sizeof(GPUString)*input->num_strings);
|
|
|
|
|
for(uint32_t s = 0; s < input->num_strings; s++) {
|
|
|
|
|
container->layers[index].strings_buffer[s].codes = 0;
|
|
|
|
|
}
|
|
|
|
|
add_transfers(container->layers[index].strings_buffer, container->layers[index].strings, 0, sizeof(GPUString)*input->num_strings, gpu);
|
|
|
|
|
|
|
|
|
|
for(uint32_t s = 0; s < input->num_strings; s++) {
|
|
|
|
|
if(input->strings[s].max_length == 0) continue;
|
|
|
|
|
for(uint32_t f = 0; f < MAX_FRAMES_IN_FLIGHT; f++) {
|
|
|
|
|
VkDeviceAddress addr = buffer_address(gpu->device, container->layers[index].string_resources[s].codes[f]);
|
|
|
|
|
add_transfer(
|
|
|
|
|
&addr,
|
|
|
|
|
container->layers[index].strings[f],
|
|
|
|
|
s * sizeof(GPUString) + offsetof(GPUString, codes),
|
|
|
|
|
sizeof(VkDeviceAddress),
|
|
|
|
|
f,
|
|
|
|
|
gpu);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(input->num_drawables > 0) {
|
|
|
|
|
@ -412,11 +431,6 @@ VkResult create_layer(
|
|
|
|
|
add_transfers(container->layers[index].drawables_buffer, container->layers[index].drawables, 0, sizeof(GPUDrawable)*input->num_drawables, gpu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(input->num_codes > 0) {
|
|
|
|
|
memcpy(container->layers[index].codes_buffer, input->codes, sizeof(uint32_t)*input->num_codes);
|
|
|
|
|
add_transfers(container->layers[index].codes_buffer, container->layers[index].codes, 0, sizeof(uint32_t)*input->num_codes, gpu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -1170,14 +1184,13 @@ VkResult create_ui_context(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkResult map_string(
|
|
|
|
|
const char * text,
|
|
|
|
|
const char* text,
|
|
|
|
|
uint32_t* buffer,
|
|
|
|
|
uint32_t offset,
|
|
|
|
|
uint32_t font,
|
|
|
|
|
UIContext* context) {
|
|
|
|
|
size_t i = 0;
|
|
|
|
|
memset((uint8_t*)buffer + offset, 0, strlen(text));
|
|
|
|
|
while(text[i] != '\0') {
|
|
|
|
|
size_t len = strlen(text);
|
|
|
|
|
memset(buffer, 0, ((len + 3) / 4) * sizeof(uint32_t));
|
|
|
|
|
for(size_t i = 0; i < len; i++) {
|
|
|
|
|
uint32_t mapped = 0xFFFFFFFF;
|
|
|
|
|
for(uint32_t j = 0; j < context->fonts[font].num_symbols; j++) {
|
|
|
|
|
if(context->fonts[font].charmap[j] == (uint32_t)text[i]) {
|
|
|
|
|
@ -1188,10 +1201,8 @@ VkResult map_string(
|
|
|
|
|
if(mapped == 0xFFFFFFFF) {
|
|
|
|
|
return VK_ERROR_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
buffer[(i + offset)/4] += mapped << ((i + offset) % 4)*8;
|
|
|
|
|
i += 1;
|
|
|
|
|
buffer[i/4] |= mapped << (i % 4)*8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -1222,21 +1233,20 @@ VkResult update_ui_string(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Layer* layer = &container->layers[layer_index];
|
|
|
|
|
layer->strings_buffer[string_index].length = strlen(string);
|
|
|
|
|
if(strlen(string) > 0) {
|
|
|
|
|
VK_RESULT(map_string(
|
|
|
|
|
string,
|
|
|
|
|
layer->codes_buffer,
|
|
|
|
|
layer->strings_buffer[string_index].offset,
|
|
|
|
|
layer->strings_buffer[string_index].font,
|
|
|
|
|
ui));
|
|
|
|
|
VK_RESULT(add_transfers(
|
|
|
|
|
(uint8_t*)layer->codes_buffer + layer->strings_buffer[string_index].offset,
|
|
|
|
|
layer->codes,
|
|
|
|
|
layer->strings_buffer[string_index].offset,
|
|
|
|
|
strlen(string),
|
|
|
|
|
gpu));
|
|
|
|
|
StringResources* sr = &layer->string_resources[string_index];
|
|
|
|
|
uint32_t len = strlen(string);
|
|
|
|
|
|
|
|
|
|
if(len > layer->strings_buffer[string_index].max_length) {
|
|
|
|
|
len = layer->strings_buffer[string_index].max_length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
layer->strings_buffer[string_index].length = len;
|
|
|
|
|
|
|
|
|
|
if(len > 0) {
|
|
|
|
|
VK_RESULT(map_string(string, sr->codes_buffer, layer->strings_buffer[string_index].font, ui));
|
|
|
|
|
VK_RESULT(add_transfers(sr->codes_buffer, sr->codes, 0, ((len + 3) / 4) * sizeof(uint32_t), gpu));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VK_RESULT(add_transfers(
|
|
|
|
|
&layer->strings_buffer[string_index].length,
|
|
|
|
|
layer->strings,
|
|
|
|
|
|