[Mesa-dev] [PATCH 12/14] llvmpipe: Fix convert_to_blend_type on big-endian

Adam Jackson ajax at redhat.com
Tue Jun 18 10:28:13 PDT 2013


From: Richard Sandiford <r.sandiford at uk.ibm.com>

Reviewed-by: Adam Jackson <ajax at redhat.com>
Signed-off-by: Richard Sandiford <r.sandiford at uk.ibm.com>
---
 src/gallium/drivers/llvmpipe/lp_state_fs.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c
index fc2ba5e..38e9fc7 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_fs.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c
@@ -1015,12 +1015,17 @@ convert_to_blend_type(struct gallivm_state *gallivm,
    for (i = 0; i < num_srcs; ++i) {
       LLVMValueRef chans[4];
       LLVMValueRef res = NULL;
-      unsigned sa = 0;
 
       dst[i] = LLVMBuildZExt(builder, src[i], lp_build_vec_type(gallivm, src_type), "");
 
       for (j = 0; j < src_fmt->nr_channels; ++j) {
          unsigned mask = 0;
+         unsigned sa = src_fmt->channel[j].shift;
+#ifdef PIPE_ARCH_LITTLE_ENDIAN
+         unsigned from_lsb = j;
+#else
+         unsigned from_lsb = src_fmt->nr_channels - j - 1;
+#endif
 
          for (k = 0; k < src_fmt->channel[j].size; ++k) {
             mask |= 1 << k;
@@ -1046,11 +1051,9 @@ convert_to_blend_type(struct gallivm_state *gallivm,
          /* Insert bits into correct position */
          chans[j] = LLVMBuildShl(builder,
                                  chans[j],
-                                 lp_build_const_int_vec(gallivm, src_type, j * blend_type.width),
+                                 lp_build_const_int_vec(gallivm, src_type, from_lsb * blend_type.width),
                                  "");
 
-         sa += src_fmt->channel[j].size;
-
          if (j == 0) {
             res = chans[j];
          } else {
@@ -1166,12 +1169,17 @@ convert_from_blend_type(struct gallivm_state *gallivm,
    for (i = 0; i < num_srcs; ++i) {
       LLVMValueRef chans[4];
       LLVMValueRef res = NULL;
-      unsigned sa = 0;
 
       dst[i] = LLVMBuildBitCast(builder, src[i], lp_build_vec_type(gallivm, src_type), "");
 
       for (j = 0; j < src_fmt->nr_channels; ++j) {
          unsigned mask = 0;
+         unsigned sa = src_fmt->channel[j].shift;
+#ifdef PIPE_ARCH_LITTLE_ENDIAN
+         unsigned from_lsb = j;
+#else
+         unsigned from_lsb = src_fmt->nr_channels - j - 1;
+#endif
 
          assert(blend_type.width > src_fmt->channel[j].size);
 
@@ -1182,7 +1190,7 @@ convert_from_blend_type(struct gallivm_state *gallivm,
          /* Extract bits */
          chans[j] = LLVMBuildLShr(builder,
                                   dst[i],
-                                  lp_build_const_int_vec(gallivm, src_type, j * blend_type.width),
+                                  lp_build_const_int_vec(gallivm, src_type, from_lsb * blend_type.width),
                                   "");
 
          chans[j] = LLVMBuildAnd(builder,
-- 
1.8.2.1



More information about the mesa-dev mailing list