The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

c/render: Make ubo upload and descriptor setting shareable

+117 -91
+117 -91
src/xrt/compositor/render/render_gfx.c
··· 180 180 vk->vkCmdBeginRenderPass(command_buffer, &render_pass_begin_info, VK_SUBPASS_CONTENTS_INLINE); 181 181 } 182 182 183 + static void 184 + update_ubo_and_src_discriptor_set(struct vk_bundle *vk, 185 + uint32_t ubo_binding, 186 + VkBuffer buffer, 187 + VkDeviceSize offset, 188 + VkDeviceSize size, 189 + uint32_t src_binding, 190 + VkSampler sampler, 191 + VkImageView image_view, 192 + VkDescriptorSet descriptor_set) 193 + { 194 + VkDescriptorImageInfo image_info = { 195 + .sampler = sampler, 196 + .imageView = image_view, 197 + .imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 198 + }; 199 + 200 + VkDescriptorBufferInfo buffer_info = { 201 + .buffer = buffer, 202 + .offset = offset, 203 + .range = size, 204 + }; 205 + 206 + VkWriteDescriptorSet write_descriptor_sets[2] = { 207 + { 208 + .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, 209 + .dstSet = descriptor_set, 210 + .dstBinding = src_binding, 211 + .descriptorCount = 1, 212 + .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 213 + .pImageInfo = &image_info, 214 + }, 215 + { 216 + .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, 217 + .dstSet = descriptor_set, 218 + .dstBinding = ubo_binding, 219 + .descriptorCount = 1, 220 + .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 221 + .pBufferInfo = &buffer_info, 222 + }, 223 + }; 224 + 225 + vk->vkUpdateDescriptorSets( // 226 + vk->device, // 227 + ARRAY_SIZE(write_descriptor_sets), // descriptorWriteCount 228 + write_descriptor_sets, // pDescriptorWrites 229 + 0, // descriptorCopyCount 230 + NULL); // pDescriptorCopies 231 + } 232 + 233 + XRT_CHECK_RESULT static VkResult 234 + do_ubo_and_src_alloc_and_write(struct render_gfx *rr, 235 + uint32_t ubo_binding, 236 + const void *ubo_ptr, 237 + VkDeviceSize ubo_size, 238 + uint32_t src_binding, 239 + VkSampler src_sampler, 240 + VkImageView src_image_view, 241 + VkDescriptorPool descriptor_pool, 242 + VkDescriptorSetLayout descriptor_set_layout, 243 + VkDescriptorSet *out_descriptor_set) 244 + { 245 + VkDescriptorSet descriptor_set = VK_NULL_HANDLE; 246 + struct render_sub_alloc ubo = XRT_STRUCT_INIT; 247 + struct vk_bundle *vk = vk_from_rr(rr); 248 + 249 + VkResult ret; 250 + 251 + 252 + /* 253 + * Allocate and upload data. 254 + */ 255 + ret = render_sub_alloc_ubo_alloc_and_write( // 256 + vk, // vk_bundle 257 + &rr->ubo_tracker, // rsat 258 + ubo_ptr, // ptr 259 + ubo_size, // size 260 + &ubo); // out_rsa 261 + VK_CHK_AND_RET(ret, "render_sub_alloc_ubo_alloc_and_write"); 262 + 263 + 264 + /* 265 + * Create and fill out destriptor. 266 + */ 267 + 268 + ret = vk_create_descriptor_set( // 269 + vk, // vk_bundle 270 + descriptor_pool, // descriptor_pool 271 + descriptor_set_layout, // descriptor_set_layout 272 + &descriptor_set); // descriptor_set 273 + VK_CHK_AND_RET(ret, "vk_create_descriptor_set"); 274 + 275 + update_ubo_and_src_discriptor_set( // 276 + vk, // vk_bundle 277 + ubo_binding, // ubo_binding 278 + ubo.buffer, // buffer 279 + ubo.offset, // offset 280 + ubo.size, // size 281 + src_binding, // src_binding 282 + src_sampler, // sampler 283 + src_image_view, // image_view 284 + descriptor_set); // descriptor_set 285 + 286 + *out_descriptor_set = descriptor_set; 287 + 288 + return VK_SUCCESS; 289 + } 290 + 183 291 184 292 /* 185 293 * ··· 347 455 *out_mesh_pipeline = pipeline; 348 456 349 457 return VK_SUCCESS; 350 - } 351 - 352 - static void 353 - update_mesh_discriptor_set(struct vk_bundle *vk, 354 - uint32_t src_binding, 355 - VkSampler sampler, 356 - VkImageView image_view, 357 - uint32_t ubo_binding, 358 - VkBuffer buffer, 359 - VkDeviceSize offset, 360 - VkDeviceSize size, 361 - VkDescriptorSet descriptor_set) 362 - { 363 - VkDescriptorImageInfo image_info = { 364 - .sampler = sampler, 365 - .imageView = image_view, 366 - .imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 367 - }; 368 - 369 - VkDescriptorBufferInfo buffer_info = { 370 - .buffer = buffer, 371 - .offset = offset, 372 - .range = size, 373 - }; 374 - 375 - VkWriteDescriptorSet write_descriptor_sets[2] = { 376 - { 377 - .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, 378 - .dstSet = descriptor_set, 379 - .dstBinding = src_binding, 380 - .descriptorCount = 1, 381 - .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 382 - .pImageInfo = &image_info, 383 - }, 384 - { 385 - .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, 386 - .dstSet = descriptor_set, 387 - .dstBinding = ubo_binding, 388 - .descriptorCount = 1, 389 - .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 390 - .pBufferInfo = &buffer_info, 391 - }, 392 - }; 393 - 394 - vk->vkUpdateDescriptorSets( // 395 - vk->device, // 396 - ARRAY_SIZE(write_descriptor_sets), // descriptorWriteCount 397 - write_descriptor_sets, // pDescriptorWrites 398 - 0, // descriptorCopyCount 399 - NULL); // pDescriptorCopies 400 458 } 401 459 402 460 ··· 697 755 VkImageView src_image_view, 698 756 VkDescriptorSet *out_descriptor_set) 699 757 { 700 - VkDescriptorSet descriptor_set = VK_NULL_HANDLE; 701 - struct render_sub_alloc ubo = XRT_STRUCT_INIT; 702 - struct vk_bundle *vk = vk_from_rr(rr); 703 758 struct render_resources *r = rr->r; 704 - VkResult ret; 705 759 706 - 707 - /* 708 - * Allocate and upload data. 709 - */ 710 - 711 - ret = render_sub_alloc_ubo_alloc_and_write( // 712 - vk, // vk_bundle 713 - &rr->ubo_tracker, // rsat 714 - data, // ptr 715 - sizeof(*data), // size 716 - &ubo); // out_rsa 717 - VK_CHK_AND_RET(ret, "render_sub_alloc_ubo_alloc_and_write"); 718 - 719 - 720 - /* 721 - * Create and fill out destriptor. 722 - */ 723 - 724 - ret = vk_create_descriptor_set( // 725 - vk, // vk_bundle 760 + return do_ubo_and_src_alloc_and_write( // 761 + rr, // rr 762 + r->mesh.ubo_binding, // ubo_binding 763 + data, // ubo_ptr 764 + sizeof(*data), // ubo_size 765 + r->mesh.src_binding, // src_binding 766 + src_sampler, // src_sampler 767 + src_image_view, // src_image_view 726 768 r->gfx.ubo_and_src_descriptor_pool, // descriptor_pool 727 769 r->mesh.descriptor_set_layout, // descriptor_set_layout 728 - &descriptor_set); // descriptor_set 729 - VK_CHK_AND_RET(ret, "vk_create_descriptor_set"); 730 - 731 - update_mesh_discriptor_set( // 732 - vk, // vk_bundle 733 - r->mesh.src_binding, // src_binding 734 - src_sampler, // sampler 735 - src_image_view, // image_view 736 - r->mesh.ubo_binding, // ubo_binding 737 - ubo.buffer, // buffer 738 - ubo.offset, // offset 739 - ubo.size, // size 740 - descriptor_set); // descriptor_set 741 - 742 - *out_descriptor_set = descriptor_set; 743 - 744 - return VK_SUCCESS; 770 + out_descriptor_set); // out_descriptor_set 745 771 } 746 772 747 773 void