From patchwork Fri May 8 15:18:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: galinart X-Patchwork-Id: 19574 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id E098744A4AA for ; Fri, 8 May 2020 18:51:39 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B7FB868990F; Fri, 8 May 2020 18:51:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0DCA4688121 for ; Fri, 8 May 2020 18:51:33 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id j5so2464632wrq.2 for ; Fri, 08 May 2020 08:51:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bbtgyXZJ9H6BaRYJHbGVS8wDKOL/MfFAuVp3+BDkHDU=; b=gvsqH2lNiNx1ZKd0NPPkl6pXllYFXR9S8PXNr4nBDE2DSfIvte+NvGllj0QbB4KODm BSRG3qJ9+boIsmhlgKC3A4E2hGzvSD4mTJKJ3TPgOIyObTTZEghaJhIcnjOs7KGLhY8A Po5BQnDfMJBij3iM/a6JgQIF9FDI8j2XqQet0jRu67s3d/4ysiIjhPdatXtLP9oXzY53 xWjnwo5jdUM4Y7xVm9+IwsQYOkXNw9nbpeqXpWvf9bNq7ssYOPVuHmZmC8oCfdwV4a6w 2wssjFA/yccmf1JC2RXh85PjO2ie3NZR2GJ8wNBf2f9PYECwroPTcikIq78/pNVQ1trc iDPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bbtgyXZJ9H6BaRYJHbGVS8wDKOL/MfFAuVp3+BDkHDU=; b=A40wWmTot0urp/aNKHsOl/OCOFNH4EvDLAff10M7BqwlUQWRzkhEPpzHqJFMPoYJiM xjwjOVac2aPxrn1ITbezNyEbmyChdTcq/NiiJ/pkiVL2Yqyy2oHoQaAhPn/P3hlSWWL7 Oeyz6aYMAWQDvr7Daupj9Km7IPXshqdB8w64I67rH4wIo/yQJFarxkz12V6Rcsi6fwuv V8aZI306ia975JLp3wFQP8WqxNp3xU5p1f35gyNt9zLU2oz3Ce18ANdpSbrNUFFGA553 vm3ywNTGgGrTNupuqM44ELyszUJ6QN/KgggBJJdNToKQap8/jUM/r0Ct+Rkd5wAGhXKm QENA== X-Gm-Message-State: AGi0PuZA/HBDuYEBNmNvQKt1w1+8Kcn35nJlbM4AS59KKYcpL0pEgTW9 wnRcnkYfMtOTmlajzHr1G457nsoHU6paPA== X-Google-Smtp-Source: APiQypIu5fMNXBnw8aL8scV4F5ZD49+T8tTikdJY5CS2MxvYNafCXGq94dLqgY4yATCHPGhKP5u7hw== X-Received: by 2002:adf:f1c4:: with SMTP id z4mr3765841wro.25.1588951229766; Fri, 08 May 2020 08:20:29 -0700 (PDT) Received: from localhost.localdomain ([2a02:c7d:3e2e:7400:c904:d18e:fdcb:4131]) by smtp.googlemail.com with ESMTPSA id u24sm7339937wmm.47.2020.05.08.08.20.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 May 2020 08:20:29 -0700 (PDT) From: artem.galin@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Fri, 8 May 2020 16:18:13 +0100 Message-Id: <20200508151821.49051-3-artem.galin@gmail.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200508151821.49051-1-artem.galin@gmail.com> References: <20200424145219.54067-4-artem.galin@gmail.com> <20200508151821.49051-1-artem.galin@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 03/11] libavutil/hwcontext_d3d11va: adding more texture information to the D3D11 hwcontext API X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Artem Galin , robux4@ycbcr.xyz Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Artem Galin Added AVD3D11FrameDescriptors array to store array of single textures in case if there is no way to allocate array texture with BindFlags = D3D11_BIND_RENDER_TARGET. Signed-off-by: Artem Galin --- libavutil/hwcontext_d3d11va.c | 26 ++++++++++++++++++++------ libavutil/hwcontext_d3d11va.h | 9 +++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/libavutil/hwcontext_d3d11va.c b/libavutil/hwcontext_d3d11va.c index c8ae58f908..cd80931dd3 100644 --- a/libavutil/hwcontext_d3d11va.c +++ b/libavutil/hwcontext_d3d11va.c @@ -72,8 +72,8 @@ static av_cold void load_functions(void) } typedef struct D3D11VAFramesContext { - int nb_surfaces_used; - + size_t nb_surfaces; + size_t nb_surfaces_used; DXGI_FORMAT format; ID3D11Texture2D *staging_texture; @@ -112,6 +112,8 @@ static void d3d11va_frames_uninit(AVHWFramesContext *ctx) if (s->staging_texture) ID3D11Texture2D_Release(s->staging_texture); s->staging_texture = NULL; + + av_freep(&frames_hwctx->texture_infos); } static int d3d11va_frames_get_constraints(AVHWDeviceContext *ctx, @@ -152,8 +154,10 @@ static void free_texture(void *opaque, uint8_t *data) av_free(data); } -static AVBufferRef *wrap_texture_buf(ID3D11Texture2D *tex, int index) +static AVBufferRef *wrap_texture_buf(AVHWFramesContext *ctx, ID3D11Texture2D *tex, int index) { + D3D11VAFramesContext *s = ctx->internal->priv; + AVD3D11VAFramesContext *frames_hwctx = ctx->hwctx; AVBufferRef *buf; AVD3D11FrameDescriptor *desc = av_mallocz(sizeof(*desc)); if (!desc) { @@ -161,6 +165,10 @@ static AVBufferRef *wrap_texture_buf(ID3D11Texture2D *tex, int index) return NULL; } + frames_hwctx->texture_infos[s->nb_surfaces_used].texture = tex; + frames_hwctx->texture_infos[s->nb_surfaces_used].index = index; + s->nb_surfaces_used++; + desc->texture = tex; desc->index = index; @@ -199,7 +207,7 @@ static AVBufferRef *d3d11va_alloc_single(AVHWFramesContext *ctx) return NULL; } - return wrap_texture_buf(tex, 0); + return wrap_texture_buf(ctx, tex, 0); } static AVBufferRef *d3d11va_pool_alloc(void *opaque, int size) @@ -220,7 +228,7 @@ static AVBufferRef *d3d11va_pool_alloc(void *opaque, int size) } ID3D11Texture2D_AddRef(hwctx->texture); - return wrap_texture_buf(hwctx->texture, s->nb_surfaces_used++); + return wrap_texture_buf(ctx, hwctx->texture, s->nb_surfaces_used); } static int d3d11va_frames_init(AVHWFramesContext *ctx) @@ -267,7 +275,7 @@ static int d3d11va_frames_init(AVHWFramesContext *ctx) av_log(ctx, AV_LOG_ERROR, "User-provided texture has mismatching parameters\n"); return AVERROR(EINVAL); } - } else if (texDesc.ArraySize > 0) { + } else if (!(texDesc.BindFlags & D3D11_BIND_RENDER_TARGET) && texDesc.ArraySize > 0) { hr = ID3D11Device_CreateTexture2D(device_hwctx->device, &texDesc, NULL, &hwctx->texture); if (FAILED(hr)) { av_log(ctx, AV_LOG_ERROR, "Could not create the texture (%lx)\n", (long)hr); @@ -275,6 +283,12 @@ static int d3d11va_frames_init(AVHWFramesContext *ctx) } } + hwctx->texture_infos = av_mallocz_array(ctx->initial_pool_size, sizeof(*hwctx->texture_infos)); + if (!hwctx->texture_infos) + return AVERROR(ENOMEM); + + s->nb_surfaces = ctx->initial_pool_size; + ctx->internal->pool_internal = av_buffer_pool_init2(sizeof(AVD3D11FrameDescriptor), ctx, d3d11va_pool_alloc, NULL); if (!ctx->internal->pool_internal) diff --git a/libavutil/hwcontext_d3d11va.h b/libavutil/hwcontext_d3d11va.h index 9f91e9b1b6..295bdcd90d 100644 --- a/libavutil/hwcontext_d3d11va.h +++ b/libavutil/hwcontext_d3d11va.h @@ -164,6 +164,15 @@ typedef struct AVD3D11VAFramesContext { * This field is ignored/invalid if a user-allocated texture is provided. */ UINT MiscFlags; + + /** + * In case if texture structure member above is not NULL contains the same texture + * pointer for all elements and different indexes into the array texture. + * In case if texture structure member above is NULL, all elements contains + * pointers to separate non-array textures and 0 indexes. + * This field is ignored/invalid if a user-allocated texture is provided. + */ + AVD3D11FrameDescriptor *texture_infos; } AVD3D11VAFramesContext; #endif /* AVUTIL_HWCONTEXT_D3D11VA_H */