From patchwork Sat Dec 14 01:25:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Packard X-Patchwork-Id: 3343961 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C68529F2A9 for ; Sat, 14 Dec 2013 01:26:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BF5DC20263 for ; Sat, 14 Dec 2013 01:26:34 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id AD0A5205EC for ; Sat, 14 Dec 2013 01:26:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E36B2FBC12; Fri, 13 Dec 2013 17:26:16 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from keithp.com (home.keithp.com [63.227.221.253]) by gabe.freedesktop.org (Postfix) with ESMTP id 5C56DFB872; Fri, 13 Dec 2013 17:26:07 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by keithp.com (Postfix) with ESMTP id 0372D1488008; Fri, 13 Dec 2013 17:26:07 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from keithp.com ([127.0.0.1]) by localhost (keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 99Ew9U74K3lG; Fri, 13 Dec 2013 17:26:02 -0800 (PST) Received: by keithp.com (Postfix, from userid 1033) id 463151488016; Fri, 13 Dec 2013 17:25:35 -0800 (PST) Received: from miki.keithp.com (localhost [127.0.0.1]) by keithp.com (Postfix) with ESMTP id 4EA631498016; Fri, 13 Dec 2013 17:25:35 -0800 (PST) Received: by miki.keithp.com (Postfix, from userid 1001) id D2252EB5; Fri, 13 Dec 2013 17:25:31 -0800 (PST) From: Keith Packard To: mesa-dev@lists.freedesktop.org Subject: [PATCH 15/18] gallium: Add __DRIimageDriverExtension support to gallium Date: Fri, 13 Dec 2013 17:25:27 -0800 Message-Id: <1386984330-26074-16-git-send-email-keithp@keithp.com> X-Mailer: git-send-email 1.8.4.4 In-Reply-To: <1386984330-26074-1-git-send-email-keithp@keithp.com> References: <1386984330-26074-1-git-send-email-keithp@keithp.com> Cc: dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Provide the hook to pull textures out of __DRIimage structures and use them as renderbuffers. Signed-off-by: Keith Packard --- src/gallium/state_trackers/dri/drm/dri2.c | 238 +++++++++++++++++++++++++++++- 1 file changed, 230 insertions(+), 8 deletions(-) diff --git a/src/gallium/state_trackers/dri/drm/dri2.c b/src/gallium/state_trackers/dri/drm/dri2.c index 8ff77b3..03b93ae 100644 --- a/src/gallium/state_trackers/dri/drm/dri2.c +++ b/src/gallium/state_trackers/dri/drm/dri2.c @@ -457,6 +457,219 @@ dri2_release_buffer(__DRIscreen *sPriv, __DRIbuffer *bPriv) FREE(buffer); } +static void +dri_image_allocate_textures(struct dri_context *ctx, + struct dri_drawable *drawable, + const enum st_attachment_type *statts, + unsigned statts_count) +{ + __DRIdrawable *dPriv = drawable->dPriv; + __DRIscreen *sPriv = drawable->sPriv; + struct dri_screen *screen = dri_screen(sPriv); + unsigned int image_format = __DRI_IMAGE_FORMAT_NONE; + uint32_t buffer_mask = 0; + struct __DRIimageList images; + boolean alloc_depthstencil = FALSE; + int i, j; + struct pipe_resource templ; + + /* See if we need a depth-stencil buffer. */ + for (i = 0; i < statts_count; i++) { + if (statts[i] == ST_ATTACHMENT_DEPTH_STENCIL) { + alloc_depthstencil = TRUE; + break; + } + } + + /* Delete the resources we won't need. */ + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { + /* Don't delete the depth-stencil buffer, we can reuse it. */ + if (i == ST_ATTACHMENT_DEPTH_STENCIL && alloc_depthstencil) + continue; + + pipe_resource_reference(&drawable->textures[i], NULL); + } + + if (drawable->stvis.samples > 1) { + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { + boolean del = TRUE; + + /* Don't delete MSAA resources for the attachments which are enabled, + * we can reuse them. */ + for (j = 0; j < statts_count; j++) { + if (i == statts[j]) { + del = FALSE; + break; + } + } + + if (del) { + pipe_resource_reference(&drawable->msaa_textures[i], NULL); + } + } + } + + for (i = 0; i < statts_count; i++) { + enum pipe_format pf; + unsigned bind; + + dri_drawable_get_format(drawable, statts[i], &pf, &bind); + if (pf == PIPE_FORMAT_NONE) + continue; + + switch (pf) { + case PIPE_FORMAT_B5G6R5_UNORM: + image_format = __DRI_IMAGE_FORMAT_RGB565; + break; + case PIPE_FORMAT_B8G8R8X8_UNORM: + image_format = __DRI_IMAGE_FORMAT_XRGB8888; + break; + case PIPE_FORMAT_B8G8R8A8_UNORM: + image_format = __DRI_IMAGE_FORMAT_ARGB8888; + break; + case PIPE_FORMAT_R8G8B8A8_UNORM: + image_format = __DRI_IMAGE_FORMAT_ABGR8888; + break; + default: + image_format = __DRI_IMAGE_FORMAT_NONE; + break; + } + + switch (statts[i]) { + case ST_ATTACHMENT_FRONT_LEFT: + buffer_mask |= __DRI_IMAGE_BUFFER_FRONT; + break; + case ST_ATTACHMENT_BACK_LEFT: + buffer_mask |= __DRI_IMAGE_BUFFER_BACK; + break; + default: + continue; + } + } + + (*sPriv->image.loader->getBuffers) (dPriv, + image_format, + &dPriv->dri2.stamp, + dPriv->loaderPrivate, + buffer_mask, + &images); + + if (images.image_mask & __DRI_IMAGE_BUFFER_FRONT) { + struct pipe_resource *texture = images.front->texture; + + dPriv->w = texture->width0; + dPriv->h = texture->height0; + + pipe_resource_reference(&drawable->textures[ST_ATTACHMENT_FRONT_LEFT], texture); + } + + if (images.image_mask & __DRI_IMAGE_BUFFER_BACK) { + struct pipe_resource *texture = images.back->texture; + + dPriv->w = images.back->texture->width0; + dPriv->h = images.back->texture->height0; + + pipe_resource_reference(&drawable->textures[ST_ATTACHMENT_BACK_LEFT], texture); + } + + memset(&templ, 0, sizeof(templ)); + templ.target = screen->target; + templ.last_level = 0; + templ.width0 = dPriv->w; + templ.height0 = dPriv->h; + templ.depth0 = 1; + templ.array_size = 1; + + /* Allocate private MSAA colorbuffers. */ + if (drawable->stvis.samples > 1) { + for (i = 0; i < statts_count; i++) { + enum st_attachment_type att = statts[i]; + + if (att == ST_ATTACHMENT_DEPTH_STENCIL) + continue; + + if (drawable->textures[att]) { + templ.format = drawable->textures[att]->format; + templ.bind = drawable->textures[att]->bind; + templ.nr_samples = drawable->stvis.samples; + + /* Try to reuse the resource. + * (the other resource parameters should be constant) + */ + if (!drawable->msaa_textures[att] || + drawable->msaa_textures[att]->width0 != templ.width0 || + drawable->msaa_textures[att]->height0 != templ.height0) { + /* Allocate a new one. */ + pipe_resource_reference(&drawable->msaa_textures[att], NULL); + + drawable->msaa_textures[att] = + screen->base.screen->resource_create(screen->base.screen, + &templ); + assert(drawable->msaa_textures[att]); + + /* If there are any MSAA resources, we should initialize them + * such that they contain the same data as the single-sample + * resources we just got from the X server. + * + * The reason for this is that the state tracker (and + * therefore the app) can access the MSAA resources only. + * The single-sample resources are not exposed + * to the state tracker. + * + */ + dri_pipe_blit(ctx->st->pipe, + drawable->msaa_textures[att], + drawable->textures[att]); + } + } + else { + pipe_resource_reference(&drawable->msaa_textures[att], NULL); + } + } + } + + /* Allocate a private depth-stencil buffer. */ + if (alloc_depthstencil) { + enum st_attachment_type att = ST_ATTACHMENT_DEPTH_STENCIL; + struct pipe_resource **zsbuf; + enum pipe_format format; + unsigned bind; + + dri_drawable_get_format(drawable, att, &format, &bind); + + if (format) { + templ.format = format; + templ.bind = bind; + + if (drawable->stvis.samples > 1) { + templ.nr_samples = drawable->stvis.samples; + zsbuf = &drawable->msaa_textures[att]; + } + else { + templ.nr_samples = 0; + zsbuf = &drawable->textures[att]; + } + + /* Try to reuse the resource. + * (the other resource parameters should be constant) + */ + if (!*zsbuf || + (*zsbuf)->width0 != templ.width0 || + (*zsbuf)->height0 != templ.height0) { + /* Allocate a new one. */ + pipe_resource_reference(zsbuf, NULL); + *zsbuf = screen->base.screen->resource_create(screen->base.screen, + &templ); + assert(*zsbuf); + } + } + else { + pipe_resource_reference(&drawable->msaa_textures[att], NULL); + pipe_resource_reference(&drawable->textures[att], NULL); + } + } +} + /* * Backend functions for st_framebuffer interface. */ @@ -467,13 +680,18 @@ dri2_allocate_textures(struct dri_context *ctx, const enum st_attachment_type *statts, unsigned statts_count) { - __DRIbuffer *buffers; - unsigned num_buffers = statts_count; - - buffers = dri2_drawable_get_buffers(drawable, statts, &num_buffers); - if (buffers) - dri2_drawable_process_buffers(ctx, drawable, buffers, num_buffers, - statts, statts_count); + __DRIscreen *sPriv = drawable->sPriv; + + if (sPriv->image.loader) { + dri_image_allocate_textures(ctx, drawable, statts, statts_count); + } else { + __DRIbuffer *buffers; + unsigned num_buffers = statts_count; + buffers = dri2_drawable_get_buffers(drawable, statts, &num_buffers); + if (buffers) + dri2_drawable_process_buffers(ctx, drawable, buffers, num_buffers, + statts, statts_count); + } } static void @@ -482,6 +700,7 @@ dri2_flush_frontbuffer(struct dri_context *ctx, enum st_attachment_type statt) { __DRIdrawable *dri_drawable = drawable->dPriv; + struct __DRIimageLoaderExtensionRec *image = drawable->sPriv->image.loader; struct __DRIdri2LoaderExtensionRec *loader = drawable->sPriv->dri2.loader; struct pipe_context *pipe = ctx->st->pipe; @@ -501,7 +720,9 @@ dri2_flush_frontbuffer(struct dri_context *ctx, pipe->flush(pipe, NULL, 0); - if (loader->flushFrontBuffer) { + if (image->flushFrontBuffer) { + image->flushFrontBuffer(dri_drawable, dri_drawable->loaderPrivate); + } else if (loader->flushFrontBuffer) { loader->flushFrontBuffer(dri_drawable, dri_drawable->loaderPrivate); } } @@ -1116,6 +1337,7 @@ const struct __DriverAPIRec driDriverAPI = { /* This is the table of extensions that the loader will dlsym() for. */ PUBLIC const __DRIextension *__driDriverExtensions[] = { &driCoreExtension.base, + &driImageDriverExtension.base, &driDRI2Extension.base, &gallium_config_options.base, NULL