[Mesa-dev] [PATCH 9/9] spirv: Replace unreachable with vtn_fail

Jason Ekstrand jason at jlekstrand.net
Thu Aug 17 17:22:23 UTC 2017


---
 src/compiler/spirv/spirv_to_nir.c  | 136 +++++++++++++++++++------------------
 src/compiler/spirv/vtn_alu.c       |  20 +++---
 src/compiler/spirv/vtn_cfg.c       |   8 +--
 src/compiler/spirv/vtn_glsl450.c   |  14 ++--
 src/compiler/spirv/vtn_private.h   |   3 +-
 src/compiler/spirv/vtn_variables.c |  41 +++++------
 6 files changed, 116 insertions(+), 106 deletions(-)

diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index 707fe48..ba5870c 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -237,7 +237,7 @@ vtn_const_ssa_value(struct vtn_builder *b, nir_constant *constant,
    }
 
    default:
-      unreachable("bad constant type");
+      vtn_fail("bad constant type");
    }
 
    return val;
@@ -265,7 +265,7 @@ vtn_ssa_value(struct vtn_builder *b, uint32_t value_id)
       return ssa;
 
    default:
-      unreachable("Invalid type for an SSA value");
+      vtn_fail("Invalid type for an SSA value");
    }
 }
 
@@ -342,7 +342,7 @@ vtn_handle_extension(struct vtn_builder *b, SpvOp opcode,
       if (strcmp((const char *)&w[2], "GLSL.std.450") == 0) {
          val->ext_handler = vtn_handle_glsl450_instruction;
       } else {
-         assert(!"Unsupported extension");
+         vtn_fail("Unsupported extension");
       }
       break;
    }
@@ -354,7 +354,7 @@ vtn_handle_extension(struct vtn_builder *b, SpvOp opcode,
    }
 
    default:
-      unreachable("Unhandled opcode");
+      vtn_fail("Unhandled opcode");
    }
 }
 
@@ -443,7 +443,7 @@ vtn_handle_decoration(struct vtn_builder *b, SpvOp opcode,
          dec->scope = VTN_DEC_EXECUTION_MODE;
          break;
       default:
-         unreachable("Invalid decoration opcode");
+         vtn_fail("Invalid decoration opcode");
       }
       dec->decoration = *(w++);
       dec->literals = w;
@@ -478,7 +478,7 @@ vtn_handle_decoration(struct vtn_builder *b, SpvOp opcode,
    }
 
    default:
-      unreachable("Unhandled opcode");
+      vtn_fail("Unhandled opcode");
    }
 }
 
@@ -642,7 +642,7 @@ struct_member_decoration_cb(struct vtn_builder *b,
       break;
 
    default:
-      unreachable("Unhandled decoration");
+      vtn_fail("Unhandled decoration");
    }
 }
 
@@ -753,12 +753,12 @@ type_decoration_cb(struct vtn_builder *b,
       break;
 
    default:
-      unreachable("Unhandled decoration");
+      vtn_fail("Unhandled decoration");
    }
 }
 
 static unsigned
-translate_image_format(SpvImageFormat format)
+translate_image_format(struct vtn_builder *b, SpvImageFormat format)
 {
    switch (format) {
    case SpvImageFormatUnknown:      return 0;      /* GL_NONE */
@@ -802,7 +802,7 @@ translate_image_format(SpvImageFormat format)
    case SpvImageFormatR16ui:        return 0x8234; /* GL_R16UI */
    case SpvImageFormatR8ui:         return 0x8232; /* GL_R8UI */
    default:
-      assert(!"Invalid image format");
+      vtn_fail("Invalid image format");
       return 0;
    }
 }
@@ -977,7 +977,7 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode,
       case SpvDimBuffer:   dim = GLSL_SAMPLER_DIM_BUF;   break;
       case SpvDimSubpassData: dim = GLSL_SAMPLER_DIM_SUBPASS; break;
       default:
-         unreachable("Invalid SPIR-V Sampler dimension");
+         vtn_fail("Invalid SPIR-V Sampler dimension");
       }
 
       bool is_shadow = w[4];
@@ -997,10 +997,10 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode,
          else if (dim == GLSL_SAMPLER_DIM_SUBPASS)
             dim = GLSL_SAMPLER_DIM_SUBPASS_MS;
          else
-            assert(!"Unsupported multisampled image type");
+            vtn_fail("Unsupported multisampled image type");
       }
 
-      val->type->image_format = translate_image_format(format);
+      val->type->image_format = translate_image_format(b, format);
 
       if (sampled == 1) {
          val->type->sampled = true;
@@ -1012,7 +1012,7 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode,
          val->type->type = glsl_image_type(dim, is_array,
                                            glsl_get_base_type(sampled_type));
       } else {
-         assert(!"We need to know if the image will be sampled");
+         vtn_fail("We need to know if the image will be sampled");
       }
       break;
    }
@@ -1038,7 +1038,7 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode,
    case SpvOpTypeQueue:
    case SpvOpTypePipe:
    default:
