r300: Set up shadow sampler lowering in precompiles.
authorEmma Anholt <emma@anholt.net>
Thu, 3 Feb 2022 05:08:13 +0000 (21:08 -0800)
committerEmma Anholt <emma@anholt.net>
Thu, 3 Feb 2022 22:28:44 +0000 (14:28 -0800)
Otherwise you end up lowering all shadow samples to a MOV dst
temp[0].0000, which is pretty silly.

Reviewed-by: Matt Turner <mattst88@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14847>

src/gallium/drivers/r300/r300_state.c

index 25b69c4..e3f482b 100644 (file)
@@ -1053,12 +1053,19 @@ static void* r300_create_fs_state(struct pipe_context* pipe,
 
     /* Precompile the fragment shader at creation time to avoid jank at runtime.
      * In most cases we won't have anything in the key at draw time.
-     *
-     * TODO: precompile state for shadow samplers (but this needs a decision for
-     * the default shadow compare and texture swizzle values).
      */
     struct r300_fragment_program_external_state precompile_state;
     memset(&precompile_state, 0, sizeof(precompile_state));
+
+    struct tgsi_shader_info info;
+    tgsi_scan_shader(fs->state.tokens, &info);
+    for (int i = 0; i < PIPE_MAX_SHADER_SAMPLER_VIEWS; i++) {
+        if (info.sampler_targets[i] == TGSI_TEXTURE_SHADOW1D ||
+            info.sampler_targets[i] == TGSI_TEXTURE_SHADOW2D) {
+            precompile_state.unit[i].compare_mode_enabled = true;
+            precompile_state.unit[i].texture_compare_func = PIPE_FUNC_LESS;
+        }
+    }
     r300_pick_fragment_shader(r300, fs, &precompile_state);
 
     return (void *)fs;