128 0x07230203,0x00010000,0x00080001,0x0000002e,0x00000000,0x00020011,0x00000001,0x0006000b,
129 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001,
130 0x000a000f,0x00000000,0x00000004,0x6e69616d,0x00000000,0x0000000b,0x0000000f,0x00000015,
131 0x0000001b,0x0000001c,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d,
132 0x00000000,0x00030005,0x00000009,0x00000000,0x00050006,0x00000009,0x00000000,0x6f6c6f43,
133 0x00000072,0x00040006,0x00000009,0x00000001,0x00005655,0x00030005,0x0000000b,0x0074754f,
134 0x00040005,0x0000000f,0x6c6f4361,0x0000726f,0x00030005,0x00000015,0x00565561,0x00060005,
135 0x00000019,0x505f6c67,0x65567265,0x78657472,0x00000000,0x00060006,0x00000019,0x00000000,
136 0x505f6c67,0x7469736f,0x006e6f69,0x00030005,0x0000001b,0x00000000,0x00040005,0x0000001c,
137 0x736f5061,0x00000000,0x00060005,0x0000001e,0x73755075,0x6e6f4368,0x6e617473,0x00000074,
138 0x00050006,0x0000001e,0x00000000,0x61635375,0x0000656c,0x00060006,0x0000001e,0x00000001,
139 0x61725475,0x616c736e,0x00006574,0x00030005,0x00000020,0x00006370,0x00040047,0x0000000b,
140 0x0000001e,0x00000000,0x00040047,0x0000000f,0x0000001e,0x00000002,0x00040047,0x00000015,
141 0x0000001e,0x00000001,0x00050048,0x00000019,0x00000000,0x0000000b,0x00000000,0x00030047,
142 0x00000019,0x00000002,0x00040047,0x0000001c,0x0000001e,0x00000000,0x00050048,0x0000001e,
143 0x00000000,0x00000023,0x00000000,0x00050048,0x0000001e,0x00000001,0x00000023,0x00000008,
144 0x00030047,0x0000001e,0x00000002,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,
145 0x00030016,0x00000006,0x00000020,0x00040017,0x00000007,0x00000006,0x00000004,0x00040017,
146 0x00000008,0x00000006,0x00000002,0x0004001e,0x00000009,0x00000007,0x00000008,0x00040020,
147 0x0000000a,0x00000003,0x00000009,0x0004003b,0x0000000a,0x0000000b,0x00000003,0x00040015,
148 0x0000000c,0x00000020,0x00000001,0x0004002b,0x0000000c,0x0000000d,0x00000000,0x00040020,
149 0x0000000e,0x00000001,0x00000007,0x0004003b,0x0000000e,0x0000000f,0x00000001,0x00040020,
150 0x00000011,0x00000003,0x00000007,0x0004002b,0x0000000c,0x00000013,0x00000001,0x00040020,
151 0x00000014,0x00000001,0x00000008,0x0004003b,0x00000014,0x00000015,0x00000001,0x00040020,
152 0x00000017,0x00000003,0x00000008,0x0003001e,0x00000019,0x00000007,0x00040020,0x0000001a,
153 0x00000003,0x00000019,0x0004003b,0x0000001a,0x0000001b,0x00000003,0x0004003b,0x00000014,
154 0x0000001c,0x00000001,0x0004001e,0x0000001e,0x00000008,0x00000008,0x00040020,0x0000001f,
155 0x00000009,0x0000001e,0x0004003b,0x0000001f,0x00000020,0x00000009,0x00040020,0x00000021,
156 0x00000009,0x00000008,0x0004002b,0x00000006,0x00000028,0x00000000,0x0004002b,0x00000006,
157 0x00000029,0x3f800000,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,
158 0x00000005,0x0004003d,0x00000007,0x00000010,0x0000000f,0x00050041,0x00000011,0x00000012,
159 0x0000000b,0x0000000d,0x0003003e,0x00000012,0x00000010,0x0004003d,0x00000008,0x00000016,
160 0x00000015,0x00050041,0x00000017,0x00000018,0x0000000b,0x00000013,0x0003003e,0x00000018,
161 0x00000016,0x0004003d,0x00000008,0x0000001d,0x0000001c,0x00050041,0x00000021,0x00000022,
162 0x00000020,0x0000000d,0x0004003d,0x00000008,0x00000023,0x00000022,0x00050085,0x00000008,
163 0x00000024,0x0000001d,0x00000023,0x00050041,0x00000021,0x00000025,0x00000020,0x00000013,
164 0x0004003d,0x00000008,0x00000026,0x00000025,0x00050081,0x00000008,0x00000027,0x00000024,
165 0x00000026,0x00050051,0x00000006,0x0000002a,0x00000027,0x00000000,0x00050051,0x00000006,
166 0x0000002b,0x00000027,0x00000001,0x00070050,0x00000007,0x0000002c,0x0000002a,0x0000002b,
167 0x00000028,0x00000029,0x00050041,0x00000011,0x0000002d,0x0000001b,0x0000000d,0x0003003e,
168 0x0000002d,0x0000002c,0x000100fd,0x00010038
185 0x07230203,0x00010000,0x00080001,0x0000001e,0x00000000,0x00020011,0x00000001,0x0006000b,
186 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001,
187 0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x00000009,0x0000000d,0x00030010,
188 0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d,
189 0x00000000,0x00040005,0x00000009,0x6c6f4366,0x0000726f,0x00030005,0x0000000b,0x00000000,
190 0x00050006,0x0000000b,0x00000000,0x6f6c6f43,0x00000072,0x00040006,0x0000000b,0x00000001,
191 0x00005655,0x00030005,0x0000000d,0x00006e49,0x00050005,0x00000016,0x78655473,0x65727574,
192 0x00000000,0x00040047,0x00000009,0x0000001e,0x00000000,0x00040047,0x0000000d,0x0000001e,
193 0x00000000,0x00040047,0x00000016,0x00000022,0x00000000,0x00040047,0x00000016,0x00000021,
194 0x00000000,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00030016,0x00000006,
195 0x00000020,0x00040017,0x00000007,0x00000006,0x00000004,0x00040020,0x00000008,0x00000003,
196 0x00000007,0x0004003b,0x00000008,0x00000009,0x00000003,0x00040017,0x0000000a,0x00000006,
197 0x00000002,0x0004001e,0x0000000b,0x00000007,0x0000000a,0x00040020,0x0000000c,0x00000001,
198 0x0000000b,0x0004003b,0x0000000c,0x0000000d,0x00000001,0x00040015,0x0000000e,0x00000020,
199 0x00000001,0x0004002b,0x0000000e,0x0000000f,0x00000000,0x00040020,0x00000010,0x00000001,
200 0x00000007,0x00090019,0x00000013,0x00000006,0x00000001,0x00000000,0x00000000,0x00000000,
201 0x00000001,0x00000000,0x0003001b,0x00000014,0x00000013,0x00040020,0x00000015,0x00000000,
202 0x00000014,0x0004003b,0x00000015,0x00000016,0x00000000,0x0004002b,0x0000000e,0x00000018,
203 0x00000001,0x00040020,0x00000019,0x00000001,0x0000000a,0x00050036,0x00000002,0x00000004,
204 0x00000000,0x00000003,0x000200f8,0x00000005,0x00050041,0x00000010,0x00000011,0x0000000d,
205 0x0000000f,0x0004003d,0x00000007,0x00000012,0x00000011,0x0004003d,0x00000014,0x00000017,
206 0x00000016,0x00050041,0x00000019,0x0000001a,0x0000000d,0x00000018,0x0004003d,0x0000000a,
207 0x0000001b,0x0000001a,0x00050057,0x00000007,0x0000001c,0x00000017,0x0000001b,0x00050085,
208 0x00000007,0x0000001d,0x00000012,0x0000001c,0x0003003e,0x00000009,0x0000001d,0x000100fd,
219 VkPhysicalDeviceMemoryProperties prop;
220 vkGetPhysicalDeviceMemoryProperties(
v->PhysicalDevice, &prop);
221 for (uint32_t
i = 0;
i < prop.memoryTypeCount;
i++)
222 if ((prop.memoryTypes[
i].propertyFlags & properties) == properties && type_bits & (1<<
i))
230 if (
v->CheckVkResultFn)
238 if (
buffer != VK_NULL_HANDLE)
239 vkDestroyBuffer(
v->Device,
buffer,
v->Allocator);
240 if (buffer_memory != VK_NULL_HANDLE)
241 vkFreeMemory(
v->Device, buffer_memory,
v->Allocator);
244 VkBufferCreateInfo buffer_info = {};
245 buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
246 buffer_info.size = vertex_buffer_size_aligned;
247 buffer_info.usage =
usage;
248 buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
249 err = vkCreateBuffer(
v->Device, &buffer_info,
v->Allocator, &
buffer);
252 VkMemoryRequirements
req;
253 vkGetBufferMemoryRequirements(
v->Device,
buffer, &
req);
255 VkMemoryAllocateInfo alloc_info = {};
256 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
257 alloc_info.allocationSize =
req.size;
259 err = vkAllocateMemory(
v->Device, &alloc_info,
v->Allocator, &buffer_memory);
262 err = vkBindBufferMemory(
v->Device,
buffer, buffer_memory, 0);
264 p_buffer_size = new_size;
271 vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
g_Pipeline);
273 vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
g_PipelineLayout, 0, 1, desc_set, 0,
NULL);
279 VkDeviceSize vertex_offset[1] = { 0 };
280 vkCmdBindVertexBuffers(command_buffer, 0, 1, vertex_buffers, vertex_offset);
281 vkCmdBindIndexBuffer(command_buffer, rb->
IndexBuffer, 0,
sizeof(
ImDrawIdx) == 2 ? VK_INDEX_TYPE_UINT16 : VK_INDEX_TYPE_UINT32);
289 viewport.width = (float)fb_width;
290 viewport.height = (float)fb_height;
291 viewport.minDepth = 0.0f;
292 viewport.maxDepth = 1.0f;
293 vkCmdSetViewport(command_buffer, 0, 1, &viewport);
303 translate[0] = -1.0f - draw_data->
DisplayPos.
x * scale[0];
304 translate[1] = -1.0f - draw_data->
DisplayPos.
y * scale[1];
305 vkCmdPushConstants(command_buffer,
g_PipelineLayout, VK_SHADER_STAGE_VERTEX_BIT,
sizeof(
float) * 0,
sizeof(
float) * 2, scale);
306 vkCmdPushConstants(command_buffer,
g_PipelineLayout, VK_SHADER_STAGE_VERTEX_BIT,
sizeof(
float) * 2,
sizeof(
float) * 2, translate);
317 if (fb_width <= 0 || fb_height <= 0 || draw_data->TotalVtxCount == 0)
327 wrb->
Count =
v->ImageCount;
340 if (rb->VertexBuffer == VK_NULL_HANDLE || rb->VertexBufferSize < vertex_size)
341 CreateOrResizeBuffer(rb->VertexBuffer, rb->VertexBufferMemory, rb->VertexBufferSize, vertex_size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT);
342 if (rb->IndexBuffer == VK_NULL_HANDLE || rb->IndexBufferSize < index_size)
343 CreateOrResizeBuffer(rb->IndexBuffer, rb->IndexBufferMemory, rb->IndexBufferSize, index_size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT);
349 err = vkMapMemory(
v->Device, rb->VertexBufferMemory, 0, vertex_size, 0, (
void**)(&vtx_dst));
351 err = vkMapMemory(
v->Device, rb->IndexBufferMemory, 0, index_size, 0, (
void**)(&idx_dst));
361 VkMappedMemoryRange
range[2] = {};
362 range[0].sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
363 range[0].memory = rb->VertexBufferMemory;
364 range[0].size = VK_WHOLE_SIZE;
365 range[1].sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
366 range[1].memory = rb->IndexBufferMemory;
367 range[1].size = VK_WHOLE_SIZE;
368 err = vkFlushMappedMemoryRanges(
v->Device, 2,
range);
370 vkUnmapMemory(
v->Device, rb->VertexBufferMemory);
371 vkUnmapMemory(
v->Device, rb->IndexBufferMemory);
383 int global_vtx_offset = 0;
384 int global_idx_offset = 0;
388 for (
int cmd_i = 0; cmd_i < cmd_list->
CmdBuffer.
Size; cmd_i++)
404 clip_rect.
x = (pcmd->
ClipRect.
x - clip_off.
x) * clip_scale.
x;
405 clip_rect.
y = (pcmd->
ClipRect.
y - clip_off.
y) * clip_scale.
y;
406 clip_rect.
z = (pcmd->
ClipRect.
z - clip_off.
x) * clip_scale.
x;
407 clip_rect.
w = (pcmd->
ClipRect.
w - clip_off.
y) * clip_scale.
y;
409 if (clip_rect.
x < fb_width && clip_rect.
y < fb_height && clip_rect.
z >= 0.0f && clip_rect.
w >= 0.0f)
412 if (clip_rect.
x < 0.0f)
414 if (clip_rect.
y < 0.0f)
419 scissor.offset.x = (int32_t)(clip_rect.
x);
420 scissor.offset.y = (int32_t)(clip_rect.
y);
421 scissor.extent.width = (uint32_t)(clip_rect.
z - clip_rect.
x);
422 scissor.extent.height = (uint32_t)(clip_rect.
w - clip_rect.
y);
423 vkCmdSetScissor(command_buffer, 0, 1, &scissor);
449 VkImageCreateInfo info = {};
450 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
451 info.imageType = VK_IMAGE_TYPE_2D;
452 info.format = VK_FORMAT_R8G8B8A8_UNORM;
453 info.extent.width =
width;
454 info.extent.height =
height;
455 info.extent.depth = 1;
457 info.arrayLayers = 1;
458 info.samples = VK_SAMPLE_COUNT_1_BIT;
459 info.tiling = VK_IMAGE_TILING_OPTIMAL;
460 info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
461 info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
462 info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
465 VkMemoryRequirements
req;
467 VkMemoryAllocateInfo alloc_info = {};
468 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
469 alloc_info.allocationSize =
req.size;
479 VkImageViewCreateInfo info = {};
480 info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
482 info.viewType = VK_IMAGE_VIEW_TYPE_2D;
483 info.format = VK_FORMAT_R8G8B8A8_UNORM;
484 info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
485 info.subresourceRange.levelCount = 1;
486 info.subresourceRange.layerCount = 1;
493 VkDescriptorImageInfo desc_image[1] = {};
496 desc_image[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
497 VkWriteDescriptorSet write_desc[1] = {};
498 write_desc[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
500 write_desc[0].descriptorCount = 1;
501 write_desc[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
502 write_desc[0].pImageInfo = desc_image;
503 vkUpdateDescriptorSets(
v->Device, 1, write_desc, 0,
NULL);
508 VkBufferCreateInfo buffer_info = {};
509 buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
510 buffer_info.size = upload_size;
511 buffer_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
512 buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
515 VkMemoryRequirements
req;
518 VkMemoryAllocateInfo alloc_info = {};
519 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
520 alloc_info.allocationSize =
req.size;
534 VkMappedMemoryRange
range[1] = {};
535 range[0].sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
537 range[0].size = upload_size;
538 err = vkFlushMappedMemoryRanges(
v->Device, 1,
range);
545 VkImageMemoryBarrier copy_barrier[1] = {};
546 copy_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
547 copy_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
548 copy_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
549 copy_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
550 copy_barrier[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
551 copy_barrier[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
553 copy_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
554 copy_barrier[0].subresourceRange.levelCount = 1;
555 copy_barrier[0].subresourceRange.layerCount = 1;
556 vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0,
NULL, 0,
NULL, 1, copy_barrier);
558 VkBufferImageCopy region = {};
559 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
560 region.imageSubresource.layerCount = 1;
561 region.imageExtent.width =
width;
562 region.imageExtent.height =
height;
563 region.imageExtent.depth = 1;
566 VkImageMemoryBarrier use_barrier[1] = {};
567 use_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
568 use_barrier[0].srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
569 use_barrier[0].dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
570 use_barrier[0].oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
571 use_barrier[0].newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
572 use_barrier[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
573 use_barrier[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
575 use_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
576 use_barrier[0].subresourceRange.levelCount = 1;
577 use_barrier[0].subresourceRange.layerCount = 1;
578 vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0,
NULL, 0,
NULL, 1, use_barrier);
591 VkShaderModule vert_module;
592 VkShaderModule frag_module;
596 VkShaderModuleCreateInfo vert_info = {};
597 vert_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
600 err = vkCreateShaderModule(
v->Device, &vert_info,
v->Allocator, &vert_module);
602 VkShaderModuleCreateInfo frag_info = {};
603 frag_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
606 err = vkCreateShaderModule(
v->Device, &frag_info,
v->Allocator, &frag_module);
612 VkSamplerCreateInfo info = {};
613 info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
614 info.magFilter = VK_FILTER_LINEAR;
615 info.minFilter = VK_FILTER_LINEAR;
616 info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
617 info.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT;
618 info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
619 info.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT;
622 info.maxAnisotropy = 1.0f;
630 VkDescriptorSetLayoutBinding binding[1] = {};
631 binding[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
632 binding[0].descriptorCount = 1;
633 binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
634 binding[0].pImmutableSamplers =
sampler;
635 VkDescriptorSetLayoutCreateInfo info = {};
636 info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
637 info.bindingCount = 1;
638 info.pBindings = binding;
645 VkDescriptorSetAllocateInfo alloc_info = {};
646 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
647 alloc_info.descriptorPool =
v->DescriptorPool;
648 alloc_info.descriptorSetCount = 1;
657 VkPushConstantRange push_constants[1] = {};
658 push_constants[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
659 push_constants[0].offset =
sizeof(float) * 0;
660 push_constants[0].size =
sizeof(float) * 4;
662 VkPipelineLayoutCreateInfo layout_info = {};
663 layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
664 layout_info.setLayoutCount = 1;
665 layout_info.pSetLayouts = set_layout;
666 layout_info.pushConstantRangeCount = 1;
667 layout_info.pPushConstantRanges = push_constants;
672 VkPipelineShaderStageCreateInfo stage[2] = {};
673 stage[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
674 stage[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
675 stage[0].module = vert_module;
676 stage[0].pName =
"main";
677 stage[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
678 stage[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
679 stage[1].module = frag_module;
680 stage[1].pName =
"main";
682 VkVertexInputBindingDescription binding_desc[1] = {};
684 binding_desc[0].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
686 VkVertexInputAttributeDescription attribute_desc[3] = {};
687 attribute_desc[0].location = 0;
688 attribute_desc[0].binding = binding_desc[0].binding;
689 attribute_desc[0].format = VK_FORMAT_R32G32_SFLOAT;
691 attribute_desc[1].location = 1;
692 attribute_desc[1].binding = binding_desc[0].binding;
693 attribute_desc[1].format = VK_FORMAT_R32G32_SFLOAT;
695 attribute_desc[2].location = 2;
696 attribute_desc[2].binding = binding_desc[0].binding;
697 attribute_desc[2].format = VK_FORMAT_R8G8B8A8_UNORM;
700 VkPipelineVertexInputStateCreateInfo vertex_info = {};
701 vertex_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
702 vertex_info.vertexBindingDescriptionCount = 1;
703 vertex_info.pVertexBindingDescriptions = binding_desc;
704 vertex_info.vertexAttributeDescriptionCount = 3;
705 vertex_info.pVertexAttributeDescriptions = attribute_desc;
707 VkPipelineInputAssemblyStateCreateInfo ia_info = {};
708 ia_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
709 ia_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
711 VkPipelineViewportStateCreateInfo viewport_info = {};
712 viewport_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
713 viewport_info.viewportCount = 1;
714 viewport_info.scissorCount = 1;
716 VkPipelineRasterizationStateCreateInfo raster_info = {};
717 raster_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
718 raster_info.polygonMode = VK_POLYGON_MODE_FILL;
719 raster_info.cullMode = VK_CULL_MODE_NONE;
720 raster_info.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
721 raster_info.lineWidth = 1.0f;
723 VkPipelineMultisampleStateCreateInfo ms_info = {};
724 ms_info.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
725 if (
v->MSAASamples != 0)
726 ms_info.rasterizationSamples =
v->MSAASamples;
728 ms_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
730 VkPipelineColorBlendAttachmentState color_attachment[1] = {};
731 color_attachment[0].blendEnable = VK_TRUE;
732 color_attachment[0].srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
733 color_attachment[0].dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
734 color_attachment[0].colorBlendOp = VK_BLEND_OP_ADD;
735 color_attachment[0].srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
736 color_attachment[0].dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
737 color_attachment[0].alphaBlendOp = VK_BLEND_OP_ADD;
738 color_attachment[0].colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
740 VkPipelineDepthStencilStateCreateInfo depth_info = {};
741 depth_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
743 VkPipelineColorBlendStateCreateInfo blend_info = {};
744 blend_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
745 blend_info.attachmentCount = 1;
746 blend_info.pAttachments = color_attachment;
748 VkDynamicState dynamic_states[2] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
749 VkPipelineDynamicStateCreateInfo dynamic_state = {};
750 dynamic_state.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
751 dynamic_state.dynamicStateCount = (uint32_t)
IM_ARRAYSIZE(dynamic_states);
752 dynamic_state.pDynamicStates = dynamic_states;
754 VkGraphicsPipelineCreateInfo info = {};
755 info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
758 info.pStages = stage;
759 info.pVertexInputState = &vertex_info;
760 info.pInputAssemblyState = &ia_info;
761 info.pViewportState = &viewport_info;
762 info.pRasterizationState = &raster_info;
763 info.pMultisampleState = &ms_info;
764 info.pDepthStencilState = &depth_info;
765 info.pColorBlendState = &blend_info;
766 info.pDynamicState = &dynamic_state;
769 err = vkCreateGraphicsPipelines(
v->Device,
v->PipelineCache, 1, &info,
v->Allocator, &
g_Pipeline);
772 vkDestroyShaderModule(
v->Device, vert_module,
v->Allocator);
773 vkDestroyShaderModule(
v->Device, frag_module,
v->Allocator);
822 IM_ASSERT(render_pass != VK_NULL_HANDLE);
847 VkResult
err = vkDeviceWaitIdle(
v->Device);
870 VkSurfaceFormatKHR
ImGui_ImplVulkanH_SelectSurfaceFormat(VkPhysicalDevice physical_device, VkSurfaceKHR surface,
const VkFormat* request_formats,
int request_formats_count, VkColorSpaceKHR request_color_space)
879 uint32_t avail_count;
880 vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &avail_count,
NULL);
882 avail_format.
resize((
int)avail_count);
883 vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &avail_count, avail_format.
Data);
886 if (avail_count == 1)
888 if (avail_format[0].
format == VK_FORMAT_UNDEFINED)
890 VkSurfaceFormatKHR ret;
891 ret.format = request_formats[0];
892 ret.colorSpace = request_color_space;
898 return avail_format[0];
904 for (
int request_i = 0; request_i < request_formats_count; request_i++)
905 for (uint32_t avail_i = 0; avail_i < avail_count; avail_i++)
906 if (avail_format[avail_i].
format == request_formats[request_i] && avail_format[avail_i].colorSpace == request_color_space)
907 return avail_format[avail_i];
910 return avail_format[0];
920 uint32_t avail_count = 0;
921 vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device, surface, &avail_count,
NULL);
923 avail_modes.
resize((
int)avail_count);
924 vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device, surface, &avail_count, avail_modes.
Data);
928 for (
int request_i = 0; request_i < request_modes_count; request_i++)
929 for (uint32_t avail_i = 0; avail_i < avail_count; avail_i++)
930 if (request_modes[request_i] == avail_modes[avail_i])
931 return request_modes[request_i];
933 return VK_PRESENT_MODE_FIFO_KHR;
938 IM_ASSERT(physical_device != VK_NULL_HANDLE && device != VK_NULL_HANDLE);
939 (
void)physical_device;
949 VkCommandPoolCreateInfo info = {};
950 info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
951 info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
952 info.queueFamilyIndex = queue_family;
953 err = vkCreateCommandPool(device, &info, allocator, &fd->
CommandPool);
957 VkCommandBufferAllocateInfo info = {};
958 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
960 info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
961 info.commandBufferCount = 1;
966 VkFenceCreateInfo info = {};
967 info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
968 info.flags = VK_FENCE_CREATE_SIGNALED_BIT;
969 err = vkCreateFence(device, &info, allocator, &fd->
Fence);
973 VkSemaphoreCreateInfo info = {};
974 info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
985 if (present_mode == VK_PRESENT_MODE_MAILBOX_KHR)
987 if (present_mode == VK_PRESENT_MODE_FIFO_KHR || present_mode == VK_PRESENT_MODE_FIFO_RELAXED_KHR)
989 if (present_mode == VK_PRESENT_MODE_IMMEDIATE_KHR)
999 VkSwapchainKHR old_swapchain = wd->
Swapchain;
1000 err = vkDeviceWaitIdle(device);
1016 vkDestroyRenderPass(device, wd->
RenderPass, allocator);
1019 if (min_image_count == 0)
1024 VkSwapchainCreateInfoKHR info = {};
1025 info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1027 info.minImageCount = min_image_count;
1030 info.imageArrayLayers = 1;
1031 info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
1032 info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
1033 info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
1034 info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
1036 info.clipped = VK_TRUE;
1037 info.oldSwapchain = old_swapchain;
1038 VkSurfaceCapabilitiesKHR cap;
1039 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_device, wd->
Surface, &cap);
1041 if (info.minImageCount < cap.minImageCount)
1042 info.minImageCount = cap.minImageCount;
1043 else if (cap.maxImageCount != 0 && info.minImageCount > cap.maxImageCount)
1044 info.minImageCount = cap.maxImageCount;
1046 if (cap.currentExtent.width == 0xffffffff)
1048 info.imageExtent.width = wd->
Width =
w;
1049 info.imageExtent.height = wd->
Height =
h;
1053 info.imageExtent.width = wd->
Width = cap.currentExtent.width;
1054 info.imageExtent.height = wd->
Height = cap.currentExtent.height;
1056 err = vkCreateSwapchainKHR(device, &info, allocator, &wd->
Swapchain);
1060 VkImage backbuffers[16] = {};
1075 vkDestroySwapchainKHR(device, old_swapchain, allocator);
1082 attachment.loadOp = wd->
ClearEnable ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_DONT_CARE;
1083 attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
1084 attachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
1085 attachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
1086 attachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
1087 attachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
1088 VkAttachmentReference color_attachment = {};
1089 color_attachment.attachment = 0;
1090 color_attachment.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
1091 VkSubpassDescription subpass = {};
1092 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
1093 subpass.colorAttachmentCount = 1;
1094 subpass.pColorAttachments = &color_attachment;
1095 VkSubpassDependency dependency = {};
1096 dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
1097 dependency.dstSubpass = 0;
1098 dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
1099 dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
1100 dependency.srcAccessMask = 0;
1101 dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
1102 VkRenderPassCreateInfo info = {};
1103 info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
1104 info.attachmentCount = 1;
1106 info.subpassCount = 1;
1107 info.pSubpasses = &subpass;
1108 info.dependencyCount = 1;
1109 info.pDependencies = &dependency;
1110 err = vkCreateRenderPass(device, &info, allocator, &wd->
RenderPass);
1116 VkImageViewCreateInfo info = {};
1117 info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1118 info.viewType = VK_IMAGE_VIEW_TYPE_2D;
1120 info.components.r = VK_COMPONENT_SWIZZLE_R;
1121 info.components.g = VK_COMPONENT_SWIZZLE_G;
1122 info.components.b = VK_COMPONENT_SWIZZLE_B;
1123 info.components.a = VK_COMPONENT_SWIZZLE_A;
1124 VkImageSubresourceRange image_range = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 };
1125 info.subresourceRange = image_range;
1138 VkFramebufferCreateInfo info = {};
1139 info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
1141 info.attachmentCount = 1;
1143 info.width = wd->
Width;
1144 info.height = wd->
Height;
1150 err = vkCreateFramebuffer(device, &info, allocator, &fd->
Framebuffer);
1165 vkDeviceWaitIdle(device);
1177 vkDestroyRenderPass(device, wd->
RenderPass, allocator);
1178 vkDestroySwapchainKHR(device, wd->
Swapchain, allocator);
1179 vkDestroySurfaceKHR(instance, wd->
Surface, allocator);
1186 vkDestroyFence(device, fd->
Fence, allocator);
1188 vkDestroyCommandPool(device, fd->
CommandPool, allocator);
1189 fd->
Fence = VK_NULL_HANDLE;
1194 vkDestroyFramebuffer(device, fd->
Framebuffer, allocator);
1206 if (
buffers->VertexBuffer) { vkDestroyBuffer(device,
buffers->VertexBuffer, allocator);
buffers->VertexBuffer = VK_NULL_HANDLE; }
1207 if (
buffers->VertexBufferMemory) { vkFreeMemory(device,
buffers->VertexBufferMemory, allocator);
buffers->VertexBufferMemory = VK_NULL_HANDLE; }
1208 if (
buffers->IndexBuffer) { vkDestroyBuffer(device,
buffers->IndexBuffer, allocator);
buffers->IndexBuffer = VK_NULL_HANDLE; }
1209 if (
buffers->IndexBufferMemory) { vkFreeMemory(device,
buffers->IndexBufferMemory, allocator);
buffers->IndexBufferMemory = VK_NULL_HANDLE; }
1210 buffers->VertexBufferSize = 0;
1216 for (uint32_t
n = 0;
n <
buffers->Count;
n++)