-      unreachable("Unhandled opcode");
+      vtn_fail("Unhandled opcode");
    }
 
    vtn_foreach_decoration(b, val, type_decoration_cb, NULL);
@@ -1086,7 +1086,7 @@ vtn_null_constant(struct vtn_builder *b, const struct glsl_type *type)
       break;
 
    default:
-      unreachable("Invalid type for null constant");
+      vtn_fail("Invalid type for null constant");
    }
 
    return c;
@@ -1247,7 +1247,7 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,
          break;
 
       default:
-         unreachable("Unsupported type for constants");
+         vtn_fail("Unsupported type for constants");
       }
       break;
    }
@@ -1383,7 +1383,7 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,
                continue;
 
             default:
-               unreachable("Invalid constant type");
+               vtn_fail("Invalid constant type");
             }
          }
 
@@ -1426,7 +1426,9 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,
          bool swap;
          nir_alu_type dst_alu_type = nir_get_nir_type_for_glsl_type(val->const_type);
          nir_alu_type src_alu_type = dst_alu_type;
-         nir_op op = vtn_nir_alu_op_for_spirv_opcode(opcode, &swap, src_alu_type, dst_alu_type);
+         nir_op op = vtn_nir_alu_op_for_spirv_opcode(b, opcode, &swap,
+                                                     src_alu_type,
+                                                     dst_alu_type);
 
          unsigned num_components = glsl_get_vector_elements(val->const_type);
          unsigned bit_size =
@@ -1456,11 +1458,11 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,
       break;
 
    case SpvOpConstantSampler:
-      assert(!"OpConstantSampler requires Kernel Capability");
+      vtn_fail("OpConstantSampler requires Kernel Capability");
       break;
 
    default:
-      unreachable("Unhandled opcode");
+      vtn_fail("Unhandled opcode");
    }
 
    /* Now that we have the value, update the workgroup size if needed */
@@ -1541,7 +1543,7 @@ vtn_create_ssa_value(struct vtn_builder *b, const struct glsl_type *type)
             child_type = glsl_get_struct_field(type, i);
             break;
          default:
-            unreachable("unkown base type");
+            vtn_fail("unkown base type");
          }
 
          val->elems[i] = vtn_create_ssa_value(b, child_type);
@@ -1656,7 +1658,7 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
       break;
 
    default:
-      unreachable("Unhandled opcode");
+      vtn_fail("Unhandled opcode");
    }
 
    nir_tex_src srcs[8]; /* 8 should be enough */
@@ -1695,7 +1697,7 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
          coord_components = 3;
          break;
       default:
-         unreachable("Invalid sampler type");
+         vtn_fail("Invalid sampler type");
       }
 
       if (is_array && texop != nir_texop_lod)
@@ -1816,7 +1818,7 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
    case GLSL_TYPE_UINT:    instr->dest_type = nir_type_uint;  break;
    case GLSL_TYPE_BOOL:    instr->dest_type = nir_type_bool;      break;
    default:
-      unreachable("Invalid base type for sampler result");
+      vtn_fail("Invalid base type for sampler result");
    }
 
    nir_deref_var *sampler = vtn_pointer_to_deref(b, sampled.sampler);
@@ -1850,7 +1852,7 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
       instr->sampler = NULL;
       break;
    case nir_texop_txf_ms_mcs:
-      unreachable("unexpected nir_texop_txf_ms_mcs");
+      vtn_fail("unexpected nir_texop_txf_ms_mcs");
    }
 
    nir_ssa_dest_init(&instr->instr, &instr->dest,
@@ -1956,7 +1958,7 @@ fill_common_atomic_sources(struct vtn_builder *b, SpvOp opcode,
       break;
 
    default:
-      unreachable("Invalid SPIR-V atomic");
+      vtn_fail("Invalid SPIR-V atomic");
    }
 }
 
@@ -2048,7 +2050,7 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
       break;
 
    default:
-      unreachable("Invalid image opcode");
+      vtn_fail("Invalid image opcode");
    }
 
    nir_intrinsic_op op;
@@ -2074,7 +2076,7 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
    OP(AtomicXor,              atomic_xor)
 #undef OP
    default:
-      unreachable("Invalid image opcode");
+      vtn_fail("Invalid image opcode");
    }
 
    nir_intrinsic_instr *intrin = nir_intrinsic_instr_create(b->shader, op);
@@ -2123,7 +2125,7 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
       break;
 
    default:
-      unreachable("Invalid image opcode");
+      vtn_fail("Invalid image opcode");
    }
 
    if (opcode != SpvOpImageWrite) {
@@ -2150,7 +2152,7 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
 }
 
 static nir_intrinsic_op
