llvmpipe: Unbreak Z32_FLOAT.
[mesa.git] / src / gallium / drivers / llvmpipe / lp_state_fs.c
index 6bfd02061d5fa8de061edad6627e63a23b60f6b5..c09835635dd0e7907a7d0c87d82b9214a69bc11b 100644 (file)
@@ -238,9 +238,9 @@ generate_fs(struct llvmpipe_context *lp,
    LLVMValueRef zs_value = NULL;
    LLVMValueRef stencil_refs[2];
    struct lp_build_mask_context mask;
-   boolean simple_shader = (shader->info.file_count[TGSI_FILE_SAMPLER] == 0 &&
-                            shader->info.num_inputs < 3 &&
-                            shader->info.num_instructions < 8);
+   boolean simple_shader = (shader->info.base.file_count[TGSI_FILE_SAMPLER] == 0 &&
+                            shader->info.base.num_inputs < 3 &&
+                            shader->info.base.num_instructions < 8);
    unsigned attrib;
    unsigned chan;
    unsigned cbuf;
@@ -253,8 +253,8 @@ generate_fs(struct llvmpipe_context *lp,
       zs_format_desc = util_format_description(key->zsbuf_format);
       assert(zs_format_desc);
 
-      if (!shader->info.writes_z) {
-         if (key->alpha.enabled || shader->info.uses_kill)
+      if (!shader->info.base.writes_z) {
+         if (key->alpha.enabled || shader->info.base.uses_kill)
             /* With alpha test and kill, can do the depth test early
              * and hopefully eliminate some quads.  But need to do a
              * special deferred depth write once the final mask value
@@ -325,8 +325,9 @@ generate_fs(struct llvmpipe_context *lp,
                                   &zs_value,
                                   !simple_shader);
 
-      if (depth_mode & EARLY_DEPTH_WRITE)
-         LLVMBuildStore(builder, zs_value, depth_ptr);
+      if (depth_mode & EARLY_DEPTH_WRITE) {
+         lp_build_depth_write(builder, zs_format_desc, depth_ptr, zs_value);
+      }
    }
 
    lp_build_interp_soa_update_inputs(interp, i);
@@ -334,12 +335,12 @@ generate_fs(struct llvmpipe_context *lp,
    /* Build the actual shader */
    lp_build_tgsi_soa(builder, tokens, type, &mask,
                      consts_ptr, interp->pos, interp->inputs,
-                     outputs, sampler, &shader->info);
+                     outputs, sampler, &shader->info.base);
 
 
    /* Alpha test */
    if (key->alpha.enabled) {
-      int color0 = find_output_by_semantic(&shader->info,
+      int color0 = find_output_by_semantic(&shader->info.base,
                                            TGSI_SEMANTIC_COLOR,
                                            0);
 
@@ -358,7 +359,7 @@ generate_fs(struct llvmpipe_context *lp,
 
    /* Late Z test */
    if (depth_mode & LATE_DEPTH_TEST) { 
-      int pos0 = find_output_by_semantic(&shader->info,
+      int pos0 = find_output_by_semantic(&shader->info.base,
                                          TGSI_SEMANTIC_POSITION,
                                          0);
          
@@ -379,8 +380,9 @@ generate_fs(struct llvmpipe_context *lp,
                                   &zs_value,
                                   !simple_shader);
       /* Late Z write */
-      if (depth_mode & LATE_DEPTH_WRITE)
-         LLVMBuildStore(builder, zs_value, depth_ptr);
+      if (depth_mode & LATE_DEPTH_WRITE) {
+         lp_build_depth_write(builder, zs_format_desc, depth_ptr, zs_value);
+      }
    }
    else if ((depth_mode & EARLY_DEPTH_TEST) &&
             (depth_mode & LATE_DEPTH_WRITE))
@@ -399,11 +401,11 @@ generate_fs(struct llvmpipe_context *lp,
 
 
    /* Color write  */
-   for (attrib = 0; attrib < shader->info.num_outputs; ++attrib)
+   for (attrib = 0; attrib < shader->info.base.num_outputs; ++attrib)
    {
-      if (shader->info.output_semantic_name[attrib] == TGSI_SEMANTIC_COLOR)
+      if (shader->info.base.output_semantic_name[attrib] == TGSI_SEMANTIC_COLOR)
       {
-         unsigned cbuf = shader->info.output_semantic_index[attrib];
+         unsigned cbuf = shader->info.base.output_semantic_index[attrib];
          for(chan = 0; chan < NUM_CHANNELS; ++chan)
          {
             /* XXX: just initialize outputs to point at colors[] and
@@ -534,6 +536,7 @@ generate_fragment(struct llvmpipe_context *lp,
    LLVMValueRef blend_mask;
    LLVMValueRef function;
    LLVMValueRef facing;
+   const struct util_format_description *zs_format_desc;
    unsigned num_fs;
    unsigned i;
    unsigned chan;
@@ -579,7 +582,7 @@ generate_fragment(struct llvmpipe_context *lp,
    arg_types[5] = LLVMPointerType(fs_elem_type, 0);    /* dadx */
    arg_types[6] = LLVMPointerType(fs_elem_type, 0);    /* dady */
    arg_types[7] = LLVMPointerType(LLVMPointerType(blend_vec_type, 0), 0);  /* color */
-   arg_types[8] = LLVMPointerType(fs_int_vec_type, 0); /* depth */
+   arg_types[8] = LLVMPointerType(LLVMInt8Type(), 0);  /* depth */
    arg_types[9] = LLVMInt32Type();                     /* mask_input */
    arg_types[10] = LLVMPointerType(LLVMInt32Type(), 0);/* counter */
 
@@ -648,12 +651,16 @@ generate_fragment(struct llvmpipe_context *lp,
    sampler = lp_llvm_sampler_soa_create(key->sampler, context_ptr);
 
    /* loop over quads in the block */
+   zs_format_desc = util_format_description(key->zsbuf_format);
+
    for(i = 0; i < num_fs; ++i) {
-      LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
+      LLVMValueRef depth_offset = LLVMConstInt(LLVMInt32Type(),
+                                               i*fs_type.length*zs_format_desc->block.bits/8,
+                                               0);
       LLVMValueRef out_color[PIPE_MAX_COLOR_BUFS][NUM_CHANNELS];
       LLVMValueRef depth_ptr_i;
 
-      depth_ptr_i = LLVMBuildGEP(builder, depth_ptr, &index, 1, "");
+      depth_ptr_i = LLVMBuildGEP(builder, depth_ptr, &depth_offset, 1, "");
 
       generate_fs(lp, shader, key,
                   builder,
@@ -728,7 +735,7 @@ generate_fragment(struct llvmpipe_context *lp,
           */
          boolean do_branch = ((key->depth.enabled || key->stencil[0].enabled) &&
                               !key->alpha.enabled &&
-                              !shader->info.uses_kill);
+                              !shader->info.base.uses_kill);
 
          generate_blend(&key->blend,
                         rt,
@@ -917,7 +924,7 @@ generate_variant(struct llvmpipe_context *lp,
          !key->stencil[0].enabled &&
          !key->alpha.enabled &&
          !key->depth.enabled &&
-         !shader->info.uses_kill
+         !shader->info.base.uses_kill
          ? TRUE : FALSE;
 
 
@@ -954,7 +961,7 @@ llvmpipe_create_fs_state(struct pipe_context *pipe,
    make_empty_list(&shader->variants);
 
    /* get/save the summary info for this shader */
-   tgsi_scan_shader(templ->tokens, &shader->info);
+   lp_build_tgsi_info(templ->tokens, &shader->info);
 
    /* we need to keep a local copy of the tokens */
    shader->base.tokens = tgsi_dup_tokens(templ->tokens);
@@ -966,7 +973,7 @@ llvmpipe_create_fs_state(struct pipe_context *pipe,
       return NULL;
    }
 
-   nr_samplers = shader->info.file_max[TGSI_FILE_SAMPLER] + 1;
+   nr_samplers = shader->info.base.file_max[TGSI_FILE_SAMPLER] + 1;
 
    shader->variant_key_size = Offset(struct lp_fragment_shader_variant_key,
                                     sampler[nr_samplers]);
@@ -976,8 +983,8 @@ llvmpipe_create_fs_state(struct pipe_context *pipe,
       debug_printf("llvmpipe: Create fragment shader #%u %p:\n", shader->no, (void *) shader);
       tgsi_dump(templ->tokens, 0);
       debug_printf("usage masks:\n");
-      for (attrib = 0; attrib < shader->info.num_inputs; ++attrib) {
-         unsigned usage_mask = shader->info.input_usage_mask[attrib];
+      for (attrib = 0; attrib < shader->info.base.num_inputs; ++attrib) {
+         unsigned usage_mask = shader->info.base.input_usage_mask[attrib];
          debug_printf("  IN[%u].%s%s%s%s\n",
                       attrib,
                       usage_mask & TGSI_WRITEMASK_X ? "x" : "",
@@ -1206,10 +1213,10 @@ make_variant_key(struct llvmpipe_context *lp,
 
    /* This value will be the same for all the variants of a given shader:
     */
-   key->nr_samplers = shader->info.file_max[TGSI_FILE_SAMPLER] + 1;
+   key->nr_samplers = shader->info.base.file_max[TGSI_FILE_SAMPLER] + 1;
 
    for(i = 0; i < key->nr_samplers; ++i) {
-      if(shader->info.file_mask[TGSI_FILE_SAMPLER] & (1 << i)) {
+      if(shader->info.base.file_mask[TGSI_FILE_SAMPLER] & (1 << i)) {
          lp_sampler_static_state(&key->sampler[i],
                                 lp->fragment_sampler_views[i],
                                 lp->sampler[i]);