ac/cull: don't read Position.Z if it's not needed for culling
[mesa.git] / src / amd / llvm / ac_llvm_cull.c
index 1c2da3e041849ea4ad6838e68992bc5954b6e655..c76d4e1f9373f37a4389a23c61a6d2bd109f23ec 100644 (file)
@@ -136,7 +136,7 @@ static LLVMValueRef cull_bbox(struct ac_llvm_context *ctx,
        LLVMBuilderRef builder = ctx->builder;
 
        if (!cull_view_xy && !cull_view_near_z && !cull_view_far_z && !cull_small_prims)
-               return ctx->i1true;
+               return initially_accepted;
 
        /* Skip the culling if the primitive has already been rejected or
         * if any W is negative. The bounding box culling doesn't work when
@@ -153,7 +153,7 @@ static LLVMValueRef cull_bbox(struct ac_llvm_context *ctx,
                LLVMValueRef accepted = initially_accepted;
 
                /* Compute the primitive bounding box for easy culling. */
-               for (unsigned chan = 0; chan < 3; chan++) {
+               for (unsigned chan = 0; chan < (cull_view_near_z || cull_view_far_z ? 3 : 2); chan++) {
                        bbox_min[chan] = ac_build_fmin(ctx, pos[0][chan], pos[1][chan]);
                        bbox_min[chan] = ac_build_fmin(ctx, bbox_min[chan], pos[2][chan]);