[Mesa-dev] [PATCH 1/2] i965/draw: Do resolves properly for textures used by TXF

Jason Ekstrand jason at jlekstrand.net
Wed Nov 1 03:01:04 UTC 2017


---
 src/mesa/drivers/dri/i965/brw_draw.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/brw_draw.c b/src/mesa/drivers/dri/i965/brw_draw.c
index 809e722..2ae60d5 100644
--- a/src/mesa/drivers/dri/i965/brw_draw.c
+++ b/src/mesa/drivers/dri/i965/brw_draw.c
@@ -40,6 +40,7 @@
 #include "swrast_setup/swrast_setup.h"
 #include "drivers/common/meta.h"
 #include "util/bitscan.h"
+#include "util/bitset.h"
 
 #include "brw_blorp.h"
 #include "brw_draw.h"
@@ -390,6 +391,24 @@ brw_predraw_resolve_inputs(struct brw_context *brw, bool rendering)
    memset(brw->draw_aux_buffer_disabled, 0,
           sizeof(brw->draw_aux_buffer_disabled));
 
+   BITSET_DECLARE(used_for_txf, MAX_COMBINED_TEXTURE_IMAGE_UNITS);
+   memset(used_for_txf, 0, sizeof(used_for_txf));
+
+   for (unsigned stage = 0; stage < MESA_SHADER_STAGES; stage++) {
+      if ((stage != MESA_SHADER_COMPUTE) != rendering)
+         continue;
+
+      const struct gl_program *prog = brw->programs[stage];
+      if (!prog)
+         continue;
+
+      unsigned mask = prog->SamplersUsed & prog->info.textures_used_by_txf;
+      while (mask) {
+         int s = u_bit_scan(&mask);
+         BITSET_SET(used_for_txf, prog->SamplerUnits[s]);
+      }
+   }
+
    /* Resolve depth buffer and render cache of each enabled texture. */
    int maxEnabledUnit = ctx->Texture._MaxEnabledTexImageUnit;
    for (int i = 0; i <= maxEnabledUnit; i++) {
@@ -426,6 +445,20 @@ brw_predraw_resolve_inputs(struct brw_context *brw, bool rendering)
                                     min_layer, num_layers,
                                     disable_aux);
 
+      /* If any programs are using it with texelFetch, we may need to also do
+       * a prepare with an sRGB format to ensure texelFetch works "properly".
+       */
+      if (BITSET_TEST(used_for_txf, i)) {
+         enum isl_format txf_format =
+            translate_tex_format(brw, tex_obj->_Format, GL_DECODE_EXT);
+         if (txf_format != view_format) {
+            intel_miptree_prepare_texture(brw, tex_obj->mt, txf_format,
+                                          min_level, num_levels,
+                                          min_layer, num_layers,
+                                          disable_aux);
+         }
+      }
+
       brw_render_cache_set_check_flush(brw, tex_obj->mt->bo);
 
       if (tex_obj->base.StencilSampling ||
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list