zink: directly set nir variable bindings for reuse during ntv

this lets us prepopulate the binding values without "fetching" them
twice

Reviewed-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9624>
This commit is contained in:
Mike Blumenkrantz 2020-12-31 12:56:04 -05:00 committed by Marge Bot
parent 84293f5395
commit dbbcf4e780
2 changed files with 25 additions and 30 deletions

View file

@ -819,7 +819,7 @@ emit_image(struct ntv_context *ctx, struct nir_variable *var)
image_type);
SpvId var_type = is_sampler ? sampled_type : image_type;
int index = var->data.binding;
int index = var->data.driver_location;
assert(!is_sampler || (!(ctx->samplers_used & (1 << index))));
assert(!is_sampler || !ctx->sampler_types[index]);
assert(is_sampler || !ctx->image_types[index]);
@ -857,10 +857,7 @@ emit_image(struct ntv_context *ctx, struct nir_variable *var)
ctx->entry_ifaces[ctx->num_entry_ifaces++] = var_id;
spirv_builder_emit_descriptor_set(&ctx->builder, var_id, is_sampler ? ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW : ZINK_DESCRIPTOR_TYPE_IMAGE);
int binding = zink_binding(ctx->stage,
is_sampler ? zink_sampler_type(type) : zink_image_type(type),
var->data.binding);
spirv_builder_emit_binding(&ctx->builder, var_id, binding);
spirv_builder_emit_binding(&ctx->builder, var_id, var->data.binding);
}
static SpvId
@ -1001,12 +998,7 @@ emit_bo(struct ntv_context *ctx, struct nir_variable *var)
ctx->entry_ifaces[ctx->num_entry_ifaces++] = var_id;
spirv_builder_emit_descriptor_set(&ctx->builder, var_id, ssbo ? ZINK_DESCRIPTOR_TYPE_SSBO : ZINK_DESCRIPTOR_TYPE_UBO);
int binding = zink_binding(ctx->stage,
ssbo ? VK_DESCRIPTOR_TYPE_STORAGE_BUFFER :
/* only make the first ubo dynamic to stay within driver limits */
(ctx->num_ubos == 1) ? VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC : VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
var->data.binding + i);
spirv_builder_emit_binding(&ctx->builder, var_id, binding);
spirv_builder_emit_binding(&ctx->builder, var_id, var->data.binding + i);
}
}
@ -2829,7 +2821,7 @@ emit_intrinsic(struct ntv_context *ctx, nir_intrinsic_instr *intr)
case nir_intrinsic_image_deref_store: {
SpvId img_var = get_src(ctx, &intr->src[0]);
nir_variable *var = get_var_from_image(ctx, img_var);
SpvId img_type = ctx->image_types[var->data.binding];
SpvId img_type = ctx->image_types[var->data.driver_location];
const struct glsl_type *type = glsl_without_array(var->type);
SpvId base_type = get_glsl_basetype(ctx, glsl_get_sampler_result_type(type));
SpvId img = spirv_builder_emit_load(&ctx->builder, img_type, img_var);
@ -2846,7 +2838,7 @@ emit_intrinsic(struct ntv_context *ctx, nir_intrinsic_instr *intr)
case nir_intrinsic_image_deref_load: {
SpvId img_var = get_src(ctx, &intr->src[0]);
nir_variable *var = get_var_from_image(ctx, img_var);
SpvId img_type = ctx->image_types[var->data.binding];
SpvId img_type = ctx->image_types[var->data.driver_location];
const struct glsl_type *type = glsl_without_array(var->type);
SpvId base_type = get_glsl_basetype(ctx, glsl_get_sampler_result_type(type));
SpvId img = spirv_builder_emit_load(&ctx->builder, img_type, img_var);
@ -2860,7 +2852,7 @@ emit_intrinsic(struct ntv_context *ctx, nir_intrinsic_instr *intr)
case nir_intrinsic_image_deref_size: {
SpvId img_var = get_src(ctx, &intr->src[0]);
nir_variable *var = get_var_from_image(ctx, img_var);
SpvId img_type = ctx->image_types[var->data.binding];
SpvId img_type = ctx->image_types[var->data.driver_location];
const struct glsl_type *type = glsl_without_array(var->type);
SpvId img = spirv_builder_emit_load(&ctx->builder, img_type, img_var);
SpvId result = spirv_builder_emit_image_query_size(&ctx->builder, get_uvec_type(ctx, 32, glsl_get_sampler_coordinate_components(type)), img, 0);
@ -3280,7 +3272,7 @@ emit_deref_array(struct ntv_context *ctx, nir_deref_instr *deref)
struct hash_entry *he = _mesa_hash_table_search(ctx->vars, var);
assert(he);
base = (SpvId)(intptr_t)he->data;
type = ctx->image_types[var->data.binding];
type = ctx->image_types[var->data.driver_location];
break;
}

View file

@ -609,7 +609,6 @@ zink_shader_create(struct zink_screen *screen, struct nir_shader *nir,
fprintf(stderr, "---8<---\n");
}
uint32_t cur_ubo = 0;
/* UBO buffers are zero-indexed, but buffer 0 is always the one created by nir_lower_uniforms_to_ubo,
* which means there is no buffer 0 if there are no uniforms
*/
@ -629,8 +628,11 @@ zink_shader_create(struct zink_screen *screen, struct nir_shader *nir,
bool ubo_array = glsl_type_is_array(var->type) && glsl_type_is_interface(type);
if (var->data.location && !ubo_array && var->type != var->interface_type)
continue;
var->data.binding = cur_ubo;
ztype = ZINK_DESCRIPTOR_TYPE_UBO;
var->data.driver_location = ret->num_bindings[ztype];
var->data.binding = zink_binding(nir->info.stage,
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
var->data.driver_location);
/* if this is a ubo array, create a binding point for each array member:
*
"For uniform blocks declared as arrays, each individual array element
@ -641,9 +643,7 @@ zink_shader_create(struct zink_screen *screen, struct nir_shader *nir,
*/
for (unsigned i = 0; i < (ubo_array ? glsl_get_aoa_size(var->type) : 1); i++) {
VkDescriptorType vktype = !ubo_index ? VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC : VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
int binding = zink_binding(nir->info.stage,
vktype,
cur_ubo++);
int binding = var->data.binding + i;
ret->bindings[ztype][ret->num_bindings[ztype]].index = ubo_index++;
ret->bindings[ztype][ret->num_bindings[ztype]].binding = binding;
ret->bindings[ztype][ret->num_bindings[ztype]].type = vktype;
@ -657,13 +657,15 @@ zink_shader_create(struct zink_screen *screen, struct nir_shader *nir,
if (var->data.location && !bo_array)
continue;
if (!var->data.explicit_binding) {
var->data.binding = ssbo_array_index;
}
var->data.driver_location = ssbo_array_index;
} else
var->data.driver_location = var->data.binding;
ztype = ZINK_DESCRIPTOR_TYPE_SSBO;
var->data.binding = zink_binding(nir->info.stage,
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
var->data.driver_location);
for (unsigned i = 0; i < (bo_array ? glsl_get_aoa_size(var->type) : 1); i++) {
int binding = zink_binding(nir->info.stage,
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
var->data.binding + i);
int binding = var->data.binding + i;
if (strcmp(glsl_get_type_name(var->interface_type), "counters"))
ret->bindings[ztype][ret->num_bindings[ztype]].index = ssbo_array_index++;
else
@ -679,11 +681,12 @@ zink_shader_create(struct zink_screen *screen, struct nir_shader *nir,
if (glsl_type_is_sampler(type) || glsl_type_is_image(type)) {
VkDescriptorType vktype = glsl_type_is_image(type) ? zink_image_type(type) : zink_sampler_type(type);
ztype = zink_desc_type_from_vktype(vktype);
int binding = zink_binding(nir->info.stage,
vktype,
var->data.binding);
ret->bindings[ztype][ret->num_bindings[ztype]].index = var->data.binding;
ret->bindings[ztype][ret->num_bindings[ztype]].binding = binding;
var->data.driver_location = var->data.binding;
var->data.binding = zink_binding(nir->info.stage,
vktype,
var->data.driver_location);
ret->bindings[ztype][ret->num_bindings[ztype]].index = var->data.driver_location;
ret->bindings[ztype][ret->num_bindings[ztype]].binding = var->data.binding;
ret->bindings[ztype][ret->num_bindings[ztype]].type = vktype;
if (glsl_type_is_array(var->type))
ret->bindings[ztype][ret->num_bindings[ztype]].size = glsl_get_aoa_size(var->type);