1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © 2016 Bas Nieuwenhuizen 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 24bf215546Sopenharmony_ci#ifndef RADV_DESCRIPTOR_SET_H 25bf215546Sopenharmony_ci#define RADV_DESCRIPTOR_SET_H 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci#include "radv_constants.h" 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ci#include "vulkan/runtime/vk_descriptor_set_layout.h" 30bf215546Sopenharmony_ci#include "vulkan/runtime/vk_object.h" 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci#include <vulkan/vulkan.h> 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_cistruct radv_descriptor_set_binding_layout { 35bf215546Sopenharmony_ci VkDescriptorType type; 36bf215546Sopenharmony_ci 37bf215546Sopenharmony_ci /* Number of array elements in this binding */ 38bf215546Sopenharmony_ci uint32_t array_size; 39bf215546Sopenharmony_ci 40bf215546Sopenharmony_ci uint32_t offset; 41bf215546Sopenharmony_ci uint32_t buffer_offset; 42bf215546Sopenharmony_ci uint16_t dynamic_offset_offset; 43bf215546Sopenharmony_ci 44bf215546Sopenharmony_ci uint16_t dynamic_offset_count; 45bf215546Sopenharmony_ci /* redundant with the type, each for a single array element */ 46bf215546Sopenharmony_ci uint32_t size; 47bf215546Sopenharmony_ci 48bf215546Sopenharmony_ci /* Offset in the radv_descriptor_set_layout of the immutable samplers, or 0 49bf215546Sopenharmony_ci * if there are no immutable samplers. */ 50bf215546Sopenharmony_ci uint32_t immutable_samplers_offset; 51bf215546Sopenharmony_ci bool immutable_samplers_equal; 52bf215546Sopenharmony_ci}; 53bf215546Sopenharmony_ci 54bf215546Sopenharmony_cistruct radv_descriptor_set_layout { 55bf215546Sopenharmony_ci struct vk_descriptor_set_layout vk; 56bf215546Sopenharmony_ci 57bf215546Sopenharmony_ci /* Everything below is hashed and shouldn't contain any pointers. Be careful when modifying this 58bf215546Sopenharmony_ci * structure. 59bf215546Sopenharmony_ci */ 60bf215546Sopenharmony_ci 61bf215546Sopenharmony_ci /* The create flags for this descriptor set layout */ 62bf215546Sopenharmony_ci VkDescriptorSetLayoutCreateFlags flags; 63bf215546Sopenharmony_ci 64bf215546Sopenharmony_ci /* Number of bindings in this descriptor set */ 65bf215546Sopenharmony_ci uint32_t binding_count; 66bf215546Sopenharmony_ci 67bf215546Sopenharmony_ci /* Total size of the descriptor set with room for all array entries */ 68bf215546Sopenharmony_ci uint32_t size; 69bf215546Sopenharmony_ci 70bf215546Sopenharmony_ci /* CPU size of this struct + all associated data, for hashing. */ 71bf215546Sopenharmony_ci uint32_t layout_size; 72bf215546Sopenharmony_ci 73bf215546Sopenharmony_ci /* Shader stages affected by this descriptor set */ 74bf215546Sopenharmony_ci uint16_t shader_stages; 75bf215546Sopenharmony_ci uint16_t dynamic_shader_stages; 76bf215546Sopenharmony_ci 77bf215546Sopenharmony_ci /* Number of buffers in this descriptor set */ 78bf215546Sopenharmony_ci uint32_t buffer_count; 79bf215546Sopenharmony_ci 80bf215546Sopenharmony_ci /* Number of dynamic offsets used by this descriptor set */ 81bf215546Sopenharmony_ci uint16_t dynamic_offset_count; 82bf215546Sopenharmony_ci 83bf215546Sopenharmony_ci bool has_immutable_samplers; 84bf215546Sopenharmony_ci bool has_variable_descriptors; 85bf215546Sopenharmony_ci 86bf215546Sopenharmony_ci uint32_t ycbcr_sampler_offsets_offset; 87bf215546Sopenharmony_ci 88bf215546Sopenharmony_ci /* Bindings in this descriptor set */ 89bf215546Sopenharmony_ci struct radv_descriptor_set_binding_layout binding[0]; 90bf215546Sopenharmony_ci}; 91bf215546Sopenharmony_ci 92bf215546Sopenharmony_cistruct radv_pipeline_layout { 93bf215546Sopenharmony_ci struct vk_object_base base; 94bf215546Sopenharmony_ci struct { 95bf215546Sopenharmony_ci struct radv_descriptor_set_layout *layout; 96bf215546Sopenharmony_ci uint32_t dynamic_offset_start; 97bf215546Sopenharmony_ci } set[MAX_SETS]; 98bf215546Sopenharmony_ci 99bf215546Sopenharmony_ci uint32_t num_sets; 100bf215546Sopenharmony_ci uint32_t push_constant_size; 101bf215546Sopenharmony_ci uint32_t dynamic_offset_count; 102bf215546Sopenharmony_ci uint16_t dynamic_shader_stages; 103bf215546Sopenharmony_ci 104bf215546Sopenharmony_ci bool independent_sets; 105bf215546Sopenharmony_ci 106bf215546Sopenharmony_ci unsigned char sha1[20]; 107bf215546Sopenharmony_ci}; 108bf215546Sopenharmony_ci 109bf215546Sopenharmony_cistatic inline const uint32_t * 110bf215546Sopenharmony_ciradv_immutable_samplers(const struct radv_descriptor_set_layout *set, 111bf215546Sopenharmony_ci const struct radv_descriptor_set_binding_layout *binding) 112bf215546Sopenharmony_ci{ 113bf215546Sopenharmony_ci return (const uint32_t *)((const char *)set + binding->immutable_samplers_offset); 114bf215546Sopenharmony_ci} 115bf215546Sopenharmony_ci 116bf215546Sopenharmony_cistatic inline unsigned 117bf215546Sopenharmony_ciradv_combined_image_descriptor_sampler_offset( 118bf215546Sopenharmony_ci const struct radv_descriptor_set_binding_layout *binding) 119bf215546Sopenharmony_ci{ 120bf215546Sopenharmony_ci return binding->size - ((!binding->immutable_samplers_equal) ? 16 : 0); 121bf215546Sopenharmony_ci} 122bf215546Sopenharmony_ci 123bf215546Sopenharmony_cistatic inline const struct radv_sampler_ycbcr_conversion_state * 124bf215546Sopenharmony_ciradv_immutable_ycbcr_samplers(const struct radv_descriptor_set_layout *set, unsigned binding_index) 125bf215546Sopenharmony_ci{ 126bf215546Sopenharmony_ci if (!set->ycbcr_sampler_offsets_offset) 127bf215546Sopenharmony_ci return NULL; 128bf215546Sopenharmony_ci 129bf215546Sopenharmony_ci const uint32_t *offsets = 130bf215546Sopenharmony_ci (const uint32_t *)((const char *)set + set->ycbcr_sampler_offsets_offset); 131bf215546Sopenharmony_ci 132bf215546Sopenharmony_ci if (offsets[binding_index] == 0) 133bf215546Sopenharmony_ci return NULL; 134bf215546Sopenharmony_ci return (const struct radv_sampler_ycbcr_conversion_state *)((const char *)set + 135bf215546Sopenharmony_ci offsets[binding_index]); 136bf215546Sopenharmony_ci} 137bf215546Sopenharmony_ci 138bf215546Sopenharmony_cistruct radv_device; 139bf215546Sopenharmony_ci 140bf215546Sopenharmony_civoid radv_pipeline_layout_init(struct radv_device *device, struct radv_pipeline_layout *layout, 141bf215546Sopenharmony_ci bool independent_sets); 142bf215546Sopenharmony_civoid radv_pipeline_layout_add_set(struct radv_pipeline_layout *layout, uint32_t set_idx, 143bf215546Sopenharmony_ci struct radv_descriptor_set_layout *set_layout); 144bf215546Sopenharmony_civoid radv_pipeline_layout_hash(struct radv_pipeline_layout *layout); 145bf215546Sopenharmony_civoid radv_pipeline_layout_finish(struct radv_device *device, struct radv_pipeline_layout *layout); 146bf215546Sopenharmony_ci 147bf215546Sopenharmony_ci#endif /* RADV_DESCRIPTOR_SET_H */ 148