zink: move some descriptor data into a substruct

no functional changes

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20489>
This commit is contained in:
Mike Blumenkrantz
2022-10-24 16:40:32 -04:00
parent 885e5a3571
commit 20e1474c2c
3 changed files with 36 additions and 27 deletions

View File

@@ -562,15 +562,15 @@ update_descriptor_state_ubo(struct zink_context *ctx, gl_shader_stage shader, un
bool have_null_descriptors = screen->info.rb2_feats.nullDescriptor;
const enum zink_descriptor_type type = ZINK_DESCRIPTOR_TYPE_UBO;
ctx->di.descriptor_res[type][shader][slot] = res;
ctx->di.ubos[shader][slot].offset = ctx->ubos[shader][slot].buffer_offset;
ctx->di.t.ubos[shader][slot].offset = ctx->ubos[shader][slot].buffer_offset;
if (res) {
ctx->di.ubos[shader][slot].buffer = res->obj->buffer;
ctx->di.ubos[shader][slot].range = ctx->ubos[shader][slot].buffer_size;
assert(ctx->di.ubos[shader][slot].range <= screen->info.props.limits.maxUniformBufferRange);
ctx->di.t.ubos[shader][slot].buffer = res->obj->buffer;
ctx->di.t.ubos[shader][slot].range = ctx->ubos[shader][slot].buffer_size;
assert(ctx->di.t.ubos[shader][slot].range <= screen->info.props.limits.maxUniformBufferRange);
} else {
VkBuffer null_buffer = zink_resource(ctx->dummy_vertex_buffer)->obj->buffer;
ctx->di.ubos[shader][slot].buffer = have_null_descriptors ? VK_NULL_HANDLE : null_buffer;
ctx->di.ubos[shader][slot].range = VK_WHOLE_SIZE;
ctx->di.t.ubos[shader][slot].buffer = have_null_descriptors ? VK_NULL_HANDLE : null_buffer;
ctx->di.t.ubos[shader][slot].range = VK_WHOLE_SIZE;
}
if (!slot) {
if (res)
@@ -588,14 +588,14 @@ update_descriptor_state_ssbo(struct zink_context *ctx, gl_shader_stage shader, u
bool have_null_descriptors = screen->info.rb2_feats.nullDescriptor;
const enum zink_descriptor_type type = ZINK_DESCRIPTOR_TYPE_SSBO;
ctx->di.descriptor_res[type][shader][slot] = res;
ctx->di.ssbos[shader][slot].offset = ctx->ssbos[shader][slot].buffer_offset;
ctx->di.t.ssbos[shader][slot].offset = ctx->ssbos[shader][slot].buffer_offset;
if (res) {
ctx->di.ssbos[shader][slot].buffer = res->obj->buffer;
ctx->di.ssbos[shader][slot].range = ctx->ssbos[shader][slot].buffer_size;
ctx->di.t.ssbos[shader][slot].buffer = res->obj->buffer;
ctx->di.t.ssbos[shader][slot].range = ctx->ssbos[shader][slot].buffer_size;
} else {
VkBuffer null_buffer = zink_resource(ctx->dummy_vertex_buffer)->obj->buffer;
ctx->di.ssbos[shader][slot].buffer = have_null_descriptors ? VK_NULL_HANDLE : null_buffer;
ctx->di.ssbos[shader][slot].range = VK_WHOLE_SIZE;
ctx->di.t.ssbos[shader][slot].buffer = have_null_descriptors ? VK_NULL_HANDLE : null_buffer;
ctx->di.t.ssbos[shader][slot].range = VK_WHOLE_SIZE;
}
return res;
}
@@ -610,7 +610,7 @@ update_descriptor_state_sampler(struct zink_context *ctx, gl_shader_stage shader
if (res) {
if (res->obj->is_buffer) {
struct zink_buffer_view *bv = get_bufferview_for_binding(ctx, shader, type, slot);
ctx->di.tbos[shader][slot] = bv->buffer_view;
ctx->di.t.tbos[shader][slot] = bv->buffer_view;
} else {
struct zink_surface *surface = get_imageview_for_binding(ctx, shader, type, slot);
ctx->di.textures[shader][slot].imageLayout = get_layout_for_binding(ctx, res, type, shader == MESA_SHADER_COMPUTE);
@@ -632,13 +632,13 @@ update_descriptor_state_sampler(struct zink_context *ctx, gl_shader_stage shader
if (likely(have_null_descriptors)) {
ctx->di.textures[shader][slot].imageView = VK_NULL_HANDLE;
ctx->di.textures[shader][slot].imageLayout = VK_IMAGE_LAYOUT_UNDEFINED;
ctx->di.tbos[shader][slot] = VK_NULL_HANDLE;
ctx->di.t.tbos[shader][slot] = VK_NULL_HANDLE;
} else {
struct zink_surface *null_surface = zink_get_dummy_surface(ctx, 0);
struct zink_buffer_view *null_bufferview = ctx->dummy_bufferview;
ctx->di.textures[shader][slot].imageView = null_surface->image_view;
ctx->di.textures[shader][slot].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
ctx->di.tbos[shader][slot] = null_bufferview->buffer_view;
ctx->di.t.tbos[shader][slot] = null_bufferview->buffer_view;
}
}
return res;
@@ -654,7 +654,7 @@ update_descriptor_state_image(struct zink_context *ctx, gl_shader_stage shader,
if (res) {
if (res->obj->is_buffer) {
struct zink_buffer_view *bv = get_bufferview_for_binding(ctx, shader, type, slot);
ctx->di.texel_images[shader][slot] = bv->buffer_view;
ctx->di.t.texel_images[shader][slot] = bv->buffer_view;
} else {
struct zink_surface *surface = get_imageview_for_binding(ctx, shader, type, slot);
ctx->di.images[shader][slot].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
@@ -663,13 +663,13 @@ update_descriptor_state_image(struct zink_context *ctx, gl_shader_stage shader,
} else {
if (likely(have_null_descriptors)) {
memset(&ctx->di.images[shader][slot], 0, sizeof(ctx->di.images[shader][slot]));
ctx->di.texel_images[shader][slot] = VK_NULL_HANDLE;
ctx->di.t.texel_images[shader][slot] = VK_NULL_HANDLE;
} else {
struct zink_surface *null_surface = zink_get_dummy_surface(ctx, 0);
struct zink_buffer_view *null_bufferview = ctx->dummy_bufferview;
ctx->di.images[shader][slot].imageView = null_surface->image_view;
ctx->di.images[shader][slot].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
ctx->di.texel_images[shader][slot] = null_bufferview->buffer_view;
ctx->di.t.texel_images[shader][slot] = null_bufferview->buffer_view;
}
}
return res;
@@ -4913,10 +4913,16 @@ zink_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
if (!is_copy_only) {
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
/* need to update these based on screen config for null descriptors */
for (unsigned j = 0; j < 32; j++) {
for (unsigned j = 0; j < ARRAY_SIZE(ctx->di.t.ubos[i]); j++) {
update_descriptor_state_ubo(ctx, i, j, NULL);
}
for (unsigned j = 0; j < ARRAY_SIZE(ctx->di.textures[i]); j++) {
update_descriptor_state_sampler(ctx, i, j, NULL);
}
for (unsigned j = 0; j < ARRAY_SIZE(ctx->di.t.ssbos[i]); j++) {
update_descriptor_state_ssbo(ctx, i, j, NULL);
}
for (unsigned j = 0; j < ARRAY_SIZE(ctx->di.images[i]); j++) {
update_descriptor_state_image(ctx, i, j, NULL);
}
}

View File

@@ -321,7 +321,7 @@ init_template_entry(struct zink_shader *shader, enum zink_descriptor_type type,
switch (shader->bindings[type][idx].type) {
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
entry->offset = offsetof(struct zink_context, di.ubos[stage][index]);
entry->offset = offsetof(struct zink_context, di.t.ubos[stage][index]);
entry->stride = sizeof(VkDescriptorBufferInfo);
break;
case VK_DESCRIPTOR_TYPE_SAMPLER:
@@ -331,11 +331,11 @@ init_template_entry(struct zink_shader *shader, enum zink_descriptor_type type,
entry->stride = sizeof(VkDescriptorImageInfo);
break;
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
entry->offset = offsetof(struct zink_context, di.tbos[stage][index]);
entry->offset = offsetof(struct zink_context, di.t.tbos[stage][index]);
entry->stride = sizeof(VkBufferView);
break;
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
entry->offset = offsetof(struct zink_context, di.ssbos[stage][index]);
entry->offset = offsetof(struct zink_context, di.t.ssbos[stage][index]);
entry->stride = sizeof(VkDescriptorBufferInfo);
break;
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
@@ -343,7 +343,7 @@ init_template_entry(struct zink_shader *shader, enum zink_descriptor_type type,
entry->stride = sizeof(VkDescriptorImageInfo);
break;
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
entry->offset = offsetof(struct zink_context, di.texel_images[stage][index]);
entry->offset = offsetof(struct zink_context, di.t.texel_images[stage][index]);
entry->stride = sizeof(VkBufferView);
break;
default:
@@ -1108,7 +1108,7 @@ init_push_template_entry(VkDescriptorUpdateTemplateEntry *entry, unsigned i)
entry->dstBinding = i;
entry->descriptorCount = 1;
entry->descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
entry->offset = offsetof(struct zink_context, di.ubos[i][0]);
entry->offset = offsetof(struct zink_context, di.t.ubos[i][0]);
entry->stride = sizeof(VkDescriptorBufferInfo);
}

View File

@@ -1632,24 +1632,27 @@ struct zink_context {
struct {
/* descriptor info */
VkDescriptorBufferInfo ubos[MESA_SHADER_STAGES][PIPE_MAX_CONSTANT_BUFFERS];
uint32_t push_valid;
uint8_t num_ubos[MESA_SHADER_STAGES];
VkDescriptorBufferInfo ssbos[MESA_SHADER_STAGES][PIPE_MAX_SHADER_BUFFERS];
uint8_t num_ssbos[MESA_SHADER_STAGES];
VkDescriptorImageInfo textures[MESA_SHADER_STAGES][PIPE_MAX_SAMPLERS];
VkBufferView tbos[MESA_SHADER_STAGES][PIPE_MAX_SAMPLERS];
uint32_t emulate_nonseamless[MESA_SHADER_STAGES];
uint32_t cubes[MESA_SHADER_STAGES];
uint8_t num_samplers[MESA_SHADER_STAGES];
uint8_t num_sampler_views[MESA_SHADER_STAGES];
VkDescriptorImageInfo images[MESA_SHADER_STAGES][ZINK_MAX_SHADER_IMAGES];
VkBufferView texel_images[MESA_SHADER_STAGES][ZINK_MAX_SHADER_IMAGES];
uint8_t num_images[MESA_SHADER_STAGES];
struct {
VkDescriptorBufferInfo ubos[MESA_SHADER_STAGES][PIPE_MAX_CONSTANT_BUFFERS];
VkDescriptorBufferInfo ssbos[MESA_SHADER_STAGES][PIPE_MAX_SHADER_BUFFERS];
VkBufferView tbos[MESA_SHADER_STAGES][PIPE_MAX_SAMPLERS];
VkBufferView texel_images[MESA_SHADER_STAGES][ZINK_MAX_SHADER_IMAGES];
} t;
VkDescriptorImageInfo fbfetch;
struct zink_resource *descriptor_res[ZINK_DESCRIPTOR_BASE_TYPES][MESA_SHADER_STAGES][PIPE_MAX_SAMPLERS];