gallivm/rgtc: fix the truncation to 8-bit
authorDave Airlie <airlied@redhat.com>
Fri, 3 Apr 2020 03:54:17 +0000 (13:54 +1000)
committerDave Airlie <airlied@redhat.com>
Sat, 4 Apr 2020 02:33:49 +0000 (12:33 +1000)
The 8 bit type wasn't 8-bit so when doing signed work we lost
the sign bit. This fixes it to use a proper vector type,
even if we just end up in here with the 1-wide path for now.

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4425>

src/gallium/auxiliary/gallivm/lp_bld_format_s3tc.c

index d799a5d45a93d117cd2289d64cdbc645e7775b3e..174857e06d9860c483150ca797a8f1c3ea781cb9 100644 (file)
@@ -898,19 +898,23 @@ s3tc_dxt5_alpha_channel(struct gallivm_state *gallivm,
                         LLVMValueRef i, LLVMValueRef j)
 {
    LLVMBuilderRef builder = gallivm->builder;
-   struct lp_type type;
+   struct lp_type type, type8;
    LLVMValueRef tmp, alpha0, alpha1, alphac, alphac0, bit_pos, shift;
    LLVMValueRef sel_mask, tmp_mask, alpha, alpha64, code_s;
    LLVMValueRef mask6, mask7, ainterp;
    LLVMTypeRef i64t = LLVMInt64TypeInContext(gallivm->context);
    LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context);
-   LLVMTypeRef i8t = LLVMInt32TypeInContext(gallivm->context);
    struct lp_build_context bld32;
 
    memset(&type, 0, sizeof type);
    type.width = 32;
    type.length = n;
 
+   memset(&type8, 0, sizeof type8);
+   type8.width = 8;
+   type8.length = n;
+   type8.sign = is_signed;
+
    lp_build_context_init(&bld32, gallivm, type);
    /* this looks pretty complex for vectorization:
     * extract a0/a1 values
@@ -924,8 +928,8 @@ s3tc_dxt5_alpha_channel(struct gallivm_state *gallivm,
    alpha0 = LLVMBuildAnd(builder, alpha_lo,
                          lp_build_const_int_vec(gallivm, type, 0xff), "");
    if (is_signed) {
-      alpha0 = LLVMBuildTrunc(builder, alpha0, i8t, "");
-      alpha0 = LLVMBuildSExt(builder, alpha0, i32t, "");
+      alpha0 = LLVMBuildTrunc(builder, alpha0, lp_build_vec_type(gallivm, type8), "");
+      alpha0 = LLVMBuildSExt(builder, alpha0, lp_build_vec_type(gallivm, type), "");
    }
 
    alpha1 = LLVMBuildLShr(builder, alpha_lo,
@@ -933,8 +937,8 @@ s3tc_dxt5_alpha_channel(struct gallivm_state *gallivm,
    alpha1 = LLVMBuildAnd(builder, alpha1,
                          lp_build_const_int_vec(gallivm, type, 0xff), "");
    if (is_signed) {
-      alpha1 = LLVMBuildTrunc(builder, alpha1, i8t, "");
-      alpha1 = LLVMBuildSExt(builder, alpha1, i32t, "");
+      alpha1 = LLVMBuildTrunc(builder, alpha1, lp_build_vec_type(gallivm, type8), "");
+      alpha1 = LLVMBuildSExt(builder, alpha1, lp_build_vec_type(gallivm, type), "");
    }
 
    /* pos = 3*(4j+i) */