From 317a7da2c452f35ef627aec6fc4d31406758725d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fonseca?= Date: Tue, 3 Mar 2009 17:54:38 +0000 Subject: wgl: Support the same combinations of single buffer pixel formats. --- src/gallium/state_trackers/wgl/shared/stw_pixelformat.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c b/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c index 5cfdd41597..2992a1ac0a 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c +++ b/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c @@ -74,6 +74,18 @@ add_standard_pixelformats( pf->depth = depth24s8; pf++; + pf->flags = flags; + pf->color = color24; + pf->alpha = alpha8; + pf->depth = depth16; + pf++; + + pf->flags = flags; + pf->color = color24; + pf->alpha = alpha8; + pf->depth = depth24s8; + pf++; + pf->flags = flags; pf->color = color24; pf->alpha = noalpha; -- cgit v1.2.3 From de1caa550700ae38ff791c30f6d482f3efddebd0 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 3 Mar 2009 13:52:24 -0700 Subject: mesa: fix sw fallback state validation bug When a hw driver fell back to swrast, swrast wasn't always getting informed of program changes. When fixed function is translated into shaders, flags like _NEW_LIGHT, _NEW_TEXTURE, etc. should really signal _NEW_PROGRAM. In this case, swrast wasn't seeing _NEW_PROGRAM when new fragment shaders were generated. --- src/mesa/main/state.c | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c index 9ea932ea96..9d03ee744d 100644 --- a/src/mesa/main/state.c +++ b/src/mesa/main/state.c @@ -202,13 +202,17 @@ update_program_enables(GLcontext *ctx) * * This function needs to be called after texture state validation in case * we're generating a fragment program from fixed-function texture state. + * + * \return bitfield which will indicate _NEW_PROGRAM state if a new vertex + * or fragment program is being used. */ -static void +static GLbitfield update_program(GLcontext *ctx) { const struct gl_shader_program *shProg = ctx->Shader.CurrentProgram; const struct gl_vertex_program *prevVP = ctx->VertexProgram._Current; const struct gl_fragment_program *prevFP = ctx->FragmentProgram._Current; + GLbitfield new_state = 0x0; /* * Set the ctx->VertexProgram._Current and ctx->FragmentProgram._Current @@ -278,15 +282,23 @@ update_program(GLcontext *ctx) /* Let the driver know what's happening: */ - if (ctx->FragmentProgram._Current != prevFP && ctx->Driver.BindProgram) { - ctx->Driver.BindProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, - (struct gl_program *) ctx->FragmentProgram._Current); + if (ctx->FragmentProgram._Current != prevFP) { + new_state |= _NEW_PROGRAM; + if (ctx->Driver.BindProgram) { + ctx->Driver.BindProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, + (struct gl_program *) ctx->FragmentProgram._Current); + } } - if (ctx->VertexProgram._Current != prevVP && ctx->Driver.BindProgram) { - ctx->Driver.BindProgram(ctx, GL_VERTEX_PROGRAM_ARB, - (struct gl_program *) ctx->VertexProgram._Current); + if (ctx->VertexProgram._Current != prevVP) { + new_state |= _NEW_PROGRAM; + if (ctx->Driver.BindProgram) { + ctx->Driver.BindProgram(ctx, GL_VERTEX_PROGRAM_ARB, + (struct gl_program *) ctx->VertexProgram._Current); + } } + + return new_state; } @@ -447,6 +459,7 @@ _mesa_update_state_locked( GLcontext *ctx ) { GLbitfield new_state = ctx->NewState; GLbitfield prog_flags = _NEW_PROGRAM; + GLbitfield new_prog_state = 0x0; if (new_state == _NEW_CURRENT_ATTRIB) goto out; @@ -531,8 +544,13 @@ _mesa_update_state_locked( GLcontext *ctx ) if (new_state & _MESA_NEW_NEED_EYE_COORDS) _mesa_update_tnl_spaces( ctx, new_state ); - if (new_state & prog_flags) - update_program( ctx ); + if (new_state & prog_flags) { + /* When we generate programs from fixed-function vertex/fragment state + * this call may generate/bind a new program. If so, we need to + * propogate the _NEW_PROGRAM flag to the driver. + */ + new_prog_state |= update_program( ctx ); + } /* * Give the driver a chance to act upon the new_state flags. @@ -544,7 +562,7 @@ _mesa_update_state_locked( GLcontext *ctx ) * Driver.UpdateState() has to call FLUSH_VERTICES(). (fixed?) */ out: - new_state = ctx->NewState; + new_state = ctx->NewState | new_prog_state; ctx->NewState = 0; ctx->Driver.UpdateState(ctx, new_state); ctx->Array.NewState = 0; -- cgit v1.2.3 From c37872d8c02c5c875b1570d8eaa1fe5de0380b53 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 3 Mar 2009 14:01:10 -0700 Subject: xlib: code to force fixed function -> shader translation (for debug, disabled) --- src/mesa/drivers/x11/xm_api.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c index 908fecc85a..6ae5b6fd58 100644 --- a/src/mesa/drivers/x11/xm_api.c +++ b/src/mesa/drivers/x11/xm_api.c @@ -1584,6 +1584,14 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) return NULL; } + /* Enable this to exercise fixed function -> shader translation + * with software rendering. + */ + if (0) { + mesaCtx->VertexProgram._MaintainTnlProgram = GL_TRUE; + mesaCtx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; + } + _mesa_enable_sw_extensions(mesaCtx); _mesa_enable_1_3_extensions(mesaCtx); _mesa_enable_1_4_extensions(mesaCtx); -- cgit v1.2.3 From 3873ffe27d00f4890290441a6a6923e09ff9434c Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 3 Mar 2009 14:01:49 -0700 Subject: gallium: remove old state tracker renderbuffer attachment assertion Not needed since renderbuffers are ref-counted. Fixes progs/demos/shadowtex. --- src/mesa/state_tracker/st_cb_fbo.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 15bd6fee05..4e669f113b 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -357,8 +357,6 @@ st_render_texture(GLcontext *ctx, if (!pt) return; - assert(!att->Renderbuffer); - /* create new renderbuffer which wraps the texture image */ rb = st_new_renderbuffer(ctx, 0); if (!rb) { -- cgit v1.2.3 From 16526b70998b8c6e0ba298db86f1f738c1a3df3f Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Tue, 3 Mar 2009 21:56:10 +0100 Subject: st/drm: s/hocks/hooks/ --- src/gallium/include/state_tracker/drm_api.h | 2 +- src/gallium/state_trackers/dri2/dri_context.c | 2 +- src/gallium/state_trackers/dri2/dri_drawable.c | 2 +- src/gallium/state_trackers/dri2/dri_screen.c | 2 +- src/gallium/state_trackers/egl/egl_context.c | 2 +- src/gallium/state_trackers/egl/egl_surface.c | 3 +-- src/gallium/state_trackers/egl/egl_tracker.c | 2 +- src/gallium/state_trackers/xorg/xorg_crtc.c | 2 +- src/gallium/state_trackers/xorg/xorg_dri2.c | 4 ++-- src/gallium/state_trackers/xorg/xorg_driver.c | 2 +- src/gallium/state_trackers/xorg/xorg_exa.c | 6 +++--- src/gallium/winsys/drm/intel/gem/intel_be_api.c | 2 +- 12 files changed, 15 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/gallium/include/state_tracker/drm_api.h b/src/gallium/include/state_tracker/drm_api.h index 91a727be66..435435da29 100644 --- a/src/gallium/include/state_tracker/drm_api.h +++ b/src/gallium/include/state_tracker/drm_api.h @@ -42,6 +42,6 @@ struct drm_api /** * A driver needs to export this symbol */ -extern struct drm_api drm_api_hocks; +extern struct drm_api drm_api_hooks; #endif diff --git a/src/gallium/state_trackers/dri2/dri_context.c b/src/gallium/state_trackers/dri2/dri_context.c index a8a94be176..b8e92a76c0 100644 --- a/src/gallium/state_trackers/dri2/dri_context.c +++ b/src/gallium/state_trackers/dri2/dri_context.c @@ -71,7 +71,7 @@ dri_create_context(const __GLcontextModes *visual, sPriv->myNum, "dri"); - ctx->pipe = drm_api_hocks.create_context(screen->pipe_screen); + ctx->pipe = drm_api_hooks.create_context(screen->pipe_screen); if (ctx->pipe == NULL) goto fail; diff --git a/src/gallium/state_trackers/dri2/dri_drawable.c b/src/gallium/state_trackers/dri2/dri_drawable.c index 120d45bc03..97778473b1 100644 --- a/src/gallium/state_trackers/dri2/dri_drawable.c +++ b/src/gallium/state_trackers/dri2/dri_drawable.c @@ -57,7 +57,7 @@ dri_surface_from_handle(struct pipe_screen *screen, struct pipe_texture templat; struct pipe_buffer *buf = NULL; - buf = drm_api_hocks.buffer_from_handle(screen, "dri2 buffer", handle); + buf = drm_api_hooks.buffer_from_handle(screen, "dri2 buffer", handle); if (!buf) return NULL; diff --git a/src/gallium/state_trackers/dri2/dri_screen.c b/src/gallium/state_trackers/dri2/dri_screen.c index 1fef538294..ac3aee5015 100644 --- a/src/gallium/state_trackers/dri2/dri_screen.c +++ b/src/gallium/state_trackers/dri2/dri_screen.c @@ -208,7 +208,7 @@ dri_init_screen2(__DRIscreenPrivate *sPriv) sPriv->extensions = dri_screen_extensions; - screen->pipe_screen = drm_api_hocks.create_screen(screen->fd, screen->deviceID); + screen->pipe_screen = drm_api_hooks.create_screen(screen->fd, screen->deviceID); if (!screen->pipe_screen) { debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__); goto fail; diff --git a/src/gallium/state_trackers/egl/egl_context.c b/src/gallium/state_trackers/egl/egl_context.c index 8564972b91..36548fae26 100644 --- a/src/gallium/state_trackers/egl/egl_context.c +++ b/src/gallium/state_trackers/egl/egl_context.c @@ -115,7 +115,7 @@ drm_create_context(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, EGLContext _eglInitContext(drv, dpy, &ctx->base, config, attrib_list); - ctx->pipe = drm_api_hocks.create_context(dev->screen); + ctx->pipe = drm_api_hooks.create_context(dev->screen); if (!ctx->pipe) goto err_pipe; diff --git a/src/gallium/state_trackers/egl/egl_surface.c b/src/gallium/state_trackers/egl/egl_surface.c index aa3c32d41c..7ebc34871c 100644 --- a/src/gallium/state_trackers/egl/egl_surface.c +++ b/src/gallium/state_trackers/egl/egl_surface.c @@ -132,7 +132,7 @@ drm_create_texture(_EGLDriver *drv, scrn->front.width = w; scrn->front.height = h; scrn->front.pitch = pitch; - drm_api_hocks.handle_from_buffer(dev->winsys, scrn->buffer, &scrn->front.handle); + drm_api_hooks.handle_from_buffer(screen, scrn->buffer, &scrn->front.handle); if (0) goto err_handle; @@ -271,7 +271,6 @@ drm_show_screen_surface_mesa(_EGLDriver *drv, EGLDisplay dpy, struct drm_device *dev = (struct drm_device *)drv; struct drm_surface *surf = lookup_drm_surface(surface); struct drm_screen *scrn = lookup_drm_screen(dpy, screen); - struct pipe_context *pipe; _EGLMode *mode = _eglLookupMode(dpy, m); int ret; unsigned int i, k; diff --git a/src/gallium/state_trackers/egl/egl_tracker.c b/src/gallium/state_trackers/egl/egl_tracker.c index 2813bf4360..a22ef381b9 100644 --- a/src/gallium/state_trackers/egl/egl_tracker.c +++ b/src/gallium/state_trackers/egl/egl_tracker.c @@ -121,7 +121,7 @@ drm_initialize(_EGLDriver *drv, EGLDisplay dpy, EGLint *major, EGLint *minor) dev->drmFD = fd; drm_get_device_id(dev); - dev->screen = drm_api_hocks.create_screen(dev->drmFD, dev->deviceID); + dev->screen = drm_api_hooks.create_screen(dev->drmFD, dev->deviceID); if (!dev->screen) goto err_screen; dev->winsys = dev->screen->winsys; diff --git a/src/gallium/state_trackers/xorg/xorg_crtc.c b/src/gallium/state_trackers/xorg/xorg_crtc.c index 0765f56ee1..0bd69c214f 100644 --- a/src/gallium/state_trackers/xorg/xorg_crtc.c +++ b/src/gallium/state_trackers/xorg/xorg_crtc.c @@ -194,7 +194,7 @@ crtc_load_cursor_argb(xf86CrtcPtr crtc, CARD32 * image) PIPE_BUFFER_USAGE_CPU_WRITE | PIPE_BUFFER_USAGE_GPU_READ, 64*64*4); - drm_api_hocks.handle_from_buffer(ms->screen, + drm_api_hooks.handle_from_buffer(ms->screen, crtcp->cursor_buf, &crtcp->cursor_handle); } diff --git a/src/gallium/state_trackers/xorg/xorg_dri2.c b/src/gallium/state_trackers/xorg/xorg_dri2.c index 72b333eaf1..d48b7dd27b 100644 --- a/src/gallium/state_trackers/xorg/xorg_dri2.c +++ b/src/gallium/state_trackers/xorg/xorg_dri2.c @@ -109,8 +109,8 @@ driCreateBuffers(DrawablePtr pDraw, unsigned int *attachments, int count) tex = ms->screen->texture_create(ms->screen, &template); } - drm_api_hocks.buffer_from_texture(tex, &buf, &stride); - drm_api_hocks.global_handle_from_buffer(ms->screen, buf, &handle); + drm_api_hooks.buffer_from_texture(tex, &buf, &stride); + drm_api_hooks.global_handle_from_buffer(ms->screen, buf, &handle); buffers[i].name = handle; buffers[i].attachment = attachments[i]; diff --git a/src/gallium/state_trackers/xorg/xorg_driver.c b/src/gallium/state_trackers/xorg/xorg_driver.c index d166a365ac..8a2711e70c 100644 --- a/src/gallium/state_trackers/xorg/xorg_driver.c +++ b/src/gallium/state_trackers/xorg/xorg_driver.c @@ -476,7 +476,7 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) } if (!ms->screen) { - ms->screen = drm_api_hocks.create_screen(ms->fd, ms->PciInfo->device_id); + ms->screen = drm_api_hooks.create_screen(ms->fd, ms->PciInfo->device_id); if (!ms->screen) { FatalError("Could not init pipe_screen\n"); diff --git a/src/gallium/state_trackers/xorg/xorg_exa.c b/src/gallium/state_trackers/xorg/xorg_exa.c index ac0bfc88a4..c62625c448 100644 --- a/src/gallium/state_trackers/xorg/xorg_exa.c +++ b/src/gallium/state_trackers/xorg/xorg_exa.c @@ -380,8 +380,8 @@ xorg_exa_get_pixmap_handle(PixmapPtr pPixmap) return 0; } - drm_api_hocks.buffer_from_texture(priv->tex, &buffer, &stride); - drm_api_hocks.handle_from_buffer(ms->screen, buffer, &handle); + drm_api_hooks.buffer_from_texture(priv->tex, &buffer, &stride); + drm_api_hooks.handle_from_buffer(ms->screen, buffer, &handle); pipe_buffer_reference(ms->screen, &buffer, NULL); return handle; } @@ -519,7 +519,7 @@ xorg_exa_init(ScrnInfoPtr pScrn) } exa->scrn = ms->screen; - exa->ctx = drm_api_hocks.create_context(exa->scrn); + exa->ctx = drm_api_hooks.create_context(exa->scrn); /* Share context with DRI */ ms->ctx = exa->ctx; diff --git a/src/gallium/winsys/drm/intel/gem/intel_be_api.c b/src/gallium/winsys/drm/intel/gem/intel_be_api.c index 3f71c25441..f4ef7c2d88 100644 --- a/src/gallium/winsys/drm/intel/gem/intel_be_api.c +++ b/src/gallium/winsys/drm/intel/gem/intel_be_api.c @@ -2,7 +2,7 @@ #include "intel_be_api.h" #include "i915simple/i915_winsys.h" -struct drm_api drm_api_hocks = +struct drm_api drm_api_hooks = { /* intel_be_context.c */ .create_context = intel_be_create_context, -- cgit v1.2.3 From b7b046150bc61604777baa8a57f81d770837bd10 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 4 Mar 2009 00:31:35 +0100 Subject: st/dri2: We are strictly a dri2 driver --- src/gallium/state_trackers/dri2/dri_drawable.c | 40 +++----------------------- src/gallium/state_trackers/dri2/dri_screen.c | 16 +++++++++-- 2 files changed, 17 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/gallium/state_trackers/dri2/dri_drawable.c b/src/gallium/state_trackers/dri2/dri_drawable.c index 97778473b1..5c8f3ba866 100644 --- a/src/gallium/state_trackers/dri2/dri_drawable.c +++ b/src/gallium/state_trackers/dri2/dri_drawable.c @@ -187,48 +187,16 @@ dri_get_buffers(__DRIdrawablePrivate *dPriv) void dri_swap_buffers(__DRIdrawablePrivate * dPriv) { - struct dri_drawable *drawable = dri_drawable(dPriv); - struct pipe_surface *back_surf; - - assert(drawable); - assert(drawable->stfb); - - st_get_framebuffer_surface(drawable->stfb, - ST_SURFACE_BACK_LEFT, - &back_surf); - if (back_surf) { - st_notify_swapbuffers(drawable->stfb); - /* TODO do stuff here */ - st_notify_swapbuffers_complete(drawable->stfb); - } + /* not needed for dri2 */ + assert(0); } -/** - * Called via glXCopySubBufferMESA() to copy a subrect of the back - * buffer to the front buffer/screen. - */ void dri_copy_sub_buffer(__DRIdrawablePrivate * dPriv, int x, int y, int w, int h) { - struct dri_drawable *drawable = dri_drawable(dPriv); - struct pipe_surface *back_surf; - - assert(drawable); - assert(drawable->stfb); - - st_get_framebuffer_surface(drawable->stfb, - ST_SURFACE_BACK_LEFT, - &back_surf); - if (back_surf) { - drm_clip_rect_t rect; - rect.x1 = x; - rect.y1 = y; - rect.x2 = w; - rect.y2 = h; - - /* do stuff here */ - } + /* not needed for dri2 */ + assert(0); } diff --git a/src/gallium/state_trackers/dri2/dri_screen.c b/src/gallium/state_trackers/dri2/dri_screen.c index ac3aee5015..57249a5111 100644 --- a/src/gallium/state_trackers/dri2/dri_screen.c +++ b/src/gallium/state_trackers/dri2/dri_screen.c @@ -183,6 +183,16 @@ dri_get_swap_info(__DRIdrawablePrivate * dPriv, } +/** + * NULL stub for old dri loaders + */ +const __DRIconfig ** +dri_init_screen(__DRIscreenPrivate *sPriv) +{ + return NULL; +} + + /** * This is the driver specific part of the createNewScreen entry point. * @@ -240,19 +250,19 @@ dri_destroy_screen(__DRIscreenPrivate * sPriv) PUBLIC const struct __DriverAPIRec driDriverAPI = { - .InitScreen = NULL, + .InitScreen = dri_init_screen, /* not supported but exported */ .DestroyScreen = dri_destroy_screen, .CreateContext = dri_create_context, .DestroyContext = dri_destroy_context, .CreateBuffer = dri_create_buffer, .DestroyBuffer = dri_destroy_buffer, - .SwapBuffers = dri_swap_buffers, + .SwapBuffers = dri_swap_buffers, /* not supported but exported */ .MakeCurrent = dri_make_current, .UnbindContext = dri_unbind_context, .GetSwapInfo = dri_get_swap_info, .GetDrawableMSC = driDrawableGetMSC32, .WaitForMSC = driWaitForMSC32, - .CopySubBuffer = dri_copy_sub_buffer, + .CopySubBuffer = dri_copy_sub_buffer, /* not supported but exported */ .InitScreen2 = dri_init_screen2, }; -- cgit v1.2.3 From 28c325f8d3925d703a0cc5a3d3d3fa57b7f11fe4 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 4 Mar 2009 00:35:33 +0100 Subject: st/dri2: Hook up flush_frontbuffer Doesn't do anything because we can't tell the X server about any changes to the fake front buffer. --- src/gallium/state_trackers/dri2/dri_context.c | 4 +++- src/gallium/state_trackers/dri2/dri_drawable.c | 19 +++++++++++++++++++ src/gallium/state_trackers/dri2/dri_drawable.h | 5 +++++ src/gallium/state_trackers/dri2/dri_screen.c | 3 +++ 4 files changed, 30 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gallium/state_trackers/dri2/dri_context.c b/src/gallium/state_trackers/dri2/dri_context.c index b8e92a76c0..92c26ac70f 100644 --- a/src/gallium/state_trackers/dri2/dri_context.c +++ b/src/gallium/state_trackers/dri2/dri_context.c @@ -76,7 +76,8 @@ dri_create_context(const __GLcontextModes *visual, if (ctx->pipe == NULL) goto fail; - ctx->pipe->priv = ctx; /* I guess */ + /* used in dri_flush_frontbuffer */ + ctx->pipe->priv = ctx; ctx->st = st_create_context(ctx->pipe, visual, st_share); if (ctx->st == NULL) @@ -152,6 +153,7 @@ dri_make_current(__DRIcontextPrivate *cPriv, draw->stfb, read->stfb); + /* used in dri_flush_frontbuffer */ ctx->dPriv = driDrawPriv; if (driDrawPriv) diff --git a/src/gallium/state_trackers/dri2/dri_drawable.c b/src/gallium/state_trackers/dri2/dri_drawable.c index 5c8f3ba866..8a00c6caf1 100644 --- a/src/gallium/state_trackers/dri2/dri_drawable.c +++ b/src/gallium/state_trackers/dri2/dri_drawable.c @@ -44,6 +44,15 @@ #include "util/u_memory.h" +static void +dri_copy_to_front(__DRIdrawablePrivate *dPriv, + struct pipe_surface *from, + int x, int y, unsigned w, unsigned h) +{ + /* TODO send a message to the Xserver to copy to the real front buffer */ +} + + static struct pipe_surface * dri_surface_from_handle(struct pipe_screen *screen, unsigned handle, @@ -184,6 +193,16 @@ dri_get_buffers(__DRIdrawablePrivate *dPriv) } +void +dri_flush_frontbuffer(struct pipe_screen *screen, + struct pipe_surface *surf, + void *context_private) +{ + struct dri_context *ctx = (struct dri_context *)context_private; + dri_copy_to_front(ctx->dPriv, surf, 0, 0, surf->width, surf->height); +} + + void dri_swap_buffers(__DRIdrawablePrivate * dPriv) { diff --git a/src/gallium/state_trackers/dri2/dri_drawable.h b/src/gallium/state_trackers/dri2/dri_drawable.h index d40d09c9b5..185c657b35 100644 --- a/src/gallium/state_trackers/dri2/dri_drawable.h +++ b/src/gallium/state_trackers/dri2/dri_drawable.h @@ -65,6 +65,11 @@ dri_create_buffer(__DRIscreenPrivate *sPriv, const __GLcontextModes *visual, boolean isPixmap); +void +dri_flush_frontbuffer(struct pipe_screen *screen, + struct pipe_surface *surf, + void *context_private); + void dri_swap_buffers(__DRIdrawablePrivate * dPriv); diff --git a/src/gallium/state_trackers/dri2/dri_screen.c b/src/gallium/state_trackers/dri2/dri_screen.c index 57249a5111..ab5878a4bc 100644 --- a/src/gallium/state_trackers/dri2/dri_screen.c +++ b/src/gallium/state_trackers/dri2/dri_screen.c @@ -224,6 +224,9 @@ dri_init_screen2(__DRIscreenPrivate *sPriv) goto fail; } + /* We need to hook in here */ + screen->pipe_screen->flush_frontbuffer = dri_flush_frontbuffer; + driParseOptionInfo(&screen->optionCache, __driConfigOptions, __driNConfigOptions); -- cgit v1.2.3 From 145aa57e45d5492278ae4fe182a77b0d02ecc6f5 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 4 Mar 2009 00:36:59 +0100 Subject: st/dri2: Fake frontbuffer changes Front buffer rendering works as it stands but it completely wrong. But as it stands fake front buffer rendering is completely broken. So we keep it as it is. But lets atleast handle it in the get buffers code. --- src/gallium/state_trackers/dri2/dri_drawable.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gallium/state_trackers/dri2/dri_drawable.c b/src/gallium/state_trackers/dri2/dri_drawable.c index 8a00c6caf1..2f6913ec5c 100644 --- a/src/gallium/state_trackers/dri2/dri_drawable.c +++ b/src/gallium/state_trackers/dri2/dri_drawable.c @@ -153,6 +153,10 @@ dri_get_buffers(__DRIdrawablePrivate *dPriv) index = ST_SURFACE_FRONT_LEFT; format = PIPE_FORMAT_A8R8G8B8_UNORM; break; + case __DRI_BUFFER_FAKE_FRONT_LEFT: + index = ST_SURFACE_FRONT_LEFT; + format = PIPE_FORMAT_A8R8G8B8_UNORM; + break; case __DRI_BUFFER_BACK_LEFT: index = ST_SURFACE_BACK_LEFT; format = PIPE_FORMAT_A8R8G8B8_UNORM; @@ -275,7 +279,12 @@ dri_create_buffer(__DRIscreenPrivate *sPriv, /* setup dri2 buffers information */ i = 0; drawable->attachments[i++] = __DRI_BUFFER_FRONT_LEFT; - drawable->attachments[i++] = __DRI_BUFFER_BACK_LEFT; +#if 0 + /* TODO incase of double buffer visual, delay fake creation */ + drawable->attachments[i++] = __DRI_BUFFER_FAKE_FRONT_LEFT; +#endif + if (visual->doubleBufferMode) + drawable->attachments[i++] = __DRI_BUFFER_BACK_LEFT; if (visual->depthBits) drawable->attachments[i++] = __DRI_BUFFER_DEPTH; if (visual->stencilBits) -- cgit v1.2.3 From a255472ee789d13c07174e385c7d40f965916e7b Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 3 Mar 2009 20:45:45 -0700 Subject: mesa: include main/dd.h in t_vb_points.c and t_vp_build.c For some reason makedepend doesn't seem to find the dependency on this header in these two files. Directly including the header is a work-around. --- src/mesa/tnl/t_vb_points.c | 2 ++ src/mesa/tnl/t_vp_build.c | 1 + 2 files changed, 3 insertions(+) (limited to 'src') diff --git a/src/mesa/tnl/t_vb_points.c b/src/mesa/tnl/t_vb_points.c index 01d055c1dd..a52505b4b8 100644 --- a/src/mesa/tnl/t_vb_points.c +++ b/src/mesa/tnl/t_vb_points.c @@ -25,7 +25,9 @@ * Brian Paul */ +#include "main/glheader.h" #include "main/mtypes.h" +#include "main/dd.h" #include "main/imports.h" #include "t_context.h" #include "t_pipeline.h" diff --git a/src/mesa/tnl/t_vp_build.c b/src/mesa/tnl/t_vp_build.c index 7be4d95af6..735937bbe2 100644 --- a/src/mesa/tnl/t_vp_build.c +++ b/src/mesa/tnl/t_vp_build.c @@ -32,6 +32,7 @@ #include "main/glheader.h" #include "main/ffvertex_prog.h" +#include "main/dd.h" #include "t_vp_build.h" -- cgit v1.2.3 From 9e67b0a1745e50fe34efedb0a3191b4a27e10724 Mon Sep 17 00:00:00 2001 From: Corbin Simpson Date: Tue, 3 Mar 2009 21:14:33 -0800 Subject: r300-gallium, radeon-gallium: Begin migration to DRI2 state tracker, part 1. s/migration/migrane/ , actually. Anyway, this has working glxinfo... --- src/gallium/drivers/r300/r300_context.c | 7 +- src/gallium/drivers/r300/r300_context.h | 1 - src/gallium/drivers/r300/r300_screen.c | 5 +- src/gallium/drivers/r300/r300_screen.h | 3 +- src/gallium/drivers/r300/r300_winsys.h | 11 +-- src/gallium/winsys/drm/radeon/Makefile | 3 +- src/gallium/winsys/drm/radeon/radeon_buffer.c | 90 ++++++++++++---------- src/gallium/winsys/drm/radeon/radeon_buffer.h | 11 ++- src/gallium/winsys/drm/radeon/radeon_drm.c | 80 +++++++++++++++++++ src/gallium/winsys/drm/radeon/radeon_drm.h | 30 ++++++++ src/gallium/winsys/drm/radeon/radeon_r300.c | 8 +- src/gallium/winsys/drm/radeon/radeon_r300.h | 2 +- .../winsys/drm/radeon/radeon_winsys_softpipe.c | 9 +-- .../winsys/drm/radeon/radeon_winsys_softpipe.h | 2 +- 14 files changed, 190 insertions(+), 72 deletions(-) (limited to 'src') diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c index a981150143..653d919ef1 100644 --- a/src/gallium/drivers/r300/r300_context.c +++ b/src/gallium/drivers/r300/r300_context.c @@ -103,7 +103,6 @@ static void r300_destroy_context(struct pipe_context* context) { } struct pipe_context* r300_create_context(struct pipe_screen* screen, - struct pipe_winsys* winsys, struct r300_winsys* r300_winsys) { struct r300_context* r300 = CALLOC_STRUCT(r300_context); @@ -111,9 +110,11 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen, if (!r300) return NULL; + /* XXX this could be refactored now? */ r300->winsys = r300_winsys; - r300->context.winsys = winsys; - r300->context.screen = r300_create_screen(winsys, r300_winsys); + + r300->context.winsys = (struct pipe_winsys*)r300_winsys; + r300->context.screen = r300_screen(screen); r300->context.destroy = r300_destroy_context; diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h index 5247901be5..2be9e2eb33 100644 --- a/src/gallium/drivers/r300/r300_context.h +++ b/src/gallium/drivers/r300/r300_context.h @@ -268,7 +268,6 @@ void r300_init_surface_functions(struct r300_context* r300); * We'll just step out in that case... */ #ifndef R300_WINSYS_H struct pipe_context* r300_create_context(struct pipe_screen* screen, - struct pipe_winsys* winsys, struct r300_winsys* r300_winsys); #endif diff --git a/src/gallium/drivers/r300/r300_screen.c b/src/gallium/drivers/r300/r300_screen.c index 2fcd504812..e97334463a 100644 --- a/src/gallium/drivers/r300/r300_screen.c +++ b/src/gallium/drivers/r300/r300_screen.c @@ -337,8 +337,7 @@ static void r300_destroy_screen(struct pipe_screen* pscreen) FREE(r300screen); } -struct pipe_screen* r300_create_screen(struct pipe_winsys* winsys, - struct r300_winsys* r300_winsys) +struct pipe_screen* r300_create_screen(struct r300_winsys* r300_winsys) { struct r300_screen* r300screen = CALLOC_STRUCT(r300_screen); struct r300_capabilities* caps = CALLOC_STRUCT(r300_capabilities); @@ -352,7 +351,7 @@ struct pipe_screen* r300_create_screen(struct pipe_winsys* winsys, r300_parse_chipset(caps); r300screen->caps = caps; - r300screen->screen.winsys = winsys; + r300screen->screen.winsys = (struct pipe_winsys*)r300_winsys; r300screen->screen.destroy = r300_destroy_screen; r300screen->screen.get_name = r300_get_name; r300screen->screen.get_vendor = r300_get_vendor; diff --git a/src/gallium/drivers/r300/r300_screen.h b/src/gallium/drivers/r300/r300_screen.h index 6c845144cb..3f52dbc3be 100644 --- a/src/gallium/drivers/r300/r300_screen.h +++ b/src/gallium/drivers/r300/r300_screen.h @@ -61,7 +61,6 @@ r300_transfer(struct pipe_transfer* transfer) } /* Creates a new r300 screen. */ -struct pipe_screen* r300_create_screen(struct pipe_winsys* winsys, - struct r300_winsys* r300_winsys); +struct pipe_screen* r300_create_screen(struct r300_winsys* r300_winsys); #endif /* R300_SCREEN_H */ diff --git a/src/gallium/drivers/r300/r300_winsys.h b/src/gallium/drivers/r300/r300_winsys.h index 5a3a212892..b7341c4f3a 100644 --- a/src/gallium/drivers/r300/r300_winsys.h +++ b/src/gallium/drivers/r300/r300_winsys.h @@ -33,10 +33,16 @@ extern "C" { #include "pipe/p_defines.h" #include "pipe/p_state.h" +#include "pipe/internal/p_winsys_screen.h" struct radeon_cs; struct r300_winsys { + /* Parent class */ + struct pipe_winsys base; + + /* Opaque Radeon-specific winsys object. */ + void* radeon_winsys; /* PCI ID */ uint32_t pci_id; @@ -47,10 +53,6 @@ struct r300_winsys { /* CS object. This is very much like Intel's batchbuffer. * Fill it full of dwords and relocs and then submit. * Repeat as needed. */ - /* Note: Unlike Mesa's version of this, we don't keep a copy of the CSM - * that was used to create this CS. Is this a good idea? */ - /* Note: The pipe driver doesn't know how to use this. This is purely - * for the winsys. */ struct radeon_cs* cs; /* Check to see if there's room for commands. */ @@ -84,7 +86,6 @@ struct r300_winsys { }; struct pipe_context* r300_create_context(struct pipe_screen* screen, - struct pipe_winsys* winsys, struct r300_winsys* r300_winsys); #ifdef __cplusplus diff --git a/src/gallium/winsys/drm/radeon/Makefile b/src/gallium/winsys/drm/radeon/Makefile index 784686ffb6..8721f2cb5d 100644 --- a/src/gallium/winsys/drm/radeon/Makefile +++ b/src/gallium/winsys/drm/radeon/Makefile @@ -7,15 +7,14 @@ LIBNAME = radeon_dri.so MINIGLX_SOURCES = PIPE_DRIVERS = \ + $(TOP)/src/gallium/state_trackers/dri2/libdri2drm.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ $(TOP)/src/gallium/drivers/r300/libr300.a DRIVER_SOURCES = \ radeon_buffer.c \ - radeon_context.c \ radeon_drm.c \ radeon_r300.c \ - radeon_screen.c \ radeon_winsys_softpipe.c C_SOURCES = \ diff --git a/src/gallium/winsys/drm/radeon/radeon_buffer.c b/src/gallium/winsys/drm/radeon/radeon_buffer.c index 918d2f98e2..79b8f777ca 100644 --- a/src/gallium/winsys/drm/radeon/radeon_buffer.c +++ b/src/gallium/winsys/drm/radeon/radeon_buffer.c @@ -1,5 +1,6 @@ /* * Copyright © 2008 Jérôme Glisse + * 2009 Corbin Simpson * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining @@ -26,10 +27,14 @@ /* * Authors: * Jérôme Glisse + * Corbin Simpson */ #include -#include "dri_util.h" + #include "state_tracker/st_public.h" + +#include "util/u_memory.h" + #include "pipe/p_defines.h" #include "pipe/p_inlines.h" #include "radeon_buffer.h" @@ -38,24 +43,26 @@ #include "radeon_bo.h" #include "radeon_drm.h" + static const char *radeon_get_name(struct pipe_winsys *ws) { - return "RADEON/DRI2"; + return "Radeon/GEM+KMS"; } static struct pipe_buffer *radeon_buffer_create(struct pipe_winsys *ws, - unsigned alignment, - unsigned usage, - unsigned size) + unsigned alignment, + unsigned usage, + unsigned size) { - struct radeon_pipe_winsys *radeon_ws = (struct radeon_pipe_winsys *)ws; + struct radeon_winsys *radeon_ws = (struct radeon_winsys *)ws; struct radeon_pipe_buffer *radeon_buffer; uint32_t domain; - radeon_buffer = calloc(1, sizeof(*radeon_buffer)); + radeon_buffer = CALLOC_STRUCT(radeon_pipe_buffer); if (radeon_buffer == NULL) { return NULL; } + radeon_buffer->base.refcount = 1; radeon_buffer->base.alignment = alignment; radeon_buffer->base.usage = usage; @@ -69,21 +76,21 @@ static struct pipe_buffer *radeon_buffer_create(struct pipe_winsys *ws, if (usage & PIPE_BUFFER_USAGE_VERTEX) { domain |= RADEON_GEM_DOMAIN_GTT; } - if (usage & PIPE_BUFFER_USAGE_INDEX) { domain |= RADEON_GEM_DOMAIN_GTT; } - radeon_buffer->bo = radeon_bo_open(radeon_ws->radeon_screen->bom, 0, - size, alignment, domain, 0); + + radeon_buffer->bo = radeon_bo_open(radeon_ws->bom, 0, size, alignment, + domain, 0); if (radeon_buffer->bo == NULL) { - free(radeon_buffer); + FREE(radeon_buffer); } return &radeon_buffer->base; } static struct pipe_buffer *radeon_buffer_user_create(struct pipe_winsys *ws, - void *ptr, - unsigned bytes) + void *ptr, + unsigned bytes) { struct radeon_pipe_buffer *radeon_buffer; @@ -106,21 +113,20 @@ static void radeon_buffer_del(struct pipe_winsys *ws, struct pipe_buffer *buffer } static void *radeon_buffer_map(struct pipe_winsys *ws, - struct pipe_buffer *buffer, - unsigned flags) + struct pipe_buffer *buffer, + unsigned flags) { struct radeon_pipe_buffer *radeon_buffer = (struct radeon_pipe_buffer*)buffer; int write = 0; if (flags & PIPE_BUFFER_USAGE_DONTBLOCK) { - /* Remove this when radeon_bo_map supports DONTBLOCK - */ + /* XXX Remove this when radeon_bo_map supports DONTBLOCK */ return NULL; } - if (flags & PIPE_BUFFER_USAGE_CPU_WRITE) { write = 1; } + if (radeon_bo_map(radeon_buffer->bo, write)) return NULL; return radeon_buffer->bo->ptr; @@ -134,59 +140,58 @@ static void radeon_buffer_unmap(struct pipe_winsys *ws, struct pipe_buffer *buff } static void radeon_fence_reference(struct pipe_winsys *ws, - struct pipe_fence_handle **ptr, - struct pipe_fence_handle *pfence) + struct pipe_fence_handle **ptr, + struct pipe_fence_handle *pfence) { } static int radeon_fence_signalled(struct pipe_winsys *ws, - struct pipe_fence_handle *pfence, - unsigned flag) + struct pipe_fence_handle *pfence, + unsigned flag) { return 1; } static int radeon_fence_finish(struct pipe_winsys *ws, - struct pipe_fence_handle *pfence, - unsigned flag) + struct pipe_fence_handle *pfence, + unsigned flag) { return 0; } static void radeon_flush_frontbuffer(struct pipe_winsys *pipe_winsys, - struct pipe_surface *pipe_surface, - void *context_private) + struct pipe_surface *pipe_surface, + void *context_private) { /* TODO: call dri2CopyRegion */ } -struct pipe_winsys *radeon_pipe_winsys(struct radeon_screen *radeon_screen) +struct pipe_winsys *radeon_pipe_winsys() { - struct radeon_pipe_winsys *radeon_ws; + struct pipe_winsys *radeon_ws; - radeon_ws = calloc(1, sizeof(struct radeon_pipe_winsys)); + radeon_ws = CALLOC_STRUCT(pipe_winsys); if (radeon_ws == NULL) { return NULL; } - radeon_ws->radeon_screen = radeon_screen; - radeon_ws->winsys.flush_frontbuffer = radeon_flush_frontbuffer; + radeon_ws->flush_frontbuffer = radeon_flush_frontbuffer; - radeon_ws->winsys.buffer_create = radeon_buffer_create; - radeon_ws->winsys.buffer_destroy = radeon_buffer_del; - radeon_ws->winsys.user_buffer_create = radeon_buffer_user_create; - radeon_ws->winsys.buffer_map = radeon_buffer_map; - radeon_ws->winsys.buffer_unmap = radeon_buffer_unmap; + radeon_ws->buffer_create = radeon_buffer_create; + radeon_ws->buffer_destroy = radeon_buffer_del; + radeon_ws->user_buffer_create = radeon_buffer_user_create; + radeon_ws->buffer_map = radeon_buffer_map; + radeon_ws->buffer_unmap = radeon_buffer_unmap; - radeon_ws->winsys.fence_reference = radeon_fence_reference; - radeon_ws->winsys.fence_signalled = radeon_fence_signalled; - radeon_ws->winsys.fence_finish = radeon_fence_finish; + radeon_ws->fence_reference = radeon_fence_reference; + radeon_ws->fence_signalled = radeon_fence_signalled; + radeon_ws->fence_finish = radeon_fence_finish; - radeon_ws->winsys.get_name = radeon_get_name; + radeon_ws->get_name = radeon_get_name; - return &radeon_ws->winsys; + return radeon_ws; } - +#if 0 static struct pipe_buffer *radeon_buffer_from_handle(struct radeon_screen *radeon_screen, uint32_t handle) { @@ -243,3 +248,4 @@ struct pipe_surface *radeon_surface_from_handle(struct radeon_context *radeon_co PIPE_BUFFER_USAGE_GPU_WRITE); return ps; } +#endif \ No newline at end of file diff --git a/src/gallium/winsys/drm/radeon/radeon_buffer.h b/src/gallium/winsys/drm/radeon/radeon_buffer.h index c626c20229..e062308f44 100644 --- a/src/gallium/winsys/drm/radeon/radeon_buffer.h +++ b/src/gallium/winsys/drm/radeon/radeon_buffer.h @@ -40,12 +40,15 @@ struct radeon_pipe_buffer { struct radeon_bo *bo; }; -struct radeon_pipe_winsys { - struct pipe_winsys winsys; - struct radeon_screen *radeon_screen; +struct radeon_winsys { + /* Parent class. */ + struct pipe_winsys base; + + /* Radeon BO manager. This corresponds to void* radeon_winsys in r300_winsys. */ + struct radeon_bo_manager* bom; }; -struct pipe_winsys *radeon_pipe_winsys(struct radeon_screen *radeon_screen); +struct pipe_winsys *radeon_pipe_winsys(); struct pipe_surface *radeon_surface_from_handle(struct radeon_context *radeon_context, uint32_t handle, enum pipe_format format, diff --git a/src/gallium/winsys/drm/radeon/radeon_drm.c b/src/gallium/winsys/drm/radeon/radeon_drm.c index 839b0bf0bd..9cd178f944 100644 --- a/src/gallium/winsys/drm/radeon/radeon_drm.c +++ b/src/gallium/winsys/drm/radeon/radeon_drm.c @@ -27,4 +27,84 @@ * Authors: * Corbin Simpson */ + #include "radeon_drm.h" + +/* Create a pipe_screen. */ +struct pipe_screen* radeon_create_screen(int drmFB, int pciID) +{ + struct radeon_context* radeon = CALLOC_STRUCT(radeon_context); + struct pipe_winsys* winsys = radeon_pipe_winsys(radeon); + + if (getenv("RADEON_SOFTPIPE")) { + return softpipe_create_screen(winsys); + } else { + struct r300_winsys* r300 = radeon_create_r300_winsys(drmFB, winsys); + FREE(winsys); + return r300_create_screen(r300); + } +} + +/* Create a pipe_context. */ +struct pipe_context* radeon_create_context(struct pipe_screen* screen) +{ + if (getenv("RADEON_SOFTPIPE")) { + return radeon_create_softpipe(screen->winsys); + } else { + return r300_create_context(screen, screen->winsys); + } +} + +boolean radeon_buffer_from_texture(struct pipe_texture* texture, + struct pipe_buffer** buffer, + unsigned* stride) +{ +} + +/* Create a buffer from a handle. */ +/* XXX what's up with name? */ +struct pipe_buffer* radeon_buffer_from_handle(struct pipe_screen* screen, + const char* name, + unsigned handle) +{ + struct radeon_bo_manager* bom = ((struct radeon_winsys*)screen->winsys)->bom; + struct radeon_pipe_buffer* radeon_buffer; + struct radeon_bo* bo = NULL; + + bo = radeon_bo_open(bom, handle, 0, 0, 0, 0); + if (bo == NULL) { + return NULL; + } + + radeon_buffer = CALLOC_STRUCT(radeon_pipe_buffer); + if (radeon_buffer == NULL) { + radeon_bo_unref(bo); + return NULL; + } + + radeon_buffer->base.refcount = 1; + radeon_buffer->base.usage = PIPE_BUFFER_USAGE_PIXEL; + radeon_buffer->bo = bo; + return &radeon_buffer->base; +} + +boolean radeon_handle_from_buffer(struct pipe_screen* screen, + struct pipe_buffer* buffer, + unsigned* handle) +{ +} + +boolean radeon_global_handle_from_buffer(struct pipe_screen* screen, + struct pipe_buffer* buffer, + unsigned* handle) +{ +} + +struct drm_api drm_api_hooks = { + .create_screen = radeon_create_screen, + .create_context = radeon_create_context, + .buffer_from_texture = radeon_buffer_from_texture, + .buffer_from_handle = radeon_buffer_from_handle, + .handle_from_buffer = radeon_handle_from_buffer, + .global_handle_from_buffer = radeon_global_handle_from_buffer, +}; \ No newline at end of file diff --git a/src/gallium/winsys/drm/radeon/radeon_drm.h b/src/gallium/winsys/drm/radeon/radeon_drm.h index 8ccbc81895..e434106cb5 100644 --- a/src/gallium/winsys/drm/radeon/radeon_drm.h +++ b/src/gallium/winsys/drm/radeon/radeon_drm.h @@ -30,6 +30,36 @@ #ifndef RADEON_DRM_H #define RADEON_DRM_H +#include "pipe/p_screen.h" + +#include "util/u_memory.h" + #include "state_tracker/drm_api.h" +#include "radeon_buffer.h" +#include "radeon_context.h" +#include "radeon_r300.h" +#include "radeon_screen.h" +#include "radeon_winsys_softpipe.h" + +struct pipe_screen* radeon_create_screen(int drmFB, int pciID); + +struct pipe_context* radeon_create_context(struct pipe_screen* screen); + +boolean radeon_buffer_from_texture(struct pipe_texture* texture, + struct pipe_buffer** buffer, + unsigned* stride); + +struct pipe_buffer* radeon_buffer_from_handle(struct pipe_screen* screen, + const char* name, + unsigned handle); + +boolean radeon_handle_from_buffer(struct pipe_screen* screen, + struct pipe_buffer* buffer, + unsigned* handle); + +boolean radeon_global_handle_from_buffer(struct pipe_screen* screen, + struct pipe_buffer* buffer, + unsigned* handle); + #endif diff --git a/src/gallium/winsys/drm/radeon/radeon_r300.c b/src/gallium/winsys/drm/radeon/radeon_r300.c index 8fe2375e34..e9b96b1ee9 100644 --- a/src/gallium/winsys/drm/radeon/radeon_r300.c +++ b/src/gallium/winsys/drm/radeon/radeon_r300.c @@ -75,14 +75,16 @@ static void do_ioctls(struct r300_winsys* winsys, int fd) } -struct r300_winsys* radeon_create_r300_winsys(int fd) +struct r300_winsys* radeon_create_r300_winsys(int fd, struct pipe_winsys* old_winsys) { - struct r300_winsys* winsys = calloc(1, sizeof(struct r300_winsys)); + struct r300_winsys* winsys = CALLOC_STRUCT(r300_winsys); do_ioctls(winsys, fd); + struct radeon_bo_manager* bom = radeon_bo_manager_gem_ctor(fd); struct radeon_cs_manager* csm = radeon_cs_manager_gem_ctor(fd); + winsys->radeon_winsys = bom; winsys->cs = radeon_cs_create(csm, 1024 * 64 / 4); winsys->check_cs = radeon_r300_check_cs; @@ -92,5 +94,7 @@ struct r300_winsys* radeon_create_r300_winsys(int fd) winsys->end_cs = radeon_cs_end; winsys->flush_cs = radeon_r300_flush_cs; + winsys->base = *old_winsys; + return winsys; } diff --git a/src/gallium/winsys/drm/radeon/radeon_r300.h b/src/gallium/winsys/drm/radeon/radeon_r300.h index 8ed95a3a9b..432b7b1833 100644 --- a/src/gallium/winsys/drm/radeon/radeon_r300.h +++ b/src/gallium/winsys/drm/radeon/radeon_r300.h @@ -31,4 +31,4 @@ #include "radeon_buffer.h" -struct r300_winsys* radeon_create_r300_winsys(int fd); +struct r300_winsys* radeon_create_r300_winsys(int fd, struct pipe_winsys* old_winsys); diff --git a/src/gallium/winsys/drm/radeon/radeon_winsys_softpipe.c b/src/gallium/winsys/drm/radeon/radeon_winsys_softpipe.c index 8402e1fa5a..75e975f5e2 100644 --- a/src/gallium/winsys/drm/radeon/radeon_winsys_softpipe.c +++ b/src/gallium/winsys/drm/radeon/radeon_winsys_softpipe.c @@ -29,7 +29,6 @@ * Authors: Keith Whitwell */ #include -#include "imports.h" #include "pipe/p_defines.h" #include "pipe/p_format.h" #include "softpipe/sp_winsys.h" @@ -57,21 +56,19 @@ static boolean radeon_is_format_supported(struct softpipe_winsys *sws, uint form return FALSE; } -struct pipe_context *radeon_create_softpipe(struct radeon_context *radeon_context) +struct pipe_context *radeon_create_softpipe(struct pipe_winsys* winsys) { struct radeon_softpipe_winsys *radeon_sp_ws; struct pipe_screen *pipe_screen; - pipe_screen = softpipe_create_screen(radeon_context->pipe_winsys); + pipe_screen = softpipe_create_screen(winsys); radeon_sp_ws = CALLOC_STRUCT(radeon_softpipe_winsys); if (radeon_sp_ws == NULL) { return NULL; } - radeon_context->pipe_screen = pipe_screen; - radeon_sp_ws->radeon_context = radeon_context; radeon_sp_ws->sp_winsys.is_format_supported = radeon_is_format_supported; return softpipe_create(pipe_screen, - radeon_context->pipe_winsys, + winsys, &radeon_sp_ws->sp_winsys); } diff --git a/src/gallium/winsys/drm/radeon/radeon_winsys_softpipe.h b/src/gallium/winsys/drm/radeon/radeon_winsys_softpipe.h index 519eab769c..093693eddf 100644 --- a/src/gallium/winsys/drm/radeon/radeon_winsys_softpipe.h +++ b/src/gallium/winsys/drm/radeon/radeon_winsys_softpipe.h @@ -32,6 +32,6 @@ #include "radeon_context.h" -struct pipe_context *radeon_create_softpipe(struct radeon_context *radeon_context); +struct pipe_context *radeon_create_softpipe(struct pipe_winsys* winsys); #endif -- cgit v1.2.3 From 60041203d5847de8ab71842a6ce5d33d96cc4930 Mon Sep 17 00:00:00 2001 From: Corbin Simpson Date: Tue, 3 Mar 2009 22:11:56 -0800 Subject: r300-gallium, radeon-gallium: Continue migration to DRI2 state_tracker, part 2. Almost there. glxinfo still works, and AFAICT so does trivial/clear. --- src/gallium/drivers/r300/r300_texture.c | 18 ++++++++++++++++++ src/gallium/drivers/r300/r300_texture.h | 8 ++++++++ src/gallium/drivers/r300/r300_winsys.h | 4 ++++ src/gallium/winsys/drm/radeon/radeon_drm.c | 18 +++++++++++++++--- 4 files changed, 45 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c index 8251a597ea..b3425587e3 100644 --- a/src/gallium/drivers/r300/r300_texture.c +++ b/src/gallium/drivers/r300/r300_texture.c @@ -186,3 +186,21 @@ void r300_init_screen_texture_functions(struct pipe_screen* screen) screen->tex_surface_release = r300_tex_surface_release; screen->texture_blanket = r300_texture_blanket; } + +boolean r300_get_texture_buffer(struct pipe_texture* texture, + struct pipe_buffer** buffer, + unsigned* stride) +{ + struct r300_texture* tex = (struct r300_texture*)texture; + if (!tex) { + return FALSE; + } + + pipe_buffer_reference(texture->screen, buffer, tex->buffer); + + if (stride) { + *stride = tex->stride; + } + + return TRUE; +} diff --git a/src/gallium/drivers/r300/r300_texture.h b/src/gallium/drivers/r300/r300_texture.h index 7964229a94..27f5ea1eb7 100644 --- a/src/gallium/drivers/r300/r300_texture.h +++ b/src/gallium/drivers/r300/r300_texture.h @@ -31,4 +31,12 @@ void r300_init_screen_texture_functions(struct pipe_screen* screen); +#ifndef R300_WINSYS_H + +boolean r300_get_texture_buffer(struct pipe_texture* texture, + struct pipe_buffer** buffer, + unsigned* stride); + +#endif /* R300_WINSYS_H */ + #endif /* R300_TEXTURE_H */ diff --git a/src/gallium/drivers/r300/r300_winsys.h b/src/gallium/drivers/r300/r300_winsys.h index b7341c4f3a..8c9578de51 100644 --- a/src/gallium/drivers/r300/r300_winsys.h +++ b/src/gallium/drivers/r300/r300_winsys.h @@ -92,4 +92,8 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen, } #endif +boolean r300_get_texture_buffer(struct pipe_texture* texture, + struct pipe_buffer** buffer, + unsigned* stride); + #endif /* R300_WINSYS_H */ diff --git a/src/gallium/winsys/drm/radeon/radeon_drm.c b/src/gallium/winsys/drm/radeon/radeon_drm.c index 9cd178f944..21f2a62e0f 100644 --- a/src/gallium/winsys/drm/radeon/radeon_drm.c +++ b/src/gallium/winsys/drm/radeon/radeon_drm.c @@ -59,6 +59,7 @@ boolean radeon_buffer_from_texture(struct pipe_texture* texture, struct pipe_buffer** buffer, unsigned* stride) { + return FALSE; } /* Create a buffer from a handle. */ @@ -67,7 +68,8 @@ struct pipe_buffer* radeon_buffer_from_handle(struct pipe_screen* screen, const char* name, unsigned handle) { - struct radeon_bo_manager* bom = ((struct radeon_winsys*)screen->winsys)->bom; + struct radeon_bo_manager* bom = + ((struct radeon_winsys*)screen->winsys)->bom; struct radeon_pipe_buffer* radeon_buffer; struct radeon_bo* bo = NULL; @@ -92,19 +94,29 @@ boolean radeon_handle_from_buffer(struct pipe_screen* screen, struct pipe_buffer* buffer, unsigned* handle) { + struct radeon_pipe_buffer* radeon_buffer = + (struct radeon_pipe_buffer*)buffer; + *handle = radeon_buffer->bo->handle; + return TRUE; } boolean radeon_global_handle_from_buffer(struct pipe_screen* screen, struct pipe_buffer* buffer, unsigned* handle) { + /* XXX WTF is the difference here? global? */ + struct radeon_pipe_buffer* radeon_buffer = + (struct radeon_pipe_buffer*)buffer; + *handle = radeon_buffer->bo->handle; + return TRUE; } struct drm_api drm_api_hooks = { .create_screen = radeon_create_screen, .create_context = radeon_create_context, - .buffer_from_texture = radeon_buffer_from_texture, + /* XXX fix this */ + .buffer_from_texture = r300_get_texture_buffer, .buffer_from_handle = radeon_buffer_from_handle, .handle_from_buffer = radeon_handle_from_buffer, .global_handle_from_buffer = radeon_global_handle_from_buffer, -}; \ No newline at end of file +}; -- cgit v1.2.3 From 5e27cd46c04a9e7b5904cc014bffd0f4daae31fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michel=20D=C3=A4nzer?= Date: Wed, 4 Mar 2009 11:58:48 +0100 Subject: gallium: Unify reference counting. The core reference counting code is centralized in p_refcnt.h. This has some consequences related to struct pipe_buffer: * The screen member of struct pipe_buffer must be initialized, or pipe_buffer_reference() will crash trying to destroy a buffer with reference count 0. u_simple_screen takes care of this, but I may have missed some of the drivers not using it. * Except for rare exceptions deep in winsys code, buffers must always be allocated via pipe_buffer_create() or via screen->*buffer_create() rather than via winsys->*buffer_create(). --- src/gallium/auxiliary/draw/draw_pipe_aaline.c | 4 +- src/gallium/auxiliary/draw/draw_pipe_pstipple.c | 4 +- src/gallium/auxiliary/pipebuffer/pb_buffer.h | 25 ++--- .../auxiliary/pipebuffer/pb_buffer_fenced.c | 16 +-- .../auxiliary/pipebuffer/pb_buffer_malloc.c | 2 +- src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c | 11 +- src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c | 8 +- src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c | 6 +- .../auxiliary/pipebuffer/pb_bufmgr_ondemand.c | 2 +- src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c | 8 +- src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c | 6 +- src/gallium/auxiliary/sct/sct.c | 2 +- src/gallium/auxiliary/util/u_blit.c | 17 +-- src/gallium/auxiliary/util/u_debug.c | 4 +- src/gallium/auxiliary/util/u_draw_quad.c | 2 +- src/gallium/auxiliary/util/u_gen_mipmap.c | 17 +-- src/gallium/auxiliary/util/u_rect.c | 6 +- src/gallium/auxiliary/util/u_simple_screen.c | 28 +++-- src/gallium/auxiliary/util/u_timed_winsys.c | 7 +- src/gallium/drivers/cell/ppu/cell_fence.c | 6 +- src/gallium/drivers/cell/ppu/cell_texture.c | 65 ++++------- src/gallium/drivers/failover/fo_context.c | 2 +- src/gallium/drivers/i915simple/i915_prim_vbuf.c | 2 +- src/gallium/drivers/i915simple/i915_screen.c | 16 +-- src/gallium/drivers/i915simple/i915_texture.c | 72 +++++------- src/gallium/drivers/i965simple/brw_tex_layout.c | 38 +++---- .../drivers/i965simple/brw_wm_surface_state.c | 2 +- src/gallium/drivers/nouveau/nouveau_stateobj.h | 12 +- src/gallium/drivers/nv04/nv04_miptree.c | 33 ++---- src/gallium/drivers/nv04/nv04_transfer.c | 11 +- src/gallium/drivers/nv10/nv10_miptree.c | 43 +++----- src/gallium/drivers/nv10/nv10_prim_vbuf.c | 6 +- src/gallium/drivers/nv10/nv10_transfer.c | 11 +- src/gallium/drivers/nv20/nv20_miptree.c | 46 +++----- src/gallium/drivers/nv20/nv20_prim_vbuf.c | 6 +- src/gallium/drivers/nv20/nv20_transfer.c | 11 +- src/gallium/drivers/nv30/nv30_fragprog.c | 3 +- src/gallium/drivers/nv30/nv30_miptree.c | 33 ++---- src/gallium/drivers/nv30/nv30_transfer.c | 11 +- src/gallium/drivers/nv40/nv40_fragprog.c | 3 +- src/gallium/drivers/nv40/nv40_miptree.c | 33 ++---- src/gallium/drivers/nv40/nv40_transfer.c | 11 +- src/gallium/drivers/nv50/nv50_miptree.c | 41 +++---- src/gallium/drivers/nv50/nv50_program.c | 6 +- src/gallium/drivers/nv50/nv50_query.c | 6 +- src/gallium/drivers/nv50/nv50_screen.c | 6 +- src/gallium/drivers/nv50/nv50_transfer.c | 13 +-- src/gallium/drivers/r300/r300_screen.c | 16 +-- src/gallium/drivers/r300/r300_swtcl_emit.c | 5 +- src/gallium/drivers/r300/r300_texture.c | 48 +++----- src/gallium/drivers/softpipe/sp_context.c | 3 +- src/gallium/drivers/softpipe/sp_state_fs.c | 4 +- src/gallium/drivers/softpipe/sp_texture.c | 76 +++++-------- src/gallium/drivers/softpipe/sp_tile_cache.c | 14 +-- src/gallium/drivers/trace/tr_screen.c | 122 ++++++--------------- src/gallium/drivers/trace/tr_state.c | 12 +- src/gallium/drivers/trace/tr_texture.c | 4 +- src/gallium/drivers/trace/tr_winsys.c | 8 +- .../include/pipe/internal/p_winsys_screen.h | 3 +- src/gallium/include/pipe/p_inlines.h | 113 ------------------- src/gallium/include/pipe/p_refcnt.h | 84 ++++++++++++++ src/gallium/include/pipe/p_screen.h | 16 +-- src/gallium/include/pipe/p_state.h | 47 ++++++-- src/gallium/state_trackers/dri2/dri_drawable.c | 2 +- src/gallium/state_trackers/egl/egl_surface.c | 6 +- src/gallium/state_trackers/g3dvl/vl_basic_csc.c | 6 +- .../state_trackers/g3dvl/vl_r16snorm_mc_buf.c | 8 +- src/gallium/state_trackers/python/st_device.c | 24 ++-- src/gallium/state_trackers/python/st_device.h | 6 +- .../state_trackers/python/st_softpipe_winsys.c | 4 +- src/gallium/state_trackers/xorg/xorg_crtc.c | 4 +- src/gallium/state_trackers/xorg/xorg_dri2.c | 2 +- src/gallium/state_trackers/xorg/xorg_exa.c | 12 +- .../winsys/drm/intel/gem/intel_be_batchbuffer.c | 4 +- src/gallium/winsys/drm/intel/gem/intel_be_device.c | 19 +--- src/gallium/winsys/drm/intel/gem/intel_be_fence.h | 18 ++- .../winsys/drm/nouveau/common/nouveau_context.c | 7 +- .../winsys/drm/nouveau/common/nouveau_context.h | 2 +- .../drm/nouveau/common/nouveau_winsys_pipe.c | 6 +- src/gallium/winsys/drm/radeon/radeon_buffer.c | 10 +- src/gallium/winsys/drm/radeon/radeon_drm.c | 3 +- src/gallium/winsys/egl_xlib/sw_winsys.c | 6 +- src/gallium/winsys/g3dvl/xsp_winsys.c | 4 +- src/gallium/winsys/gdi/gdi_softpipe_winsys.c | 7 +- src/gallium/winsys/xlib/xlib_brw_screen.c | 7 +- src/gallium/winsys/xlib/xlib_cell.c | 4 +- src/gallium/winsys/xlib/xlib_softpipe.c | 7 +- src/mesa/state_tracker/st_atom_constbuf.c | 2 +- src/mesa/state_tracker/st_atom_pixeltransfer.c | 2 +- src/mesa/state_tracker/st_cb_accum.c | 18 +-- src/mesa/state_tracker/st_cb_bitmap.c | 16 +-- src/mesa/state_tracker/st_cb_bufferobjects.c | 5 +- src/mesa/state_tracker/st_cb_clear.c | 8 +- src/mesa/state_tracker/st_cb_drawpixels.c | 12 +- src/mesa/state_tracker/st_cb_fbo.c | 3 +- src/mesa/state_tracker/st_cb_readpixels.c | 8 +- src/mesa/state_tracker/st_cb_texture.c | 16 +-- src/mesa/state_tracker/st_context.c | 2 +- src/mesa/state_tracker/st_draw.c | 10 +- src/mesa/state_tracker/st_draw_feedback.c | 4 +- src/mesa/state_tracker/st_gen_mipmap.c | 4 +- src/mesa/state_tracker/st_texture.c | 10 +- 102 files changed, 653 insertions(+), 943 deletions(-) create mode 100644 src/gallium/include/pipe/p_refcnt.h (limited to 'src') diff --git a/src/gallium/auxiliary/draw/draw_pipe_aaline.c b/src/gallium/auxiliary/draw/draw_pipe_aaline.c index 80c9c918a9..e83a075794 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_aaline.c +++ b/src/gallium/auxiliary/draw/draw_pipe_aaline.c @@ -446,7 +446,7 @@ aaline_create_texture(struct aaline_stage *aaline) /* unmap */ screen->transfer_unmap(screen, transfer); - screen->tex_transfer_release(screen, &transfer); + screen->tex_transfer_destroy(transfer); } return TRUE; } @@ -728,7 +728,7 @@ aaline_destroy(struct draw_stage *stage) aaline->pipe->delete_sampler_state(aaline->pipe, aaline->sampler_cso); if (aaline->texture) - pipe_texture_release(&aaline->texture); + pipe_texture_reference(&aaline->texture, NULL); draw_free_temp_verts( stage ); diff --git a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c index e68c824c86..fa7bc67476 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c +++ b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c @@ -406,7 +406,7 @@ pstip_update_texture(struct pstip_stage *pstip) /* unmap */ screen->transfer_unmap(screen, transfer); - screen->tex_transfer_release(screen, &transfer); + screen->tex_transfer_destroy(transfer); } @@ -572,7 +572,7 @@ pstip_destroy(struct draw_stage *stage) pstip->pipe->delete_sampler_state(pstip->pipe, pstip->sampler_cso); - pipe_texture_release(&pstip->texture); + pipe_texture_reference(&pstip->texture, NULL); draw_free_temp_verts( stage ); FREE( stage ); diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer.h b/src/gallium/auxiliary/pipebuffer/pb_buffer.h index e6b0b30ff4..be1654c654 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_buffer.h +++ b/src/gallium/auxiliary/pipebuffer/pb_buffer.h @@ -159,7 +159,7 @@ pb_map(struct pb_buffer *buf, assert(buf); if(!buf) return NULL; - assert(buf->base.refcount > 0); + assert(buf->base.reference.count > 0); return buf->vtbl->map(buf, flags); } @@ -170,7 +170,7 @@ pb_unmap(struct pb_buffer *buf) assert(buf); if(!buf) return; - assert(buf->base.refcount > 0); + assert(buf->base.reference.count > 0); buf->vtbl->unmap(buf); } @@ -186,7 +186,7 @@ pb_get_base_buffer( struct pb_buffer *buf, offset = 0; return; } - assert(buf->base.refcount > 0); + assert(buf->base.reference.count > 0); assert(buf->vtbl->get_base_buffer); buf->vtbl->get_base_buffer(buf, base_buf, offset); assert(*base_buf); @@ -222,29 +222,18 @@ pb_destroy(struct pb_buffer *buf) assert(buf); if(!buf) return; - assert(buf->base.refcount == 0); + assert(buf->base.reference.count == 0); buf->vtbl->destroy(buf); } - -/* XXX: thread safety issues! - */ static INLINE void pb_reference(struct pb_buffer **dst, struct pb_buffer *src) { - if (src) { - assert(src->base.refcount); - src->base.refcount++; - } - - if (*dst) { - assert((*dst)->base.refcount); - if(--(*dst)->base.refcount == 0) - pb_destroy( *dst ); - } + struct pb_buffer *old = *dst; - *dst = src; + if (pipe_reference((struct pipe_reference**)dst, &src->base.reference)) + pb_destroy( old ); } diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c index 17ff61b675..e4adf8aad7 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c +++ b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c @@ -115,7 +115,7 @@ _fenced_buffer_add(struct fenced_buffer *fenced_buf) { struct fenced_buffer_list *fenced_list = fenced_buf->list; - assert(fenced_buf->base.base.refcount); + assert(fenced_buf->base.base.reference.count); assert(fenced_buf->flags & PIPE_BUFFER_USAGE_GPU_READ_WRITE); assert(fenced_buf->fence); @@ -137,7 +137,7 @@ _fenced_buffer_destroy(struct fenced_buffer *fenced_buf) { struct fenced_buffer_list *fenced_list = fenced_buf->list; - assert(!fenced_buf->base.base.refcount); + assert(!fenced_buf->base.base.reference.count); assert(!fenced_buf->fence); #ifdef DEBUG assert(fenced_buf->head.prev); @@ -177,7 +177,7 @@ _fenced_buffer_remove(struct fenced_buffer_list *fenced_list, ++fenced_list->numUnfenced; #endif - if(!fenced_buf->base.base.refcount) + if(!fenced_buf->base.base.reference.count) _fenced_buffer_destroy(fenced_buf); } @@ -253,7 +253,7 @@ fenced_buffer_destroy(struct pb_buffer *buf) struct fenced_buffer_list *fenced_list = fenced_buf->list; pipe_mutex_lock(fenced_list->mutex); - assert(fenced_buf->base.base.refcount == 0); + assert(fenced_buf->base.base.reference.count == 0); if (fenced_buf->fence) { struct pb_fence_ops *ops = fenced_list->ops; if(ops->fence_signalled(ops, fenced_buf->fence, 0) == 0) { @@ -461,7 +461,7 @@ fenced_buffer_create(struct fenced_buffer_list *fenced_list, return NULL; } - buf->base.base.refcount = 1; + pipe_reference_init(&buf->base.base.reference, 1); buf->base.base.alignment = buffer->base.alignment; buf->base.base.usage = buffer->base.usage; buf->base.base.size = buffer->base.size; @@ -527,7 +527,7 @@ fenced_buffer_list_dump(struct fenced_buffer_list *fenced_list) pipe_mutex_lock(fenced_list->mutex); debug_printf("%10s %7s %10s %s\n", - "buffer", "refcount", "fence", "signalled"); + "buffer", "reference.count", "fence", "signalled"); curr = fenced_list->unfenced.next; next = curr->next; @@ -536,7 +536,7 @@ fenced_buffer_list_dump(struct fenced_buffer_list *fenced_list) assert(!fenced_buf->fence); debug_printf("%10p %7u\n", fenced_buf, - fenced_buf->base.base.refcount); + fenced_buf->base.base.reference.count); curr = next; next = curr->next; } @@ -549,7 +549,7 @@ fenced_buffer_list_dump(struct fenced_buffer_list *fenced_list) signaled = ops->fence_signalled(ops, fenced_buf->fence, 0); debug_printf("%10p %7u %10p %s\n", fenced_buf, - fenced_buf->base.base.refcount, + fenced_buf->base.base.reference.count, fenced_buf->fence, signaled == 0 ? "y" : "n"); curr = next; diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c b/src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c index 282802b171..689fd74771 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c +++ b/src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c @@ -132,7 +132,7 @@ pb_malloc_buffer_create(size_t size, if(!buf) return NULL; - buf->base.base.refcount = 1; + pipe_reference_init(&buf->base.base.reference, 1); buf->base.base.alignment = desc->alignment; buf->base.base.usage = desc->usage; buf->base.base.size = size; diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c index 29117efe9b..06ed0002ca 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c @@ -112,7 +112,7 @@ _pb_cache_buffer_destroy(struct pb_cache_buffer *buf) LIST_DEL(&buf->head); assert(mgr->numDelayed); --mgr->numDelayed; - assert(!buf->base.base.refcount); + assert(!buf->base.base.reference.count); pb_reference(&buf->buffer, NULL); FREE(buf); } @@ -153,7 +153,7 @@ pb_cache_buffer_destroy(struct pb_buffer *_buf) struct pb_cache_manager *mgr = buf->mgr; pipe_mutex_lock(mgr->mutex); - assert(buf->base.base.refcount == 0); + assert(buf->base.base.reference.count == 0); _pb_cache_buffer_list_check_free(mgr); @@ -293,7 +293,8 @@ pb_cache_manager_create_buffer(struct pb_manager *_mgr, if(buf) { LIST_DEL(&buf->head); pipe_mutex_unlock(mgr->mutex); - ++buf->base.base.refcount; + /* Increase refcount */ + pb_reference((struct pb_buffer**)&buf, &buf->base); return &buf->base; } @@ -309,12 +310,12 @@ pb_cache_manager_create_buffer(struct pb_manager *_mgr, return NULL; } - assert(buf->buffer->base.refcount >= 1); + assert(buf->buffer->base.reference.count >= 1); assert(pb_check_alignment(desc->alignment, buf->buffer->base.alignment)); assert(pb_check_usage(desc->usage, buf->buffer->base.usage)); assert(buf->buffer->base.size >= size); - buf->base.base.refcount = 1; + pipe_reference_init(&buf->base.base.reference, 1); buf->base.base.alignment = buf->buffer->base.alignment; buf->base.base.usage = buf->buffer->base.usage; buf->base.base.size = buf->buffer->base.size; diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c index 21079b8bfd..37ed64b84f 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c @@ -206,9 +206,9 @@ pb_debug_buffer_check(struct pb_debug_buffer *buf) static void pb_debug_buffer_destroy(struct pb_buffer *_buf) { - struct pb_debug_buffer *buf = pb_debug_buffer(_buf); + struct pb_debug_buffer *buf = pb_debug_buffer(_buf); - assert(!buf->base.base.refcount); + assert(!buf->base.base.reference.count); pb_debug_buffer_check(buf); @@ -315,12 +315,12 @@ pb_debug_manager_create_buffer(struct pb_manager *_mgr, return NULL; } - assert(buf->buffer->base.refcount >= 1); + assert(buf->buffer->base.reference.count >= 1); assert(pb_check_alignment(real_desc.alignment, buf->buffer->base.alignment)); assert(pb_check_usage(real_desc.usage, buf->buffer->base.usage)); assert(buf->buffer->base.size >= real_size); - buf->base.base.refcount = 1; + pipe_reference_init(&buf->base.base.reference, 1); buf->base.base.alignment = desc->alignment; buf->base.base.usage = desc->usage; buf->base.base.size = size; diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c index 85ff3a09de..9b0f77bedb 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c @@ -97,11 +97,11 @@ mm_buffer_destroy(struct pb_buffer *buf) struct mm_buffer *mm_buf = mm_buffer(buf); struct mm_pb_manager *mm = mm_buf->mgr; - assert(buf->base.refcount == 0); + assert(mm_buf->base.base.reference.count == 0); pipe_mutex_lock(mm->mutex); u_mmFreeMem(mm_buf->block); - FREE(buf); + FREE(mm_buf); pipe_mutex_unlock(mm->mutex); } @@ -189,7 +189,7 @@ mm_bufmgr_create_buffer(struct pb_manager *mgr, return NULL; } - mm_buf->base.base.refcount = 1; + pipe_reference_init(&mm_buf->base.base.reference, 1); mm_buf->base.base.alignment = desc->alignment; mm_buf->base.base.usage = desc->usage; mm_buf->base.base.size = size; diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c index 3d9c7bba0b..4f7e6b1c4d 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c @@ -242,7 +242,7 @@ pb_ondemand_manager_create_buffer(struct pb_manager *_mgr, if(!buf) return NULL; - buf->base.base.refcount = 1; + pipe_reference_init(&buf->base.base.reference, 1); buf->base.base.alignment = desc->alignment; buf->base.base.usage = desc->usage; buf->base.base.size = size; diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c index 12447acfd9..ca6c14a627 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c @@ -108,7 +108,7 @@ pool_buffer_destroy(struct pb_buffer *buf) struct pool_buffer *pool_buf = pool_buffer(buf); struct pool_pb_manager *pool = pool_buf->mgr; - assert(pool_buf->base.base.refcount == 0); + assert(pool_buf->base.base.reference.count == 0); pipe_mutex_lock(pool->mutex); LIST_ADD(&pool_buf->head, &pool->free); @@ -216,8 +216,8 @@ pool_bufmgr_create_buffer(struct pb_manager *mgr, pipe_mutex_unlock(pool->mutex); pool_buf = LIST_ENTRY(struct pool_buffer, item, head); - assert(pool_buf->base.base.refcount == 0); - pool_buf->base.base.refcount = 1; + assert(pool_buf->base.base.reference.count == 0); + pipe_reference_init(&pool_buf->base.base.reference, 1); pool_buf->base.base.alignment = desc->alignment; pool_buf->base.base.usage = desc->usage; @@ -295,7 +295,7 @@ pool_bufmgr_create(struct pb_manager *provider, pool_buf = pool->bufs; for (i = 0; i < numBufs; ++i) { - pool_buf->base.base.refcount = 0; + pipe_reference_init(&pool_buf->base.base.reference, 0); pool_buf->base.base.alignment = 0; pool_buf->base.base.usage = 0; pool_buf->base.base.size = bufSize; diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c index a3259351b9..2cdb5a5e29 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c @@ -202,7 +202,7 @@ pb_slab_buffer_destroy(struct pb_buffer *_buf) pipe_mutex_lock(mgr->mutex); - assert(buf->base.base.refcount == 0); + assert(buf->base.base.reference.count == 0); buf->mapCount = 0; @@ -340,7 +340,7 @@ pb_slab_create(struct pb_slab_manager *mgr) buf = slab->buffers; for (i=0; i < numBuffers; ++i) { - buf->base.base.refcount = 0; + pipe_reference_init(&buf->base.base.reference, 0); buf->base.base.size = mgr->bufSize; buf->base.base.alignment = 0; buf->base.base.usage = 0; @@ -419,7 +419,7 @@ pb_slab_manager_create_buffer(struct pb_manager *_mgr, pipe_mutex_unlock(mgr->mutex); buf = LIST_ENTRY(struct pb_slab_buffer, list, head); - ++buf->base.base.refcount; + pipe_reference_init(&buf->base.base.reference, 1); buf->base.base.alignment = desc->alignment; buf->base.base.usage = desc->usage; diff --git a/src/gallium/auxiliary/sct/sct.c b/src/gallium/auxiliary/sct/sct.c index 49bb7ea92e..fcfa04ef7d 100644 --- a/src/gallium/auxiliary/sct/sct.c +++ b/src/gallium/auxiliary/sct/sct.c @@ -372,7 +372,7 @@ sct_flush_textures(struct surface_context_tracker *sct, for (tl = ci->textures_used; tl; tl = next) { next = tl->next; - pipe_texture_release(&tl->texture); + pipe_texture_reference(&tl->texture, NULL); FREE(tl); } ci->textures_used = NULL; diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c index 4cc720269d..813e41f1b1 100644 --- a/src/gallium/auxiliary/util/u_blit.c +++ b/src/gallium/auxiliary/util/u_blit.c @@ -38,6 +38,7 @@ #include "pipe/p_defines.h" #include "pipe/p_inlines.h" #include "pipe/p_shader_tokens.h" +#include "pipe/p_state.h" #include "util/u_blit.h" #include "util/u_draw_quad.h" @@ -166,7 +167,7 @@ util_destroy_blit(struct blit_state *ctx) FREE((void*) ctx->vert_shader.tokens); FREE((void*) ctx->frag_shader.tokens); - pipe_buffer_reference(pipe->screen, &ctx->vbuf, NULL); + pipe_buffer_reference(&ctx->vbuf, NULL); FREE(ctx); } @@ -368,7 +369,7 @@ util_blit_pixels(struct blit_state *ctx, /* free the surface, update the texture if necessary. */ - screen->tex_surface_release(screen, &texSurf); + pipe_surface_reference(&texSurf, NULL); /* save state (restored below) */ cso_save_blend(ctx->cso); @@ -429,7 +430,7 @@ util_blit_pixels(struct blit_state *ctx, cso_restore_vertex_shader(ctx->cso); cso_restore_viewport(ctx->cso); - screen->texture_release(screen, &tex); + pipe_texture_reference(&tex, NULL); } @@ -438,7 +439,7 @@ util_blit_pixels(struct blit_state *ctx, */ void util_blit_flush( struct blit_state *ctx ) { - pipe_buffer_reference(ctx->pipe->screen, &ctx->vbuf, NULL); + pipe_buffer_reference(&ctx->vbuf, NULL); ctx->vbuf_slot = 0; } @@ -461,8 +462,6 @@ util_blit_pixels_tex(struct blit_state *ctx, int dstX1, int dstY1, float z, uint filter) { - struct pipe_context *pipe = ctx->pipe; - struct pipe_screen *screen = pipe->screen; struct pipe_framebuffer_state fb; float s0, t0, s1, t1; unsigned offset; @@ -478,8 +477,10 @@ util_blit_pixels_tex(struct blit_state *ctx, t0 = srcY0 / (float)tex->height[0]; t1 = srcY1 / (float)tex->height[0]; - assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)); + assert(ctx->pipe->screen->is_format_supported(ctx->pipe->screen, dst->format, + PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_RENDER_TARGET, + 0)); /* save state (restored below) */ cso_save_blend(ctx->cso); diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c index e05c419b2f..f96e27e09f 100644 --- a/src/gallium/auxiliary/util/u_debug.c +++ b/src/gallium/auxiliary/util/u_debug.c @@ -680,7 +680,7 @@ void debug_dump_surface(const char *prefix, screen->transfer_unmap(screen, transfer); error: - screen->tex_transfer_release(screen, &transfer); + screen->tex_transfer_destroy(transfer); } @@ -785,7 +785,7 @@ debug_dump_surface_bmp(const char *filename, } } - screen->tex_transfer_release(screen, &transfer); + screen->tex_transfer_destroy(transfer); util_stream_close(stream); error2: diff --git a/src/gallium/auxiliary/util/u_draw_quad.c b/src/gallium/auxiliary/util/u_draw_quad.c index f0bcd75899..4110485fb1 100644 --- a/src/gallium/auxiliary/util/u_draw_quad.c +++ b/src/gallium/auxiliary/util/u_draw_quad.c @@ -129,6 +129,6 @@ util_draw_texquad(struct pipe_context *pipe, util_draw_vertex_buffer(pipe, vbuf, 0, PIPE_PRIM_TRIANGLE_FAN, 4, 2); } - pipe_buffer_reference(pipe->screen, &vbuf, NULL); + pipe_buffer_reference(&vbuf, NULL); } } diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c index 1857a71dd8..2b675e71b2 100644 --- a/src/gallium/auxiliary/util/u_gen_mipmap.c +++ b/src/gallium/auxiliary/util/u_gen_mipmap.c @@ -39,6 +39,7 @@ #include "pipe/p_defines.h" #include "pipe/p_inlines.h" #include "pipe/p_shader_tokens.h" +#include "pipe/p_state.h" #include "util/u_memory.h" #include "util/u_draw_quad.h" @@ -1138,8 +1139,8 @@ make_1d_mipmap(struct gen_mipmap_state *ctx, screen->transfer_unmap(screen, srcTrans); screen->transfer_unmap(screen, dstTrans); - screen->tex_transfer_release(screen, &srcTrans); - screen->tex_transfer_release(screen, &dstTrans); + screen->tex_transfer_destroy(srcTrans); + screen->tex_transfer_destroy(dstTrans); } } @@ -1183,8 +1184,8 @@ make_2d_mipmap(struct gen_mipmap_state *ctx, screen->transfer_unmap(screen, srcTrans); screen->transfer_unmap(screen, dstTrans); - screen->tex_transfer_release(screen, &srcTrans); - screen->tex_transfer_release(screen, &dstTrans); + screen->tex_transfer_destroy(srcTrans); + screen->tex_transfer_destroy(dstTrans); } } @@ -1228,8 +1229,8 @@ make_3d_mipmap(struct gen_mipmap_state *ctx, screen->transfer_unmap(screen, srcTrans); screen->transfer_unmap(screen, dstTrans); - screen->tex_transfer_release(screen, &srcTrans); - screen->tex_transfer_release(screen, &dstTrans); + screen->tex_transfer_destroy(srcTrans); + screen->tex_transfer_destroy(dstTrans); } #else (void) reduce_3d; @@ -1414,7 +1415,7 @@ util_destroy_gen_mipmap(struct gen_mipmap_state *ctx) FREE((void*) ctx->vert_shader.tokens); FREE((void*) ctx->frag_shader.tokens); - pipe_buffer_reference(pipe->screen, &ctx->vbuf, NULL); + pipe_buffer_reference(&ctx->vbuf, NULL); FREE(ctx); } @@ -1426,7 +1427,7 @@ util_destroy_gen_mipmap(struct gen_mipmap_state *ctx) */ void util_gen_mipmap_flush( struct gen_mipmap_state *ctx ) { - pipe_buffer_reference(ctx->pipe->screen, &ctx->vbuf, NULL); + pipe_buffer_reference(&ctx->vbuf, NULL); ctx->vbuf_slot = 0; } diff --git a/src/gallium/auxiliary/util/u_rect.c b/src/gallium/auxiliary/util/u_rect.c index 6e24e594e4..74259d453b 100644 --- a/src/gallium/auxiliary/util/u_rect.c +++ b/src/gallium/auxiliary/util/u_rect.c @@ -218,8 +218,8 @@ util_surface_copy(struct pipe_context *pipe, pipe->screen->transfer_unmap(pipe->screen, src_trans); pipe->screen->transfer_unmap(pipe->screen, dst_trans); - screen->tex_transfer_release(screen, &src_trans); - screen->tex_transfer_release(screen, &dst_trans); + screen->tex_transfer_destroy(src_trans); + screen->tex_transfer_destroy(dst_trans); } @@ -297,5 +297,5 @@ util_surface_fill(struct pipe_context *pipe, } pipe->screen->transfer_unmap(pipe->screen, dst_trans); - screen->tex_transfer_release(screen, &dst_trans); + screen->tex_transfer_destroy(dst_trans); } diff --git a/src/gallium/auxiliary/util/u_simple_screen.c b/src/gallium/auxiliary/util/u_simple_screen.c index 089bbbc48a..8114b53cd0 100644 --- a/src/gallium/auxiliary/util/u_simple_screen.c +++ b/src/gallium/auxiliary/util/u_simple_screen.c @@ -28,6 +28,7 @@ #include "u_simple_screen.h" #include "pipe/p_screen.h" +#include "pipe/p_state.h" #include "pipe/internal/p_winsys_screen.h" @@ -37,8 +38,12 @@ pass_buffer_create(struct pipe_screen *screen, unsigned usage, unsigned size) { - return screen->winsys->buffer_create(screen->winsys, - alignment, usage, size); + struct pipe_buffer *buffer = + screen->winsys->buffer_create(screen->winsys, alignment, usage, size); + + buffer->screen = screen; + + return buffer; } static struct pipe_buffer * @@ -46,8 +51,13 @@ pass_user_buffer_create(struct pipe_screen *screen, void *ptr, unsigned bytes) { - return screen->winsys->user_buffer_create(screen->winsys, + struct pipe_buffer *buffer = + screen->winsys->user_buffer_create(screen->winsys, ptr, bytes); + + buffer->screen = screen; + + return buffer; } static struct pipe_buffer * @@ -57,9 +67,14 @@ pass_surface_buffer_create(struct pipe_screen *screen, unsigned usage, unsigned *stride) { - return screen->winsys->surface_buffer_create(screen->winsys, + struct pipe_buffer *buffer = + screen->winsys->surface_buffer_create(screen->winsys, width, height, format, usage, stride); + + buffer->screen = screen; + + return buffer; } static void * @@ -79,10 +94,9 @@ pass_buffer_unmap(struct pipe_screen *screen, } static void -pass_buffer_destroy(struct pipe_screen *screen, - struct pipe_buffer *buf) +pass_buffer_destroy(struct pipe_buffer *buf) { - screen->winsys->buffer_destroy(screen->winsys, buf); + buf->screen->winsys->buffer_destroy(buf); } diff --git a/src/gallium/auxiliary/util/u_timed_winsys.c b/src/gallium/auxiliary/util/u_timed_winsys.c index f237e12d73..77b2a3a1c8 100644 --- a/src/gallium/auxiliary/util/u_timed_winsys.c +++ b/src/gallium/auxiliary/util/u_timed_winsys.c @@ -29,6 +29,7 @@ * Authors: Keith Whitwell */ +#include "pipe/p_state.h" #include "pipe/internal/p_winsys_screen.h" #include "u_timed_winsys.h" #include "util/u_memory.h" @@ -178,13 +179,13 @@ timed_buffer_unmap(struct pipe_winsys *winsys, static void -timed_buffer_destroy(struct pipe_winsys *winsys, - struct pipe_buffer *buf) +timed_buffer_destroy(struct pipe_buffer *buf) { + struct pipe_winsys *winsys = buf->screen->winsys; struct pipe_winsys *backend = timed_winsys(winsys)->backend; uint64_t start = time_start(); - backend->buffer_destroy( backend, buf ); + backend->buffer_destroy( buf ); time_finish(winsys, start, 4, __FUNCTION__); } diff --git a/src/gallium/drivers/cell/ppu/cell_fence.c b/src/gallium/drivers/cell/ppu/cell_fence.c index 32dbf5706c..13125a9fa3 100644 --- a/src/gallium/drivers/cell/ppu/cell_fence.c +++ b/src/gallium/drivers/cell/ppu/cell_fence.c @@ -96,7 +96,7 @@ cell_add_buffer_to_list(struct cell_context *cell, struct cell_buffer_node *node = CALLOC_STRUCT(cell_buffer_node); /* create new list node which references the buffer, insert at head */ if (node) { - pipe_buffer_reference(ps, &node->buffer, buffer); + pipe_buffer_reference(&node->buffer, buffer); node->next = list->head; list->head = node; } @@ -127,10 +127,10 @@ cell_free_fenced_buffers(struct cell_context *cell, pipe_buffer_unmap(ps, node->buffer); #if 0 printf("Unref buffer %p\n", node->buffer); - if (node->buffer->refcount == 1) + if (node->buffer->reference.count == 1) printf(" Delete!\n"); #endif - pipe_buffer_reference(ps, &node->buffer, NULL); + pipe_buffer_reference(&node->buffer, NULL); FREE(node); node = next; } diff --git a/src/gallium/drivers/cell/ppu/cell_texture.c b/src/gallium/drivers/cell/ppu/cell_texture.c index 74724393f7..bc6afa94a8 100644 --- a/src/gallium/drivers/cell/ppu/cell_texture.c +++ b/src/gallium/drivers/cell/ppu/cell_texture.c @@ -101,18 +101,17 @@ static struct pipe_texture * cell_texture_create(struct pipe_screen *screen, const struct pipe_texture *templat) { - struct pipe_winsys *ws = screen->winsys; struct cell_texture *ct = CALLOC_STRUCT(cell_texture); if (!ct) return NULL; ct->base = *templat; - ct->base.refcount = 1; + pipe_reference_init(&ct->base.reference, 1); ct->base.screen = screen; cell_texture_layout(ct); - ct->buffer = ws->buffer_create(ws, 32, PIPE_BUFFER_USAGE_PIXEL, + ct->buffer = screen->buffer_create(screen, 32, PIPE_BUFFER_USAGE_PIXEL, ct->buffer_size); if (!ct->buffer) { @@ -125,28 +124,18 @@ cell_texture_create(struct pipe_screen *screen, static void -cell_texture_release(struct pipe_screen *screen, - struct pipe_texture **pt) +cell_texture_destroy(struct pipe_texture *pt) { - if (!*pt) - return; - - if (--(*pt)->refcount <= 0) { - /* Delete this texture now. - * But note that the underlying pipe_buffer may linger... - */ - struct cell_texture *ct = cell_texture(*pt); + struct cell_texture *ct = cell_texture(pt); - if (ct->mapped) { - pipe_buffer_unmap(screen, ct->buffer); - ct->mapped = NULL; - } + if (ct->mapped) { + pipe_buffer_unmap(screen, ct->buffer); + ct->mapped = NULL; + } - pipe_buffer_reference(screen, &ct->buffer, NULL); + pipe_buffer_reference(&ct->buffer, NULL); - FREE(ct); - } - *pt = NULL; + FREE(ct); } @@ -291,7 +280,7 @@ cell_get_tex_surface(struct pipe_screen *screen, ps = CALLOC_STRUCT(pipe_surface); if (ps) { - ps->refcount = 1; + pipe_reference_init(&ps->reference, 1); pipe_texture_reference(&ps->texture, pt); ps->format = pt->format; ps->width = pt->width[level]; @@ -319,16 +308,10 @@ cell_get_tex_surface(struct pipe_screen *screen, static void -cell_tex_surface_release(struct pipe_screen *screen, - struct pipe_surface **s) +cell_tex_surface_destroy(struct pipe_surface *s) { - struct pipe_surface *surf = *s; - - if (--surf->refcount == 0) { - pipe_texture_reference(&surf->texture, NULL); - FREE(surf); - } - *s = NULL; + pipe_texture_reference(&surf->texture, NULL); + FREE(surf); } @@ -353,7 +336,7 @@ cell_get_tex_transfer(struct pipe_screen *screen, ctrans = CALLOC_STRUCT(cell_transfer); if (ctrans) { struct pipe_transfer *pt = &ctrans->base; - pt->refcount = 1; + pipe_reference_init(&pt->reference, 1); pipe_texture_reference(&pt->texture, texture); pt->format = texture->format; pt->block = texture->block; @@ -388,20 +371,16 @@ cell_get_tex_transfer(struct pipe_screen *screen, static void -cell_tex_transfer_release(struct pipe_screen *screen, - struct pipe_transfer **t) +cell_tex_transfer_destroy(struct pipe_transfer *t) { - struct cell_transfer *transfer = cell_transfer(*t); + struct cell_transfer *transfer = cell_transfer(t); /* Effectively do the texture_update work here - if texture images * needed post-processing to put them into hardware layout, this is * where it would happen. For cell, nothing to do. */ assert (transfer->base.texture); - if (--transfer->base.refcount == 0) { - pipe_texture_reference(&transfer->base.texture, NULL); - FREE(transfer); - } - *t = NULL; + pipe_texture_reference(&transfer->base.texture, NULL); + FREE(transfer); } @@ -511,13 +490,13 @@ void cell_init_screen_texture_funcs(struct pipe_screen *screen) { screen->texture_create = cell_texture_create; - screen->texture_release = cell_texture_release; + screen->texture_destroy = cell_texture_destroy; screen->get_tex_surface = cell_get_tex_surface; - screen->tex_surface_release = cell_tex_surface_release; + screen->tex_surface_destroy = cell_tex_surface_destroy; screen->get_tex_transfer = cell_get_tex_transfer; - screen->tex_transfer_release = cell_tex_transfer_release; + screen->tex_transfer_destroy = cell_tex_transfer_destroy; screen->transfer_map = cell_transfer_map; screen->transfer_unmap = cell_transfer_unmap; diff --git a/src/gallium/drivers/failover/fo_context.c b/src/gallium/drivers/failover/fo_context.c index 0742b27b8f..fcad717cf8 100644 --- a/src/gallium/drivers/failover/fo_context.c +++ b/src/gallium/drivers/failover/fo_context.c @@ -145,7 +145,7 @@ struct pipe_context *failover_create( struct pipe_context *hw, #if 0 failover->pipe.texture_create = hw->texture_create; - failover->pipe.texture_release = hw->texture_release; + failover->pipe.texture_destroy = hw->texture_destroy; failover->pipe.get_tex_surface = hw->get_tex_surface; failover->pipe.texture_update = hw->texture_update; #endif diff --git a/src/gallium/drivers/i915simple/i915_prim_vbuf.c b/src/gallium/drivers/i915simple/i915_prim_vbuf.c index 58c41840e1..9bdd91f288 100644 --- a/src/gallium/drivers/i915simple/i915_prim_vbuf.c +++ b/src/gallium/drivers/i915simple/i915_prim_vbuf.c @@ -126,7 +126,7 @@ i915_vbuf_render_allocate_vertices( struct vbuf_render *render, } else { i915->vbo_flushed = 0; if (i915_render->vbo) - pipe_buffer_reference(screen, &i915_render->vbo, NULL); + pipe_buffer_reference(&i915_render->vbo, NULL); } if (!i915_render->vbo) { diff --git a/src/gallium/drivers/i915simple/i915_screen.c b/src/gallium/drivers/i915simple/i915_screen.c index 49471287a2..f4aa8e60d8 100644 --- a/src/gallium/drivers/i915simple/i915_screen.c +++ b/src/gallium/drivers/i915simple/i915_screen.c @@ -230,7 +230,6 @@ i915_get_tex_transfer(struct pipe_screen *screen, trans = CALLOC_STRUCT(i915_transfer); if (trans) { - trans->base.refcount = 1; pipe_texture_reference(&trans->base.texture, texture); trans->base.format = trans->base.format; trans->base.width = w; @@ -246,17 +245,10 @@ i915_get_tex_transfer(struct pipe_screen *screen, } static void -i915_tex_transfer_release(struct pipe_screen *screen, - struct pipe_transfer **transfer) +i915_tex_transfer_destroy(struct pipe_transfer *trans) { - struct pipe_transfer *trans = *transfer; - - if (--trans->refcount == 0) { - pipe_texture_reference(&trans->texture, NULL); - FREE(trans); - } - - *transfer = NULL; + pipe_texture_reference(&trans->texture, NULL); + FREE(trans); } static void * @@ -344,7 +336,7 @@ i915_create_screen(struct pipe_winsys *winsys, uint pci_id) i915screen->screen.get_paramf = i915_get_paramf; i915screen->screen.is_format_supported = i915_is_format_supported; i915screen->screen.get_tex_transfer = i915_get_tex_transfer; - i915screen->screen.tex_transfer_release = i915_tex_transfer_release; + i915screen->screen.tex_transfer_destroy = i915_tex_transfer_destroy; i915screen->screen.transfer_map = i915_transfer_map; i915screen->screen.transfer_unmap = i915_transfer_unmap; diff --git a/src/gallium/drivers/i915simple/i915_texture.c b/src/gallium/drivers/i915simple/i915_texture.c index 6aead3e75e..39aca9f817 100644 --- a/src/gallium/drivers/i915simple/i915_texture.c +++ b/src/gallium/drivers/i915simple/i915_texture.c @@ -582,7 +582,6 @@ i915_texture_create(struct pipe_screen *screen, const struct pipe_texture *templat) { struct i915_screen *i915screen = i915_screen(screen); - struct pipe_winsys *ws = screen->winsys; struct i915_texture *tex = CALLOC_STRUCT(i915_texture); size_t tex_size; @@ -590,7 +589,7 @@ i915_texture_create(struct pipe_screen *screen, return NULL; tex->base = *templat; - tex->base.refcount = 1; + pipe_reference_init(&tex->base.reference, 1); tex->base.screen = screen; tex->base.nblocksx[0] = pf_get_nblocksx(&tex->base.block, tex->base.width[0]); @@ -606,7 +605,7 @@ i915_texture_create(struct pipe_screen *screen, tex_size = tex->stride * tex->total_nblocksy; - tex->buffer = ws->buffer_create(ws, 64, + tex->buffer = screen->buffer_create(screen, 64, PIPE_BUFFER_USAGE_PIXEL, tex_size); @@ -629,33 +628,22 @@ fail: static void -i915_texture_release(struct pipe_screen *screen, - struct pipe_texture **pt) +i915_texture_destroy(struct pipe_texture *pt) { - if (!*pt) - return; + struct i915_texture *tex = (struct i915_texture *)pt; + uint i; /* - DBG("%s %p refcount will be %d\n", - __FUNCTION__, (void *) *pt, (*pt)->refcount - 1); + DBG("%s deleting %p\n", __FUNCTION__, (void *) tex); */ - if (--(*pt)->refcount <= 0) { - struct i915_texture *tex = (struct i915_texture *)*pt; - uint i; - - /* - DBG("%s deleting %p\n", __FUNCTION__, (void *) tex); - */ - pipe_buffer_reference(screen, &tex->buffer, NULL); + pipe_buffer_reference(&tex->buffer, NULL); - for (i = 0; i < PIPE_MAX_TEXTURE_LEVELS; i++) - if (tex->image_offset[i]) - FREE(tex->image_offset[i]); + for (i = 0; i < PIPE_MAX_TEXTURE_LEVELS; i++) + if (tex->image_offset[i]) + FREE(tex->image_offset[i]); - FREE(tex); - } - *pt = NULL; + FREE(tex); } static struct pipe_surface * @@ -682,7 +670,7 @@ i915_get_tex_surface(struct pipe_screen *screen, ps = CALLOC_STRUCT(pipe_surface); if (ps) { - ps->refcount = 1; + pipe_reference_init(&ps->reference, 1); pipe_texture_reference(&ps->texture, pt); ps->format = pt->format; ps->width = pt->width[level]; @@ -715,7 +703,7 @@ i915_texture_blanket(struct pipe_screen * screen, return NULL; tex->base = *base; - tex->base.refcount = 1; + pipe_reference_init(&tex->base.reference, 1); tex->base.screen = screen; tex->stride = stride[0]; @@ -723,7 +711,7 @@ i915_texture_blanket(struct pipe_screen * screen, i915_miptree_set_level_info(tex, 0, 1, base->width[0], base->height[0], 1); i915_miptree_set_image_offset(tex, 0, 0, 0, 0); - pipe_buffer_reference(screen, &tex->buffer, buffer); + pipe_buffer_reference(&tex->buffer, buffer); return &tex->base; } @@ -735,36 +723,28 @@ i915_init_texture_functions(struct i915_context *i915) } static void -i915_tex_surface_release(struct pipe_screen *screen, - struct pipe_surface **surface) +i915_tex_surface_destroy(struct pipe_surface *surf) { - struct pipe_surface *surf = *surface; - - if (--surf->refcount == 0) { - - /* This really should not be possible, but it's actually - * happening quite a bit... Will fix. - */ - if (surf->status == PIPE_SURFACE_STATUS_CLEAR) { - debug_printf("XXX destroying a surface with pending clears...\n"); - assert(0); - } - - pipe_texture_reference(&surf->texture, NULL); - FREE(surf); + /* This really should not be possible, but it's actually + * happening quite a bit... Will fix. + */ + if (surf->status == PIPE_SURFACE_STATUS_CLEAR) { + debug_printf("XXX destroying a surface with pending clears...\n"); + assert(0); } - *surface = NULL; + pipe_texture_reference(&surf->texture, NULL); + FREE(surf); } void i915_init_screen_texture_functions(struct pipe_screen *screen) { screen->texture_create = i915_texture_create; - screen->texture_release = i915_texture_release; + screen->texture_destroy = i915_texture_destroy; screen->get_tex_surface = i915_get_tex_surface; screen->texture_blanket = i915_texture_blanket; - screen->tex_surface_release = i915_tex_surface_release; + screen->tex_surface_destroy = i915_tex_surface_destroy; } boolean i915_get_texture_buffer( struct pipe_texture *texture, @@ -776,7 +756,7 @@ boolean i915_get_texture_buffer( struct pipe_texture *texture, if (!tex) return FALSE; - pipe_buffer_reference(texture->screen, buf, tex->buffer); + pipe_buffer_reference(buf, tex->buffer); if (stride) *stride = tex->stride; diff --git a/src/gallium/drivers/i965simple/brw_tex_layout.c b/src/gallium/drivers/i965simple/brw_tex_layout.c index 448229ed4e..c921c0d38b 100644 --- a/src/gallium/drivers/i965simple/brw_tex_layout.c +++ b/src/gallium/drivers/i965simple/brw_tex_layout.c @@ -284,18 +284,17 @@ static struct pipe_texture * brw_texture_create_screen(struct pipe_screen *screen, const struct pipe_texture *templat) { - struct pipe_winsys *ws = screen->winsys; struct brw_texture *tex = CALLOC_STRUCT(brw_texture); if (tex) { tex->base = *templat; - tex->base.refcount = 1; + pipe_reference_init(&tex->base.reference, 1); tex->base.nblocksx[0] = pf_get_nblocksx(&tex->base.block, tex->base.width[0]); tex->base.nblocksy[0] = pf_get_nblocksy(&tex->base.block, tex->base.height[0]); if (brw_miptree_layout(tex)) - tex->buffer = ws->buffer_create(ws, 64, + tex->buffer = screen->buffer_create(screen, 64, PIPE_BUFFER_USAGE_PIXEL, tex->stride * tex->total_nblocksy); @@ -311,33 +310,22 @@ brw_texture_create_screen(struct pipe_screen *screen, static void -brw_texture_release_screen(struct pipe_screen *screen, - struct pipe_texture **pt) +brw_texture_destroy_screen(struct pipe_texture *pt) { - if (!*pt) - return; + struct brw_texture *tex = (struct brw_texture *)pt; + uint i; /* - DBG("%s %p refcount will be %d\n", - __FUNCTION__, (void *) *pt, (*pt)->refcount - 1); + DBG("%s deleting %p\n", __FUNCTION__, (void *) tex); */ - if (--(*pt)->refcount <= 0) { - struct brw_texture *tex = (struct brw_texture *)*pt; - uint i; - - /* - DBG("%s deleting %p\n", __FUNCTION__, (void *) tex); - */ - pipe_buffer_reference(screen, &tex->buffer, NULL); + pipe_buffer_reference(&tex->buffer, NULL); - for (i = 0; i < PIPE_MAX_TEXTURE_LEVELS; i++) - if (tex->image_offset[i]) - free(tex->image_offset[i]); + for (i = 0; i < PIPE_MAX_TEXTURE_LEVELS; i++) + if (tex->image_offset[i]) + free(tex->image_offset[i]); - free(tex); - } - *pt = NULL; + free(tex); } @@ -365,7 +353,7 @@ brw_get_tex_surface_screen(struct pipe_screen *screen, ps = CALLOC_STRUCT(pipe_surface); if (ps) { - ps->refcount = 1; + pipe_reference_init(&ps->reference, 1); pipe_texture_reference(&ps->texture, pt); ps->format = pt->format; ps->width = pt->width[level]; @@ -392,7 +380,7 @@ void brw_init_screen_texture_funcs(struct pipe_screen *screen) { screen->texture_create = brw_texture_create_screen; - screen->texture_release = brw_texture_release_screen; + screen->texture_destroy = brw_texture_destroy_screen; screen->get_tex_surface = brw_get_tex_surface_screen; } diff --git a/src/gallium/drivers/i965simple/brw_wm_surface_state.c b/src/gallium/drivers/i965simple/brw_wm_surface_state.c index 1bab5bfdb3..b5b9e0e702 100644 --- a/src/gallium/drivers/i965simple/brw_wm_surface_state.c +++ b/src/gallium/drivers/i965simple/brw_wm_surface_state.c @@ -242,7 +242,7 @@ static void upload_wm_surfaces(struct brw_context *brw ) const struct brw_texture *texUnit = brw->attribs.Texture[i]; if (texUnit && - texUnit->base.refcount/*(texUnit->refcount > 0) == really used */) { + texUnit->base.reference.count/*(texUnit->reference.count > 0) == really used */) { brw_update_texture_surface(brw, i); diff --git a/src/gallium/drivers/nouveau/nouveau_stateobj.h b/src/gallium/drivers/nouveau/nouveau_stateobj.h index 029b01e17d..666e061ac3 100644 --- a/src/gallium/drivers/nouveau/nouveau_stateobj.h +++ b/src/gallium/drivers/nouveau/nouveau_stateobj.h @@ -16,7 +16,7 @@ struct nouveau_stateobj_reloc { }; struct nouveau_stateobj { - int refcount; + struct pipe_reference reference; unsigned *push; struct nouveau_stateobj_reloc *reloc; @@ -32,7 +32,7 @@ so_new(unsigned push, unsigned reloc) struct nouveau_stateobj *so; so = MALLOC(sizeof(struct nouveau_stateobj)); - so->refcount = 0; + pipe_reference_init(&so->reference, 0); so->push = MALLOC(sizeof(unsigned) * push); so->reloc = MALLOC(sizeof(struct nouveau_stateobj_reloc) * reloc); @@ -47,17 +47,11 @@ so_ref(struct nouveau_stateobj *ref, struct nouveau_stateobj **pso) { struct nouveau_stateobj *so = *pso; - if (ref) { - ref->refcount++; - } - - if (so && --so->refcount <= 0) { + if (pipe_reference((struct pipe_reference**)pso, &ref->reference)) { free(so->push); free(so->reloc); free(so); } - - *pso = ref; } static INLINE void diff --git a/src/gallium/drivers/nv04/nv04_miptree.c b/src/gallium/drivers/nv04/nv04_miptree.c index 9acd613e2e..85dc017fbc 100644 --- a/src/gallium/drivers/nv04/nv04_miptree.c +++ b/src/gallium/drivers/nv04/nv04_miptree.c @@ -41,21 +41,20 @@ nv04_miptree_layout(struct nv04_miptree *nv04mt) static struct pipe_texture * nv04_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *pt) { - struct pipe_winsys *ws = pscreen->winsys; struct nv04_miptree *mt; mt = MALLOC(sizeof(struct nv04_miptree)); if (!mt) return NULL; mt->base = *pt; - mt->base.refcount = 1; + pipe_reference_init(&mt->base.reference, 1); mt->base.screen = pscreen; //mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR; nv04_miptree_layout(mt); - mt->buffer = ws->buffer_create(ws, 256, PIPE_BUFFER_USAGE_PIXEL | + mt->buffer = pscreen->buffer_create(pscreen, 256, PIPE_BUFFER_USAGE_PIXEL | NOUVEAU_BUFFER_USAGE_TEXTURE, mt->total_size); if (!mt->buffer) { @@ -83,27 +82,22 @@ nv04_miptree_blanket(struct pipe_screen *pscreen, const struct pipe_texture *pt, return NULL; mt->base = *pt; - mt->base.refcount = 1; + pipe_reference_init(&mt->base.reference, 1); mt->base.screen = pscreen; mt->level[0].pitch = stride[0]; mt->level[0].image_offset = CALLOC(1, sizeof(unsigned)); - pipe_buffer_reference(pscreen, &mt->buffer, pb); + pipe_buffer_reference(&mt->buffer, pb); return &mt->base; } static void -nv04_miptree_release(struct pipe_screen *pscreen, struct pipe_texture **ppt) +nv04_miptree_destroy(struct pipe_texture *pt) { - struct pipe_texture *pt = *ppt; struct nv04_miptree *mt = (struct nv04_miptree *)pt; int l; - *ppt = NULL; - if (--pt->refcount) - return; - - pipe_buffer_reference(pscreen, &mt->buffer, NULL); + pipe_buffer_reference(&mt->buffer, NULL); for (l = 0; l <= pt->last_level; l++) { if (mt->level[l].image_offset) FREE(mt->level[l].image_offset); @@ -129,7 +123,7 @@ nv04_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt, ns->base.height = pt->height[level]; ns->base.usage = flags; ns->base.status = PIPE_SURFACE_STATUS_DEFINED; - ns->base.refcount = 1; + pipe_reference_init(&ns->base.reference, 1); ns->base.face = face; ns->base.level = level; ns->base.zslice = zslice; @@ -141,15 +135,8 @@ nv04_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt, } static void -nv04_miptree_surface_del(struct pipe_screen *pscreen, - struct pipe_surface **psurface) +nv04_miptree_surface_del(struct pipe_surface *ps) { - struct pipe_surface *ps = *psurface; - - *psurface = NULL; - if (--ps->refcount > 0) - return; - pipe_texture_reference(&ps->texture, NULL); FREE(ps); } @@ -159,8 +146,8 @@ nv04_screen_init_miptree_functions(struct pipe_screen *pscreen) { pscreen->texture_create = nv04_miptree_create; pscreen->texture_blanket = nv04_miptree_blanket; - pscreen->texture_release = nv04_miptree_release; + pscreen->texture_destroy = nv04_miptree_destroy; pscreen->get_tex_surface = nv04_miptree_surface_new; - pscreen->tex_surface_release = nv04_miptree_surface_del; + pscreen->tex_surface_destroy = nv04_miptree_surface_del; } diff --git a/src/gallium/drivers/nv04/nv04_transfer.c b/src/gallium/drivers/nv04/nv04_transfer.c index 573b043f5b..e925a44e29 100644 --- a/src/gallium/drivers/nv04/nv04_transfer.c +++ b/src/gallium/drivers/nv04/nv04_transfer.c @@ -64,7 +64,6 @@ nv04_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt, if (!tx) return NULL; - tx->base.refcount = 1; pipe_texture_reference(&tx->base.texture, pt); tx->base.format = pt->format; tx->base.x = x; @@ -138,12 +137,12 @@ nv04_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt, } static void -nv04_transfer_del(struct pipe_screen *pscreen, struct pipe_transfer **pptx) +nv04_transfer_del(struct pipe_transfer *ptx) { - struct pipe_transfer *ptx = *pptx; struct nv04_transfer *tx = (struct nv04_transfer *)ptx; if (!tx->direct && ptx->usage != PIPE_TRANSFER_READ) { + struct pipe_screen *pscreen = ptx->texture->screen; struct nv04_screen *nvscreen = nv04_screen(pscreen); struct pipe_surface *dst; @@ -160,10 +159,6 @@ nv04_transfer_del(struct pipe_screen *pscreen, struct pipe_transfer **pptx) pipe_surface_reference(&dst, NULL); } - *pptx = NULL; - if (--ptx->refcount) - return; - pipe_surface_reference(&tx->surface, NULL); pipe_texture_reference(&ptx->texture, NULL); FREE(ptx); @@ -195,7 +190,7 @@ void nv04_screen_init_transfer_functions(struct pipe_screen *pscreen) { pscreen->get_tex_transfer = nv04_transfer_new; - pscreen->tex_transfer_release = nv04_transfer_del; + pscreen->tex_transfer_destroy = nv04_transfer_del; pscreen->transfer_map = nv04_transfer_map; pscreen->transfer_unmap = nv04_transfer_unmap; } diff --git a/src/gallium/drivers/nv10/nv10_miptree.c b/src/gallium/drivers/nv10/nv10_miptree.c index 4747868a50..bb3a1c0f19 100644 --- a/src/gallium/drivers/nv10/nv10_miptree.c +++ b/src/gallium/drivers/nv10/nv10_miptree.c @@ -66,31 +66,30 @@ nv10_miptree_blanket(struct pipe_screen *pscreen, const struct pipe_texture *pt, return NULL; mt->base = *pt; - mt->base.refcount = 1; + pipe_reference_init(&mt->base.reference, 1); mt->base.screen = pscreen; mt->level[0].pitch = stride[0]; mt->level[0].image_offset = CALLOC(1, sizeof(unsigned)); - pipe_buffer_reference(pscreen, &mt->buffer, pb); + pipe_buffer_reference(&mt->buffer, pb); return &mt->base; } static struct pipe_texture * nv10_miptree_create(struct pipe_screen *screen, const struct pipe_texture *pt) { - struct pipe_winsys *ws = screen->winsys; struct nv10_miptree *mt; mt = MALLOC(sizeof(struct nv10_miptree)); if (!mt) return NULL; mt->base = *pt; - mt->base.refcount = 1; + pipe_reference_init(&mt->base.reference, 1); mt->base.screen = screen; nv10_miptree_layout(mt); - mt->buffer = ws->buffer_create(ws, 256, PIPE_BUFFER_USAGE_PIXEL, + mt->buffer = screen->buffer_create(screen, 256, PIPE_BUFFER_USAGE_PIXEL, mt->total_size); if (!mt->buffer) { FREE(mt); @@ -101,22 +100,17 @@ nv10_miptree_create(struct pipe_screen *screen, const struct pipe_texture *pt) } static void -nv10_miptree_release(struct pipe_screen *screen, struct pipe_texture **pt) +nv10_miptree_destroy(struct pipe_texture *pt) { - struct pipe_texture *mt = *pt; - - *pt = NULL; - if (--mt->refcount <= 0) { - struct nv10_miptree *nv10mt = (struct nv10_miptree *)mt; - int l; - - pipe_buffer_reference(screen, &nv10mt->buffer, NULL); - for (l = 0; l <= mt->last_level; l++) { - if (nv10mt->level[l].image_offset) - FREE(nv10mt->level[l].image_offset); - } - FREE(nv10mt); - } + struct nv10_miptree *nv10mt = (struct nv10_miptree *)pt; + int l; + + pipe_buffer_reference(&nv10mt->buffer, NULL); + for (l = 0; l <= pt->last_level; l++) { + if (nv10mt->level[l].image_offset) + FREE(nv10mt->level[l].image_offset); + } + FREE(nv10mt); } static void @@ -143,7 +137,7 @@ nv10_miptree_surface_get(struct pipe_screen *screen, struct pipe_texture *pt, ns->base.height = pt->height[level]; ns->base.usage = flags; ns->base.status = PIPE_SURFACE_STATUS_DEFINED; - ns->base.refcount = 1; + pipe_reference_init(&ns->base.reference, 1); ns->base.face = face; ns->base.level = level; ns->base.zslice = zslice; @@ -159,8 +153,7 @@ nv10_miptree_surface_get(struct pipe_screen *screen, struct pipe_texture *pt, } static void -nv10_miptree_surface_release(struct pipe_screen *screen, - struct pipe_surface **surface) +nv10_miptree_surface_destroy(struct pipe_surface *surface) { } @@ -168,8 +161,8 @@ void nv10_screen_init_miptree_functions(struct pipe_screen *pscreen) { pscreen->texture_create = nv10_miptree_create; pscreen->texture_blanket = nv10_miptree_blanket; - pscreen->texture_release = nv10_miptree_release; + pscreen->texture_destroy = nv10_miptree_destroy; pscreen->get_tex_surface = nv10_miptree_surface_get; - pscreen->tex_surface_release = nv10_miptree_surface_release; + pscreen->tex_surface_destroy = nv10_miptree_surface_destroy; } diff --git a/src/gallium/drivers/nv10/nv10_prim_vbuf.c b/src/gallium/drivers/nv10/nv10_prim_vbuf.c index 491a881806..089c236302 100644 --- a/src/gallium/drivers/nv10/nv10_prim_vbuf.c +++ b/src/gallium/drivers/nv10/nv10_prim_vbuf.c @@ -106,11 +106,11 @@ nv10_vbuf_render_allocate_vertices( struct vbuf_render *render, { struct nv10_vbuf_render *nv10_render = nv10_vbuf_render(render); struct nv10_context *nv10 = nv10_render->nv10; - struct pipe_winsys *winsys = nv10->pipe.winsys; + struct pipe_screen *screen = nv10->pipe.screen; size_t size = (size_t)vertex_size * (size_t)nr_vertices; assert(!nv10_render->buffer); - nv10_render->buffer = winsys->buffer_create(winsys, 64, PIPE_BUFFER_USAGE_VERTEX, size); + nv10_render->buffer = screen->buffer_create(screen, 64, PIPE_BUFFER_USAGE_VERTEX, size); nv10->dirty |= NV10_NEW_VTXARRAYS; @@ -206,7 +206,7 @@ nv10_vbuf_render_release_vertices( struct vbuf_render *render ) struct pipe_screen *pscreen = &nv10->screen->pipe; assert(nv10_render->buffer); - pipe_buffer_reference(pscreen, &nv10_render->buffer, NULL); + pipe_buffer_reference(&nv10_render->buffer, NULL); } diff --git a/src/gallium/drivers/nv10/nv10_transfer.c b/src/gallium/drivers/nv10/nv10_transfer.c index daec37ab28..5a99225409 100644 --- a/src/gallium/drivers/nv10/nv10_transfer.c +++ b/src/gallium/drivers/nv10/nv10_transfer.c @@ -64,7 +64,6 @@ nv10_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt, if (!tx) return NULL; - tx->base.refcount = 1; pipe_texture_reference(&tx->base.texture, pt); tx->base.format = pt->format; tx->base.x = x; @@ -138,12 +137,12 @@ nv10_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt, } static void -nv10_transfer_del(struct pipe_screen *pscreen, struct pipe_transfer **pptx) +nv10_transfer_del(struct pipe_transfer *ptx) { - struct pipe_transfer *ptx = *pptx; struct nv10_transfer *tx = (struct nv10_transfer *)ptx; if (!tx->direct && ptx->usage != PIPE_TRANSFER_READ) { + struct pipe_screen *pscreen = ptx->texture->screen; struct nv10_screen *nvscreen = nv10_screen(pscreen); struct pipe_surface *dst; @@ -160,10 +159,6 @@ nv10_transfer_del(struct pipe_screen *pscreen, struct pipe_transfer **pptx) pipe_surface_reference(&dst, NULL); } - *pptx = NULL; - if (--ptx->refcount) - return; - pipe_surface_reference(&tx->surface, NULL); pipe_texture_reference(&ptx->texture, NULL); FREE(ptx); @@ -195,7 +190,7 @@ void nv10_screen_init_transfer_functions(struct pipe_screen *pscreen) { pscreen->get_tex_transfer = nv10_transfer_new; - pscreen->tex_transfer_release = nv10_transfer_del; + pscreen->tex_transfer_destroy = nv10_transfer_del; pscreen->transfer_map = nv10_transfer_map; pscreen->transfer_unmap = nv10_transfer_unmap; } diff --git a/src/gallium/drivers/nv20/nv20_miptree.c b/src/gallium/drivers/nv20/nv20_miptree.c index 2946240897..b2f29aff8d 100644 --- a/src/gallium/drivers/nv20/nv20_miptree.c +++ b/src/gallium/drivers/nv20/nv20_miptree.c @@ -76,19 +76,18 @@ nv20_miptree_blanket(struct pipe_screen *pscreen, const struct pipe_texture *pt, return NULL; mt->base = *pt; - mt->base.refcount = 1; + pipe_reference_init(&mt->base.reference, 1); mt->base.screen = pscreen; mt->level[0].pitch = stride[0]; mt->level[0].image_offset = CALLOC(1, sizeof(unsigned)); - pipe_buffer_reference(pscreen, &mt->buffer, pb); + pipe_buffer_reference(&mt->buffer, pb); return &mt->base; } static struct pipe_texture * nv20_miptree_create(struct pipe_screen *screen, const struct pipe_texture *pt) { - struct pipe_winsys *ws = screen->winsys; struct nv20_miptree *mt; unsigned buf_usage = PIPE_BUFFER_USAGE_PIXEL | NOUVEAU_BUFFER_USAGE_TEXTURE; @@ -97,7 +96,7 @@ nv20_miptree_create(struct pipe_screen *screen, const struct pipe_texture *pt) if (!mt) return NULL; mt->base = *pt; - mt->base.refcount = 1; + pipe_reference_init(&mt->base.reference, 1); mt->base.screen = screen; /* Swizzled textures must be POT */ @@ -133,7 +132,7 @@ nv20_miptree_create(struct pipe_screen *screen, const struct pipe_texture *pt) nv20_miptree_layout(mt); - mt->buffer = ws->buffer_create(ws, 256, buf_usage, mt->total_size); + mt->buffer = screen->buffer_create(screen, 256, buf_usage, mt->total_size); if (!mt->buffer) { FREE(mt); return NULL; @@ -143,22 +142,16 @@ nv20_miptree_create(struct pipe_screen *screen, const struct pipe_texture *pt) } static void -nv20_miptree_release(struct pipe_screen *screen, struct pipe_texture **pt) +nv20_miptree_destroy(struct pipe_texture *pt) { - struct pipe_texture *mt = *pt; - - *pt = NULL; - if (--mt->refcount <= 0) { - struct nv20_miptree *nv20mt = (struct nv20_miptree *)mt; - int l; + struct nv20_miptree *nv20mt = (struct nv20_miptree *)pt; + int l; - pipe_buffer_reference(screen, &nv20mt->buffer, NULL); - for (l = 0; l <= mt->last_level; l++) { - if (nv20mt->level[l].image_offset) - FREE(nv20mt->level[l].image_offset); - } - FREE(nv20mt); - } + pipe_buffer_reference(&nv20mt->buffer, NULL); + for (l = 0; l <= pt->last_level; l++) { + if (nv20mt->level[l].image_offset) + FREE(nv20mt->level[l].image_offset); + } } static struct pipe_surface * @@ -178,7 +171,7 @@ nv20_miptree_surface_get(struct pipe_screen *screen, struct pipe_texture *pt, ns->base.height = pt->height[level]; ns->base.usage = flags; ns->base.status = PIPE_SURFACE_STATUS_DEFINED; - ns->base.refcount = 1; + pipe_reference_init(&ns->base.reference, 1); ns->base.face = face; ns->base.level = level; ns->base.zslice = zslice; @@ -197,15 +190,8 @@ nv20_miptree_surface_get(struct pipe_screen *screen, struct pipe_texture *pt, } static void -nv20_miptree_surface_release(struct pipe_screen *pscreen, - struct pipe_surface **psurface) +nv20_miptree_surface_destroy(struct pipe_surface *ps) { - struct pipe_surface *ps = *psurface; - - *psurface = NULL; - if (--ps->refcount > 0) - return; - pipe_texture_reference(&ps->texture, NULL); FREE(ps); } @@ -214,8 +200,8 @@ void nv20_screen_init_miptree_functions(struct pipe_screen *pscreen) { pscreen->texture_create = nv20_miptree_create; pscreen->texture_blanket = nv20_miptree_blanket; - pscreen->texture_release = nv20_miptree_release; + pscreen->texture_destroy = nv20_miptree_destroy; pscreen->get_tex_surface = nv20_miptree_surface_get; - pscreen->tex_surface_release = nv20_miptree_surface_release; + pscreen->tex_surface_destroy = nv20_miptree_surface_destroy; } diff --git a/src/gallium/drivers/nv20/nv20_prim_vbuf.c b/src/gallium/drivers/nv20/nv20_prim_vbuf.c index 319e1f6557..8aa342cd2d 100644 --- a/src/gallium/drivers/nv20/nv20_prim_vbuf.c +++ b/src/gallium/drivers/nv20/nv20_prim_vbuf.c @@ -112,8 +112,8 @@ nv20__allocate_mbuffer(struct nv20_vbuf_render *nv20_render, size_t size) static void nv20__allocate_pbuffer(struct nv20_vbuf_render *nv20_render, size_t size) { - struct pipe_winsys *winsys = nv20_render->nv20->pipe.winsys; - nv20_render->pbuffer = winsys->buffer_create(winsys, 64, + struct pipe_screen *screen = nv20_render->nv20->pipe.screen; + nv20_render->pbuffer = screen->buffer_create(screen, 64, PIPE_BUFFER_USAGE_VERTEX, size); } @@ -361,7 +361,7 @@ nv20_vbuf_render_release_vertices( struct vbuf_render *render ) struct pipe_screen *pscreen = &nv20->screen->pipe; if (nv20_render->pbuffer) { - pipe_buffer_reference(pscreen, &nv20_render->pbuffer, NULL); + pipe_buffer_reference(&nv20_render->pbuffer, NULL); } else if (nv20_render->mbuffer) { FREE(nv20_render->mbuffer); nv20_render->mbuffer = NULL; diff --git a/src/gallium/drivers/nv20/nv20_transfer.c b/src/gallium/drivers/nv20/nv20_transfer.c index 1631637067..e5255296aa 100644 --- a/src/gallium/drivers/nv20/nv20_transfer.c +++ b/src/gallium/drivers/nv20/nv20_transfer.c @@ -64,7 +64,6 @@ nv20_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt, if (!tx) return NULL; - tx->base.refcount = 1; pipe_texture_reference(&tx->base.texture, pt); tx->base.format = pt->format; tx->base.x = x; @@ -138,12 +137,12 @@ nv20_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt, } static void -nv20_transfer_del(struct pipe_screen *pscreen, struct pipe_transfer **pptx) +nv20_transfer_del(struct pipe_transfer *ptx) { - struct pipe_transfer *ptx = *pptx; struct nv20_transfer *tx = (struct nv20_transfer *)ptx; if (!tx->direct && ptx->usage != PIPE_TRANSFER_READ) { + struct pipe_screen *pscreen = ptx->texture->screen; struct nv20_screen *nvscreen = nv20_screen(pscreen); struct pipe_surface *dst; @@ -160,10 +159,6 @@ nv20_transfer_del(struct pipe_screen *pscreen, struct pipe_transfer **pptx) pipe_surface_reference(&dst, NULL); } - *pptx = NULL; - if (--ptx->refcount) - return; - pipe_surface_reference(&tx->surface, NULL); pipe_texture_reference(&ptx->texture, NULL); FREE(ptx); @@ -195,7 +190,7 @@ void nv20_screen_init_transfer_functions(struct pipe_screen *pscreen) { pscreen->get_tex_transfer = nv20_transfer_new; - pscreen->tex_transfer_release = nv20_transfer_del; + pscreen->tex_transfer_destroy = nv20_transfer_del; pscreen->transfer_map = nv20_transfer_map; pscreen->transfer_unmap = nv20_transfer_unmap; } diff --git a/src/gallium/drivers/nv30/nv30_fragprog.c b/src/gallium/drivers/nv30/nv30_fragprog.c index 320ba3f4bf..0da392fed3 100644 --- a/src/gallium/drivers/nv30/nv30_fragprog.c +++ b/src/gallium/drivers/nv30/nv30_fragprog.c @@ -834,6 +834,7 @@ nv30_fragprog_validate(struct nv30_context *nv30) struct nv30_fragment_program *fp = nv30->fragprog; struct pipe_buffer *constbuf = nv30->constbuf[PIPE_SHADER_FRAGMENT]; + struct pipe_screen *screen = nv30->pipe.screen; struct pipe_winsys *ws = nv30->pipe.winsys; struct nouveau_stateobj *so; boolean new_consts = FALSE; @@ -849,7 +850,7 @@ nv30_fragprog_validate(struct nv30_context *nv30) return FALSE; } - fp->buffer = ws->buffer_create(ws, 0x100, 0, fp->insn_len * 4); + fp->buffer = screen->buffer_create(screen, 0x100, 0, fp->insn_len * 4); nv30_fragprog_upload(nv30, fp); so = so_new(8, 1); diff --git a/src/gallium/drivers/nv30/nv30_miptree.c b/src/gallium/drivers/nv30/nv30_miptree.c index ec0a8b8438..d6dc621c9e 100644 --- a/src/gallium/drivers/nv30/nv30_miptree.c +++ b/src/gallium/drivers/nv30/nv30_miptree.c @@ -67,7 +67,6 @@ nv30_miptree_layout(struct nv30_miptree *nv30mt) static struct pipe_texture * nv30_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *pt) { - struct pipe_winsys *ws = pscreen->winsys; struct nv30_miptree *mt; unsigned buf_usage = PIPE_BUFFER_USAGE_PIXEL | NOUVEAU_BUFFER_USAGE_TEXTURE; @@ -76,7 +75,7 @@ nv30_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *pt) if (!mt) return NULL; mt->base = *pt; - mt->base.refcount = 1; + pipe_reference_init(&mt->base.reference, 1); mt->base.screen = pscreen; /* Swizzled textures must be POT */ @@ -112,7 +111,7 @@ nv30_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *pt) nv30_miptree_layout(mt); - mt->buffer = ws->buffer_create(ws, 256, buf_usage, + mt->buffer = pscreen->buffer_create(pscreen, 256, buf_usage, mt->total_size); if (!mt->buffer) { FREE(mt); @@ -138,27 +137,22 @@ nv30_miptree_blanket(struct pipe_screen *pscreen, const struct pipe_texture *pt, return NULL; mt->base = *pt; - mt->base.refcount = 1; + pipe_reference_init(&mt->base.reference, 1); mt->base.screen = pscreen; mt->level[0].pitch = stride[0]; mt->level[0].image_offset = CALLOC(1, sizeof(unsigned)); - pipe_buffer_reference(pscreen, &mt->buffer, pb); + pipe_buffer_reference(&mt->buffer, pb); return &mt->base; } static void -nv30_miptree_release(struct pipe_screen *pscreen, struct pipe_texture **ppt) +nv30_miptree_destroy(struct pipe_texture *pt) { - struct pipe_texture *pt = *ppt; struct nv30_miptree *mt = (struct nv30_miptree *)pt; int l; - *ppt = NULL; - if (--pt->refcount) - return; - - pipe_buffer_reference(pscreen, &mt->buffer, NULL); + pipe_buffer_reference(&mt->buffer, NULL); for (l = 0; l <= pt->last_level; l++) { if (mt->level[l].image_offset) FREE(mt->level[l].image_offset); @@ -184,7 +178,7 @@ nv30_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt, ns->base.height = pt->height[level]; ns->base.usage = flags; ns->base.status = PIPE_SURFACE_STATUS_DEFINED; - ns->base.refcount = 1; + pipe_reference_init(&ns->base.reference, 1); ns->base.face = face; ns->base.level = level; ns->base.zslice = zslice; @@ -203,15 +197,8 @@ nv30_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt, } static void -nv30_miptree_surface_del(struct pipe_screen *pscreen, - struct pipe_surface **psurface) +nv30_miptree_surface_del(struct pipe_surface *ps) { - struct pipe_surface *ps = *psurface; - - *psurface = NULL; - if (--ps->refcount > 0) - return; - pipe_texture_reference(&ps->texture, NULL); FREE(ps); } @@ -221,7 +208,7 @@ nv30_screen_init_miptree_functions(struct pipe_screen *pscreen) { pscreen->texture_create = nv30_miptree_create; pscreen->texture_blanket = nv30_miptree_blanket; - pscreen->texture_release = nv30_miptree_release; + pscreen->texture_destroy = nv30_miptree_destroy; pscreen->get_tex_surface = nv30_miptree_surface_new; - pscreen->tex_surface_release = nv30_miptree_surface_del; + pscreen->tex_surface_destroy = nv30_miptree_surface_del; } diff --git a/src/gallium/drivers/nv30/nv30_transfer.c b/src/gallium/drivers/nv30/nv30_transfer.c index 6367374a61..8b915b35bd 100644 --- a/src/gallium/drivers/nv30/nv30_transfer.c +++ b/src/gallium/drivers/nv30/nv30_transfer.c @@ -64,7 +64,6 @@ nv30_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt, if (!tx) return NULL; - tx->base.refcount = 1; pipe_texture_reference(&tx->base.texture, pt); tx->base.format = pt->format; tx->base.x = x; @@ -138,12 +137,12 @@ nv30_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt, } static void -nv30_transfer_del(struct pipe_screen *pscreen, struct pipe_transfer **pptx) +nv30_transfer_del(struct pipe_transfer *ptx) { - struct pipe_transfer *ptx = *pptx; struct nv30_transfer *tx = (struct nv30_transfer *)ptx; if (!tx->direct && ptx->usage != PIPE_TRANSFER_READ) { + struct pipe_screen *pscreen = ptx->texture->screen; struct nv30_screen *nvscreen = nv30_screen(pscreen); struct pipe_surface *dst; @@ -160,10 +159,6 @@ nv30_transfer_del(struct pipe_screen *pscreen, struct pipe_transfer **pptx) pipe_surface_reference(&dst, NULL); } - *pptx = NULL; - if (--ptx->refcount) - return; - pipe_surface_reference(&tx->surface, NULL); pipe_texture_reference(&ptx->texture, NULL); FREE(ptx); @@ -195,7 +190,7 @@ void nv30_screen_init_transfer_functions(struct pipe_screen *pscreen) { pscreen->get_tex_transfer = nv30_transfer_new; - pscreen->tex_transfer_release = nv30_transfer_del; + pscreen->tex_transfer_destroy = nv30_transfer_del; pscreen->transfer_map = nv30_transfer_map; pscreen->transfer_unmap = nv30_transfer_unmap; } diff --git a/src/gallium/drivers/nv40/nv40_fragprog.c b/src/gallium/drivers/nv40/nv40_fragprog.c index 91dcbebda0..1031e87e97 100644 --- a/src/gallium/drivers/nv40/nv40_fragprog.c +++ b/src/gallium/drivers/nv40/nv40_fragprog.c @@ -917,6 +917,7 @@ nv40_fragprog_validate(struct nv40_context *nv40) struct nv40_fragment_program *fp = nv40->fragprog; struct pipe_buffer *constbuf = nv40->constbuf[PIPE_SHADER_FRAGMENT]; + struct pipe_screen *screen = nv40->pipe.screen; struct pipe_winsys *ws = nv40->pipe.winsys; struct nouveau_stateobj *so; boolean new_consts = FALSE; @@ -932,7 +933,7 @@ nv40_fragprog_validate(struct nv40_context *nv40) return FALSE; } - fp->buffer = ws->buffer_create(ws, 0x100, 0, fp->insn_len * 4); + fp->buffer = screen->buffer_create(screen, 0x100, 0, fp->insn_len * 4); nv40_fragprog_upload(nv40, fp); so = so_new(4, 1); diff --git a/src/gallium/drivers/nv40/nv40_miptree.c b/src/gallium/drivers/nv40/nv40_miptree.c index 638d279aa5..abadca8c93 100644 --- a/src/gallium/drivers/nv40/nv40_miptree.c +++ b/src/gallium/drivers/nv40/nv40_miptree.c @@ -67,7 +67,6 @@ nv40_miptree_layout(struct nv40_miptree *mt) static struct pipe_texture * nv40_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *pt) { - struct pipe_winsys *ws = pscreen->winsys; struct nv40_miptree *mt; unsigned buf_usage = PIPE_BUFFER_USAGE_PIXEL | NOUVEAU_BUFFER_USAGE_TEXTURE; @@ -76,7 +75,7 @@ nv40_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *pt) if (!mt) return NULL; mt->base = *pt; - mt->base.refcount = 1; + pipe_reference_init(&mt->base.reference, 1); mt->base.screen = pscreen; /* Swizzled textures must be POT */ @@ -112,7 +111,7 @@ nv40_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *pt) nv40_miptree_layout(mt); - mt->buffer = ws->buffer_create(ws, 256, buf_usage, mt->total_size); + mt->buffer = pscreen->buffer_create(pscreen, 256, buf_usage, mt->total_size); if (!mt->buffer) { FREE(mt); return NULL; @@ -137,27 +136,22 @@ nv40_miptree_blanket(struct pipe_screen *pscreen, const struct pipe_texture *pt, return NULL; mt->base = *pt; - mt->base.refcount = 1; + pipe_reference_init(&mt->base.reference, 1); mt->base.screen = pscreen; mt->level[0].pitch = stride[0]; mt->level[0].image_offset = CALLOC(1, sizeof(unsigned)); - pipe_buffer_reference(pscreen, &mt->buffer, pb); + pipe_buffer_reference(&mt->buffer, pb); return &mt->base; } static void -nv40_miptree_release(struct pipe_screen *pscreen, struct pipe_texture **ppt) +nv40_miptree_destroy(struct pipe_texture *pt) { - struct pipe_texture *pt = *ppt; struct nv40_miptree *mt = (struct nv40_miptree *)pt; int l; - *ppt = NULL; - if (--pt->refcount) - return; - - pipe_buffer_reference(pscreen, &mt->buffer, NULL); + pipe_buffer_reference(&mt->buffer, NULL); for (l = 0; l <= pt->last_level; l++) { if (mt->level[l].image_offset) FREE(mt->level[l].image_offset); @@ -183,7 +177,7 @@ nv40_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt, ns->base.height = pt->height[level]; ns->base.usage = flags; ns->base.status = PIPE_SURFACE_STATUS_DEFINED; - ns->base.refcount = 1; + pipe_reference_init(&ns->base.reference, 1); ns->base.face = face; ns->base.level = level; ns->base.zslice = zslice; @@ -202,15 +196,8 @@ nv40_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt, } static void -nv40_miptree_surface_del(struct pipe_screen *pscreen, - struct pipe_surface **psurface) +nv40_miptree_surface_del(struct pipe_surface *ps) { - struct pipe_surface *ps = *psurface; - - *psurface = NULL; - if (--ps->refcount > 0) - return; - pipe_texture_reference(&ps->texture, NULL); FREE(ps); } @@ -220,8 +207,8 @@ nv40_screen_init_miptree_functions(struct pipe_screen *pscreen) { pscreen->texture_create = nv40_miptree_create; pscreen->texture_blanket = nv40_miptree_blanket; - pscreen->texture_release = nv40_miptree_release; + pscreen->texture_destroy = nv40_miptree_destroy; pscreen->get_tex_surface = nv40_miptree_surface_new; - pscreen->tex_surface_release = nv40_miptree_surface_del; + pscreen->tex_surface_destroy = nv40_miptree_surface_del; } diff --git a/src/gallium/drivers/nv40/nv40_transfer.c b/src/gallium/drivers/nv40/nv40_transfer.c index f762f32f0c..728e8b5674 100644 --- a/src/gallium/drivers/nv40/nv40_transfer.c +++ b/src/gallium/drivers/nv40/nv40_transfer.c @@ -64,7 +64,6 @@ nv40_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt, if (!tx) return NULL; - tx->base.refcount = 1; pipe_texture_reference(&tx->base.texture, pt); tx->base.format = pt->format; tx->base.x = x; @@ -138,12 +137,12 @@ nv40_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt, } static void -nv40_transfer_del(struct pipe_screen *pscreen, struct pipe_transfer **pptx) +nv40_transfer_del(struct pipe_screen *pscreen, struct pipe_transfer *ptx) { - struct pipe_transfer *ptx = *pptx; struct nv40_transfer *tx = (struct nv40_transfer *)ptx; if (!tx->direct && ptx->usage != PIPE_TRANSFER_READ) { + struct pipe_screen *pscreen = ptx->texture->screen; struct nv40_screen *nvscreen = nv40_screen(pscreen); struct pipe_surface *dst; @@ -160,10 +159,6 @@ nv40_transfer_del(struct pipe_screen *pscreen, struct pipe_transfer **pptx) pipe_surface_reference(&dst, NULL); } - *pptx = NULL; - if (--ptx->refcount) - return; - pipe_surface_reference(&tx->surface, NULL); pipe_texture_reference(&ptx->texture, NULL); FREE(ptx); @@ -195,7 +190,7 @@ void nv40_screen_init_transfer_functions(struct pipe_screen *pscreen) { pscreen->get_tex_transfer = nv40_transfer_new; - pscreen->tex_transfer_release = nv40_transfer_del; + pscreen->tex_transfer_destroy = nv40_transfer_del; pscreen->transfer_map = nv40_transfer_map; pscreen->transfer_unmap = nv40_transfer_unmap; } diff --git a/src/gallium/drivers/nv50/nv50_miptree.c b/src/gallium/drivers/nv50/nv50_miptree.c index 24a68b7235..dc4688ccdc 100644 --- a/src/gallium/drivers/nv50/nv50_miptree.c +++ b/src/gallium/drivers/nv50/nv50_miptree.c @@ -29,7 +29,6 @@ static struct pipe_texture * nv50_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *tmp) { - struct pipe_winsys *ws = pscreen->winsys; struct nv50_miptree *mt = CALLOC_STRUCT(nv50_miptree); struct pipe_texture *pt = &mt->base; unsigned usage, width = tmp->width[0], height = tmp->height[0]; @@ -37,7 +36,7 @@ nv50_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *tmp) int i, l; mt->base = *tmp; - mt->base.refcount = 1; + pipe_reference_init(&mt->base.reference, 1); mt->base.screen = pscreen; usage = PIPE_BUFFER_USAGE_PIXEL; @@ -94,7 +93,7 @@ nv50_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *tmp) } } - mt->buffer = ws->buffer_create(ws, 256, usage, mt->total_size); + mt->buffer = pscreen->buffer_create(pscreen, 256, usage, mt->total_size); if (!mt->buffer) { FREE(mt); return NULL; @@ -119,29 +118,23 @@ nv50_miptree_blanket(struct pipe_screen *pscreen, const struct pipe_texture *pt, return NULL; mt->base = *pt; - mt->base.refcount = 1; + pipe_reference_init(&mt->base.reference, 1); mt->base.screen = pscreen; mt->image_nr = 1; mt->level[0].pitch = *stride; mt->level[0].image_offset = CALLOC(1, sizeof(unsigned)); - pipe_buffer_reference(pscreen, &mt->buffer, pb); + pipe_buffer_reference(&mt->buffer, pb); return &mt->base; } static void -nv50_miptree_release(struct pipe_screen *pscreen, struct pipe_texture **ppt) +nv50_miptree_destroy(struct pipe_texture *pt) { - struct pipe_texture *pt = *ppt; - - *ppt = NULL; - - if (--pt->refcount <= 0) { - struct nv50_miptree *mt = nv50_miptree(pt); + struct nv50_miptree *mt = nv50_miptree(pt); - pipe_buffer_reference(pscreen, &mt->buffer, NULL); - FREE(mt); - } + pipe_buffer_reference(&mt->buffer, NULL); + FREE(mt); } static struct pipe_surface * @@ -171,7 +164,7 @@ nv50_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt, ps->height = pt->height[level]; ps->usage = flags; ps->status = PIPE_SURFACE_STATUS_DEFINED; - ps->refcount = 1; + pipe_reference_init(&ps->reference, 1); ps->face = face; ps->level = level; ps->zslice = zslice; @@ -181,18 +174,12 @@ nv50_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt, } static void -nv50_miptree_surface_del(struct pipe_screen *pscreen, - struct pipe_surface **psurface) +nv50_miptree_surface_del(struct pipe_surface *ps) { - struct pipe_surface *ps = *psurface; struct nv50_surface *s = nv50_surface(ps); - *psurface = NULL; - - if (--ps->refcount <= 0) { - pipe_texture_reference(&ps->texture, NULL); - FREE(s); - } + pipe_texture_reference(&ps->texture, NULL); + FREE(s); } void @@ -200,8 +187,8 @@ nv50_screen_init_miptree_functions(struct pipe_screen *pscreen) { pscreen->texture_create = nv50_miptree_create; pscreen->texture_blanket = nv50_miptree_blanket; - pscreen->texture_release = nv50_miptree_release; + pscreen->texture_destroy = nv50_miptree_destroy; pscreen->get_tex_surface = nv50_miptree_surface_new; - pscreen->tex_surface_release = nv50_miptree_surface_del; + pscreen->tex_surface_destroy = nv50_miptree_surface_del; } diff --git a/src/gallium/drivers/nv50/nv50_program.c b/src/gallium/drivers/nv50/nv50_program.c index 14c5d47e79..308eb34784 100644 --- a/src/gallium/drivers/nv50/nv50_program.c +++ b/src/gallium/drivers/nv50/nv50_program.c @@ -1603,7 +1603,7 @@ nv50_program_validate_code(struct nv50_context *nv50, struct nv50_program *p) { struct nouveau_channel *chan = nv50->screen->nvws->channel; struct nouveau_grobj *tesla = nv50->screen->tesla; - struct pipe_winsys *ws = nv50->pipe.winsys; + struct pipe_screen *screen = nv50->pipe.screen; struct nv50_program_exec *e; struct nouveau_stateobj *so; const unsigned flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_WR; @@ -1611,7 +1611,7 @@ nv50_program_validate_code(struct nv50_context *nv50, struct nv50_program *p) boolean upload = FALSE; if (!p->buffer) { - p->buffer = ws->buffer_create(ws, 0x100, 0, p->exec_size * 4); + p->buffer = screen->buffer_create(screen, 0x100, 0, p->exec_size * 4); upload = TRUE; } @@ -1775,7 +1775,7 @@ nv50_program_destroy(struct nv50_context *nv50, struct nv50_program *p) p->exec_size = 0; if (p->buffer) - pipe_buffer_reference(pscreen, &p->buffer, NULL); + pipe_buffer_reference(&p->buffer, NULL); nv50->screen->nvws->res_free(&p->data); diff --git a/src/gallium/drivers/nv50/nv50_query.c b/src/gallium/drivers/nv50/nv50_query.c index 7c8831a46d..a2c56f99a8 100644 --- a/src/gallium/drivers/nv50/nv50_query.c +++ b/src/gallium/drivers/nv50/nv50_query.c @@ -41,13 +41,13 @@ nv50_query(struct pipe_query *pipe) static struct pipe_query * nv50_query_create(struct pipe_context *pipe, unsigned type) { - struct pipe_winsys *ws = pipe->winsys; + struct pipe_screen *screen = pipe->winsys; struct nv50_query *q = CALLOC_STRUCT(nv50_query); assert (q->type == PIPE_QUERY_OCCLUSION_COUNTER); q->type = type; - q->buffer = ws->buffer_create(ws, 256, 0, 16); + q->buffer = screen->buffer_create(screen, 256, 0, 16); if (!q->buffer) { FREE(q); return NULL; @@ -62,7 +62,7 @@ nv50_query_destroy(struct pipe_context *pipe, struct pipe_query *pq) struct nv50_query *q = nv50_query(pq); if (q) { - pipe_buffer_reference(pipe->screen, &q->buffer, NULL); + pipe_buffer_reference(&q->buffer, NULL); FREE(q); } } diff --git a/src/gallium/drivers/nv50/nv50_screen.c b/src/gallium/drivers/nv50/nv50_screen.c index ee24405d36..bbfe42e478 100644 --- a/src/gallium/drivers/nv50/nv50_screen.c +++ b/src/gallium/drivers/nv50/nv50_screen.c @@ -285,7 +285,7 @@ nv50_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *nvws) so_data (so, 8); /* Shared constant buffer */ - screen->constbuf = ws->buffer_create(ws, 0, 0, 128 * 4 * 4); + screen->constbuf = screen->pipe.buffer_create(&screen->pipe, 0, 0, 128 * 4 * 4); if (nvws->res_init(&screen->vp_data_heap, 0, 128)) { NOUVEAU_ERR("Error initialising constant buffer\n"); nv50_screen_destroy(&screen->pipe); @@ -304,7 +304,7 @@ nv50_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *nvws) * blocks. At some point we *may* want to go the NVIDIA way of doing * things? */ - screen->tic = ws->buffer_create(ws, 0, 0, 32 * 8 * 4); + screen->tic = screen->pipe.buffer_create(&screen->pipe, 0, 0, 32 * 8 * 4); so_method(so, screen->tesla, 0x1280, 3); so_reloc (so, screen->tic, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | NOUVEAU_BO_HIGH, 0, 0); @@ -318,7 +318,7 @@ nv50_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *nvws) NOUVEAU_BO_RD | NOUVEAU_BO_LOW, 0, 0); so_data (so, 0x00000800); - screen->tsc = ws->buffer_create(ws, 0, 0, 32 * 8 * 4); + screen->tsc = screen->pipe.buffer_create(&screen->pipe, 0, 0, 32 * 8 * 4); so_method(so, screen->tesla, 0x1280, 3); so_reloc (so, screen->tsc, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | NOUVEAU_BO_HIGH, 0, 0); diff --git a/src/gallium/drivers/nv50/nv50_transfer.c b/src/gallium/drivers/nv50/nv50_transfer.c index a00c999510..747195b4f6 100644 --- a/src/gallium/drivers/nv50/nv50_transfer.c +++ b/src/gallium/drivers/nv50/nv50_transfer.c @@ -123,7 +123,6 @@ nv50_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt, if (!tx) return NULL; - tx->base.refcount = 1; pipe_texture_reference(&tx->base.texture, pt); tx->base.format = pt->format; tx->base.width = w; @@ -158,17 +157,13 @@ nv50_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt, } static void -nv50_transfer_del(struct pipe_screen *pscreen, struct pipe_transfer **pptx) +nv50_transfer_del(struct pipe_transfer *ptx) { - struct pipe_transfer *ptx = *pptx; struct nv50_transfer *tx = (struct nv50_transfer *)ptx; struct nv50_miptree *mt = nv50_miptree(ptx->texture); - *pptx = NULL; - if (--ptx->refcount) - return; - if (ptx->usage != PIPE_TRANSFER_READ) { + struct pipe_screen *pscreen = ptx->texture->screen; nv50_transfer_rect_m2mf(pscreen, tx->buffer, tx->base.stride, 0, 0, tx->base.width, tx->base.height, mt->buffer, tx->level_pitch, @@ -179,7 +174,7 @@ nv50_transfer_del(struct pipe_screen *pscreen, struct pipe_transfer **pptx) NOUVEAU_BO_VRAM | NOUVEAU_BO_GART); } - pipe_buffer_reference(pscreen, &tx->buffer, NULL); + pipe_buffer_reference(&tx->buffer, NULL); pipe_texture_reference(&ptx->texture, NULL); FREE(ptx); } @@ -210,7 +205,7 @@ void nv50_transfer_init_screen_functions(struct pipe_screen *pscreen) { pscreen->get_tex_transfer = nv50_transfer_new; - pscreen->tex_transfer_release = nv50_transfer_del; + pscreen->tex_transfer_destroy = nv50_transfer_del; pscreen->transfer_map = nv50_transfer_map; pscreen->transfer_unmap = nv50_transfer_unmap; } diff --git a/src/gallium/drivers/r300/r300_screen.c b/src/gallium/drivers/r300/r300_screen.c index e97334463a..3c91967a72 100644 --- a/src/gallium/drivers/r300/r300_screen.c +++ b/src/gallium/drivers/r300/r300_screen.c @@ -268,7 +268,6 @@ r300_get_tex_transfer(struct pipe_screen *screen, trans = CALLOC_STRUCT(r300_transfer); if (trans) { - trans->transfer.refcount = 1; pipe_texture_reference(&trans->transfer.texture, texture); trans->transfer.format = trans->transfer.format; trans->transfer.width = w; @@ -284,17 +283,10 @@ r300_get_tex_transfer(struct pipe_screen *screen, } static void -r300_tex_transfer_release(struct pipe_screen *screen, - struct pipe_transfer **transfer) +r300_tex_transfer_destroy(struct pipe_transfer *trans) { - struct pipe_transfer *trans = *transfer; - - if (--trans->refcount == 0) { - pipe_texture_reference(&trans->texture, NULL); - FREE(trans); - } - - *transfer = NULL; + pipe_texture_reference(&trans->texture, NULL); + FREE(trans); } static void* r300_transfer_map(struct pipe_screen* screen, @@ -359,7 +351,7 @@ struct pipe_screen* r300_create_screen(struct r300_winsys* r300_winsys) r300screen->screen.get_paramf = r300_get_paramf; r300screen->screen.is_format_supported = r300_is_format_supported; r300screen->screen.get_tex_transfer = r300_get_tex_transfer; - r300screen->screen.tex_transfer_release = r300_tex_transfer_release; + r300screen->screen.tex_transfer_destroy = r300_tex_transfer_destroy; r300screen->screen.transfer_map = r300_transfer_map; r300screen->screen.transfer_unmap = r300_transfer_unmap; diff --git a/src/gallium/drivers/r300/r300_swtcl_emit.c b/src/gallium/drivers/r300/r300_swtcl_emit.c index f9baaade1e..01235674ac 100644 --- a/src/gallium/drivers/r300/r300_swtcl_emit.c +++ b/src/gallium/drivers/r300/r300_swtcl_emit.c @@ -79,7 +79,7 @@ static boolean r300_swtcl_render_allocate_vertices(struct vbuf_render* render, size_t size = (size_t)vertex_size * (size_t)count; if (r300render->vbo) { - pipe_buffer_reference(screen, &r300render->vbo, NULL); + pipe_buffer_reference(&r300render->vbo, NULL); } r300render->vbo_size = MAX2(size, r300render->vbo_alloc_size); @@ -125,9 +125,8 @@ static void r300_swtcl_render_unmap_vertices(struct vbuf_render* render, static void r300_swtcl_render_release_vertices(struct vbuf_render* render) { struct r300_swtcl_render* r300render = r300_swtcl_render(render); - struct pipe_screen* screen = r300render->r300->context.screen; - pipe_buffer_reference(screen, &r300render->vbo, NULL); + pipe_buffer_reference(&r300render->vbo, NULL); } static boolean r300_swtcl_render_set_primitive(struct vbuf_render* render, diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c index b3425587e3..b7027553b5 100644 --- a/src/gallium/drivers/r300/r300_texture.c +++ b/src/gallium/drivers/r300/r300_texture.c @@ -68,7 +68,7 @@ static struct pipe_texture* } tex->tex = *template; - tex->tex.refcount = 1; + pipe_reference_init(&tex->tex.reference, 1); tex->tex.screen = screen; r300_setup_miptree(tex); @@ -85,24 +85,13 @@ static struct pipe_texture* return (struct pipe_texture*)tex; } -static void r300_texture_release(struct pipe_screen* screen, - struct pipe_texture** texture) +static void r300_texture_destroy(struct pipe_texture* texture) { - if (!*texture) { - return; - } - - (*texture)->refcount--; - - if ((*texture)->refcount <= 0) { - struct r300_texture* tex = (struct r300_texture*)*texture; + struct r300_texture* tex = (struct r300_texture*)texture; - pipe_buffer_reference(screen, &tex->buffer, NULL); + pipe_buffer_reference(&tex->buffer, NULL); - FREE(tex); - } - - *texture = NULL; + FREE(tex); } static struct pipe_surface* r300_get_tex_surface(struct pipe_screen* screen, @@ -120,7 +109,7 @@ static struct pipe_surface* r300_get_tex_surface(struct pipe_screen* screen, offset = tex->offset[level]; if (surface) { - surface->refcount = 1; + pipe_reference_init(&surface->reference, 1); pipe_texture_reference(&surface->texture, texture); surface->format = texture->format; surface->width = texture->width[level]; @@ -133,19 +122,10 @@ static struct pipe_surface* r300_get_tex_surface(struct pipe_screen* screen, return surface; } -static void r300_tex_surface_release(struct pipe_screen* screen, - struct pipe_surface** surface) +static void r300_tex_surface_destroy(struct pipe_surface* s) { - struct pipe_surface* s = *surface; - - s->refcount--; - - if (s->refcount <= 0) { - pipe_texture_reference(&s->texture, NULL); - FREE(s); - } - - *surface = NULL; + pipe_texture_reference(&s->texture, NULL); + FREE(s); } static struct pipe_texture* @@ -168,12 +148,12 @@ static struct pipe_texture* } tex->tex = *base; - tex->tex.refcount = 1; + pipe_reference_init(&tex->tex.reference, 1); tex->tex.screen = screen; tex->stride = *stride; - pipe_buffer_reference(screen, &tex->buffer, buffer); + pipe_buffer_reference(&tex->buffer, buffer); return (struct pipe_texture*)tex; } @@ -181,9 +161,9 @@ static struct pipe_texture* void r300_init_screen_texture_functions(struct pipe_screen* screen) { screen->texture_create = r300_texture_create; - screen->texture_release = r300_texture_release; + screen->texture_destroy = r300_texture_destroy; screen->get_tex_surface = r300_get_tex_surface; - screen->tex_surface_release = r300_tex_surface_release; + screen->tex_surface_destroy = r300_tex_surface_destroy; screen->texture_blanket = r300_texture_blanket; } @@ -196,7 +176,7 @@ boolean r300_get_texture_buffer(struct pipe_texture* texture, return FALSE; } - pipe_buffer_reference(texture->screen, buffer, tex->buffer); + pipe_buffer_reference(buffer, tex->buffer); if (stride) { *stride = tex->stride; diff --git a/src/gallium/drivers/softpipe/sp_context.c b/src/gallium/drivers/softpipe/sp_context.c index ff5d1b54a4..cc552c4915 100644 --- a/src/gallium/drivers/softpipe/sp_context.c +++ b/src/gallium/drivers/softpipe/sp_context.c @@ -87,7 +87,6 @@ softpipe_unmap_transfers(struct softpipe_context *sp) static void softpipe_destroy( struct pipe_context *pipe ) { struct softpipe_context *softpipe = softpipe_context( pipe ); - struct pipe_screen *screen = pipe->screen; uint i; if (softpipe->draw) @@ -116,7 +115,7 @@ static void softpipe_destroy( struct pipe_context *pipe ) for (i = 0; i < Elements(softpipe->constants); i++) { if (softpipe->constants[i].buffer) { - pipe_buffer_reference(screen, &softpipe->constants[i].buffer, NULL); + pipe_buffer_reference(&softpipe->constants[i].buffer, NULL); } } diff --git a/src/gallium/drivers/softpipe/sp_state_fs.c b/src/gallium/drivers/softpipe/sp_state_fs.c index 4d01a9dbe1..957c8b72e4 100644 --- a/src/gallium/drivers/softpipe/sp_state_fs.c +++ b/src/gallium/drivers/softpipe/sp_state_fs.c @@ -146,14 +146,12 @@ softpipe_set_constant_buffer(struct pipe_context *pipe, const struct pipe_constant_buffer *buf) { struct softpipe_context *softpipe = softpipe_context(pipe); - struct pipe_screen *screen = pipe->screen; assert(shader < PIPE_SHADER_TYPES); assert(index == 0); /* note: reference counting */ - pipe_buffer_reference(screen, - &softpipe->constants[shader].buffer, + pipe_buffer_reference(&softpipe->constants[shader].buffer, buf ? buf->buffer : NULL); softpipe->dirty |= SP_NEW_CONSTANTS; diff --git a/src/gallium/drivers/softpipe/sp_texture.c b/src/gallium/drivers/softpipe/sp_texture.c index 142ce230fc..4919ec826e 100644 --- a/src/gallium/drivers/softpipe/sp_texture.c +++ b/src/gallium/drivers/softpipe/sp_texture.c @@ -59,7 +59,6 @@ static boolean softpipe_texture_layout(struct pipe_screen *screen, struct softpipe_texture * spt) { - struct pipe_winsys *ws = screen->winsys; struct pipe_texture *pt = &spt->base; unsigned level; unsigned width = pt->width[0]; @@ -87,9 +86,9 @@ softpipe_texture_layout(struct pipe_screen *screen, depth = minify(depth); } - spt->buffer = ws->buffer_create(ws, 32, - PIPE_BUFFER_USAGE_PIXEL, - buffer_size); + spt->buffer = screen->buffer_create(screen, 32, + PIPE_BUFFER_USAGE_PIXEL, + buffer_size); return spt->buffer != NULL; } @@ -98,19 +97,18 @@ static boolean softpipe_displaytarget_layout(struct pipe_screen *screen, struct softpipe_texture * spt) { - struct pipe_winsys *ws = screen->winsys; unsigned usage = (PIPE_BUFFER_USAGE_CPU_READ_WRITE | PIPE_BUFFER_USAGE_GPU_READ_WRITE); spt->base.nblocksx[0] = pf_get_nblocksx(&spt->base.block, spt->base.width[0]); spt->base.nblocksy[0] = pf_get_nblocksy(&spt->base.block, spt->base.height[0]); - spt->buffer = ws->surface_buffer_create( ws, - spt->base.width[0], - spt->base.height[0], - spt->base.format, - usage, - &spt->stride[0]); + spt->buffer = screen->surface_buffer_create( screen, + spt->base.width[0], + spt->base.height[0], + spt->base.format, + usage, + &spt->stride[0]); return spt->buffer != NULL; } @@ -128,7 +126,7 @@ softpipe_texture_create(struct pipe_screen *screen, return NULL; spt->base = *templat; - spt->base.refcount = 1; + pipe_reference_init(&spt->base.reference, 1); spt->base.screen = screen; if (spt->base.tex_usage & PIPE_TEXTURE_USAGE_DISPLAY_TARGET) { @@ -140,7 +138,7 @@ softpipe_texture_create(struct pipe_screen *screen, goto fail; } - assert(spt->base.refcount == 1); + assert(spt->base.reference.count == 1); return &spt->base; fail: @@ -170,32 +168,25 @@ softpipe_texture_blanket(struct pipe_screen * screen, return NULL; spt->base = *base; - spt->base.refcount = 1; + pipe_reference_init(&spt->base.reference, 1); spt->base.screen = screen; spt->base.nblocksx[0] = pf_get_nblocksx(&spt->base.block, spt->base.width[0]); spt->base.nblocksy[0] = pf_get_nblocksy(&spt->base.block, spt->base.height[0]); spt->stride[0] = stride[0]; - pipe_buffer_reference(screen, &spt->buffer, buffer); + pipe_buffer_reference(&spt->buffer, buffer); return &spt->base; } static void -softpipe_texture_release(struct pipe_screen *screen, - struct pipe_texture **pt) +softpipe_texture_destroy(struct pipe_texture *pt) { - if (!*pt) - return; - - if (--(*pt)->refcount <= 0) { - struct softpipe_texture *spt = softpipe_texture(*pt); + struct softpipe_texture *spt = softpipe_texture(pt); - pipe_buffer_reference(screen, &spt->buffer, NULL); - FREE(spt); - } - *pt = NULL; + pipe_buffer_reference(&spt->buffer, NULL); + FREE(spt); } @@ -212,7 +203,7 @@ softpipe_get_tex_surface(struct pipe_screen *screen, ps = CALLOC_STRUCT(pipe_surface); if (ps) { - ps->refcount = 1; + pipe_reference_init(&ps->reference, 1); pipe_texture_reference(&ps->texture, pt); ps->format = pt->format; ps->width = pt->width[level]; @@ -259,20 +250,15 @@ softpipe_get_tex_surface(struct pipe_screen *screen, static void -softpipe_tex_surface_release(struct pipe_screen *screen, - struct pipe_surface **s) +softpipe_tex_surface_destroy(struct pipe_surface *surf) { - struct pipe_surface *surf = *s; /* Effectively do the texture_update work here - if texture images * needed post-processing to put them into hardware layout, this is * where it would happen. For softpipe, nothing to do. */ assert(surf->texture); - if (--surf->refcount == 0) { - pipe_texture_reference(&surf->texture, NULL); - FREE(surf); - } - *s = NULL; + pipe_texture_reference(&surf->texture, NULL); + FREE(surf); } @@ -292,7 +278,6 @@ softpipe_get_tex_transfer(struct pipe_screen *screen, spt = CALLOC_STRUCT(softpipe_transfer); if (spt) { struct pipe_transfer *pt = &spt->base; - pt->refcount = 1; pipe_texture_reference(&pt->texture, texture); pt->format = texture->format; pt->block = texture->block; @@ -327,20 +312,15 @@ softpipe_get_tex_transfer(struct pipe_screen *screen, static void -softpipe_tex_transfer_release(struct pipe_screen *screen, - struct pipe_transfer **t) +softpipe_tex_transfer_destroy(struct pipe_transfer *transfer) { - struct softpipe_transfer *transfer = softpipe_transfer(*t); /* Effectively do the texture_update work here - if texture images * needed post-processing to put them into hardware layout, this is * where it would happen. For softpipe, nothing to do. */ - assert (transfer->base.texture); - if (--transfer->base.refcount == 0) { - pipe_texture_reference(&transfer->base.texture, NULL); - FREE(transfer); - } - *t = NULL; + assert (transfer->texture); + pipe_texture_reference(&transfer->texture, NULL); + FREE(transfer); } @@ -408,13 +388,13 @@ softpipe_init_screen_texture_funcs(struct pipe_screen *screen) { screen->texture_create = softpipe_texture_create; screen->texture_blanket = softpipe_texture_blanket; - screen->texture_release = softpipe_texture_release; + screen->texture_destroy = softpipe_texture_destroy; screen->get_tex_surface = softpipe_get_tex_surface; - screen->tex_surface_release = softpipe_tex_surface_release; + screen->tex_surface_destroy = softpipe_tex_surface_destroy; screen->get_tex_transfer = softpipe_get_tex_transfer; - screen->tex_transfer_release = softpipe_tex_transfer_release; + screen->tex_transfer_destroy = softpipe_tex_transfer_destroy; screen->transfer_map = softpipe_transfer_map; screen->transfer_unmap = softpipe_transfer_unmap; } diff --git a/src/gallium/drivers/softpipe/sp_tile_cache.c b/src/gallium/drivers/softpipe/sp_tile_cache.c index 593360aab0..51e34d0d62 100644 --- a/src/gallium/drivers/softpipe/sp_tile_cache.c +++ b/src/gallium/drivers/softpipe/sp_tile_cache.c @@ -140,11 +140,11 @@ sp_destroy_tile_cache(struct softpipe_tile_cache *tc) } if (tc->transfer) { screen = tc->transfer->texture->screen; - screen->tex_transfer_release(screen, &tc->transfer); + screen->tex_transfer_destroy(tc->transfer); } if (tc->tex_trans) { screen = tc->tex_trans->texture->screen; - screen->tex_transfer_release(screen, &tc->tex_trans); + screen->tex_transfer_destroy(tc->tex_trans); } FREE( tc ); @@ -167,11 +167,11 @@ sp_tile_cache_set_surface(struct softpipe_tile_cache *tc, return; if (tc->transfer_map) { - tc->screen->transfer_unmap(tc->screen, tc->transfer); + screen->transfer_unmap(screen, tc->transfer); tc->transfer_map = NULL; } - screen->tex_transfer_release(screen, &tc->transfer); + screen->tex_transfer_destroy(tc->transfer); } tc->surface = ps; @@ -249,11 +249,11 @@ sp_tile_cache_set_texture(struct pipe_context *pipe, struct pipe_screen *screen = tc->transfer->texture->screen; if (tc->tex_trans_map) { - tc->screen->transfer_unmap(tc->screen, tc->tex_trans); + screen->transfer_unmap(screen, tc->tex_trans); tc->tex_trans_map = NULL; } - screen->tex_transfer_release(screen, &tc->tex_trans); + screen->tex_transfer_destroy(tc->tex_trans); } /* mark as entries as invalid/empty */ @@ -559,7 +559,7 @@ sp_get_cached_tile_tex(struct softpipe_context *sp, if (tc->tex_trans_map) tc->screen->transfer_unmap(tc->screen, tc->tex_trans); - screen->tex_transfer_release(screen, &tc->tex_trans); + screen->tex_transfer_destroy(tc->tex_trans); } tc->tex_trans = screen->get_tex_transfer(screen, tc->texture, face, level, z, diff --git a/src/gallium/drivers/trace/tr_screen.c b/src/gallium/drivers/trace/tr_screen.c index 164c6bbc4d..1d868eff6b 100644 --- a/src/gallium/drivers/trace/tr_screen.c +++ b/src/gallium/drivers/trace/tr_screen.c @@ -207,37 +207,18 @@ trace_screen_texture_blanket(struct pipe_screen *_screen, static void -trace_screen_texture_release(struct pipe_screen *_screen, - struct pipe_texture **ptexture) +trace_screen_texture_destroy(struct pipe_texture *texture) { - struct trace_screen *tr_scr = trace_screen(_screen); - struct pipe_screen *screen = tr_scr->screen; - struct trace_texture *tr_tex; - struct pipe_texture *texture; - - assert(ptexture); - if(*ptexture) { - tr_tex = trace_texture(tr_scr, *ptexture); - texture = tr_tex->texture; - assert(texture->screen == screen); - } - else - texture = NULL; - - if (*ptexture) { - if (!--(*ptexture)->refcount) { - trace_dump_call_begin("pipe_screen", "texture_destroy"); - - trace_dump_arg(ptr, screen); - trace_dump_arg(ptr, texture); - - trace_texture_destroy(tr_scr, *ptexture); - - trace_dump_call_end(); - } + struct pipe_screen *screen = texture->screen; - *ptexture = NULL; - } + trace_dump_call_begin("pipe_screen", "texture_destroy"); + + trace_dump_arg(ptr, screen); + trace_dump_arg(ptr, texture); + + trace_texture_destroy(trace_screen(screen), texture); + + trace_dump_call_end(); } @@ -280,38 +261,19 @@ trace_screen_get_tex_surface(struct pipe_screen *_screen, static void -trace_screen_tex_surface_release(struct pipe_screen *_screen, - struct pipe_surface **psurface) +trace_screen_tex_surface_destroy(struct pipe_surface *surface) { - struct trace_screen *tr_scr = trace_screen(_screen); - struct pipe_screen *screen = tr_scr->screen; - struct trace_texture *tr_tex; - struct trace_surface *tr_surf; - struct pipe_surface *surface; - - assert(psurface); - if(*psurface) { - tr_tex = trace_texture(tr_scr, (*psurface)->texture); - tr_surf = trace_surface(tr_tex, *psurface); - surface = tr_surf->surface; - } - else - surface = NULL; + struct pipe_screen *screen = surface->texture->screen; - if (*psurface) { - if (!--(*psurface)->refcount) { - trace_dump_call_begin("pipe_screen", "tex_surface_destroy"); - - trace_dump_arg(ptr, screen); - trace_dump_arg(ptr, surface); + trace_dump_call_begin("pipe_screen", "tex_surface_destroy"); - trace_surface_destroy(tr_tex, *psurface); + trace_dump_arg(ptr, screen); + trace_dump_arg(ptr, surface); - trace_dump_call_end(); - } - - *psurface = NULL; - } + trace_surface_destroy(trace_texture(trace_screen(screen), surface->texture), + surface); + + trace_dump_call_end(); } @@ -356,38 +318,20 @@ trace_screen_get_tex_transfer(struct pipe_screen *_screen, static void -trace_screen_tex_transfer_release(struct pipe_screen *_screen, - struct pipe_transfer **ptransfer) +trace_screen_tex_transfer_destroy(struct pipe_transfer *transfer) { - struct trace_screen *tr_scr = trace_screen(_screen); - struct pipe_screen *screen = tr_scr->screen; - struct trace_texture *tr_tex; - struct trace_transfer *tr_trans; - struct pipe_transfer *transfer; - - assert(ptransfer); - if(*ptransfer) { - tr_tex = trace_texture(tr_scr, (*ptransfer)->texture); - tr_trans = trace_transfer(tr_tex, *ptransfer); - transfer = tr_trans->transfer; - } - else - transfer = NULL; - - if (*ptransfer) { - if (!--(*ptransfer)->refcount) { - trace_dump_call_begin("pipe_screen", "tex_transfer_destroy"); - - trace_dump_arg(ptr, screen); - trace_dump_arg(ptr, transfer); + struct pipe_texture *texture = transfer->texture; + struct pipe_screen *screen = texture->screen; - trace_transfer_destroy(tr_tex, *ptransfer); + trace_dump_call_begin("pipe_screen", "tex_transfer_destroy"); - trace_dump_call_end(); - } - - *ptransfer = NULL; - } + trace_dump_arg(ptr, screen); + trace_dump_arg(ptr, transfer); + + trace_transfer_destroy(trace_texture(trace_screen(screen), texture), + transfer); + + trace_dump_call_end(); } @@ -509,11 +453,11 @@ trace_screen_create(struct pipe_screen *screen) tr_scr->base.is_format_supported = trace_screen_is_format_supported; tr_scr->base.texture_create = trace_screen_texture_create; tr_scr->base.texture_blanket = trace_screen_texture_blanket; - tr_scr->base.texture_release = trace_screen_texture_release; + tr_scr->base.texture_destroy = trace_screen_texture_destroy; tr_scr->base.get_tex_surface = trace_screen_get_tex_surface; - tr_scr->base.tex_surface_release = trace_screen_tex_surface_release; + tr_scr->base.tex_surface_destroy = trace_screen_tex_surface_destroy; tr_scr->base.get_tex_transfer = trace_screen_get_tex_transfer; - tr_scr->base.tex_transfer_release = trace_screen_tex_transfer_release; + tr_scr->base.tex_transfer_destroy = trace_screen_tex_transfer_destroy; tr_scr->base.transfer_map = trace_screen_transfer_map; tr_scr->base.transfer_unmap = trace_screen_transfer_unmap; diff --git a/src/gallium/drivers/trace/tr_state.c b/src/gallium/drivers/trace/tr_state.c index 81a9e2376e..0f175cd31c 100644 --- a/src/gallium/drivers/trace/tr_state.c +++ b/src/gallium/drivers/trace/tr_state.c @@ -50,6 +50,14 @@ void trace_dump_block(const struct pipe_format_block *block) } +static void trace_dump_reference(const struct pipe_reference *reference) +{ + trace_dump_struct_begin("pipe_reference"); + trace_dump_member(uint, reference, count); + trace_dump_struct_end(); +} + + void trace_dump_template(const struct pipe_texture *templat) { if(!templat) { @@ -397,6 +405,8 @@ void trace_dump_surface(const struct pipe_surface *state) trace_dump_struct_begin("pipe_surface"); + trace_dump_reference(&state->reference); + trace_dump_member(format, state, format); trace_dump_member(uint, state, status); trace_dump_member(uint, state, clear_value); @@ -405,7 +415,6 @@ void trace_dump_surface(const struct pipe_surface *state) trace_dump_member(uint, state, layout); trace_dump_member(uint, state, offset); - trace_dump_member(uint, state, refcount); trace_dump_member(uint, state, usage); trace_dump_member(ptr, state, texture); @@ -437,7 +446,6 @@ void trace_dump_transfer(const struct pipe_transfer *state) trace_dump_member(uint, state, nblocksx); trace_dump_member(uint, state, nblocksy); trace_dump_member(uint, state, stride); - trace_dump_member(uint, state, refcount); trace_dump_member(uint, state, usage); trace_dump_member(ptr, state, texture); diff --git a/src/gallium/drivers/trace/tr_texture.c b/src/gallium/drivers/trace/tr_texture.c index 120ba0dd31..dc45d3dcc1 100644 --- a/src/gallium/drivers/trace/tr_texture.c +++ b/src/gallium/drivers/trace/tr_texture.c @@ -134,7 +134,7 @@ trace_transfer_create(struct trace_texture *tr_tex, return &tr_trans->base; error: - pipe_transfer_reference(&transfer, NULL); + transfer->texture->screen->tex_transfer_destroy(transfer); return NULL; } @@ -145,7 +145,7 @@ trace_transfer_destroy(struct trace_texture *tr_tex, { struct trace_transfer *tr_trans = trace_transfer(tr_tex, transfer); pipe_texture_reference(&tr_trans->base.texture, NULL); - pipe_transfer_reference(&tr_trans->transfer, NULL); + transfer->texture->screen->tex_transfer_destroy(tr_trans->transfer); FREE(tr_trans); } diff --git a/src/gallium/drivers/trace/tr_winsys.c b/src/gallium/drivers/trace/tr_winsys.c index c4148fe810..86420bbf22 100644 --- a/src/gallium/drivers/trace/tr_winsys.c +++ b/src/gallium/drivers/trace/tr_winsys.c @@ -295,18 +295,16 @@ trace_winsys_buffer_unmap(struct pipe_winsys *_winsys, static void -trace_winsys_buffer_destroy(struct pipe_winsys *_winsys, - struct pipe_buffer *buffer) +trace_winsys_buffer_destroy(struct pipe_buffer *buffer) { - struct trace_winsys *tr_ws = trace_winsys(_winsys); - struct pipe_winsys *winsys = tr_ws->winsys; + struct pipe_winsys *winsys = buffer->screen->winsys; trace_dump_call_begin("pipe_winsys", "buffer_destroy"); trace_dump_arg(ptr, winsys); trace_dump_arg(ptr, buffer); - winsys->buffer_destroy(winsys, buffer); + winsys->buffer_destroy(buffer); trace_dump_call_end(); } diff --git a/src/gallium/include/pipe/internal/p_winsys_screen.h b/src/gallium/include/pipe/internal/p_winsys_screen.h index 8d3bab0caa..f4a29e63c7 100644 --- a/src/gallium/include/pipe/internal/p_winsys_screen.h +++ b/src/gallium/include/pipe/internal/p_winsys_screen.h @@ -154,8 +154,7 @@ struct pipe_winsys void (*buffer_unmap)( struct pipe_winsys *ws, struct pipe_buffer *buf ); - void (*buffer_destroy)( struct pipe_winsys *ws, - struct pipe_buffer *buf ); + void (*buffer_destroy)( struct pipe_buffer *buf ); /** Set ptr = fence, with reference counting */ diff --git a/src/gallium/include/pipe/p_inlines.h b/src/gallium/include/pipe/p_inlines.h index 4eb928d882..a68b521429 100644 --- a/src/gallium/include/pipe/p_inlines.h +++ b/src/gallium/include/pipe/p_inlines.h @@ -38,97 +38,6 @@ extern "C" { #endif -/** - * Set 'ptr' to point to 'surf' and update reference counting. - * The old thing pointed to, if any, will be unreferenced first. - * 'surf' may be NULL. - */ -static INLINE void -pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf) -{ - /* bump the refcount first */ - if (surf) { - assert(surf->refcount); - surf->refcount++; - } - - if (*ptr) { - struct pipe_screen *screen; - assert((*ptr)->refcount); - assert((*ptr)->texture); - screen = (*ptr)->texture->screen; - screen->tex_surface_release( screen, ptr ); - assert(!*ptr); - } - - *ptr = surf; -} - - -/** - * \sa pipe_surface_reference - */ -static INLINE void -pipe_transfer_reference(struct pipe_transfer **ptr, struct pipe_transfer *trans) -{ - /* bump the refcount first */ - if (trans) { - assert(trans->refcount); - trans->refcount++; - } - - if (*ptr) { - struct pipe_screen *screen; - assert((*ptr)->refcount); - assert((*ptr)->texture); - screen = (*ptr)->texture->screen; - screen->tex_transfer_release( screen, ptr ); - assert(!*ptr); - } - - *ptr = trans; -} - - -/** - * \sa pipe_surface_reference - */ -static INLINE void -pipe_texture_reference(struct pipe_texture **ptr, - struct pipe_texture *pt) -{ - assert(ptr); - - if (pt) { - assert(pt->refcount); - pt->refcount++; - } - - if (*ptr) { - struct pipe_screen *screen = (*ptr)->screen; - assert(screen); - assert((*ptr)->refcount); - screen->texture_release(screen, ptr); - - assert(!*ptr); - } - - *ptr = pt; -} - - -static INLINE void -pipe_texture_release(struct pipe_texture **ptr) -{ - struct pipe_screen *screen; - assert(ptr); - screen = (*ptr)->screen; - assert((*ptr)->refcount); - screen->texture_release(screen, ptr); - *ptr = NULL; -} - - /** * Convenience wrappers for screen buffer functions. */ @@ -199,28 +108,6 @@ pipe_buffer_read(struct pipe_screen *screen, } } -/* XXX: thread safety issues! - */ -static INLINE void -pipe_buffer_reference(struct pipe_screen *screen, - struct pipe_buffer **ptr, - struct pipe_buffer *buf) -{ - if (buf) { - assert(buf->refcount); - buf->refcount++; - } - - if (*ptr) { - assert((*ptr)->refcount); - if(--(*ptr)->refcount == 0) { - screen->buffer_destroy( screen, *ptr ); - } - } - - *ptr = buf; -} - #ifdef __cplusplus } diff --git a/src/gallium/include/pipe/p_refcnt.h b/src/gallium/include/pipe/p_refcnt.h new file mode 100644 index 0000000000..50b7aa90ef --- /dev/null +++ b/src/gallium/include/pipe/p_refcnt.h @@ -0,0 +1,84 @@ +/************************************************************************** + * + * 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 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 P_REFCNT_H +#define P_REFCNT_H + + +#include "p_defines.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +struct pipe_reference +{ + unsigned count; +}; + + +static INLINE void +pipe_reference_init(struct pipe_reference *reference, unsigned count) +{ + reference->count = count; +} + + +/** + * Set 'ptr' to point to 'reference' and update reference counting. + * The old thing pointed to, if any, will be unreferenced first. + * 'reference' may be NULL. + * + * XXX: thread safety issues! + */ +static INLINE bool +pipe_reference(struct pipe_reference **ptr, struct pipe_reference *reference) +{ + bool destroy = FALSE; + + /* bump the reference.count first */ + if (reference) { + assert(reference->count); + reference->count++; + } + + if (*ptr) { + assert((*ptr)->count); + if (--(*ptr)->count == 0) { + destroy = TRUE; + } + } + + *ptr = reference; + + return destroy; +} + + +#endif /* P_REFCNT_H */ diff --git a/src/gallium/include/pipe/p_screen.h b/src/gallium/include/pipe/p_screen.h index 341d1caea0..3688d58118 100644 --- a/src/gallium/include/pipe/p_screen.h +++ b/src/gallium/include/pipe/p_screen.h @@ -113,8 +113,7 @@ struct pipe_screen { const unsigned *stride, struct pipe_buffer *buffer); - void (*texture_release)(struct pipe_screen *, - struct pipe_texture **pt); + void (*texture_destroy)(struct pipe_texture *pt); /** Get a surface which is a "view" into a texture */ struct pipe_surface *(*get_tex_surface)(struct pipe_screen *, @@ -123,10 +122,7 @@ struct pipe_screen { unsigned zslice, unsigned usage ); - /* Surfaces allocated by the above must be released here: - */ - void (*tex_surface_release)( struct pipe_screen *, - struct pipe_surface ** ); + void (*tex_surface_destroy)(struct pipe_surface *); /** Get a transfer object for transferring data to/from a texture */ @@ -138,10 +134,7 @@ struct pipe_screen { unsigned x, unsigned y, unsigned w, unsigned h); - /* Transfer objects allocated by the above must be released here: - */ - void (*tex_transfer_release)( struct pipe_screen *, - struct pipe_transfer ** ); + void (*tex_transfer_destroy)(struct pipe_transfer *); void *(*transfer_map)( struct pipe_screen *, struct pipe_transfer *transfer ); @@ -213,8 +206,7 @@ struct pipe_screen { void (*buffer_unmap)( struct pipe_screen *screen, struct pipe_buffer *buf ); - void (*buffer_destroy)( struct pipe_screen *screen, - struct pipe_buffer *buf ); + void (*buffer_destroy)( struct pipe_buffer *buf ); /** diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h index a2e839da5c..57a7672d6c 100644 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@ -43,6 +43,8 @@ #include "p_compiler.h" #include "p_defines.h" #include "p_format.h" +#include "p_refcnt.h" +#include "p_screen.h" #ifdef __cplusplus @@ -64,23 +66,20 @@ extern "C" { /* fwd decls */ -struct pipe_screen; struct pipe_surface; - /** * The driver will certainly subclass this to include actual memory * management information. */ struct pipe_buffer { + struct pipe_reference reference; + struct pipe_screen *screen; unsigned alignment; unsigned usage; unsigned size; - - /** Reference count */ - unsigned refcount; }; @@ -275,6 +274,7 @@ struct pipe_sampler_state */ struct pipe_surface { + struct pipe_reference reference; enum pipe_format format; /**< PIPE_FORMAT_x */ unsigned status; /**< PIPE_SURFACE_STATUS_x */ unsigned clear_value; /**< XXX may be temporary */ @@ -282,7 +282,6 @@ struct pipe_surface unsigned height; /**< logical height in pixels */ unsigned layout; /**< PIPE_SURFACE_LAYOUT_x */ unsigned offset; /**< offset from start of buffer, in bytes */ - unsigned refcount; unsigned usage; /**< PIPE_BUFFER_USAGE_* */ struct pipe_texture *texture; /**< texture into which this is a view */ @@ -306,7 +305,6 @@ struct pipe_transfer unsigned nblocksx; /**< allocated width in blocks */ unsigned nblocksy; /**< allocated height in blocks */ unsigned stride; /**< stride in bytes between rows of blocks */ - unsigned refcount; unsigned usage; /**< PIPE_TRANSFER_* */ struct pipe_texture *texture; /**< texture to transfer to/from */ @@ -321,6 +319,8 @@ struct pipe_transfer */ struct pipe_texture { + struct pipe_reference reference; + enum pipe_texture_target target; /**< PIPE_TEXTURE_x */ enum pipe_format format; /**< PIPE_FORMAT_x */ @@ -339,10 +339,6 @@ struct pipe_texture unsigned tex_usage; /* PIPE_TEXTURE_USAGE_* */ - /* These are also refcounted: - */ - unsigned refcount; - struct pipe_screen *screen; /**< screen that this texture belongs to */ }; @@ -379,6 +375,35 @@ struct pipe_vertex_element }; +/* Reference counting helper functions */ +static INLINE void +pipe_buffer_reference(struct pipe_buffer **ptr, struct pipe_buffer *buf) +{ + struct pipe_buffer *old_buf = *ptr; + + if (pipe_reference((struct pipe_reference **)ptr, &buf->reference)) + old_buf->screen->buffer_destroy(old_buf); +} + +static INLINE void +pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf) +{ + struct pipe_surface *old_surf = *ptr; + + if (pipe_reference((struct pipe_reference **)ptr, &surf->reference)) + old_surf->texture->screen->tex_surface_destroy(old_surf); +} + +static INLINE void +pipe_texture_reference(struct pipe_texture **ptr, struct pipe_texture *tex) +{ + struct pipe_texture *old_tex = *ptr; + + if (pipe_reference((struct pipe_reference **)ptr, &tex->reference)) + old_tex->screen->texture_destroy(old_tex); +} + + #ifdef __cplusplus } #endif diff --git a/src/gallium/state_trackers/dri2/dri_drawable.c b/src/gallium/state_trackers/dri2/dri_drawable.c index 2f6913ec5c..aa86411190 100644 --- a/src/gallium/state_trackers/dri2/dri_drawable.c +++ b/src/gallium/state_trackers/dri2/dri_drawable.c @@ -86,7 +86,7 @@ dri_surface_from_handle(struct pipe_screen *screen, buf); /* we don't need the buffer from this point on */ - pipe_buffer_reference(screen, &buf, NULL); + pipe_buffer_reference(&buf, NULL); if (!texture) return NULL; diff --git a/src/gallium/state_trackers/egl/egl_surface.c b/src/gallium/state_trackers/egl/egl_surface.c index 7ebc34871c..b8d5f4217f 100644 --- a/src/gallium/state_trackers/egl/egl_surface.c +++ b/src/gallium/state_trackers/egl/egl_surface.c @@ -143,7 +143,7 @@ err_handle: err_surf: pipe_texture_reference(&texture, NULL); err_tex: - pipe_buffer_reference(screen, &buf, NULL); + pipe_buffer_reference(&buf, NULL); err_buf: return; } @@ -173,7 +173,7 @@ drm_takedown_shown_screen(_EGLDriver *drv, struct drm_screen *screen) pipe_surface_reference(&screen->surface, NULL); pipe_texture_reference(&screen->tex, NULL); - pipe_buffer_reference(dev->screen, &screen->buffer, NULL); + pipe_buffer_reference(&screen->buffer, NULL); screen->shown = 0; } @@ -348,7 +348,7 @@ err_fb: err_bo: pipe_surface_reference(&scrn->surface, NULL); pipe_texture_reference(&scrn->tex, NULL); - pipe_buffer_reference(dev->screen, &scrn->buffer, NULL); + pipe_buffer_reference(&scrn->buffer, NULL); return EGL_FALSE; } diff --git a/src/gallium/state_trackers/g3dvl/vl_basic_csc.c b/src/gallium/state_trackers/g3dvl/vl_basic_csc.c index 187a13a560..38cfd5d7f1 100644 --- a/src/gallium/state_trackers/g3dvl/vl_basic_csc.c +++ b/src/gallium/state_trackers/g3dvl/vl_basic_csc.c @@ -237,10 +237,10 @@ static int vlDestroy pipe->delete_fs_state(pipe, basic_csc->fragment_shader); for (i = 0; i < 2; ++i) - pipe_buffer_reference(pipe->screen, &basic_csc->vertex_bufs[i].buffer, NULL); + pipe_buffer_reference(&basic_csc->vertex_bufs[i].buffer, NULL); - pipe_buffer_reference(pipe->screen, &basic_csc->vs_const_buf.buffer, NULL); - pipe_buffer_reference(pipe->screen, &basic_csc->fs_const_buf.buffer, NULL); + pipe_buffer_reference(&basic_csc->vs_const_buf.buffer, NULL); + pipe_buffer_reference(&basic_csc->fs_const_buf.buffer, NULL); FREE(basic_csc); diff --git a/src/gallium/state_trackers/g3dvl/vl_r16snorm_mc_buf.c b/src/gallium/state_trackers/g3dvl/vl_r16snorm_mc_buf.c index 7cd753f736..eb8270ecad 100644 --- a/src/gallium/state_trackers/g3dvl/vl_r16snorm_mc_buf.c +++ b/src/gallium/state_trackers/g3dvl/vl_r16snorm_mc_buf.c @@ -636,7 +636,7 @@ static int vlFlush for (i = 0; i < 3; ++i) { pipe->screen->transfer_unmap(pipe->screen, mc->tex_transfer[i]); - pipe->screen->tex_transfer_release(pipe->screen, &mc->tex_transfer[i]); + pipe->screen->tex_transfer_destroy(mc->tex_transfer[i]); } mc->render_target.cbufs[0] = pipe->screen->get_tex_surface @@ -856,7 +856,7 @@ static int vlDestroy pipe->delete_sampler_state(pipe, mc->samplers.all[i]); for (i = 0; i < 3; ++i) - pipe_buffer_reference(pipe->screen, &mc->vertex_bufs.all[i].buffer, NULL); + pipe_buffer_reference(&mc->vertex_bufs.all[i].buffer, NULL); /* Textures 3 & 4 are not created directly, no need to release them here */ for (i = 0; i < 3; ++i) @@ -873,8 +873,8 @@ static int vlDestroy pipe->delete_fs_state(pipe, mc->b_fs[i]); } - pipe_buffer_reference(pipe->screen, &mc->vs_const_buf.buffer, NULL); - pipe_buffer_reference(pipe->screen, &mc->fs_const_buf.buffer, NULL); + pipe_buffer_reference(&mc->vs_const_buf.buffer, NULL); + pipe_buffer_reference(&mc->fs_const_buf.buffer, NULL); FREE(mc->macroblocks); FREE(mc); diff --git a/src/gallium/state_trackers/python/st_device.c b/src/gallium/state_trackers/python/st_device.c index 20dd8d269d..a2cd25067d 100644 --- a/src/gallium/state_trackers/python/st_device.c +++ b/src/gallium/state_trackers/python/st_device.c @@ -51,11 +51,20 @@ st_device_really_destroy(struct st_device *st_dev) } +static void +st_device_reference(struct st_device **ptr, struct st_device *st_dev) +{ + struct st_device *old_dev = *ptr; + + if (pipe_reference((struct pipe_reference **)ptr, &st_dev->reference)) + st_device_really_destroy(old_dev); +} + + void st_device_destroy(struct st_device *st_dev) { - if(!--st_dev->refcount) - st_device_really_destroy(st_dev); + st_device_reference(&st_dev, NULL); } @@ -72,7 +81,7 @@ st_device_create_from_st_winsys(const struct st_winsys *st_ws) if(!st_dev) return NULL; - st_dev->refcount = 1; + pipe_reference_init(&st_dev->reference, 1); st_dev->st_ws = st_ws; st_dev->real_screen = st_ws->screen_create(); @@ -124,8 +133,7 @@ st_context_destroy(struct st_context *st_ctx) FREE(st_ctx); - if(!--st_dev->refcount) - st_device_really_destroy(st_dev); + st_device_reference(&st_dev, NULL); } } @@ -139,8 +147,7 @@ st_context_create(struct st_device *st_dev) if(!st_ctx) return NULL; - st_ctx->st_dev = st_dev; - ++st_dev->refcount; + st_device_reference(&st_ctx->st_dev, st_dev); st_ctx->real_pipe = st_dev->st_ws->context_create(st_dev->real_screen); if(!st_ctx->real_pipe) { @@ -292,8 +299,7 @@ void st_buffer_destroy(struct st_buffer *st_buf) { if(st_buf) { - struct pipe_screen *screen = st_buf->st_dev->screen; - pipe_buffer_reference(screen, &st_buf->buffer, NULL); + pipe_buffer_reference(&st_buf->buffer, NULL); FREE(st_buf); } } diff --git a/src/gallium/state_trackers/python/st_device.h b/src/gallium/state_trackers/python/st_device.h index 7cfe6de9f6..0641aff149 100644 --- a/src/gallium/state_trackers/python/st_device.h +++ b/src/gallium/state_trackers/python/st_device.h @@ -68,13 +68,13 @@ struct st_context { struct st_device { + /* FIXME: we also need to refcount for textures and surfaces... */ + struct pipe_reference reference; + const struct st_winsys *st_ws; struct pipe_screen *real_screen; struct pipe_screen *screen; - - /* FIXME: we also need to refcount for textures and surfaces... */ - unsigned refcount; }; diff --git a/src/gallium/state_trackers/python/st_softpipe_winsys.c b/src/gallium/state_trackers/python/st_softpipe_winsys.c index 4d798df99b..426f347d18 100644 --- a/src/gallium/state_trackers/python/st_softpipe_winsys.c +++ b/src/gallium/state_trackers/python/st_softpipe_winsys.c @@ -124,7 +124,7 @@ st_softpipe_buffer_create(struct pipe_winsys *winsys, { struct st_softpipe_buffer *buffer = CALLOC_STRUCT(st_softpipe_buffer); - buffer->base.refcount = 1; + pipe_reference_init(&buffer->base.reference, 1); buffer->base.alignment = alignment; buffer->base.usage = usage; buffer->base.size = size; @@ -149,7 +149,7 @@ st_softpipe_user_buffer_create(struct pipe_winsys *winsys, if(!buffer) return NULL; - buffer->base.refcount = 1; + pipe_reference_init(&buffer->base.reference, 1); buffer->base.size = bytes; buffer->userBuffer = TRUE; buffer->data = ptr; diff --git a/src/gallium/state_trackers/xorg/xorg_crtc.c b/src/gallium/state_trackers/xorg/xorg_crtc.c index 0bd69c214f..7304113a65 100644 --- a/src/gallium/state_trackers/xorg/xorg_crtc.c +++ b/src/gallium/state_trackers/xorg/xorg_crtc.c @@ -175,7 +175,7 @@ crtc_destroy(xf86CrtcPtr crtc) struct crtc_private *crtcp = crtc->driver_private; if (crtcp->cursor_buf) - pipe_buffer_reference(ms->screen, &crtcp->cursor_buf, NULL); + pipe_buffer_reference(&crtcp->cursor_buf, NULL); drmModeFreeCrtc(crtcp->drm_crtc); xfree(crtcp); @@ -266,7 +266,7 @@ cursor_destroy(xf86CrtcPtr crtc) struct crtc_private *crtcp = crtc->driver_private; if (crtcp->cursor_buf) { - pipe_buffer_reference(ms->screen, &crtcp->cursor_buf, NULL); + pipe_buffer_reference(&crtcp->cursor_buf, NULL); } } diff --git a/src/gallium/state_trackers/xorg/xorg_dri2.c b/src/gallium/state_trackers/xorg/xorg_dri2.c index d48b7dd27b..b9993b1ea1 100644 --- a/src/gallium/state_trackers/xorg/xorg_dri2.c +++ b/src/gallium/state_trackers/xorg/xorg_dri2.c @@ -147,7 +147,7 @@ driDestroyBuffers(DrawablePtr pDraw, DRI2BufferPtr buffers, int count) (*pScreen->DestroyPixmap)(private->pPixmap); pipe_texture_reference(&private->tex, NULL); - pipe_buffer_reference(ms->screen, &private->buf, NULL); + pipe_buffer_reference(&private->buf, NULL); } if (buffers) { diff --git a/src/gallium/state_trackers/xorg/xorg_exa.c b/src/gallium/state_trackers/xorg/xorg_exa.c index c62625c448..e53b46c3ad 100644 --- a/src/gallium/state_trackers/xorg/xorg_exa.c +++ b/src/gallium/state_trackers/xorg/xorg_exa.c @@ -147,7 +147,7 @@ ExaFinishAccess(PixmapPtr pPix, int index) return; exa->scrn->transfer_unmap(exa->scrn, priv->map_transfer); - pipe_transfer_reference(&priv->map_transfer, NULL); + exa->scrn->tex_transfer_destroy(priv->map_transfer); } @@ -163,7 +163,7 @@ ExaDone(PixmapPtr pPixmap) return; if (priv->src_surf) - exa->scrn->tex_surface_release(exa->scrn, &priv->src_surf); + exa->scrn->tex_surface_destroy(priv->src_surf); priv->src_surf = NULL; } @@ -219,7 +219,7 @@ ExaSolid(PixmapPtr pPixmap, int x0, int y0, int x1, int y1) exa->ctx->surface_fill(exa->ctx, surf, x0, y0, x1 - x0, y1 - y0, priv->color); - exa->scrn->tex_surface_release(exa->scrn, &surf); + exa->scrn->tex_surface_destroy(surf); } static Bool @@ -276,7 +276,7 @@ ExaCopy(PixmapPtr pDstPixmap, int srcX, int srcY, int dstX, int dstY, exa->ctx->surface_copy(exa->ctx, 0, surf, dstX, dstY, priv->src_surf, srcX, srcY, width, height); - exa->scrn->tex_surface_release(exa->scrn, &surf); + exa->scrn->tex_surface_destroy(surf); } static Bool @@ -336,7 +336,7 @@ ExaDestroyPixmap(ScreenPtr pScreen, void *dPriv) return; if (priv->tex) - ms->screen->texture_release(exa->scrn, &priv->tex); + ms->screen->texture_destroy(priv->tex); xfree(priv); } @@ -382,7 +382,7 @@ xorg_exa_get_pixmap_handle(PixmapPtr pPixmap) drm_api_hooks.buffer_from_texture(priv->tex, &buffer, &stride); drm_api_hooks.handle_from_buffer(ms->screen, buffer, &handle); - pipe_buffer_reference(ms->screen, &buffer, NULL); + pipe_buffer_reference(&buffer, NULL); return handle; } diff --git a/src/gallium/winsys/drm/intel/gem/intel_be_batchbuffer.c b/src/gallium/winsys/drm/intel/gem/intel_be_batchbuffer.c index 0137433785..d5e63c3bae 100644 --- a/src/gallium/winsys/drm/intel/gem/intel_be_batchbuffer.c +++ b/src/gallium/winsys/drm/intel/gem/intel_be_batchbuffer.c @@ -114,10 +114,10 @@ intel_be_batchbuffer_flush(struct intel_be_batchbuffer *batch, if (fence) { if (*fence) - intel_be_fence_unreference(*fence); + intel_be_fence_reference(fence, NULL); (*fence) = CALLOC_STRUCT(intel_be_fence); - (*fence)->refcount = 1; + pipe_reference_init(&(*fence)->reference, 1); (*fence)->bo = NULL; } } diff --git a/src/gallium/winsys/drm/intel/gem/intel_be_device.c b/src/gallium/winsys/drm/intel/gem/intel_be_device.c index 2e191a6d12..de13fb39c7 100644 --- a/src/gallium/winsys/drm/intel/gem/intel_be_device.c +++ b/src/gallium/winsys/drm/intel/gem/intel_be_device.c @@ -51,8 +51,7 @@ intel_be_buffer_unmap(struct pipe_winsys *winsys, } static void -intel_be_buffer_destroy(struct pipe_winsys *winsys, - struct pipe_buffer *buf) +intel_be_buffer_destroy(struct pipe_buffer *buf) { drm_intel_bo_unreference(intel_bo(buf)); free(buf); @@ -72,7 +71,7 @@ intel_be_buffer_create(struct pipe_winsys *winsys, if (!buffer) return NULL; - buffer->base.refcount = 1; + pipe_reference_init(&buffer->base.reference, 1); buffer->base.alignment = alignment; buffer->base.usage = usage; buffer->base.size = size; @@ -115,7 +114,7 @@ intel_be_user_buffer_create(struct pipe_winsys *winsys, void *ptr, unsigned byte if (!buffer) return NULL; - buffer->base.refcount = 1; + pipe_reference_init(&buffer->base.reference, 1); buffer->base.alignment = 0; buffer->base.usage = 0; buffer->base.size = bytes; @@ -155,7 +154,7 @@ intel_be_buffer_from_handle(struct pipe_screen *screen, if (!buffer->bo) goto err; - buffer->base.refcount = 1; + pipe_reference_init(&buffer->base.reference, 1); buffer->base.alignment = buffer->bo->align; buffer->base.usage = PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE | @@ -215,15 +214,7 @@ intel_be_fence_refunref(struct pipe_winsys *sws, struct intel_be_fence **p = (struct intel_be_fence **)ptr; struct intel_be_fence *f = (struct intel_be_fence *)fence; - assert(p); - - if (f) - intel_be_fence_reference(f); - - if (*p) - intel_be_fence_unreference(*p); - - *p = f; + intel_be_fence_reference(p, f); } static int diff --git a/src/gallium/winsys/drm/intel/gem/intel_be_fence.h b/src/gallium/winsys/drm/intel/gem/intel_be_fence.h index 0fe18f66f8..a8abb01a9e 100644 --- a/src/gallium/winsys/drm/intel/gem/intel_be_fence.h +++ b/src/gallium/winsys/drm/intel/gem/intel_be_fence.h @@ -15,23 +15,19 @@ */ struct intel_be_fence { - uint32_t refcount; + struct pipe_reference reference; drm_intel_bo *bo; }; static INLINE void -intel_be_fence_reference(struct intel_be_fence *f) +intel_be_fence_reference(struct intel_be_fence **ptr, struct intel_be_fence *f) { - f->refcount++; -} + struct intel_be_fence *old_fence = *ptr; -static INLINE void -intel_be_fence_unreference(struct intel_be_fence *f) -{ - if (!--f->refcount) { - if (f->bo) - drm_intel_bo_unreference(f->bo); - free(f); + if (pipe_reference((struct pipe_reference**)ptr, &f->reference)) { + if (old_fence->bo) + drm_intel_bo_unreference(old_fence->bo); + free(old_fence); } } diff --git a/src/gallium/winsys/drm/nouveau/common/nouveau_context.c b/src/gallium/winsys/drm/nouveau/common/nouveau_context.c index d6ae0827cd..25c98456ac 100644 --- a/src/gallium/winsys/drm/nouveau/common/nouveau_context.c +++ b/src/gallium/winsys/drm/nouveau/common/nouveau_context.c @@ -109,8 +109,7 @@ nouveau_context_init(struct nouveau_screen *nv_screen, nv_screen->nvc = nvc; } - nvc->refcount++; - nv->nvc = nvc; + pipe_reference((struct pipe_reference**)&nv->nvc, &nvc->reference); /* Find a free slot for a pipe context, allocate a new one if needed */ nv->pctx_id = -1; @@ -159,7 +158,7 @@ nouveau_context_init(struct nouveau_screen *nv_screen, enum pipe_format format; fb_buf = calloc(1, sizeof(struct nouveau_pipe_buffer)); - fb_buf->base.refcount = 1; + pipe_reference_init(&fb_buf->base.reference, 1); fb_buf->base.usage = PIPE_BUFFER_USAGE_PIXEL; nouveau_bo_fake(dev, nv_screen->front_offset, NOUVEAU_BO_VRAM, @@ -195,7 +194,7 @@ nouveau_context_cleanup(struct nouveau_context *nv) if (nv->pctx_id >= 0) { nvc->pctx[nv->pctx_id] = NULL; - if (--nvc->refcount <= 0) { + if (pipe_reference((struct pipe_reference**)&nv->nvc, NULL)) { nouveau_channel_context_destroy(nvc); nv->nv_screen->nvc = NULL; } diff --git a/src/gallium/winsys/drm/nouveau/common/nouveau_context.h b/src/gallium/winsys/drm/nouveau/common/nouveau_context.h index 02d2745680..ba8fc3ad2d 100644 --- a/src/gallium/winsys/drm/nouveau/common/nouveau_context.h +++ b/src/gallium/winsys/drm/nouveau/common/nouveau_context.h @@ -13,8 +13,8 @@ #include "nouveau_local.h" struct nouveau_channel_context { + struct pipe_reference reference; struct pipe_screen *pscreen; - int refcount; unsigned cur_pctx; unsigned nr_pctx; diff --git a/src/gallium/winsys/drm/nouveau/common/nouveau_winsys_pipe.c b/src/gallium/winsys/drm/nouveau/common/nouveau_winsys_pipe.c index 54c7dd46b1..24bbd4516f 100644 --- a/src/gallium/winsys/drm/nouveau/common/nouveau_winsys_pipe.c +++ b/src/gallium/winsys/drm/nouveau/common/nouveau_winsys_pipe.c @@ -67,7 +67,7 @@ nouveau_pipe_bo_create(struct pipe_winsys *pws, unsigned alignment, nvbuf = CALLOC_STRUCT(nouveau_pipe_buffer); if (!nvbuf) return NULL; - nvbuf->base.refcount = 1; + pipe_reference_init(&nvbuf->base.reference, 1); nvbuf->base.alignment = alignment; nvbuf->base.usage = usage; nvbuf->base.size = size; @@ -92,7 +92,7 @@ nouveau_pipe_bo_user_create(struct pipe_winsys *pws, void *ptr, unsigned bytes) nvbuf = CALLOC_STRUCT(nouveau_pipe_buffer); if (!nvbuf) return NULL; - nvbuf->base.refcount = 1; + pipe_reference_init(&nvbuf->base.reference, 1); nvbuf->base.size = bytes; if (nouveau_bo_user(dev, ptr, bytes, &nvbuf->bo)) { @@ -104,7 +104,7 @@ nouveau_pipe_bo_user_create(struct pipe_winsys *pws, void *ptr, unsigned bytes) } static void -nouveau_pipe_bo_del(struct pipe_winsys *ws, struct pipe_buffer *buf) +nouveau_pipe_bo_del(struct pipe_buffer *buf) { struct nouveau_pipe_buffer *nvbuf = nouveau_pipe_buffer(buf); diff --git a/src/gallium/winsys/drm/radeon/radeon_buffer.c b/src/gallium/winsys/drm/radeon/radeon_buffer.c index 79b8f777ca..b3582e3314 100644 --- a/src/gallium/winsys/drm/radeon/radeon_buffer.c +++ b/src/gallium/winsys/drm/radeon/radeon_buffer.c @@ -63,7 +63,7 @@ static struct pipe_buffer *radeon_buffer_create(struct pipe_winsys *ws, return NULL; } - radeon_buffer->base.refcount = 1; + pipe_reference_init(&radeon_buffer->base.reference, 1); radeon_buffer->base.alignment = alignment; radeon_buffer->base.usage = usage; radeon_buffer->base.size = size; @@ -104,7 +104,7 @@ static struct pipe_buffer *radeon_buffer_user_create(struct pipe_winsys *ws, return &radeon_buffer->base; } -static void radeon_buffer_del(struct pipe_winsys *ws, struct pipe_buffer *buffer) +static void radeon_buffer_del(struct pipe_buffer *buffer) { struct radeon_pipe_buffer *radeon_buffer = (struct radeon_pipe_buffer*)buffer; @@ -207,7 +207,7 @@ static struct pipe_buffer *radeon_buffer_from_handle(struct radeon_screen *radeo radeon_bo_unref(bo); return NULL; } - radeon_buffer->base.refcount = 1; + pipe_reference_init(&radeon_buffer->base.reference, 1); radeon_buffer->base.usage = PIPE_BUFFER_USAGE_PIXEL; radeon_buffer->bo = bo; return &radeon_buffer->base; @@ -242,10 +242,10 @@ struct pipe_surface *radeon_surface_from_handle(struct radeon_context *radeon_co pt = pipe_screen->texture_blanket(pipe_screen, &tmpl, &pitch, pb); if (pt == NULL) { - pipe_buffer_reference(pipe_screen, &pb, NULL); + pipe_buffer_reference(&pb, NULL); } ps = pipe_screen->get_tex_surface(pipe_screen, pt, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); return ps; } -#endif \ No newline at end of file +#endif diff --git a/src/gallium/winsys/drm/radeon/radeon_drm.c b/src/gallium/winsys/drm/radeon/radeon_drm.c index 21f2a62e0f..016634c8fd 100644 --- a/src/gallium/winsys/drm/radeon/radeon_drm.c +++ b/src/gallium/winsys/drm/radeon/radeon_drm.c @@ -84,7 +84,8 @@ struct pipe_buffer* radeon_buffer_from_handle(struct pipe_screen* screen, return NULL; } - radeon_buffer->base.refcount = 1; + pipe_reference_init(&radeon_buffer->base.reference, 1); + radeon_buffer->base.screen = screen; radeon_buffer->base.usage = PIPE_BUFFER_USAGE_PIXEL; radeon_buffer->bo = bo; return &radeon_buffer->base; diff --git a/src/gallium/winsys/egl_xlib/sw_winsys.c b/src/gallium/winsys/egl_xlib/sw_winsys.c index 739bfa1c1a..aa1bfa8e88 100644 --- a/src/gallium/winsys/egl_xlib/sw_winsys.c +++ b/src/gallium/winsys/egl_xlib/sw_winsys.c @@ -99,7 +99,7 @@ buffer_create(struct pipe_winsys *pws, if (!buffer) return NULL; - buffer->Base.refcount = 1; + pipe_reference_init(&buffer->Base.reference, 1); buffer->Base.alignment = alignment; buffer->Base.usage = usage; buffer->Base.size = size; @@ -121,7 +121,7 @@ user_buffer_create(struct pipe_winsys *pws, void *ptr, unsigned bytes) if (!buffer) return NULL; - buffer->Base.refcount = 1; + pipe_reference_init(&buffer->Base.reference, 1); buffer->Base.size = bytes; buffer->UserBuffer = TRUE; buffer->Data = ptr; @@ -148,7 +148,7 @@ buffer_unmap(struct pipe_winsys *pws, struct pipe_buffer *buf) static void -buffer_destroy(struct pipe_winsys *pws, struct pipe_buffer *buf) +buffer_destroy(struct pipe_buffer *buf) { struct sw_pipe_buffer *buffer = sw_pipe_buffer(buf); diff --git a/src/gallium/winsys/g3dvl/xsp_winsys.c b/src/gallium/winsys/g3dvl/xsp_winsys.c index c4623e82f9..5b9fdb5c1f 100644 --- a/src/gallium/winsys/g3dvl/xsp_winsys.c +++ b/src/gallium/winsys/g3dvl/xsp_winsys.c @@ -39,7 +39,7 @@ static struct pipe_buffer* xsp_buffer_create(struct pipe_winsys *pws, unsigned a assert(pws); buffer = calloc(1, sizeof(struct xsp_buffer)); - buffer->base.refcount = 1; + pipe_reference_init(&buffer->base.reference, 1); buffer->base.alignment = alignment; buffer->base.usage = usage; buffer->base.size = size; @@ -55,7 +55,7 @@ static struct pipe_buffer* xsp_user_buffer_create(struct pipe_winsys *pws, void assert(pws); buffer = calloc(1, sizeof(struct xsp_buffer)); - buffer->base.refcount = 1; + pipe_reference_init(&buffer->base.reference, 1); buffer->base.size = size; buffer->is_user_buffer = TRUE; buffer->data = data; diff --git a/src/gallium/winsys/gdi/gdi_softpipe_winsys.c b/src/gallium/winsys/gdi/gdi_softpipe_winsys.c index 2d961f7087..440666d835 100644 --- a/src/gallium/winsys/gdi/gdi_softpipe_winsys.c +++ b/src/gallium/winsys/gdi/gdi_softpipe_winsys.c @@ -87,8 +87,7 @@ gdi_softpipe_buffer_unmap(struct pipe_winsys *winsys, static void -gdi_softpipe_buffer_destroy(struct pipe_winsys *winsys, - struct pipe_buffer *buf) +gdi_softpipe_buffer_destroy(struct pipe_buffer *buf) { struct gdi_softpipe_buffer *oldBuf = gdi_softpipe_buffer(buf); @@ -118,7 +117,7 @@ gdi_softpipe_buffer_create(struct pipe_winsys *winsys, { struct gdi_softpipe_buffer *buffer = CALLOC_STRUCT(gdi_softpipe_buffer); - buffer->base.refcount = 1; + pipe_reference_init(&buffer->base.reference, 1); buffer->base.alignment = alignment; buffer->base.usage = usage; buffer->base.size = size; @@ -143,7 +142,7 @@ gdi_softpipe_user_buffer_create(struct pipe_winsys *winsys, if(!buffer) return NULL; - buffer->base.refcount = 1; + pipe_reference_init(&buffer->base.reference, 1); buffer->base.size = bytes; buffer->userBuffer = TRUE; buffer->data = ptr; diff --git a/src/gallium/winsys/xlib/xlib_brw_screen.c b/src/gallium/winsys/xlib/xlib_brw_screen.c index 8e1bfab2f5..8329d3bbf7 100644 --- a/src/gallium/winsys/xlib/xlib_brw_screen.c +++ b/src/gallium/winsys/xlib/xlib_brw_screen.c @@ -57,10 +57,10 @@ buffer_from_surface(struct pipe_surface *surface) } struct aub_buffer { + struct pipe_reference reference; char *data; unsigned offset; unsigned size; - unsigned refcount; unsigned map_count; boolean dump_on_unmap; }; @@ -144,8 +144,7 @@ static void aub_buffer_unmap(struct pipe_winsys *winsys, static void -aub_buffer_destroy(struct pipe_winsys *winsys, - struct pipe_buffer *buf) +aub_buffer_destroy(struct pipe_buffer *buf) { free(buf); } @@ -189,7 +188,7 @@ aub_buffer_create(struct pipe_winsys *winsys, struct aub_pipe_winsys *iws = aub_pipe_winsys(winsys); struct aub_buffer *sbo = CALLOC_STRUCT(aub_buffer); - sbo->refcount = 1; + pipe_reference_init(&sbo->reference, 1); /* Could reuse buffers that are not referenced in current * batchbuffer. Can't do that atm, so always reallocate: diff --git a/src/gallium/winsys/xlib/xlib_cell.c b/src/gallium/winsys/xlib/xlib_cell.c index 40bcdfe42a..a5dbdf30f6 100644 --- a/src/gallium/winsys/xlib/xlib_cell.c +++ b/src/gallium/winsys/xlib/xlib_cell.c @@ -243,7 +243,7 @@ xm_buffer_create(struct pipe_winsys *pws, { struct xm_buffer *buffer = CALLOC_STRUCT(xm_buffer); - buffer->base.refcount = 1; + pipe_reference_init(&buffer->base.reference, 1); buffer->base.alignment = alignment; buffer->base.usage = usage; buffer->base.size = size; @@ -267,7 +267,7 @@ static struct pipe_buffer * xm_user_buffer_create(struct pipe_winsys *pws, void *ptr, unsigned bytes) { struct xm_buffer *buffer = CALLOC_STRUCT(xm_buffer); - buffer->base.refcount = 1; + pipe_reference_init(&buffer->base.reference, 1); buffer->base.size = bytes; buffer->userBuffer = TRUE; buffer->data = ptr; diff --git a/src/gallium/winsys/xlib/xlib_softpipe.c b/src/gallium/winsys/xlib/xlib_softpipe.c index 71f12b2b47..762ebd9847 100644 --- a/src/gallium/winsys/xlib/xlib_softpipe.c +++ b/src/gallium/winsys/xlib/xlib_softpipe.c @@ -207,8 +207,7 @@ xm_buffer_unmap(struct pipe_winsys *pws, struct pipe_buffer *buf) } static void -xm_buffer_destroy(struct pipe_winsys *pws, - struct pipe_buffer *buf) +xm_buffer_destroy(struct pipe_buffer *buf) { struct xm_buffer *oldBuf = xm_buffer(buf); @@ -338,7 +337,7 @@ xm_buffer_create(struct pipe_winsys *pws, } #endif - buffer->base.refcount = 1; + pipe_reference_init(&buffer->base.reference, 1); buffer->base.alignment = alignment; buffer->base.usage = usage; buffer->base.size = size; @@ -359,7 +358,7 @@ static struct pipe_buffer * xm_user_buffer_create(struct pipe_winsys *pws, void *ptr, unsigned bytes) { struct xm_buffer *buffer = CALLOC_STRUCT(xm_buffer); - buffer->base.refcount = 1; + pipe_reference_init(&buffer->base.reference, 1); buffer->base.size = bytes; buffer->userBuffer = TRUE; buffer->data = ptr; diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c index 2df6fef210..fd81ac36d2 100644 --- a/src/mesa/state_tracker/st_atom_constbuf.c +++ b/src/mesa/state_tracker/st_atom_constbuf.c @@ -73,7 +73,7 @@ void st_upload_constants( struct st_context *st, /* We always need to get a new buffer, to keep the drivers simple and * avoid gratuitous rendering synchronization. */ - pipe_buffer_reference(pipe->screen, &cbuf->buffer, NULL ); + pipe_buffer_reference(&cbuf->buffer, NULL ); cbuf->buffer = pipe_buffer_create(pipe->screen, 16, PIPE_BUFFER_USAGE_CONSTANT, paramBytes ); diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index 05b69c9d00..347f2b60c3 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -171,7 +171,7 @@ load_color_map_texture(GLcontext *ctx, struct pipe_texture *pt) } screen->transfer_unmap(screen, transfer); - screen->tex_transfer_release(screen, &transfer); + screen->tex_transfer_destroy(transfer); } diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c index 15cc4cd95d..3f9a825a15 100644 --- a/src/mesa/state_tracker/st_cb_accum.c +++ b/src/mesa/state_tracker/st_cb_accum.c @@ -149,7 +149,7 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) } screen->transfer_unmap(screen, acc_pt); - screen->tex_transfer_release(screen, &acc_pt); + screen->tex_transfer_destroy(acc_pt); } @@ -187,7 +187,7 @@ accum_mad(GLcontext *ctx, GLfloat scale, GLfloat bias, } screen->transfer_unmap(screen, acc_pt); - screen->tex_transfer_release(screen, &acc_pt); + screen->tex_transfer_destroy(acc_pt); } @@ -220,7 +220,7 @@ accum_accum(struct pipe_context *pipe, GLfloat value, accBuf[i] = accBuf[i] + colorBuf[i] * value; } - screen->tex_transfer_release(screen, &acc_trans); + screen->tex_transfer_destroy(acc_trans); acc_trans = screen->get_tex_transfer(screen, acc_strb->texture, 0, 0, 0, PIPE_TRANSFER_WRITE, xpos, ypos, width, height); @@ -229,8 +229,8 @@ accum_accum(struct pipe_context *pipe, GLfloat value, _mesa_free(colorBuf); _mesa_free(accBuf); - screen->tex_transfer_release(screen, &acc_trans); - screen->tex_transfer_release(screen, &color_trans); + screen->tex_transfer_destroy(acc_trans); + screen->tex_transfer_destroy(color_trans); } @@ -264,8 +264,8 @@ accum_load(struct pipe_context *pipe, GLfloat value, acc_put_tile_rgba(pipe, acc_trans, 0, 0, width, height, buf); _mesa_free(buf); - screen->tex_transfer_release(screen, &acc_trans); - screen->tex_transfer_release(screen, &color_trans); + screen->tex_transfer_destroy(acc_trans); + screen->tex_transfer_destroy(color_trans); } @@ -316,8 +316,8 @@ accum_return(GLcontext *ctx, GLfloat value, _mesa_free(abuf); if (cbuf) _mesa_free(cbuf); - screen->tex_transfer_release(screen, &acc_trans); - screen->tex_transfer_release(screen, &color_trans); + screen->tex_transfer_destroy(acc_trans); + screen->tex_transfer_destroy(color_trans); } diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index f55a5e713f..f77ac14762 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -351,7 +351,7 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, /* Release transfer */ screen->transfer_unmap(screen, transfer); - screen->tex_transfer_release(screen, &transfer); + screen->tex_transfer_destroy(transfer); return pt; } @@ -379,7 +379,7 @@ setup_bitmap_vertex_data(struct st_context *st, GLuint i; if (st->bitmap.vbuf_slot >= max_slots) { - pipe_buffer_reference(pipe->screen, &st->bitmap.vbuf, NULL); + pipe_buffer_reference(&st->bitmap.vbuf, NULL); st->bitmap.vbuf_slot = 0; } @@ -571,7 +571,7 @@ reset_cache(struct st_context *st) cache->ymax = -1000000; if (cache->trans) - screen->tex_transfer_release(screen, &cache->trans); + screen->tex_transfer_destroy(cache->trans); assert(!cache->texture); @@ -623,7 +623,7 @@ st_flush_bitmap_cache(struct st_context *st) screen->transfer_unmap(screen, cache->trans); cache->buffer = NULL; - screen->tex_transfer_release(screen, &cache->trans); + screen->tex_transfer_destroy(cache->trans); draw_bitmap_quad(st->ctx, cache->xpos, @@ -651,7 +651,7 @@ st_flush_bitmap( struct st_context *st ) /* Release vertex buffer to avoid synchronous rendering if we were * to map it in the next frame. */ - pipe_buffer_reference(st->pipe->screen, &st->bitmap.vbuf, NULL); + pipe_buffer_reference(&st->bitmap.vbuf, NULL); st->bitmap.vbuf_slot = 0; } @@ -819,7 +819,7 @@ st_destroy_bitmap(struct st_context *st) struct bitmap_cache *cache = st->bitmap.cache; screen->transfer_unmap(screen, cache->trans); - screen->tex_transfer_release(screen, &cache->trans); + screen->tex_transfer_destroy(cache->trans); if (st->bitmap.vs) { cso_delete_vertex_shader(st->cso_context, st->bitmap.vs); @@ -828,12 +828,12 @@ st_destroy_bitmap(struct st_context *st) util_free_shader(&st->bitmap.vert_shader); if (st->bitmap.vbuf) { - pipe_buffer_reference(pipe->screen, &st->bitmap.vbuf, NULL); + pipe_buffer_reference(&st->bitmap.vbuf, NULL); st->bitmap.vbuf = NULL; } if (st->bitmap.cache) { - pipe_texture_release(&st->bitmap.cache->texture); + pipe_texture_reference(&st->bitmap.cache->texture, NULL); _mesa_free(st->bitmap.cache); st->bitmap.cache = NULL; } diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c index 28e387c399..52099232ad 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -74,11 +74,10 @@ st_bufferobj_alloc(GLcontext *ctx, GLuint name, GLenum target) 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_reference(pipe->screen, &st_obj->buffer, NULL); + pipe_buffer_reference(&st_obj->buffer, NULL); _mesa_free(st_obj); } @@ -165,7 +164,7 @@ st_bufferobj_data(GLcontext *ctx, buffer_usage = 0; } - pipe_buffer_reference( pipe->screen, &st_obj->buffer, NULL ); + pipe_buffer_reference( &st_obj->buffer, NULL ); st_obj->buffer = pipe_buffer_create( pipe->screen, 32, buffer_usage, size ); diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index c6fc7cec27..7d4948a64e 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -95,8 +95,6 @@ st_init_clear(struct st_context *st) void st_destroy_clear(struct st_context *st) { - struct pipe_context *pipe = st->pipe; - if (st->clear.vert_shader.tokens) { util_free_shader(&st->clear.vert_shader); st->clear.vert_shader.tokens = NULL; @@ -116,7 +114,7 @@ st_destroy_clear(struct st_context *st) st->clear.vs = NULL; } if (st->clear.vbuf) { - pipe_buffer_reference(pipe->screen, &st->clear.vbuf, NULL); + pipe_buffer_reference(&st->clear.vbuf, NULL); st->clear.vbuf = NULL; } } @@ -152,7 +150,7 @@ draw_quad(GLcontext *ctx, GLuint i; if (st->clear.vbuf_slot >= max_slots) { - pipe_buffer_reference(pipe->screen, &st->clear.vbuf, NULL); + pipe_buffer_reference(&st->clear.vbuf, NULL); st->clear.vbuf_slot = 0; } @@ -524,7 +522,7 @@ void st_flush_clear( struct st_context *st ) /* Release vertex buffer to avoid synchronous rendering if we were * to map it in the next frame. */ - pipe_buffer_reference(st->pipe->screen, &st->clear.vbuf, NULL); + pipe_buffer_reference(&st->clear.vbuf, NULL); st->clear.vbuf_slot = 0; } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index cc7a9e7890..0a09e7e6f1 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -392,7 +392,7 @@ make_texture(struct st_context *st, /* unmap */ screen->transfer_unmap(screen, transfer); - screen->tex_transfer_release(screen, &transfer); + screen->tex_transfer_destroy(transfer); assert(success); @@ -495,7 +495,7 @@ draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z, PIPE_PRIM_QUADS, 4, /* verts */ 3); /* attribs/vert */ - pipe_buffer_reference(pipe->screen, &buf, NULL); + pipe_buffer_reference(&buf, NULL); } } @@ -808,7 +808,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, /* unmap the stencil buffer */ screen->transfer_unmap(screen, pt); - screen->tex_transfer_release(screen, &pt); + screen->tex_transfer_destroy(pt); } @@ -951,7 +951,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, /* unmap the stencil buffer */ screen->transfer_unmap(screen, ptDraw); - screen->tex_transfer_release(screen, &ptDraw); + screen->tex_transfer_destroy(ptDraw); } @@ -1070,8 +1070,8 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, _mesa_free(buf); } - screen->tex_transfer_release(screen, &ptRead); - screen->tex_transfer_release(screen, &ptTex); + screen->tex_transfer_destroy(ptRead); + screen->tex_transfer_destroy(ptTex); } /* draw textured quad */ diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 4e669f113b..121ca8c29a 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -413,7 +413,6 @@ static void st_finish_render_texture(GLcontext *ctx, struct gl_renderbuffer_attachment *att) { - struct pipe_screen *screen = ctx->st->pipe->screen; struct st_renderbuffer *strb = st_renderbuffer(att->Renderbuffer); if (!strb) @@ -422,7 +421,7 @@ st_finish_render_texture(GLcontext *ctx, st_flush( ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL ); if (strb->surface) - screen->tex_surface_release( screen, &strb->surface ); + pipe_surface_reference( &strb->surface, NULL ); strb->rtt = NULL; diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index 5a4a7f0a61..2a4beccd90 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -134,7 +134,7 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, /* unmap the stencil buffer */ screen->transfer_unmap(screen, pt); - screen->tex_transfer_release(screen, &pt); + screen->tex_transfer_destroy(pt); } @@ -224,7 +224,7 @@ st_fast_readpixels(GLcontext *ctx, struct st_renderbuffer *strb, map = screen->transfer_map(screen, trans); if (!map) { - screen->tex_transfer_release(screen, &trans); + screen->tex_transfer_destroy(trans); return GL_FALSE; } @@ -282,7 +282,7 @@ st_fast_readpixels(GLcontext *ctx, struct st_renderbuffer *strb, } screen->transfer_unmap(screen, trans); - screen->tex_transfer_release(screen, &trans); + screen->tex_transfer_destroy(trans); } return GL_TRUE; @@ -466,7 +466,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, } } - screen->tex_transfer_release(screen, &trans); + screen->tex_transfer_destroy(trans); _mesa_unmap_readpix_pbo(ctx, &clippedPacking); } diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 3039eb2a87..a504454145 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -938,12 +938,12 @@ fallback_copy_texsubimage(GLcontext *ctx, srcY = strb->Base.Height - srcY - height; } - src_trans = pipe->screen->get_tex_transfer( pipe->screen, - strb->texture, - 0, 0, 0, - PIPE_TRANSFER_READ, - srcX, srcY, - width, height); + src_trans = screen->get_tex_transfer( screen, + strb->texture, + 0, 0, 0, + PIPE_TRANSFER_READ, + srcX, srcY, + width, height); texDest = st_texture_image_map(ctx->st, stImage, 0, PIPE_TRANSFER_WRITE, destX, destY, width, height); @@ -1020,7 +1020,7 @@ fallback_copy_texsubimage(GLcontext *ctx, } st_texture_image_unmap(ctx->st, stImage); - screen->tex_transfer_release(screen, &src_trans); + screen->tex_transfer_destroy(src_trans); } @@ -1413,7 +1413,7 @@ st_finalize_texture(GLcontext *ctx, stObj->pt->depth[0] != firstImage->base.Depth2 || stObj->pt->block.size/stObj->pt->block.width != cpp || /* Nominal bytes per pixel */ stObj->pt->compressed != firstImage->base.IsCompressed) { - pipe_texture_release(&stObj->pt); + pipe_texture_reference(&stObj->pt, NULL); ctx->st->dirty.st |= ST_NEW_FRAMEBUFFER; } } diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 78a7956c90..f31be69023 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -209,7 +209,7 @@ static void st_destroy_context_priv( struct st_context *st ) for (i = 0; i < Elements(st->state.constants); i++) { if (st->state.constants[i].buffer) { - pipe_buffer_reference(st->pipe->screen, &st->state.constants[i].buffer, NULL); + pipe_buffer_reference(&st->state.constants[i].buffer, NULL); } } diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index b52e488612..be1d9a8628 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -378,7 +378,7 @@ setup_interleaved_attribs(GLcontext *ctx, } else { vbuffer->buffer = NULL; - pipe_buffer_reference(pipe->screen, &vbuffer->buffer, stobj->buffer); + pipe_buffer_reference(&vbuffer->buffer, stobj->buffer); vbuffer->buffer_offset = (unsigned) low; } vbuffer->stride = stride; /* in bytes */ @@ -433,7 +433,7 @@ setup_non_interleaved_attribs(GLcontext *ctx, /*printf("stobj %u = %p\n", attr, (void*) stobj);*/ vbuffer[attr].buffer = NULL; - pipe_buffer_reference(pipe->screen, &vbuffer[attr].buffer, stobj->buffer); + pipe_buffer_reference(&vbuffer[attr].buffer, stobj->buffer); vbuffer[attr].buffer_offset = (unsigned) arrays[mesaAttr]->Ptr; velements[attr].src_offset = 0; } @@ -617,7 +617,7 @@ st_draw_vbo(GLcontext *ctx, if (bufobj && bufobj->Name) { /* elements/indexes are in a real VBO */ struct st_buffer_object *stobj = st_buffer_object(bufobj); - pipe_buffer_reference(pipe->screen, &indexBuf, stobj->buffer); + pipe_buffer_reference(&indexBuf, stobj->buffer); indexOffset = (unsigned) ib->ptr / indexSize; } else { @@ -657,7 +657,7 @@ st_draw_vbo(GLcontext *ctx, } } - pipe_buffer_reference(pipe->screen, &indexBuf, NULL); + pipe_buffer_reference(&indexBuf, NULL); } else { /* non-indexed */ @@ -673,7 +673,7 @@ st_draw_vbo(GLcontext *ctx, /* unreference buffers (frees wrapped user-space buffer objects) */ for (attr = 0; attr < num_vbuffers; attr++) { - pipe_buffer_reference(pipe->screen, &vbuffer[attr].buffer, NULL); + pipe_buffer_reference(&vbuffer[attr].buffer, NULL); assert(!vbuffer[attr].buffer); } diff --git a/src/mesa/state_tracker/st_draw_feedback.c b/src/mesa/state_tracker/st_draw_feedback.c index 5c9c4506c2..d63d8cae28 100644 --- a/src/mesa/state_tracker/st_draw_feedback.c +++ b/src/mesa/state_tracker/st_draw_feedback.c @@ -152,7 +152,7 @@ st_feedback_draw_vbo(GLcontext *ctx, assert(stobj->buffer); vbuffers[attr].buffer = NULL; - pipe_buffer_reference(pipe->screen, &vbuffers[attr].buffer, stobj->buffer); + pipe_buffer_reference(&vbuffers[attr].buffer, stobj->buffer); vbuffers[attr].buffer_offset = (unsigned) arrays[0]->Ptr;/* in bytes */ velements[attr].src_offset = arrays[mesaAttr]->Ptr - arrays[0]->Ptr; } @@ -248,7 +248,7 @@ st_feedback_draw_vbo(GLcontext *ctx, for (i = 0; i < PIPE_MAX_ATTRIBS; i++) { if (draw->pt.vertex_buffer[i].buffer) { pipe_buffer_unmap(pipe->screen, draw->pt.vertex_buffer[i].buffer); - pipe_buffer_reference(pipe->screen, &draw->pt.vertex_buffer[i].buffer, NULL); + pipe_buffer_reference(&draw->pt.vertex_buffer[i].buffer, NULL); draw_set_mapped_vertex_buffer(draw, i, NULL); } } diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c index 08e4803068..9cc2176d5e 100644 --- a/src/mesa/state_tracker/st_gen_mipmap.c +++ b/src/mesa/state_tracker/st_gen_mipmap.c @@ -147,8 +147,8 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target, screen->transfer_unmap(screen, srcTrans); screen->transfer_unmap(screen, dstTrans); - screen->tex_transfer_release(screen, &srcTrans); - screen->tex_transfer_release(screen, &dstTrans); + screen->tex_transfer_destroy(srcTrans); + screen->tex_transfer_destroy(dstTrans); } } diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c index fcf76ef82e..79a4bd84d0 100644 --- a/src/mesa/state_tracker/st_texture.c +++ b/src/mesa/state_tracker/st_texture.c @@ -108,7 +108,7 @@ st_texture_create(struct st_context *st, newtex = screen->texture_create(screen, &pt); - assert(!newtex || newtex->refcount == 1); + assert(!newtex || newtex->reference.count == 1); return newtex; } @@ -219,7 +219,7 @@ st_texture_image_unmap(struct st_context *st, screen->transfer_unmap(screen, stImage->transfer); - screen->tex_transfer_release(screen, &stImage->transfer); + screen->tex_transfer_destroy(stImage->transfer); } @@ -284,7 +284,7 @@ st_texture_image_data(struct pipe_context *pipe, 0, 0, /* source x, y */ dst->width[level], dst->height[level]); /* width, height */ - screen->tex_transfer_release(screen, &dst_transfer); + screen->tex_transfer_destroy(dst_transfer); srcUB += src_image_stride; } @@ -350,8 +350,8 @@ st_texture_image_copy(struct pipe_context *pipe, 0, 0, /* srcX, Y */ width, height); - screen->tex_surface_release(screen, &src_surface); - screen->tex_surface_release(screen, &dst_surface); + pipe_surface_reference(&src_surface, NULL); + pipe_surface_reference(&dst_surface, NULL); } } -- cgit v1.2.3 From 45bde75bd67e7e920f0113842d1fa58613ccc3ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michel=20D=C3=A4nzer?= Date: Wed, 4 Mar 2009 11:58:52 +0100 Subject: gallium: Remove some superfluous instances of #include "p_inlines.h". --- src/gallium/auxiliary/cso_cache/cso_context.c | 1 - src/gallium/auxiliary/draw/draw_pipe_aaline.c | 1 - src/gallium/auxiliary/draw/draw_pipe_aapoint.c | 1 - src/gallium/auxiliary/draw/draw_pipe_pstipple.c | 1 - src/gallium/auxiliary/pipebuffer/pb_buffer.h | 1 - src/gallium/auxiliary/sct/sct.c | 1 - src/gallium/auxiliary/util/u_simple_shaders.c | 1 - src/gallium/drivers/failover/fo_state.c | 2 -- src/gallium/drivers/softpipe/sp_context.c | 1 - src/gallium/drivers/softpipe/sp_fs_exec.c | 1 - src/gallium/drivers/softpipe/sp_fs_llvm.c | 1 - src/gallium/drivers/softpipe/sp_fs_sse.c | 1 - src/gallium/drivers/softpipe/sp_query.c | 1 - src/gallium/drivers/softpipe/sp_state_fs.c | 1 - src/gallium/drivers/softpipe/sp_state_sampler.c | 1 - src/gallium/drivers/softpipe/sp_state_surface.c | 1 - src/gallium/drivers/trace/tr_texture.c | 1 - src/gallium/winsys/xlib/xlib_brw_screen.c | 1 - src/mesa/state_tracker/st_atom_pixeltransfer.c | 1 - src/mesa/state_tracker/st_atom_texture.c | 1 - src/mesa/state_tracker/st_cb_fbo.c | 1 - src/mesa/state_tracker/st_context.c | 1 - src/mesa/state_tracker/st_framebuffer.c | 1 - src/mesa/state_tracker/st_texture.c | 1 - 24 files changed, 25 deletions(-) (limited to 'src') diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c index a9157aad71..f388bf5d95 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.c +++ b/src/gallium/auxiliary/cso_cache/cso_context.c @@ -37,7 +37,6 @@ #include "pipe/p_state.h" #include "util/u_memory.h" -#include "pipe/p_inlines.h" #include "tgsi/tgsi_parse.h" #include "cso_cache/cso_context.h" diff --git a/src/gallium/auxiliary/draw/draw_pipe_aaline.c b/src/gallium/auxiliary/draw/draw_pipe_aaline.c index e83a075794..ca69f0b95e 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_aaline.c +++ b/src/gallium/auxiliary/draw/draw_pipe_aaline.c @@ -32,7 +32,6 @@ */ -#include "pipe/p_inlines.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_shader_tokens.h" diff --git a/src/gallium/auxiliary/draw/draw_pipe_aapoint.c b/src/gallium/auxiliary/draw/draw_pipe_aapoint.c index 2c1cacbdb4..5008086cf2 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_aapoint.c +++ b/src/gallium/auxiliary/draw/draw_pipe_aapoint.c @@ -38,7 +38,6 @@ */ -#include "pipe/p_inlines.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_shader_tokens.h" diff --git a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c index fa7bc67476..04e59152c5 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c +++ b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c @@ -34,7 +34,6 @@ */ -#include "pipe/p_inlines.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_shader_tokens.h" diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer.h b/src/gallium/auxiliary/pipebuffer/pb_buffer.h index be1654c654..f3a48d7ab0 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_buffer.h +++ b/src/gallium/auxiliary/pipebuffer/pb_buffer.h @@ -48,7 +48,6 @@ #include "util/u_debug.h" #include "pipe/p_error.h" #include "pipe/p_state.h" -#include "pipe/p_inlines.h" #ifdef __cplusplus diff --git a/src/gallium/auxiliary/sct/sct.c b/src/gallium/auxiliary/sct/sct.c index fcfa04ef7d..722d2b7e66 100644 --- a/src/gallium/auxiliary/sct/sct.c +++ b/src/gallium/auxiliary/sct/sct.c @@ -28,7 +28,6 @@ #include "util/u_memory.h" #include "pipe/p_state.h" -#include "pipe/p_inlines.h" #include "sct.h" diff --git a/src/gallium/auxiliary/util/u_simple_shaders.c b/src/gallium/auxiliary/util/u_simple_shaders.c index 2fcad6fe3d..8da18d6715 100644 --- a/src/gallium/auxiliary/util/u_simple_shaders.c +++ b/src/gallium/auxiliary/util/u_simple_shaders.c @@ -36,7 +36,6 @@ #include "pipe/p_context.h" #include "util/u_debug.h" #include "pipe/p_defines.h" -#include "pipe/p_inlines.h" #include "pipe/p_screen.h" #include "pipe/p_shader_tokens.h" diff --git a/src/gallium/drivers/failover/fo_state.c b/src/gallium/drivers/failover/fo_state.c index 6a79706632..c8eb926299 100644 --- a/src/gallium/drivers/failover/fo_state.c +++ b/src/gallium/drivers/failover/fo_state.c @@ -28,8 +28,6 @@ /* Authors: Keith Whitwell */ -#include "pipe/p_inlines.h" - #include "fo_context.h" diff --git a/src/gallium/drivers/softpipe/sp_context.c b/src/gallium/drivers/softpipe/sp_context.c index cc552c4915..06ace27d14 100644 --- a/src/gallium/drivers/softpipe/sp_context.c +++ b/src/gallium/drivers/softpipe/sp_context.c @@ -32,7 +32,6 @@ #include "draw/draw_context.h" #include "pipe/p_defines.h" -#include "pipe/p_inlines.h" #include "util/u_math.h" #include "util/u_memory.h" #include "sp_clear.h" diff --git a/src/gallium/drivers/softpipe/sp_fs_exec.c b/src/gallium/drivers/softpipe/sp_fs_exec.c index 3c7ba565d6..0c14d92864 100644 --- a/src/gallium/drivers/softpipe/sp_fs_exec.c +++ b/src/gallium/drivers/softpipe/sp_fs_exec.c @@ -35,7 +35,6 @@ #include "pipe/p_state.h" #include "pipe/p_defines.h" #include "util/u_memory.h" -#include "pipe/p_inlines.h" #include "tgsi/tgsi_exec.h" #include "tgsi/tgsi_parse.h" diff --git a/src/gallium/drivers/softpipe/sp_fs_llvm.c b/src/gallium/drivers/softpipe/sp_fs_llvm.c index 34adac5226..f33b3e3285 100644 --- a/src/gallium/drivers/softpipe/sp_fs_llvm.c +++ b/src/gallium/drivers/softpipe/sp_fs_llvm.c @@ -37,7 +37,6 @@ #include "pipe/p_state.h" #include "pipe/p_defines.h" #include "util/u_memory.h" -#include "pipe/p_inlines.h" #include "tgsi/tgsi_sse2.h" #if 0 diff --git a/src/gallium/drivers/softpipe/sp_fs_sse.c b/src/gallium/drivers/softpipe/sp_fs_sse.c index 7e22081132..abd37547a9 100644 --- a/src/gallium/drivers/softpipe/sp_fs_sse.c +++ b/src/gallium/drivers/softpipe/sp_fs_sse.c @@ -35,7 +35,6 @@ #include "pipe/p_state.h" #include "pipe/p_defines.h" #include "util/u_memory.h" -#include "pipe/p_inlines.h" #include "tgsi/tgsi_exec.h" #include "tgsi/tgsi_sse2.h" diff --git a/src/gallium/drivers/softpipe/sp_query.c b/src/gallium/drivers/softpipe/sp_query.c index b0d8e01426..93dab236d6 100644 --- a/src/gallium/drivers/softpipe/sp_query.c +++ b/src/gallium/drivers/softpipe/sp_query.c @@ -31,7 +31,6 @@ #include "draw/draw_context.h" #include "pipe/p_defines.h" -#include "pipe/p_inlines.h" #include "util/u_memory.h" #include "sp_context.h" #include "sp_query.h" diff --git a/src/gallium/drivers/softpipe/sp_state_fs.c b/src/gallium/drivers/softpipe/sp_state_fs.c index 957c8b72e4..b63180baa5 100644 --- a/src/gallium/drivers/softpipe/sp_state_fs.c +++ b/src/gallium/drivers/softpipe/sp_state_fs.c @@ -31,7 +31,6 @@ #include "pipe/p_defines.h" #include "util/u_memory.h" -#include "pipe/p_inlines.h" #include "pipe/internal/p_winsys_screen.h" #include "pipe/p_shader_tokens.h" #include "draw/draw_context.h" diff --git a/src/gallium/drivers/softpipe/sp_state_sampler.c b/src/gallium/drivers/softpipe/sp_state_sampler.c index 99a28c0d7e..cb517b02e4 100644 --- a/src/gallium/drivers/softpipe/sp_state_sampler.c +++ b/src/gallium/drivers/softpipe/sp_state_sampler.c @@ -30,7 +30,6 @@ */ #include "util/u_memory.h" -#include "pipe/p_inlines.h" #include "draw/draw_context.h" diff --git a/src/gallium/drivers/softpipe/sp_state_surface.c b/src/gallium/drivers/softpipe/sp_state_surface.c index 1493c65884..7c06d864a7 100644 --- a/src/gallium/drivers/softpipe/sp_state_surface.c +++ b/src/gallium/drivers/softpipe/sp_state_surface.c @@ -27,7 +27,6 @@ /* Authors: Keith Whitwell */ -#include "pipe/p_inlines.h" #include "sp_context.h" #include "sp_state.h" diff --git a/src/gallium/drivers/trace/tr_texture.c b/src/gallium/drivers/trace/tr_texture.c index dc45d3dcc1..9187de7a18 100644 --- a/src/gallium/drivers/trace/tr_texture.c +++ b/src/gallium/drivers/trace/tr_texture.c @@ -25,7 +25,6 @@ * **************************************************************************/ -#include "pipe/p_inlines.h" #include "util/u_hash_table.h" #include "util/u_memory.h" diff --git a/src/gallium/winsys/xlib/xlib_brw_screen.c b/src/gallium/winsys/xlib/xlib_brw_screen.c index 8329d3bbf7..fe8dfff767 100644 --- a/src/gallium/winsys/xlib/xlib_brw_screen.c +++ b/src/gallium/winsys/xlib/xlib_brw_screen.c @@ -37,7 +37,6 @@ //#include "state_trackers/xlib/xmesaP.h" #include "pipe/internal/p_winsys_screen.h" -#include "pipe/p_inlines.h" #include "util/u_math.h" #include "util/u_memory.h" #include "i965simple/brw_winsys.h" diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index 347f2b60c3..8d0029dde5 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -48,7 +48,6 @@ #include "pipe/p_screen.h" #include "pipe/p_context.h" -#include "pipe/p_inlines.h" #include "util/u_pack_color.h" diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c index 21f7321f97..4d4f97da7e 100644 --- a/src/mesa/state_tracker/st_atom_texture.c +++ b/src/mesa/state_tracker/st_atom_texture.c @@ -37,7 +37,6 @@ #include "st_texture.h" #include "st_cb_texture.h" #include "pipe/p_context.h" -#include "pipe/p_inlines.h" #include "cso_cache/cso_context.h" diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 121ca8c29a..f74d0d46d0 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -41,7 +41,6 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" -#include "pipe/p_inlines.h" #include "pipe/p_screen.h" #include "st_context.h" #include "st_cb_fbo.h" diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index f31be69023..9a17038eaf 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -66,7 +66,6 @@ #include "st_gen_mipmap.h" #include "st_program.h" #include "pipe/p_context.h" -#include "pipe/p_inlines.h" #include "draw/draw_context.h" #include "cso_cache/cso_cache.h" #include "cso_cache/cso_context.h" diff --git a/src/mesa/state_tracker/st_framebuffer.c b/src/mesa/state_tracker/st_framebuffer.c index 0d4474a8b3..d76a1eae09 100644 --- a/src/mesa/state_tracker/st_framebuffer.c +++ b/src/mesa/state_tracker/st_framebuffer.c @@ -38,7 +38,6 @@ #include "st_public.h" #include "pipe/p_defines.h" #include "pipe/p_context.h" -#include "pipe/p_inlines.h" struct st_framebuffer * diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c index 79a4bd84d0..20c34cd80a 100644 --- a/src/mesa/state_tracker/st_texture.c +++ b/src/mesa/state_tracker/st_texture.c @@ -40,7 +40,6 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_inlines.h" -#include "pipe/p_inlines.h" #include "util/u_rect.h" -- cgit v1.2.3 From 945dcbfca62b9b57340caccc1b8286b2f3e743bc Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 4 Mar 2009 07:57:40 -0700 Subject: mesa: include mfeatures.h See bug 20319. --- src/mesa/shader/prog_instruction.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/mesa/shader/prog_instruction.h b/src/mesa/shader/prog_instruction.h index 3808644550..95dd7fda7f 100644 --- a/src/mesa/shader/prog_instruction.h +++ b/src/mesa/shader/prog_instruction.h @@ -38,6 +38,9 @@ #define PROG_INSTRUCTION_H +#include "main/mfeatures.h" + + /** * Swizzle indexes. * Do not change! -- cgit v1.2.3 From f9ce417aaf14c00e72e92307b910de5dbed1bb6d Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Wed, 4 Mar 2009 15:15:43 +0000 Subject: vbo: use FLUSH_UPDATE_CURRENT flag to indicate whether the vbo module is active Add asserts for expected values on wakeup and flush. Remove cases where this flag is set or cleared except when waking up and flushing vbo module. --- src/mesa/vbo/vbo_exec_api.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/mesa/vbo/vbo_exec_api.c b/src/mesa/vbo/vbo_exec_api.c index c0ffdb55e4..9c2d065913 100644 --- a/src/mesa/vbo/vbo_exec_api.c +++ b/src/mesa/vbo/vbo_exec_api.c @@ -183,8 +183,6 @@ static void vbo_exec_copy_to_current( struct vbo_exec_context *exec ) _mesa_update_color_material(ctx, ctx->Current.Attrib[VBO_ATTRIB_COLOR0]); } - - ctx->Driver.NeedFlush &= ~FLUSH_UPDATE_CURRENT; } @@ -204,8 +202,6 @@ static void vbo_exec_copy_from_current( struct vbo_exec_context *exec ) break; } } - - ctx->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT; } @@ -346,8 +342,6 @@ static void vbo_exec_fixup_vertex( GLcontext *ctx, */ if (attr == 0) exec->ctx->Driver.NeedFlush |= FLUSH_STORED_VERTICES; - else - exec->ctx->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT; } @@ -750,6 +744,9 @@ void vbo_exec_BeginVertices( GLcontext *ctx ) struct vbo_exec_context *exec = &vbo_context(ctx)->exec; if (0) _mesa_printf("%s\n", __FUNCTION__); vbo_exec_vtx_map( exec ); + + assert(exec->ctx->Driver.NeedFlush == 0); + exec->ctx->Driver.NeedFlush = FLUSH_UPDATE_CURRENT; } void vbo_exec_FlushVertices_internal( GLcontext *ctx, GLboolean unmap ) @@ -785,6 +782,7 @@ void vbo_exec_FlushVertices( GLcontext *ctx, GLuint flags ) */ _mesa_restore_exec_vtxfmt( ctx ); + assert(exec->ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT); exec->ctx->Driver.NeedFlush = 0; } -- cgit v1.2.3