}
default:
- unreachable("bad constant type");
+ vtn_fail("bad constant type");
}
return val;
return ssa;
default:
- unreachable("Invalid type for an SSA value");
+ vtn_fail("Invalid type for an SSA value");
}
}
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;
}
}
default:
- unreachable("Unhandled opcode");
+ vtn_fail("Unhandled opcode");
}
}
dec->scope = VTN_DEC_EXECUTION_MODE;
break;
default:
- unreachable("Invalid decoration opcode");
+ vtn_fail("Invalid decoration opcode");
}
dec->decoration = *(w++);
dec->literals = w;
}
default:
- unreachable("Unhandled opcode");
+ vtn_fail("Unhandled opcode");
}
}
break;
default:
- unreachable("Unhandled decoration");
+ vtn_fail("Unhandled decoration");
}
}
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 */
case SpvImageFormatR16ui: return 0x8234; /* GL_R16UI */
case SpvImageFormatR8ui: return 0x8232; /* GL_R8UI */
default:
- unreachable("Invalid image format");
- return 0;
+ vtn_fail("Invalid image format");
}
}
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];
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;
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;
}
case SpvOpTypeQueue:
case SpvOpTypePipe:
default:
- unreachable("Unhandled opcode");
+ vtn_fail("Unhandled opcode");
}
vtn_foreach_decoration(b, val, type_decoration_cb, NULL);
break;
default:
- unreachable("Invalid type for null constant");
+ vtn_fail("Invalid type for null constant");
}
return c;
break;
default:
- unreachable("Unsupported type for constants");
+ vtn_fail("Unsupported type for constants");
}
break;
}
continue;
default:
- unreachable("Invalid constant type");
+ vtn_fail("Invalid constant type");
}
}
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 =
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 */
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);
break;
default:
- unreachable("Unhandled opcode");
+ vtn_fail("Unhandled opcode");
}
nir_tex_src srcs[8]; /* 8 should be enough */
coord_components = 3;
break;
default:
- unreachable("Invalid sampler type");
+ vtn_fail("Invalid sampler type");
}
if (is_array && texop != nir_texop_lod)
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);
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,
break;
default:
- unreachable("Invalid SPIR-V atomic");
+ vtn_fail("Invalid SPIR-V atomic");
}
}
break;
default:
- unreachable("Invalid image opcode");
+ vtn_fail("Invalid image opcode");
}
nir_intrinsic_op op;
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);
break;
default:
- unreachable("Invalid image opcode");
+ vtn_fail("Invalid image opcode");
}
if (opcode != SpvOpImageWrite) {
}
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;
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;
OP(AtomicXor, atomic_xor)
#undef OP
default:
- unreachable("Invalid shared atomic");
+ vtn_fail("Invalid shared atomic");
}
}
break;
default:
- unreachable("Invalid SPIR-V atomic");
+ vtn_fail("Invalid SPIR-V atomic");
}
/*
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);
break;
default:
- unreachable("Invalid SPIR-V atomic");
+ vtn_fail("Invalid SPIR-V atomic");
}
} else {
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);
break;
default:
- unreachable("Invalid SPIR-V atomic");
+ vtn_fail("Invalid SPIR-V atomic");
}
}
}
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) {
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;
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;
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++) {
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];
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:
*
break;
default:
- unreachable("unknown composite operation");
+ vtn_fail("unknown composite operation");
}
}
intrinsic_op = nir_intrinsic_barrier;
break;
default:
- unreachable("unknown barrier instruction");
+ vtn_fail("unknown barrier instruction");
}
nir_intrinsic_instr *intrin =
}
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:
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:
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:
case SpvExecutionModelGLCompute:
return MESA_SHADER_COMPUTE;
default:
- unreachable("Unsupported execution model");
+ vtn_fail("Unsupported execution model");
}
}
break;
default:
- unreachable("Unhandled capability");
+ vtn_fail("Unhandled capability");
}
break;
}
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);
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;
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:
break;
case SpvExecutionModeXfb:
- unreachable("Unhandled execution mode");
+ vtn_fail("Unhandled execution mode");
break;
case SpvExecutionModeVecTypeHint:
break; /* OpenCL */
default:
- unreachable("Unhandled execution mode");
+ vtn_fail("Unhandled execution mode");
}
}
case SpvOpMemberDecorate:
case SpvOpGroupDecorate:
case SpvOpGroupMemberDecorate:
- unreachable("Invalid opcode types and variables section");
+ vtn_fail("Invalid opcode types and variables section");
break;
case SpvOpTypeVoid:
break;
default:
- unreachable("Unhandled opcode");
+ vtn_fail("Unhandled opcode");
}
return true;
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;
}
}
break;
- default: unreachable("unknown matrix opcode");
+ default: vtn_fail("unknown matrix opcode");
}
}
}
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
case SpvOpDPdyCoarse: return nir_op_fddy_coarse;
default:
- unreachable("No NIR equivalent");
+ vtn_fail("No NIR equivalent");
}
}
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),
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),
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];
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];
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];
}
default:
- unreachable("Invalid type for deref");
+ vtn_fail("Invalid type for deref");
}
}
break;
}
default:
- unreachable("Invalid type for deref");
+ vtn_fail("Invalid type for deref");
}
}
}
default:
- unreachable("Invalid type for deref");
+ vtn_fail("Invalid type for deref");
}
}
return type->stride * glsl_get_length(type->type);
default:
- unreachable("Invalid block type");
+ vtn_fail("Invalid block type");
return 0;
}
}
}
default:
- unreachable("Invalid block member type");
+ vtn_fail("Invalid block member type");
}
}
&access_offset, &access_size);
break;
default:
- unreachable("Invalid block variable mode");
+ vtn_fail("Invalid block variable mode");
}
nir_ssa_def *offset, *index = NULL;
}
default:
- unreachable("Invalid access chain type");
+ vtn_fail("Invalid access chain type");
}
}
}
default:
- unreachable("Invalid access chain type");
+ vtn_fail("Invalid access chain type");
}
}
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;
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;
break;
case SpvBuiltInWorkgroupSize:
/* This should already be handled */
- unreachable("unsupported builtin");
+ vtn_fail("unsupported builtin");
break;
case SpvBuiltInWorkgroupId:
*location = SYSTEM_VALUE_WORK_GROUP_ID;
set_mode_system_value(b, mode);
break;
default:
- unreachable("unsupported builtin");
+ vtn_fail("unsupported builtin");
}
}
break;
case SpvDecorationLocation:
- unreachable("Handled above");
+ vtn_fail("Handled above");
case SpvDecorationBlock:
case SpvDecorationBufferBlock:
break;
default:
- unreachable("Unhandled decoration");
+ vtn_fail("Unhandled decoration");
}
}
}
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)
{
mode = vtn_variable_mode_ssbo;
nir_mode = 0;
} else {
- unreachable("Invalid uniform variable type");
+ vtn_fail("Invalid uniform variable type");
}
break;
case SpvStorageClassStorageBuffer:
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:
case SpvStorageClassGeneric:
case SpvStorageClassAtomicCounter:
default:
- unreachable("Unhandled variable storage class");
+ vtn_fail("Unhandled variable storage class");
}
if (nir_mode_out)
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;
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:
}
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:
case SpvOpCopyMemorySized:
default:
- unreachable("Unhandled opcode");
+ vtn_fail("Unhandled opcode");
}
}