gallivm/llvmpipe: simplify front/back stencil ref value handling
authorBrian Paul <brianp@vmware.com>
Thu, 18 Mar 2010 17:31:38 +0000 (11:31 -0600)
committerBrian Paul <brianp@vmware.com>
Thu, 18 Mar 2010 17:31:38 +0000 (11:31 -0600)
Instead of passing an array, just pass two scalar values.

src/gallium/auxiliary/gallivm/lp_bld_depth.c
src/gallium/auxiliary/gallivm/lp_bld_depth.h
src/gallium/drivers/llvmpipe/lp_jit.c
src/gallium/drivers/llvmpipe/lp_jit.h
src/gallium/drivers/llvmpipe/lp_setup.c
src/gallium/drivers/llvmpipe/lp_state_fs.c

index 49de5c94a3c8c656dc8958588522f21813c9e509..c253764e603655c7a185f31462d9573558457d4a 100644 (file)
@@ -363,32 +363,6 @@ lp_depth_type(const struct util_format_description *format_desc,
 }
 
 
-/** Get front/back-face stencil ref value */
-static LLVMValueRef
-lp_build_get_stencil_ref(struct lp_build_context *bld,
-                         struct lp_type type, LLVMValueRef stencil_refs_ptr,
-                         unsigned face_index)
-{
-   LLVMValueRef indexes[2], ptr, ref, ref_vec;
-
-   assert(face_index < 2);
-
-   /* load [face_index] element of the array */
-   indexes[0] = LLVMConstInt(LLVMInt32Type(), 0, 0);
-   indexes[1] = LLVMConstInt(LLVMInt32Type(), face_index, 0);
-   ptr = LLVMBuildGEP(bld->builder, stencil_refs_ptr, indexes, 2, "");
-   ref = LLVMBuildLoad(bld->builder, ptr, "");
-
-   /* convert int8 value to i32 */
-   ref = LLVMBuildZExt(bld->builder, ref, LLVMIntType(type.width), "");
-
-   /* make scalar into vector */
-   ref_vec = lp_build_broadcast_scalar(bld, ref);
-
-   return ref_vec;
-}
-
-
 /**
  * Generate code for performing depth and/or stencil tests.
  * We operate on a vector of values (typically a 2x2 quad).
@@ -406,13 +380,12 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder,
                             struct lp_type type,
                             const struct util_format_description *format_desc,
                             struct lp_build_mask_context *mask,
-                            LLVMValueRef stencil_refs_ptr,
+                            LLVMValueRef stencil_refs[2],
                             LLVMValueRef z_src,
                             LLVMValueRef zs_dst_ptr)
 {
    struct lp_build_context bld;
    unsigned z_swizzle, s_swizzle;
-   LLVMValueRef stencil_refs[2];
    LLVMValueRef zs_dst, z_dst = NULL;
    LLVMValueRef stencil_vals = NULL;
    LLVMValueRef z_bitmask = NULL, s_bitmask = NULL;
@@ -502,19 +475,17 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder,
 
    lp_build_name(z_dst, "zsbuf.z");
 
-
+   /*
    printf("build depth %d stencil %d\n",
           depth->enabled,
           stencil[0].enabled);
-
+   */
 
    if (stencil[0].enabled) {
-      /* Incoming stencil_refs is ptr to int8[2].  Get/convert to int32[4]. */
-      stencil_refs[0] = lp_build_get_stencil_ref(&bld, type, stencil_refs_ptr, 0);
+      /* convert scalar stencil refs into vectors */
+      stencil_refs[0] = lp_build_broadcast_scalar(&bld, stencil_refs[0]);
+      stencil_refs[1] = lp_build_broadcast_scalar(&bld, stencil_refs[1]);
 
-      if (stencil[1].enabled)
-         stencil_refs[1] =
-            lp_build_get_stencil_ref(&bld, type, stencil_refs_ptr, 1);
 
       s_pass_mask = lp_build_stencil_test(&bld, stencil,
                                           stencil_refs, stencil_vals, face);
index eedc1e419b5c49e2287240a8e6c120137a199b29..5708ced9839cb5e7b908bc8b699be3796509106b 100644 (file)
@@ -57,7 +57,7 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder,
                             struct lp_type type,
                             const struct util_format_description *format_desc,
                             struct lp_build_mask_context *mask,
-                            LLVMValueRef stencil_refs,
+                            LLVMValueRef stencil_refs[2],
                             LLVMValueRef zs_src,
                             LLVMValueRef zs_dst_ptr);
 
index 1eee9212e6fd4e5648dab89a347ade47488006f3..927e472ff26a20240147b31301dc084027245a9a 100644 (file)
@@ -96,7 +96,8 @@ lp_jit_init_globals(struct llvmpipe_screen *screen)
 
       elem_types[LP_JIT_CTX_CONSTANTS] = LLVMPointerType(LLVMFloatType(), 0);
       elem_types[LP_JIT_CTX_ALPHA_REF] = LLVMFloatType();
-      elem_types[LP_JIT_CTX_STENCIL_REF] = LLVMArrayType(LLVMInt8Type(), 2);
+      elem_types[LP_JIT_CTX_STENCIL_REF_FRONT] = LLVMInt32Type();
+      elem_types[LP_JIT_CTX_STENCIL_REF_BACK] = LLVMInt32Type();
       elem_types[LP_JIT_CTX_SCISSOR_XMIN] = LLVMFloatType();
       elem_types[LP_JIT_CTX_SCISSOR_YMIN] = LLVMFloatType();
       elem_types[LP_JIT_CTX_SCISSOR_XMAX] = LLVMFloatType();