-get_ssbo_nir_atomic_op(SpvOp opcode)
+get_ssbo_nir_atomic_op(struct vtn_builder *b, SpvOp opcode)
 {
    switch (opcode) {
    case SpvOpAtomicLoad:      return nir_intrinsic_load_ssbo;
@@ -2171,12 +2173,12 @@ get_ssbo_nir_atomic_op(SpvOp opcode)
    OP(AtomicXor,              atomic_xor)
 #undef OP
    default:
-      unreachable("Invalid SSBO atomic");
+      vtn_fail("Invalid SSBO atomic");
    }
 }
 
 static nir_intrinsic_op
-get_shared_nir_atomic_op(SpvOp opcode)
+get_shared_nir_atomic_op(struct vtn_builder *b, SpvOp opcode)
 {
    switch (opcode) {
    case SpvOpAtomicLoad:      return nir_intrinsic_load_var;
@@ -2197,7 +2199,7 @@ get_shared_nir_atomic_op(SpvOp opcode)
    OP(AtomicXor,              atomic_xor)
 #undef OP
    default:
-      unreachable("Invalid shared atomic");
+      vtn_fail("Invalid shared atomic");
    }
 }
 
@@ -2232,7 +2234,7 @@ vtn_handle_ssbo_or_shared_atomic(struct vtn_builder *b, SpvOp opcode,
       break;
 
    default:
-      unreachable("Invalid SPIR-V atomic");
+      vtn_fail("Invalid SPIR-V atomic");
    }
 
    /*
@@ -2243,7 +2245,7 @@ vtn_handle_ssbo_or_shared_atomic(struct vtn_builder *b, SpvOp opcode,
    if (ptr->mode == vtn_variable_mode_workgroup) {
       nir_deref_var *deref = vtn_pointer_to_deref(b, ptr);
       const struct glsl_type *deref_type = nir_deref_tail(&deref->deref)->type;
-      nir_intrinsic_op op = get_shared_nir_atomic_op(opcode);
+      nir_intrinsic_op op = get_shared_nir_atomic_op(b, opcode);
       atomic = nir_intrinsic_instr_create(b->nb.shader, op);
       atomic->variables[0] = nir_deref_var_clone(deref, atomic);
 
@@ -2276,7 +2278,7 @@ vtn_handle_ssbo_or_shared_atomic(struct vtn_builder *b, SpvOp opcode,
          break;
 
       default:
-         unreachable("Invalid SPIR-V atomic");
+         vtn_fail("Invalid SPIR-V atomic");
 
       }
    } else {
@@ -2284,7 +2286,7 @@ vtn_handle_ssbo_or_shared_atomic(struct vtn_builder *b, SpvOp opcode,
       nir_ssa_def *offset, *index;
       offset = vtn_pointer_to_offset(b, ptr, &index, NULL);
 
-      nir_intrinsic_op op = get_ssbo_nir_atomic_op(opcode);
+      nir_intrinsic_op op = get_ssbo_nir_atomic_op(b, opcode);
 
       atomic = nir_intrinsic_instr_create(b->nb.shader, op);
 
@@ -2323,7 +2325,7 @@ vtn_handle_ssbo_or_shared_atomic(struct vtn_builder *b, SpvOp opcode,
          break;
 
       default:
-         unreachable("Invalid SPIR-V atomic");
+         vtn_fail("Invalid SPIR-V atomic");
       }
    }
 
@@ -2344,7 +2346,7 @@ vtn_handle_ssbo_or_shared_atomic(struct vtn_builder *b, SpvOp opcode,
 }
 
 static nir_alu_instr *
-create_vec(nir_shader *shader, unsigned num_components, unsigned bit_size)
+create_vec(struct vtn_builder *b, unsigned num_components, unsigned bit_size)
 {
    nir_op op;
    switch (num_components) {
@@ -2352,10 +2354,10 @@ create_vec(nir_shader *shader, unsigned num_components, unsigned bit_size)
    case 2: op = nir_op_vec2; break;
    case 3: op = nir_op_vec3; break;
    case 4: op = nir_op_vec4; break;
-   default: unreachable("bad vector size");
+   default: vtn_fail("bad vector size");
    }
 
-   nir_alu_instr *vec = nir_alu_instr_create(shader, op);
+   nir_alu_instr *vec = nir_alu_instr_create(b->shader, op);
    nir_ssa_dest_init(&vec->instr, &vec->dest.dest, num_components,
                      bit_size, NULL);
    vec->dest.write_mask = (1 << num_components) - 1;
@@ -2373,9 +2375,8 @@ vtn_ssa_transpose(struct vtn_builder *b, struct vtn_ssa_value *src)
       vtn_create_ssa_value(b, glsl_transposed_type(src->type));
 
    for (unsigned i = 0; i < glsl_get_matrix_columns(dest->type); i++) {
-      nir_alu_instr *vec = create_vec(b->shader,
-                                      glsl_get_matrix_columns(src->type),
-                                      glsl_get_bit_size(src->type));
+      nir_alu_instr *vec = create_vec(b, glsl_get_matrix_columns(src->type),
+                                         glsl_get_bit_size(src->type));
       if (glsl_type_is_vector_or_scalar(src->type)) {
           vec->src[0].src = nir_src_for_ssa(src->def);
           vec->src[0].swizzle[0] = i;
@@ -2405,7 +2406,7 @@ nir_ssa_def *
 vtn_vector_insert(struct vtn_builder *b, nir_ssa_def *src, nir_ssa_def *insert,
                   unsigned index)
 {
-   nir_alu_instr *vec = create_vec(b->shader, src->num_components,
+   nir_alu_instr *vec = create_vec(b, src->num_components,
                                    src->bit_size);
 
    for (unsigned i = 0; i < src->num_components; i++) {
@@ -2451,7 +2452,7 @@ vtn_vector_shuffle(struct vtn_builder *b, unsigned num_components,
                    nir_ssa_def *src0, nir_ssa_def *src1,
                    const uint32_t *indices)
 {
-   nir_alu_instr *vec = create_vec(b->shader, num_components, src0->bit_size);
+   nir_alu_instr *vec = create_vec(b, num_components, src0->bit_size);
 
    for (unsigned i = 0; i < num_components; i++) {
       uint32_t index = indices[i];
@@ -2479,8 +2480,7 @@ static nir_ssa_def *
 vtn_vector_construct(struct vtn_builder *b, unsigned num_components,
                      unsigned num_srcs, nir_ssa_def **srcs)
 {
-   nir_alu_instr *vec = create_vec(b->shader, num_components,
-                                   srcs[0]->bit_size);
+   nir_alu_instr *vec = create_vec(b, num_components, srcs[0]->bit_size);
 
    /* From the SPIR-V 1.1 spec for OpCompositeConstruct:
     *
@@ -2643,7 +2643,7 @@ vtn_handle_composite(struct vtn_builder *b, SpvOp opcode,
       break;
 
    default:
-      unreachable("unknown composite operation");
+      vtn_fail("unknown composite operation");
    }
 }
 
@@ -2668,7 +2668,7 @@ vtn_handle_barrier(struct vtn_builder *b, SpvOp opcode,
       intrinsic_op = nir_intrinsic_barrier;
       break;
    default:
-      unreachable("unknown barrier instruction");
+      vtn_fail("unknown barrier instruction");
    }
 
    nir_intrinsic_instr *intrin =
@@ -2681,7 +2681,8 @@ vtn_handle_barrier(struct vtn_builder *b, SpvOp opcode,
 }
 
 static unsigned
-gl_primitive_from_spv_execution_mode(SpvExecutionMode mode)
+gl_primitive_from_spv_execution_mode(struct vtn_builder *b,
+                                     SpvExecutionMode mode)
 {
    switch (mode) {
    case SpvExecutionModeInputPoints:
@@ -2704,13 +2705,14 @@ gl_primitive_from_spv_execution_mode(SpvExecutionMode mode)
    case SpvExecutionModeOutputTriangleStrip:
       return 5; /* GL_TRIANGLE_STRIP */
    default:
