Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] d3d11va: let user can create SRV from output
@ 2022-03-09  6:56 Wang Chuan
  2022-03-09  7:20 ` Hendrik Leppkes
  0 siblings, 1 reply; 2+ messages in thread
From: Wang Chuan @ 2022-03-09  6:56 UTC (permalink / raw)
  To: ffmpeg-devel

Starting from Windows 8, users can create SRV from video resource
and bind it to shaders directly. This can avoid unnecessary memcpy
(ID3D11DeviceContext::CopyResource, etc), so create texture with
[D3D11_BIND_SHADER_RESOURCE] as decoder's output if possible.

Signed-off-by: Wang Chuan <ouchuanm@outlook.com>
---
  libavcodec/dxva2.c            |  2 +-
  libavutil/hwcontext_d3d11va.c | 10 ++++++++++
  2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/libavcodec/dxva2.c b/libavcodec/dxva2.c
index 568d686f39..15b25d793c 100644
--- a/libavcodec/dxva2.c
+++ b/libavcodec/dxva2.c
@@ -645,7 +645,7 @@ int ff_dxva2_common_frame_params(AVCodecContext *avctx,
      if (frames_ctx->format == AV_PIX_FMT_D3D11) {
          AVD3D11VAFramesContext *frames_hwctx = frames_ctx->hwctx;
  -        frames_hwctx->BindFlags |= D3D11_BIND_DECODER;
+        frames_hwctx->BindFlags |= (D3D11_BIND_DECODER | 
D3D11_BIND_SHADER_RESOURCE);
      }
  #endif
  diff --git a/libavutil/hwcontext_d3d11va.c b/libavutil/hwcontext_d3d11va.c
index 8ab96bad25..97ffd745bd 100644
--- a/libavutil/hwcontext_d3d11va.c
+++ b/libavutil/hwcontext_d3d11va.c
@@ -203,6 +203,11 @@ static AVBufferRef 
*d3d11va_alloc_single(AVHWFramesContext *ctx)
      };
       hr = ID3D11Device_CreateTexture2D(device_hwctx->device, &texDesc, 
NULL, &tex);
+    if (FAILED(hr) && (texDesc.BindFlags & D3D11_BIND_SHADER_RESOURCE)) {
+        av_log(ctx, AV_LOG_ERROR, "Could not create the texture with 
[D3D11_BIND_SHADER_RESOURCE] flag");
+        texDesc.BindFlags &= ~D3D11_BIND_SHADER_RESOURCE;
+        hr = ID3D11Device_CreateTexture2D(device_hwctx->device, 
&texDesc, NULL, &tex);
+    }
      if (FAILED(hr)) {
          av_log(ctx, AV_LOG_ERROR, "Could not create the texture 
(%lx)\n", (long)hr);
          return NULL;
@@ -278,6 +283,11 @@ static int d3d11va_frames_init(AVHWFramesContext *ctx)
          }
      } else if (!(texDesc.BindFlags & D3D11_BIND_RENDER_TARGET) && 
texDesc.ArraySize > 0) {
          hr = ID3D11Device_CreateTexture2D(device_hwctx->device, 
&texDesc, NULL, &hwctx->texture);
+        if (FAILED(hr) && (texDesc.BindFlags & 
D3D11_BIND_SHADER_RESOURCE)) {
+            av_log(ctx, AV_LOG_ERROR, "Could not create the texture 
with [D3D11_BIND_SHADER_RESOURCE] flag");
+            texDesc.BindFlags &= ~D3D11_BIND_SHADER_RESOURCE;
+            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);
              return AVERROR_UNKNOWN;
-- 
2.35.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [FFmpeg-devel] [PATCH] d3d11va: let user can create SRV from output
  2022-03-09  6:56 [FFmpeg-devel] [PATCH] d3d11va: let user can create SRV from output Wang Chuan
@ 2022-03-09  7:20 ` Hendrik Leppkes
  0 siblings, 0 replies; 2+ messages in thread
From: Hendrik Leppkes @ 2022-03-09  7:20 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

