[vlc-commits] d3d11_quad: make the number of pixel shader not fixed
Steve Lhomme
git at videolan.org
Mon May 28 13:25:47 CEST 2018
vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Wed Jan 10 10:46:28 2018 +0100| [3f50a0f8bf47a19468198e6fdc78a56a34f7bdf5] | committer: Steve Lhomme
d3d11_quad: make the number of pixel shader not fixed
When rendering to NV12 we need to render to 2 different targets
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3f50a0f8bf47a19468198e6fdc78a56a34f7bdf5
---
modules/video_output/win32/d3d11_quad.c | 12 +++--
modules/video_output/win32/d3d11_quad.h | 2 +-
modules/video_output/win32/d3d11_shaders.c | 74 +++++++++++++++++-------------
modules/video_output/win32/d3d11_shaders.h | 2 +-
modules/video_output/win32/direct3d11.c | 37 ++++++++++-----
5 files changed, 78 insertions(+), 49 deletions(-)
diff --git a/modules/video_output/win32/d3d11_quad.c b/modules/video_output/win32/d3d11_quad.c
index b908f748cf..dfe90967c7 100644
--- a/modules/video_output/win32/d3d11_quad.c
+++ b/modules/video_output/win32/d3d11_quad.c
@@ -64,12 +64,13 @@ void D3D11_RenderQuad(d3d11_device_t *d3d_dev, d3d_quad_t *quad,
assert(quad->resourceCount <= D3D11_MAX_SHADER_VIEW);
ID3D11DeviceContext_PSSetShaderResources(d3d_dev->d3dcontext, 0, quad->resourceCount, resourceView);
- ID3D11DeviceContext_PSSetShader(d3d_dev->d3dcontext, quad->d3dpixelShader, NULL, 0);
for (size_t i=0; i<D3D11_MAX_SHADER_VIEW; i++)
{
if (!d3drenderTargetView[i])
break;
+ ID3D11DeviceContext_PSSetShader(d3d_dev->d3dcontext, quad->d3dpixelShader[0], NULL, 0);
+
ID3D11DeviceContext_RSSetViewports(d3d_dev->d3dcontext, 1, &quad->cropViewport[i]);
ID3D11DeviceContext_OMSetRenderTargets(d3d_dev->d3dcontext, 1, &d3drenderTargetView[i], NULL);
@@ -163,10 +164,13 @@ void D3D11_ReleaseQuad(d3d_quad_t *quad)
ID3D11Buffer_Release(quad->pVertexShaderConstants);
quad->pVertexShaderConstants = NULL;
}
- if (quad->d3dpixelShader)
+ for (size_t i=0; i<D3D11_MAX_SHADER_VIEW; i++)
{
- ID3D11PixelShader_Release(quad->d3dpixelShader);
- quad->d3dpixelShader = NULL;
+ if (quad->d3dpixelShader[i])
+ {
+ ID3D11PixelShader_Release(quad->d3dpixelShader[i]);
+ quad->d3dpixelShader[i] = NULL;
+ }
}
ReleasePictureSys(&quad->picSys);
}
diff --git a/modules/video_output/win32/d3d11_quad.h b/modules/video_output/win32/d3d11_quad.h
index 34b49d37f5..208173e92b 100644
--- a/modules/video_output/win32/d3d11_quad.h
+++ b/modules/video_output/win32/d3d11_quad.h
@@ -43,7 +43,7 @@ typedef struct
ID3D11Buffer *pVertexShaderConstants;
ID3D11Buffer *pPixelShaderConstants[2];
UINT PSConstantsCount;
- ID3D11PixelShader *d3dpixelShader;
+ ID3D11PixelShader *d3dpixelShader[D3D11_MAX_SHADER_VIEW];
ID3D11InputLayout *pVertexLayout;
D3D11_VIEWPORT cropViewport[D3D11_MAX_SHADER_VIEW];
unsigned int i_width;
diff --git a/modules/video_output/win32/d3d11_shaders.c b/modules/video_output/win32/d3d11_shaders.c
index 35405811e3..88e78e28d5 100644
--- a/modules/video_output/win32/d3d11_shaders.c
+++ b/modules/video_output/win32/d3d11_shaders.c
@@ -195,12 +195,50 @@ bool IsRGBShader(const d3d_format_t *cfg)
cfg->formatTexture != DXGI_FORMAT_YUY2;
}
+static HRESULT CompileTargetShader(vlc_object_t *o, d3d11_handle_t *hd3d, bool legacy_shader,
+ d3d11_device_t *d3d_dev,
+ const char *psz_sampler,
+ const char *psz_src_transform, const char *psz_display_transform,
+ const char *psz_tone_mapping,
+ const char *psz_adjust_range, ID3D11PixelShader **output)
+{
+ char *shader = malloc(strlen(globPixelShaderDefault) + 32 + strlen(psz_sampler) +
+ strlen(psz_src_transform) + strlen(psz_display_transform) +
+ strlen(psz_tone_mapping) + strlen(psz_adjust_range));
+ if (!shader)
+ {
+ msg_Err(o, "no room for the Pixel Shader");
+ return E_OUTOFMEMORY;
+ }
+ sprintf(shader, globPixelShaderDefault, legacy_shader ? "" : "Array", psz_src_transform,
+ psz_display_transform, psz_tone_mapping, psz_adjust_range, psz_sampler);
+#ifndef NDEBUG
+ msg_Dbg(o,"psz_src_transform %s", psz_src_transform);
+ msg_Dbg(o,"psz_tone_mapping %s", psz_tone_mapping);
+ msg_Dbg(o,"psz_display_transform %s", psz_display_transform);
+ msg_Dbg(o,"psz_adjust_range %s", psz_adjust_range);
+ msg_Dbg(o,"psz_sampler %s", psz_sampler);
+#endif
+
+ ID3DBlob *pPSBlob = D3D11_CompileShader(o, hd3d, d3d_dev, shader, true);
+ free(shader);
+ if (!pPSBlob)
+ return E_INVALIDARG;
+
+ HRESULT hr = ID3D11Device_CreatePixelShader(d3d_dev->d3ddevice,
+ (void *)ID3D10Blob_GetBufferPointer(pPSBlob),
+ ID3D10Blob_GetBufferSize(pPSBlob), NULL, output);
+
+ ID3D10Blob_Release(pPSBlob);
+ return hr;
+}
+
#undef D3D11_CompilePixelShader
HRESULT D3D11_CompilePixelShader(vlc_object_t *o, d3d11_handle_t *hd3d, bool legacy_shader,
d3d11_device_t *d3d_dev,
const d3d_format_t *format, const display_info_t *display,
video_transfer_func_t transfer, bool src_full_range,
- ID3D11PixelShader **output)
+ ID3D11PixelShader *output[D3D11_MAX_SHADER_VIEW])
{
static const char *DEFAULT_NOOP = "return rgb";
const char *psz_sampler;
@@ -420,38 +458,12 @@ HRESULT D3D11_CompilePixelShader(vlc_object_t *o, d3d11_handle_t *hd3d, bool leg
}
}
- char *shader = malloc(strlen(globPixelShaderDefault) + 32 + strlen(psz_sampler) +
- strlen(psz_src_transform) + strlen(psz_display_transform) +
- strlen(psz_tone_mapping) + strlen(psz_adjust_range));
- if (!shader)
- {
- msg_Err(o, "no room for the Pixel Shader");
- free(psz_range);
- return E_OUTOFMEMORY;
- }
- sprintf(shader, globPixelShaderDefault, legacy_shader ? "" : "Array", psz_src_transform,
- psz_display_transform, psz_tone_mapping, psz_adjust_range, psz_sampler);
-#ifndef NDEBUG
- if (!IsRGBShader(format)) {
- msg_Dbg(o,"psz_src_transform %s", psz_src_transform);
- msg_Dbg(o,"psz_tone_mapping %s", psz_tone_mapping);
- msg_Dbg(o,"psz_display_transform %s", psz_display_transform);
- msg_Dbg(o,"psz_adjust_range %s", psz_adjust_range);
- msg_Dbg(o,"psz_sampler %s", psz_sampler);
- }
-#endif
+ HRESULT hr = CompileTargetShader(o, hd3d, legacy_shader, d3d_dev,
+ psz_sampler, psz_src_transform,
+ psz_display_transform, psz_tone_mapping,
+ psz_adjust_range, &output[0]);
free(psz_range);
- ID3DBlob *pPSBlob = D3D11_CompileShader(o, hd3d, d3d_dev, shader, true);
- free(shader);
- if (!pPSBlob)
- return E_INVALIDARG;
-
- HRESULT hr = ID3D11Device_CreatePixelShader(d3d_dev->d3ddevice,
- (void *)ID3D10Blob_GetBufferPointer(pPSBlob),
- ID3D10Blob_GetBufferSize(pPSBlob), NULL, output);
-
- ID3D10Blob_Release(pPSBlob);
return hr;
}
diff --git a/modules/video_output/win32/d3d11_shaders.h b/modules/video_output/win32/d3d11_shaders.h
index 1bdfa10822..3c0b2ba1f0 100644
--- a/modules/video_output/win32/d3d11_shaders.h
+++ b/modules/video_output/win32/d3d11_shaders.h
@@ -84,7 +84,7 @@ bool IsRGBShader(const d3d_format_t *);
HRESULT D3D11_CompilePixelShader(vlc_object_t *, d3d11_handle_t *, bool legacy_shader,
d3d11_device_t *, const d3d_format_t *, const display_info_t *,
video_transfer_func_t, bool src_full_range,
- ID3D11PixelShader **output);
+ ID3D11PixelShader *output[D3D11_MAX_SHADER_VIEW]);
#define D3D11_CompilePixelShader(a,b,c,d,e,f,g,h,i) \
D3D11_CompilePixelShader(VLC_OBJECT(a),b,c,d,e,f,g,h,i)
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 6f8bf054cb..0aef5aeebc 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -114,7 +114,7 @@ struct vout_display_sys_t
// SPU
vlc_fourcc_t pSubpictureChromas[2];
- ID3D11PixelShader *pSPUPixelShader;
+ ID3D11PixelShader *pSPUPixelShader[D3D11_MAX_SHADER_VIEW];
const d3d_format_t *d3dregion_format;
int d3dregion_count;
picture_t **d3dregions;
@@ -1387,7 +1387,8 @@ static int Direct3D11CreateFormatResources(vout_display_t *vd, const video_forma
sys->legacy_shader = sys->d3d_dev.feature_level < D3D_FEATURE_LEVEL_10_0 || !CanUseTextureArray(vd);
hr = D3D11_CompilePixelShader(vd, &sys->hd3d, sys->legacy_shader, &sys->d3d_dev,
- sys->picQuad.formatInfo, &sys->display, fmt->transfer, fmt->b_color_range_full, &sys->picQuad.d3dpixelShader);
+ sys->picQuad.formatInfo, &sys->display, fmt->transfer, fmt->b_color_range_full,
+ sys->picQuad.d3dpixelShader);
if (FAILED(hr))
{
msg_Err(vd, "Failed to create the pixel shader. (hr=0x%lX)", hr);
@@ -1509,13 +1510,17 @@ static int Direct3D11CreateGenericResources(vout_display_t *vd)
if (sys->d3dregion_format != NULL)
{
hr = D3D11_CompilePixelShader(vd, &sys->hd3d, sys->legacy_shader, &sys->d3d_dev,
- sys->d3dregion_format, &sys->display, TRANSFER_FUNC_SRGB, true, &sys->pSPUPixelShader);
+ sys->d3dregion_format, &sys->display, TRANSFER_FUNC_SRGB, true,
+ sys->pSPUPixelShader);
if (FAILED(hr))
{
- if (sys->picQuad.d3dpixelShader)
+ for (size_t i=0; i<D3D11_MAX_SHADER_VIEW; i++)
{
- ID3D11PixelShader_Release(sys->picQuad.d3dpixelShader);
- sys->picQuad.d3dpixelShader = NULL;
+ if (sys->picQuad.d3dpixelShader[i])
+ {
+ ID3D11PixelShader_Release(sys->picQuad.d3dpixelShader[i]);
+ sys->picQuad.d3dpixelShader[i] = NULL;
+ }
}
msg_Err(vd, "Failed to create the SPU pixel shader. (hr=0x%lX)", hr);
return VLC_EGENERIC;
@@ -1641,11 +1646,11 @@ static void Direct3D11DestroyResources(vout_display_t *vd)
ID3D11RenderTargetView_Release(sys->d3drenderTargetView[i]);
sys->d3drenderTargetView[i] = NULL;
}
- }
- if (sys->pSPUPixelShader)
- {
- ID3D11PixelShader_Release(sys->pSPUPixelShader);
- sys->pSPUPixelShader = NULL;
+ if (sys->pSPUPixelShader[i])
+ {
+ ID3D11PixelShader_Release(sys->pSPUPixelShader[i]);
+ sys->pSPUPixelShader[i] = NULL;
+ }
}
#if defined(HAVE_ID3D11VIDEODECODER)
if( sys->d3d_dev.context_mutex != INVALID_HANDLE_VALUE )
@@ -1756,7 +1761,6 @@ static int Direct3D11MapSubpicture(vout_display_t *vd, int *subpicture_region_co
free(d3dquad);
continue;
}
- d3dquad->d3dpixelShader = sys->pSPUPixelShader;
picture_resource_t picres = {
.p_sys = (picture_sys_t *) d3dquad,
.pf_destroy = DestroyPictureQuad,
@@ -1769,6 +1773,15 @@ static int Direct3D11MapSubpicture(vout_display_t *vd, int *subpicture_region_co
continue;
}
quad_picture = (*region)[i];
+ for (size_t j=0; j<D3D11_MAX_SHADER_VIEW; j++)
+ {
+ /* TODO use something more accurate if we have different formats */
+ if (sys->pSPUPixelShader[j])
+ {
+ d3dquad->d3dpixelShader[j] = sys->pSPUPixelShader[j];
+ ID3D11PixelShader_AddRef(d3dquad->d3dpixelShader[j]);
+ }
+ }
} else {
D3D11_UpdateQuadPosition(vd, &sys->d3d_dev, (d3d_quad_t *) quad_picture->p_sys, &output, ORIENT_NORMAL);
}
More information about the vlc-commits
mailing list