Squashed commit of the following:
[mesa.git] / src / gallium / state_trackers / vega / vg_tracker.c
index ea5c2ce41f6f2df40d284fd86ec79b93fc5ad74e..117c6d3977f925def8bcf7200d0669c224933265 100644 (file)
@@ -32,6 +32,7 @@
 #include "util/u_inlines.h"
 #include "pipe/p_screen.h"
 #include "util/u_format.h"
+#include "util/u_sampler.h"
 #include "util/u_memory.h"
 #include "util/u_math.h"
 #include "util/u_rect.h"
 /* advertise OpenVG support */
 PUBLIC const int st_api_OpenVG = 1;
 
-static struct pipe_texture *
+static struct pipe_resource *
 create_texture(struct pipe_context *pipe, enum pipe_format format,
-               VGint width, VGint height)
+                    VGint width, VGint height)
 {
-   struct pipe_texture templ;
+   struct pipe_resource templ;
 
    memset(&templ, 0, sizeof(templ));
 
@@ -61,14 +62,35 @@ create_texture(struct pipe_context *pipe, enum pipe_format format,
    templ.last_level = 0;
 
    if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_ZS, 1)) {
-      templ.tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL;
+      templ.bind = PIPE_BIND_DEPTH_STENCIL;
    } else {
-      templ.tex_usage = (PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
-                         PIPE_TEXTURE_USAGE_RENDER_TARGET |
-                         PIPE_TEXTURE_USAGE_SAMPLER);
+      templ.bind = (PIPE_BIND_DISPLAY_TARGET |
+                   PIPE_BIND_RENDER_TARGET |
+                   PIPE_BIND_SAMPLER_VIEW);
    }
 
-   return pipe->screen->texture_create(pipe->screen, &templ);
+   return pipe->screen->resource_create(pipe->screen, &templ);
+}
+
+static struct pipe_sampler_view *
+create_tex_and_view(struct pipe_context *pipe, enum pipe_format format,
+                    VGint width, VGint height)
+{
+   struct pipe_resource *texture;
+   struct pipe_sampler_view view_templ;
+   struct pipe_sampler_view *view;
+
+   texture = create_texture(pipe, format, width, height);
+
+   if (!texture)
+      return NULL;
+
+   u_sampler_view_default_template(&view_templ, texture, texture->format);
+   view = pipe->create_sampler_view(pipe, texture, &view_templ);
+   /* want the texture to go away if the view is freed */
+   pipe_resource_reference(&texture, NULL);
+
+   return view;
 }
 
 /**
@@ -107,16 +129,17 @@ st_renderbuffer_alloc_storage(struct vg_context * ctx,
    /* Free the old surface and texture
     */
    pipe_surface_reference(&strb->surface, NULL);
-   pipe_texture_reference(&strb->texture, NULL);
+   pipe_resource_reference(&strb->texture, NULL);
 
 
    /* Probably need dedicated flags for surface usage too:
     */
-   surface_usage = (PIPE_BUFFER_USAGE_GPU_READ  |
-                    PIPE_BUFFER_USAGE_GPU_WRITE);
+   surface_usage = (PIPE_BIND_RENDER_TARGET  |
+                    PIPE_BIND_BLIT_SOURCE |
+                   PIPE_BIND_BLIT_DESTINATION);
+
+   strb->texture = create_texture(pipe, strb->format, width, height);
 
-   strb->texture = create_texture(pipe, strb->format,
-                                  width, height);
 
    if (!strb->texture)
       return FALSE;
