X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fintel%2Fvulkan%2Fanv_descriptor_set.c;h=a8e1915e6b98cc1b2e703ff82fe6135b60dae1f2;hb=70e8064e131467527e70a681ac6cf763587bd8bf;hp=90a02997a8dcc00fa15047771e23f8b7a3da199c;hpb=146deec9ef5f73794daba4ad7cd95016fd07266a;p=mesa.git diff --git a/src/intel/vulkan/anv_descriptor_set.c b/src/intel/vulkan/anv_descriptor_set.c index 90a02997a8d..a8e1915e6b9 100644 --- a/src/intel/vulkan/anv_descriptor_set.c +++ b/src/intel/vulkan/anv_descriptor_set.c @@ -45,15 +45,24 @@ anv_descriptor_data_for_type(const struct anv_physical_device *device, switch (type) { case VK_DESCRIPTOR_TYPE_SAMPLER: data = ANV_DESCRIPTOR_SAMPLER_STATE; + if (device->has_bindless_samplers) + data |= ANV_DESCRIPTOR_SAMPLED_IMAGE; break; case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: data = ANV_DESCRIPTOR_SURFACE_STATE | ANV_DESCRIPTOR_SAMPLER_STATE; + if (device->has_bindless_images || device->has_bindless_samplers) + data |= ANV_DESCRIPTOR_SAMPLED_IMAGE; break; case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: + data = ANV_DESCRIPTOR_SURFACE_STATE; + if (device->has_bindless_images) + data |= ANV_DESCRIPTOR_SAMPLED_IMAGE; + break; + case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: data = ANV_DESCRIPTOR_SURFACE_STATE; break; @@ -63,6 +72,8 @@ anv_descriptor_data_for_type(const struct anv_physical_device *device, data = ANV_DESCRIPTOR_SURFACE_STATE; if (device->info.gen < 9) data |= ANV_DESCRIPTOR_IMAGE_PARAM; + if (device->has_bindless_images) + data |= ANV_DESCRIPTOR_STORAGE_IMAGE; break; case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: @@ -84,6 +95,24 @@ anv_descriptor_data_for_type(const struct anv_physical_device *device, unreachable("Unsupported descriptor type"); } + /* On gen8 and above when we have softpin enabled, we also need to push + * SSBO address ranges so that we can use A64 messages in the shader. + */ + if (device->has_a64_buffer_access && + (type == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER || + type == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) + data |= ANV_DESCRIPTOR_ADDRESS_RANGE; + + /* On Ivy Bridge and Bay Trail, we need swizzles textures in the shader + * Do not handle VK_DESCRIPTOR_TYPE_STORAGE_IMAGE and + * VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT because they already must + * have identity swizzle. + */ + if (device->info.gen == 7 && !device->info.is_haswell && + (type == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE || + type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)) + data |= ANV_DESCRIPTOR_TEXTURE_SWIZZLE; + return data; } @@ -92,12 +121,34 @@ anv_descriptor_data_size(enum anv_descriptor_data data) { unsigned size = 0; + if (data & ANV_DESCRIPTOR_SAMPLED_IMAGE) + size += sizeof(struct anv_sampled_image_descriptor); + + if (data & ANV_DESCRIPTOR_STORAGE_IMAGE) + size += sizeof(struct anv_storage_image_descriptor); + if (data & ANV_DESCRIPTOR_IMAGE_PARAM) size += BRW_IMAGE_PARAM_SIZE * 4; + if (data & ANV_DESCRIPTOR_ADDRESS_RANGE) + size += sizeof(struct anv_address_range_descriptor); + + if (data & ANV_DESCRIPTOR_TEXTURE_SWIZZLE) + size += sizeof(struct anv_texture_swizzle_descriptor); + return size; } +static bool +anv_needs_descriptor_buffer(VkDescriptorType desc_type, + enum anv_descriptor_data desc_data) +{ + if (desc_type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT || + anv_descriptor_data_size(desc_data) > 0) + return true; + return false; +} + /** Returns the size in bytes of each descriptor with the given layout */ unsigned anv_descriptor_size(const struct anv_descriptor_set_binding_layout *layout) @@ -107,7 +158,17 @@ anv_descriptor_size(const struct anv_descriptor_set_binding_layout *layout) return layout->array_size; } - return anv_descriptor_data_size(layout->data); + unsigned size = anv_descriptor_data_size(layout->data); + + /* For multi-planar bindings, we make every descriptor consume the maximum + * number of planes so we don't have to bother with walking arrays and + * adding things up every time. Fortunately, YCbCr samplers aren't all + * that common and likely won't be in the middle of big arrays. + */ + if (layout->max_plane_count > 1) + size *= layout->max_plane_count; + + return size; } /** Returns the size in bytes of each descriptor of the given type @@ -121,7 +182,11 @@ unsigned anv_descriptor_type_size(const struct anv_physical_device *pdevice, VkDescriptorType type) { - assert(type != VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT); + assert(type != VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT && + type != VK_DESCRIPTOR_TYPE_SAMPLER && + type != VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE && + type != VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER); + return anv_descriptor_data_size(anv_descriptor_data_for_type(pdevice, type)); } @@ -130,6 +195,22 @@ anv_descriptor_data_supports_bindless(const struct anv_physical_device *pdevice, enum anv_descriptor_data data, bool sampler) { + if (data & ANV_DESCRIPTOR_ADDRESS_RANGE) { + assert(pdevice->has_a64_buffer_access); + return true; + } + + if (data & ANV_DESCRIPTOR_SAMPLED_IMAGE) { + assert(pdevice->has_bindless_images || pdevice->has_bindless_samplers); + return sampler ? pdevice->has_bindless_samplers : + pdevice->has_bindless_images; + } + + if (data & ANV_DESCRIPTOR_STORAGE_IMAGE) { + assert(pdevice->has_bindless_images); + return true; + } + return false; } @@ -150,7 +231,12 @@ anv_descriptor_requires_bindless(const struct anv_physical_device *pdevice, if (pdevice->always_use_bindless) return anv_descriptor_supports_bindless(pdevice, binding, sampler); - return false; + static const VkDescriptorBindingFlagBitsEXT flags_requiring_bindless = + VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT | + VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT_EXT | + VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT_EXT; + + return (binding->flags & flags_requiring_bindless) != 0; } void anv_GetDescriptorSetLayoutSupport( @@ -159,10 +245,10 @@ void anv_GetDescriptorSetLayoutSupport( VkDescriptorSetLayoutSupport* pSupport) { ANV_FROM_HANDLE(anv_device, device, _device); - const struct anv_physical_device *pdevice = - &device->instance->physicalDevice; + const struct anv_physical_device *pdevice = device->physical; uint32_t surface_count[MESA_SHADER_STAGES] = { 0, }; + bool needs_descriptor_buffer = false; for (uint32_t b = 0; b < pCreateInfo->bindingCount; b++) { const VkDescriptorSetLayoutBinding *binding = &pCreateInfo->pBindings[b]; @@ -170,11 +256,18 @@ void anv_GetDescriptorSetLayoutSupport( enum anv_descriptor_data desc_data = anv_descriptor_data_for_type(pdevice, binding->descriptorType); + if (anv_needs_descriptor_buffer(binding->descriptorType, desc_data)) + needs_descriptor_buffer = true; + switch (binding->descriptorType) { case VK_DESCRIPTOR_TYPE_SAMPLER: /* There is no real limit on samplers */ break; + case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT: + /* Inline uniforms don't use a binding */ + break; + case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: if (anv_descriptor_data_supports_bindless(pdevice, desc_data, false)) break; @@ -202,12 +295,17 @@ void anv_GetDescriptorSetLayoutSupport( } } + for (unsigned s = 0; s < MESA_SHADER_STAGES; s++) { + if (needs_descriptor_buffer) + surface_count[s] += 1; + } + bool supported = true; for (unsigned s = 0; s < MESA_SHADER_STAGES; s++) { /* Our maximum binding table size is 240 and we need to reserve 8 for * render targets. */ - if (surface_count[s] >= MAX_BINDING_TABLE_SIZE - MAX_RTS) + if (surface_count[s] > MAX_BINDING_TABLE_SIZE - MAX_RTS) supported = false; } @@ -272,7 +370,9 @@ VkResult anv_CreateDescriptorSetLayout( /* Initialize all binding_layout entries to -1 */ memset(&set_layout->binding[b], -1, sizeof(set_layout->binding[b])); + set_layout->binding[b].flags = 0; set_layout->binding[b].data = 0; + set_layout->binding[b].max_plane_count = 0; set_layout->binding[b].array_size = 0; set_layout->binding[b].immutable_samplers = NULL; } @@ -287,34 +387,46 @@ VkResult anv_CreateDescriptorSetLayout( for (uint32_t j = 0; j < pCreateInfo->bindingCount; j++) { const VkDescriptorSetLayoutBinding *binding = &pCreateInfo->pBindings[j]; uint32_t b = binding->binding; - /* We temporarily store the pointer to the binding in the + /* We temporarily store pCreateInfo->pBindings[] index (plus one) in the * immutable_samplers pointer. This provides us with a quick-and-dirty * way to sort the bindings by binding number. */ - set_layout->binding[b].immutable_samplers = (void *)binding; + set_layout->binding[b].immutable_samplers = (void *)(uintptr_t)(j + 1); } - for (uint32_t b = 0; b <= max_binding; b++) { - const VkDescriptorSetLayoutBinding *binding = - (void *)set_layout->binding[b].immutable_samplers; - - if (binding == NULL) - continue; + const VkDescriptorSetLayoutBindingFlagsCreateInfoEXT *binding_flags_info = + vk_find_struct_const(pCreateInfo->pNext, + DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO_EXT); - /* We temporarily stashed the pointer to the binding in the - * immutable_samplers pointer. Now that we've pulled it back out - * again, we reset immutable_samplers to NULL. + for (uint32_t b = 0; b <= max_binding; b++) { + /* We stashed the pCreateInfo->pBindings[] index (plus one) in the + * immutable_samplers pointer. Check for NULL (empty binding) and then + * reset it and compute the index. */ + if (set_layout->binding[b].immutable_samplers == NULL) + continue; + const uint32_t info_idx = + (uintptr_t)(void *)set_layout->binding[b].immutable_samplers - 1; set_layout->binding[b].immutable_samplers = NULL; + const VkDescriptorSetLayoutBinding *binding = + &pCreateInfo->pBindings[info_idx]; + if (binding->descriptorCount == 0) continue; #ifndef NDEBUG set_layout->binding[b].type = binding->descriptorType; #endif + + if (binding_flags_info && binding_flags_info->bindingCount > 0) { + assert(binding_flags_info->bindingCount == pCreateInfo->bindingCount); + set_layout->binding[b].flags = + binding_flags_info->pBindingFlags[info_idx]; + } + set_layout->binding[b].data = - anv_descriptor_data_for_type(&device->instance->physicalDevice, + anv_descriptor_data_for_type(device->physical, binding->descriptorType); set_layout->binding[b].array_size = binding->descriptorCount; set_layout->binding[b].descriptor_index = set_layout->size; @@ -328,15 +440,26 @@ VkResult anv_CreateDescriptorSetLayout( switch (binding->descriptorType) { case VK_DESCRIPTOR_TYPE_SAMPLER: case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: + set_layout->binding[b].max_plane_count = 1; if (binding->pImmutableSamplers) { set_layout->binding[b].immutable_samplers = samplers; samplers += binding->descriptorCount; - for (uint32_t i = 0; i < binding->descriptorCount; i++) - set_layout->binding[b].immutable_samplers[i] = - anv_sampler_from_handle(binding->pImmutableSamplers[i]); + for (uint32_t i = 0; i < binding->descriptorCount; i++) { + ANV_FROM_HANDLE(anv_sampler, sampler, + binding->pImmutableSamplers[i]); + + set_layout->binding[b].immutable_samplers[i] = sampler; + if (set_layout->binding[b].max_plane_count < sampler->n_planes) + set_layout->binding[b].max_plane_count = sampler->n_planes; + } } break; + + case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: + set_layout->binding[b].max_plane_count = 1; + break; + default: break; } @@ -345,7 +468,15 @@ VkResult anv_CreateDescriptorSetLayout( case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: set_layout->binding[b].dynamic_offset_index = dynamic_offset_count; + anv_foreach_stage(s, binding->stageFlags) { + STATIC_ASSERT(MAX_DYNAMIC_BUFFERS <= + sizeof(set_layout->stage_dynamic_offsets[s]) * 8); + set_layout->stage_dynamic_offsets[s] |= + BITFIELD_RANGE(set_layout->binding[b].dynamic_offset_index, + binding->descriptorCount); + } dynamic_offset_count += binding->descriptorCount; + assert(dynamic_offset_count < MAX_DYNAMIC_BUFFERS); break; default: @@ -410,7 +541,9 @@ static void sha1_update_descriptor_set_binding_layout(struct mesa_sha1 *ctx, const struct anv_descriptor_set_binding_layout *layout) { + SHA1_UPDATE_VALUE(ctx, layout->flags); SHA1_UPDATE_VALUE(ctx, layout->data); + SHA1_UPDATE_VALUE(ctx, layout->max_plane_count); SHA1_UPDATE_VALUE(ctx, layout->array_size); SHA1_UPDATE_VALUE(ctx, layout->descriptor_index); SHA1_UPDATE_VALUE(ctx, layout->dynamic_offset_index); @@ -477,6 +610,7 @@ VkResult anv_CreatePipelineLayout( dynamic_offset_count += set_layout->binding[b].array_size; } } + assert(dynamic_offset_count < MAX_DYNAMIC_BUFFERS); struct mesa_sha1 ctx; _mesa_sha1_init(&ctx); @@ -548,7 +682,7 @@ VkResult anv_CreateDescriptorPool( uint32_t descriptor_bo_size = 0; for (uint32_t i = 0; i < pCreateInfo->poolSizeCount; i++) { enum anv_descriptor_data desc_data = - anv_descriptor_data_for_type(&device->instance->physicalDevice, + anv_descriptor_data_for_type(device->physical, pCreateInfo->pPoolSizes[i].type); if (desc_data & ANV_DESCRIPTOR_BUFFER_VIEW) @@ -557,6 +691,13 @@ VkResult anv_CreateDescriptorPool( unsigned desc_data_size = anv_descriptor_data_size(desc_data) * pCreateInfo->pPoolSizes[i].descriptorCount; + /* Combined image sampler descriptors can take up to 3 slots if they + * hold a YCbCr image. + */ + if (pCreateInfo->pPoolSizes[i].type == + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) + desc_data_size *= 3; + if (pCreateInfo->pPoolSizes[i].type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) { /* Inline uniform blocks are specified to use the descriptor array @@ -579,10 +720,10 @@ VkResult anv_CreateDescriptorPool( * of them to 32B. */ descriptor_bo_size += 32 * pCreateInfo->maxSets; - descriptor_bo_size = ALIGN(descriptor_bo_size, 4096); /* We align inline uniform blocks to 32B */ if (inline_info) descriptor_bo_size += 32 * inline_info->maxInlineUniformBlockBindings; + descriptor_bo_size = ALIGN(descriptor_bo_size, 4096); const size_t pool_size = pCreateInfo->maxSets * sizeof(struct anv_descriptor_set) + @@ -600,30 +741,20 @@ VkResult anv_CreateDescriptorPool( pool->free_list = EMPTY; if (descriptor_bo_size > 0) { - VkResult result = anv_bo_init_new(&pool->bo, device, descriptor_bo_size); + VkResult result = anv_device_alloc_bo(device, + descriptor_bo_size, + ANV_BO_ALLOC_MAPPED | + ANV_BO_ALLOC_SNOOPED, + 0 /* explicit_address */, + &pool->bo); if (result != VK_SUCCESS) { vk_free2(&device->alloc, pAllocator, pool); return result; } - anv_gem_set_caching(device, pool->bo.gem_handle, I915_CACHING_CACHED); - - pool->bo.map = anv_gem_mmap(device, pool->bo.gem_handle, 0, - descriptor_bo_size, 0); - if (pool->bo.map == NULL) { - anv_gem_close(device, pool->bo.gem_handle); - vk_free2(&device->alloc, pAllocator, pool); - return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); - } - - if (device->instance->physicalDevice.use_softpin) { - pool->bo.flags |= EXEC_OBJECT_PINNED; - anv_vma_alloc(device, &pool->bo); - } - util_vma_heap_init(&pool->bo_heap, POOL_HEAP_OFFSET, descriptor_bo_size); } else { - pool->bo.size = 0; + pool->bo = NULL; } anv_state_stream_init(&pool->surface_state_stream, @@ -648,19 +779,14 @@ void anv_DestroyDescriptorPool( if (!pool) return; - if (pool->bo.size) { - anv_gem_munmap(pool->bo.map, pool->bo.size); - anv_vma_free(device, &pool->bo); - anv_gem_close(device, pool->bo.gem_handle); - } - anv_state_stream_finish(&pool->surface_state_stream); - list_for_each_entry_safe(struct anv_descriptor_set, set, &pool->desc_sets, pool_link) { - anv_descriptor_set_destroy(device, pool, set); + anv_descriptor_set_layout_unref(device, set->layout); } - util_vma_heap_finish(&pool->bo_heap); + if (pool->bo) + anv_device_release_bo(device, pool->bo); + anv_state_stream_finish(&pool->surface_state_stream); vk_free2(&device->alloc, pAllocator, pool); } @@ -675,15 +801,16 @@ VkResult anv_ResetDescriptorPool( list_for_each_entry_safe(struct anv_descriptor_set, set, &pool->desc_sets, pool_link) { - anv_descriptor_set_destroy(device, pool, set); + anv_descriptor_set_layout_unref(device, set->layout); } + list_inithead(&pool->desc_sets); pool->next = 0; pool->free_list = EMPTY; - if (pool->bo.size) { + if (pool->bo) { util_vma_heap_finish(&pool->bo_heap); - util_vma_heap_init(&pool->bo_heap, POOL_HEAP_OFFSET, pool->bo.size); + util_vma_heap_init(&pool->bo_heap, POOL_HEAP_OFFSET, pool->bo->size); } anv_state_stream_finish(&pool->surface_state_stream); @@ -743,8 +870,6 @@ anv_descriptor_pool_free_set(struct anv_descriptor_pool *pool, entry->size = set->size; pool->free_list = (char *) entry - pool->data; } - - list_del(&set->pool_link); } struct surface_state_free_list_entry { @@ -805,9 +930,9 @@ anv_descriptor_set_create(struct anv_device *device, /* Align the size to 32 so that alignment gaps don't cause extra holes * in the heap which can lead to bad performance. */ + uint32_t set_buffer_size = ALIGN(layout->descriptor_buffer_size, 32); uint64_t pool_vma_offset = - util_vma_heap_alloc(&pool->bo_heap, - ALIGN(layout->descriptor_buffer_size, 32), 32); + util_vma_heap_alloc(&pool->bo_heap, set_buffer_size, 32); if (pool_vma_offset == 0) { anv_descriptor_pool_free_set(pool, set); return vk_error(VK_ERROR_FRAGMENTED_POOL); @@ -815,14 +940,14 @@ anv_descriptor_set_create(struct anv_device *device, assert(pool_vma_offset >= POOL_HEAP_OFFSET && pool_vma_offset - POOL_HEAP_OFFSET <= INT32_MAX); set->desc_mem.offset = pool_vma_offset - POOL_HEAP_OFFSET; - set->desc_mem.alloc_size = layout->descriptor_buffer_size; - set->desc_mem.map = pool->bo.map + set->desc_mem.offset; + set->desc_mem.alloc_size = set_buffer_size; + set->desc_mem.map = pool->bo->map + set->desc_mem.offset; set->desc_surface_state = anv_descriptor_pool_alloc_state(pool); anv_fill_buffer_surface_state(device, set->desc_surface_state, ISL_FORMAT_R32G32B32A32_FLOAT, (struct anv_address) { - .bo = &pool->bo, + .bo = pool->bo, .offset = set->desc_mem.offset, }, layout->descriptor_buffer_size, 1); @@ -854,11 +979,15 @@ anv_descriptor_set_create(struct anv_device *device, * UpdateDescriptorSets if needed. However, if the descriptor * set has an immutable sampler, UpdateDescriptorSets may never * touch it, so we need to make sure it's 100% valid now. + * + * We don't need to actually provide a sampler because the helper + * will always write in the immutable sampler regardless of what + * is in the sampler parameter. */ - desc[i] = (struct anv_descriptor) { - .type = VK_DESCRIPTOR_TYPE_SAMPLER, - .sampler = layout->binding[b].immutable_samplers[i], - }; + VkDescriptorImageInfo info = { }; + anv_descriptor_set_write_image_view(device, set, &info, + VK_DESCRIPTOR_TYPE_SAMPLER, + b, i); } } desc += layout->binding[b].array_size; @@ -870,6 +999,8 @@ anv_descriptor_set_create(struct anv_device *device, anv_descriptor_pool_alloc_state(pool); } + list_addtail(&set->pool_link, &pool->desc_sets); + *out_set = set; return VK_SUCCESS; @@ -892,6 +1023,8 @@ anv_descriptor_set_destroy(struct anv_device *device, for (uint32_t b = 0; b < set->buffer_view_count; b++) anv_descriptor_pool_free_state(pool, set->buffer_views[b].surface_state); + list_del(&set->pool_link); + anv_descriptor_pool_free_set(pool, set); } @@ -915,8 +1048,6 @@ VkResult anv_AllocateDescriptorSets( if (result != VK_SUCCESS) break; - list_addtail(&set->pool_link, &pool->desc_sets); - pDescriptorSets[i] = anv_descriptor_set_to_handle(set); } @@ -966,6 +1097,18 @@ anv_descriptor_set_write_image_param(uint32_t *param_desc_map, #undef WRITE_PARAM_FIELD } +static uint32_t +anv_surface_state_to_handle(struct anv_state state) +{ + /* Bits 31:12 of the bindless surface offset in the extended message + * descriptor is bits 25:6 of the byte-based address. + */ + assert(state.offset >= 0); + uint32_t offset = state.offset; + assert((offset & 0x3f) == 0 && offset < (1 << 26)); + return offset << 6; +} + void anv_descriptor_set_write_image_view(struct anv_device *device, struct anv_descriptor_set *set, @@ -981,7 +1124,11 @@ anv_descriptor_set_write_image_view(struct anv_device *device, struct anv_image_view *image_view = NULL; struct anv_sampler *sampler = NULL; - assert(type == bind_layout->type); + /* We get called with just VK_DESCRIPTOR_TYPE_SAMPLER as part of descriptor + * set initialization to set the bindless samplers. + */ + assert(type == bind_layout->type || + type == VK_DESCRIPTOR_TYPE_SAMPLER); switch (type) { case VK_DESCRIPTOR_TYPE_SAMPLER: @@ -1020,6 +1167,45 @@ anv_descriptor_set_write_image_view(struct anv_device *device, void *desc_map = set->desc_mem.map + bind_layout->descriptor_offset + element * anv_descriptor_size(bind_layout); + if (bind_layout->data & ANV_DESCRIPTOR_SAMPLED_IMAGE) { + struct anv_sampled_image_descriptor desc_data[3]; + memset(desc_data, 0, sizeof(desc_data)); + + if (image_view) { + for (unsigned p = 0; p < image_view->n_planes; p++) { + struct anv_surface_state sstate = + (desc->layout == VK_IMAGE_LAYOUT_GENERAL) ? + image_view->planes[p].general_sampler_surface_state : + image_view->planes[p].optimal_sampler_surface_state; + desc_data[p].image = anv_surface_state_to_handle(sstate.state); + } + } + + if (sampler) { + for (unsigned p = 0; p < sampler->n_planes; p++) + desc_data[p].sampler = sampler->bindless_state.offset + p * 32; + } + + /* We may have max_plane_count < 0 if this isn't a sampled image but it + * can be no more than the size of our array of handles. + */ + assert(bind_layout->max_plane_count <= ARRAY_SIZE(desc_data)); + memcpy(desc_map, desc_data, + MAX2(1, bind_layout->max_plane_count) * sizeof(desc_data[0])); + } + + if (bind_layout->data & ANV_DESCRIPTOR_STORAGE_IMAGE) { + assert(!(bind_layout->data & ANV_DESCRIPTOR_IMAGE_PARAM)); + assert(image_view->n_planes == 1); + struct anv_storage_image_descriptor desc_data = { + .read_write = anv_surface_state_to_handle( + image_view->planes[0].storage_surface_state.state), + .write_only = anv_surface_state_to_handle( + image_view->planes[0].writeonly_storage_surface_state.state), + }; + memcpy(desc_map, &desc_data, sizeof(desc_data)); + } + if (bind_layout->data & ANV_DESCRIPTOR_IMAGE_PARAM) { /* Storage images can only ever have one plane */ assert(image_view->n_planes == 1); @@ -1028,6 +1214,26 @@ anv_descriptor_set_write_image_view(struct anv_device *device, anv_descriptor_set_write_image_param(desc_map, image_param); } + + if (image_view && (bind_layout->data & ANV_DESCRIPTOR_TEXTURE_SWIZZLE)) { + assert(!(bind_layout->data & ANV_DESCRIPTOR_SAMPLED_IMAGE)); + assert(image_view); + struct anv_texture_swizzle_descriptor desc_data[3]; + memset(desc_data, 0, sizeof(desc_data)); + + for (unsigned p = 0; p < image_view->n_planes; p++) { + desc_data[p] = (struct anv_texture_swizzle_descriptor) { + .swizzle = { + (uint8_t)image_view->planes[p].isl.swizzle.r, + (uint8_t)image_view->planes[p].isl.swizzle.g, + (uint8_t)image_view->planes[p].isl.swizzle.b, + (uint8_t)image_view->planes[p].isl.swizzle.a, + }, + }; + } + memcpy(desc_map, desc_data, + MAX2(1, bind_layout->max_plane_count) * sizeof(desc_data[0])); + } } void @@ -1053,6 +1259,24 @@ anv_descriptor_set_write_buffer_view(struct anv_device *device, void *desc_map = set->desc_mem.map + bind_layout->descriptor_offset + element * anv_descriptor_size(bind_layout); + if (bind_layout->data & ANV_DESCRIPTOR_SAMPLED_IMAGE) { + struct anv_sampled_image_descriptor desc_data = { + .image = anv_surface_state_to_handle(buffer_view->surface_state), + }; + memcpy(desc_map, &desc_data, sizeof(desc_data)); + } + + if (bind_layout->data & ANV_DESCRIPTOR_STORAGE_IMAGE) { + assert(!(bind_layout->data & ANV_DESCRIPTOR_IMAGE_PARAM)); + struct anv_storage_image_descriptor desc_data = { + .read_write = anv_surface_state_to_handle( + buffer_view->storage_surface_state), + .write_only = anv_surface_state_to_handle( + buffer_view->writeonly_storage_surface_state), + }; + memcpy(desc_map, &desc_data, sizeof(desc_data)); + } + if (bind_layout->data & ANV_DESCRIPTOR_IMAGE_PARAM) { anv_descriptor_set_write_image_param(desc_map, &buffer_view->storage_image_param); @@ -1077,6 +1301,9 @@ anv_descriptor_set_write_buffer(struct anv_device *device, assert(type == bind_layout->type); + struct anv_address bind_addr = anv_address_add(buffer->address, offset); + uint64_t bind_range = anv_buffer_get_range(buffer, offset, range); + if (type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC || type == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) { *desc = (struct anv_descriptor) { @@ -1091,8 +1318,8 @@ anv_descriptor_set_write_buffer(struct anv_device *device, &set->buffer_views[bind_layout->buffer_view_index + element]; bview->format = anv_isl_format_for_descriptor_type(type); - bview->range = anv_buffer_get_range(buffer, offset, range); - bview->address = anv_address_add(buffer->address, offset); + bview->range = bind_range; + bview->address = bind_addr; /* If we're writing descriptors through a push command, we need to * allocate the surface state from the command buffer. Otherwise it will @@ -1102,14 +1329,24 @@ anv_descriptor_set_write_buffer(struct anv_device *device, bview->surface_state = anv_state_stream_alloc(alloc_stream, 64, 64); anv_fill_buffer_surface_state(device, bview->surface_state, - bview->format, - bview->address, bview->range, 1); + bview->format, bind_addr, bind_range, 1); *desc = (struct anv_descriptor) { .type = type, .buffer_view = bview, }; } + + void *desc_map = set->desc_mem.map + bind_layout->descriptor_offset + + element * anv_descriptor_size(bind_layout); + + if (bind_layout->data & ANV_DESCRIPTOR_ADDRESS_RANGE) { + struct anv_address_range_descriptor desc = { + .address = anv_address_physical(bind_addr), + .range = bind_range, + }; + memcpy(desc_map, &desc, sizeof(desc)); + } } void @@ -1227,9 +1464,6 @@ void anv_UpdateDescriptorSets( &dst->descriptors[dst_layout->descriptor_index]; dst_desc += copy->dstArrayElement; - for (uint32_t j = 0; j < copy->descriptorCount; j++) - dst_desc[j] = src_desc[j]; - if (src_layout->data & ANV_DESCRIPTOR_INLINE_UNIFORM) { assert(src_layout->data == ANV_DESCRIPTOR_INLINE_UNIFORM); memcpy(dst->desc_mem.map + dst_layout->descriptor_offset + @@ -1238,6 +1472,9 @@ void anv_UpdateDescriptorSets( copy->srcArrayElement, copy->descriptorCount); } else { + for (uint32_t j = 0; j < copy->descriptorCount; j++) + dst_desc[j] = src_desc[j]; + unsigned desc_size = anv_descriptor_size(src_layout); if (desc_size > 0) { assert(desc_size == anv_descriptor_size(dst_layout));