spirv: Get rid of vtn_variable_mode_image/sampler
vtn_variable_mode_image and _sampler are instead replaced with vtn_variable_mode_uniform which encompasses both of them. In the few places where it was neccessary to distinguish between the two, the GLSL type of the pointer is used instead. The main reason to do this is that on OpenGL it is permitted to put images and samplers into structs and declare a uniform with them. That means that variables can now have a mix of uniform, sampler and image modes so picking a single one of those modes for a variable no longer makes sense. This fixes OpLoad on a sampler within a struct which was previously using the variable mode to determine whether it was a sampler or not. The type of the variable is a struct so it was not being considered to be uniform mode even though the member being loaded should be sampler mode. The previous code appeared to be using var->interface_type as a place to store the type of the variable without the enclosing array for images and samplers. I guess this worked because opaque types can not appear in interfaces so the interface_type is sort of unused. This patch removes the overloading of var->interface_type and any places that needed the type without the array can now just deduce it from var->type. v2: squash in this patch the changes to anv/nir (Timothy) Signed-off-by: Eduardo Lima <elima@igalia.com> Signed-off-by: Neil Roberts <nroberts@igalia.com Signed-off-by: Alejandro Piñeiro <apinheiro@igalia.com> Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
This commit is contained in:

committed by
Alejandro Piñeiro

