mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-22 11:57:00 +00:00
Vulkan Example: Some code layout changes.
This commit is contained in:
parent
4ea4fa3e73
commit
1394616d9c
@ -228,7 +228,7 @@ static uint32_t ImGui_ImplGlfwVulkan_MemoryType(VkMemoryPropertyFlags properties
|
|||||||
if((prop.memoryTypes[i].propertyFlags & properties) == properties &&
|
if((prop.memoryTypes[i].propertyFlags & properties) == properties &&
|
||||||
type_bits & (1<<i))
|
type_bits & (1<<i))
|
||||||
return i;
|
return i;
|
||||||
return 0;
|
return 0xffffffff; // Unable to find memoryType
|
||||||
}
|
}
|
||||||
static void ImGui_ImplGlfwVulkan_VkResult(VkResult err)
|
static void ImGui_ImplGlfwVulkan_VkResult(VkResult err)
|
||||||
{
|
{
|
||||||
@ -603,27 +603,24 @@ bool ImGui_ImplGlfwVulkan_CreateFontsTexture(VkCommandBuffer command_buffer)
|
|||||||
ImGui_ImplGlfwVulkan_VkResult(err);
|
ImGui_ImplGlfwVulkan_VkResult(err);
|
||||||
vkUnmapMemory(g_Device, g_UploadBufferMemory);
|
vkUnmapMemory(g_Device, g_UploadBufferMemory);
|
||||||
}
|
}
|
||||||
// Upload Barrier:
|
// Copy to Image:
|
||||||
{
|
{
|
||||||
VkImageMemoryBarrier image_barrier[1] = {};
|
VkImageMemoryBarrier copy_barrier[1] = {};
|
||||||
image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
copy_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||||
image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
copy_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||||
image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
copy_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
copy_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
||||||
image_barrier[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
copy_barrier[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||||
image_barrier[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
copy_barrier[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||||
image_barrier[0].image = g_FontImage;
|
copy_barrier[0].image = g_FontImage;
|
||||||
image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
copy_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
image_barrier[0].subresourceRange.levelCount = 1;
|
copy_barrier[0].subresourceRange.levelCount = 1;
|
||||||
image_barrier[0].subresourceRange.layerCount = 1;
|
copy_barrier[0].subresourceRange.layerCount = 1;
|
||||||
vkCmdPipelineBarrier(command_buffer,
|
vkCmdPipelineBarrier(command_buffer,
|
||||||
VK_PIPELINE_STAGE_HOST_BIT,
|
VK_PIPELINE_STAGE_HOST_BIT,
|
||||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||||
0,
|
0,
|
||||||
0, NULL, 0, NULL, 1, image_barrier);
|
0, NULL, 0, NULL, 1, copy_barrier);
|
||||||
}
|
|
||||||
// Copy to Image:
|
|
||||||
{
|
|
||||||
VkBufferImageCopy region = {};
|
VkBufferImageCopy region = {};
|
||||||
region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
region.imageSubresource.layerCount = 1;
|
region.imageSubresource.layerCount = 1;
|
||||||
@ -634,26 +631,23 @@ bool ImGui_ImplGlfwVulkan_CreateFontsTexture(VkCommandBuffer command_buffer)
|
|||||||
g_FontImage,
|
g_FontImage,
|
||||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||||
1, ®ion);
|
1, ®ion);
|
||||||
}
|
VkImageMemoryBarrier use_barrier[1] = {};
|
||||||
// Usage Barrier:
|
use_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||||
{
|
use_barrier[0].srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||||
VkImageMemoryBarrier image_barrier[1] = {};
|
use_barrier[0].dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
|
||||||
image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
use_barrier[0].oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
||||||
image_barrier[0].srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
use_barrier[0].newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||||
image_barrier[0].dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
|
use_barrier[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||||
image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
use_barrier[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||||
image_barrier[0].newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
use_barrier[0].image = g_FontImage;
|
||||||
image_barrier[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
use_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
image_barrier[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
use_barrier[0].subresourceRange.levelCount = 1;
|
||||||
image_barrier[0].image = g_FontImage;
|
use_barrier[0].subresourceRange.layerCount = 1;
|
||||||
image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
|
||||||
image_barrier[0].subresourceRange.levelCount = 1;
|
|
||||||
image_barrier[0].subresourceRange.layerCount = 1;
|
|
||||||
vkCmdPipelineBarrier(command_buffer,
|
vkCmdPipelineBarrier(command_buffer,
|
||||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||||
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
|
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
|
||||||
0,
|
0,
|
||||||
0, NULL, 0, NULL, 1, image_barrier);
|
0, NULL, 0, NULL, 1, use_barrier);
|
||||||
}
|
}
|
||||||
io.Fonts->TexID = (void *)(intptr_t)g_FontImage;
|
io.Fonts->TexID = (void *)(intptr_t)g_FontImage;
|
||||||
|
|
||||||
@ -685,7 +679,6 @@ bool ImGui_ImplGlfwVulkan_CreateDeviceObjects()
|
|||||||
err = vkCreateShaderModule(g_Device, &frag_info, g_Allocator, &frag_module);
|
err = vkCreateShaderModule(g_Device, &frag_info, g_Allocator, &frag_module);
|
||||||
ImGui_ImplGlfwVulkan_VkResult(err);
|
ImGui_ImplGlfwVulkan_VkResult(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!g_FontSampler){
|
if(!g_FontSampler){
|
||||||
VkSamplerCreateInfo info = {};
|
VkSamplerCreateInfo info = {};
|
||||||
info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
|
info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
|
||||||
@ -703,7 +696,6 @@ bool ImGui_ImplGlfwVulkan_CreateDeviceObjects()
|
|||||||
&g_FontSampler);
|
&g_FontSampler);
|
||||||
ImGui_ImplGlfwVulkan_VkResult(err);
|
ImGui_ImplGlfwVulkan_VkResult(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!g_DescriptorSetLayout){
|
if(!g_DescriptorSetLayout){
|
||||||
VkSampler sampler[1] = {g_FontSampler};
|
VkSampler sampler[1] = {g_FontSampler};
|
||||||
VkDescriptorSetLayoutBinding binding[1] = {};
|
VkDescriptorSetLayoutBinding binding[1] = {};
|
||||||
@ -721,6 +713,7 @@ bool ImGui_ImplGlfwVulkan_CreateDeviceObjects()
|
|||||||
&g_DescriptorSetLayout);
|
&g_DescriptorSetLayout);
|
||||||
ImGui_ImplGlfwVulkan_VkResult(err);
|
ImGui_ImplGlfwVulkan_VkResult(err);
|
||||||
}
|
}
|
||||||
|
// Create Descriptor Set:
|
||||||
{
|
{
|
||||||
VkDescriptorSetAllocateInfo alloc_info = {};
|
VkDescriptorSetAllocateInfo alloc_info = {};
|
||||||
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
||||||
|
Loading…
Reference in New Issue
Block a user