1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © 2022 Collabora Ltd 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21bf215546Sopenharmony_ci * IN THE SOFTWARE. 22bf215546Sopenharmony_ci */ 23bf215546Sopenharmony_ci#ifndef VK_PIPELINE_LAYOUT_H 24bf215546Sopenharmony_ci#define VK_PIPELINE_LAYOUT_H 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci#include "vk_object.h" 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#include "util/u_atomic.h" 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci#ifdef __cplusplus 31bf215546Sopenharmony_ciextern "C" { 32bf215546Sopenharmony_ci#endif 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_cistruct vk_descriptor_set_layout; 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_ci#define VK_MESA_PIPELINE_LAYOUT_MAX_SETS 32 37bf215546Sopenharmony_ci 38bf215546Sopenharmony_cistruct vk_pipeline_layout { 39bf215546Sopenharmony_ci struct vk_object_base base; 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_ci /** Reference count 42bf215546Sopenharmony_ci * 43bf215546Sopenharmony_ci * It's often necessary to store a pointer to the descriptor set layout in 44bf215546Sopenharmony_ci * the descriptor so that any entrypoint which has access to a descriptor 45bf215546Sopenharmony_ci * set also has the layout. While layouts are often passed into various 46bf215546Sopenharmony_ci * entrypoints, they're notably missing from vkUpdateDescriptorSets(). In 47bf215546Sopenharmony_ci * order to implement descriptor writes, you either need to stash a pointer 48bf215546Sopenharmony_ci * to the descriptor set layout in the descriptor set or you need to copy 49bf215546Sopenharmony_ci * all of the relevant information. Storing a pointer is a lot cheaper. 50bf215546Sopenharmony_ci * 51bf215546Sopenharmony_ci * Because descriptor set layout lifetimes and descriptor set lifetimes are 52bf215546Sopenharmony_ci * not guaranteed to coincide, we have to reference count if we're going to 53bf215546Sopenharmony_ci * do this. 54bf215546Sopenharmony_ci */ 55bf215546Sopenharmony_ci uint32_t ref_cnt; 56bf215546Sopenharmony_ci 57bf215546Sopenharmony_ci /** VkPipelineLayoutCreateInfo::flags */ 58bf215546Sopenharmony_ci VkPipelineLayoutCreateFlagBits create_flags; 59bf215546Sopenharmony_ci 60bf215546Sopenharmony_ci /** Number of descriptor set layouts in this pipeline layout */ 61bf215546Sopenharmony_ci uint32_t set_count; 62bf215546Sopenharmony_ci 63bf215546Sopenharmony_ci /** Array of pointers to descriptor set layouts, indexed by set index */ 64bf215546Sopenharmony_ci const struct vk_descriptor_set_layout *set_layouts[VK_MESA_PIPELINE_LAYOUT_MAX_SETS]; 65bf215546Sopenharmony_ci 66bf215546Sopenharmony_ci /** Destroy callback 67bf215546Sopenharmony_ci * 68bf215546Sopenharmony_ci * Will be initially set to vk_pipeline_layout_destroy() but may be set to 69bf215546Sopenharmony_ci * a driver-specific callback which does driver-specific clean-up and then 70bf215546Sopenharmony_ci * calls vk_pipeline_layout_destroy(). 71bf215546Sopenharmony_ci */ 72bf215546Sopenharmony_ci void (*destroy)(struct vk_device *device, 73bf215546Sopenharmony_ci struct vk_pipeline_layout *layout); 74bf215546Sopenharmony_ci}; 75bf215546Sopenharmony_ci 76bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(vk_pipeline_layout, base, VkPipelineLayout, 77bf215546Sopenharmony_ci VK_OBJECT_TYPE_PIPELINE_LAYOUT); 78bf215546Sopenharmony_ci 79bf215546Sopenharmony_civoid * 80bf215546Sopenharmony_civk_pipeline_layout_zalloc(struct vk_device *device, size_t size, 81bf215546Sopenharmony_ci const VkPipelineLayoutCreateInfo *pCreateInfo); 82bf215546Sopenharmony_ci 83bf215546Sopenharmony_civoid * 84bf215546Sopenharmony_civk_pipeline_layout_multizalloc(struct vk_device *device, 85bf215546Sopenharmony_ci struct vk_multialloc *ma, 86bf215546Sopenharmony_ci const VkPipelineLayoutCreateInfo *pCreateInfo); 87bf215546Sopenharmony_ci 88bf215546Sopenharmony_civoid vk_pipeline_layout_destroy(struct vk_device *device, 89bf215546Sopenharmony_ci struct vk_pipeline_layout *layout); 90bf215546Sopenharmony_ci 91bf215546Sopenharmony_cistatic inline struct vk_pipeline_layout * 92bf215546Sopenharmony_civk_pipeline_layout_ref(struct vk_pipeline_layout *layout) 93bf215546Sopenharmony_ci{ 94bf215546Sopenharmony_ci assert(layout && layout->ref_cnt >= 1); 95bf215546Sopenharmony_ci p_atomic_inc(&layout->ref_cnt); 96bf215546Sopenharmony_ci return layout; 97bf215546Sopenharmony_ci} 98bf215546Sopenharmony_ci 99bf215546Sopenharmony_cistatic inline void 100bf215546Sopenharmony_civk_pipeline_layout_unref(struct vk_device *device, 101bf215546Sopenharmony_ci struct vk_pipeline_layout *layout) 102bf215546Sopenharmony_ci{ 103bf215546Sopenharmony_ci assert(layout && layout->ref_cnt >= 1); 104bf215546Sopenharmony_ci if (p_atomic_dec_zero(&layout->ref_cnt)) 105bf215546Sopenharmony_ci layout->destroy(device, layout); 106bf215546Sopenharmony_ci} 107bf215546Sopenharmony_ci 108bf215546Sopenharmony_ci#ifdef __cplusplus 109bf215546Sopenharmony_ci} 110bf215546Sopenharmony_ci#endif 111bf215546Sopenharmony_ci 112bf215546Sopenharmony_ci#endif /* VK_PIPELINE_LAYOUT_H */ 113bf215546Sopenharmony_ci 114