[Mesa-dev] [PATCH] llvmpipe: Fix rendering into PIPE_FORMAT_X8B8G8R8_UNORM.

jfonseca at vmware.com jfonseca at vmware.com
Thu Feb 21 14:34:46 PST 2013


From: José Fonseca <jose.r.fonseca at gmail.com>

Weird format, which Mesa state tracker recently started using.

Fixes segfault in

  ./bin/texture-packed-formats -auto

because swizzle[foo] was 0xff for padding channel (X). It still fails though.

I believe the only reason this doesn't BGRX doesn't crash is that we have
special code for when X in in the last channel.
---
 src/gallium/drivers/llvmpipe/lp_state_fs.c |   16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c
index 44a9fcb..9bf9b9c 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_fs.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c
@@ -1493,7 +1493,7 @@ generate_unswizzled_blend(struct gallivm_state *gallivm,
    vector_width    = dst_type.floating ? lp_native_vector_width : lp_integer_vector_width;
 
    /* Compute correct swizzle and count channels */
-   memset(swizzle, 0xFF, TGSI_NUM_CHANNELS);
+   memset(swizzle, LP_BLD_SWIZZLE_DONTCARE, TGSI_NUM_CHANNELS);
    dst_channels = 0;
 
    for (i = 0; i < TGSI_NUM_CHANNELS; ++i) {
@@ -1538,7 +1538,12 @@ generate_unswizzled_blend(struct gallivm_state *gallivm,
 
       /* Load each channel */
       for (j = 0; j < dst_channels; ++j) {
-         fs_src[i][j] = LLVMBuildLoad(builder, fs_out_color[rt][swizzle[j]][i], "");
+         unsigned src_channel = swizzle[j];
+         if (src_channel < 4) {
+            fs_src[i][j] = LLVMBuildLoad(builder, fs_out_color[rt][src_channel][i], "");
+         } else {
+            fs_src[i][j] = lp_build_undef(gallivm, fs_type);
+         }
       }
 
       /* If 3 channels then pad to include alpha for 4 element transpose */
@@ -1568,7 +1573,12 @@ generate_unswizzled_blend(struct gallivm_state *gallivm,
          LLVMValueRef alpha = LLVMBuildLoad(builder, fs_out_color[1][alpha_channel][i], "");
 
          for (j = 0; j < dst_channels; ++j) {
-            fs_src1[i][j] = LLVMBuildLoad(builder, fs_out_color[1][swizzle[j]][i], "");
+            unsigned src_channel = swizzle[j];
+            if (src_channel < 4) {
+               fs_src1[i][j] = LLVMBuildLoad(builder, fs_out_color[1][src_channel][i], "");
+            } else {
+               fs_src1[i][j] = lp_build_undef(gallivm, fs_type);
+            }
          }
          if (dst_channels == 3 && !has_alpha) {
             fs_src1[i][3] = alpha;
-- 
1.7.10.4



More information about the mesa-dev mailing list