diff options
Diffstat (limited to 'src/compiler/spirv')
-rw-r--r-- | src/compiler/spirv/spirv_to_nir.c | 139 | ||||
-rw-r--r-- | src/compiler/spirv/vtn_alu.c | 20 | ||||
-rw-r--r-- | src/compiler/spirv/vtn_cfg.c | 8 | ||||
-rw-r--r-- | src/compiler/spirv/vtn_glsl450.c | 14 | ||||
-rw-r--r-- | src/compiler/spirv/vtn_private.h | 3 | ||||
-rw-r--r-- | src/compiler/spirv/vtn_variables.c | 45 |
6 files changed, 118 insertions, 111 deletions
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index 297db87d575..33692dc2ca6 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -239,7 +239,7 @@ vtn_const_ssa_value(struct vtn_builder *b, nir_constant *constant, } default: - unreachable("bad constant type"); + vtn_fail("bad constant type"); } return val; @@ -267,7 +267,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"); } } @@ -344,7 +344,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 { - unreachable("Unsupported extension"); + vtn_fail("Unsupported extension"); } break; } @@ -357,7 +357,7 @@ vtn_handle_extension(struct vtn_builder *b, SpvOp opcode, } default: - unreachable("Unhandled opcode"); + vtn_fail("Unhandled opcode"); } } @@ -446,7 +446,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; @@ -481,7 +481,7 @@ vtn_handle_decoration(struct vtn_builder *b, SpvOp opcode, } default: - unreachable("Unhandled opcode"); + vtn_fail("Unhandled opcode"); } } @@ -645,7 +645,7 @@ struct_member_decoration_cb(struct vtn_builder *b, break; default: - unreachable("Unhandled decoration"); + vtn_fail("Unhandled decoration"); } } @@ -756,12 +756,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 */ @@ -805,8 +805,7 @@ translate_image_format(SpvImageFormat format) case SpvImageFormatR16ui: return 0x8234; /* GL_R16UI */ case SpvImageFormatR8ui: return 0x8232; /* GL_R8UI */ default: - unreachable("Invalid image format"); - return 0; + vtn_fail("Invalid image format"); } } @@ -980,7 +979,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]; @@ -1000,10 +999,10 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode, else if (dim == GLSL_SAMPLER_DIM_SUBPASS) dim = GLSL_SAMPLER_DIM_SUBPASS_MS; else - unreachable("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; @@ -1015,7 +1014,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 { - unreachable("We need to know if the image will be sampled"); + vtn_fail("We need to know if the image will be sampled"); } break; } @@ -1041,7 +1040,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); @@ -1089,7 +1088,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; @@ -1250,7 +1249,7 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode, break; default: - unreachable("Unsupported type for constants"); + vtn_fail("Unsupported type for constants"); } break; } @@ -1386,7 +1385,7 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode, continue; default: - unreachable("Invalid constant type"); + vtn_fail("Invalid constant type"); } } @@ -1429,7 +1428,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 = @@ -1459,11 +1460,11 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode, break; case SpvOpConstantSampler: - unreachable("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 */ @@ -1547,7 +1548,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); @@ -1660,7 +1661,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 */ @@ -1699,7 +1700,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) @@ -1820,7 +1821,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); @@ -1854,7 +1855,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, @@ -1960,7 +1961,7 @@ fill_common_atomic_sources(struct vtn_builder *b, SpvOp opcode, break; default: - unreachable("Invalid SPIR-V atomic"); + vtn_fail("Invalid SPIR-V atomic"); } } @@ -2052,7 +2053,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; @@ -2078,7 +2079,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); @@ -2128,7 +2129,7 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode, break; default: - unreachable("Invalid image opcode"); + vtn_fail("Invalid image opcode"); } if (opcode != SpvOpImageWrite) { @@ -2155,7 +2156,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; @@ -2176,12 +2177,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; @@ -2202,7 +2203,7 @@ get_shared_nir_atomic_op(SpvOp opcode) OP(AtomicXor, atomic_xor) #undef OP default: - unreachable("Invalid shared atomic"); + vtn_fail("Invalid shared atomic"); } } @@ -2237,7 +2238,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"); } /* @@ -2248,7 +2249,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); @@ -2281,7 +2282,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 { @@ -2289,7 +2290,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); @@ -2328,7 +2329,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"); } } @@ -2349,7 +2350,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) { @@ -2357,10 +2358,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; @@ -2378,9 +2379,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; @@ -2410,7 +2410,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++) { @@ -2456,7 +2456,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]; @@ -2484,8 +2484,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: * @@ -2648,7 +2647,7 @@ vtn_handle_composite(struct vtn_builder *b, SpvOp opcode, break; default: - unreachable("unknown composite operation"); + vtn_fail("unknown composite operation"); } } @@ -2673,7 +2672,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 = @@ -2686,7 +2685,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: @@ -2709,13 +2709,13 @@ gl_primitive_from_spv_execution_mode(SpvExecutionMode mode) case SpvExecutionModeOutputTriangleStrip: return 5; /* GL_TRIANGLE_STRIP */ default: - unreachable("Invalid primitive type"); - return 4; + vtn_fail("Invalid primitive type"); } } 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: @@ -2729,13 +2729,12 @@ vertices_in_from_spv_execution_mode(SpvExecutionMode mode) case SpvExecutionModeInputTrianglesAdjacency: return 6; default: - unreachable("Invalid GS input mode"); - return 0; + vtn_fail("Invalid GS input mode"); } } static gl_shader_stage -stage_for_execution_model(SpvExecutionModel model) +stage_for_execution_model(struct vtn_builder *b, SpvExecutionModel model) { switch (model) { case SpvExecutionModelVertex: @@ -2751,7 +2750,7 @@ stage_for_execution_model(SpvExecutionModel model) case SpvExecutionModelGLCompute: return MESA_SHADER_COMPUTE; default: - unreachable("Unsupported execution model"); + vtn_fail("Unsupported execution model"); } } @@ -2893,7 +2892,7 @@ vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode, break; default: - unreachable("Unhandled capability"); + vtn_fail("Unhandled capability"); } break; } @@ -2915,7 +2914,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); @@ -3021,11 +3020,11 @@ vtn_handle_execution_mode(struct vtn_builder *b, struct vtn_value *entry_point, if (b->shader->info.stage == MESA_SHADER_TESS_CTRL || b->shader->info.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->info.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; @@ -3034,7 +3033,7 @@ vtn_handle_execution_mode(struct vtn_builder *b, struct vtn_value *entry_point, case SpvExecutionModeOutputTriangleStrip: vtn_assert(b->shader->info.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: @@ -3073,7 +3072,7 @@ vtn_handle_execution_mode(struct vtn_builder *b, struct vtn_value *entry_point, break; case SpvExecutionModeXfb: - unreachable("Unhandled execution mode"); + vtn_fail("Unhandled execution mode"); break; case SpvExecutionModeVecTypeHint: @@ -3081,7 +3080,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"); } } @@ -3107,7 +3106,7 @@ vtn_handle_variable_or_type_instruction(struct vtn_builder *b, SpvOp opcode, case SpvOpMemberDecorate: case SpvOpGroupDecorate: case SpvOpGroupMemberDecorate: - unreachable("Invalid opcode types and variables section"); + vtn_fail("Invalid opcode types and variables section"); break; case SpvOpTypeVoid: @@ -3407,7 +3406,7 @@ vtn_handle_body_instruction(struct vtn_builder *b, SpvOp opcode, break; default: - unreachable("Unhandled opcode"); + vtn_fail("Unhandled opcode"); } return true; @@ -3458,7 +3457,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 5fa695bea19..7653b8acfa1 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 a8dff09b7f6..25140ffc7dd 100644 --- a/src/compiler/spirv/vtn_cfg.c +++ b/src/compiler/spirv/vtn_cfg.c @@ -405,7 +405,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: { @@ -475,7 +475,7 @@ vtn_cfg_walk_blocks(struct vtn_builder *b, struct list_head *cf_list, return; default: - unreachable("Unhandled opcode"); + vtn_fail("Unhandled opcode"); } } } @@ -577,7 +577,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"); } } @@ -758,7 +758,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 051e03482e9..46ef40f5e3f 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 d07f6a2beb2..8efa9193015 100644 --- a/src/compiler/spirv/vtn_private.h +++ b/src/compiler/spirv/vtn_private.h @@ -683,7 +683,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 3190b21f0c7..c0db46d55a0 100644 --- a/src/compiler/spirv/vtn_variables.c +++ b/src/compiler/spirv/vtn_variables.c @@ -209,7 +209,7 @@ vtn_ssa_offset_pointer_dereference(struct vtn_builder *b, } default: - unreachable("Invalid type for deref"); + vtn_fail("Invalid type for deref"); } } @@ -344,7 +344,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"); } } @@ -547,7 +547,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"); } } @@ -605,7 +605,7 @@ vtn_type_block_size(struct vtn_builder *b, struct vtn_type *type) return type->stride * glsl_get_length(type->type); default: - unreachable("Invalid block type"); + vtn_fail("Invalid block type"); return 0; } } @@ -810,7 +810,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"); } } @@ -832,7 +832,7 @@ vtn_block_load(struct vtn_builder *b, struct vtn_pointer *src) &access_offset, &access_size); break; default: - unreachable("Invalid block variable mode"); + vtn_fail("Invalid block variable mode"); } nir_ssa_def *offset, *index = NULL; @@ -918,7 +918,7 @@ _vtn_variable_load_store(struct vtn_builder *b, bool load, } default: - unreachable("Invalid access chain type"); + vtn_fail("Invalid access chain type"); } } @@ -991,7 +991,7 @@ _vtn_variable_copy(struct vtn_builder *b, struct vtn_pointer *dest, } default: - unreachable("Invalid access chain type"); + vtn_fail("Invalid access chain type"); } } @@ -1071,7 +1071,7 @@ vtn_get_builtin_location(struct vtn_builder *b, else if (b->shader->info.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; @@ -1080,7 +1080,7 @@ vtn_get_builtin_location(struct vtn_builder *b, else if (b->shader->info.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; @@ -1138,7 +1138,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; @@ -1173,7 +1173,7 @@ vtn_get_builtin_location(struct vtn_builder *b, set_mode_system_value(b, mode); break; default: - unreachable("unsupported builtin"); + vtn_fail("unsupported builtin"); } } @@ -1271,7 +1271,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: @@ -1305,7 +1305,7 @@ apply_var_decoration(struct vtn_builder *b, nir_variable *nir_var, break; default: - unreachable("Unhandled decoration"); + vtn_fail("Unhandled decoration"); } } @@ -1417,7 +1417,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) { @@ -1432,7 +1433,7 @@ vtn_storage_class_to_mode(SpvStorageClass class, mode = vtn_variable_mode_ssbo; nir_mode = 0; } else { - unreachable("Invalid uniform variable type"); + vtn_fail("Invalid uniform variable type"); } break; case SpvStorageClassStorageBuffer: @@ -1447,7 +1448,7 @@ vtn_storage_class_to_mode(SpvStorageClass class, mode = vtn_variable_mode_sampler; nir_mode = nir_var_uniform; } else { - unreachable("Invalid uniform constant variable type"); + vtn_fail("Invalid uniform constant variable type"); } break; case SpvStorageClassPushConstant: @@ -1478,7 +1479,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) @@ -1524,7 +1525,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; @@ -1566,7 +1567,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: @@ -1702,7 +1703,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: @@ -1901,6 +1902,6 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode, case SpvOpCopyMemorySized: default: - unreachable("Unhandled opcode"); + vtn_fail("Unhandled opcode"); } } |