From: Keith Whitwell Date: Mon, 6 Aug 2007 09:15:30 +0000 (+0100) Subject: Add pipe buffer managment functions. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=95794abec4bdc5cda9f2e7d139a70c3acf372fe3;p=mesa.git Add pipe buffer managment functions. The state_tracker driver needs these to implement, eg. pixel buffer objects, vertex buffer objects. --- diff --git a/src/mesa/drivers/dri/i915pipe/intel_blit.c b/src/mesa/drivers/dri/i915pipe/intel_blit.c index 5d9cb0cf0f4..8e878f00887 100644 --- a/src/mesa/drivers/dri/i915pipe/intel_blit.c +++ b/src/mesa/drivers/dri/i915pipe/intel_blit.c @@ -391,161 +391,4 @@ intelEmitCopyBlit(struct intel_context *intel, } -/** - * Use blitting to clear the renderbuffers named by 'flags'. - * Note: we can't use the ctx->DrawBuffer->_ColorDrawBufferMask field - * since that might include software renderbuffers or renderbuffers - * which we're clearing with triangles. - * \param mask bitmask of BUFFER_BIT_* values indicating buffers to clear - */ -void -intelClearWithBlit(GLcontext * ctx, GLbitfield mask) -{ - struct intel_context *intel = intel_context(ctx); - struct gl_framebuffer *fb = ctx->DrawBuffer; - GLuint clear_depth; - GLbitfield skipBuffers = 0; - BATCH_LOCALS; - - DBG("%s %x\n", __FUNCTION__, mask); - /* - * Compute values for clearing the buffers. - */ - clear_depth = 0; - if (mask & BUFFER_BIT_DEPTH) { - clear_depth = (GLuint) (fb->_DepthMax * ctx->Depth.Clear); - } - if (mask & BUFFER_BIT_STENCIL) { - clear_depth |= (ctx->Stencil.Clear & 0xff) << 24; - } - - /* If clearing both depth and stencil, skip BUFFER_BIT_STENCIL in - * the loop below. - */ - if ((mask & BUFFER_BIT_DEPTH) && (mask & BUFFER_BIT_STENCIL)) { - skipBuffers = BUFFER_BIT_STENCIL; - } - - /* XXX Move this flush/lock into the following conditional? */ - intelFlush(&intel->ctx); - LOCK_HARDWARE(intel); - - if (intel->numClipRects) { - GLint cx, cy, cw, ch; - drm_clip_rect_t b; - - /* Get clear bounds after locking */ - cx = fb->_Xmin; - cy = fb->_Ymin; - cw = fb->_Xmax - cx; - ch = fb->_Ymax - cy; - - if (fb->Name == 0) { - /* clearing a window */ - /* flip top to bottom */ - b.x1 = cx; - b.y1 = fb->Height - cy - ch; - b.x2 = b.x1 + cw; - b.y2 = b.y1 + ch; - } - else { - /* clearing FBO */ - b.x1 = cx; - b.y1 = cy; - b.x2 = b.x1 + cw; - b.y2 = b.y1 + ch; - /* no change to mask */ - } - - { - GLuint buf; - GLuint clearMask = mask; /* use copy, since we modify it below */ - GLboolean all = (cw == fb->Width && ch == fb->Height); - - DBG("clear %d,%d..%d,%d, mask %x\n", - b.x1, b.y1, b.x2, b.y2, mask); - - /* Loop over all renderbuffers */ - for (buf = 0; buf < BUFFER_COUNT && clearMask; buf++) { - const GLbitfield bufBit = 1 << buf; - if ((clearMask & bufBit) && !(bufBit & skipBuffers)) { - /* OK, clear this renderbuffer */ - struct pipe_region *irb_region = - intel_get_rb_region(fb, buf); - struct _DriBufferObject *write_buffer = - intel->pipe->region_buffer(intel->pipe, irb_region, - all ? INTEL_WRITE_FULL : - INTEL_WRITE_PART); - - GLuint clearVal; - GLint pitch, cpp; - GLuint BR13, CMD; - - ASSERT(irb_region); - - pitch = irb_region->pitch; - cpp = irb_region->cpp; - - DBG("%s dst:buf(%p)/%d+%d %d,%d sz:%dx%d\n", - __FUNCTION__, - irb_region->buffer, (pitch * cpp), - irb_region->draw_offset, - b.x1, b.y1, b.x2 - b.x1, b.y2 - b.y1); - - - /* Setup the blit command */ - if (cpp == 4) { - BR13 = (0xF0 << 16) | (pitch * cpp) | (1 << 24) | (1 << 25); - if (buf == BUFFER_DEPTH || buf == BUFFER_STENCIL) { - CMD = XY_COLOR_BLT_CMD; - if (clearMask & BUFFER_BIT_DEPTH) - CMD |= XY_COLOR_BLT_WRITE_RGB; - if (clearMask & BUFFER_BIT_STENCIL) - CMD |= XY_COLOR_BLT_WRITE_ALPHA; - } - else { - /* clearing RGBA */ - CMD = (XY_COLOR_BLT_CMD | - XY_COLOR_BLT_WRITE_ALPHA | - XY_COLOR_BLT_WRITE_RGB); - } - } - else { - ASSERT(cpp == 2 || cpp == 0); - BR13 = (0xF0 << 16) | (pitch * cpp) | (1 << 24); - CMD = XY_COLOR_BLT_CMD; - } - - if (buf == BUFFER_DEPTH || buf == BUFFER_STENCIL) { - clearVal = clear_depth; - } - else { - clearVal = (cpp == 4) - ? intel->ClearColor8888 : intel->ClearColor565; - } - /* - _mesa_debug(ctx, "hardware blit clear buf %d rb id %d\n", - buf, irb->Base.Name); - */ - intel_wait_flips(intel, INTEL_BATCH_NO_CLIPRECTS); - - BEGIN_BATCH(6, INTEL_BATCH_NO_CLIPRECTS); - OUT_BATCH(CMD); - OUT_BATCH(BR13); - OUT_BATCH((b.y1 << 16) | b.x1); - OUT_BATCH((b.y2 << 16) | b.x2); - OUT_RELOC(write_buffer, DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_WRITE, - DRM_BO_MASK_MEM | DRM_BO_FLAG_WRITE, - irb_region->draw_offset); - OUT_BATCH(clearVal); - ADVANCE_BATCH(); - clearMask &= ~bufBit; /* turn off bit, for faster loop exit */ - } - } - } - intel_batchbuffer_flush(intel->batch); - } - - UNLOCK_HARDWARE(intel); -} diff --git a/src/mesa/drivers/dri/i915pipe/intel_fbo.c b/src/mesa/drivers/dri/i915pipe/intel_fbo.c index 9eee5cce457..267c12fd4b7 100644 --- a/src/mesa/drivers/dri/i915pipe/intel_fbo.c +++ b/src/mesa/drivers/dri/i915pipe/intel_fbo.c @@ -40,7 +40,6 @@ #include "intel_depthstencil.h" #include "intel_fbo.h" #include "intel_mipmap_tree.h" -#include "intel_regions.h" #include "intel_tex.h" #include "pipe/p_context.h" diff --git a/src/mesa/drivers/dri/i915pipe/intel_softpipe.c b/src/mesa/drivers/dri/i915pipe/intel_softpipe.c index 4591730a02e..ef477443586 100644 --- a/src/mesa/drivers/dri/i915pipe/intel_softpipe.c +++ b/src/mesa/drivers/dri/i915pipe/intel_softpipe.c @@ -54,15 +54,15 @@ struct intel_softpipe_winsys { * buffer pointer... */ static inline struct _DriBufferObject * -dri_bo( struct softpipe_buffer_handle *bo ) +dri_bo( struct pipe_buffer_handle *bo ) { return (struct _DriBufferObject *)bo; } -static inline struct softpipe_buffer_handle * +static inline struct pipe_buffer_handle * pipe_bo( struct _DriBufferObject *bo ) { - return (struct softpipe_buffer_handle *)bo; + return (struct pipe_buffer_handle *)bo; } /* Turn a softpipe winsys into an intel/softpipe winsys: @@ -77,36 +77,39 @@ intel_softpipe_winsys( struct softpipe_winsys *sws ) /* Most callbacks map direcly onto dri_bufmgr operations: */ static void *intel_buffer_map(struct softpipe_winsys *sws, - struct softpipe_buffer_handle *buf ) + struct pipe_buffer_handle *buf ) { return driBOMap( dri_bo(buf), DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0 ); } static void intel_buffer_unmap(struct softpipe_winsys *sws, - struct softpipe_buffer_handle *buf) + struct pipe_buffer_handle *buf) { driBOUnmap( dri_bo(buf) ); } -static struct softpipe_buffer_handle * +static struct pipe_buffer_handle * intel_buffer_reference(struct softpipe_winsys *sws, - struct softpipe_buffer_handle *buf) + struct pipe_buffer_handle *buf) { return pipe_bo( driBOReference( dri_bo(buf) ) ); } static void intel_buffer_unreference(struct softpipe_winsys *sws, - struct softpipe_buffer_handle *buf) + struct pipe_buffer_handle **buf) { - driBOUnReference( dri_bo(buf) ); + if (*buf) { + driBOUnReference( dri_bo(*buf) ); + *buf = NULL; + } } /* Grabs the hardware lock! */ static void intel_buffer_data(struct softpipe_winsys *sws, - struct softpipe_buffer_handle *buf, + struct pipe_buffer_handle *buf, unsigned size, const void *data ) { struct intel_context *intel = intel_softpipe_winsys(sws)->intel; @@ -117,7 +120,7 @@ static void intel_buffer_data(struct softpipe_winsys *sws, } static void intel_buffer_subdata(struct softpipe_winsys *sws, - struct softpipe_buffer_handle *buf, + struct pipe_buffer_handle *buf, unsigned long offset, unsigned long size, const void *data) @@ -126,7 +129,7 @@ static void intel_buffer_subdata(struct softpipe_winsys *sws, } static void intel_buffer_get_subdata(struct softpipe_winsys *sws, - struct softpipe_buffer_handle *buf, + struct pipe_buffer_handle *buf, unsigned long offset, unsigned long size, void *data) @@ -137,9 +140,8 @@ static void intel_buffer_get_subdata(struct softpipe_winsys *sws, /* Softpipe has no concept of pools. We choose the tex/region pool * for all buffers. */ -static struct softpipe_buffer_handle * +static struct pipe_buffer_handle * intel_create_buffer(struct softpipe_winsys *sws, - const char *name, unsigned alignment) { struct intel_context *intel = intel_softpipe_winsys(sws)->intel; @@ -147,7 +149,7 @@ intel_create_buffer(struct softpipe_winsys *sws, LOCK_HARDWARE( intel ); driGenBuffers( intel->intelScreen->regionPool, - name, 1, &buffer, alignment, 0, 0 ); + "softpipe buffer", 1, &buffer, alignment, 0, 0 ); UNLOCK_HARDWARE( intel ); return pipe_bo(buffer); diff --git a/src/mesa/drivers/dri/i915pipe/intel_surface.c b/src/mesa/drivers/dri/i915pipe/intel_surface.c index 78ed9957945..3fa40271c83 100644 --- a/src/mesa/drivers/dri/i915pipe/intel_surface.c +++ b/src/mesa/drivers/dri/i915pipe/intel_surface.c @@ -10,7 +10,6 @@ #include "intel_context.h" #include "intel_buffers.h" -#include "intel_regions.h" #include "intel_fbo.h" #include "pipe/p_state.h" diff --git a/src/mesa/drivers/dri/i915pipe/intel_tex_image.c b/src/mesa/drivers/dri/i915pipe/intel_tex_image.c index b4e440e49a1..9f8e115533c 100644 --- a/src/mesa/drivers/dri/i915pipe/intel_tex_image.c +++ b/src/mesa/drivers/dri/i915pipe/intel_tex_image.c @@ -225,9 +225,11 @@ try_pbo_upload(struct intel_context *intel, { struct _DriBufferObject *src_buffer = intel_bufferobj_buffer(intel, pbo, INTEL_READ); + + /* Temporary hack: cast to _DriBufferObject: + */ struct _DriBufferObject *dst_buffer = - intel->pipe->region_buffer(intel->pipe, intelImage->mt->region, - INTEL_WRITE_FULL); + (struct _DriBufferObject *)intelImage->mt->region->buffer; intelEmitCopyBlit(intel, diff --git a/src/mesa/pipe/Makefile.template b/src/mesa/pipe/Makefile.template index 7c64981d7b0..84b4dcd13a8 100644 --- a/src/mesa/pipe/Makefile.template +++ b/src/mesa/pipe/Makefile.template @@ -39,6 +39,7 @@ $(LIBNAME): $(OBJECTS) Makefile $(TOP)/src/mesa/pipe/Makefile.template depend: $(C_SOURCES) $(ASM_SOURCES) $(SYMLINKS) + rm -f depend touch depend $(MKDEP) $(MKDEP_OPTIONS) $(DRIVER_DEFINES) $(INCLUDES) $(C_SOURCES) \ $(ASM_SOURCES) 2> /dev/null diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 92670c77337..76a25935672 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -169,9 +169,44 @@ struct pipe_context { GLuint width, GLuint height, GLuint value); - struct _DriBufferObject *(*region_buffer)(struct pipe_context *pipe, - struct pipe_region *region, - GLuint flag); + + /* Buffer management functions need to be exposed as well. A pipe + * buffer may be used as a texture, render target or vertex/index + * buffer, or some combination according to flags. + */ + + struct pipe_buffer_handle *(*create_buffer)(struct pipe_context *pipe, + unsigned alignment, + unsigned flags ); + + void *(*buffer_map)( struct pipe_context *pipe, + struct pipe_buffer_handle *buf, + unsigned flags ); + + void (*buffer_unmap)( struct pipe_context *pipe, + struct pipe_buffer_handle *buf ); + + struct pipe_buffer_handle *(*buffer_reference)( struct pipe_context *pipe, + struct pipe_buffer_handle *buf ); + + void (*buffer_unreference)( struct pipe_context *pipe, + struct pipe_buffer_handle **buf ); + + void (*buffer_data)(struct pipe_context *pipe, + struct pipe_buffer_handle *buf, + unsigned size, const void *data ); + + void (*buffer_subdata)(struct pipe_context *pipe, + struct pipe_buffer_handle *buf, + unsigned long offset, + unsigned long size, + const void *data); + + void (*buffer_get_subdata)(struct pipe_context *pipe, + struct pipe_buffer_handle *buf, + unsigned long offset, + unsigned long size, + void *data); }; diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 3be1010007a..518110d4470 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -292,4 +292,17 @@ struct pipe_texture_object }; +struct pipe_buffer_handle; + +#define PIPE_BUFFER_FLAG_READ 0x1 +#define PIPE_BUFFER_FLAG_WRITE 0x2 + +#define PIPE_BUFFER_USE_TEXTURE 0x1 +#define PIPE_BUFFER_USE_VERTEX_BUFFER 0x2 +#define PIPE_BUFFER_USE_INDEX_BUFFER 0x4 +#define PIPE_BUFFER_USE_RENDER_TARGET 0x8 + + + + #endif diff --git a/src/mesa/pipe/softpipe/Makefile b/src/mesa/pipe/softpipe/Makefile index 04464154e75..0eacfa2182a 100644 --- a/src/mesa/pipe/softpipe/Makefile +++ b/src/mesa/pipe/softpipe/Makefile @@ -5,6 +5,7 @@ include $(TOP)/configs/current LIBNAME = softpipe DRIVER_SOURCES = \ + sp_buffer.c \ sp_clear.c \ sp_context.c \ sp_prim_setup.c \ diff --git a/src/mesa/pipe/softpipe/sp_buffer.c b/src/mesa/pipe/softpipe/sp_buffer.c new file mode 100644 index 00000000000..f3a47184496 --- /dev/null +++ b/src/mesa/pipe/softpipe/sp_buffer.c @@ -0,0 +1,119 @@ +/************************************************************************** + * + * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA + * 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 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 + * THE COPYRIGHT HOLDERS, AUTHORS 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * + **************************************************************************/ +/* + * Authors: Keith Whitwell + */ + +#include +#include "sp_context.h" +#include "sp_winsys.h" + + + +/* Most callbacks map direcly onto winsys operations: + */ +static struct pipe_buffer_handle * +sp_create_buffer(struct pipe_context *pipe, + unsigned alignment, + unsigned flags) +{ + struct softpipe_context *sp = softpipe_context( pipe ); + return sp->winsys->create_buffer( sp->winsys, alignment ); +} + +static void *sp_buffer_map(struct pipe_context *pipe, + struct pipe_buffer_handle *buf, + unsigned flags ) +{ + struct softpipe_context *sp = softpipe_context( pipe ); + return sp->winsys->buffer_map( sp->winsys, buf ); +} + +static void sp_buffer_unmap(struct pipe_context *pipe, + struct pipe_buffer_handle *buf) +{ + struct softpipe_context *sp = softpipe_context( pipe ); + sp->winsys->buffer_unmap( sp->winsys, buf ); +} + +static struct pipe_buffer_handle * +sp_buffer_reference(struct pipe_context *pipe, + struct pipe_buffer_handle *buf) +{ + struct softpipe_context *sp = softpipe_context( pipe ); + return sp->winsys->buffer_reference( sp->winsys, buf ); +} + +static void sp_buffer_unreference(struct pipe_context *pipe, + struct pipe_buffer_handle **buf) +{ + struct softpipe_context *sp = softpipe_context( pipe ); + sp->winsys->buffer_unreference( sp->winsys, buf ); +} + +static void sp_buffer_data(struct pipe_context *pipe, + struct pipe_buffer_handle *buf, + unsigned size, const void *data ) +{ + struct softpipe_context *sp = softpipe_context( pipe ); + sp->winsys->buffer_data( sp->winsys, buf, size, data ); +} + +static void sp_buffer_subdata(struct pipe_context *pipe, + struct pipe_buffer_handle *buf, + unsigned long offset, + unsigned long size, + const void *data) +{ + struct softpipe_context *sp = softpipe_context( pipe ); + sp->winsys->buffer_subdata( sp->winsys, buf, offset, size, data ); +} + +static void sp_buffer_get_subdata(struct pipe_context *pipe, + struct pipe_buffer_handle *buf, + unsigned long offset, + unsigned long size, + void *data) +{ + struct softpipe_context *sp = softpipe_context( pipe ); + sp->winsys->buffer_get_subdata( sp->winsys, buf, offset, size, data ); +} + + +void +sp_init_buffer_functions( struct softpipe_context *sp ) +{ + sp->pipe.create_buffer = sp_create_buffer; + sp->pipe.buffer_map = sp_buffer_map; + sp->pipe.buffer_unmap = sp_buffer_unmap; + sp->pipe.buffer_reference = sp_buffer_reference; + sp->pipe.buffer_unreference = sp_buffer_unreference; + sp->pipe.buffer_data = sp_buffer_data; + sp->pipe.buffer_subdata = sp_buffer_subdata; + sp->pipe.buffer_get_subdata = sp_buffer_get_subdata; +} diff --git a/src/mesa/pipe/softpipe/sp_buffer.h b/src/mesa/pipe/softpipe/sp_buffer.h new file mode 100644 index 00000000000..9805c5142ad --- /dev/null +++ b/src/mesa/pipe/softpipe/sp_buffer.h @@ -0,0 +1,40 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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 TUNGSTEN GRAPHICS 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 SP_BUFFER_H +#define SP_BUFFER_H + + +struct softpipe_context; + + +extern void +sp_init_buffer_functions(struct softpipe_context *sp); + + +#endif /* SP_BUFFER_H */ diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index 22928f7bd64..9352c7afa71 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -36,6 +36,7 @@ #include "sp_context.h" #include "sp_clear.h" #include "sp_region.h" +#include "sp_buffer.h" #include "sp_state.h" #include "sp_surface.h" #include "sp_prim_setup.h" @@ -219,6 +220,7 @@ struct pipe_context *softpipe_create( struct softpipe_winsys *sws ) assert(softpipe->draw); draw_set_setup_stage(softpipe->draw, sp_draw_render_stage(softpipe)); + sp_init_buffer_functions(softpipe); sp_init_region_functions(softpipe); sp_init_surface_functions(softpipe); diff --git a/src/mesa/pipe/softpipe/sp_region.c b/src/mesa/pipe/softpipe/sp_region.c index 78a0919ad50..a0ced3eb869 100644 --- a/src/mesa/pipe/softpipe/sp_region.c +++ b/src/mesa/pipe/softpipe/sp_region.c @@ -80,7 +80,7 @@ sp_region_alloc(struct pipe_context *pipe, region->height = height; /* needed? */ region->refcount = 1; - region->buffer = sp->winsys->create_buffer(sp->winsys, "region", 64 ); + region->buffer = sp->winsys->create_buffer( sp->winsys, 64 ); sp->winsys->buffer_data( sp->winsys, region->buffer, @@ -259,13 +259,6 @@ sp_region_fill(struct pipe_context *pipe, -static struct _DriBufferObject * -sp_region_buffer(struct pipe_context *pipe, - struct pipe_region *region, GLuint flag) -{ - return region->buffer; -} - void @@ -279,6 +272,5 @@ sp_init_region_functions(struct softpipe_context *sp) sp->pipe.region_data = sp_region_data; sp->pipe.region_copy = sp_region_copy; sp->pipe.region_fill = sp_region_fill; - sp->pipe.region_buffer = sp_region_buffer; } diff --git a/src/mesa/pipe/softpipe/sp_winsys.h b/src/mesa/pipe/softpipe/sp_winsys.h index 43953c648ba..bc6db15d326 100644 --- a/src/mesa/pipe/softpipe/sp_winsys.h +++ b/src/mesa/pipe/softpipe/sp_winsys.h @@ -46,7 +46,7 @@ * etc. */ -struct softpipe_buffer_handle; +struct pipe_buffer_handle; struct softpipe_winsys { @@ -60,34 +60,33 @@ struct softpipe_winsys { * Softpipe only really wants to make system memory allocations, * right?? */ - struct softpipe_buffer_handle *(*create_buffer)(struct softpipe_winsys *sws, - const char *name, - unsigned alignment ); + struct pipe_buffer_handle *(*create_buffer)(struct softpipe_winsys *sws, + unsigned alignment ); void *(*buffer_map)( struct softpipe_winsys *sws, - struct softpipe_buffer_handle *buf ); + struct pipe_buffer_handle *buf ); void (*buffer_unmap)( struct softpipe_winsys *sws, - struct softpipe_buffer_handle *buf ); + struct pipe_buffer_handle *buf ); - struct softpipe_buffer_handle *(*buffer_reference)( struct softpipe_winsys *sws, - struct softpipe_buffer_handle *buf ); + struct pipe_buffer_handle *(*buffer_reference)( struct softpipe_winsys *sws, + struct pipe_buffer_handle *buf ); void (*buffer_unreference)( struct softpipe_winsys *sws, - struct softpipe_buffer_handle *buf ); + struct pipe_buffer_handle **buf ); void (*buffer_data)(struct softpipe_winsys *sws, - struct softpipe_buffer_handle *buf, + struct pipe_buffer_handle *buf, unsigned size, const void *data ); void (*buffer_subdata)(struct softpipe_winsys *sws, - struct softpipe_buffer_handle *buf, + struct pipe_buffer_handle *buf, unsigned long offset, unsigned long size, const void *data); void (*buffer_get_subdata)(struct softpipe_winsys *sws, - struct softpipe_buffer_handle *buf, + struct pipe_buffer_handle *buf, unsigned long offset, unsigned long size, void *data); diff --git a/src/mesa/sources b/src/mesa/sources index 4e3e44f15a3..bd1bbd42998 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -196,6 +196,7 @@ STATETRACKER_SOURCES = \ state_tracker/st_cb_fbo.c \ state_tracker/st_cb_program.c \ state_tracker/st_cb_teximage.c \ + state_tracker/st_cb_bufferobjects.c \ state_tracker/st_draw.c \ state_tracker/st_context.c \ state_tracker/st_texobj.c diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c new file mode 100644 index 00000000000..a667b3e7753 --- /dev/null +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -0,0 +1,206 @@ +/************************************************************************** + * + * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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 TUNGSTEN GRAPHICS 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 "imports.h" +#include "mtypes.h" +#include "bufferobj.h" + +#include "st_context.h" +#include "st_cb_bufferobjects.h" + +#include "pipe/p_context.h" + +/* Pixel buffers and Vertex/index buffers are handled through these + * mesa callbacks. Framebuffer/Renderbuffer objects are + * created/managed elsewhere. + */ + + + +/** + * There is some duplication between mesa's bufferobjects and our + * bufmgr buffers. Both have an integer handle and a hashtable to + * lookup an opaque structure. It would be nice if the handles and + * internal structure where somehow shared. + */ +static struct gl_buffer_object * +st_bufferobj_alloc(GLcontext *ctx, GLuint name, GLenum target) +{ + struct st_context *st = st_context(ctx); + struct st_buffer_object *st_obj = CALLOC_STRUCT(st_buffer_object); + + _mesa_initialize_buffer_object(&st_obj->Base, name, target); + + st_obj->buffer = st->pipe->create_buffer( st->pipe, 32, 0 ); + + return &st_obj->Base; +} + + + +/** + * Deallocate/free a vertex/pixel buffer object. + * Called via glDeleteBuffersARB(). + */ +static void +st_bufferobj_free(GLcontext *ctx, struct gl_buffer_object *obj) +{ + struct pipe_context *pipe = st_context(ctx)->pipe; + struct st_buffer_object *st_obj = st_buffer_object(obj); + + if (st_obj->buffer) + pipe->buffer_unreference(pipe, &st_obj->buffer); + + FREE(st_obj); +} + + + +/** + * Allocate space for and store data in a buffer object. Any data that was + * previously stored in the buffer object is lost. If data is NULL, + * memory will be allocated, but no copy will occur. + * Called via glBufferDataARB(). + */ +static void +st_bufferobj_data(GLcontext *ctx, + GLenum target, + GLsizeiptrARB size, + const GLvoid * data, + GLenum usage, + struct gl_buffer_object *obj) +{ + struct pipe_context *pipe = st_context(ctx)->pipe; + struct st_buffer_object *st_obj = st_buffer_object(obj); + + st_obj->Base.Size = size; + st_obj->Base.Usage = usage; + + pipe->buffer_data( pipe, st_obj->buffer, size, data ); +} + + +/** + * Replace data in a subrange of buffer object. If the data range + * specified by size + offset extends beyond the end of the buffer or + * if data is NULL, no copy is performed. + * Called via glBufferSubDataARB(). + */ +static void +st_bufferobj_subdata(GLcontext *ctx, + GLenum target, + GLintptrARB offset, + GLsizeiptrARB size, + const GLvoid * data, struct gl_buffer_object *obj) +{ + struct pipe_context *pipe = st_context(ctx)->pipe; + struct st_buffer_object *st_obj = st_buffer_object(obj); + + pipe->buffer_subdata(pipe, st_obj->buffer, offset, size, data); +} + + +/** + * Called via glGetBufferSubDataARB(). + */ +static void +st_bufferobj_get_subdata(GLcontext *ctx, + GLenum target, + GLintptrARB offset, + GLsizeiptrARB size, + GLvoid * data, struct gl_buffer_object *obj) +{ + struct pipe_context *pipe = st_context(ctx)->pipe; + struct st_buffer_object *st_obj = st_buffer_object(obj); + + pipe->buffer_get_subdata(pipe, st_obj->buffer, offset, size, data); +} + + + +/** + * Called via glMapBufferARB(). + */ +static void * +st_bufferobj_map(GLcontext *ctx, + GLenum target, + GLenum access, struct gl_buffer_object *obj) +{ + struct pipe_context *pipe = st_context(ctx)->pipe; + struct st_buffer_object *st_obj = st_buffer_object(obj); + GLuint flags; + + switch (access) { + case GL_WRITE_ONLY: + flags = PIPE_BUFFER_FLAG_WRITE; + break; + + + flags = PIPE_BUFFER_FLAG_READ; + break; + + case GL_READ_WRITE: + default: + flags = PIPE_BUFFER_FLAG_READ | PIPE_BUFFER_FLAG_WRITE; + break; + } + + obj->Pointer = pipe->buffer_map(pipe, st_obj->buffer, flags); + return obj->Pointer; +} + + +/** + * Called via glMapBufferARB(). + */ +static GLboolean +st_bufferobj_unmap(GLcontext *ctx, + GLenum target, struct gl_buffer_object *obj) +{ + struct pipe_context *pipe = st_context(ctx)->pipe; + struct st_buffer_object *st_obj = st_buffer_object(obj); + + pipe->buffer_unmap(pipe, st_obj->buffer); + obj->Pointer = NULL; + return GL_TRUE; +} + + +void +st_init_cb_bufferobjects( struct st_context *st ) +{ + GLcontext *ctx = st->ctx; + + ctx->Driver.NewBufferObject = st_bufferobj_alloc; + ctx->Driver.DeleteBuffer = st_bufferobj_free; + ctx->Driver.BufferData = st_bufferobj_data; + ctx->Driver.BufferSubData = st_bufferobj_subdata; + ctx->Driver.GetBufferSubData = st_bufferobj_get_subdata; + ctx->Driver.MapBuffer = st_bufferobj_map; + ctx->Driver.UnmapBuffer = st_bufferobj_unmap; +} diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.h b/src/mesa/state_tracker/st_cb_bufferobjects.h new file mode 100644 index 00000000000..2787411c5fa --- /dev/null +++ b/src/mesa/state_tracker/st_cb_bufferobjects.h @@ -0,0 +1,66 @@ + /************************************************************************** + * + * Copyright 2005 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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 TUNGSTEN GRAPHICS 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 ST_CB_BUFFEROBJECTS_H +#define ST_CB_BUFFEROBJECTS_H + +struct st_context; +struct gl_buffer_object; +struct pipe_buffer_handle; + +/** + * State_tracker vertex/pixel buffer object, derived from Mesa's + * gl_buffer_object. + */ +struct st_buffer_object +{ + struct gl_buffer_object Base; + struct pipe_buffer_handle *buffer; +}; + + +/* Hook the bufferobject implementation into mesa: + */ +void st_init_cb_bufferobjects( struct st_context *st ); + + +/* Are the obj->Name tests necessary? Unfortunately yes, mesa + * allocates a couple of gl_buffer_object structs statically, and the + * Name == 0 test is the only way to identify them and avoid casting + * them erroneously to our structs. + */ +static INLINE struct st_buffer_object * +st_buffer_object(struct gl_buffer_object *obj) +{ + if (obj->Name) + return (struct st_buffer_object *) obj; + else + return NULL; +} + + +#endif