1/* 2 * Copyright © 2016 Bas Nieuwenhuizen 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 * IN THE SOFTWARE. 22 */ 23 24#ifndef RADV_DESCRIPTOR_SET_H 25#define RADV_DESCRIPTOR_SET_H 26 27#include <vulkan/vulkan.h> 28 29#define MAX_SETS 32 30 31struct radv_descriptor_set_binding_layout { 32 VkDescriptorType type; 33 34 /* Number of array elements in this binding */ 35 uint32_t array_size; 36 37 uint32_t offset; 38 uint32_t buffer_offset; 39 uint16_t dynamic_offset_offset; 40 41 uint16_t dynamic_offset_count; 42 /* redundant with the type, each for a single array element */ 43 uint32_t size; 44 45 /* Offset in the radv_descriptor_set_layout of the immutable samplers, or 0 46 * if there are no immutable samplers. */ 47 uint32_t immutable_samplers_offset; 48 bool immutable_samplers_equal; 49}; 50 51struct radv_descriptor_set_layout { 52 /* The create flags for this descriptor set layout */ 53 VkDescriptorSetLayoutCreateFlags flags; 54 55 /* Number of bindings in this descriptor set */ 56 uint32_t binding_count; 57 58 /* Total size of the descriptor set with room for all array entries */ 59 uint32_t size; 60 61 /* CPU size of this struct + all associated data, for hashing. */ 62 uint32_t layout_size; 63 64 /* Shader stages affected by this descriptor set */ 65 uint16_t shader_stages; 66 uint16_t dynamic_shader_stages; 67 68 /* Number of buffers in this descriptor set */ 69 uint32_t buffer_count; 70 71 /* Number of dynamic offsets used by this descriptor set */ 72 uint16_t dynamic_offset_count; 73 74 bool has_immutable_samplers; 75 bool has_variable_descriptors; 76 77 uint32_t ycbcr_sampler_offsets_offset; 78 79 /* Bindings in this descriptor set */ 80 struct radv_descriptor_set_binding_layout binding[0]; 81}; 82 83struct radv_pipeline_layout { 84 struct { 85 struct radv_descriptor_set_layout *layout; 86 uint32_t size; 87 uint32_t dynamic_offset_start; 88 } set[MAX_SETS]; 89 90 uint32_t num_sets; 91 uint32_t push_constant_size; 92 uint32_t dynamic_offset_count; 93 uint16_t dynamic_shader_stages; 94 95 unsigned char sha1[20]; 96}; 97 98static inline const uint32_t * 99radv_immutable_samplers(const struct radv_descriptor_set_layout *set, 100 const struct radv_descriptor_set_binding_layout *binding) { 101 return (const uint32_t*)((const char*)set + binding->immutable_samplers_offset); 102} 103 104static inline unsigned 105radv_combined_image_descriptor_sampler_offset(const struct radv_descriptor_set_binding_layout *binding) 106{ 107 return binding->size - ((!binding->immutable_samplers_equal) ? 16 : 0); 108} 109 110static inline const struct radv_sampler_ycbcr_conversion * 111radv_immutable_ycbcr_samplers(const struct radv_descriptor_set_layout *set, 112 unsigned binding_index) 113{ 114 if (!set->ycbcr_sampler_offsets_offset) 115 return NULL; 116 117 const uint32_t *offsets = (const uint32_t*)((const char*)set + set->ycbcr_sampler_offsets_offset); 118 119 if (offsets[binding_index] == 0) 120 return NULL; 121 return (const struct radv_sampler_ycbcr_conversion *)((const char*)set + offsets[binding_index]); 122} 123#endif /* RADV_DESCRIPTOR_SET_H */ 124