| 3001 | } |
| 3002 | |
| 3003 | VulkanDescriptorSet* DescriptorCache::Allocate(Stage stage, int storage_buffers_num, int textures2d_sampled_num, int textures2d_storage_num, |
| 3004 | int samplers_num, int gds_buffers_num) |
| 3005 | { |
| 3006 | KYTY_PROFILER_BLOCK("DescriptorCache::Allocate"); |
| 3007 | |
| 3008 | EXIT_IF(storage_buffers_num < 0 || storage_buffers_num > BUFFERS_MAX); |
| 3009 | EXIT_IF(textures2d_sampled_num < 0 || textures2d_sampled_num > TEXTURES_SAMPLED_MAX); |
| 3010 | EXIT_IF(textures2d_storage_num < 0 || textures2d_storage_num > TEXTURES_STORAGE_MAX); |
| 3011 | EXIT_IF(samplers_num < 0 || samplers_num > SAMPLERS_MAX); |
| 3012 | EXIT_IF(gds_buffers_num < 0 || gds_buffers_num > GDS_BUFFER_MAX); |
| 3013 | |
| 3014 | Core::LockGuard lock(m_mutex); |
| 3015 | |
| 3016 | auto* gctx = g_render_ctx->GetGraphicCtx(); |
| 3017 | EXIT_IF(gctx == nullptr); |
| 3018 | |
| 3019 | Init(); |
| 3020 | |
| 3021 | auto* ret = new VulkanDescriptorSet; |
| 3022 | |
| 3023 | ret->set = nullptr; |
| 3024 | |
| 3025 | for (int try_num = 0; try_num < 2; try_num++) |
| 3026 | { |
| 3027 | int pool_id = m_first_free_pool; |
| 3028 | while (pool_id != -1) |
| 3029 | { |
| 3030 | auto& pool = m_pools[pool_id]; |
| 3031 | |
| 3032 | VkDescriptorSetAllocateInfo alloc_info {}; |
| 3033 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 3034 | alloc_info.pNext = nullptr; |
| 3035 | alloc_info.descriptorPool = pool.pool; |
| 3036 | alloc_info.descriptorSetCount = 1; |
| 3037 | |
| 3038 | switch (stage) |
| 3039 | { |
| 3040 | case Stage::Vertex: |
| 3041 | alloc_info.pSetLayouts = &m_descriptor_set_layout_vertex[storage_buffers_num][textures2d_sampled_num] |
| 3042 | [textures2d_storage_num][samplers_num][gds_buffers_num]; |
| 3043 | break; |
| 3044 | case Stage::Pixel: |
| 3045 | alloc_info.pSetLayouts = &m_descriptor_set_layout_pixel[storage_buffers_num][textures2d_sampled_num] |
| 3046 | [textures2d_storage_num][samplers_num][gds_buffers_num]; |
| 3047 | break; |
| 3048 | case Stage::Compute: |
| 3049 | alloc_info.pSetLayouts = &m_descriptor_set_layout_compute[storage_buffers_num][textures2d_sampled_num] |
| 3050 | [textures2d_storage_num][samplers_num][gds_buffers_num]; |
| 3051 | break; |
| 3052 | default: EXIT("unknown stage\n"); |
| 3053 | } |
| 3054 | |
| 3055 | ret->pool_id = pool_id; |
| 3056 | ret->layout = *alloc_info.pSetLayouts; |
| 3057 | |
| 3058 | EXIT_IF(!pool.free); |
| 3059 | |
| 3060 | { |
nothing calls this directly
no test coverage detected