gallium: change set_constant_buffer to be UBO-friendly
[mesa.git] / src / gallium / state_trackers / xorg / xorg_renderer.c
index 583493116d50405b1b1af0d91586fd186166d63d..e28e06a9261f026737af6a72ba56e8321dea1ae2 100644 (file)
@@ -7,11 +7,10 @@
 #include "util/u_draw_quad.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
-#include "util/u_rect.h"
 #include "util/u_sampler.h"
-#include "util/u_surface.h"
 
 #include "util/u_inlines.h"
+#include "util/u_box.h"
 
 #include <math.h>
 
@@ -74,7 +73,7 @@ renderer_draw(struct xorg_renderer *r)
    if (buf) {
       cso_set_vertex_elements(r->cso, r->attrs_per_vertex, r->velems);
 
-      util_draw_vertex_buffer(pipe, buf, 0,
+      util_draw_vertex_buffer(pipe, r->cso, buf, 0,
                               PIPE_PRIM_QUADS,
                               num_verts,  /* verts */
                               r->attrs_per_vertex); /* attribs/vert */
@@ -108,6 +107,7 @@ renderer_init_state(struct xorg_renderer *r)
    /* XXX: move to renderer_init_state? */
    memset(&raster, 0, sizeof(struct pipe_rasterizer_state));
    raster.gl_rasterization_rules = 1;
+   raster.depth_clip = 1;
    cso_set_rasterizer(r->cso, &raster);
 
    /* vertex elements state */
@@ -430,13 +430,14 @@ void renderer_set_constants(struct xorg_renderer *r,
    pipe_resource_reference(cbuf, NULL);
    *cbuf = pipe_buffer_create(r->pipe->screen,
                               PIPE_BIND_CONSTANT_BUFFER,
+                              PIPE_USAGE_STATIC,
                               param_bytes);
 
    if (*cbuf) {
       pipe_buffer_write(r->pipe, *cbuf,
                         0, param_bytes, params);
    }
-   r->pipe->set_constant_buffer(r->pipe, shader_type, 0, *cbuf);
+   pipe_set_constant_buffer(r->pipe, shader_type, 0, *cbuf);
 }
 
 
@@ -449,9 +450,8 @@ void renderer_copy_prepare(struct xorg_renderer *r,
    struct xorg_shader shader;
 
    assert(screen->is_format_supported(screen, dst_surface->format,
-                                      PIPE_TEXTURE_2D,
-                                      PIPE_BIND_RENDER_TARGET,
-                                      0));
+                                      PIPE_TEXTURE_2D, 0,
+                                      PIPE_BIND_RENDER_TARGET));
    (void) screen;
 
 
@@ -519,14 +519,10 @@ renderer_clone_texture(struct xorg_renderer *r,
    struct pipe_resource *pt;
    struct pipe_resource templ;
 
-   if (pipe->is_resource_referenced(pipe, src, 0, 0) &
-       PIPE_REFERENCED_FOR_WRITE)
-      pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
-
    /* the coming in texture should already have that invariance */
    debug_assert(screen->is_format_supported(screen, src->format,
-                                            PIPE_TEXTURE_2D,
-                                            PIPE_BIND_SAMPLER_VIEW, 0));
+                                            PIPE_TEXTURE_2D, 0,
+                                            PIPE_BIND_SAMPLER_VIEW));
 
    format = src->format;
 
@@ -537,6 +533,7 @@ renderer_clone_texture(struct xorg_renderer *r,
    templ.width0 = src->width0;
    templ.height0 = src->height0;
    templ.depth0 = 1;
+   templ.array_size = 1;
    templ.bind = PIPE_BIND_SAMPLER_VIEW;
 
    pt = screen->resource_create(screen, &templ);
@@ -548,25 +545,15 @@ renderer_clone_texture(struct xorg_renderer *r,
 
    {
       /* copy source framebuffer surface into texture */
-      struct pipe_surface *ps_read = screen->get_tex_surface(
-         screen, src, 0, 0, 0, PIPE_BIND_BLIT_SOURCE);
-      struct pipe_surface *ps_tex = screen->get_tex_surface(
-         screen, pt, 0, 0, 0, PIPE_BIND_BLIT_DESTINATION );
-      if (pipe->surface_copy) {
-         pipe->surface_copy(pipe,
-                ps_tex, /* dest */
-                0, 0, /* destx/y */
-                ps_read,
-                0, 0, src->width0, src->height0);
-      } else {
-          util_surface_copy(pipe, FALSE,
-                ps_tex, /* dest */
-                0, 0, /* destx/y */
-                ps_read,
-                0, 0, src->width0, src->height0);
-      }
-      pipe_surface_reference(&ps_read, NULL);
-      pipe_surface_reference(&ps_tex, NULL);
+      struct pipe_box src_box;
+      u_box_origin_2d(src->width0, src->height0, &src_box);
+
+      pipe->resource_copy_region(pipe,
+                                 pt, /* dest */
+                                 0, /* dest_level */
+                                 0, 0, 0, /* destx/y/z */
+                                 src,
+                                 0, &src_box);
    }
 
    return pt;
@@ -609,7 +596,7 @@ void renderer_copy_pixmap(struct xorg_renderer *r,
 
 
 void renderer_draw_yuv(struct xorg_renderer *r,
-                       int src_x, int src_y, int src_w, int src_h,
+                       float src_x, float src_y, float src_w, float src_h,
                        int dst_x, int dst_y, int dst_w, int dst_h,
                        struct pipe_resource **textures)
 {
@@ -626,7 +613,7 @@ void renderer_draw_yuv(struct xorg_renderer *r,
 
       cso_set_vertex_elements(r->cso, num_attribs, r->velems);
 
-      util_draw_vertex_buffer(pipe, buf, 0,
+      util_draw_vertex_buffer(pipe, r->cso, buf, 0,
                               PIPE_PRIM_QUADS,
                               4,  /* verts */
                               num_attribs); /* attribs/vert */