From f2fe74a462ea6e019678c89632a99d8037a2f153 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Wed, 28 Jun 2017 00:45:36 -0700 Subject: nir/spirv: Add support for SPV_KHR_variable_pointers Reviewed-by: Iago Toral Quiroga --- src/compiler/spirv/spirv_to_nir.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'src/compiler/spirv/spirv_to_nir.c') diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index 6e35f83a421..4b9c1218cf2 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -185,6 +185,13 @@ vtn_ssa_value(struct vtn_builder *b, uint32_t value_id) case vtn_value_type_ssa: return val->ssa; + case vtn_value_type_pointer: + assert(val->pointer->ptr_type && val->pointer->ptr_type->type); + struct vtn_ssa_value *ssa = + vtn_create_ssa_value(b, val->pointer->ptr_type->type); + ssa->def = vtn_pointer_to_ssa(b, val->pointer); + return ssa; + default: unreachable("Invalid type for an SSA value"); } @@ -861,9 +868,16 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode, vtn_value(b, w[3], vtn_value_type_type)->type; val->type->base_type = vtn_base_type_pointer; - val->type->type = NULL; val->type->storage_class = storage_class; val->type->deref = deref_type; + + if (storage_class == SpvStorageClassUniform || + storage_class == SpvStorageClassStorageBuffer) { + /* These can actually be stored to nir_variables and used as SSA + * values so they need a real glsl_type. + */ + val->type->type = glsl_vector_type(GLSL_TYPE_UINT, 2); + } break; } @@ -1387,7 +1401,8 @@ vtn_handle_function_call(struct vtn_builder *b, SpvOp opcode, for (unsigned i = 0; i < call->num_params; i++) { unsigned arg_id = w[4 + i]; struct vtn_value *arg = vtn_untyped_value(b, arg_id); - if (arg->value_type == vtn_value_type_pointer) { + if (arg->value_type == vtn_value_type_pointer && + arg->pointer->ptr_type->type == NULL) { nir_deref_var *d = vtn_pointer_to_deref(b, arg->pointer); call->params[i] = nir_deref_var_clone(d, call); } else { @@ -2769,6 +2784,11 @@ vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode, spv_check_supported(multiview, cap); break; + case SpvCapabilityVariablePointersStorageBuffer: + case SpvCapabilityVariablePointers: + spv_check_supported(variable_pointers, cap); + break; + default: unreachable("Unhandled capability"); } @@ -3153,6 +3173,19 @@ vtn_handle_body_instruction(struct vtn_builder *b, SpvOp opcode, break; } + case SpvOpSelect: { + /* Handle OpSelect up-front here because it needs to be able to handle + * pointers and not just regular vectors and scalars. + */ + struct vtn_type *res_type = vtn_value(b, w[1], vtn_value_type_type)->type; + struct vtn_ssa_value *ssa = vtn_create_ssa_value(b, res_type->type); + ssa->def = nir_bcsel(&b->nb, vtn_ssa_value(b, w[3])->def, + vtn_ssa_value(b, w[4])->def, + vtn_ssa_value(b, w[5])->def); + vtn_push_ssa(b, w[2], res_type, ssa); + break; + } + case SpvOpSNegate: case SpvOpFNegate: case SpvOpNot: @@ -3210,7 +3243,6 @@ vtn_handle_body_instruction(struct vtn_builder *b, SpvOp opcode, case SpvOpBitwiseOr: case SpvOpBitwiseXor: case SpvOpBitwiseAnd: - case SpvOpSelect: case SpvOpIEqual: case SpvOpFOrdEqual: case SpvOpFUnordEqual: -- cgit v1.2.3