|
|
@ -438,7 +438,7 @@ VkResult create_text_descriptor_pool(VkDevice device, uint32_t max_sets, VkDescr
|
|
|
|
return VK_SUCCESS;
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VkResult create_text_descriptor(VkDevice device, VmaAllocator allocator, VkDescriptorSetLayout layout, VkDescriptorPool pool, FontData* font, VkCommandPool transfer_pool, Queue transfer_queue, VmaAllocation* uniform_memory, VkBuffer* uniform, VmaAllocation* image_memory, VkImage* image, VkImageView* view, VkSampler* sampler, VkDescriptorSet* set) {
|
|
|
|
VkResult create_text_descriptor(VkDevice device, VmaAllocator allocator, VkDescriptorSetLayout layout, VkDescriptorPool pool, FontData* font, VkCommandPool transfer_pool, Queue transfer_queue, FontDescriptor* descriptor) {
|
|
|
|
VkResult result;
|
|
|
|
VkResult result;
|
|
|
|
VkDescriptorSetAllocateInfo set_allocate_info = {
|
|
|
|
VkDescriptorSetAllocateInfo set_allocate_info = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
|
|
|
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
|
|
|
@ -447,7 +447,7 @@ VkResult create_text_descriptor(VkDevice device, VmaAllocator allocator, VkDescr
|
|
|
|
.descriptorPool = pool,
|
|
|
|
.descriptorPool = pool,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
result = vkAllocateDescriptorSets(device, &set_allocate_info, set);
|
|
|
|
result = vkAllocateDescriptorSets(device, &set_allocate_info, &descriptor->set);
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -463,14 +463,14 @@ VkResult create_text_descriptor(VkDevice device, VmaAllocator allocator, VkDescr
|
|
|
|
.usage = VMA_MEMORY_USAGE_GPU_ONLY,
|
|
|
|
.usage = VMA_MEMORY_USAGE_GPU_ONLY,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
result = vmaCreateBuffer(allocator, &uniform_buffer_info, &uniform_memory_info, uniform, uniform_memory, NULL);
|
|
|
|
result = vmaCreateBuffer(allocator, &uniform_buffer_info, &uniform_memory_info, &descriptor->uniform, &descriptor->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,
|
|
|
|
.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
|
|
|
|
.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
|
|
|
|
.extent.depth = 1,
|
|
|
|
.extent.depth = 1,
|
|
|
|
.extent.width = font->info.size[0]*font->info.columns,
|
|
|
|
.extent.width = font->info.size[0]*font->info.cols,
|
|
|
|
.extent.height = font->info.size[1]*font->rows,
|
|
|
|
.extent.height = font->info.size[1]*font->info.rows,
|
|
|
|
.mipLevels = 1,
|
|
|
|
.mipLevels = 1,
|
|
|
|
.arrayLayers = 1,
|
|
|
|
.arrayLayers = 1,
|
|
|
|
.format = VK_FORMAT_R8G8B8A8_SRGB,
|
|
|
|
.format = VK_FORMAT_R8G8B8A8_SRGB,
|
|
|
@ -483,16 +483,17 @@ VkResult create_text_descriptor(VkDevice device, VmaAllocator allocator, VkDescr
|
|
|
|
.usage = VMA_MEMORY_USAGE_GPU_ONLY,
|
|
|
|
.usage = VMA_MEMORY_USAGE_GPU_ONLY,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
result = vmaCreateImage(allocator, &image_info, &image_memory_info, image, image_memory, NULL);
|
|
|
|
result = vmaCreateImage(allocator, &image_info, &image_memory_info, &descriptor->image, &descriptor->image_memory, NULL);
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t image_size = sizeof(uint32_t)*font->info.rows*font->info.size[0]*font->info.cols*font->info.size[1];
|
|
|
|
VkBufferCreateInfo staging_info = {
|
|
|
|
VkBufferCreateInfo staging_info = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
|
|
|
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
|
|
|
.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
|
|
|
|
.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
|
|
|
|
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
|
|
|
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
|
|
|
.size = sizeof(FontUniform) + 4*image_info.extent.width*image_info.extent.height,
|
|
|
|
.size = sizeof(FontUniform) + image_size,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
VmaAllocationCreateInfo staging_memory_info = {
|
|
|
|
VmaAllocationCreateInfo staging_memory_info = {
|
|
|
@ -511,22 +512,22 @@ VkResult create_text_descriptor(VkDevice device, VmaAllocator allocator, VkDescr
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
memcpy(mapped_staging, &font->info, sizeof(FontUniform));
|
|
|
|
memcpy(mapped_staging + image_size, &font->info, sizeof(FontUniform));
|
|
|
|
memcpy(mapped_staging + sizeof(FontUniform), font->data, 4*font->rows*font->info.columns);
|
|
|
|
memcpy(mapped_staging, font->data, image_size);
|
|
|
|
vmaUnmapMemory(allocator, staging_memory);
|
|
|
|
vmaUnmapMemory(allocator, staging_memory);
|
|
|
|
|
|
|
|
|
|
|
|
VkCommandBuffer command_buffer = command_begin_single(device, transfer_pool);
|
|
|
|
VkCommandBuffer command_buffer = command_begin_single(device, transfer_pool);
|
|
|
|
|
|
|
|
|
|
|
|
VkBufferCopy copy_info = {
|
|
|
|
VkBufferCopy copy_info = {
|
|
|
|
.size = sizeof(FontUniform),
|
|
|
|
.size = sizeof(FontUniform),
|
|
|
|
.srcOffset = 0,
|
|
|
|
.srcOffset = image_size,
|
|
|
|
.dstOffset = 0,
|
|
|
|
.dstOffset = 0,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
vkCmdCopyBuffer(command_buffer, staging_buffer, *uniform, 1, ©_info);
|
|
|
|
vkCmdCopyBuffer(command_buffer, staging_buffer, descriptor->uniform, 1, ©_info);
|
|
|
|
|
|
|
|
|
|
|
|
VkImageMemoryBarrier first_barrier = {
|
|
|
|
VkImageMemoryBarrier first_barrier = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
|
|
|
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
|
|
|
.image = *image,
|
|
|
|
.image = descriptor->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,
|
|
|
@ -543,13 +544,12 @@ VkResult create_text_descriptor(VkDevice device, VmaAllocator allocator, VkDescr
|
|
|
|
.imageSubresource.layerCount = 1,
|
|
|
|
.imageSubresource.layerCount = 1,
|
|
|
|
.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
|
|
|
.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
|
|
|
.imageExtent = image_info.extent,
|
|
|
|
.imageExtent = image_info.extent,
|
|
|
|
.bufferOffset = sizeof(FontUniform),
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
vkCmdCopyBufferToImage(command_buffer, staging_buffer, *image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &image_copy);
|
|
|
|
vkCmdCopyBufferToImage(command_buffer, staging_buffer, descriptor->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 = *image,
|
|
|
|
.image = descriptor->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,
|
|
|
@ -570,7 +570,7 @@ VkResult create_text_descriptor(VkDevice device, VmaAllocator allocator, VkDescr
|
|
|
|
|
|
|
|
|
|
|
|
VkImageViewCreateInfo view_info = {
|
|
|
|
VkImageViewCreateInfo view_info = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
|
|
|
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
|
|
|
.image = *image,
|
|
|
|
.image = descriptor->image,
|
|
|
|
.viewType = VK_IMAGE_VIEW_TYPE_2D,
|
|
|
|
.viewType = VK_IMAGE_VIEW_TYPE_2D,
|
|
|
|
.format = VK_FORMAT_R8G8B8A8_SRGB,
|
|
|
|
.format = VK_FORMAT_R8G8B8A8_SRGB,
|
|
|
|
.subresourceRange = {
|
|
|
|
.subresourceRange = {
|
|
|
@ -580,7 +580,7 @@ VkResult create_text_descriptor(VkDevice device, VmaAllocator allocator, VkDescr
|
|
|
|
.baseArrayLayer = 0,
|
|
|
|
.baseArrayLayer = 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
result = vkCreateImageView(device, &view_info, NULL, view);
|
|
|
|
result = vkCreateImageView(device, &view_info, NULL, &descriptor->view);
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -593,7 +593,7 @@ VkResult create_text_descriptor(VkDevice device, VmaAllocator allocator, VkDescr
|
|
|
|
.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, sampler);
|
|
|
|
result = vkCreateSampler(device, &sampler_info, NULL, &descriptor->sampler);
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -601,19 +601,19 @@ VkResult create_text_descriptor(VkDevice device, VmaAllocator allocator, VkDescr
|
|
|
|
VkDescriptorBufferInfo desc_uniform_info = {
|
|
|
|
VkDescriptorBufferInfo desc_uniform_info = {
|
|
|
|
.offset = 0,
|
|
|
|
.offset = 0,
|
|
|
|
.range = sizeof(FontUniform),
|
|
|
|
.range = sizeof(FontUniform),
|
|
|
|
.buffer = *uniform,
|
|
|
|
.buffer = descriptor->uniform,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
VkDescriptorImageInfo desc_image_info = {
|
|
|
|
VkDescriptorImageInfo desc_image_info = {
|
|
|
|
.sampler = *sampler,
|
|
|
|
.sampler = descriptor->sampler,
|
|
|
|
.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
|
|
|
.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
|
|
|
.imageView = *view,
|
|
|
|
.imageView = descriptor->view,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
VkWriteDescriptorSet descriptor_writes[] = {
|
|
|
|
VkWriteDescriptorSet descriptor_writes[] = {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
|
|
|
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
|
|
|
.dstSet = *set,
|
|
|
|
.dstSet = descriptor->set,
|
|
|
|
.dstBinding = 0,
|
|
|
|
.dstBinding = 0,
|
|
|
|
.dstArrayElement = 0,
|
|
|
|
.dstArrayElement = 0,
|
|
|
|
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
|
|
|
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
|
|
@ -622,7 +622,7 @@ VkResult create_text_descriptor(VkDevice device, VmaAllocator allocator, VkDescr
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
|
|
|
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
|
|
|
.dstSet = *set,
|
|
|
|
.dstSet = descriptor->set,
|
|
|
|
.dstBinding = 1,
|
|
|
|
.dstBinding = 1,
|
|
|
|
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
|
|
|
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
|
|
|
.descriptorCount = 1,
|
|
|
|
.descriptorCount = 1,
|
|
|
@ -841,13 +841,6 @@ VkResult create_ui_rect_buffer(VkDevice device, Queue transfer_queue, VkCommandP
|
|
|
|
return VK_SUCCESS;
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define WHITE {1.0f, 1.0f, 1.0f, 1.0f}
|
|
|
|
|
|
|
|
#define CLEAR {0.0f, 0.0f, 0.0f, 0.0f}
|
|
|
|
|
|
|
|
vec4 test_font_data[] = {
|
|
|
|
|
|
|
|
WHITE, WHITE, CLEAR, WHITE,
|
|
|
|
|
|
|
|
CLEAR, CLEAR, WHITE, CLEAR,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VkResult init_pipelines(VkDevice device, VmaAllocator allocator, VkExtent2D swapchain_extent, VkRenderPass render_pass, Queue transfer_queue, VkCommandPool transfer_pool, UIContext* context) {
|
|
|
|
VkResult init_pipelines(VkDevice device, VmaAllocator allocator, VkExtent2D swapchain_extent, VkRenderPass render_pass, Queue transfer_queue, VkCommandPool transfer_pool, UIContext* context) {
|
|
|
|
|
|
|
|
|
|
|
|
VkResult result;
|
|
|
|
VkResult result;
|
|
|
@ -876,20 +869,5 @@ VkResult init_pipelines(VkDevice device, VmaAllocator allocator, VkExtent2D swap
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FontData test_font = {
|
|
|
|
|
|
|
|
.info = {
|
|
|
|
|
|
|
|
.size = {4, 4},
|
|
|
|
|
|
|
|
.start = 0,
|
|
|
|
|
|
|
|
.columns = 2,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
.rows = 1,
|
|
|
|
|
|
|
|
.data = test_font_data,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = create_text_descriptor(device, allocator, context->font_layout, context->font_pool, &test_font, transfer_pool, transfer_queue, &context->test_font_uniform_memory, &context->test_font_uniform, &context->test_font_image_memory, &context->test_font_image, &context->test_font_view, &context->test_font_sampler, &context->test_font_set);
|
|
|
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|