gallium: add PIPE_SHADER_CAP_GLSL_16BIT_TEMPS for LowerPrecisionTemporaries
[mesa.git] / src / gallium / drivers / svga / svga_pipe_fs.c
index a461a86dd316ea0915569fa4598caa527b0560ee..4562174910643aef22a08d0cf8e9cb25dab4716c 100644 (file)
  *
  **********************************************************/
 
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
 #include "util/u_bitmask.h"
 #include "tgsi/tgsi_parse.h"
-#include "tgsi/tgsi_text.h"
+#include "draw/draw_context.h"
 
-#include "svga_screen.h"
 #include "svga_context.h"
-#include "svga_state.h"
-#include "svga_tgsi.h"
 #include "svga_hw_reg.h"
 #include "svga_cmd.h"
-#include "svga_draw.h"
 #include "svga_debug.h"
+#include "svga_shader.h"
 
 
-/***********************************************************************
- * Fragment shaders 
- */
-
-static void *
+void *
 svga_create_fs_state(struct pipe_context *pipe,
                      const struct pipe_shader_state *templ)
 {
    struct svga_context *svga = svga_context(pipe);
-   struct svga_screen *svgascreen = svga_screen(pipe->screen);
    struct svga_fragment_shader *fs;
 
    fs = CALLOC_STRUCT(svga_fragment_shader);
    if (!fs)
       return NULL;
 
+   SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_CREATEFS);
+
    fs->base.tokens = tgsi_dup_tokens(templ->tokens);
 
    /* Collect basic info that we'll need later:
@@ -63,18 +57,19 @@ svga_create_fs_state(struct pipe_context *pipe,
    tgsi_scan_shader(fs->base.tokens, &fs->base.info);
 
    fs->base.id = svga->debug.shader_id++;
-   fs->base.use_sm30 = svgascreen->use_ps30;
-   
-   if (SVGA_DEBUG & DEBUG_TGSI || 0) {
-      debug_printf("%s id: %u, inputs: %u, outputs: %u\n",
-                   __FUNCTION__, fs->base.id,
-                   fs->base.info.num_inputs, fs->base.info.num_outputs);
-   }
 
+   fs->generic_inputs = svga_get_generic_inputs_mask(&fs->base.info);
+
+   svga_remap_generics(fs->generic_inputs, fs->generic_remap_table);
+
+   fs->draw_shader = draw_create_fragment_shader(svga->swtnl.draw, templ);
+
+   SVGA_STATS_TIME_POP(svga_sws(svga));
    return fs;
 }
 
-static void
+
+void
 svga_bind_fs_state(struct pipe_context *pipe, void *shader)
 {
    struct svga_fragment_shader *fs = (struct svga_fragment_shader *) shader;
@@ -84,44 +79,47 @@ svga_bind_fs_state(struct pipe_context *pipe, void *shader)
    svga->dirty |= SVGA_NEW_FS;
 }
 
-static
-void svga_delete_fs_state(struct pipe_context *pipe, void *shader)
+
+static void
+svga_delete_fs_state(struct pipe_context *pipe, void *shader)
 {
    struct svga_context *svga = svga_context(pipe);
    struct svga_fragment_shader *fs = (struct svga_fragment_shader *) shader;
-   struct svga_shader_result *result, *tmp;
-   enum pipe_error ret;
-
-   svga_hwtnl_flush_retry( svga );
-
-   for (result = fs->base.results; result; result = tmp ) {
-      tmp = result->next;
-
-      ret = SVGA3D_DestroyShader(svga->swc, 
-                                 result->id,
-                                 SVGA3D_SHADERTYPE_PS );
-      if(ret != PIPE_OK) {
-         svga_context_flush(svga, NULL);
-         ret = SVGA3D_DestroyShader(svga->swc, 
-                                    result->id,
-                                    SVGA3D_SHADERTYPE_PS );
-         assert(ret == PIPE_OK);
-      }
+   struct svga_fragment_shader *next_fs;
+   struct svga_shader_variant *variant, *tmp;
 
-      util_bitmask_clear( svga->fs_bm, result->id );
+   svga_hwtnl_flush_retry(svga);
 
-      svga_destroy_shader_result( result );
-   }
+   assert(fs->base.parent == NULL);
+
+   while (fs) {
+      next_fs = (struct svga_fragment_shader *) fs->base.next;
+
+      draw_delete_fragment_shader(svga->swtnl.draw, fs->draw_shader);
+
+      for (variant = fs->base.variants; variant; variant = tmp) {
+         tmp = variant->next;
 
-   FREE((void *)fs->base.tokens);
-   FREE(fs);
+         /* Check if deleting currently bound shader */
+         if (variant == svga->state.hw_draw.fs) {
+            SVGA_RETRY(svga, svga_set_shader(svga, SVGA3D_SHADERTYPE_PS, NULL));
+            svga->state.hw_draw.fs = NULL;
+         }
+
+         svga_destroy_shader_variant(svga, variant);
+      }
+
+      FREE((void *)fs->base.tokens);
+      FREE(fs);
+      fs = next_fs;
+   }
 }
 
 
-void svga_init_fs_functions( struct svga_context *svga )
+void
+svga_init_fs_functions(struct svga_context *svga)
 {
    svga->pipe.create_fs_state = svga_create_fs_state;
    svga->pipe.bind_fs_state = svga_bind_fs_state;
    svga->pipe.delete_fs_state = svga_delete_fs_state;
 }
-