static VkDescriptorSetLayoutBinding *
create_sorted_bindings(const VkDescriptorSetLayoutBinding *bindings, unsigned count) {
- VkDescriptorSetLayoutBinding *sorted_bindings = malloc(count * sizeof(VkDescriptorSetLayoutBinding));
+ VkDescriptorSetLayoutBinding *sorted_bindings = malloc(MAX2(count * sizeof(VkDescriptorSetLayoutBinding), 1));
if (!sorted_bindings)
return NULL;
- memcpy(sorted_bindings, bindings, count * sizeof(VkDescriptorSetLayoutBinding));
-
- qsort(sorted_bindings, count, sizeof(VkDescriptorSetLayoutBinding), binding_compare);
+ if (count) {
+ memcpy(sorted_bindings, bindings, count * sizeof(VkDescriptorSetLayoutBinding));
+ qsort(sorted_bindings, count, sizeof(VkDescriptorSetLayoutBinding), binding_compare);
+ }
return sorted_bindings;
}
struct radv_descriptor_set_layout *set_layout;
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO);
- const VkDescriptorSetLayoutBindingFlagsCreateInfoEXT *variable_flags =
- vk_find_struct_const(pCreateInfo->pNext, DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO_EXT);
+ const VkDescriptorSetLayoutBindingFlagsCreateInfo *variable_flags =
+ vk_find_struct_const(pCreateInfo->pNext, DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO);
uint32_t max_binding = 0;
uint32_t immutable_sampler_count = 0;
}
}
- uint32_t samplers_offset = sizeof(struct radv_descriptor_set_layout) +
- (max_binding + 1) * sizeof(set_layout->binding[0]);
+ uint32_t samplers_offset =
+ offsetof(struct radv_descriptor_set_layout, binding[max_binding + 1]);
size_t size = samplers_offset + immutable_sampler_count * 4 * sizeof(uint32_t);
if (ycbcr_sampler_count > 0) {
size += ycbcr_sampler_count * sizeof(struct radv_sampler_ycbcr_conversion) + (max_binding + 1) * sizeof(uint32_t);
}
- set_layout = vk_alloc2(&device->alloc, pAllocator, size, 8,
- VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+ set_layout = vk_zalloc2(&device->vk.alloc, pAllocator, size, 8,
+ VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (!set_layout)
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
+ vk_object_base_init(&device->vk, &set_layout->base,
+ VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT);
+
set_layout->flags = pCreateInfo->flags;
+ set_layout->layout_size = size;
/* We just allocate all the samplers at the end of the struct */
uint32_t *samplers = (uint32_t*)&set_layout->binding[max_binding + 1];
VkDescriptorSetLayoutBinding *bindings = create_sorted_bindings(pCreateInfo->pBindings,
pCreateInfo->bindingCount);
if (!bindings) {
- vk_free2(&device->alloc, pAllocator, set_layout);
+ vk_object_base_finish(&set_layout->base);
+ vk_free2(&device->vk.alloc, pAllocator, set_layout);
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
}
set_layout->has_immutable_samplers = false;
set_layout->size = 0;
- memset(set_layout->binding, 0, size - sizeof(struct radv_descriptor_set_layout));
-
uint32_t buffer_count = 0;
uint32_t dynamic_offset_count = 0;
for (uint32_t j = 0; j < pCreateInfo->bindingCount; j++) {
const VkDescriptorSetLayoutBinding *binding = bindings + j;
uint32_t b = binding->binding;
- uint32_t alignment;
+ uint32_t alignment = 0;
unsigned binding_buffer_count = 0;
uint32_t descriptor_count = binding->descriptorCount;
bool has_ycbcr_sampler = false;
break;
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
/* main descriptor + fmask descriptor + sampler */
- set_layout->binding[b].size = 32 + 32 * max_sampled_image_descriptors;
+ set_layout->binding[b].size = 96;
binding_buffer_count = 1;
alignment = 32;
break;
descriptor_count = 1;
break;
default:
- unreachable("unknown descriptor type\n");
break;
}
/* Don't reserve space for the samplers if they're not accessed. */
if (set_layout->binding[b].immutable_samplers_equal) {
- if (binding->descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
+ if (binding->descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER &&
+ max_sampled_image_descriptors <= 2)
set_layout->binding[b].size -= 32;
else if (binding->descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER)
set_layout->binding[b].size -= 16;
if (!set_layout)
return;
- vk_free2(&device->alloc, pAllocator, set_layout);
+ vk_object_base_finish(&set_layout->base);
+ vk_free2(&device->vk.alloc, pAllocator, set_layout);
}
void radv_GetDescriptorSetLayoutSupport(VkDevice device,
return;
}
- const VkDescriptorSetLayoutBindingFlagsCreateInfoEXT *variable_flags =
- vk_find_struct_const(pCreateInfo->pNext, DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO_EXT);
- VkDescriptorSetVariableDescriptorCountLayoutSupportEXT *variable_count =
- vk_find_struct((void*)pCreateInfo->pNext, DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_LAYOUT_SUPPORT_EXT);
+ const VkDescriptorSetLayoutBindingFlagsCreateInfo *variable_flags =
+ vk_find_struct_const(pCreateInfo->pNext, DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO);
+ VkDescriptorSetVariableDescriptorCountLayoutSupport *variable_count =
+ vk_find_struct((void*)pCreateInfo->pNext, DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_LAYOUT_SUPPORT);
if (variable_count) {
variable_count->maxVariableDescriptorCount = 0;
}
descriptor_count = 1;
break;
default:
- unreachable("unknown descriptor type\n");
break;
}
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO);
- layout = vk_alloc2(&device->alloc, pAllocator, sizeof(*layout), 8,
+ layout = vk_alloc2(&device->vk.alloc, pAllocator, sizeof(*layout), 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (layout == NULL)
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
+ vk_object_base_init(&device->vk, &layout->base,
+ VK_OBJECT_TYPE_PIPELINE_LAYOUT);
+
layout->num_sets = pCreateInfo->setLayoutCount;
unsigned dynamic_offset_count = 0;
for (uint32_t b = 0; b < set_layout->binding_count; b++) {
dynamic_offset_count += set_layout->binding[b].array_size * set_layout->binding[b].dynamic_offset_count;
dynamic_shader_stages |= set_layout->dynamic_shader_stages;
- if (set_layout->binding[b].immutable_samplers_offset)
- _mesa_sha1_update(&ctx, radv_immutable_samplers(set_layout, set_layout->binding + b),
- set_layout->binding[b].array_size * 4 * sizeof(uint32_t));
}
- _mesa_sha1_update(&ctx, set_layout->binding,
- sizeof(set_layout->binding[0]) * set_layout->binding_count);
+ _mesa_sha1_update(&ctx, set_layout, set_layout->layout_size);
}
layout->dynamic_offset_count = dynamic_offset_count;
if (!pipeline_layout)
return;
- vk_free2(&device->alloc, pAllocator, pipeline_layout);
+
+ vk_object_base_finish(&pipeline_layout->base);
+ vk_free2(&device->vk.alloc, pAllocator, pipeline_layout);
}
#define EMPTY 1
struct radv_descriptor_set **out_set)
{
struct radv_descriptor_set *set;
+ uint32_t buffer_count = layout->buffer_count;
+ if (variable_count) {
+ unsigned stride = 1;
+ if (layout->binding[layout->binding_count - 1].type == VK_DESCRIPTOR_TYPE_SAMPLER ||
+ layout->binding[layout->binding_count - 1].type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT)
+ stride = 0;
+ buffer_count = layout->binding[layout->binding_count - 1].buffer_offset +
+ *variable_count * stride;
+ }
unsigned range_offset = sizeof(struct radv_descriptor_set) +
- sizeof(struct radeon_winsys_bo *) * layout->buffer_count;
+ sizeof(struct radeon_winsys_bo *) * buffer_count;
unsigned mem_size = range_offset +
sizeof(struct radv_descriptor_range) * layout->dynamic_offset_count;
set = (struct radv_descriptor_set*)pool->host_memory_ptr;
pool->host_memory_ptr += mem_size;
} else {
- set = vk_alloc2(&device->alloc, NULL, mem_size, 8,
+ set = vk_alloc2(&device->vk.alloc, NULL, mem_size, 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (!set)
memset(set, 0, mem_size);
+ vk_object_base_init(&device->vk, &set->base,
+ VK_OBJECT_TYPE_DESCRIPTOR_SET);
+
if (layout->dynamic_offset_count) {
set->dynamic_descriptors = (struct radv_descriptor_range*)((uint8_t*)set + range_offset);
}
set->layout = layout;
- uint32_t layout_size = align_u32(layout->size, 32);
+ set->buffer_count = buffer_count;
+ uint32_t layout_size = layout->size;
+ if (variable_count) {
+ assert(layout->has_variable_descriptors);
+ uint32_t stride = layout->binding[layout->binding_count - 1].size;
+ if (layout->binding[layout->binding_count - 1].type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT)
+ stride = 1;
+
+ layout_size = layout->binding[layout->binding_count - 1].offset +
+ *variable_count * stride;
+ }
+ layout_size = align_u32(layout_size, 32);
if (layout_size) {
set->size = layout_size;
if (!pool->host_memory_base && pool->entry_count == pool->max_entry_count) {
- vk_free2(&device->alloc, NULL, set);
+ vk_free2(&device->vk.alloc, NULL, set);
return vk_error(device->instance, VK_ERROR_OUT_OF_POOL_MEMORY);
}
}
if (pool->size - offset < layout_size) {
- vk_free2(&device->alloc, NULL, set);
+ vk_free2(&device->vk.alloc, NULL, set);
return vk_error(device->instance, VK_ERROR_OUT_OF_POOL_MEMORY);
}
set->bo = pool->bo;
}
}
}
- vk_free2(&device->alloc, NULL, set);
+ vk_object_base_finish(&set->base);
+ vk_free2(&device->vk.alloc, NULL, set);
+}
+
+static void radv_destroy_descriptor_pool(struct radv_device *device,
+ const VkAllocationCallbacks *pAllocator,
+ struct radv_descriptor_pool *pool)
+{
+ if (!pool->host_memory_base) {
+ for(int i = 0; i < pool->entry_count; ++i) {
+ radv_descriptor_set_destroy(device, pool, pool->entries[i].set, false);
+ }
+ }
+
+ if (pool->bo)
+ device->ws->buffer_destroy(pool->bo);
+
+ vk_object_base_finish(&pool->base);
+ vk_free2(&device->vk.alloc, pAllocator, pool);
}
VkResult radv_CreateDescriptorPool(
bo_size += pCreateInfo->pPoolSizes[i].descriptorCount;
break;
default:
- unreachable("unknown descriptor type\n");
break;
}
}
size += sizeof(struct radv_descriptor_pool_entry) * pCreateInfo->maxSets;
}
- pool = vk_alloc2(&device->alloc, pAllocator, size, 8,
+ pool = vk_alloc2(&device->vk.alloc, pAllocator, size, 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (!pool)
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
memset(pool, 0, sizeof(*pool));
+ vk_object_base_init(&device->vk, &pool->base,
+ VK_OBJECT_TYPE_DESCRIPTOR_POOL);
+
if (!(pCreateInfo->flags & VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT)) {
pool->host_memory_base = (uint8_t*)pool + sizeof(struct radv_descriptor_pool);
pool->host_memory_ptr = pool->host_memory_base;
RADEON_FLAG_READ_ONLY |
RADEON_FLAG_32BIT,
RADV_BO_PRIORITY_DESCRIPTOR);
+ if (!pool->bo) {
+ radv_destroy_descriptor_pool(device, pAllocator, pool);
+ return vk_error(device->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY);
+ }
pool->mapped_ptr = (uint8_t*)device->ws->buffer_map(pool->bo);
+ if (!pool->mapped_ptr) {
+ radv_destroy_descriptor_pool(device, pAllocator, pool);
+ return vk_error(device->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY);
+ }
}
pool->size = bo_size;
pool->max_entry_count = pCreateInfo->maxSets;
if (!pool)
return;
- if (!pool->host_memory_base) {
- for(int i = 0; i < pool->entry_count; ++i) {
- radv_descriptor_set_destroy(device, pool, pool->entries[i].set, false);
- }
- }
-
- if (pool->bo)
- device->ws->buffer_destroy(pool->bo);
- vk_free2(&device->alloc, pAllocator, pool);
+ radv_destroy_descriptor_pool(device, pAllocator, pool);
}
VkResult radv_ResetDescriptorPool(
uint32_t i;
struct radv_descriptor_set *set = NULL;
- const VkDescriptorSetVariableDescriptorCountAllocateInfoEXT *variable_counts =
- vk_find_struct_const(pAllocateInfo->pNext, DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO_EXT);
+ const VkDescriptorSetVariableDescriptorCountAllocateInfo *variable_counts =
+ vk_find_struct_const(pAllocateInfo->pNext, DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO);
const uint32_t zero = 0;
/* allocate a set of buffers for each shader to contain descriptors */
pDescriptorSets[i] = radv_descriptor_set_to_handle(set);
}
- if (result != VK_SUCCESS)
+ if (result != VK_SUCCESS) {
radv_FreeDescriptorSets(_device, pAllocateInfo->descriptorPool,
i, pDescriptorSets);
+ for (i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
+ pDescriptorSets[i] = VK_NULL_HANDLE;
+ }
+ }
return result;
}
{
RADV_FROM_HANDLE(radv_buffer_view, buffer_view, _buffer_view);
+ if (!buffer_view) {
+ memset(dst, 0, 4 * 4);
+ return;
+ }
+
memcpy(dst, buffer_view->state, 4 * 4);
if (cmd_buffer)
const VkDescriptorBufferInfo *buffer_info)
{
RADV_FROM_HANDLE(radv_buffer, buffer, buffer_info->buffer);
+
+ if (!buffer) {
+ memset(dst, 0, 4 * 4);
+ return;
+ }
+
uint64_t va = radv_buffer_get_va(buffer->bo);
uint32_t range = buffer_info->range;
if (buffer_info->range == VK_WHOLE_SIZE)
range = buffer->size - buffer_info->offset;
+ /* robustBufferAccess is relaxed enough to allow this (in combination
+ * with the alignment/size we return from vkGetBufferMemoryRequirements)
+ * and this allows the shader compiler to create more efficient 8/16-bit
+ * buffer accesses. */
+ range = align(range, 4);
+
va += buffer_info->offset + buffer->offset;
+
+ uint32_t rsrc_word3 = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X) |
+ S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y) |
+ S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z) |
+ S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W);
+
+ if (device->physical_device->rad_info.chip_class >= GFX10) {
+ rsrc_word3 |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT) |
+ S_008F0C_OOB_SELECT(V_008F0C_OOB_SELECT_RAW) |
+ S_008F0C_RESOURCE_LEVEL(1);
+ } else {
+ rsrc_word3 |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT) |
+ S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32);
+ }
+
dst[0] = va;
dst[1] = S_008F04_BASE_ADDRESS_HI(va >> 32);
dst[2] = range;
- dst[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X) |
- S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y) |
- S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z) |
- S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W) |
- S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT) |
- S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32);
+ dst[3] = rsrc_word3;
if (cmd_buffer)
radv_cs_add_buffer(device->ws, cmd_buffer->cs, buffer->bo);
const VkDescriptorBufferInfo *buffer_info)
{
RADV_FROM_HANDLE(radv_buffer, buffer, buffer_info->buffer);
- uint64_t va = radv_buffer_get_va(buffer->bo);
- unsigned size = buffer_info->range;
+ uint64_t va;
+ unsigned size;
+
+ if (!buffer)
+ return;
+
+ va = radv_buffer_get_va(buffer->bo);
+ size = buffer_info->range;
if (buffer_info->range == VK_WHOLE_SIZE)
size = buffer->size - buffer_info->offset;
+ /* robustBufferAccess is relaxed enough to allow this (in combination
+ * with the alignment/size we return from vkGetBufferMemoryRequirements)
+ * and this allows the shader compiler to create more efficient 8/16-bit
+ * buffer accesses. */
+ size = align(size, 4);
+
va += buffer_info->offset + buffer->offset;
range->va = va;
range->size = size;
RADV_FROM_HANDLE(radv_image_view, iview, image_info->imageView);
union radv_descriptor *descriptor;
+ if (!iview) {
+ memset(dst, 0, size);
+ return;
+ }
+
if (descriptor_type == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) {
descriptor = &iview->storage_descriptor;
} else {
}
break;
default:
- unreachable("unimplemented descriptor type");
break;
}
ptr += binding_layout->size / 4;
src_ptr += src_binding_layout->offset / 4;
dst_ptr += dst_binding_layout->offset / 4;
+ if (src_binding_layout->type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) {
+ src_ptr += copyset->srcArrayElement / 4;
+ dst_ptr += copyset->dstArrayElement / 4;
+
+ memcpy(dst_ptr, src_ptr, copyset->descriptorCount);
+ continue;
+ }
+
src_ptr += src_binding_layout->size * copyset->srcArrayElement / 4;
dst_ptr += dst_binding_layout->size * copyset->dstArrayElement / 4;
struct radv_descriptor_update_template *templ;
uint32_t i;
- templ = vk_alloc2(&device->alloc, pAllocator, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+ templ = vk_alloc2(&device->vk.alloc, pAllocator, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (!templ)
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
+ vk_object_base_init(&device->vk, &templ->base,
+ VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE);
+
templ->entry_count = entry_count;
- templ->bind_point = pCreateInfo->pipelineBindPoint;
+
+ if (pCreateInfo->templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR) {
+ RADV_FROM_HANDLE(radv_pipeline_layout, pipeline_layout, pCreateInfo->pipelineLayout);
+
+ /* descriptorSetLayout should be ignored for push descriptors
+ * and instead it refers to pipelineLayout and set.
+ */
+ assert(pCreateInfo->set < MAX_SETS);
+ set_layout = pipeline_layout->set[pCreateInfo->set].layout;
+
+ templ->bind_point = pCreateInfo->pipelineBindPoint;
+ }
for (i = 0; i < entry_count; i++) {
const VkDescriptorUpdateTemplateEntry *entry = &pCreateInfo->pDescriptorUpdateEntries[i];
if (!templ)
return;
- vk_free2(&device->alloc, pAllocator, templ);
+ vk_object_base_finish(&templ->base);
+ vk_free2(&device->vk.alloc, pAllocator, templ);
}
void radv_update_descriptor_set_with_template(struct radv_device *device,
memcpy(pDst, templ->entry[i].immutable_samplers + 4 * j, 16);
break;
default:
- unreachable("unimplemented descriptor type");
break;
}
pSrc += templ->entry[i].src_stride;
RADV_FROM_HANDLE(radv_device, device, _device);
struct radv_sampler_ycbcr_conversion *conversion = NULL;
- conversion = vk_zalloc2(&device->alloc, pAllocator, sizeof(*conversion), 8,
+ conversion = vk_zalloc2(&device->vk.alloc, pAllocator, sizeof(*conversion), 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (conversion == NULL)
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
+ vk_object_base_init(&device->vk, &conversion->base,
+ VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION);
+
conversion->format = pCreateInfo->format;
conversion->ycbcr_model = pCreateInfo->ycbcrModel;
conversion->ycbcr_range = pCreateInfo->ycbcrRange;
RADV_FROM_HANDLE(radv_device, device, _device);
RADV_FROM_HANDLE(radv_sampler_ycbcr_conversion, ycbcr_conversion, ycbcrConversion);
- if (ycbcr_conversion)
- vk_free2(&device->alloc, pAllocator, ycbcr_conversion);
+ if (!ycbcr_conversion)
+ return;
+
+ vk_object_base_finish(&ycbcr_conversion->base);
+ vk_free2(&device->vk.alloc, pAllocator, ycbcr_conversion);
}