瀏覽代碼

anv: Stop allocating buffer views for dynamic buffers

We emit the surface states for those on-the-fly so we don't need the
buffer view.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
tags/19.1-branchpoint
Jason Ekstrand 6 年之前
父節點
當前提交
3822c7495a
共有 3 個檔案被更改,包括 22 行新增24 行删除
  1. 2
    2
      src/intel/vulkan/anv_cmd_buffer.c
  2. 16
    18
      src/intel/vulkan/anv_descriptor_set.c
  3. 4
    4
      src/intel/vulkan/anv_private.h

+ 2
- 2
src/intel/vulkan/anv_cmd_buffer.c 查看文件



set->layout = set_layout; set->layout = set_layout;
set->size = anv_descriptor_set_layout_size(set_layout); set->size = anv_descriptor_set_layout_size(set_layout);
set->buffer_count = set_layout->buffer_count;
set->buffer_view_count = set_layout->buffer_view_count;
set->buffer_views = push_set->buffer_views; set->buffer_views = push_set->buffer_views;


/* Go through the user supplied descriptors. */ /* Go through the user supplied descriptors. */


set->layout = set_layout; set->layout = set_layout;
set->size = anv_descriptor_set_layout_size(set_layout); set->size = anv_descriptor_set_layout_size(set_layout);
set->buffer_count = set_layout->buffer_count;
set->buffer_view_count = set_layout->buffer_view_count;
set->buffer_views = push_set->buffer_views; set->buffer_views = push_set->buffer_views;


