diff options
author | Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com> | 2019-04-10 11:13:40 -0700 |
---|---|---|
committer | Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com> | 2019-04-16 11:11:10 -0700 |
commit | a0dae78e720c980a311c6c3cfd8ddcef70102bfe (patch) | |
tree | 582bb284fdd515269af1553a9a1db041618c8d52 | |
parent | 0ccfe741b106efea2f2c5d526d50f4bce61d701e (diff) |
spirv: Tell which opcode or value is unhandled when failing
v2: When available, include the opcode name too. (Karol)
v3: Use more to_string helpers. (Karol)
Include the wrong bit_size in those failures.
Include the capability number in spv_check_supported.
Provide vtn_fail_with_* macros to avoid noise in the call sites.
v4: Provide macros only for opcode and decoration, which have enough
usages to justify them. (Jason)
Acked-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Karol Herbst <kherbst@redhat.com>
-rw-r--r-- | src/compiler/spirv/spirv_to_nir.c | 79 | ||||
-rw-r--r-- | src/compiler/spirv/vtn_alu.c | 3 | ||||
-rw-r--r-- | src/compiler/spirv/vtn_private.h | 6 | ||||
-rw-r--r-- | src/compiler/spirv/vtn_variables.c | 15 |
4 files changed, 61 insertions, 42 deletions
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index 99bf649e57e..b297a4c2e4a 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -415,7 +415,7 @@ vtn_handle_extension(struct vtn_builder *b, SpvOp opcode, } default: - vtn_fail("Unhandled opcode"); + vtn_fail_with_opcode("Unhandled opcode", opcode); } } @@ -846,7 +846,7 @@ struct_member_decoration_cb(struct vtn_builder *b, break; default: - vtn_fail("Unhandled decoration"); + vtn_fail_with_decoration("Unhandled decoration", dec->decoration); } } @@ -1022,7 +1022,7 @@ type_decoration_cb(struct vtn_builder *b, break; default: - vtn_fail("Unhandled decoration"); + vtn_fail_with_decoration("Unhandled decoration", dec->decoration); } } @@ -1071,7 +1071,8 @@ translate_image_format(struct vtn_builder *b, SpvImageFormat format) case SpvImageFormatR16ui: return 0x8234; /* GL_R16UI */ case SpvImageFormatR8ui: return 0x8232; /* GL_R8UI */ default: - vtn_fail("Invalid image format"); + vtn_fail("Invalid image format: %s (%u)", + spirv_imageformat_to_string(format), format); } } @@ -1179,7 +1180,7 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode, val->type->type = (signedness ? glsl_int8_t_type() : glsl_uint8_t_type()); break; default: - vtn_fail("Invalid int bit size"); + vtn_fail("Invalid int bit size: %u", bit_size); } val->type->length = 1; break; @@ -1199,7 +1200,7 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode, val->type->type = glsl_double_type(); break; default: - vtn_fail("Invalid float bit size"); + vtn_fail("Invalid float bit size: %u", bit_size); } val->type->length = 1; break; @@ -1453,7 +1454,8 @@ 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: - vtn_fail("Invalid SPIR-V image dimensionality"); + vtn_fail("Invalid SPIR-V image dimensionality: %s (%u)", + spirv_dim_to_string((SpvDim)w[3]), w[3]); } /* w[4]: as per Vulkan spec "Validation Rules within a Module", @@ -1518,7 +1520,7 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode, case SpvOpTypeQueue: case SpvOpTypePipe: default: - vtn_fail("Unhandled opcode"); + vtn_fail_with_opcode("Unhandled opcode", opcode); } vtn_foreach_decoration(b, val, type_decoration_cb, NULL); @@ -1693,7 +1695,7 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode, val->constant->values[0][0].u8 = w[3]; break; default: - vtn_fail("Unsupported SpvOpConstant bit size"); + vtn_fail("Unsupported SpvOpConstant bit size: %u", bit_size); } break; } @@ -2008,7 +2010,7 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode, break; default: - vtn_fail("Unhandled opcode"); + vtn_fail_with_opcode("Unhandled opcode", opcode); } /* Now that we have the value, update the workgroup size if needed */ @@ -2162,7 +2164,7 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode, break; default: - vtn_fail("Unhandled opcode"); + vtn_fail_with_opcode("Unhandled opcode", opcode); } nir_tex_src srcs[10]; /* 10 should be enough */ @@ -2402,7 +2404,7 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode, case 32: instr->tg4_offsets[i][j] = cvec[j].i32; break; case 64: instr->tg4_offsets[i][j] = cvec[j].i64; break; default: - vtn_fail("Unsupported bit size"); + vtn_fail("Unsupported bit size: %u", bit_size); } } } @@ -2450,7 +2452,7 @@ fill_common_atomic_sources(struct vtn_builder *b, SpvOp opcode, break; default: - vtn_fail("Invalid SPIR-V atomic"); + vtn_fail_with_opcode("Invalid SPIR-V atomic", opcode); } } @@ -2554,7 +2556,7 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode, break; default: - vtn_fail("Invalid image opcode"); + vtn_fail_with_opcode("Invalid image opcode", opcode); } nir_intrinsic_op op; @@ -2580,7 +2582,7 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode, OP(AtomicXor, atomic_xor) #undef OP default: - vtn_fail("Invalid image opcode"); + vtn_fail_with_opcode("Invalid image opcode", opcode); } nir_intrinsic_instr *intrin = nir_intrinsic_instr_create(b->shader, op); @@ -2630,7 +2632,7 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode, break; default: - vtn_fail("Invalid image opcode"); + vtn_fail_with_opcode("Invalid image opcode", opcode); } if (opcode != SpvOpImageWrite && opcode != SpvOpAtomicStore) { @@ -2680,7 +2682,7 @@ get_ssbo_nir_atomic_op(struct vtn_builder *b, SpvOp opcode) OP(AtomicXor, atomic_xor) #undef OP default: - vtn_fail("Invalid SSBO atomic"); + vtn_fail_with_opcode("Invalid SSBO atomic", opcode); } } @@ -2735,7 +2737,7 @@ get_shared_nir_atomic_op(struct vtn_builder *b, SpvOp opcode) OP(AtomicXor, atomic_xor) #undef OP default: - vtn_fail("Invalid shared atomic"); + vtn_fail_with_opcode("Invalid shared atomic", opcode); } } @@ -2761,7 +2763,7 @@ get_deref_nir_atomic_op(struct vtn_builder *b, SpvOp opcode) OP(AtomicXor, atomic_xor) #undef OP default: - vtn_fail("Invalid shared atomic"); + vtn_fail_with_opcode("Invalid shared atomic", opcode); } } @@ -2799,7 +2801,7 @@ vtn_handle_atomics(struct vtn_builder *b, SpvOp opcode, break; default: - vtn_fail("Invalid SPIR-V atomic"); + vtn_fail_with_opcode("Invalid SPIR-V atomic", opcode); } /* @@ -2909,7 +2911,7 @@ vtn_handle_atomics(struct vtn_builder *b, SpvOp opcode, break; default: - vtn_fail("Invalid SPIR-V atomic"); + vtn_fail_with_opcode("Invalid SPIR-V atomic", opcode); } } else { nir_deref_instr *deref = vtn_pointer_to_deref(b, ptr); @@ -2947,7 +2949,7 @@ vtn_handle_atomics(struct vtn_builder *b, SpvOp opcode, break; default: - vtn_fail("Invalid SPIR-V atomic"); + vtn_fail_with_opcode("Invalid SPIR-V atomic", opcode); } } @@ -2976,7 +2978,7 @@ create_vec(struct vtn_builder *b, 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: vtn_fail("bad vector size"); + default: vtn_fail("bad vector size: %u", num_components); } nir_alu_instr *vec = nir_alu_instr_create(b->shader, op); @@ -3266,7 +3268,7 @@ vtn_handle_composite(struct vtn_builder *b, SpvOp opcode, break; default: - vtn_fail("unknown composite operation"); + vtn_fail_with_opcode("unknown composite operation", opcode); } } @@ -3423,7 +3425,8 @@ gl_primitive_from_spv_execution_mode(struct vtn_builder *b, case SpvExecutionModeOutputTriangleStrip: return 5; /* GL_TRIANGLE_STRIP */ default: - vtn_fail("Invalid primitive type"); + vtn_fail("Invalid primitive type: %s (%u)", + spirv_executionmode_to_string(mode), mode); } } @@ -3443,7 +3446,8 @@ vertices_in_from_spv_execution_mode(struct vtn_builder *b, case SpvExecutionModeInputTrianglesAdjacency: return 6; default: - vtn_fail("Invalid GS input mode"); + vtn_fail("Invalid GS input mode: %s (%u)", + spirv_executionmode_to_string(mode), mode); } } @@ -3466,14 +3470,15 @@ stage_for_execution_model(struct vtn_builder *b, SpvExecutionModel model) case SpvExecutionModelKernel: return MESA_SHADER_KERNEL; default: - vtn_fail("Unsupported execution model"); + vtn_fail("Unsupported execution model: %s (%u)", + spirv_executionmodel_to_string(model), model); } } -#define spv_check_supported(name, cap) do { \ - if (!(b->options && b->options->caps.name)) \ - vtn_warn("Unsupported SPIR-V capability: %s", \ - spirv_capability_to_string(cap)); \ +#define spv_check_supported(name, cap) do { \ + if (!(b->options && b->options->caps.name)) \ + vtn_warn("Unsupported SPIR-V capability: %s (%u)", \ + spirv_capability_to_string(cap), cap); \ } while(0) @@ -3735,7 +3740,8 @@ vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode, break; default: - vtn_fail("Unhandled capability"); + vtn_fail("Unhandled capability: %s (%u)", + spirv_capability_to_string(cap), cap); } break; } @@ -3776,7 +3782,8 @@ vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode, "AddressingModelPhysicalStorageBuffer64EXT not supported"); break; default: - vtn_fail("Unknown addressing model"); + vtn_fail("Unknown addressing model: %s (%u)", + spirv_addressingmodel_to_string(w[1]), w[1]); break; } @@ -3988,7 +3995,9 @@ vtn_handle_execution_mode(struct vtn_builder *b, struct vtn_value *entry_point, break; default: - vtn_fail("Unhandled execution mode"); + vtn_fail("Unhandled execution mode: %s (%u)", + spirv_executionmode_to_string(mode->exec_mode), + mode->exec_mode); } } @@ -4406,7 +4415,7 @@ vtn_handle_body_instruction(struct vtn_builder *b, SpvOp opcode, break; default: - vtn_fail("Unhandled opcode"); + vtn_fail_with_opcode("Unhandled opcode", opcode); } return true; diff --git a/src/compiler/spirv/vtn_alu.c b/src/compiler/spirv/vtn_alu.c index f93e336fb8b..0c0e87e0e6f 100644 --- a/src/compiler/spirv/vtn_alu.c +++ b/src/compiler/spirv/vtn_alu.c @@ -23,6 +23,7 @@ #include <math.h> #include "vtn_private.h" +#include "spirv_info.h" /* * Normally, column vectors in SPIR-V correspond to a single NIR SSA @@ -207,7 +208,7 @@ vtn_handle_matrix_alu(struct vtn_builder *b, SpvOp opcode, } break; - default: vtn_fail("unknown matrix opcode"); + default: vtn_fail_with_opcode("unknown matrix opcode", opcode); } } diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h index dd3c328b3a7..f21bb5bd10c 100644 --- a/src/compiler/spirv/vtn_private.h +++ b/src/compiler/spirv/vtn_private.h @@ -88,6 +88,12 @@ _vtn_fail(struct vtn_builder *b, const char *file, unsigned line, vtn_fail(__VA_ARGS__); \ } while (0) +#define _vtn_fail_with(t, msg, v) \ + vtn_fail("%s: %s (%u)\n", msg, spirv_ ## t ## _to_string(v), v) + +#define vtn_fail_with_decoration(msg, v) _vtn_fail_with(decoration, msg, v) +#define vtn_fail_with_opcode(msg, v) _vtn_fail_with(op, msg, v) + /** Assert that a condition is true and, if it isn't, vtn_fail * * This macro is transitional only and should not be used in new code. Use diff --git a/src/compiler/spirv/vtn_variables.c b/src/compiler/spirv/vtn_variables.c index 4cc152fb90d..ad6c3789573 100644 --- a/src/compiler/spirv/vtn_variables.c +++ b/src/compiler/spirv/vtn_variables.c @@ -1422,7 +1422,8 @@ vtn_get_builtin_location(struct vtn_builder *b, set_mode_system_value(b, mode); break; default: - vtn_fail("unsupported builtin: %u", builtin); + vtn_fail("Unsupported builtin: %s (%u)", + spirv_builtin_to_string(builtin), builtin); } } @@ -1564,7 +1565,7 @@ apply_var_decoration(struct vtn_builder *b, break; default: - vtn_fail("Unhandled decoration"); + vtn_fail_with_decoration("Unhandled decoration", dec->decoration); } } @@ -1779,7 +1780,8 @@ vtn_storage_class_to_mode(struct vtn_builder *b, break; case SpvStorageClassGeneric: default: - vtn_fail("Unhandled variable storage class"); + vtn_fail("Unhandled variable storage class: %s (%u)", + spirv_storageclass_to_string(class), class); } if (nir_mode_out) @@ -2354,7 +2356,8 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode, struct vtn_value *link_val = vtn_untyped_value(b, w[i]); if (link_val->value_type == vtn_value_type_constant) { chain->link[idx].mode = vtn_access_mode_literal; - switch (glsl_get_bit_size(link_val->type->type)) { + const unsigned bit_size = glsl_get_bit_size(link_val->type->type); + switch (bit_size) { case 8: chain->link[idx].id = link_val->constant->values[0][0].i8; break; @@ -2368,7 +2371,7 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode, chain->link[idx].id = link_val->constant->values[0][0].i64; break; default: - vtn_fail("Invalid bit size"); + vtn_fail("Invalid bit size: %u", bit_size); } } else { chain->link[idx].mode = vtn_access_mode_id; @@ -2570,6 +2573,6 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode, case SpvOpCopyMemorySized: default: - vtn_fail("Unhandled opcode"); + vtn_fail_with_opcode("Unhandled opcode", opcode); } } |