parent
23edc5b1ef
commit
386f09be9b
@@ -3742,10 +3742,10 @@ vtn_handle_body_instruction(struct vtn_builder *b, SpvOp opcode,
|
|||||||
case SpvOpImageQuerySize: {
|
case SpvOpImageQuerySize: {
|
||||||
struct vtn_pointer *image =
|
struct vtn_pointer *image =
|
||||||
vtn_value(b, w[3], vtn_value_type_pointer)->pointer;
|
vtn_value(b, w[3], vtn_value_type_pointer)->pointer;
|
||||||
if (image->mode == vtn_variable_mode_image) {
|
if (glsl_type_is_image(image->type->type)) {
|
||||||
vtn_handle_image(b, opcode, w, count);
|
vtn_handle_image(b, opcode, w, count);
|
||||||
} else {
|
} else {
|
||||||
vtn_assert(image->mode == vtn_variable_mode_sampler);
|
vtn_assert(glsl_type_is_sampler(image->type->type));
|
||||||
vtn_handle_texture(b, opcode, w, count);
|
vtn_handle_texture(b, opcode, w, count);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@@ -124,10 +124,10 @@ vtn_cfg_handle_prepass_instruction(struct vtn_builder *b, SpvOp opcode,
|
|||||||
without_array = without_array->array_element;
|
without_array = without_array->array_element;
|
||||||
|
|
||||||
if (glsl_type_is_image(without_array->type)) {
|
if (glsl_type_is_image(without_array->type)) {
|
||||||
vtn_var->mode = vtn_variable_mode_image;
|
vtn_var->mode = vtn_variable_mode_uniform;
|
||||||
param->interface_type = without_array->type;
|
param->interface_type = without_array->type;
|
||||||
} else if (glsl_type_is_sampler(without_array->type)) {
|
} else if (glsl_type_is_sampler(without_array->type)) {
|
||||||
vtn_var->mode = vtn_variable_mode_sampler;
|
vtn_var->mode = vtn_variable_mode_uniform;
|
||||||
param->interface_type = without_array->type;
|
param->interface_type = without_array->type;
|
||||||
} else {
|
} else {
|
||||||
vtn_var->mode = vtn_variable_mode_param;
|
vtn_var->mode = vtn_variable_mode_param;
|
||||||
|
@@ -410,8 +410,6 @@ enum vtn_variable_mode {
|
|||||||
vtn_variable_mode_ubo,
|
vtn_variable_mode_ubo,
|
||||||
vtn_variable_mode_ssbo,
|
vtn_variable_mode_ssbo,
|
||||||
vtn_variable_mode_push_constant,
|
vtn_variable_mode_push_constant,
|
||||||
vtn_variable_mode_image,
|
|
||||||
vtn_variable_mode_sampler,
|
|
||||||
vtn_variable_mode_workgroup,
|
vtn_variable_mode_workgroup,
|
||||||
vtn_variable_mode_input,
|
vtn_variable_mode_input,
|
||||||
vtn_variable_mode_output,
|
vtn_variable_mode_output,
|
||||||
|
@@ -1548,9 +1548,7 @@ var_decoration_cb(struct vtn_builder *b, struct vtn_value *val, int member,
|
|||||||
vtn_var->mode == vtn_variable_mode_output) {
|
vtn_var->mode == vtn_variable_mode_output) {
|
||||||
is_vertex_input = false;
|
is_vertex_input = false;
|
||||||
location += vtn_var->patch ? VARYING_SLOT_PATCH0 : VARYING_SLOT_VAR0;
|
location += vtn_var->patch ? VARYING_SLOT_PATCH0 : VARYING_SLOT_VAR0;
|
||||||
} else if (vtn_var->mode != vtn_variable_mode_uniform &&
|
} else if (vtn_var->mode != vtn_variable_mode_uniform) {
|
||||||
vtn_var->mode != vtn_variable_mode_sampler &&
|
|
||||||
vtn_var->mode != vtn_variable_mode_image) {
|
|
||||||
vtn_warn("Location must be on input, output, uniform, sampler or "
|
vtn_warn("Location must be on input, output, uniform, sampler or "
|
||||||
"image variable");
|
"image variable");
|
||||||
return;
|
return;
|
||||||
@@ -1628,12 +1626,7 @@ vtn_storage_class_to_mode(struct vtn_builder *b,
|
|||||||
nir_mode = 0;
|
nir_mode = 0;
|
||||||
break;
|
break;
|
||||||
case SpvStorageClassUniformConstant:
|
case SpvStorageClassUniformConstant:
|
||||||
if (glsl_type_is_image(interface_type->type))
|
mode = vtn_variable_mode_uniform;
|
||||||
mode = vtn_variable_mode_image;
|
|
||||||
else if (glsl_type_is_sampler(interface_type->type))
|
|
||||||
mode = vtn_variable_mode_sampler;
|
|
||||||
else
|
|
||||||
mode = vtn_variable_mode_uniform;
|
|
||||||
nir_mode = nir_var_uniform;
|
nir_mode = nir_var_uniform;
|
||||||
break;
|
break;
|
||||||
case SpvStorageClassPushConstant:
|
case SpvStorageClassPushConstant:
|
||||||
@@ -1776,11 +1769,11 @@ vtn_create_variable(struct vtn_builder *b, struct vtn_value *val,
|
|||||||
case vtn_variable_mode_ssbo:
|
case vtn_variable_mode_ssbo:
|
||||||
b->shader->info.num_ssbos++;
|
b->shader->info.num_ssbos++;
|
||||||
break;
|
break;
|
||||||
case vtn_variable_mode_image:
|
case vtn_variable_mode_uniform:
|
||||||
b->shader->info.num_images++;
|
if (glsl_type_is_image(without_array->type))
|
||||||
break;
|
b->shader->info.num_images++;
|
||||||
case vtn_variable_mode_sampler:
|
else if (glsl_type_is_sampler(without_array->type))
|
||||||
b->shader->info.num_textures++;
|
b->shader->info.num_textures++;
|
||||||
break;
|
break;
|
||||||
case vtn_variable_mode_push_constant:
|
case vtn_variable_mode_push_constant:
|
||||||
b->shader->num_uniforms = vtn_type_block_size(b, type);
|
b->shader->num_uniforms = vtn_type_block_size(b, type);
|
||||||
@@ -1800,8 +1793,6 @@ vtn_create_variable(struct vtn_builder *b, struct vtn_value *val,
|
|||||||
switch (var->mode) {
|
switch (var->mode) {
|
||||||
case vtn_variable_mode_local:
|
case vtn_variable_mode_local:
|
||||||
case vtn_variable_mode_global:
|
case vtn_variable_mode_global:
|
||||||
case vtn_variable_mode_image:
|
|
||||||
case vtn_variable_mode_sampler:
|
|
||||||
case vtn_variable_mode_uniform:
|
case vtn_variable_mode_uniform:
|
||||||
/* For these, we create the variable normally */
|
/* For these, we create the variable normally */
|
||||||
var->var = rzalloc(b->shader, nir_variable);
|
var->var = rzalloc(b->shader, nir_variable);
|
||||||
@@ -1809,16 +1800,7 @@ vtn_create_variable(struct vtn_builder *b, struct vtn_value *val,
|
|||||||
var->var->type = var->type->type;
|
var->var->type = var->type->type;
|
||||||
var->var->data.mode = nir_mode;
|
var->var->data.mode = nir_mode;
|
||||||
var->var->data.location = -1;
|
var->var->data.location = -1;
|
||||||
|
var->var->interface_type = NULL;
|
||||||
switch (var->mode) {
|
|
||||||
case vtn_variable_mode_image:
|
|
||||||
case vtn_variable_mode_sampler:
|
|
||||||
var->var->interface_type = without_array->type;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
var->var->interface_type = NULL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case vtn_variable_mode_workgroup:
|
case vtn_variable_mode_workgroup:
|
||||||
@@ -1943,8 +1925,7 @@ vtn_create_variable(struct vtn_builder *b, struct vtn_value *val,
|
|||||||
|
|
||||||
vtn_foreach_decoration(b, val, var_decoration_cb, var);
|
vtn_foreach_decoration(b, val, var_decoration_cb, var);
|
||||||
|
|
||||||
if (var->mode == vtn_variable_mode_image ||
|
if (var->mode == vtn_variable_mode_uniform) {
|
||||||
var->mode == vtn_variable_mode_sampler) {
|
|
||||||
/* XXX: We still need the binding information in the nir_variable
|
/* XXX: We still need the binding information in the nir_variable
|
||||||
* for these. We should fix that.
|
* for these. We should fix that.
|
||||||
*/
|
*/
|
||||||
@@ -1952,7 +1933,7 @@ vtn_create_variable(struct vtn_builder *b, struct vtn_value *val,
|
|||||||
var->var->data.descriptor_set = var->descriptor_set;
|
var->var->data.descriptor_set = var->descriptor_set;
|
||||||
var->var->data.index = var->input_attachment_index;
|
var->var->data.index = var->input_attachment_index;
|
||||||
|
|
||||||
if (var->mode == vtn_variable_mode_image)
|
if (glsl_type_is_image(without_array->type))
|
||||||
var->var->data.image.format = without_array->image_format;
|
var->var->data.image.format = without_array->image_format;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2092,8 +2073,8 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
|
|||||||
|
|
||||||
vtn_assert_types_equal(b, opcode, res_type, src_val->type->deref);
|
vtn_assert_types_equal(b, opcode, res_type, src_val->type->deref);
|
||||||
|
|
||||||
if (src->mode == vtn_variable_mode_image ||
|
if (glsl_type_is_image(res_type->type) ||
|
||||||
src->mode == vtn_variable_mode_sampler) {
|
glsl_type_is_sampler(res_type->type)) {
|
||||||
vtn_push_value(b, w[2], vtn_value_type_pointer)->pointer = src;
|
vtn_push_value(b, w[2], vtn_value_type_pointer)->pointer = src;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -427,10 +427,12 @@ anv_nir_apply_pipeline_layout(struct anv_pipeline *pipeline,
|
|||||||
}
|
}
|
||||||
|
|
||||||
nir_foreach_variable(var, &shader->uniforms) {
|
nir_foreach_variable(var, &shader->uniforms) {
|
||||||
if (!glsl_type_is_image(var->interface_type))
|
const struct glsl_type *glsl_type = glsl_without_array(var->type);
|
||||||
|
|
||||||
|
if (!glsl_type_is_image(glsl_type))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
enum glsl_sampler_dim dim = glsl_get_sampler_dim(var->interface_type);
|
enum glsl_sampler_dim dim = glsl_get_sampler_dim(glsl_type);
|
||||||
|
|
||||||
const uint32_t set = var->data.descriptor_set;
|
const uint32_t set = var->data.descriptor_set;
|
||||||
const uint32_t binding = var->data.binding;
|
const uint32_t binding = var->data.binding;
|
||||||
|
Reference in New Issue
Block a user