-      assert(!"Invalid primitive type");
+      vtn_fail("Invalid primitive type");
       return 4;
    }
 }
 
 static unsigned
-vertices_in_from_spv_execution_mode(SpvExecutionMode mode)
+vertices_in_from_spv_execution_mode(struct vtn_builder *b,
+                                    SpvExecutionMode mode)
 {
    switch (mode) {
    case SpvExecutionModeInputPoints:
@@ -2724,13 +2726,13 @@ vertices_in_from_spv_execution_mode(SpvExecutionMode mode)
    case SpvExecutionModeInputTrianglesAdjacency:
       return 6;
    default:
-      assert(!"Invalid GS input mode");
+      vtn_fail("Invalid GS input mode");
       return 0;
    }
 }
 
 static gl_shader_stage
-stage_for_execution_model(SpvExecutionModel model)
+stage_for_execution_model(struct vtn_builder *b, SpvExecutionModel model)
 {
    switch (model) {
    case SpvExecutionModelVertex:
@@ -2746,7 +2748,7 @@ stage_for_execution_model(SpvExecutionModel model)
    case SpvExecutionModelGLCompute:
       return MESA_SHADER_COMPUTE;
    default:
-      unreachable("Unsupported execution model");
+      vtn_fail("Unsupported execution model");
    }
 }
 
@@ -2888,7 +2890,7 @@ vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode,
          break;
 
       default:
-         unreachable("Unhandled capability");
+         vtn_fail("Unhandled capability");
       }
       break;
    }
@@ -2909,7 +2911,7 @@ vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode,
       entry_point->name = vtn_string_literal(b, &w[3], count - 3, &name_words);
 
       if (strcmp(entry_point->name, b->entry_point_name) != 0 ||
-          stage_for_execution_model(w[1]) != b->entry_point_stage)
+          stage_for_execution_model(b, w[1]) != b->entry_point_stage)
          break;
 
       vtn_assert(b->entry_point == NULL);
