svga: Fix banded DMA upload unmap
[mesa.git] / src / gallium / drivers / svga / svga_tgsi.c
index 9a6fb465ccb2e6b05c695c3469fff489ef92f67a..5c3afee38453e8cbcf34cb7b3c4b1d38152d415e 100644 (file)
  */
 static char err_buf[128];
 
-#if 0
-static void
-svga_destroy_shader_emitter(struct svga_shader_emitter *emit)
-{
-   if (emit->buf != err_buf)
-      FREE(emit->buf);
-}
-#endif
-
 
 static boolean
 svga_shader_expand(struct svga_shader_emitter *emit)
@@ -71,7 +62,7 @@ svga_shader_expand(struct svga_shader_emitter *emit)
    else
       new_buf = NULL;
 
-   if (new_buf == NULL) {
+   if (!new_buf) {
       emit->ptr = err_buf;
       emit->buf = err_buf;
       emit->size = sizeof(err_buf);
@@ -175,12 +166,16 @@ svga_shader_emit_header(struct svga_shader_emitter *emit)
  * it is, it will be copied to a hardware buffer for upload.
  */
 struct svga_shader_variant *
-svga_tgsi_vgpu9_translate(const struct svga_shader *shader,
-                          const struct svga_compile_key *key, unsigned unit)
+svga_tgsi_vgpu9_translate(struct svga_context *svga,
+                          const struct svga_shader *shader,
+                          const struct svga_compile_key *key,
+                          enum pipe_shader_type unit)
 {
    struct svga_shader_variant *variant = NULL;
    struct svga_shader_emitter emit;
 
+   SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_TGSIVGPU9TRANSLATE);
+
    memset(&emit, 0, sizeof(emit));
 
    emit.size = 1024;
@@ -215,6 +210,12 @@ svga_tgsi_vgpu9_translate(const struct svga_shader *shader,
       goto fail;
    }
 
+   if (emit.info.indirect_files & (1 << TGSI_FILE_TEMPORARY)) {
+      debug_printf(
+         "svga: indirect indexing of temporary registers is not supported.\n");
+      goto fail;
+   }
+
    emit.in_main_func = TRUE;
 
    if (!svga_shader_emit_header(&emit)) {
@@ -227,8 +228,8 @@ svga_tgsi_vgpu9_translate(const struct svga_shader *shader,
       goto fail;
    }
 
-   variant = CALLOC_STRUCT(svga_shader_variant);
-   if (variant == NULL)
+   variant = svga_new_shader_variant(svga, unit);
+   if (!variant)
       goto fail;
 
    variant->shader = shader;
@@ -239,6 +240,13 @@ svga_tgsi_vgpu9_translate(const struct svga_shader *shader,
 
    variant->pstipple_sampler_unit = emit.pstipple_sampler_unit;
 
+   /* If there was exactly one write to a fragment shader output register
+    * and it came from a constant buffer, we know all fragments will have
+    * the same color (except for blending).
+    */
+   variant->constant_color_output =
+      emit.constant_color_output && emit.num_output_writes == 1;
+
 #if 0
    if (!svga_shader_verify(variant->tokens, variant->nr_tokens) ||
        SVGA_DEBUG & DEBUG_TGSI) {
@@ -253,10 +261,15 @@ svga_tgsi_vgpu9_translate(const struct svga_shader *shader,
    }
 #endif
 
-   return variant;
+   goto done;
 
- fail:
+fail:
    FREE(variant);
-   FREE(emit.buf);
-   return NULL;
+   if (emit.buf != err_buf)
+      FREE(emit.buf);
+   variant = NULL;
+
+done:
+   SVGA_STATS_TIME_POP(svga_sws(svga));
+   return variant;
 }