Module: Mesa
Branch: gallium-resources
Commit: 42642ec0984107d82b740711f2debbf38457a06e
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=42642ec0984107d82b740711f2debbf38457a06e

Author: Keith Whitwell <[email protected]>
Date:   Sun Mar 14 22:38:33 2010 +0000

llvmpipe: convert to pipe_resources

---

 src/gallium/drivers/llvmpipe/Makefile           |    1 -
 src/gallium/drivers/llvmpipe/SConscript         |    1 -
 src/gallium/drivers/llvmpipe/lp_buffer.c        |  118 ---------------
 src/gallium/drivers/llvmpipe/lp_buffer.h        |   55 -------
 src/gallium/drivers/llvmpipe/lp_context.c       |   22 +---
 src/gallium/drivers/llvmpipe/lp_context.h       |    2 +-
 src/gallium/drivers/llvmpipe/lp_draw_arrays.c   |    9 +-
 src/gallium/drivers/llvmpipe/lp_rast.c          |    8 +-
 src/gallium/drivers/llvmpipe/lp_scene.c         |   10 +-
 src/gallium/drivers/llvmpipe/lp_scene.h         |    8 +-
 src/gallium/drivers/llvmpipe/lp_screen.c        |    6 +-
 src/gallium/drivers/llvmpipe/lp_setup.c         |   23 ++--
 src/gallium/drivers/llvmpipe/lp_setup.h         |    6 +-
 src/gallium/drivers/llvmpipe/lp_setup_context.h |    2 +-
 src/gallium/drivers/llvmpipe/lp_state.h         |    8 +-
 src/gallium/drivers/llvmpipe/lp_state_fs.c      |    9 +-
 src/gallium/drivers/llvmpipe/lp_state_sampler.c |    6 +-
 src/gallium/drivers/llvmpipe/lp_texture.c       |  176 +++++++++++++++--------
 src/gallium/drivers/llvmpipe/lp_texture.h       |   24 ++--
 19 files changed, 173 insertions(+), 321 deletions(-)

diff --git a/src/gallium/drivers/llvmpipe/Makefile 
b/src/gallium/drivers/llvmpipe/Makefile
index 89c06ea..0613e7a 100644
--- a/src/gallium/drivers/llvmpipe/Makefile
+++ b/src/gallium/drivers/llvmpipe/Makefile
@@ -6,7 +6,6 @@ LIBNAME = llvmpipe
 DEFINES += -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS
 
 C_SOURCES = \
-       lp_buffer.c \
        lp_clear.c \
        lp_context.c \
        lp_draw_arrays.c \
