ir_function_signature *
builtin_builder::_bitfieldExtract(const glsl_type *type)
{
+ bool is_uint = type->base_type == GLSL_TYPE_UINT;
ir_variable *value = in_var(type, "value");
ir_variable *offset = in_var(glsl_type::int_type, "offset");
ir_variable *bits = in_var(glsl_type::int_type, "bits");
MAKE_SIG(type, gpu_shader5_or_es31, 3, value, offset, bits);
- body.emit(ret(expr(ir_triop_bitfield_extract, value, offset, bits)));
+ operand cast_offset = is_uint ? i2u(offset) : operand(offset);
+ operand cast_bits = is_uint ? i2u(bits) : operand(bits);
+
+ body.emit(ret(expr(ir_triop_bitfield_extract, value,
+ swizzle(cast_offset, SWIZZLE_XXXX, type->vector_elements),
+ swizzle(cast_bits, SWIZZLE_XXXX, type->vector_elements))));
return sig;
}
operation == ir_binop_dot ||
operation == ir_binop_vector_extract ||
operation == ir_triop_vector_insert ||
- operation == ir_quadop_vector ||
- /* TODO: these can't currently be vectorized */
- operation == ir_triop_bitfield_extract;
+ operation == ir_quadop_vector;
}
/**
break;
case ir_triop_bitfield_extract: {
- int offset = op[1]->value.i[0];
- int bits = op[2]->value.i[0];
-
for (unsigned c = 0; c < components; c++) {
+ int offset = op[1]->value.i[c];
+ int bits = op[2]->value.i[c];
+
if (bits == 0)
data.u[c] = 0;
else if (offset < 0 || bits < 0)
break;
case ir_triop_bitfield_extract:
+ assert(ir->type->is_integer());
assert(ir->operands[0]->type == ir->type);
- assert(ir->operands[1]->type == glsl_type::int_type);
- assert(ir->operands[2]->type == glsl_type::int_type);
+ assert(ir->operands[1]->type == ir->type);
+ assert(ir->operands[2]->type == ir->type);
break;
case ir_triop_vector_insert:
if (op_mask & LOWER_PACK_USE_BFE) {
/* u4.y = bitfield_extract(u, 8, 8); */
- factory.emit(assign(u4, bitfield_extract(u, constant(8), constant(8)),
+ factory.emit(assign(u4, bitfield_extract(u, constant(8u), constant(8u)),
WRITEMASK_Y));
/* u4.z = bitfield_extract(u, 16, 8); */
- factory.emit(assign(u4, bitfield_extract(u, constant(16), constant(8)),
+ factory.emit(assign(u4, bitfield_extract(u, constant(16u), constant(8u)),
WRITEMASK_Z));
} else {
/* u4.y = (u >> 8u) & 0xffu; */
""")
opcode("ubitfield_extract", 0, tuint,
- [0, 1, 1], [tuint, tint, tint], "", """
+ [0, 0, 0], [tuint, tint, tint], "", """
unsigned base = src0;
-int offset = src1.x, bits = src2.x;
+int offset = src1, bits = src2;
if (bits == 0) {
dst = 0;
} else if (bits < 0 || offset < 0 || offset + bits > 32) {
}
""")
opcode("ibitfield_extract", 0, tint,
- [0, 1, 1], [tint, tint, tint], "", """
+ [0, 0, 0], [tint, tint, tint], "", """
int base = src0;
-int offset = src1.x, bits = src2.x;
+int offset = src1, bits = src2;
if (bits == 0) {
dst = 0;
} else if (offset < 0 || bits < 0 || offset + bits > 32) {