| 53 | } |
| 54 | |
| 55 | auto GPUShaderResourceTable::initialize(u32 max_buffers, u32 max_images, u32 max_samplers, u32 max_acceleration_structures, |
| 56 | VkDevice device, VkBuffer device_address_buffer, |
| 57 | PFN_vkSetDebugUtilsObjectNameEXT vkSetDebugUtilsObjectNameEXT) -> daxa_Result |
| 58 | { |
| 59 | daxa_Result result = DAXA_RESULT_SUCCESS; |
| 60 | defer |
| 61 | { |
| 62 | if (result != DAXA_RESULT_SUCCESS) |
| 63 | { |
| 64 | if (this->vk_descriptor_pool) |
| 65 | { |
| 66 | vkDestroyDescriptorPool(device, this->vk_descriptor_pool, nullptr); |
| 67 | } |
| 68 | if (this->vk_descriptor_set_layout) |
| 69 | { |
| 70 | vkDestroyDescriptorSetLayout(device, this->vk_descriptor_set_layout, nullptr); |
| 71 | } |
| 72 | } |
| 73 | }; |
| 74 | |
| 75 | bool const ray_tracing_enabled = max_acceleration_structures != (~0u); |
| 76 | |
| 77 | auto round_up_to_pages = [](auto size, auto block_size){ |
| 78 | return (size + block_size - 1) / block_size * block_size; |
| 79 | }; |
| 80 | |
| 81 | u32 max_tlas = 1024; // TODO(Raytracing): Should we have a smarter limit? |
| 82 | u32 max_blas = max_acceleration_structures; |
| 83 | max_tlas = round_up_to_pages(max_tlas, static_cast<u32>(GpuResourcePool<>::PAGE_SIZE)); |
| 84 | max_blas = round_up_to_pages(max_blas, static_cast<u32>(GpuResourcePool<>::PAGE_SIZE)); |
| 85 | max_buffers = round_up_to_pages(max_buffers, static_cast<u32>(GpuResourcePool<>::PAGE_SIZE)); |
| 86 | max_images = round_up_to_pages(max_images, static_cast<u32>(GpuResourcePool<>::PAGE_SIZE)); |
| 87 | max_samplers = round_up_to_pages(max_samplers, static_cast<u32>(GpuResourcePool<>::PAGE_SIZE)); |
| 88 | |
| 89 | buffer_slots.max_resources = max_buffers; |
| 90 | image_slots.max_resources = max_images; |
| 91 | sampler_slots.max_resources = max_samplers; |
| 92 | if (ray_tracing_enabled) |
| 93 | { |
| 94 | tlas_slots.max_resources = max_tlas; |
| 95 | blas_slots.max_resources = max_blas; |
| 96 | } |
| 97 | |
| 98 | buffer_slots.hot_data = decltype(buffer_slots.hot_data)(buffer_slots.max_resources); |
| 99 | image_slots.hot_data = decltype(image_slots.hot_data)(image_slots.max_resources); |
| 100 | sampler_slots.hot_data = decltype(sampler_slots.hot_data)(sampler_slots.max_resources); |
| 101 | if (ray_tracing_enabled) |
| 102 | { |
| 103 | tlas_slots.hot_data = decltype(tlas_slots.hot_data)(tlas_slots.max_resources); |
| 104 | blas_slots.hot_data = decltype(blas_slots.hot_data)(blas_slots.max_resources); |
| 105 | } |
| 106 | |
| 107 | VkDescriptorPoolSize const buffer_descriptor_pool_size{ |
| 108 | .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, |
| 109 | .descriptorCount = buffer_slots.max_resources + 1, |
| 110 | }; |
| 111 | |
| 112 | VkDescriptorPoolSize const storage_image_descriptor_pool_size{ |