anv_descriptor_set_write_template(cmd_buffer->device, set, anv_descriptor_set_write_template(cmd_buffer->device, set,

+ 16
- 18
src/intel/vulkan/anv_descriptor_set.c 查看文件

uint32_t sampler_count[MESA_SHADER_STAGES] = { 0, }; uint32_t sampler_count[MESA_SHADER_STAGES] = { 0, };
uint32_t surface_count[MESA_SHADER_STAGES] = { 0, }; uint32_t surface_count[MESA_SHADER_STAGES] = { 0, };
uint32_t image_count[MESA_SHADER_STAGES] = { 0, }; uint32_t image_count[MESA_SHADER_STAGES] = { 0, };
uint32_t buffer_count = 0;
uint32_t buffer_view_count = 0;
uint32_t dynamic_offset_count = 0; uint32_t dynamic_offset_count = 0;


for (uint32_t j = 0; j < pCreateInfo->bindingCount; j++) { for (uint32_t j = 0; j < pCreateInfo->bindingCount; j++) {
switch (binding->descriptorType) { switch (binding->descriptorType) {
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
set_layout->binding[b].buffer_index = buffer_count;
buffer_count += binding->descriptorCount;
set_layout->binding[b].buffer_view_index = buffer_view_count;
buffer_view_count += binding->descriptorCount;
/* fall through */ /* fall through */


case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
anv_foreach_stage(s, binding->stageFlags) { anv_foreach_stage(s, binding->stageFlags) {
set_layout->binding[b].stage[s].surface_index = surface_count[s]; set_layout->binding[b].stage[s].surface_index = surface_count[s];
set_layout->shader_stages |= binding->stageFlags; set_layout->shader_stages |= binding->stageFlags;
} }


set_layout->buffer_count = buffer_count;
set_layout->buffer_view_count = buffer_view_count;
set_layout->dynamic_offset_count = dynamic_offset_count; set_layout->dynamic_offset_count = dynamic_offset_count;


*pSetLayout = anv_descriptor_set_layout_to_handle(set_layout); *pSetLayout = anv_descriptor_set_layout_to_handle(set_layout);
SHA1_UPDATE_VALUE(ctx, layout->array_size); SHA1_UPDATE_VALUE(ctx, layout->array_size);
SHA1_UPDATE_VALUE(ctx, layout->descriptor_index); SHA1_UPDATE_VALUE(ctx, layout->descriptor_index);
SHA1_UPDATE_VALUE(ctx, layout->dynamic_offset_index); SHA1_UPDATE_VALUE(ctx, layout->dynamic_offset_index);
SHA1_UPDATE_VALUE(ctx, layout->buffer_index);
SHA1_UPDATE_VALUE(ctx, layout->buffer_view_index);
_mesa_sha1_update(ctx, layout->stage, sizeof(layout->stage)); _mesa_sha1_update(ctx, layout->stage, sizeof(layout->stage));


if (layout->immutable_samplers) { if (layout->immutable_samplers) {
SHA1_UPDATE_VALUE(ctx, layout->binding_count); SHA1_UPDATE_VALUE(ctx, layout->binding_count);
SHA1_UPDATE_VALUE(ctx, layout->size); SHA1_UPDATE_VALUE(ctx, layout->size);
SHA1_UPDATE_VALUE(ctx, layout->shader_stages); SHA1_UPDATE_VALUE(ctx, layout->shader_stages);
SHA1_UPDATE_VALUE(ctx, layout->buffer_count);
SHA1_UPDATE_VALUE(ctx, layout->buffer_view_count);
SHA1_UPDATE_VALUE(ctx, layout->dynamic_offset_count); SHA1_UPDATE_VALUE(ctx, layout->dynamic_offset_count);


for (uint16_t i = 0; i < layout->binding_count; i++) for (uint16_t i = 0; i < layout->binding_count; i++)
struct anv_descriptor_pool *pool; struct anv_descriptor_pool *pool;


uint32_t descriptor_count = 0; uint32_t descriptor_count = 0;
uint32_t buffer_count = 0;
uint32_t buffer_view_count = 0;
for (uint32_t i = 0; i < pCreateInfo->poolSizeCount; i++) { for (uint32_t i = 0; i < pCreateInfo->poolSizeCount; i++) {
switch (pCreateInfo->pPoolSizes[i].type) { switch (pCreateInfo->pPoolSizes[i].type) {
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
buffer_count += pCreateInfo->pPoolSizes[i].descriptorCount;
buffer_view_count += pCreateInfo->pPoolSizes[i].descriptorCount;
default: default:
descriptor_count += pCreateInfo->pPoolSizes[i].descriptorCount; descriptor_count += pCreateInfo->pPoolSizes[i].descriptorCount;
break; break;
const size_t pool_size = const size_t pool_size =
pCreateInfo->maxSets * sizeof(struct anv_descriptor_set) + pCreateInfo->maxSets * sizeof(struct anv_descriptor_set) +
descriptor_count * sizeof(struct anv_descriptor) + descriptor_count * sizeof(struct anv_descriptor) +
buffer_count * sizeof(struct anv_buffer_view);
buffer_view_count * sizeof(struct anv_buffer_view);
const size_t total_size = sizeof(*pool) + pool_size; const size_t total_size = sizeof(*pool) + pool_size;


pool = vk_alloc2(&device->alloc, pAllocator, total_size, 8, pool = vk_alloc2(&device->alloc, pAllocator, total_size, 8,
return return
sizeof(struct anv_descriptor_set) + sizeof(struct anv_descriptor_set) +
layout->size * sizeof(struct anv_descriptor) + layout->size * sizeof(struct anv_descriptor) +
layout->buffer_count * sizeof(struct anv_buffer_view);
layout->buffer_view_count * sizeof(struct anv_buffer_view);
} }


VkResult VkResult
set->size = size; set->size = size;
set->buffer_views = set->buffer_views =
(struct anv_buffer_view *) &set->descriptors[layout->size]; (struct anv_buffer_view *) &set->descriptors[layout->size];
set->buffer_count = layout->buffer_count;
set->buffer_view_count = layout->buffer_view_count;


/* By defining the descriptors to be zero now, we can later verify that /* By defining the descriptors to be zero now, we can later verify that
* a descriptor has not been populated with user data. * a descriptor has not been populated with user data.
} }


/* Allocate surface state for the buffer views. */ /* Allocate surface state for the buffer views. */
for (uint32_t b = 0; b < layout->buffer_count; b++) {
for (uint32_t b = 0; b < layout->buffer_view_count; b++) {
set->buffer_views[b].surface_state = set->buffer_views[b].surface_state =
anv_descriptor_pool_alloc_state(pool); anv_descriptor_pool_alloc_state(pool);
} }
{ {
anv_descriptor_set_layout_unref(device, set->layout); anv_descriptor_set_layout_unref(device, set->layout);


for (uint32_t b = 0; b < set->buffer_count; b++)
for (uint32_t b = 0; b < set->buffer_view_count; b++)
anv_descriptor_pool_free_state(pool, set->buffer_views[b].surface_state); anv_descriptor_pool_free_state(pool, set->buffer_views[b].surface_state);


anv_descriptor_pool_free_set(pool, set); anv_descriptor_pool_free_set(pool, set);
}; };
} else { } else {
struct anv_buffer_view *bview = struct anv_buffer_view *bview =
&set->buffer_views[bind_layout->buffer_index + element];
&set->buffer_views[bind_layout->buffer_view_index + element];


bview->format = anv_isl_format_for_descriptor_type(type); bview->format = anv_isl_format_for_descriptor_type(type);
bview->range = anv_buffer_get_range(buffer, offset, range); bview->range = anv_buffer_get_range(buffer, offset, range);

+ 4
- 4
src/intel/vulkan/anv_private.h 查看文件

int16_t dynamic_offset_index; int16_t dynamic_offset_index;


/* Index into the descriptor set buffer views */ /* Index into the descriptor set buffer views */
int16_t buffer_index;
int16_t buffer_view_index;


struct { struct {
/* Index into the binding table for the associated surface */ /* Index into the binding table for the associated surface */
/* Shader stages affected by this descriptor set */ /* Shader stages affected by this descriptor set */
uint16_t shader_stages; uint16_t shader_stages;


/* Number of buffers in this descriptor set */
uint16_t buffer_count;
/* Number of buffer views in this descriptor set */
uint16_t buffer_view_count;


/* Number of dynamic offsets used by this descriptor set */ /* Number of dynamic offsets used by this descriptor set */
uint16_t dynamic_offset_count; uint16_t dynamic_offset_count;
struct anv_descriptor_set { struct anv_descriptor_set {
struct anv_descriptor_set_layout *layout; struct anv_descriptor_set_layout *layout;
uint32_t size; uint32_t size;
uint32_t buffer_count;
uint32_t buffer_view_count;
struct anv_buffer_view *buffer_views; struct anv_buffer_view *buffer_views;
struct anv_descriptor descriptors[0]; struct anv_descriptor descriptors[0];
}; };

Loading…
取消
儲存