i965/vec4: Replace vec4_instruction::regs_written with ::size_written field in bytes.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_wm.c
index c9c5d5e443e88353b159527d56452fe682efcce0..fb96f2f26dbcb456b7809d72cb8293763a535a3a 100644 (file)
@@ -42,7 +42,7 @@
 #include "util/ralloc.h"
 
 static void
-assign_fs_binding_table_offsets(const struct brw_device_info *devinfo,
+assign_fs_binding_table_offsets(const struct gen_device_info *devinfo,
                                 const struct gl_shader_program *shader_prog,
                                 const struct gl_program *prog,
                                 const struct brw_wm_prog_key *key,
@@ -56,9 +56,16 @@ assign_fs_binding_table_offsets(const struct brw_device_info *devinfo,
    prog_data->binding_table.render_target_start = next_binding_table_offset;
    next_binding_table_offset += MAX2(key->nr_color_regions, 1);
 
-   brw_assign_common_binding_table_offsets(MESA_SHADER_FRAGMENT, devinfo,
-                                           shader_prog, prog, &prog_data->base,
-                                           next_binding_table_offset);
+   next_binding_table_offset =
+      brw_assign_common_binding_table_offsets(MESA_SHADER_FRAGMENT, devinfo,
+                                              shader_prog, prog, &prog_data->base,
+                                              next_binding_table_offset);
+
+   if (prog->nir->info.outputs_read && !key->coherent_fb_fetch) {
+      prog_data->binding_table.render_target_read_start =
+         next_binding_table_offset;
+      next_binding_table_offset += key->nr_color_regions;
+   }
 }
 
 /**
@@ -163,10 +170,9 @@ brw_codegen_wm_prog(struct brw_context *brw,
       }
    }
 
-   if (prog_data.base.total_scratch) {
-      brw_get_scratch_bo(brw, &brw->wm.base.scratch_bo,
-                        prog_data.base.total_scratch * brw->max_wm_threads);
-   }
+   brw_alloc_stage_scratch(brw, &brw->wm.base,
+                           prog_data.base.total_scratch,
+                           brw->max_wm_threads);
 
    if (unlikely(INTEL_DEBUG & DEBUG_WM))
       fprintf(stderr, "\n");
@@ -307,16 +313,15 @@ gen6_gather_workaround(GLenum internalformat)
 void
 brw_populate_sampler_prog_key_data(struct gl_context *ctx,
                                   const struct gl_program *prog,
-                                   unsigned sampler_count,
                                   struct brw_sampler_prog_key_data *key)
 {
    struct brw_context *brw = brw_context(ctx);
+   GLbitfield mask = prog->SamplersUsed;
 
-   for (int s = 0; s < sampler_count; s++) {
-      key->swizzles[s] = SWIZZLE_NOOP;
+   while (mask) {
+      const int s = u_bit_scan(&mask);
 
-      if (!(prog->SamplersUsed & (1 << s)))
-        continue;
+      key->swizzles[s] = SWIZZLE_NOOP;
 
       int unit_id = prog->SamplerUnits[s];
       const struct gl_texture_unit *unit = &ctx->Texture.Unit[unit_id];
@@ -507,8 +512,7 @@ brw_wm_populate_key(struct brw_context *brw, struct brw_wm_prog_key *key)
    key->clamp_fragment_color = ctx->Color._ClampFragmentColor;
 
    /* _NEW_TEXTURE */
-   brw_populate_sampler_prog_key_data(ctx, prog, brw->wm.base.sampler_count,
-                                      &key->tex);
+   brw_populate_sampler_prog_key_data(ctx, prog, &key->tex);
 
    /* _NEW_BUFFERS */
    key->nr_color_regions = ctx->DrawBuffer->_NumColorDrawBuffers;
@@ -552,6 +556,9 @@ brw_wm_populate_key(struct brw_context *brw, struct brw_wm_prog_key *key)
 
    /* The unique fragment program ID */
    key->program_string_id = fp->id;
+
+   /* Whether reads from the framebuffer should behave coherently. */
+   key->coherent_fb_fetch = ctx->Extensions.MESA_shader_framebuffer_fetch;
 }
 
 void
@@ -611,10 +618,14 @@ brw_fs_precompile(struct gl_context *ctx,
 
    key.nr_color_regions = _mesa_bitcount_64(fp->Base.OutputsWritten &
          ~(BITFIELD64_BIT(FRAG_RESULT_DEPTH) |
-         BITFIELD64_BIT(FRAG_RESULT_SAMPLE_MASK)));
+           BITFIELD64_BIT(FRAG_RESULT_STENCIL) |
+           BITFIELD64_BIT(FRAG_RESULT_SAMPLE_MASK)));
 
    key.program_string_id = bfp->id;
 
+   /* Whether reads from the framebuffer should behave coherently. */
+   key.coherent_fb_fetch = ctx->Extensions.MESA_shader_framebuffer_fetch;
+
    uint32_t old_prog_offset = brw->wm.base.prog_offset;
    struct brw_wm_prog_data *old_prog_data = brw->wm.prog_data;