[vlc-devel] [PATCH 04/11] d3d11_fmt: group the ID3D11Device and ID3D11DeviceContext in a structure
Steve Lhomme
robux4 at videolabs.io
Thu Nov 16 11:38:50 CET 2017
Since they usually go together
---
modules/codec/avcodec/d3d11va.c | 12 +--
modules/video_chroma/d3d11_fmt.c | 15 ++-
modules/video_chroma/d3d11_fmt.h | 9 +-
modules/video_output/win32/direct3d11.c | 159 ++++++++++++++++----------------
4 files changed, 98 insertions(+), 97 deletions(-)
diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index 6a3be0d66d..cfea13cc7b 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -427,19 +427,17 @@ static int D3dCreateDevice(vlc_va_t *va)
}
/* */
- ID3D11Device *d3ddev;
- ID3D11DeviceContext *d3dctx;
- hr = D3D11_CreateDevice(VLC_OBJECT(va), dx_sys->hdecoder_dll, true,
- &d3ddev, &d3dctx);
+ d3d11_handle_t hd3d11;
+ hr = D3D11_CreateDevice(VLC_OBJECT(va), dx_sys->hdecoder_dll, true, &hd3d11);
if (FAILED(hr)) {
msg_Err(va, "D3D11CreateDevice failed. (hr=0x%lX)", hr);
return VLC_EGENERIC;
}
- dx_sys->d3ddev = d3ddev;
- va->sys->d3dctx = d3dctx;
+ dx_sys->d3ddev = hd3d11.d3ddevice;
+ va->sys->d3dctx = hd3d11.d3dcontext;
void *d3dvidctx = NULL;
- hr = ID3D11DeviceContext_QueryInterface(d3dctx, &IID_ID3D11VideoContext, &d3dvidctx);
+ hr = ID3D11DeviceContext_QueryInterface(dx_sys->d3ddev, &IID_ID3D11VideoContext, &d3dvidctx);
if (FAILED(hr)) {
msg_Err(va, "Could not Query ID3D11VideoContext Interface. (hr=0x%lX)", hr);
return VLC_EGENERIC;
diff --git a/modules/video_chroma/d3d11_fmt.c b/modules/video_chroma/d3d11_fmt.c
index 2847474c4f..7ae6fecee2 100644
--- a/modules/video_chroma/d3d11_fmt.c
+++ b/modules/video_chroma/d3d11_fmt.c
@@ -132,8 +132,7 @@ int AllocateShaderView(vlc_object_t *obj, ID3D11Device *d3ddevice,
HRESULT D3D11_CreateDevice(vlc_object_t *obj, HINSTANCE hdecoder_dll,
bool hw_decoding,
- ID3D11Device **pp_d3ddevice,
- ID3D11DeviceContext **pp_d3dcontext)
+ d3d11_handle_t *p_hd3d11)
{
#if !VLC_WINSTORE_APP
# define D3D11CreateDevice(args...) pf_CreateDevice(args)
@@ -182,21 +181,21 @@ HRESULT D3D11_CreateDevice(vlc_object_t *obj, HINSTANCE hdecoder_dll,
D3D_FEATURE_LEVEL i_feature_level;
hr = D3D11CreateDevice(NULL, driverAttempts[driver], NULL, creationFlags,
D3D11_features, ARRAY_SIZE(D3D11_features), D3D11_SDK_VERSION,
- pp_d3ddevice, &i_feature_level, pp_d3dcontext);
+ &p_hd3d11->d3ddevice, &i_feature_level, &p_hd3d11->d3dcontext);
if (SUCCEEDED(hr)) {
#ifndef NDEBUG
msg_Dbg(obj, "Created the D3D11 device 0x%p ctx 0x%p type %d level %x.",
- (void *)*pp_d3ddevice, (void *)*pp_d3dcontext,
+ (void *)p_hd3d11->d3ddevice, (void *)p_hd3d11->d3dcontext,
driverAttempts[driver], i_feature_level);
#endif
/* we can work with legacy levels but only if forced */
if ( obj->obj.force || i_feature_level >= D3D_FEATURE_LEVEL_11_0 )
break;
msg_Dbg(obj, "Incompatible feature level %x", i_feature_level);
- ID3D11DeviceContext_Release(*pp_d3dcontext);
- *pp_d3dcontext = NULL;
- ID3D11Device_Release(*pp_d3ddevice);
- *pp_d3ddevice = NULL;
+ ID3D11DeviceContext_Release(p_hd3d11->d3dcontext);
+ ID3D11Device_Release(p_hd3d11->d3ddevice);
+ p_hd3d11->d3dcontext = NULL;
+ p_hd3d11->d3ddevice = NULL;
hr = E_NOTIMPL;
}
}
diff --git a/modules/video_chroma/d3d11_fmt.h b/modules/video_chroma/d3d11_fmt.h
index ee66ca6222..1f17d490b8 100644
--- a/modules/video_chroma/d3d11_fmt.h
+++ b/modules/video_chroma/d3d11_fmt.h
@@ -29,6 +29,12 @@
DEFINE_GUID(GUID_CONTEXT_MUTEX, 0x472e8835, 0x3f8e, 0x4f93, 0xa0, 0xcb, 0x25, 0x79, 0x77, 0x6c, 0xed, 0x86);
+typedef struct
+{
+ ID3D11Device *d3ddevice; /* D3D device */
+ ID3D11DeviceContext *d3dcontext; /* D3D context */
+} d3d11_handle_t;
+
/* owned by the vout for VLC_CODEC_D3D11_OPAQUE */
struct picture_sys_t
{
@@ -65,8 +71,7 @@ int AllocateShaderView(vlc_object_t *obj, ID3D11Device *d3ddevice,
HRESULT D3D11_CreateDevice(vlc_object_t *obj, HINSTANCE hdecoder_dll,
bool hw_decoding,
- ID3D11Device **pp_d3ddevice,
- ID3D11DeviceContext **pp_d3dcontext);
+ d3d11_handle_t *p_hd3d11);
bool isXboxHardware(ID3D11Device *d3ddev);
bool isNvidiaHardware(ID3D11Device *d3ddev);
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index ea15485ad6..a4bdca756c 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -150,8 +150,7 @@ struct vout_display_sys_t
#endif
IDXGISwapChain1 *dxgiswapChain; /* DXGI 1.2 swap chain */
IDXGISwapChain4 *dxgiswapChain4; /* DXGI 1.5 for HDR */
- ID3D11Device *d3ddevice; /* D3D device */
- ID3D11DeviceContext *d3dcontext; /* D3D context */
+ d3d11_handle_t hd3d11;
d3d_quad_t picQuad;
const d3d_format_t *picQuadConfig;
ID3D11PixelShader *picQuadPixelShader;
@@ -467,11 +466,11 @@ static int OpenCoreW(vout_display_t *vd)
return VLC_ENOMEM;
sys->dxgiswapChain = dxgiswapChain;
- sys->d3ddevice = d3ddevice;
- sys->d3dcontext = d3dcontext;
+ sys->hd3d11.d3ddevice = d3ddevice;
+ sys->hd3d11.d3dcontext = d3dcontext;
IDXGISwapChain_AddRef (sys->dxgiswapChain);
- ID3D11Device_AddRef (sys->d3ddevice);
- ID3D11DeviceContext_AddRef(sys->d3dcontext);
+ ID3D11Device_AddRef (sys->hd3d11.d3ddevice);
+ ID3D11DeviceContext_AddRef(sys->hd3d11.d3dcontext);
return VLC_SUCCESS;
}
@@ -639,7 +638,7 @@ static int AllocateTextures(vout_display_t *vd, const d3d_format_t *cfg,
texDesc.Height = fmt->i_height;
texDesc.Width = fmt->i_width;
- hr = ID3D11Device_CreateTexture2D( sys->d3ddevice, &texDesc, NULL, &slicedTexture );
+ hr = ID3D11Device_CreateTexture2D( sys->hd3d11.d3ddevice, &texDesc, NULL, &slicedTexture );
if (FAILED(hr)) {
msg_Err(vd, "CreateTexture2D failed for the %d pool. (hr=0x%0lx)", pool_size, hr);
goto error;
@@ -655,7 +654,7 @@ static int AllocateTextures(vout_display_t *vd, const d3d_format_t *cfg,
} else {
texDesc.Height = planes[plane].i_lines;
texDesc.Width = planes[plane].i_pitch;
- hr = ID3D11Device_CreateTexture2D( sys->d3ddevice, &texDesc, NULL, &textures[picture_count * D3D11_MAX_SHADER_VIEW + plane] );
+ hr = ID3D11Device_CreateTexture2D( sys->hd3d11.d3ddevice, &texDesc, NULL, &textures[picture_count * D3D11_MAX_SHADER_VIEW + plane] );
if (FAILED(hr)) {
msg_Err(vd, "CreateTexture2D failed for the %d pool. (hr=0x%0lx)", pool_size, hr);
goto error;
@@ -675,12 +674,12 @@ static int AllocateTextures(vout_display_t *vd, const d3d_format_t *cfg,
if (!is_d3d11_opaque(fmt->i_chroma) && cfg->formatTexture != DXGI_FORMAT_UNKNOWN) {
D3D11_MAPPED_SUBRESOURCE mappedResource;
- hr = ID3D11DeviceContext_Map(sys->d3dcontext, (ID3D11Resource*)textures[0], 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
+ hr = ID3D11DeviceContext_Map(sys->hd3d11.d3dcontext, (ID3D11Resource*)textures[0], 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if( FAILED(hr) ) {
msg_Err(vd, "The texture cannot be mapped. (hr=0x%lX)", hr);
goto error;
}
- ID3D11DeviceContext_Unmap(sys->d3dcontext, (ID3D11Resource*)textures[0], 0);
+ ID3D11DeviceContext_Unmap(sys->hd3d11.d3dcontext, (ID3D11Resource*)textures[0], 0);
if (mappedResource.RowPitch < p_chroma_desc->pixel_size * texDesc.Width) {
msg_Err( vd, "The texture row pitch is too small (%d instead of %d)", mappedResource.RowPitch,
p_chroma_desc->pixel_size * texDesc.Width );
@@ -721,7 +720,7 @@ static picture_pool_t *Pool(vout_display_t *vd, unsigned pool_size)
if (!vd->info.is_slow) {
HRESULT hr;
ID3D10Multithread *pMultithread;
- hr = ID3D11Device_QueryInterface( sys->d3ddevice, &IID_ID3D10Multithread, (void **)&pMultithread);
+ hr = ID3D11Device_QueryInterface( sys->hd3d11.d3ddevice, &IID_ID3D10Multithread, (void **)&pMultithread);
if (SUCCEEDED(hr)) {
ID3D10Multithread_SetMultithreadProtected(pMultithread, TRUE);
ID3D10Multithread_Release(pMultithread);
@@ -747,7 +746,7 @@ static picture_pool_t *Pool(vout_display_t *vd, unsigned pool_size)
picsys->slice_index = picture_count;
picsys->formatTexture = sys->picQuadConfig->formatTexture;
- picsys->context = sys->d3dcontext;
+ picsys->context = sys->hd3d11.d3dcontext;
picture_resource_t resource = {
.p_sys = picsys,
@@ -779,14 +778,14 @@ static picture_pool_t *Pool(vout_display_t *vd, unsigned pool_size)
for (unsigned plane = 0; plane < D3D11_MAX_SHADER_VIEW; plane++)
sys->stagingSys.texture[plane] = textures[plane];
- if (AllocateShaderView(VLC_OBJECT(vd), sys->d3ddevice, sys->picQuadConfig,
+ if (AllocateShaderView(VLC_OBJECT(vd), sys->hd3d11.d3ddevice, sys->picQuadConfig,
textures, 0, sys->stagingSys.resourceView))
goto error;
} else
#endif
{
for (picture_count = 0; picture_count < pool_size; picture_count++) {
- if (AllocateShaderView(VLC_OBJECT(vd), sys->d3ddevice, sys->picQuadConfig,
+ if (AllocateShaderView(VLC_OBJECT(vd), sys->hd3d11.d3ddevice, sys->picQuadConfig,
pictures[picture_count]->p_sys->texture, picture_count,
pictures[picture_count]->p_sys->resourceView))
goto error;
@@ -831,7 +830,7 @@ error:
sys->sys.pool = picture_pool_NewExtended( &pool_cfg );
} else {
msg_Dbg(vd, "D3D11 pool succeed with %d surfaces (%dx%d) context 0x%p",
- picture_count, surface_fmt.i_width, surface_fmt.i_height, sys->d3dcontext);
+ picture_count, surface_fmt.i_width, surface_fmt.i_height, sys->hd3d11.d3dcontext);
}
return sys->sys.pool;
}
@@ -881,7 +880,7 @@ static HRESULT UpdateBackBuffer(vout_display_t *vd)
return hr;
}
- hr = ID3D11Device_CreateRenderTargetView(sys->d3ddevice, (ID3D11Resource *)pBackBuffer, NULL, &sys->d3drenderTargetView);
+ hr = ID3D11Device_CreateRenderTargetView(sys->hd3d11.d3ddevice, (ID3D11Resource *)pBackBuffer, NULL, &sys->d3drenderTargetView);
ID3D11Texture2D_Release(pBackBuffer);
if (FAILED(hr)) {
msg_Err(vd, "Failed to create the target view. (hr=0x%lX)", hr);
@@ -902,7 +901,7 @@ static HRESULT UpdateBackBuffer(vout_display_t *vd)
deptTexDesc.SampleDesc.Quality = 0;
deptTexDesc.Usage = D3D11_USAGE_DEFAULT;
- hr = ID3D11Device_CreateTexture2D(sys->d3ddevice, &deptTexDesc, NULL, &pDepthStencil);
+ hr = ID3D11Device_CreateTexture2D(sys->hd3d11.d3ddevice, &deptTexDesc, NULL, &pDepthStencil);
if (FAILED(hr)) {
msg_Err(vd, "Could not create the depth stencil texture. (hr=0x%lX)", hr);
return hr;
@@ -915,7 +914,7 @@ static HRESULT UpdateBackBuffer(vout_display_t *vd)
depthViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
depthViewDesc.Texture2D.MipSlice = 0;
- hr = ID3D11Device_CreateDepthStencilView(sys->d3ddevice, (ID3D11Resource *)pDepthStencil, &depthViewDesc, &sys->d3ddepthStencilView);
+ hr = ID3D11Device_CreateDepthStencilView(sys->hd3d11.d3ddevice, (ID3D11Resource *)pDepthStencil, &depthViewDesc, &sys->d3ddepthStencilView);
ID3D11Texture2D_Release(pDepthStencil);
if (FAILED(hr)) {
@@ -1062,7 +1061,7 @@ static void SetQuadVSProjection(vout_display_t *vd, d3d_quad_t *quad, const vlc_
vout_display_sys_t *sys = vd->sys;
HRESULT hr;
D3D11_MAPPED_SUBRESOURCE mapped;
- hr = ID3D11DeviceContext_Map(sys->d3dcontext, (ID3D11Resource *)quad->pVertexShaderConstants, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
+ hr = ID3D11DeviceContext_Map(sys->hd3d11.d3dcontext, (ID3D11Resource *)quad->pVertexShaderConstants, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
if (SUCCEEDED(hr)) {
VS_PROJECTION_CONST *dst_data = mapped.pData;
getXRotMatrix(f_phi, dst_data->RotX);
@@ -1071,7 +1070,7 @@ static void SetQuadVSProjection(vout_display_t *vd, d3d_quad_t *quad, const vlc_
getZoomMatrix(SPHERE_RADIUS * f_z, dst_data->View);
getProjectionMatrix(f_sar, f_fovy, dst_data->Projection);
}
- ID3D11DeviceContext_Unmap(sys->d3dcontext, (ID3D11Resource *)quad->pVertexShaderConstants, 0);
+ ID3D11DeviceContext_Unmap(sys->hd3d11.d3dcontext, (ID3D11Resource *)quad->pVertexShaderConstants, 0);
#undef RAD
}
@@ -1175,22 +1174,22 @@ static void DisplayD3DPicture(vout_display_sys_t *sys, d3d_quad_t *quad, ID3D11S
/* Render the quad */
/* vertex shader */
- ID3D11DeviceContext_IASetVertexBuffers(sys->d3dcontext, 0, 1, &quad->pVertexBuffer, &stride, &offset);
- ID3D11DeviceContext_IASetIndexBuffer(sys->d3dcontext, quad->pIndexBuffer, DXGI_FORMAT_R16_UINT, 0);
+ ID3D11DeviceContext_IASetVertexBuffers(sys->hd3d11.d3dcontext, 0, 1, &quad->pVertexBuffer, &stride, &offset);
+ ID3D11DeviceContext_IASetIndexBuffer(sys->hd3d11.d3dcontext, quad->pIndexBuffer, DXGI_FORMAT_R16_UINT, 0);
if ( quad->pVertexShaderConstants )
- ID3D11DeviceContext_VSSetConstantBuffers(sys->d3dcontext, 0, 1, &quad->pVertexShaderConstants);
+ ID3D11DeviceContext_VSSetConstantBuffers(sys->hd3d11.d3dcontext, 0, 1, &quad->pVertexShaderConstants);
- ID3D11DeviceContext_VSSetShader(sys->d3dcontext, quad->d3dvertexShader, NULL, 0);
+ ID3D11DeviceContext_VSSetShader(sys->hd3d11.d3dcontext, quad->d3dvertexShader, NULL, 0);
/* pixel shader */
- ID3D11DeviceContext_PSSetShader(sys->d3dcontext, quad->d3dpixelShader, NULL, 0);
+ ID3D11DeviceContext_PSSetShader(sys->hd3d11.d3dcontext, quad->d3dpixelShader, NULL, 0);
- ID3D11DeviceContext_PSSetConstantBuffers(sys->d3dcontext, 0, quad->PSConstantsCount, quad->pPixelShaderConstants);
- ID3D11DeviceContext_PSSetShaderResources(sys->d3dcontext, 0, D3D11_MAX_SHADER_VIEW, resourceView);
+ ID3D11DeviceContext_PSSetConstantBuffers(sys->hd3d11.d3dcontext, 0, quad->PSConstantsCount, quad->pPixelShaderConstants);
+ ID3D11DeviceContext_PSSetShaderResources(sys->hd3d11.d3dcontext, 0, D3D11_MAX_SHADER_VIEW, resourceView);
- ID3D11DeviceContext_RSSetViewports(sys->d3dcontext, 1, &quad->cropViewport);
+ ID3D11DeviceContext_RSSetViewports(sys->hd3d11.d3dcontext, 1, &quad->cropViewport);
- ID3D11DeviceContext_DrawIndexed(sys->d3dcontext, quad->indexCount, 0, 0);
+ ID3D11DeviceContext_DrawIndexed(sys->hd3d11.d3dcontext, quad->indexCount, 0, 0);
}
static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
@@ -1205,7 +1204,7 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic
HRESULT hr;
for (i = 0; i < picture->i_planes; i++) {
- hr = ID3D11DeviceContext_Map(sys->d3dcontext, sys->stagingSys.resource[i],
+ hr = ID3D11DeviceContext_Map(sys->hd3d11.d3dcontext, sys->stagingSys.resource[i],
0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if( FAILED(hr) )
break;
@@ -1217,7 +1216,7 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic
texture_plane.i_visible_lines = picture->p[i].i_visible_lines;
texture_plane.i_visible_pitch = picture->p[i].i_visible_pitch;
plane_CopyPixels(&texture_plane, &picture->p[i]);
- ID3D11DeviceContext_Unmap(sys->d3dcontext, sys->stagingSys.resource[i], 0);
+ ID3D11DeviceContext_Unmap(sys->hd3d11.d3dcontext, sys->stagingSys.resource[i], 0);
}
}
else
@@ -1248,7 +1247,7 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic
}
assert(box.right <= texDesc.Width);
assert(box.bottom <= texDesc.Height);
- ID3D11DeviceContext_CopySubresourceRegion(sys->d3dcontext,
+ ID3D11DeviceContext_CopySubresourceRegion(sys->hd3d11.d3dcontext,
sys->stagingSys.resource[KNOWN_DXGI_INDEX],
0, 0, 0, 0,
p_sys->resource[KNOWN_DXGI_INDEX],
@@ -1291,13 +1290,13 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic
}
FLOAT blackRGBA[4] = {0.0f, 0.0f, 0.0f, 1.0f};
- ID3D11DeviceContext_ClearRenderTargetView(sys->d3dcontext, sys->d3drenderTargetView, blackRGBA);
+ ID3D11DeviceContext_ClearRenderTargetView(sys->hd3d11.d3dcontext, sys->d3drenderTargetView, blackRGBA);
/* no ID3D11Device operations should come here */
- ID3D11DeviceContext_OMSetRenderTargets(sys->d3dcontext, 1, &sys->d3drenderTargetView, sys->d3ddepthStencilView);
+ ID3D11DeviceContext_OMSetRenderTargets(sys->hd3d11.d3dcontext, 1, &sys->d3drenderTargetView, sys->d3ddepthStencilView);
- ID3D11DeviceContext_ClearDepthStencilView(sys->d3dcontext, sys->d3ddepthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
+ ID3D11DeviceContext_ClearDepthStencilView(sys->hd3d11.d3dcontext, sys->d3ddepthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
/* Render the quad */
if (!is_d3d11_opaque(picture->format.i_chroma) || sys->legacy_shader)
@@ -1343,7 +1342,7 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic
IDXGISwapChain4_SetHDRMetaData(sys->dxgiswapChain4, DXGI_HDR_METADATA_TYPE_HDR10, sizeof(hdr10), &hdr10);
}
- ID3D11DeviceContext_Flush(sys->d3dcontext);
+ ID3D11DeviceContext_Flush(sys->hd3d11.d3dcontext);
}
static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
@@ -1554,13 +1553,13 @@ static const d3d_format_t *GetDirectRenderingFormat(vout_display_t *vd, vlc_four
UINT supportFlags = D3D11_FORMAT_SUPPORT_SHADER_LOAD;
if (is_d3d11_opaque(i_src_chroma))
supportFlags |= D3D11_FORMAT_SUPPORT_DECODER_OUTPUT;
- return FindD3D11Format( vd->sys->d3ddevice, i_src_chroma, 0, is_d3d11_opaque(i_src_chroma), supportFlags );
+ return FindD3D11Format( vd->sys->hd3d11.d3ddevice, i_src_chroma, 0, is_d3d11_opaque(i_src_chroma), supportFlags );
}
static const d3d_format_t *GetDirectDecoderFormat(vout_display_t *vd, vlc_fourcc_t i_src_chroma)
{
UINT supportFlags = D3D11_FORMAT_SUPPORT_DECODER_OUTPUT;
- return FindD3D11Format( vd->sys->d3ddevice, i_src_chroma, 0, is_d3d11_opaque(i_src_chroma), supportFlags );
+ return FindD3D11Format( vd->sys->hd3d11.d3ddevice, i_src_chroma, 0, is_d3d11_opaque(i_src_chroma), supportFlags );
}
static const d3d_format_t *GetDisplayFormatByDepth(vout_display_t *vd, uint8_t bit_depth, bool from_processor)
@@ -1568,13 +1567,13 @@ static const d3d_format_t *GetDisplayFormatByDepth(vout_display_t *vd, uint8_t b
UINT supportFlags = D3D11_FORMAT_SUPPORT_SHADER_LOAD;
if (from_processor)
supportFlags |= D3D11_FORMAT_SUPPORT_VIDEO_PROCESSOR_OUTPUT;
- return FindD3D11Format( vd->sys->d3ddevice, 0, bit_depth, false, supportFlags );
+ return FindD3D11Format( vd->sys->hd3d11.d3ddevice, 0, bit_depth, false, supportFlags );
}
static const d3d_format_t *GetBlendableFormat(vout_display_t *vd, vlc_fourcc_t i_src_chroma)
{
UINT supportFlags = D3D11_FORMAT_SUPPORT_SHADER_LOAD | D3D11_FORMAT_SUPPORT_BLENDABLE;
- return FindD3D11Format( vd->sys->d3ddevice, i_src_chroma, 0, false, supportFlags );
+ return FindD3D11Format( vd->sys->hd3d11.d3ddevice, i_src_chroma, 0, false, supportFlags );
}
static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
@@ -1607,13 +1606,13 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
hr = D3D11_CreateDevice(VLC_OBJECT(vd), sys->hd3d11_dll,
is_d3d11_opaque(fmt->i_chroma),
- &sys->d3ddevice, &sys->d3dcontext);
+ &sys->hd3d11);
if (FAILED(hr)) {
msg_Err(vd, "Could not Create the D3D11 device. (hr=0x%lX)", hr);
return VLC_EGENERIC;
}
- IDXGIAdapter *dxgiadapter = D3D11DeviceAdapter(sys->d3ddevice);
+ IDXGIAdapter *dxgiadapter = D3D11DeviceAdapter(sys->hd3d11.d3ddevice);
if (unlikely(dxgiadapter==NULL)) {
msg_Err(vd, "Could not get the DXGI Adapter");
return VLC_EGENERIC;
@@ -1626,7 +1625,7 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
return VLC_EGENERIC;
}
- hr = IDXGIFactory2_CreateSwapChainForHwnd(dxgifactory, (IUnknown *)sys->d3ddevice,
+ hr = IDXGIFactory2_CreateSwapChainForHwnd(dxgifactory, (IUnknown *)sys->hd3d11.d3ddevice,
sys->sys.hvideownd, &scd, NULL, NULL, &sys->dxgiswapChain);
IDXGIFactory2_Release(dxgifactory);
if (FAILED(hr)) {
@@ -1731,16 +1730,16 @@ static void Direct3D11Close(vout_display_t *vd)
vout_display_sys_t *sys = vd->sys;
Direct3D11DestroyResources(vd);
- if (sys->d3dcontext)
+ if (sys->hd3d11.d3dcontext)
{
- ID3D11DeviceContext_Flush(sys->d3dcontext);
- ID3D11DeviceContext_Release(sys->d3dcontext);
- sys->d3dcontext = NULL;
+ ID3D11DeviceContext_Flush(sys->hd3d11.d3dcontext);
+ ID3D11DeviceContext_Release(sys->hd3d11.d3dcontext);
+ sys->hd3d11.d3dcontext = NULL;
}
- if (sys->d3ddevice)
+ if (sys->hd3d11.d3ddevice)
{
- ID3D11Device_Release(sys->d3ddevice);
- sys->d3ddevice = NULL;
+ ID3D11Device_Release(sys->hd3d11.d3ddevice);
+ sys->hd3d11.d3ddevice = NULL;
}
if (sys->dxgiswapChain4)
{
@@ -2074,7 +2073,7 @@ static HRESULT CompilePixelShader(vout_display_t *vd, const d3d_format_t *format
if (!pPSBlob)
return E_INVALIDARG;
- HRESULT hr = ID3D11Device_CreatePixelShader(sys->d3ddevice,
+ HRESULT hr = ID3D11Device_CreatePixelShader(sys->hd3d11.d3ddevice,
(void *)ID3D10Blob_GetBufferPointer(pPSBlob),
ID3D10Blob_GetBufferSize(pPSBlob), NULL, output);
@@ -2119,7 +2118,7 @@ static bool CanUseTextureArray(vout_display_t *vd)
vout_display_sys_t *sys = vd->sys;
TCHAR szData[256];
DWORD len = 256;
- IDXGIAdapter *pAdapter = D3D11DeviceAdapter(sys->d3ddevice);
+ IDXGIAdapter *pAdapter = D3D11DeviceAdapter(sys->hd3d11.d3ddevice);
if (!pAdapter)
return false;
@@ -2164,7 +2163,7 @@ static int Direct3D11CreateResources(vout_display_t *vd, video_format_t *fmt)
#if defined(HAVE_ID3D11VIDEODECODER)
sys->context_lock = CreateMutexEx( NULL, NULL, 0, SYNCHRONIZE );
- ID3D11Device_SetPrivateData( sys->d3ddevice, &GUID_CONTEXT_MUTEX, sizeof( sys->context_lock ), &sys->context_lock );
+ ID3D11Device_SetPrivateData( sys->hd3d11.d3ddevice, &GUID_CONTEXT_MUTEX, sizeof( sys->context_lock ), &sys->context_lock );
#endif
hr = UpdateBackBuffer(vd);
@@ -2196,12 +2195,12 @@ static int Direct3D11CreateResources(vout_display_t *vd, video_format_t *fmt)
spuBlendDesc.RenderTarget[1].BlendOpAlpha = D3D11_BLEND_OP_ADD;
spuBlendDesc.RenderTarget[1].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
- hr = ID3D11Device_CreateBlendState(sys->d3ddevice, &spuBlendDesc, &pSpuBlendState);
+ hr = ID3D11Device_CreateBlendState(sys->hd3d11.d3ddevice, &spuBlendDesc, &pSpuBlendState);
if (FAILED(hr)) {
msg_Err(vd, "Could not create SPU blend state. (hr=0x%lX)", hr);
return VLC_EGENERIC;
}
- ID3D11DeviceContext_OMSetBlendState(sys->d3dcontext, pSpuBlendState, NULL, 0xFFFFFFFF);
+ ID3D11DeviceContext_OMSetBlendState(sys->hd3d11.d3dcontext, pSpuBlendState, NULL, 0xFFFFFFFF);
ID3D11BlendState_Release(pSpuBlendState);
/* disable depth testing as we're only doing 2D
@@ -2212,9 +2211,9 @@ static int Direct3D11CreateResources(vout_display_t *vd, video_format_t *fmt)
ZeroMemory(&stencilDesc, sizeof(stencilDesc));
ID3D11DepthStencilState *pDepthStencilState;
- hr = ID3D11Device_CreateDepthStencilState(sys->d3ddevice, &stencilDesc, &pDepthStencilState );
+ hr = ID3D11Device_CreateDepthStencilState(sys->hd3d11.d3ddevice, &stencilDesc, &pDepthStencilState );
if (SUCCEEDED(hr)) {
- ID3D11DeviceContext_OMSetDepthStencilState(sys->d3dcontext, pDepthStencilState, 0);
+ ID3D11DeviceContext_OMSetDepthStencilState(sys->hd3d11.d3dcontext, pDepthStencilState, 0);
ID3D11DepthStencilState_Release(pDepthStencilState);
}
@@ -2255,7 +2254,7 @@ static int Direct3D11CreateResources(vout_display_t *vd, video_format_t *fmt)
if (!pVSBlob)
return VLC_EGENERIC;
- hr = ID3D11Device_CreateVertexShader(sys->d3ddevice, (void *)ID3D10Blob_GetBufferPointer(pVSBlob),
+ hr = ID3D11Device_CreateVertexShader(sys->hd3d11.d3ddevice, (void *)ID3D10Blob_GetBufferPointer(pVSBlob),
ID3D10Blob_GetBufferSize(pVSBlob), NULL, &sys->flatVSShader);
if(FAILED(hr)) {
@@ -2270,7 +2269,7 @@ static int Direct3D11CreateResources(vout_display_t *vd, video_format_t *fmt)
};
ID3D11InputLayout* pVertexLayout = NULL;
- hr = ID3D11Device_CreateInputLayout(sys->d3ddevice, layout, 2, (void *)ID3D10Blob_GetBufferPointer(pVSBlob),
+ hr = ID3D11Device_CreateInputLayout(sys->hd3d11.d3ddevice, layout, 2, (void *)ID3D10Blob_GetBufferPointer(pVSBlob),
ID3D10Blob_GetBufferSize(pVSBlob), &pVertexLayout);
ID3D10Blob_Release(pVSBlob);
@@ -2279,14 +2278,14 @@ static int Direct3D11CreateResources(vout_display_t *vd, video_format_t *fmt)
msg_Err(vd, "Failed to create the vertex input layout. (hr=0x%lX)", hr);
return VLC_EGENERIC;
}
- ID3D11DeviceContext_IASetInputLayout(sys->d3dcontext, pVertexLayout);
+ ID3D11DeviceContext_IASetInputLayout(sys->hd3d11.d3dcontext, pVertexLayout);
ID3D11InputLayout_Release(pVertexLayout);
pVSBlob = CompileShader(vd, globVertexShaderProjection, false);
if (!pVSBlob)
return VLC_EGENERIC;
- hr = ID3D11Device_CreateVertexShader(sys->d3ddevice, (void *)ID3D10Blob_GetBufferPointer(pVSBlob),
+ hr = ID3D11Device_CreateVertexShader(sys->hd3d11.d3ddevice, (void *)ID3D10Blob_GetBufferPointer(pVSBlob),
ID3D10Blob_GetBufferSize(pVSBlob), NULL, &sys->projectionVSShader);
if(FAILED(hr)) {
@@ -2296,7 +2295,7 @@ static int Direct3D11CreateResources(vout_display_t *vd, video_format_t *fmt)
}
ID3D10Blob_Release(pVSBlob);
- ID3D11DeviceContext_IASetPrimitiveTopology(sys->d3dcontext, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
+ ID3D11DeviceContext_IASetPrimitiveTopology(sys->hd3d11.d3dcontext, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
UpdatePicQuadPosition(vd);
@@ -2311,13 +2310,13 @@ static int Direct3D11CreateResources(vout_display_t *vd, video_format_t *fmt)
sampDesc.MaxLOD = D3D11_FLOAT32_MAX;
ID3D11SamplerState *d3dsampState;
- hr = ID3D11Device_CreateSamplerState(sys->d3ddevice, &sampDesc, &d3dsampState);
+ hr = ID3D11Device_CreateSamplerState(sys->hd3d11.d3ddevice, &sampDesc, &d3dsampState);
if (FAILED(hr)) {
msg_Err(vd, "Could not Create the D3d11 Sampler State. (hr=0x%lX)", hr);
return VLC_EGENERIC;
}
- ID3D11DeviceContext_PSSetSamplers(sys->d3dcontext, 0, 1, &d3dsampState);
+ ID3D11DeviceContext_PSSetSamplers(sys->hd3d11.d3dcontext, 0, 1, &d3dsampState);
ID3D11SamplerState_Release(d3dsampState);
msg_Dbg(vd, "Direct3D11 resources created");
@@ -2554,7 +2553,7 @@ static bool AllocQuadVertices(vout_display_t *vd, d3d_quad_t *quad,
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
- hr = ID3D11Device_CreateBuffer(sys->d3ddevice, &bd, NULL, &quad->pVertexBuffer);
+ hr = ID3D11Device_CreateBuffer(sys->hd3d11.d3ddevice, &bd, NULL, &quad->pVertexBuffer);
if(FAILED(hr)) {
msg_Err(vd, "Failed to create vertex buffer. (hr=%lX)", hr);
return false;
@@ -2568,7 +2567,7 @@ static bool AllocQuadVertices(vout_display_t *vd, d3d_quad_t *quad,
.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE,
};
- hr = ID3D11Device_CreateBuffer(sys->d3ddevice, &quadDesc, NULL, &quad->pIndexBuffer);
+ hr = ID3D11Device_CreateBuffer(sys->hd3d11.d3ddevice, &quadDesc, NULL, &quad->pIndexBuffer);
if(FAILED(hr)) {
msg_Err(vd, "Could not create the quad indices. (hr=0x%lX)", hr);
return false;
@@ -2587,7 +2586,7 @@ static bool UpdateQuadPosition( vout_display_t *vd, d3d_quad_t *quad,
D3D11_MAPPED_SUBRESOURCE mappedResource;
/* create the vertices */
- hr = ID3D11DeviceContext_Map(sys->d3dcontext, (ID3D11Resource *)quad->pVertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
+ hr = ID3D11DeviceContext_Map(sys->hd3d11.d3dcontext, (ID3D11Resource *)quad->pVertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(hr)) {
msg_Err(vd, "Failed to lock the vertex buffer (hr=0x%lX)", hr);
return false;
@@ -2595,10 +2594,10 @@ static bool UpdateQuadPosition( vout_display_t *vd, d3d_quad_t *quad,
d3d_vertex_t *dst_data = mappedResource.pData;
/* create the vertex indices */
- hr = ID3D11DeviceContext_Map(sys->d3dcontext, (ID3D11Resource *)quad->pIndexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
+ hr = ID3D11DeviceContext_Map(sys->hd3d11.d3dcontext, (ID3D11Resource *)quad->pIndexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(hr)) {
msg_Err(vd, "Failed to lock the index buffer (hr=0x%lX)", hr);
- ID3D11DeviceContext_Unmap(sys->d3dcontext, (ID3D11Resource *)quad->pVertexBuffer, 0);
+ ID3D11DeviceContext_Unmap(sys->hd3d11.d3dcontext, (ID3D11Resource *)quad->pVertexBuffer, 0);
return false;
}
WORD *triangle_pos = mappedResource.pData;
@@ -2608,8 +2607,8 @@ static bool UpdateQuadPosition( vout_display_t *vd, d3d_quad_t *quad,
else
SetupQuadSphere(dst_data, triangle_pos);
- ID3D11DeviceContext_Unmap(sys->d3dcontext, (ID3D11Resource *)quad->pIndexBuffer, 0);
- ID3D11DeviceContext_Unmap(sys->d3dcontext, (ID3D11Resource *)quad->pVertexBuffer, 0);
+ ID3D11DeviceContext_Unmap(sys->hd3d11.d3dcontext, (ID3D11Resource *)quad->pIndexBuffer, 0);
+ ID3D11DeviceContext_Unmap(sys->hd3d11.d3dcontext, (ID3D11Resource *)quad->pVertexBuffer, 0);
return true;
}
@@ -2635,7 +2634,7 @@ static int SetupQuad(vout_display_t *vd, const video_format_t *fmt, d3d_quad_t *
.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE,
};
D3D11_SUBRESOURCE_DATA constantInit = { .pSysMem = &defaultConstants };
- hr = ID3D11Device_CreateBuffer(sys->d3ddevice, &constantDesc, &constantInit, &quad->pPixelShaderConstants[0]);
+ hr = ID3D11Device_CreateBuffer(sys->hd3d11.d3ddevice, &constantDesc, &constantInit, &quad->pPixelShaderConstants[0]);
if(FAILED(hr)) {
msg_Err(vd, "Could not create the pixel shader constant buffer. (hr=0x%lX)", hr);
goto error;
@@ -2738,7 +2737,7 @@ static int SetupQuad(vout_display_t *vd, const video_format_t *fmt, d3d_quad_t *
static_assert((sizeof(PS_COLOR_TRANSFORM)%16)==0,"Constant buffers require 16-byte alignment");
constantDesc.ByteWidth = sizeof(PS_COLOR_TRANSFORM);
- hr = ID3D11Device_CreateBuffer(sys->d3ddevice, &constantDesc, &constantInit, &quad->pPixelShaderConstants[1]);
+ hr = ID3D11Device_CreateBuffer(sys->hd3d11.d3ddevice, &constantDesc, &constantInit, &quad->pPixelShaderConstants[1]);
if(FAILED(hr)) {
msg_Err(vd, "Could not create the pixel shader constant buffer. (hr=0x%lX)", hr);
goto error;
@@ -2750,7 +2749,7 @@ static int SetupQuad(vout_display_t *vd, const video_format_t *fmt, d3d_quad_t *
{
constantDesc.ByteWidth = sizeof(VS_PROJECTION_CONST);
static_assert((sizeof(VS_PROJECTION_CONST)%16)==0,"Constant buffers require 16-byte alignment");
- hr = ID3D11Device_CreateBuffer(sys->d3ddevice, &constantDesc, NULL, &quad->pVertexShaderConstants);
+ hr = ID3D11Device_CreateBuffer(sys->hd3d11.d3ddevice, &constantDesc, NULL, &quad->pVertexShaderConstants);
if(FAILED(hr)) {
msg_Err(vd, "Could not create the vertex shader constant buffer. (hr=0x%lX)", hr);
goto error;
@@ -2760,7 +2759,7 @@ static int SetupQuad(vout_display_t *vd, const video_format_t *fmt, d3d_quad_t *
}
quad->picSys.formatTexture = cfg->formatTexture;
- quad->picSys.context = sys->d3dcontext;
+ quad->picSys.context = sys->hd3d11.d3dcontext;
ID3D11DeviceContext_AddRef(quad->picSys.context);
if (!AllocQuadVertices(vd, quad, projection))
@@ -2886,11 +2885,11 @@ static void UpdateQuadOpacity(vout_display_t *vd, const d3d_quad_t *quad, float
vout_display_sys_t *sys = vd->sys;
D3D11_MAPPED_SUBRESOURCE mappedResource;
- HRESULT hr = ID3D11DeviceContext_Map(sys->d3dcontext, (ID3D11Resource *)quad->pPixelShaderConstants[0], 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
+ HRESULT hr = ID3D11DeviceContext_Map(sys->hd3d11.d3dcontext, (ID3D11Resource *)quad->pPixelShaderConstants[0], 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (SUCCEEDED(hr)) {
FLOAT *dst_data = mappedResource.pData;
*dst_data = opacity;
- ID3D11DeviceContext_Unmap(sys->d3dcontext, (ID3D11Resource *)quad->pPixelShaderConstants[0], 0);
+ ID3D11DeviceContext_Unmap(sys->hd3d11.d3dcontext, (ID3D11Resource *)quad->pPixelShaderConstants[0], 0);
}
else {
msg_Err(vd, "Failed to lock the subpicture vertex buffer (hr=0x%lX)", hr);
@@ -2957,7 +2956,7 @@ static int Direct3D11MapSubpicture(vout_display_t *vd, int *subpicture_region_co
for (unsigned plane = 0; plane < D3D11_MAX_SHADER_VIEW; plane++) {
d3dquad->picSys.texture[plane] = textures[plane];
}
- if (AllocateShaderView(VLC_OBJECT(vd), sys->d3ddevice, sys->d3dregion_format,
+ if (AllocateShaderView(VLC_OBJECT(vd), sys->hd3d11.d3ddevice, sys->d3dregion_format,
d3dquad->picSys.texture, 0,
d3dquad->picSys.resourceView)) {
msg_Err(vd, "Failed to create %dx%d shader view for OSD",
@@ -2996,7 +2995,7 @@ static int Direct3D11MapSubpicture(vout_display_t *vd, int *subpicture_region_co
quad_picture = (*region)[i];
}
- hr = ID3D11DeviceContext_Map(sys->d3dcontext, ((d3d_quad_t *) quad_picture->p_sys)->picSys.resource[KNOWN_DXGI_INDEX], 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
+ hr = ID3D11DeviceContext_Map(sys->hd3d11.d3dcontext, ((d3d_quad_t *) quad_picture->p_sys)->picSys.resource[KNOWN_DXGI_INDEX], 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if( SUCCEEDED(hr) ) {
err = CommonUpdatePicture(quad_picture, NULL, mappedResource.pData, mappedResource.RowPitch);
if (err != VLC_SUCCESS) {
@@ -3007,7 +3006,7 @@ static int Direct3D11MapSubpicture(vout_display_t *vd, int *subpicture_region_co
picture_CopyPixels(quad_picture, r->p_picture);
- ID3D11DeviceContext_Unmap(sys->d3dcontext, ((d3d_quad_t *) quad_picture->p_sys)->picSys.resource[KNOWN_DXGI_INDEX], 0);
+ ID3D11DeviceContext_Unmap(sys->hd3d11.d3dcontext, ((d3d_quad_t *) quad_picture->p_sys)->picSys.resource[KNOWN_DXGI_INDEX], 0);
} else {
msg_Err(vd, "Failed to map the SPU texture (hr=0x%lX)", hr );
picture_Release(quad_picture);
--
2.14.2
More information about the vlc-devel
mailing list