mesa: minor whitespace fixes, line wrapping in texcompress.c
[mesa.git] / src / mesa / main / texstate.c
index 59b964816630e11a710fa70799fe52b0dac08a23..8f87cac0ce446a08d54ea05911286e48bfb4803e 100644 (file)
@@ -38,6 +38,7 @@
 #include "teximage.h"
 #include "texstate.h"
 #include "mtypes.h"
+#include "state.h"
 #include "util/bitscan.h"
 #include "util/bitset.h"
 
@@ -306,8 +307,6 @@ active_texture(GLenum texture, bool no_error)
       }
    }
 
-   FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);
-
    ctx->Texture.CurrentUnit = texUnit;
    if (ctx->Transform.MatrixMode == GL_TEXTURE) {
       /* update current stack pointer */
@@ -350,7 +349,7 @@ _mesa_ClientActiveTexture(GLenum texture)
       return;
    }
 
-   FLUSH_VERTICES(ctx, _NEW_ARRAY);
+   /* Don't flush vertices. This is a "latched" state. */
    ctx->Array.ActiveTexture = texUnit;
 }
 
@@ -687,8 +686,6 @@ update_single_program_texture_state(struct gl_context *ctx,
    struct gl_texture_object *texObj;
 
    texObj = update_single_program_texture(ctx, prog, unit);
-   if (!texObj)
-      return;
 
    _mesa_reference_texobj(&ctx->Texture.Unit[unit]._Current, texObj);
    BITSET_SET(enabled_texture_units, unit);
@@ -704,6 +701,7 @@ update_program_texture_state(struct gl_context *ctx, struct gl_program **prog,
 
    for (i = 0; i < MESA_SHADER_STAGES; i++) {
       GLbitfield mask;
+      GLuint s;
 
       if (!prog[i])
          continue;
@@ -711,12 +709,27 @@ update_program_texture_state(struct gl_context *ctx, struct gl_program **prog,
       mask = prog[i]->SamplersUsed;
 
       while (mask) {
-         const int s = u_bit_scan(&mask);
+         s = u_bit_scan(&mask);
 
          update_single_program_texture_state(ctx, prog[i],
                                              prog[i]->SamplerUnits[s],
                                              enabled_texture_units);
       }
+
+      if (unlikely(prog[i]->sh.HasBoundBindlessSampler)) {
+         /* Loop over bindless samplers bound to texture units.
+          */
+         for (s = 0; s < prog[i]->sh.NumBindlessSamplers; s++) {
+            struct gl_bindless_sampler *sampler =
+               &prog[i]->sh.BindlessSamplers[s];
+
+            if (!sampler->bound)
+               continue;
+
+            update_single_program_texture_state(ctx, prog[i], sampler->unit,
+                                                enabled_texture_units);
+         }
+      }
    }
 
    if (prog[MESA_SHADER_FRAGMENT]) {
@@ -806,6 +819,29 @@ update_ff_texture_state(struct gl_context *ctx,
    }
 }
 
+static void
+fix_missing_textures_for_atifs(struct gl_context *ctx,
+                               struct gl_program *prog,
+                               BITSET_WORD *enabled_texture_units)
+{
+   GLbitfield mask = prog->SamplersUsed;
+
+   while (mask) {
+      const int s = u_bit_scan(&mask);
+      const int unit = prog->SamplerUnits[s];
+      const gl_texture_index target_index = ffs(prog->TexturesUsed[unit]) - 1;
+
+      if (!ctx->Texture.Unit[unit]._Current) {
+         struct gl_texture_object *texObj =
+            _mesa_get_fallback_texture(ctx, target_index);
+         _mesa_reference_texobj(&ctx->Texture.Unit[unit]._Current, texObj);
+         BITSET_SET(enabled_texture_units, unit);
+         ctx->Texture._MaxEnabledTexImageUnit =
+            MAX2(ctx->Texture._MaxEnabledTexImageUnit, (int)unit);
+      }
+   }
+}
+
 /**
  * \note This routine refers to derived texture matrix values to
  * compute the ENABLE_TEXMAT flags, but is only called on
@@ -823,15 +859,10 @@ _mesa_update_texture_state(struct gl_context *ctx)
    int old_max_unit = ctx->Texture._MaxEnabledTexImageUnit;
    BITSET_DECLARE(enabled_texture_units, MAX_COMBINED_TEXTURE_IMAGE_UNITS);
 
-   for (i = 0; i < MESA_SHADER_STAGES; i++) {
-      if (ctx->_Shader->CurrentProgram[i]) {
-         prog[i] = ctx->_Shader->CurrentProgram[i];
-      } else {
-         prog[i] = NULL;
-      }
-   }
+   memcpy(prog, ctx->_Shader->CurrentProgram, sizeof(prog));
 
-   if (prog[MESA_SHADER_FRAGMENT] == NULL && ctx->FragmentProgram._Enabled) {
+   if (prog[MESA_SHADER_FRAGMENT] == NULL &&
+       _mesa_arb_fragment_program_enabled(ctx)) {
       prog[MESA_SHADER_FRAGMENT] = ctx->FragmentProgram.Current;
    }
 
@@ -867,6 +898,13 @@ _mesa_update_texture_state(struct gl_context *ctx)
       _mesa_reference_texobj(&ctx->Texture.Unit[i]._Current, NULL);
    }
 
+   /* add fallback texture for SampleMapATI if there is nothing */
+   if (_mesa_ati_fragment_shader_enabled(ctx) &&
+       ctx->ATIFragmentShader.Current->Program)
+      fix_missing_textures_for_atifs(ctx,
+                                     ctx->ATIFragmentShader.Current->Program,
+                                     enabled_texture_units);
+
    if (!prog[MESA_SHADER_FRAGMENT] || !prog[MESA_SHADER_VERTEX])
       update_texgen(ctx);
 }