@@ -113,9 +114,12 @@ lp_jit_init_globals(struct llvmpipe_screen *screen)
       LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, alpha_ref_value,
                              screen->target, context_type,
                              LP_JIT_CTX_ALPHA_REF);
-      LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, stencil_ref,
+      LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, stencil_ref_front,
                              screen->target, context_type,
-                             LP_JIT_CTX_STENCIL_REF);
+                             LP_JIT_CTX_STENCIL_REF_FRONT);
+      LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, stencil_ref_back,
+                             screen->target, context_type,
+                             LP_JIT_CTX_STENCIL_REF_BACK);
       LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, scissor_xmin,
                              screen->target, context_type,
                              LP_JIT_CTX_SCISSOR_XMIN);
index 63e05c5d5e18af193843d186e19f409d49587973..bbd0c9610de52ce4e8a358fee09d5db7a91593d8 100644 (file)
@@ -84,7 +84,7 @@ struct lp_jit_context
 
    float alpha_ref_value;
 
-   uint8_t stencil_ref[2];
+   uint32_t stencil_ref_front, stencil_ref_back;
 
    /** floats, not ints */
    float scissor_xmin, scissor_ymin, scissor_xmax, scissor_ymax;
@@ -103,7 +103,8 @@ struct lp_jit_context
 enum {
    LP_JIT_CTX_CONSTANTS = 0,
    LP_JIT_CTX_ALPHA_REF,
-   LP_JIT_CTX_STENCIL_REF,
+   LP_JIT_CTX_STENCIL_REF_FRONT,
+   LP_JIT_CTX_STENCIL_REF_BACK,
    LP_JIT_CTX_SCISSOR_XMIN,
    LP_JIT_CTX_SCISSOR_YMIN,
    LP_JIT_CTX_SCISSOR_XMAX,
@@ -120,8 +121,11 @@ enum {
 #define lp_jit_context_alpha_ref_value(_builder, _ptr) \
    lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_ALPHA_REF, "alpha_ref_value")
 
-#define lp_jit_context_stencil_ref_values(_builder, _ptr) \
-   lp_build_struct_get_ptr(_builder, _ptr, LP_JIT_CTX_STENCIL_REF, "stencil_ref")
+#define lp_jit_context_stencil_ref_front_value(_builder, _ptr) \
+   lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_STENCIL_REF_FRONT, "stencil_ref_front")
+
+#define lp_jit_context_stencil_ref_back_value(_builder, _ptr) \
+   lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_STENCIL_REF_BACK, "stencil_ref_back")
 
 #define lp_jit_context_scissor_xmin_value(_builder, _ptr) \
    lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_SCISSOR_XMIN, "scissor_xmin")
index bcc9d1fc1a47e3bd398e446380126633c46a121f..fbb0d6f8a602de37ae6bcd03c3a0e1ac98a3ba90 100644 (file)
@@ -407,10 +407,10 @@ lp_setup_set_stencil_ref_values( struct lp_setup_context *setup,
 {
    LP_DBG(DEBUG_SETUP, "%s %d %d\n", __FUNCTION__, refs[0], refs[1]);
 
-   if (setup->fs.current.jit_context.stencil_ref[0] != refs[0] ||
-       setup->fs.current.jit_context.stencil_ref[1] != refs[1]) {
-      setup->fs.current.jit_context.stencil_ref[0] = refs[0];
-      setup->fs.current.jit_context.stencil_ref[1] = refs[1];
+   if (setup->fs.current.jit_context.stencil_ref_front != refs[0] ||
+       setup->fs.current.jit_context.stencil_ref_back != refs[1]) {
+      setup->fs.current.jit_context.stencil_ref_front = refs[0];
+      setup->fs.current.jit_context.stencil_ref_back = refs[1];
       setup->dirty |= LP_SETUP_NEW_FS;
    }
 }
index 921c51fbe84db0cde1c73f361d5de0adafc08587..0f96654a6735061b61fb7f5c730f59a805d32264 100644 (file)
@@ -145,7 +145,7 @@ generate_depth_stencil(LLVMBuilderRef builder,
                        const struct lp_fragment_shader_variant_key *key,
                        struct lp_type src_type,
                        struct lp_build_mask_context *mask,
-                       LLVMValueRef stencil_refs,
+                       LLVMValueRef stencil_refs[2],
                        LLVMValueRef src,
                        LLVMValueRef dst_ptr)
 {
@@ -408,7 +408,7 @@ generate_fs(struct llvmpipe_context *lp,
    LLVMValueRef consts_ptr;
    LLVMValueRef outputs[PIPE_MAX_SHADER_OUTPUTS][NUM_CHANNELS];
    LLVMValueRef z = interp->pos[2];
-   LLVMValueRef stencil_refs;
+   LLVMValueRef stencil_refs[2];
    struct lp_build_flow_context *flow;
    struct lp_build_mask_context mask;
    boolean early_depth_stencil_test;
@@ -418,7 +418,8 @@ generate_fs(struct llvmpipe_context *lp,
 
    assert(i < 4);
 
-   stencil_refs = lp_jit_context_stencil_ref_values(builder, context_ptr);
+   stencil_refs[0] = lp_jit_context_stencil_ref_front_value(builder, context_ptr);
+   stencil_refs[1] = lp_jit_context_stencil_ref_back_value(builder, context_ptr);
 
    elem_type = lp_build_elem_type(type);
    vec_type = lp_build_vec_type(type);