|
|
@ -556,7 +556,7 @@ VkResult create_text_pointers(
|
|
|
|
return VK_SUCCESS;
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VkResult load_font(VkDevice device, VmaAllocator allocator, VkDescriptorSetLayout layout, VkDescriptorPool pool,VkCommandPool transfer_pool, Queue transfer_queue, FT_Library library, const char* ttf_file, uint32_t size, VkBool32 antialias, uint32_t** charmap, FontDescriptor* descriptor) {
|
|
|
|
VkResult load_font(VkDevice device, VmaAllocator allocator, VkDescriptorSetLayout layout, VkDescriptorPool pool,VkCommandPool transfer_pool, Queue transfer_queue, FT_Library library, const char* ttf_file, uint32_t size, VkBool32 antialias, uint32_t** charmap, FontStorage* memory, VkDescriptorSet* font) {
|
|
|
|
FT_Face face;
|
|
|
|
FT_Face face;
|
|
|
|
|
|
|
|
|
|
|
|
int error;
|
|
|
|
int error;
|
|
|
@ -643,7 +643,7 @@ VkResult load_font(VkDevice device, VmaAllocator allocator, VkDescriptorSetLayou
|
|
|
|
.descriptorPool = pool,
|
|
|
|
.descriptorPool = pool,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
result = vkAllocateDescriptorSets(device, &set_allocate_info, &descriptor->set);
|
|
|
|
result = vkAllocateDescriptorSets(device, &set_allocate_info, font);
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -657,7 +657,7 @@ VkResult load_font(VkDevice device, VmaAllocator allocator, VkDescriptorSetLayou
|
|
|
|
VmaAllocationCreateInfo symbol_memory_info = {
|
|
|
|
VmaAllocationCreateInfo symbol_memory_info = {
|
|
|
|
.usage = VMA_MEMORY_USAGE_GPU_ONLY,
|
|
|
|
.usage = VMA_MEMORY_USAGE_GPU_ONLY,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
result = vmaCreateBuffer(allocator, &symbol_buffer_info, &symbol_memory_info, &descriptor->symbols, &descriptor->symbol_memory, NULL);
|
|
|
|
result = vmaCreateBuffer(allocator, &symbol_buffer_info, &symbol_memory_info, &memory->symbols, &memory->symbol_memory, NULL);
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -673,7 +673,7 @@ VkResult load_font(VkDevice device, VmaAllocator allocator, VkDescriptorSetLayou
|
|
|
|
.usage = VMA_MEMORY_USAGE_GPU_ONLY,
|
|
|
|
.usage = VMA_MEMORY_USAGE_GPU_ONLY,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
result = vmaCreateBuffer(allocator, &uniform_buffer_info, &uniform_memory_info, &descriptor->uniform, &descriptor->uniform_memory, NULL);
|
|
|
|
result = vmaCreateBuffer(allocator, &uniform_buffer_info, &uniform_memory_info, &memory->uniform, &memory->uniform_memory, NULL);
|
|
|
|
VkImageCreateInfo image_info = {
|
|
|
|
VkImageCreateInfo image_info = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
|
|
|
|
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
|
|
|
|
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
|
|
|
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
|
|
@ -694,7 +694,7 @@ VkResult load_font(VkDevice device, VmaAllocator allocator, VkDescriptorSetLayou
|
|
|
|
.usage = VMA_MEMORY_USAGE_GPU_ONLY,
|
|
|
|
.usage = VMA_MEMORY_USAGE_GPU_ONLY,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
result = vmaCreateImage(allocator, &image_info, &image_memory_info, &descriptor->image, &descriptor->image_memory, NULL);
|
|
|
|
result = vmaCreateImage(allocator, &image_info, &image_memory_info, &memory->image, &memory->image_memory, NULL);
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -725,7 +725,7 @@ VkResult load_font(VkDevice device, VmaAllocator allocator, VkDescriptorSetLayou
|
|
|
|
memcpy(mapped_staging + image_size*uniform.num_symbols + sizeof(FontUniform), symbols, sizeof(SymbolInfo)*uniform.num_symbols);
|
|
|
|
memcpy(mapped_staging + image_size*uniform.num_symbols + sizeof(FontUniform), symbols, sizeof(SymbolInfo)*uniform.num_symbols);
|
|
|
|
VkBufferDeviceAddressInfo address_info = {
|
|
|
|
VkBufferDeviceAddressInfo address_info = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO,
|
|
|
|
.sType = VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO,
|
|
|
|
.buffer = descriptor->symbols,
|
|
|
|
.buffer = memory->symbols,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
uniform.symbol_list = vkGetBufferDeviceAddress(device, &address_info);
|
|
|
|
uniform.symbol_list = vkGetBufferDeviceAddress(device, &address_info);
|
|
|
|
memcpy(mapped_staging + image_size*uniform.num_symbols, &uniform, sizeof(FontUniform));
|
|
|
|
memcpy(mapped_staging + image_size*uniform.num_symbols, &uniform, sizeof(FontUniform));
|
|
|
@ -741,18 +741,18 @@ VkResult load_font(VkDevice device, VmaAllocator allocator, VkDescriptorSetLayou
|
|
|
|
.srcOffset = image_size*uniform.num_symbols,
|
|
|
|
.srcOffset = image_size*uniform.num_symbols,
|
|
|
|
.dstOffset = 0,
|
|
|
|
.dstOffset = 0,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
vkCmdCopyBuffer(command_buffer, staging_buffer, descriptor->uniform, 1, &uniform_copy_info);
|
|
|
|
vkCmdCopyBuffer(command_buffer, staging_buffer, memory->uniform, 1, &uniform_copy_info);
|
|
|
|
|
|
|
|
|
|
|
|
VkBufferCopy symbol_copy_info = {
|
|
|
|
VkBufferCopy symbol_copy_info = {
|
|
|
|
.size = sizeof(SymbolInfo)*uniform.num_symbols,
|
|
|
|
.size = sizeof(SymbolInfo)*uniform.num_symbols,
|
|
|
|
.srcOffset = image_size*uniform.num_symbols + sizeof(FontUniform),
|
|
|
|
.srcOffset = image_size*uniform.num_symbols + sizeof(FontUniform),
|
|
|
|
.dstOffset = 0,
|
|
|
|
.dstOffset = 0,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
vkCmdCopyBuffer(command_buffer, staging_buffer, descriptor->symbols, 1, &symbol_copy_info);
|
|
|
|
vkCmdCopyBuffer(command_buffer, staging_buffer, memory->symbols, 1, &symbol_copy_info);
|
|
|
|
|
|
|
|
|
|
|
|
VkImageMemoryBarrier first_barrier = {
|
|
|
|
VkImageMemoryBarrier first_barrier = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
|
|
|
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
|
|
|
.image = descriptor->image,
|
|
|
|
.image = memory->image,
|
|
|
|
.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
|
|
|
.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
|
|
|
.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
|
|
|
.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
|
|
|
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
|
|
|
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
|
|
@ -770,11 +770,11 @@ VkResult load_font(VkDevice device, VmaAllocator allocator, VkDescriptorSetLayou
|
|
|
|
.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
|
|
|
.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
|
|
|
.imageExtent = image_info.extent,
|
|
|
|
.imageExtent = image_info.extent,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
vkCmdCopyBufferToImage(command_buffer, staging_buffer, descriptor->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &image_copy);
|
|
|
|
vkCmdCopyBufferToImage(command_buffer, staging_buffer, memory->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &image_copy);
|
|
|
|
|
|
|
|
|
|
|
|
VkImageMemoryBarrier second_barrier = {
|
|
|
|
VkImageMemoryBarrier second_barrier = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
|
|
|
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
|
|
|
.image = descriptor->image,
|
|
|
|
.image = memory->image,
|
|
|
|
.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
|
|
|
.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
|
|
|
.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
|
|
|
.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
|
|
|
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
|
|
|
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
|
|
@ -795,7 +795,7 @@ VkResult load_font(VkDevice device, VmaAllocator allocator, VkDescriptorSetLayou
|
|
|
|
|
|
|
|
|
|
|
|
VkImageViewCreateInfo view_info = {
|
|
|
|
VkImageViewCreateInfo view_info = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
|
|
|
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
|
|
|
.image = descriptor->image,
|
|
|
|
.image = memory->image,
|
|
|
|
.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY,
|
|
|
|
.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY,
|
|
|
|
.format = VK_FORMAT_R8G8B8A8_SRGB,
|
|
|
|
.format = VK_FORMAT_R8G8B8A8_SRGB,
|
|
|
|
.subresourceRange = {
|
|
|
|
.subresourceRange = {
|
|
|
@ -806,7 +806,7 @@ VkResult load_font(VkDevice device, VmaAllocator allocator, VkDescriptorSetLayou
|
|
|
|
.baseArrayLayer = 0,
|
|
|
|
.baseArrayLayer = 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
result = vkCreateImageView(device, &view_info, NULL, &descriptor->view);
|
|
|
|
result = vkCreateImageView(device, &view_info, NULL, &memory->view);
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -819,7 +819,7 @@ VkResult load_font(VkDevice device, VmaAllocator allocator, VkDescriptorSetLayou
|
|
|
|
.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT,
|
|
|
|
.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT,
|
|
|
|
.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT,
|
|
|
|
.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
result = vkCreateSampler(device, &sampler_info, NULL, &descriptor->sampler);
|
|
|
|
result = vkCreateSampler(device, &sampler_info, NULL, &memory->sampler);
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -827,19 +827,19 @@ VkResult load_font(VkDevice device, VmaAllocator allocator, VkDescriptorSetLayou
|
|
|
|
VkDescriptorBufferInfo desc_uniform_info = {
|
|
|
|
VkDescriptorBufferInfo desc_uniform_info = {
|
|
|
|
.offset = 0,
|
|
|
|
.offset = 0,
|
|
|
|
.range = sizeof(FontUniform),
|
|
|
|
.range = sizeof(FontUniform),
|
|
|
|
.buffer = descriptor->uniform,
|
|
|
|
.buffer = memory->uniform,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
VkDescriptorImageInfo desc_image_info = {
|
|
|
|
VkDescriptorImageInfo desc_image_info = {
|
|
|
|
.sampler = descriptor->sampler,
|
|
|
|
.sampler = memory->sampler,
|
|
|
|
.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
|
|
|
.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
|
|
|
.imageView = descriptor->view,
|
|
|
|
.imageView = memory->view,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
VkWriteDescriptorSet descriptor_writes[] = {
|
|
|
|
VkWriteDescriptorSet descriptor_writes[] = {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
|
|
|
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
|
|
|
.dstSet = descriptor->set,
|
|
|
|
.dstSet = *font,
|
|
|
|
.dstBinding = 0,
|
|
|
|
.dstBinding = 0,
|
|
|
|
.dstArrayElement = 0,
|
|
|
|
.dstArrayElement = 0,
|
|
|
|
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
|
|
|
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
|
|
@ -848,7 +848,7 @@ VkResult load_font(VkDevice device, VmaAllocator allocator, VkDescriptorSetLayou
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
|
|
|
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
|
|
|
.dstSet = descriptor->set,
|
|
|
|
.dstSet = *font,
|
|
|
|
.dstBinding = 1,
|
|
|
|
.dstBinding = 1,
|
|
|
|
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
|
|
|
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
|
|
|
.descriptorCount = 1,
|
|
|
|
.descriptorCount = 1,
|
|
|
|