Merge branch 'master' of git://anongit.freedesktop.org/mesa/mesa
[mesa.git] / src / gallium / drivers / r300 / r300_context.c
index 48a595981be6288ce46d711f4516ffd9d4daa036..b304999d424733aaec55e6b9d9b0bbf2c75a90a5 100644 (file)
 #include "util/u_sampler.h"
 #include "util/u_simple_list.h"
 #include "util/u_upload_mgr.h"
+#include "os/os_time.h"
+#include "vl/vl_decoder.h"
+#include "vl/vl_video_buffer.h"
 
 #include "r300_cb.h"
 #include "r300_context.h"
 #include "r300_emit.h"
 #include "r300_screen.h"
 #include "r300_screen_buffer.h"
-#include "r300_winsys.h"
 
 static void r300_update_num_contexts(struct r300_screen *r300screen,
                                      int diff)
@@ -96,6 +98,10 @@ static void r300_destroy_context(struct pipe_context* context)
 {
     struct r300_context* r300 = r300_context(context);
 
+    if (r300->cs && r300->hyperz_enabled) {
+        r300->rws->cs_request_feature(r300->cs, RADEON_FID_R300_HYPERZ_ACCESS, FALSE);
+    }
+
     if (r300->blitter)
         util_blitter_destroy(r300->blitter);
     if (r300->draw)
@@ -139,11 +145,11 @@ static void r300_destroy_context(struct pipe_context* context)
     FREE(r300);
 }
 
-void r300_flush_cb(void *data)
+static void r300_flush_callback(void *data, unsigned flags)
 {
     struct r300_context* const cs_context_copy = data;
 
-    cs_context_copy->context.flush(&cs_context_copy->context, 0, NULL);
+    r300_flush(&cs_context_copy->context, flags, NULL);
 }
 
 #define R300_INIT_ATOM(atomname, atomsize) \
@@ -167,9 +173,7 @@ static boolean r300_setup_atoms(struct r300_context* r300)
     boolean is_rv350 = r300->screen->caps.is_rv350;
     boolean is_r500 = r300->screen->caps.is_r500;
     boolean has_tcl = r300->screen->caps.has_tcl;
-    boolean drm_2_6_0 = r300->rws->get_value(r300->rws, R300_VID_DRM_2_6_0);
-    boolean can_hyperz = r300->rws->get_value(r300->rws, R300_CAN_HYPERZ);
-    boolean has_hiz_ram = r300->screen->caps.hiz_ram > 0;
+    boolean drm_2_6_0 = r300->screen->info.drm_minor >= 6;
 
     /* Create the actual atom list.
      *
@@ -220,13 +224,10 @@ static boolean r300_setup_atoms(struct r300_context* r300)
     /* TX. */
     R300_INIT_ATOM(texture_cache_inval, 2);
     R300_INIT_ATOM(textures_state, 0);
-    if (can_hyperz) {
-        /* HiZ Clear */
-        if (has_hiz_ram)
-            R300_INIT_ATOM(hiz_clear, 4);
-        /* zmask clear */
-        R300_INIT_ATOM(zmask_clear, 4);
-    }
+    /* HiZ Clear */
+    R300_INIT_ATOM(hiz_clear, r300->screen->caps.hiz_ram > 0 ? 4 : 0);
+    /* zmask clear */
+    R300_INIT_ATOM(zmask_clear, r300->screen->caps.zmask_ram > 0 ? 4 : 0);
     /* ZB (unpipelined), SU. */
     R300_INIT_ATOM(query_start, 4);
 
@@ -379,7 +380,7 @@ static void r300_init_states(struct pipe_context *pipe)
 
         if (r300->screen->caps.is_r500 ||
             (r300->screen->caps.is_rv350 &&
-             r300->rws->get_value(r300->rws, R300_VID_DRM_2_6_0))) {
+             r300->screen->info.drm_minor >= 6)) {
             OUT_CB_REG(R300_GB_Z_PEQ_CONFIG, 0);
         }
         END_CB;
@@ -391,7 +392,7 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
 {
     struct r300_context* r300 = CALLOC_STRUCT(r300_context);
     struct r300_screen* r300screen = r300_screen(screen);
-    struct r300_winsys_screen *rws = r300screen->rws;
+    struct radeon_winsys *rws = r300screen->rws;
 
     if (!r300)
         return NULL;
@@ -437,6 +438,9 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
     r300_init_query_functions(r300);
     r300_init_state_functions(r300);
     r300_init_resource_functions(r300);
+    
+    r300->context.create_video_decoder = vl_create_decoder;
+    r300->context.create_video_buffer = vl_video_buffer_create;
 
     r300->vbuf_mgr = u_vbuf_mgr_create(&r300->context, 1024 * 1024, 16,
                                        PIPE_BIND_VERTEX_BUFFER |
@@ -453,7 +457,7 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
     r300_init_render_functions(r300);
     r300_init_states(&r300->context);
 
-    rws->cs_set_flush(r300->cs, r300_flush_cb, r300);
+    rws->cs_set_flush_callback(r300->cs, r300_flush_callback, r300);
 
     /* The KIL opcode needs the first texture unit to be enabled
      * on r3xx-r4xx. In order to calm down the CS checker, we bind this
@@ -504,6 +508,8 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
                                                            &dsa);
     }
 
+    r300->hyperz_time_of_last_flush = os_time_get();
+
     /* Print driver info. */
 #ifdef DEBUG
     {
@@ -513,20 +519,18 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
         fprintf(stderr,
                 "r300: DRM version: %d.%d.%d, Name: %s, ID: 0x%04x, GB: %d, Z: %d\n"
                 "r300: GART size: %d MB, VRAM size: %d MB\n"
-                "r300: AA compression: %s, Z compression: %s, HiZ: %s\n",
-                rws->get_value(rws, R300_VID_DRM_MAJOR),
-                rws->get_value(rws, R300_VID_DRM_MINOR),
-                rws->get_value(rws, R300_VID_DRM_PATCHLEVEL),
+                "r300: AA compression RAM: %s, Z compression RAM: %s, HiZ RAM: %s\n",
+                r300->screen->info.drm_major,
+                r300->screen->info.drm_minor,
+                r300->screen->info.drm_patchlevel,
                 screen->get_name(screen),
-                rws->get_value(rws, R300_VID_PCI_ID),
-                rws->get_value(rws, R300_VID_GB_PIPES),
-                rws->get_value(rws, R300_VID_Z_PIPES),
-                rws->get_value(rws, R300_VID_GART_SIZE) >> 20,
-                rws->get_value(rws, R300_VID_VRAM_SIZE) >> 20,
-                rws->get_value(rws, R300_CAN_AACOMPRESS) ? "YES" : "NO",
-                rws->get_value(rws, R300_CAN_HYPERZ) &&
+                r300->screen->info.pci_id,
+                r300->screen->info.r300_num_gb_pipes,
+                r300->screen->info.r300_num_z_pipes,
+                r300->screen->info.gart_size >> 20,
+                r300->screen->info.vram_size >> 20,
+                "YES", /* XXX really? */
                 r300->screen->caps.zmask_ram ? "YES" : "NO",
-                rws->get_value(rws, R300_CAN_HYPERZ) &&
                 r300->screen->caps.hiz_ram ? "YES" : "NO");
     }