diff --git a/src/gallium/drivers/llvmpipe/SConscript 
b/src/gallium/drivers/llvmpipe/SConscript
index 13c1a13..47a0eea 100644
--- a/src/gallium/drivers/llvmpipe/SConscript
+++ b/src/gallium/drivers/llvmpipe/SConscript
@@ -28,7 +28,6 @@ env.Depends('lp_tile_soa.c', [
 llvmpipe = env.ConvenienceLibrary(
        target = 'llvmpipe',
        source = [
-               'lp_buffer.c',
                'lp_clear.c',
                'lp_context.c',
                'lp_draw_arrays.c',
diff --git a/src/gallium/drivers/llvmpipe/lp_buffer.c 
b/src/gallium/drivers/llvmpipe/lp_buffer.c
deleted file mode 100644
index 6e0f373..0000000
--- a/src/gallium/drivers/llvmpipe/lp_buffer.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2009 VMware, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-
-#include "util/u_inlines.h"
-#include "util/u_memory.h"
-#include "util/u_math.h"
-
-#include "lp_screen.h"
-#include "lp_buffer.h"
-
-
-static void *
-llvmpipe_buffer_map(struct pipe_screen *screen,
-                    struct pipe_buffer *buf,
-                    unsigned flags)
-{
-   struct llvmpipe_buffer *llvmpipe_buf = llvmpipe_buffer(buf);
-   return llvmpipe_buf->data;
-}
-
-
-static void
-llvmpipe_buffer_unmap(struct pipe_screen *screen,
-                      struct pipe_buffer *buf)
-{
-}
-
-
-static void
-llvmpipe_buffer_destroy(struct pipe_buffer *buf)
-{
-   struct llvmpipe_buffer *sbuf = llvmpipe_buffer(buf);
-
-   if (!sbuf->userBuffer)
-      align_free(sbuf->data);
-      
-   FREE(sbuf);
-}
-
-
-static struct pipe_buffer *
-llvmpipe_buffer_create(struct pipe_screen *screen,
-                       unsigned alignment,
-                       unsigned usage,
-                       unsigned size)
-{
-   struct llvmpipe_buffer *buffer = CALLOC_STRUCT(llvmpipe_buffer);
-
-   pipe_reference_init(&buffer->base.reference, 1);
-   buffer->base.screen = screen;
-   buffer->base.alignment = MAX2(alignment, 16);
-   buffer->base.usage = usage;
-   buffer->base.size = size;
-
-   buffer->data = align_malloc(size, alignment);
-
-   return &buffer->base;
-}
-
-
-/**
- * Create buffer which wraps user-space data.
- */
-static struct pipe_buffer *
-llvmpipe_user_buffer_create(struct pipe_screen *screen,
-                            void *ptr,
-                            unsigned bytes)
-{
-   struct llvmpipe_buffer *buffer;
-
-   buffer = CALLOC_STRUCT(llvmpipe_buffer);
-   if(!buffer)
-      return NULL;
-
-   pipe_reference_init(&buffer->base.reference, 1);
-   buffer->base.screen = screen;
-   buffer->base.size = bytes;
-   buffer->userBuffer = TRUE;
-   buffer->data = ptr;
-
-   return &buffer->base;
-}
-
-
-void
-llvmpipe_init_screen_buffer_funcs(struct pipe_screen *screen)
-{
-   screen->buffer_create = llvmpipe_buffer_create;
-   screen->user_buffer_create = llvmpipe_user_buffer_create;
-   screen->buffer_map = llvmpipe_buffer_map;
-   screen->buffer_unmap = llvmpipe_buffer_unmap;
-   screen->buffer_destroy = llvmpipe_buffer_destroy;
-}
diff --git a/src/gallium/drivers/llvmpipe/lp_buffer.h 
b/src/gallium/drivers/llvmpipe/lp_buffer.h
deleted file mode 100644
index d6b8184..0000000
--- a/src/gallium/drivers/llvmpipe/lp_buffer.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2009 VMware, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-#ifndef LP_BUFFER_H
-#define LP_BUFFER_H
-
-#include "pipe/p_compiler.h"
-#include "pipe/p_state.h"
-
-
-struct llvmpipe_buffer
-{
-   struct pipe_buffer base;
-   boolean userBuffer;  /** Is this a user-space buffer? */
-   void *data;
-};
-
-
-/** Cast wrapper */
-static INLINE struct llvmpipe_buffer *
-llvmpipe_buffer( struct pipe_buffer *buf )
-{
-   return (struct llvmpipe_buffer *)buf;
-}
-
-
-void
-llvmpipe_init_screen_buffer_funcs(struct pipe_screen *screen);
-
-
-#endif /* LP_BUFFER_H */
diff --git a/src/gallium/drivers/llvmpipe/lp_context.c 
b/src/gallium/drivers/llvmpipe/lp_context.c
index 951a695..b7a8319 100644
--- a/src/gallium/drivers/llvmpipe/lp_context.c
+++ b/src/gallium/drivers/llvmpipe/lp_context.c
@@ -77,29 +77,13 @@ static void llvmpipe_destroy( struct pipe_context *pipe )
 
    for (i = 0; i < Elements(llvmpipe->constants); i++) {
       if (llvmpipe->constants[i]) {
-         pipe_buffer_reference(&llvmpipe->constants[i], NULL);
+         pipe_resource_reference(&llvmpipe->constants[i], NULL);
       }
    }
 
    align_free( llvmpipe );
 }
 
-static unsigned int
-llvmpipe_is_texture_referenced( struct pipe_context *pipe,
-                               struct pipe_texture *texture,
-                               unsigned face, unsigned level)
-{
-   struct llvmpipe_context *llvmpipe = llvmpipe_context( pipe );
-
-   return lp_setup_is_texture_referenced(llvmpipe->setup, texture);
-}
-
-static unsigned int
-llvmpipe_is_buffer_referenced( struct pipe_context *pipe,
-                              struct pipe_buffer *buf)
-{
-   return PIPE_UNREFERENCED;
-}
 
 struct pipe_context *
 llvmpipe_create_context( struct pipe_screen *screen, void *priv )
@@ -171,11 +155,9 @@ llvmpipe_create_context( struct pipe_screen *screen, void 
*priv )
    llvmpipe->pipe.clear = llvmpipe_clear;
    llvmpipe->pipe.flush = llvmpipe_flush;
 
-   llvmpipe->pipe.is_texture_referenced = llvmpipe_is_texture_referenced;
-   llvmpipe->pipe.is_buffer_referenced = llvmpipe_is_buffer_referenced;
 
    llvmpipe_init_query_funcs( llvmpipe );
-   llvmpipe_init_context_texture_funcs( &llvmpipe->pipe );
+   llvmpipe_init_context_resource_funcs( &llvmpipe->pipe );
 
    /*
     * Create drawing context and plug our rendering stage into it.
diff --git a/src/gallium/drivers/llvmpipe/lp_context.h 
b/src/gallium/drivers/llvmpipe/lp_context.h
index 71f9910..4848101 100644
--- a/src/gallium/drivers/llvmpipe/lp_context.h
+++ b/src/gallium/drivers/llvmpipe/lp_context.h
@@ -65,7 +65,7 @@ struct llvmpipe_context {
    struct pipe_blend_color blend_color;
    struct pipe_stencil_ref stencil_ref;
    struct pipe_clip_state clip;
-   struct pipe_buffer *constants[PIPE_SHADER_TYPES];
+   struct pipe_resource *constants[PIPE_SHADER_TYPES];
    struct pipe_framebuffer_state framebuffer;
    struct pipe_poly_stipple poly_stipple;
    struct pipe_scissor_state scissor;
diff --git a/src/gallium/drivers/llvmpipe/lp_draw_arrays.c 
b/src/gallium/drivers/llvmpipe/lp_draw_arrays.c
index 3dd68d5..a9b8ba2 100644
--- a/src/gallium/drivers/llvmpipe/lp_draw_arrays.c
+++ b/src/gallium/drivers/llvmpipe/lp_draw_arrays.c
@@ -35,7 +35,6 @@
 #include "pipe/p_context.h"
 #include "util/u_prim.h"
 
-#include "lp_buffer.h"
 #include "lp_context.h"
 #include "lp_state.h"
 
@@ -58,7 +57,7 @@ llvmpipe_draw_arrays(struct pipe_context *pipe, unsigned mode,
  */
 void
 llvmpipe_draw_range_elements(struct pipe_context *pipe,
-                             struct pipe_buffer *indexBuffer,
+                             struct pipe_resource *indexBuffer,
                              unsigned indexSize,
                              unsigned min_index,
                              unsigned max_index,
@@ -75,13 +74,13 @@ llvmpipe_draw_range_elements(struct pipe_context *pipe,
     * Map vertex buffers
     */
    for (i = 0; i < lp->num_vertex_buffers; i++) {
-      void *buf = llvmpipe_buffer(lp->vertex_buffer[i].buffer)->data;
+      void *buf = llvmpipe_resource(lp->vertex_buffer[i].buffer)->data;
       draw_set_mapped_vertex_buffer(draw, i, buf);
    }
 
    /* Map index buffer, if present */
    if (indexBuffer) {
-      void *mapped_indexes = llvmpipe_buffer(indexBuffer)->data;
+      void *mapped_indexes = llvmpipe_resource(indexBuffer)->data;
       draw_set_mapped_element_buffer_range(draw, indexSize,
                                            min_index,
                                            max_index,
@@ -117,7 +116,7 @@ llvmpipe_draw_range_elements(struct pipe_context *pipe,
 
 void
 llvmpipe_draw_elements(struct pipe_context *pipe,
-                       struct pipe_buffer *indexBuffer,
+                       struct pipe_resource *indexBuffer,
                        unsigned indexSize,
                        unsigned mode, unsigned start, unsigned count)
 {
diff --git a/src/gallium/drivers/llvmpipe/lp_rast.c 
b/src/gallium/drivers/llvmpipe/lp_rast.c
index dd9a8e8..f521bc1 100644
--- a/src/gallium/drivers/llvmpipe/lp_rast.c
+++ b/src/gallium/drivers/llvmpipe/lp_rast.c
@@ -63,9 +63,9 @@ lp_rast_begin( struct lp_rasterizer *rast,
    
    for (i = 0; i < rast->state.nr_cbufs; i++) {
       rast->cbuf[i].map = scene->cbuf_map[i];
-      rast->cbuf[i].format = scene->cbuf_transfer[i]->texture->format;
-      rast->cbuf[i].width = scene->cbuf_transfer[i]->width;
-      rast->cbuf[i].height = scene->cbuf_transfer[i]->height;
+      rast->cbuf[i].format = scene->cbuf_transfer[i]->resource->format;
+      rast->cbuf[i].width = scene->cbuf_transfer[i]->box.width;
+      rast->cbuf[i].height = scene->cbuf_transfer[i]->box.height;
       rast->cbuf[i].stride = scene->cbuf_transfer[i]->stride;
    }
 
@@ -73,7 +73,7 @@ lp_rast_begin( struct lp_rasterizer *rast,
       rast->zsbuf.map = scene->zsbuf_map;
       rast->zsbuf.stride = scene->zsbuf_transfer->stride;
       rast->zsbuf.blocksize = 
-         util_format_get_blocksize(scene->zsbuf_transfer->texture->format);
+         util_format_get_blocksize(scene->zsbuf_transfer->resource->format);
    }
 
    lp_scene_bin_iter_begin( scene );
diff --git a/src/gallium/drivers/llvmpipe/lp_scene.c 
b/src/gallium/drivers/llvmpipe/lp_scene.c
index 74c96b9..e060cdc 100644
--- a/src/gallium/drivers/llvmpipe/lp_scene.c
+++ b/src/gallium/drivers/llvmpipe/lp_scene.c
@@ -181,7 +181,7 @@ lp_scene_reset(struct lp_scene *scene )
       struct texture_ref *ref, *next, *ref_list = &scene->textures;
       for (ref = ref_list->next; ref != ref_list; ref = next) {
          next = next_elem(ref);
-         pipe_texture_reference(&ref->texture, NULL);
+         pipe_resource_reference(&ref->texture, NULL);
          FREE(ref);
       }
       make_empty_list(ref_list);
@@ -248,12 +248,12 @@ lp_scene_bin_size( const struct lp_scene *scene, unsigned 
x, unsigned y )
  */
 void
 lp_scene_texture_reference( struct lp_scene *scene,
-                            struct pipe_texture *texture )
+                            struct pipe_resource *texture )
 {
    struct texture_ref *ref = CALLOC_STRUCT(texture_ref);
    if (ref) {
       struct texture_ref *ref_list = &scene->textures;
-      pipe_texture_reference(&ref->texture, texture);
+      pipe_resource_reference(&ref->texture, texture);
       insert_at_tail(ref_list, ref);
    }
 }
@@ -263,8 +263,8 @@ lp_scene_texture_reference( struct lp_scene *scene,
  * Does this scene have a reference to the given texture?
  */
 boolean
-lp_scene_is_texture_referenced( const struct lp_scene *scene,
-                                const struct pipe_texture *texture )
+lp_scene_is_resource_referenced( const struct lp_scene *scene,
+                                const struct pipe_resource *texture )
 {
    const struct texture_ref *ref_list = &scene->textures;
    const struct texture_ref *ref;
diff --git a/src/gallium/drivers/llvmpipe/lp_scene.h 
b/src/gallium/drivers/llvmpipe/lp_scene.h
index 739ac22..a6d181f 100644
--- a/src/gallium/drivers/llvmpipe/lp_scene.h
+++ b/src/gallium/drivers/llvmpipe/lp_scene.h
@@ -99,7 +99,7 @@ struct data_block_list {
 
 /** List of texture references */
 struct texture_ref {
-   struct pipe_texture *texture;
+   struct pipe_resource *texture;
    struct texture_ref *prev, *next;  /**< linked list w/ u_simple_list.h */
 };
 
@@ -170,10 +170,10 @@ unsigned lp_scene_data_size( const struct lp_scene *scene 
);
 unsigned lp_scene_bin_size( const struct lp_scene *scene, unsigned x, unsigned 
y );
 
 void lp_scene_texture_reference( struct lp_scene *scene,
-                                 struct pipe_texture *texture );
+                                 struct pipe_resource *texture );
 
-boolean lp_scene_is_texture_referenced( const struct lp_scene *scene,
-                                        const struct pipe_texture *texture );
+boolean lp_scene_is_resource_referenced( const struct lp_scene *scene,
+                                        const struct pipe_resource *texture );
 
 
 /**
diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c 
b/src/gallium/drivers/llvmpipe/lp_screen.c
index 5093f58..c024953 100644
--- a/src/gallium/drivers/llvmpipe/lp_screen.c
+++ b/src/gallium/drivers/llvmpipe/lp_screen.c
@@ -32,7 +32,6 @@
 #include "pipe/p_screen.h"
 
 #include "lp_texture.h"
-#include "lp_buffer.h"
 #include "lp_fence.h"
 #include "lp_jit.h"
 #include "lp_screen.h"
@@ -249,7 +248,7 @@ llvmpipe_flush_frontbuffer(struct pipe_screen *_screen,
 {
    struct llvmpipe_screen *screen = llvmpipe_screen(_screen);
    struct sw_winsys *winsys = screen->winsys;
-   struct llvmpipe_texture *texture = llvmpipe_texture(surface->texture);
+   struct llvmpipe_resource *texture = llvmpipe_resource(surface->texture);
 
    assert(texture->dt);
    if (texture->dt)
@@ -302,8 +301,7 @@ llvmpipe_create_screen(struct sw_winsys *winsys)
    screen->base.context_create = llvmpipe_create_context;
    screen->base.flush_frontbuffer = llvmpipe_flush_frontbuffer;
 
-   llvmpipe_init_screen_texture_funcs(&screen->base);
-   llvmpipe_init_screen_buffer_funcs(&screen->base);
+   llvmpipe_init_screen_resource_funcs(&screen->base);
    llvmpipe_init_screen_fence_funcs(&screen->base);
 
    lp_jit_screen_init(screen);
diff --git a/src/gallium/drivers/llvmpipe/lp_setup.c 
b/src/gallium/drivers/llvmpipe/lp_setup.c
index cd16b6b..7080a0a 100644
--- a/src/gallium/drivers/llvmpipe/lp_setup.c
+++ b/src/gallium/drivers/llvmpipe/lp_setup.c
@@ -39,7 +39,6 @@
 #include "util/u_surface.h"
 #include "lp_scene.h"
 #include "lp_scene_queue.h"
-#include "lp_buffer.h"
 #include "lp_texture.h"
 #include "lp_debug.h"
 #include "lp_fence.h"
@@ -379,11 +378,11 @@ lp_setup_set_fs_functions( struct lp_setup_context *setup,
 
 void
 lp_setup_set_fs_constants(struct lp_setup_context *setup,
-                          struct pipe_buffer *buffer)
+                          struct pipe_resource *buffer)
 {
    LP_DBG(DEBUG_SETUP, "%s %p\n", __FUNCTION__, (void *) buffer);
 
-   pipe_buffer_reference(&setup->constants.current, buffer);
+   pipe_resource_reference(&setup->constants.current, buffer);
 
    setup->dirty |= LP_SETUP_NEW_CONSTANTS;
 }
@@ -467,8 +466,8 @@ lp_setup_set_fragment_sampler_views(struct lp_setup_context 
*setup,
       struct pipe_sampler_view *view = i < num ? views[i] : NULL;
 
       if(view) {
-         struct pipe_texture *tex = view->texture;
-         struct llvmpipe_texture *lp_tex = llvmpipe_texture(tex);
+         struct pipe_resource *tex = view->texture;
+         struct llvmpipe_resource *lp_tex = llvmpipe_resource(tex);
          struct lp_jit_texture *jit_tex;
          jit_tex = &setup->fs.current.jit_context.textures[i];
          jit_tex->width = tex->width0;
@@ -516,8 +515,8 @@ lp_setup_set_fragment_sampler_views(struct lp_setup_context 
*setup,
  * being rendered and the current scene being built.
  */
 unsigned
-lp_setup_is_texture_referenced( const struct lp_setup_context *setup,
-                                const struct pipe_texture *texture )
+lp_setup_is_resource_referenced( const struct lp_setup_context *setup,
+                                const struct pipe_resource *texture )
 {
    unsigned i;
 
@@ -532,7 +531,7 @@ lp_setup_is_texture_referenced( const struct 
lp_setup_context *setup,
 
    /* check textures referenced by the scene */
    for (i = 0; i < Elements(setup->scenes); i++) {
-      if (lp_scene_is_texture_referenced(setup->scenes[i], texture)) {
+      if (lp_scene_is_resource_referenced(setup->scenes[i], texture)) {
          return PIPE_REFERENCED_FOR_READ;
       }
    }
@@ -593,11 +592,11 @@ lp_setup_update_state( struct lp_setup_context *setup )
    }
 
    if(setup->dirty & LP_SETUP_NEW_CONSTANTS) {
-      struct pipe_buffer *buffer = setup->constants.current;
+      struct pipe_resource *buffer = setup->constants.current;
 
       if(buffer) {
-         unsigned current_size = buffer->size;
-         const void *current_data = llvmpipe_buffer(buffer)->data;
+         unsigned current_size = buffer->width0;
+         const void *current_data = llvmpipe_resource(buffer)->data;
 
          /* TODO: copy only the actually used constants? */
 
@@ -667,7 +666,7 @@ lp_setup_destroy( struct lp_setup_context *setup )
 {
    reset_context( setup );
 
-   pipe_buffer_reference(&setup->constants.current, NULL);
+   pipe_resource_reference(&setup->constants.current, NULL);
 
    /* free the scenes in the 'empty' queue */
    while (1) {
diff --git a/src/gallium/drivers/llvmpipe/lp_setup.h 
b/src/gallium/drivers/llvmpipe/lp_setup.h
index 414eaec..85e2984 100644
--- a/src/gallium/drivers/llvmpipe/lp_setup.h
+++ b/src/gallium/drivers/llvmpipe/lp_setup.h
@@ -105,7 +105,7 @@ lp_setup_set_fs_functions( struct lp_setup_context *setup,
 
 void
 lp_setup_set_fs_constants(struct lp_setup_context *setup,
-                          struct pipe_buffer *buffer);
+                          struct pipe_resource *buffer);
 
 
 void
@@ -126,8 +126,8 @@ lp_setup_set_fragment_sampler_views(struct lp_setup_context 
*setup,
                                     struct pipe_sampler_view **views);
 
 unsigned
-lp_setup_is_texture_referenced( const struct lp_setup_context *setup,
-                                const struct pipe_texture *texture );
+lp_setup_is_resource_referenced( const struct lp_setup_context *setup,
+                                const struct pipe_resource *texture );
 
 void
 lp_setup_set_flatshade_first( struct lp_setup_context *setup, 
diff --git a/src/gallium/drivers/llvmpipe/lp_setup_context.h 
b/src/gallium/drivers/llvmpipe/lp_setup_context.h
index 464fb36..92c3087 100644
--- a/src/gallium/drivers/llvmpipe/lp_setup_context.h
+++ b/src/gallium/drivers/llvmpipe/lp_setup_context.h
@@ -115,7 +115,7 @@ struct lp_setup_context
 
    /** fragment shader constants */
    struct {
-      struct pipe_buffer *current;
+      struct pipe_resource *current;
       unsigned stored_size;
       const void *stored_data;
    } constants;
diff --git a/src/gallium/drivers/llvmpipe/lp_state.h 
b/src/gallium/drivers/llvmpipe/lp_state.h
index 13cd934..f3da390 100644
--- a/src/gallium/drivers/llvmpipe/lp_state.h
+++ b/src/gallium/drivers/llvmpipe/lp_state.h
@@ -169,7 +169,7 @@ void llvmpipe_set_clip_state( struct pipe_context *,
 
 void llvmpipe_set_constant_buffer(struct pipe_context *,
                                   uint shader, uint index,
-                                  struct pipe_buffer *buf);
+                                  struct pipe_resource *buf);
 
 void *llvmpipe_create_fs_state(struct pipe_context *,
                                const struct pipe_shader_state *);
@@ -203,7 +203,7 @@ llvmpipe_set_vertex_sampler_views(struct pipe_context *,
 
 struct pipe_sampler_view *
 llvmpipe_create_sampler_view(struct pipe_context *pipe,
-                            struct pipe_texture *texture,
+                            struct pipe_resource *texture,
                             const struct pipe_sampler_view *templ);
 
 void
@@ -226,12 +226,12 @@ void llvmpipe_draw_arrays(struct pipe_context *pipe, 
unsigned mode,
                             unsigned start, unsigned count);
 
 void llvmpipe_draw_elements(struct pipe_context *pipe,
-                              struct pipe_buffer *indexBuffer,
+                              struct pipe_resource *indexBuffer,
                               unsigned indexSize,
                               unsigned mode, unsigned start, unsigned count);
 void
 llvmpipe_draw_range_elements(struct pipe_context *pipe,
-                             struct pipe_buffer *indexBuffer,
+                             struct pipe_resource *indexBuffer,
                              unsigned indexSize,
                              unsigned min_index,
                              unsigned max_index,
diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c 
b/src/gallium/drivers/llvmpipe/lp_state_fs.c
index b75ca28..a8b2c18 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_fs.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c
@@ -85,7 +85,6 @@
 #include "gallivm/lp_bld_swizzle.h"
 #include "gallivm/lp_bld_flow.h"
 #include "gallivm/lp_bld_debug.h"
-#include "lp_buffer.h"
 #include "lp_context.h"
 #include "lp_debug.h"
 #include "lp_perf.h"
@@ -1012,11 +1011,11 @@ llvmpipe_delete_fs_state(struct pipe_context *pipe, 
void *fs)
 void
 llvmpipe_set_constant_buffer(struct pipe_context *pipe,
                              uint shader, uint index,
-                             struct pipe_buffer *constants)
+                             struct pipe_resource *constants)
 {
    struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
-   unsigned size = constants ? constants->size : 0;
-   const void *data = constants ? llvmpipe_buffer(constants)->data : NULL;
+   unsigned size = constants ? constants->width0 : 0;
+   const void *data = constants ? llvmpipe_resource(constants)->data : NULL;
 
    assert(shader < PIPE_SHADER_TYPES);
    assert(index == 0);
@@ -1027,7 +1026,7 @@ llvmpipe_set_constant_buffer(struct pipe_context *pipe,
    draw_flush(llvmpipe->draw);
 
    /* note: reference counting */
-   pipe_buffer_reference(&llvmpipe->constants[shader], constants);
+   pipe_resource_reference(&llvmpipe->constants[shader], constants);
 
    if(shader == PIPE_SHADER_VERTEX) {
       draw_set_mapped_constant_buffer(llvmpipe->draw, PIPE_SHADER_VERTEX, 0,
diff --git a/src/gallium/drivers/llvmpipe/lp_state_sampler.c 
b/src/gallium/drivers/llvmpipe/lp_state_sampler.c
index 2645441..3552ff5 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_sampler.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_sampler.c
@@ -165,7 +165,7 @@ llvmpipe_set_vertex_sampler_views(struct pipe_context *pipe,
 
 struct pipe_sampler_view *
 llvmpipe_create_sampler_view(struct pipe_context *pipe,
-                            struct pipe_texture *texture,
+                            struct pipe_resource *texture,
                             const struct pipe_sampler_view *templ)
 {
    struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view);
@@ -174,7 +174,7 @@ llvmpipe_create_sampler_view(struct pipe_context *pipe,
       *view = *templ;
       view->reference.count = 1;
       view->texture = NULL;
-      pipe_texture_reference(&view->texture, texture);
+      pipe_resource_reference(&view->texture, texture);
       view->context = pipe;
    }
 
@@ -186,7 +186,7 @@ void
 llvmpipe_sampler_view_destroy(struct pipe_context *pipe,
                               struct pipe_sampler_view *view)
 {
-   pipe_texture_reference(&view->texture, NULL);
+   pipe_resource_reference(&view->texture, NULL);
    FREE(view);
 }
 
diff --git a/src/gallium/drivers/llvmpipe/lp_texture.c 
b/src/gallium/drivers/llvmpipe/lp_texture.c
index 5f75078..779b486 100644
--- a/src/gallium/drivers/llvmpipe/lp_texture.c
+++ b/src/gallium/drivers/llvmpipe/lp_texture.c
@@ -37,10 +37,12 @@
 #include "util/u_format.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
+#include "util/u_transfer.h"
 
 #include "lp_context.h"
 #include "lp_screen.h"
 #include "lp_texture.h"
+#include "lp_setup.h"
 #include "lp_tile_size.h"
 #include "state_tracker/sw_winsys.h"
 
@@ -50,10 +52,10 @@
  * Simple, maximally packed layout.
  */
 static boolean
-llvmpipe_texture_layout(struct llvmpipe_screen *screen,
-                        struct llvmpipe_texture *lpt)
+llvmpipe_resource_layout(struct llvmpipe_screen *screen,
+                        struct llvmpipe_resource *lpt)
 {
-   struct pipe_texture *pt = &lpt->base;
+   struct pipe_resource *pt = &lpt->base;
    unsigned level;
    unsigned width = pt->width0;
    unsigned height = pt->height0;
@@ -91,7 +93,7 @@ llvmpipe_texture_layout(struct llvmpipe_screen *screen,
 
 static boolean
 llvmpipe_displaytarget_layout(struct llvmpipe_screen *screen,
-                              struct llvmpipe_texture *lpt)
+                              struct llvmpipe_resource *lpt)
 {
    struct sw_winsys *winsys = screen->winsys;
 
@@ -111,12 +113,12 @@ llvmpipe_displaytarget_layout(struct llvmpipe_screen 
*screen,
 }
 
 
-static struct pipe_texture *
-llvmpipe_texture_create(struct pipe_screen *_screen,
-                        const struct pipe_texture *templat)
+static struct pipe_resource *
+llvmpipe_resource_create(struct pipe_screen *_screen,
+                        const struct pipe_resource *templat)
 {
    struct llvmpipe_screen *screen = llvmpipe_screen(_screen);
-   struct llvmpipe_texture *lpt = CALLOC_STRUCT(llvmpipe_texture);
+   struct llvmpipe_resource *lpt = CALLOC_STRUCT(llvmpipe_resource);
    if (!lpt)
       return NULL;
 
@@ -131,7 +133,7 @@ llvmpipe_texture_create(struct pipe_screen *_screen,
          goto fail;
    }
    else {
-      if (!llvmpipe_texture_layout(screen, lpt))
+      if (!llvmpipe_resource_layout(screen, lpt))
          goto fail;
    }
     
@@ -144,10 +146,11 @@ llvmpipe_texture_create(struct pipe_screen *_screen,
 
 
 static void
-llvmpipe_texture_destroy(struct pipe_texture *pt)
+llvmpipe_resource_destroy(struct pipe_screen *pscreen,
+                         struct pipe_resource *pt)
 {
-   struct llvmpipe_screen *screen = llvmpipe_screen(pt->screen);
-   struct llvmpipe_texture *lpt = llvmpipe_texture(pt);
+   struct llvmpipe_screen *screen = llvmpipe_screen(pscreen);
+   struct llvmpipe_resource *lpt = llvmpipe_resource(pt);
 
    if (lpt->dt) {
       /* display target */
@@ -165,11 +168,11 @@ llvmpipe_texture_destroy(struct pipe_texture *pt)
 
 static struct pipe_surface *
 llvmpipe_get_tex_surface(struct pipe_screen *screen,
-                         struct pipe_texture *pt,
+                         struct pipe_resource *pt,
                          unsigned face, unsigned level, unsigned zslice,
                          unsigned usage)
 {
-   struct llvmpipe_texture *lpt = llvmpipe_texture(pt);
+   struct llvmpipe_resource *lpt = llvmpipe_resource(pt);
    struct pipe_surface *ps;
 
    assert(level <= pt->last_level);
@@ -177,7 +180,7 @@ llvmpipe_get_tex_surface(struct pipe_screen *screen,
    ps = CALLOC_STRUCT(pipe_surface);
    if (ps) {
       pipe_reference_init(&ps->reference, 1);
-      pipe_texture_reference(&ps->texture, pt);
+      pipe_resource_reference(&ps->texture, pt);
       ps->format = pt->format;
       ps->width = u_minify(pt->width0, level);
       ps->height = u_minify(pt->height0, level);
@@ -210,7 +213,7 @@ llvmpipe_get_tex_surface(struct pipe_screen *screen,
 
       /* XXX shouldn't that rather be
          tex_height = align(ps->height, 2);
-         to account for alignment done in llvmpipe_texture_layout ?
+         to account for alignment done in llvmpipe_resource_layout ?
       */
       if (pt->target == PIPE_TEXTURE_CUBE) {
          unsigned tex_height = ps->height;
@@ -237,55 +240,56 @@ llvmpipe_tex_surface_destroy(struct pipe_surface *surf)
     * where it would happen.  For llvmpipe, nothing to do.
     */
    assert(surf->texture);
-   pipe_texture_reference(&surf->texture, NULL);
+   pipe_resource_reference(&surf->texture, NULL);
    FREE(surf);
 }
 
 
 static struct pipe_transfer *
 llvmpipe_get_transfer(struct pipe_context *pipe,
-                          struct pipe_texture *texture,
-                          unsigned face, unsigned level, unsigned zslice,
-                          enum pipe_transfer_usage usage,
-                          unsigned x, unsigned y, unsigned w, unsigned h)
+                     struct pipe_resource *resource,
+                     struct pipe_subresource sr,
+                     enum pipe_transfer_usage usage,
+                     const struct pipe_box *box)
 {
-   struct llvmpipe_texture *lptex = llvmpipe_texture(texture);
+   struct llvmpipe_resource *lptex = llvmpipe_resource(resource);
    struct llvmpipe_transfer *lpt;
 
-   assert(texture);
-   assert(level <= texture->last_level);
+   assert(resource);
+   assert(sr.level <= resource->last_level);
 
    lpt = CALLOC_STRUCT(llvmpipe_transfer);
    if (lpt) {
       struct pipe_transfer *pt = &lpt->base;
-      pipe_texture_reference(&pt->texture, texture);
-      pt->x = x;
-      pt->y = y;
-      pt->width = align(w, TILE_SIZE);
-      pt->height = align(h, TILE_SIZE);
-      pt->stride = lptex->stride[level];
+      pipe_resource_reference(&pt->resource, resource);
+      pt->box = *box;
+      pt->stride = lptex->stride[sr.level];
       pt->usage = usage;
-      pt->face = face;
-      pt->level = level;
-      pt->zslice = zslice;
 
-      lpt->offset = lptex->level_offset[level];
+      /* XXX: this is bogus - the caller should be doing this, not
+       * imposing it on all transfers.
+       */
+      pt->box.width = align(pt->box.width, TILE_SIZE);
+      pt->box.height = align(pt->box.height, TILE_SIZE);
+
+      pt->stride = lptex->stride[sr.level];
+      lpt->offset = lptex->level_offset[sr.level];
 
       /* XXX shouldn't that rather be
-         tex_height = align(u_minify(texture->height0, level), 2)
-         to account for alignment done in llvmpipe_texture_layout ?
+         tex_height = align(u_minify(resource->height0, level), 2)
+         to account for alignment done in llvmpipe_resource_layout ?
       */
-      if (texture->target == PIPE_TEXTURE_CUBE) {
-         unsigned tex_height = u_minify(texture->height0, level);
-         lpt->offset += face *  util_format_get_nblocksy(texture->format, 
tex_height) * pt->stride;
+      if (resource->target == PIPE_TEXTURE_CUBE) {
+         unsigned tex_height = u_minify(resource->height0, sr.level);
+         lpt->offset += sr.face *  util_format_get_nblocksy(resource->format, 
tex_height) * pt->stride;
       }
-      else if (texture->target == PIPE_TEXTURE_3D) {
-         unsigned tex_height = u_minify(texture->height0, level);
-         lpt->offset += zslice * util_format_get_nblocksy(texture->format, 
tex_height) * pt->stride;
+      else if (resource->target == PIPE_TEXTURE_3D) {
+         unsigned tex_height = u_minify(resource->height0, sr.level);
+         lpt->offset += box->z * util_format_get_nblocksy(resource->format, 
tex_height) * pt->stride;
       }
       else {
-         assert(face == 0);
-         assert(zslice == 0);
+         assert(sr.face == 0);
+         assert(box->z == 0);
       }
       return pt;
    }
@@ -301,8 +305,8 @@ llvmpipe_transfer_destroy(struct pipe_context *pipe,
     * needed post-processing to put them into hardware layout, this is
     * where it would happen.  For llvmpipe, nothing to do.
     */
-   assert (transfer->texture);
-   pipe_texture_reference(&transfer->texture, NULL);
+   assert (transfer->resource);
+   pipe_resource_reference(&transfer->resource, NULL);
    FREE(transfer);
 }
 
@@ -313,11 +317,11 @@ llvmpipe_transfer_map( struct pipe_context *pipe,
 {
    struct llvmpipe_screen *screen = llvmpipe_screen(pipe->screen);
    ubyte *map, *xfer_map;
-   struct llvmpipe_texture *lpt;
+   struct llvmpipe_resource *lpt;
    enum pipe_format format;
 
-   assert(transfer->texture);
-   lpt = llvmpipe_texture(transfer->texture);
+   assert(transfer->resource);
+   lpt = llvmpipe_resource(transfer->resource);
    format = lpt->base.format;
 
    if (lpt->dt) {
@@ -325,27 +329,27 @@ llvmpipe_transfer_map( struct pipe_context *pipe,
       struct sw_winsys *winsys = screen->winsys;
 
       map = winsys->displaytarget_map(winsys, lpt->dt,
-                                      pipe_transfer_buffer_flags(transfer));
+                                      transfer->usage);
       if (map == NULL)
          return NULL;
    }
    else {
-      /* regular texture */
+      /* regular resource */
       map = lpt->data;
    }
 
    /* May want to different things here depending on read/write nature
     * of the map:
     */
-   if (transfer->texture && (transfer->usage & PIPE_TRANSFER_WRITE)) {
-      /* Do something to notify sharing contexts of a texture change.
+   if (transfer->resource && (transfer->usage & PIPE_TRANSFER_WRITE)) {
+      /* Do something to notify sharing contexts of a resource change.
        */
       screen->timestamp++;
    }
    
    xfer_map = map + llvmpipe_transfer(transfer)->offset +
-      transfer->y / util_format_get_blockheight(format) * transfer->stride +
-      transfer->x / util_format_get_blockwidth(format) * 
util_format_get_blocksize(format);
+      transfer->box.y / util_format_get_blockheight(format) * transfer->stride 
+
+      transfer->box.x / util_format_get_blockwidth(format) * 
util_format_get_blocksize(format);
    /*printf("map = %p  xfer map = %p\n", map, xfer_map);*/
    return xfer_map;
 }
@@ -356,10 +360,10 @@ llvmpipe_transfer_unmap(struct pipe_context *pipe,
                         struct pipe_transfer *transfer)
 {
    struct llvmpipe_screen *lp_screen = llvmpipe_screen(pipe->screen);
-   struct llvmpipe_texture *lpt;
+   struct llvmpipe_resource *lpt;
 
-   assert(transfer->texture);
-   lpt = llvmpipe_texture(transfer->texture);
+   assert(transfer->resource);
+   lpt = llvmpipe_resource(transfer->resource);
 
    if (lpt->dt) {
       /* display target */
@@ -368,12 +372,56 @@ llvmpipe_transfer_unmap(struct pipe_context *pipe,
    }
 }
 
+static unsigned int
+llvmpipe_is_resource_referenced( struct pipe_context *pipe,
+                               struct pipe_resource *presource,
+                               unsigned face, unsigned level)
+{
+   struct llvmpipe_context *llvmpipe = llvmpipe_context( pipe );
+
+   if (presource->target == PIPE_BUFFER)
+      return PIPE_UNREFERENCED;
+   
+   return lp_setup_is_resource_referenced(llvmpipe->setup, presource);
+}
+
+
+
+/**
+ * Create buffer which wraps user-space data.
+ */
+static struct pipe_resource *
+llvmpipe_user_buffer_create(struct pipe_screen *screen,
+                            void *ptr,
+                            unsigned bytes,
+                           unsigned usage)
+{
+   struct llvmpipe_resource *buffer;
+
+   buffer = CALLOC_STRUCT(llvmpipe_resource);
+   if(!buffer)
+      return NULL;
+
+   pipe_reference_init(&buffer->base.reference, 1);
+   buffer->base.screen = screen;
+   buffer->base.format = PIPE_FORMAT_R8_UNORM; /* ?? */
+   buffer->base.usage = PIPE_BUFFER_USAGE_CPU_READ | usage;
+   buffer->base.width0 = bytes;
+   buffer->base.height0 = 1;
+   buffer->base.depth0 = 1;
+   buffer->userBuffer = TRUE;
+   buffer->data = ptr;
+
+   return &buffer->base;
+}
+
 
 void
-llvmpipe_init_screen_texture_funcs(struct pipe_screen *screen)
+llvmpipe_init_screen_resource_funcs(struct pipe_screen *screen)
 {
-   screen->texture_create = llvmpipe_texture_create;
-   screen->texture_destroy = llvmpipe_texture_destroy;
+   screen->resource_create = llvmpipe_resource_create;
+   screen->resource_destroy = llvmpipe_resource_destroy;
+   screen->user_buffer_create = llvmpipe_user_buffer_create;
 
    screen->get_tex_surface = llvmpipe_get_tex_surface;
    screen->tex_surface_destroy = llvmpipe_tex_surface_destroy;
@@ -381,10 +429,14 @@ llvmpipe_init_screen_texture_funcs(struct pipe_screen 
*screen)
 
 
 void
-llvmpipe_init_context_texture_funcs(struct pipe_context *pipe)
+llvmpipe_init_context_resource_funcs(struct pipe_context *pipe)
 {
    pipe->get_transfer = llvmpipe_get_transfer;
    pipe->transfer_destroy = llvmpipe_transfer_destroy;
    pipe->transfer_map = llvmpipe_transfer_map;
    pipe->transfer_unmap = llvmpipe_transfer_unmap;
+   pipe->is_resource_referenced = llvmpipe_is_resource_referenced;
+ 
+   pipe->transfer_flush_region = u_default_transfer_flush_region;
+   pipe->transfer_inline_write = u_default_transfer_inline_write;
 }
diff --git a/src/gallium/drivers/llvmpipe/lp_texture.h 
b/src/gallium/drivers/llvmpipe/lp_texture.h
index 94b667a..9306a25 100644
--- a/src/gallium/drivers/llvmpipe/lp_texture.h
+++ b/src/gallium/drivers/llvmpipe/lp_texture.h
@@ -43,9 +43,9 @@ struct llvmpipe_context;
 struct sw_displaytarget;
 
 
-struct llvmpipe_texture
+struct llvmpipe_resource
 {
-   struct pipe_texture base;
+   struct pipe_resource base;
 
    unsigned long level_offset[LP_MAX_TEXTURE_2D_LEVELS];
    unsigned stride[LP_MAX_TEXTURE_2D_LEVELS];
@@ -61,6 +61,7 @@ struct llvmpipe_texture
     */
    void *data;
 
+   boolean userBuffer;  /** Is this a user-space buffer? */
    unsigned timestamp;
 };
 
@@ -74,17 +75,17 @@ struct llvmpipe_transfer
 
 
 /** cast wrappers */
-static INLINE struct llvmpipe_texture *
-llvmpipe_texture(struct pipe_texture *pt)
+static INLINE struct llvmpipe_resource *
+llvmpipe_resource(struct pipe_resource *pt)
 {
-   return (struct llvmpipe_texture *) pt;
+   return (struct llvmpipe_resource *) pt;
 }
 
 
-static INLINE const struct llvmpipe_texture *
-llvmpipe_texture_const(const struct pipe_texture *pt)
+static INLINE const struct llvmpipe_resource *
+llvmpipe_resource_const(const struct pipe_resource *pt)
 {
-   return (const struct llvmpipe_texture *) pt;
+   return (const struct llvmpipe_resource *) pt;
 }
 
 
@@ -95,10 +96,7 @@ llvmpipe_transfer(struct pipe_transfer *pt)
 }
 
 
-extern void
-llvmpipe_init_screen_texture_funcs(struct pipe_screen *screen);
-
-extern void
-llvmpipe_init_context_texture_funcs(struct pipe_context *pipe);
+void llvmpipe_init_screen_resource_funcs(struct pipe_screen *screen);
+void llvmpipe_init_context_resource_funcs(struct pipe_context *pipe);
 
 #endif /* LP_TEXTURE_H */

_______________________________________________
mesa-commit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to