@@ -3015,11 +3017,11 @@ vtn_handle_execution_mode(struct vtn_builder *b, struct vtn_value *entry_point,
       if (b->shader->stage == MESA_SHADER_TESS_CTRL ||
           b->shader->stage == MESA_SHADER_TESS_EVAL) {
          b->shader->info.tess.primitive_mode =
-            gl_primitive_from_spv_execution_mode(mode->exec_mode);
+            gl_primitive_from_spv_execution_mode(b, mode->exec_mode);
       } else {
          vtn_assert(b->shader->stage == MESA_SHADER_GEOMETRY);
          b->shader->info.gs.vertices_in =
-            vertices_in_from_spv_execution_mode(mode->exec_mode);
+            vertices_in_from_spv_execution_mode(b, mode->exec_mode);
       }
       break;
 
@@ -3028,7 +3030,7 @@ vtn_handle_execution_mode(struct vtn_builder *b, struct vtn_value *entry_point,
    case SpvExecutionModeOutputTriangleStrip:
       vtn_assert(b->shader->stage == MESA_SHADER_GEOMETRY);
       b->shader->info.gs.output_primitive =
-         gl_primitive_from_spv_execution_mode(mode->exec_mode);
+         gl_primitive_from_spv_execution_mode(b, mode->exec_mode);
       break;
 
    case SpvExecutionModeSpacingEqual:
@@ -3072,7 +3074,7 @@ vtn_handle_execution_mode(struct vtn_builder *b, struct vtn_value *entry_point,
       break;
 
    case SpvExecutionModeXfb:
-      assert(!"Unhandled execution mode");
+      vtn_fail("Unhandled execution mode");
       break;
 
    case SpvExecutionModeVecTypeHint:
@@ -3080,7 +3082,7 @@ vtn_handle_execution_mode(struct vtn_builder *b, struct vtn_value *entry_point,
       break; /* OpenCL */
 
    default:
-      unreachable("Unhandled execution mode");
+      vtn_fail("Unhandled execution mode");
    }
 }
 
@@ -3106,7 +3108,7 @@ vtn_handle_variable_or_type_instruction(struct vtn_builder *b, SpvOp opcode,
    case SpvOpMemberDecorate:
    case SpvOpGroupDecorate:
    case SpvOpGroupMemberDecorate:
-      assert(!"Invalid opcode types and variables section");
+      vtn_fail("Invalid opcode types and variables section");
       break;
 
    case SpvOpTypeVoid:
@@ -3406,7 +3408,7 @@ vtn_handle_body_instruction(struct vtn_builder *b, SpvOp opcode,
       break;
 
    default:
-      unreachable("Unhandled opcode");
+      vtn_fail("Unhandled opcode");
    }
 
    return true;
@@ -3459,7 +3461,7 @@ spirv_to_nir(const uint32_t *words, size_t word_count,
                                    vtn_handle_preamble_instruction);
 
    if (b->entry_point == NULL) {
-      assert(!"Entry point not found");
+      vtn_fail("Entry point not found");
       ralloc_free(b);
       return NULL;
    }
diff --git a/src/compiler/spirv/vtn_alu.c b/src/compiler/spirv/vtn_alu.c
index 5fa695b..7653b8a 100644
--- a/src/compiler/spirv/vtn_alu.c
+++ b/src/compiler/spirv/vtn_alu.c
@@ -206,7 +206,7 @@ vtn_handle_matrix_alu(struct vtn_builder *b, SpvOp opcode,
       }
       break;
 
-   default: unreachable("unknown matrix opcode");
+   default: vtn_fail("unknown matrix opcode");
    }
 }
 
@@ -273,7 +273,8 @@ vtn_handle_bitcast(struct vtn_builder *b, struct vtn_ssa_value *dest,
 }
 
 nir_op
-vtn_nir_alu_op_for_spirv_opcode(SpvOp opcode, bool *swap,
+vtn_nir_alu_op_for_spirv_opcode(struct vtn_builder *b,
+                                SpvOp opcode, bool *swap,
                                 nir_alu_type src, nir_alu_type dst)
 {
    /* Indicates that the first two arguments should be swapped.  This is
@@ -366,7 +367,7 @@ vtn_nir_alu_op_for_spirv_opcode(SpvOp opcode, bool *swap,
    case SpvOpDPdyCoarse:   return nir_op_fddy_coarse;
 
    default:
-      unreachable("No NIR equivalent");
+      vtn_fail("No NIR equivalent");
    }
 }
 
@@ -421,7 +422,7 @@ vtn_handle_alu(struct vtn_builder *b, SpvOp opcode,
          case 2:  op = nir_op_bany_inequal2; break;
          case 3:  op = nir_op_bany_inequal3; break;
          case 4:  op = nir_op_bany_inequal4; break;
-         default: unreachable("invalid number of components");
+         default: vtn_fail("invalid number of components");
          }
          val->ssa->def = nir_build_alu(&b->nb, op, src[0],
                                        nir_imm_int(&b->nb, NIR_FALSE),
@@ -438,7 +439,7 @@ vtn_handle_alu(struct vtn_builder *b, SpvOp opcode,
          case 2:  op = nir_op_ball_iequal2;  break;
          case 3:  op = nir_op_ball_iequal3;  break;
          case 4:  op = nir_op_ball_iequal4;  break;
-         default: unreachable("invalid number of components");
+         default: vtn_fail("invalid number of components");
          }
          val->ssa->def = nir_build_alu(&b->nb, op, src[0],
                                        nir_imm_int(&b->nb, NIR_TRUE),
@@ -521,7 +522,8 @@ vtn_handle_alu(struct vtn_builder *b, SpvOp opcode,
       bool swap;
       nir_alu_type src_alu_type = nir_get_nir_type_for_glsl_type(vtn_src[0]->type);
       nir_alu_type dst_alu_type = nir_get_nir_type_for_glsl_type(type);
-      nir_op op = vtn_nir_alu_op_for_spirv_opcode(opcode, &swap, src_alu_type, dst_alu_type);
+      nir_op op = vtn_nir_alu_op_for_spirv_opcode(b, opcode, &swap,
+                                                  src_alu_type, dst_alu_type);
 
       if (swap) {
          nir_ssa_def *tmp = src[0];
@@ -547,7 +549,8 @@ vtn_handle_alu(struct vtn_builder *b, SpvOp opcode,
       bool swap;
       nir_alu_type src_alu_type = nir_get_nir_type_for_glsl_type(vtn_src[0]->type);
       nir_alu_type dst_alu_type = nir_get_nir_type_for_glsl_type(type);
-      nir_op op = vtn_nir_alu_op_for_spirv_opcode(opcode, &swap, src_alu_type, dst_alu_type);
+      nir_op op = vtn_nir_alu_op_for_spirv_opcode(b, opcode, &swap,
+                                                  src_alu_type, dst_alu_type);
 
       if (swap) {
          nir_ssa_def *tmp = src[0];
@@ -572,7 +575,8 @@ vtn_handle_alu(struct vtn_builder *b, SpvOp opcode,
       bool swap;
       nir_alu_type src_alu_type = nir_get_nir_type_for_glsl_type(vtn_src[0]->type);
       nir_alu_type dst_alu_type = nir_get_nir_type_for_glsl_type(type);
-      nir_op op = vtn_nir_alu_op_for_spirv_opcode(opcode, &swap, src_alu_type, dst_alu_type);
+      nir_op op = vtn_nir_alu_op_for_spirv_opcode(b, opcode, &swap,
+                                                  src_alu_type, dst_alu_type);
 
       if (swap) {
          nir_ssa_def *tmp = src[0];
diff --git a/src/compiler/spirv/vtn_cfg.c b/src/compiler/spirv/vtn_cfg.c
index b5cc0ad..6390efc 100644
--- a/src/compiler/spirv/vtn_cfg.c
+++ b/src/compiler/spirv/vtn_cfg.c
@@ -397,7 +397,7 @@ vtn_cfg_walk_blocks(struct vtn_builder *b, struct list_head *cf_list,
             }
             continue;
          }
-         unreachable("Should have returned or continued");
+         vtn_fail("Should have returned or continued");
       }
 
       case SpvOpSwitch: {
@@ -467,7 +467,7 @@ vtn_cfg_walk_blocks(struct vtn_builder *b, struct list_head *cf_list,
          return;
 
       default:
-         unreachable("Unhandled opcode");
+         vtn_fail("Unhandled opcode");
       }
    }
 }
@@ -569,7 +569,7 @@ vtn_emit_branch(struct vtn_builder *b, enum vtn_branch_type branch_type,
       break;
    }
    default:
-      unreachable("Invalid branch type");
+      vtn_fail("Invalid branch type");
    }
 }
 
@@ -750,7 +750,7 @@ vtn_emit_cf_list(struct vtn_builder *b, struct list_head *cf_list,
       }
 
       default:
-         unreachable("Invalid CF node type");
+         vtn_fail("Invalid CF node type");
       }
    }
 }
diff --git a/src/compiler/spirv/vtn_glsl450.c b/src/compiler/spirv/vtn_glsl450.c
index 051e034..46ef40f 100644
--- a/src/compiler/spirv/vtn_glsl450.c
+++ b/src/compiler/spirv/vtn_glsl450.c
@@ -101,7 +101,7 @@ build_mat_det(struct vtn_builder *b, struct vtn_ssa_value *src)
    case 3: return build_mat3_det(&b->nb, cols);
    case 4: return build_mat4_det(&b->nb, cols);
    default:
-      unreachable("Invalid matrix size");
+      vtn_fail("Invalid matrix size");
    }
 }
 
@@ -413,7 +413,8 @@ build_frexp(nir_builder *b, nir_ssa_def *x, nir_ssa_def **exponent)
 }
 
 static nir_op
-vtn_nir_alu_op_for_spirv_glsl_opcode(enum GLSLstd450 opcode)
+vtn_nir_alu_op_for_spirv_glsl_opcode(struct vtn_builder *b,
+                                     enum GLSLstd450 opcode)
 {
    switch (opcode) {
    case GLSLstd450Round:         return nir_op_fround_even;
@@ -463,7 +464,7 @@ vtn_nir_alu_op_for_spirv_glsl_opcode(enum GLSLstd450 opcode)
    case GLSLstd450UnpackDouble2x32: return nir_op_unpack_64_2x32;
 
    default:
-      unreachable("No NIR equivalent");
+      vtn_fail("No NIR equivalent");
    }
 }
 
@@ -698,7 +699,8 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSLstd450 entrypoint,
 
    default:
       val->ssa->def =
-         nir_build_alu(&b->nb, vtn_nir_alu_op_for_spirv_glsl_opcode(entrypoint),
+         nir_build_alu(&b->nb,
+                       vtn_nir_alu_op_for_spirv_glsl_opcode(b, entrypoint),
                        src[0], src[1], src[2], NULL);
       return;
    }
@@ -726,7 +728,7 @@ handle_glsl450_interpolation(struct vtn_builder *b, enum GLSLstd450 opcode,
       op = nir_intrinsic_interp_var_at_offset;
       break;
    default:
-      unreachable("Invalid opcode");
+      vtn_fail("Invalid opcode");
    }
 
    nir_intrinsic_instr *intrin = nir_intrinsic_instr_create(b->nb.shader, op);
@@ -742,7 +744,7 @@ handle_glsl450_interpolation(struct vtn_builder *b, enum GLSLstd450 opcode,
       intrin->src[0] = nir_src_for_ssa(vtn_ssa_value(b, w[6])->def);
       break;
    default:
-      unreachable("Invalid opcode");
+      vtn_fail("Invalid opcode");
    }
 
    intrin->num_components = glsl_get_vector_elements(dest_type);
diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h
index f640289..953d582 100644
--- a/src/compiler/spirv/vtn_private.h
+++ b/src/compiler/spirv/vtn_private.h
@@ -666,7 +666,8 @@ typedef void (*vtn_execution_mode_foreach_cb)(struct vtn_builder *,
 void vtn_foreach_execution_mode(struct vtn_builder *b, struct vtn_value *value,
                                 vtn_execution_mode_foreach_cb cb, void *data);
 
-nir_op vtn_nir_alu_op_for_spirv_opcode(SpvOp opcode, bool *swap,
+nir_op vtn_nir_alu_op_for_spirv_opcode(struct vtn_builder *b,
+                                       SpvOp opcode, bool *swap,
                                        nir_alu_type src, nir_alu_type dst);
 
 void vtn_handle_alu(struct vtn_builder *b, SpvOp opcode,
diff --git a/src/compiler/spirv/vtn_variables.c b/src/compiler/spirv/vtn_variables.c
index 89ee7f3..2e2acaa 100644
--- a/src/compiler/spirv/vtn_variables.c
+++ b/src/compiler/spirv/vtn_variables.c
@@ -204,7 +204,7 @@ vtn_ssa_offset_pointer_dereference(struct vtn_builder *b,
       }
 
       default:
-         unreachable("Invalid type for deref");
+         vtn_fail("Invalid type for deref");
       }
    }
 
@@ -339,7 +339,7 @@ vtn_pointer_to_deref(struct vtn_builder *b, struct vtn_pointer *ptr)
          break;
       }
       default:
-         unreachable("Invalid type for deref");
+         vtn_fail("Invalid type for deref");
       }
    }
 
@@ -542,7 +542,7 @@ vtn_pointer_to_offset(struct vtn_builder *b, struct vtn_pointer *ptr,
       }
 
       default:
-         unreachable("Invalid type for deref");
+         vtn_fail("Invalid type for deref");
       }
    }
 
@@ -805,7 +805,7 @@ _vtn_block_load_store(struct vtn_builder *b, nir_intrinsic_op op, bool load,
    }
 
    default:
-      unreachable("Invalid block member type");
+      vtn_fail("Invalid block member type");
    }
 }
 
@@ -913,7 +913,7 @@ _vtn_variable_load_store(struct vtn_builder *b, bool load,
    }
 
    default:
-      unreachable("Invalid access chain type");
+      vtn_fail("Invalid access chain type");
    }
 }
 
@@ -986,7 +986,7 @@ _vtn_variable_copy(struct vtn_builder *b, struct vtn_pointer *dest,
    }
 
    default:
-      unreachable("Invalid access chain type");
+      vtn_fail("Invalid access chain type");
    }
 }
 
@@ -1066,7 +1066,7 @@ vtn_get_builtin_location(struct vtn_builder *b,
       else if (b->shader->stage == MESA_SHADER_GEOMETRY)
          *mode = nir_var_shader_out;
       else
-         unreachable("invalid stage for SpvBuiltInLayer");
+         vtn_fail("invalid stage for SpvBuiltInLayer");
       break;
    case SpvBuiltInViewportIndex:
       *location = VARYING_SLOT_VIEWPORT;
@@ -1075,7 +1075,7 @@ vtn_get_builtin_location(struct vtn_builder *b,
       else if (b->shader->stage == MESA_SHADER_FRAGMENT)
          *mode = nir_var_shader_in;
       else
-         unreachable("invalid stage for SpvBuiltInViewportIndex");
+         vtn_fail("invalid stage for SpvBuiltInViewportIndex");
       break;
    case SpvBuiltInTessLevelOuter:
       *location = VARYING_SLOT_TESS_LEVEL_OUTER;
@@ -1129,7 +1129,7 @@ vtn_get_builtin_location(struct vtn_builder *b,
       break;
    case SpvBuiltInWorkgroupSize:
       /* This should already be handled */
-      unreachable("unsupported builtin");
+      vtn_fail("unsupported builtin");
       break;
    case SpvBuiltInWorkgroupId:
       *location = SYSTEM_VALUE_WORK_GROUP_ID;
@@ -1165,7 +1165,7 @@ vtn_get_builtin_location(struct vtn_builder *b,
       break;
    case SpvBuiltInHelperInvocation:
    default:
-      unreachable("unsupported builtin");
+      vtn_fail("unsupported builtin");
    }
 }
 
@@ -1263,7 +1263,7 @@ apply_var_decoration(struct vtn_builder *b, nir_variable *nir_var,
       break;
 
    case SpvDecorationLocation:
-      unreachable("Handled above");
+      vtn_fail("Handled above");
 
    case SpvDecorationBlock:
    case SpvDecorationBufferBlock:
@@ -1297,7 +1297,7 @@ apply_var_decoration(struct vtn_builder *b, nir_variable *nir_var,
       break;
 
    default:
-      unreachable("Unhandled decoration");
+      vtn_fail("Unhandled decoration");
    }
 }
 
@@ -1409,7 +1409,8 @@ var_decoration_cb(struct vtn_builder *b, struct vtn_value *val, int member,
 }
 
 static enum vtn_variable_mode
-vtn_storage_class_to_mode(SpvStorageClass class,
+vtn_storage_class_to_mode(struct vtn_builder *b,
+                          SpvStorageClass class,
                           struct vtn_type *interface_type,
                           nir_variable_mode *nir_mode_out)
 {
@@ -1424,7 +1425,7 @@ vtn_storage_class_to_mode(SpvStorageClass class,
          mode = vtn_variable_mode_ssbo;
          nir_mode = 0;
       } else {
-         assert(!"Invalid uniform variable type");
+         vtn_fail("Invalid uniform variable type");
       }
       break;
    case SpvStorageClassStorageBuffer:
@@ -1439,7 +1440,7 @@ vtn_storage_class_to_mode(SpvStorageClass class,
          mode = vtn_variable_mode_sampler;
          nir_mode = nir_var_uniform;
       } else {
-         assert(!"Invalid uniform constant variable type");
+         vtn_fail("Invalid uniform constant variable type");
       }
       break;
    case SpvStorageClassPushConstant:
@@ -1470,7 +1471,7 @@ vtn_storage_class_to_mode(SpvStorageClass class,
    case SpvStorageClassGeneric:
    case SpvStorageClassAtomicCounter:
    default:
-      unreachable("Unhandled variable storage class");
+      vtn_fail("Unhandled variable storage class");
    }
 
    if (nir_mode_out)
@@ -1516,7 +1517,7 @@ vtn_pointer_from_ssa(struct vtn_builder *b, nir_ssa_def *ssa,
    vtn_assert(ptr_type->type);
 
    struct vtn_pointer *ptr = rzalloc(b, struct vtn_pointer);
-   ptr->mode = vtn_storage_class_to_mode(ptr_type->storage_class,
+   ptr->mode = vtn_storage_class_to_mode(b, ptr_type->storage_class,
                                          ptr_type, NULL);
    ptr->type = ptr_type->deref;
    ptr->ptr_type = ptr_type;
@@ -1558,7 +1559,7 @@ vtn_create_variable(struct vtn_builder *b, struct vtn_value *val,
 
    enum vtn_variable_mode mode;
    nir_variable_mode nir_mode;
-   mode = vtn_storage_class_to_mode(storage_class, without_array, &nir_mode);
+   mode = vtn_storage_class_to_mode(b, storage_class, without_array, &nir_mode);
 
    switch (mode) {
    case vtn_variable_mode_ubo:
@@ -1694,7 +1695,7 @@ vtn_create_variable(struct vtn_builder *b, struct vtn_value *val,
    }
 
    case vtn_variable_mode_param:
-      unreachable("Not created through OpVariable");
+      vtn_fail("Not created through OpVariable");
 
    case vtn_variable_mode_ubo:
    case vtn_variable_mode_ssbo:
@@ -1892,6 +1893,6 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
 
    case SpvOpCopyMemorySized:
    default:
-      unreachable("Unhandled opcode");
+      vtn_fail("Unhandled opcode");
    }
 }
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list