@@ -186,12 +209,12 @@ struct st_framebuffer * st_create_framebuffer(const void *visual,
       if (stencilFormat == depthFormat)
          stfb->dsrb = st_new_renderbuffer_fb(stencilFormat);
       else
-         stfb->dsrb = st_new_renderbuffer_fb(PIPE_FORMAT_Z24S8_UNORM);
+         stfb->dsrb = st_new_renderbuffer_fb(PIPE_FORMAT_Z24_UNORM_S8_USCALED);
 
       /*### currently we always allocate it but it's possible it's
         not necessary if EGL_ALPHA_MASK_SIZE was 0
       */
-      stfb->alpha_mask = 0;
+      stfb->alpha_mask_view = NULL;
 
       stfb->width = width;
       stfb->height = height;
@@ -206,19 +229,19 @@ static void setup_new_alpha_mask(struct vg_context *ctx,
                                  uint width, uint height)
 {
    struct pipe_context *pipe = ctx->pipe;
-   struct pipe_texture *old_texture = stfb->alpha_mask;
+   struct pipe_sampler_view *old_sampler_view = stfb->alpha_mask_view;
 
    /*
      we use PIPE_FORMAT_B8G8R8A8_UNORM because we want to render to
      this texture and use it as a sampler, so while this wastes some
      space it makes both of those a lot simpler
    */
-   stfb->alpha_mask =
-      create_texture(pipe, PIPE_FORMAT_B8G8R8A8_UNORM, width, height);
+   stfb->alpha_mask_view =
+      create_tex_and_view(pipe, PIPE_FORMAT_B8G8R8A8_UNORM, width, height);
 
-   if (!stfb->alpha_mask) {
-      if (old_texture)
-         pipe_texture_reference(&old_texture, NULL);
+   if (!stfb->alpha_mask_view) {
+      if (old_sampler_view)
+         pipe_sampler_view_reference(&old_sampler_view, NULL);
       return;
    }
 
@@ -228,17 +251,18 @@ static void setup_new_alpha_mask(struct vg_context *ctx,
    mask_fill(0, 0, width, height, 1.f);
 
    /* if we had an old surface copy it over */
-   if (old_texture) {
+   if (old_sampler_view) {
       struct pipe_surface *surface = pipe->screen->get_tex_surface(
          pipe->screen,
-         stfb->alpha_mask,
+         stfb->alpha_mask_view->texture,
          0, 0, 0,
-         PIPE_BUFFER_USAGE_GPU_WRITE);
+         PIPE_BIND_RENDER_TARGET |
+        PIPE_BIND_BLIT_DESTINATION);
       struct pipe_surface *old_surface = pipe->screen->get_tex_surface(
          pipe->screen,
-         old_texture,
+         old_sampler_view->texture,
          0, 0, 0,
-         PIPE_BUFFER_USAGE_GPU_READ);
+         PIPE_BIND_BLIT_SOURCE);
       if (pipe->surface_copy) {
          pipe->surface_copy(pipe,
                             surface,
@@ -264,8 +288,8 @@ static void setup_new_alpha_mask(struct vg_context *ctx,
 
    /* Free the old texture
     */
-   if (old_texture)
-      pipe_texture_reference(&old_texture, NULL);
+   if (old_sampler_view)
+      pipe_sampler_view_reference(&old_sampler_view, NULL);
 }
 
 void st_resize_framebuffer(struct st_framebuffer *stfb,
@@ -326,9 +350,9 @@ void st_resize_framebuffer(struct st_framebuffer *stfb,
 
    setup_new_alpha_mask(ctx, stfb, width, height);
 
-   pipe_texture_reference( &stfb->blend_texture, NULL );
-   stfb->blend_texture = create_texture(ctx->pipe, PIPE_FORMAT_B8G8R8A8_UNORM,
-                                        width, height);
+   pipe_sampler_view_reference( &stfb->blend_texture_view, NULL );
+   stfb->blend_texture_view = create_tex_and_view(ctx->pipe, PIPE_FORMAT_B8G8R8A8_UNORM,
+                                                  width, height);
 }
 
 void st_set_framebuffer_surface(struct st_framebuffer *stfb,
@@ -338,11 +362,11 @@ void st_set_framebuffer_surface(struct st_framebuffer *stfb,
 
    /* unreference existing surfaces */
    pipe_surface_reference( &rb->surface, NULL );
-   pipe_texture_reference( &rb->texture, NULL );
+   pipe_resource_reference( &rb->texture, NULL );
 
    /* reference new ones */
    pipe_surface_reference( &rb->surface, surf );
-   pipe_texture_reference( &rb->texture, surf->texture );
+   pipe_resource_reference( &rb->texture, surf->texture );
 
    rb->width  = surf->width;
    rb->height = surf->height;
@@ -357,7 +381,7 @@ int st_get_framebuffer_surface(struct st_framebuffer *stfb,
 }
 
 int st_get_framebuffer_texture(struct st_framebuffer *stfb,
-                               uint surfIndex, struct pipe_texture **tex)
+                               uint surfIndex, struct pipe_resource **tex)
 {
    struct st_renderbuffer *rb = stfb->strb;
    *tex = rb->texture;