[vlc-commits] [Git][videolan/vlc][3.0.x] 2 commits: dxva: allow the VA to change the amount of surfaces used in the pool
Steve Lhomme (@robUx4)
gitlab at videolan.org
Mon Oct 5 13:36:20 UTC 2026
Steve Lhomme pushed to branch 3.0.x at VideoLAN / VLC
Commits:
b4ab26f8 by Steve Lhomme at 2026-10-05T13:28:05+00:00
dxva: allow the VA to change the amount of surfaces used in the pool
- - - - -
2d6a6d61 by Steve Lhomme at 2026-10-05T13:28:05+00:00
d3d11va: grow the pool when the NVIDIA pool hack is enabled
We cannot create 30 or more DecoderOutputView when the display
pool is using a large pool. But it seems we can use a decoder pool larger than 30
slices.
However it still fails with #30187 as the pool is just large enough for the decoder.
But since the pictures from this decoder are also used in the display we need to
account for buffering and pause pictures.
- - - - -
5 changed files:
- modules/codec/avcodec/d3d11va.c
- modules/codec/avcodec/directx_va.c
- modules/codec/avcodec/dxva2.c
- modules/codec/avcodec/va_surface.c
- modules/codec/avcodec/va_surface_internal.h
Changes:
=====================================
modules/codec/avcodec/d3d11va.c
=====================================
@@ -138,7 +138,7 @@ static int DxGetInputList(vlc_va_t *, input_list_t *);
static int DxSetupOutput(vlc_va_t *, const GUID *, int surface_width, int surface_height);
static int DxCreateDecoderSurfaces(vlc_va_t *, int codec_id,
- const video_format_t *fmt, unsigned surface_count);
+ const video_format_t *fmt, unsigned *surface_count);
static void DxDestroySurfaces(vlc_va_t *);
static void SetupAVCodecContext(vlc_va_t *);
@@ -676,7 +676,7 @@ static bool CanUseDecoderPadding(const vlc_va_sys_t *sys)
* It creates a Direct3D11 decoder using the given video format
*/
static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id,
- const video_format_t *fmt, unsigned surface_count)
+ const video_format_t *fmt, unsigned *surface_count)
{
vlc_va_sys_t *sys = va->sys;
directx_sys_t *dx_sys = &va->sys->dx_sys;
@@ -704,10 +704,14 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id,
sys->textureWidth = fmt->i_width;
sys->textureHeight = fmt->i_height;
}
- if (sys->totalTextureSlices && sys->totalTextureSlices < surface_count)
+ if (sys->totalTextureSlices && sys->totalTextureSlices < *surface_count)
{
msg_Warn(va, "not enough decoding slices in the texture (%d/%d)",
- sys->totalTextureSlices, surface_count);
+ sys->totalTextureSlices, *surface_count);
+
+ // extra surfaces for the pictures kept in the display module
+ *surface_count += 3;
+
dx_sys->can_extern_pool = false;
}
#if VLC_WINSTORE_APP
@@ -748,13 +752,13 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id,
{
#if !D3D11_DIRECT_DECODE
size_t surface_idx;
- for (surface_idx = 0; surface_idx < surface_count; surface_idx++) {
+ for (surface_idx = 0; surface_idx < *surface_count; surface_idx++) {
picture_t *pic = decoder_NewPicture( (decoder_t*) va->obj.parent );
sys->extern_pics[surface_idx] = pic;
dx_sys->hw_surface[surface_idx] = NULL;
if (pic==NULL)
{
- msg_Warn(va, "not enough decoder pictures %d out of %d", surface_idx, surface_count);
+ msg_Warn(va, "not enough decoder pictures %d out of %d", surface_idx, *surface_count);
dx_sys->can_extern_pool = false;
break;
}
@@ -822,7 +826,7 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id,
texDesc.Format = sys->render;
texDesc.SampleDesc.Count = 1;
texDesc.MiscFlags = 0;
- texDesc.ArraySize = surface_count;
+ texDesc.ArraySize = *surface_count;
texDesc.Usage = D3D11_USAGE_DEFAULT;
texDesc.BindFlags = D3D11_BIND_DECODER;
texDesc.CPUAccessFlags = 0;
@@ -833,12 +837,12 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id,
ID3D11Texture2D *p_texture;
hr = ID3D11Device_CreateTexture2D( sys->d3d_dev.d3ddevice, &texDesc, NULL, &p_texture );
if (FAILED(hr)) {
- msg_Err(va, "CreateTexture2D %d failed. (hr=0x%lX)", surface_count, hr);
+ msg_Err(va, "CreateTexture2D %u failed. (hr=0x%lX)", *surface_count, hr);
return VLC_EGENERIC;
}
unsigned surface_idx;
- for (surface_idx = 0; surface_idx < surface_count; surface_idx++) {
+ for (surface_idx = 0; surface_idx < *surface_count; surface_idx++) {
sys->extern_pics[surface_idx] = NULL;
viewDesc.Texture2D.ArraySlice = surface_idx;
@@ -861,7 +865,7 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id,
}
}
msg_Dbg(va, "ID3D11VideoDecoderOutputView succeed with %d surfaces (%dx%d)",
- surface_count, fmt->i_width, fmt->i_height);
+ *surface_count, fmt->i_width, fmt->i_height);
D3D11_VIDEO_DECODER_DESC decoderDesc;
ZeroMemory(&decoderDesc, sizeof(decoderDesc));
=====================================
modules/codec/avcodec/directx_va.c
=====================================
@@ -389,7 +389,7 @@ int directx_va_Setup(vlc_va_t *va, directx_sys_t *dx_sys,
return VLC_EGENERIC;
}
- int err = va_pool_SetupDecoder(va, &dx_sys->va_pool, avctx, surface_count, surface_width, surface_height);
+ int err = va_pool_SetupDecoder(va, &dx_sys->va_pool, avctx, &surface_count, surface_width, surface_height);
if (err != VLC_SUCCESS)
return err;
if (dx_sys->can_extern_pool)
=====================================
modules/codec/avcodec/dxva2.c
=====================================
@@ -145,7 +145,7 @@ static int DxGetInputList(vlc_va_t *, input_list_t *);
static int DxSetupOutput(vlc_va_t *, const GUID *, int surface_width, int surface_height);
static int DxCreateVideoDecoder(vlc_va_t *, int codec_id,
- const video_format_t *, unsigned surface_count);
+ const video_format_t *, unsigned *surface_count);
static void DxDestroyVideoDecoder(vlc_va_t *);
static int DxResetVideoDecoder(vlc_va_t *);
static void SetupAVCodecContext(vlc_va_t *);
@@ -567,7 +567,7 @@ static int DxSetupOutput(vlc_va_t *va, const GUID *input, int surface_width, int
* It creates a DXVA2 decoder using the given video format
*/
static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id,
- const video_format_t *fmt, unsigned surface_count)
+ const video_format_t *fmt, unsigned *surface_count)
{
vlc_va_sys_t *p_sys = va->sys;
directx_sys_t *sys = &va->sys->dx_sys;
@@ -576,7 +576,7 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id,
hr = IDirectXVideoDecoderService_CreateSurface(sys->d3ddec,
fmt->i_width,
fmt->i_height,
- surface_count - 1,
+ *surface_count - 1,
p_sys->render,
D3DPOOL_DEFAULT,
0,
@@ -584,11 +584,11 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id,
sys->hw_surface,
NULL);
if (FAILED(hr)) {
- msg_Err(va, "IDirectXVideoAccelerationService_CreateSurface %d failed (hr=0x%lX)", surface_count - 1, hr);
+ msg_Err(va, "IDirectXVideoAccelerationService_CreateSurface %d failed (hr=0x%lX)", *surface_count - 1, hr);
return VLC_EGENERIC;
}
- msg_Dbg(va, "IDirectXVideoAccelerationService_CreateSurface succeed with %d surfaces (%dx%d)",
- surface_count, fmt->i_width, fmt->i_height);
+ msg_Dbg(va, "IDirectXVideoAccelerationService_CreateSurface succeed with %u surfaces (%dx%d)",
+ *surface_count, fmt->i_width, fmt->i_height);
IDirect3DSurface9 *tstCrash;
hr = IDirectXVideoDecoderService_CreateSurface(sys->d3ddec,
@@ -688,7 +688,7 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id,
&dsc,
&p_sys->cfg,
sys->hw_surface,
- surface_count,
+ *surface_count,
&decoder))) {
msg_Err(va, "IDirectXVideoDecoderService_CreateVideoDecoder failed");
goto error;
@@ -698,7 +698,7 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id,
msg_Dbg(va, "IDirectXVideoDecoderService_CreateVideoDecoder succeed");
return VLC_SUCCESS;
error:
- for (unsigned i = 0; i < surface_count; i++)
+ for (unsigned i = 0; i < *surface_count; i++)
IDirect3DSurface9_Release( sys->hw_surface[i] );
return VLC_EGENERIC;
}
=====================================
modules/codec/avcodec/va_surface.c
=====================================
@@ -54,13 +54,13 @@ static void DestroyVideoDecoder(vlc_va_t *va, va_pool_t *va_pool)
}
/* */
-int va_pool_SetupDecoder(vlc_va_t *va, va_pool_t *va_pool, const AVCodecContext *avctx, unsigned count,
+int va_pool_SetupDecoder(vlc_va_t *va, va_pool_t *va_pool, const AVCodecContext *avctx, unsigned *count,
int surface_width, int surface_height)
{
int err = VLC_ENOMEM;
unsigned i = va_pool->surface_count;
- if ( va_pool->surface_count >= count &&
+ if ( va_pool->surface_count >= *count &&
va_pool->surface_width == surface_width &&
va_pool->surface_height == surface_height )
{
@@ -73,9 +73,9 @@ int va_pool_SetupDecoder(vlc_va_t *va, va_pool_t *va_pool, const AVCodecContext
DestroyVideoDecoder(va, va_pool);
/* */
- msg_Dbg(va, "va_pool_SetupDecoder id %d %dx%d count: %d", avctx->codec_id, avctx->coded_width, avctx->coded_height, count);
+ msg_Dbg(va, "va_pool_SetupDecoder id %d %dx%d count: %u", avctx->codec_id, avctx->coded_width, avctx->coded_height, *count);
- if (count > MAX_SURFACE_COUNT)
+ if (*count > MAX_SURFACE_COUNT)
return VLC_EGENERIC;
/* FIXME transmit a video_format_t by VaSetup directly */
=====================================
modules/codec/avcodec/va_surface_internal.h
=====================================
@@ -61,7 +61,7 @@ typedef struct
*/
int (*pf_create_decoder_surfaces)(vlc_va_t *, int codec_id,
const video_format_t *fmt,
- unsigned surface_count);
+ unsigned *surface_count);
/**
* Destroy resources allocated with the surfaces and the associated decoder
*/
@@ -80,7 +80,7 @@ typedef struct
int va_pool_Open(vlc_va_t *, va_pool_t *);
void va_pool_Close(vlc_va_t *va, va_pool_t *);
-int va_pool_SetupDecoder(vlc_va_t *, va_pool_t *, const AVCodecContext *, unsigned count, int surface_width, int surface_height);
+int va_pool_SetupDecoder(vlc_va_t *, va_pool_t *, const AVCodecContext *, unsigned *count, int surface_width, int surface_height);
int va_pool_SetupSurfaces(vlc_va_t *, va_pool_t *, unsigned count);
int va_pool_Get(va_pool_t *, picture_t *);
void va_surface_AddRef(vlc_va_surface_t *surface);
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/20efb561c6f59fb653bc76e62cab787d91db2060...2d6a6d613f7e6d13ec88f01e98e728703e9673ae
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/20efb561c6f59fb653bc76e62cab787d91db2060...2d6a6d613f7e6d13ec88f01e98e728703e9673ae
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help
More information about the vlc-commits
mailing list