32 VkDescriptorSetLayoutBinding ubo_layout_bindings[2] = { 0 };
34 ubo_layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
35 ubo_layout_bindings[0].descriptorCount = 1;
37 ubo_layout_bindings[0].stageFlags = VK_SHADER_STAGE_ALL;
39 ubo_layout_bindings[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
40 ubo_layout_bindings[1].descriptorCount = 1;
42 ubo_layout_bindings[1].stageFlags = VK_SHADER_STAGE_ALL;
44 VkDescriptorSetLayoutCreateInfo layout_info = {
45 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
46 .bindingCount =
LENGTH(ubo_layout_bindings),
47 .pBindings = ubo_layout_bindings,
52 const VkMemoryPropertyFlags host_memory_flags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT |
53 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
55 const VkMemoryPropertyFlags device_memory_flags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
57 VkPhysicalDeviceProperties properties;
59 ubo_alignment = properties.limits.minUniformBufferOffsetAlignment;
68 VkDescriptorPoolSize pool_size = {
69 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
73 VkDescriptorPoolCreateInfo pool_info = {
74 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
76 .pPoolSizes = &pool_size,
82 VkDescriptorSetAllocateInfo descriptor_set_alloc_info = {
83 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
85 .descriptorSetCount = 1,
91 VkDescriptorBufferInfo buf_info = {
97 VkDescriptorBufferInfo buf1_info = {
103 VkWriteDescriptorSet writes[2] = { 0 };
105 writes[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
108 writes[0].dstArrayElement = 0,
109 writes[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
110 writes[0].descriptorCount = 1,
111 writes[0].pBufferInfo = &buf_info,
113 writes[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
116 writes[1].dstArrayElement = 0,
117 writes[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
118 writes[1].descriptorCount = 1,
119 writes[1].pBufferInfo = &buf1_info,
146 assert(ubo->
memory != VK_NULL_HANDLE);
147 assert(ubo->
buffer != VK_NULL_HANDLE);
160 VkBufferCopy copy = { 0 };
164 VkBufferMemoryBarrier barrier = {
165 .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
166 .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
167 .dstAccessMask = VK_ACCESS_UNIFORM_READ_BIT | VK_ACCESS_SHADER_READ_BIT,
168 .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
169 .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
174 vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
175 0, 0, NULL, 1, &barrier, 0, NULL);