On Wed, Mar 9, 2022 at 7:56 AM Wang Chuan <ouchuanm@outlook.com> wrote:
>
> Starting from Windows 8, users can create SRV from video resource
> and bind it to shaders directly. This can avoid unnecessary memcpy
> (ID3D11DeviceContext::CopyResource, etc), so create texture with
> [D3D11_BIND_SHADER_RESOURCE] as decoder's output if possible.
>
> Signed-off-by: Wang Chuan <ouchuanm@outlook.com>
> ---
>   libavcodec/dxva2.c            |  2 +-
>   libavutil/hwcontext_d3d11va.c | 10 ++++++++++
>   2 files changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/libavcodec/dxva2.c b/libavcodec/dxva2.c
> index 568d686f39..15b25d793c 100644
> --- a/libavcodec/dxva2.c
> +++ b/libavcodec/dxva2.c
> @@ -645,7 +645,7 @@ int ff_dxva2_common_frame_params(AVCodecContext *avctx,
>       if (frames_ctx->format == AV_PIX_FMT_D3D11) {
>           AVD3D11VAFramesContext *frames_hwctx = frames_ctx->hwctx;
>   -        frames_hwctx->BindFlags |= D3D11_BIND_DECODER;
> +        frames_hwctx->BindFlags |= (D3D11_BIND_DECODER |
> D3D11_BIND_SHADER_RESOURCE);
>       }
>   #endif
>   diff --git a/libavutil/hwcontext_d3d11va.c b/libavutil/hwcontext_d3d11va.c
> index 8ab96bad25..97ffd745bd 100644
> --- a/libavutil/hwcontext_d3d11va.c
> +++ b/libavutil/hwcontext_d3d11va.c
> @@ -203,6 +203,11 @@ static AVBufferRef
> *d3d11va_alloc_single(AVHWFramesContext *ctx)
>       };
>        hr = ID3D11Device_CreateTexture2D(device_hwctx->device, &texDesc,
> NULL, &tex);
> +    if (FAILED(hr) && (texDesc.BindFlags & D3D11_BIND_SHADER_RESOURCE)) {
> +        av_log(ctx, AV_LOG_ERROR, "Could not create the texture with
> [D3D11_BIND_SHADER_RESOURCE] flag");
> +        texDesc.BindFlags &= ~D3D11_BIND_SHADER_RESOURCE;
> +        hr = ID3D11Device_CreateTexture2D(device_hwctx->device,
> &texDesc, NULL, &tex);
> +    }
>       if (FAILED(hr)) {
>           av_log(ctx, AV_LOG_ERROR, "Could not create the texture
> (%lx)\n", (long)hr);
>           return NULL;
> @@ -278,6 +283,11 @@ static int d3d11va_frames_init(AVHWFramesContext *ctx)
>           }
>       } else if (!(texDesc.BindFlags & D3D11_BIND_RENDER_TARGET) &&
> texDesc.ArraySize > 0) {
>           hr = ID3D11Device_CreateTexture2D(device_hwctx->device,
> &texDesc, NULL, &hwctx->texture);
> +        if (FAILED(hr) && (texDesc.BindFlags &
> D3D11_BIND_SHADER_RESOURCE)) {
> +            av_log(ctx, AV_LOG_ERROR, "Could not create the texture
> with [D3D11_BIND_SHADER_RESOURCE] flag");
> +            texDesc.BindFlags &= ~D3D11_BIND_SHADER_RESOURCE;
> +            hr = ID3D11Device_CreateTexture2D(device_hwctx->device,
> &texDesc, NULL, &hwctx->texture);
> +        }

I really don't like these fallbacks. If a caller requests a certain
set of flags, it should fullfill these, or fail, and not change them.
Especially special-casing this one flag just makes it extra iffy, and
I know why you added it, but that doesn't help.

IMHO, its also not entirely unreasonable that if you require anything
but the default flags, to let the user just manage their own frames
context, the effort required is not that high and there is never a set
of flags you can set that'll cover every use case (for example, I use
surface sharing, thats not set by default either).

- Hendrik
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-09  7:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-09  6:56 [FFmpeg-devel] [PATCH] d3d11va: let user can create SRV from output Wang Chuan
2022-03-09  7:20 ` Hendrik Leppkes

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git