Browse Source

d3d_dynamic_shader: make d3d_shader_compiler_t private

This will allow changing the internals without the caller knowing about it.
pull/134/head
Steve Lhomme 5 years ago
committed by Hugo Beauzée-Luyssen
parent
commit
339cfeebba
  1. 36
      modules/video_output/win32/d3d_dynamic_shader.c
  2. 10
      modules/video_output/win32/d3d_dynamic_shader.h
  3. 14
      modules/video_output/win32/direct3d11.cpp

36
modules/video_output/win32/d3d_dynamic_shader.c

@ -35,6 +35,12 @@
#include "d3d_shaders.h"
#include "d3d_dynamic_shader.h"
struct d3d_shader_compiler_t
{
HINSTANCE compiler_dll; /* handle of the opened d3dcompiler dll */
pD3DCompile OurD3DCompile;
};
static const char globPixelShaderDefault[] = "\
#pragma warning( disable: 3571 )\n\
cbuffer PS_CONSTANT_BUFFER : register(b0)\n\
@ -730,25 +736,28 @@ HRESULT D3D_CompileVertexShader(vlc_object_t *obj, const d3d_shader_compiler_t *
}
int D3D_InitShaderCompiler(vlc_object_t *obj, d3d_shader_compiler_t *compiler)
int D3D_CreateShaderCompiler(vlc_object_t *obj, d3d_shader_compiler_t **compiler)
{
*compiler = calloc(1, sizeof(d3d_shader_compiler_t));
if (unlikely(*compiler == NULL))
return VLC_ENOMEM;
#ifndef VLC_WINSTORE_APP
/* d3dcompiler_47 is the latest on windows 10 */
for (int i = 47; i > 41; --i)
{
WCHAR filename[19];
_snwprintf(filename, ARRAY_SIZE(filename), TEXT("D3DCOMPILER_%d.dll"), i);
compiler->compiler_dll = LoadLibrary(filename);
if (compiler->compiler_dll) break;
(*compiler)->compiler_dll = LoadLibrary(filename);
if ((*compiler)->compiler_dll) break;
}
if (compiler->compiler_dll)
{
compiler->OurD3DCompile = (void *)GetProcAddress(compiler->compiler_dll, "D3DCompile");
if (!compiler->OurD3DCompile) {
msg_Err(obj, "Cannot locate reference to D3DCompile in d3dcompiler DLL");
FreeLibrary(compiler->compiler_dll);
return VLC_EGENERIC;
}
if ((*compiler)->compiler_dll)
(*compiler)->OurD3DCompile = (pD3DCompile)((void*)GetProcAddress((*compiler)->compiler_dll, "D3DCompile"));
if (!(*compiler)->OurD3DCompile) {
msg_Err(obj, "Cannot locate reference to D3DCompile in d3dcompiler DLL");
FreeLibrary((*compiler)->compiler_dll);
free(*compiler);
return VLC_EGENERIC;
}
#endif // !VLC_WINSTORE_APP
@ -759,11 +768,8 @@ void D3D_ReleaseShaderCompiler(d3d_shader_compiler_t *compiler)
{
#ifndef VLC_WINSTORE_APP
if (compiler->compiler_dll)
{
FreeLibrary(compiler->compiler_dll);
compiler->compiler_dll = NULL;
}
compiler->OurD3DCompile = NULL;
#endif // !VLC_WINSTORE_APP
free(compiler);
}

10
modules/video_output/win32/d3d_dynamic_shader.h

@ -23,17 +23,15 @@
#ifndef VLC_D3D_DYNAMIC_SHADER_H
#define VLC_D3D_DYNAMIC_SHADER_H
#include <d3dcommon.h>
#ifdef __cplusplus
extern "C" {
#endif// __cplusplus
typedef struct
{
HINSTANCE compiler_dll; /* handle of the opened d3dcompiler dll */
pD3DCompile OurD3DCompile;
} d3d_shader_compiler_t;
typedef struct d3d_shader_compiler_t d3d_shader_compiler_t;
int D3D_InitShaderCompiler(vlc_object_t *, d3d_shader_compiler_t *);
int D3D_CreateShaderCompiler(vlc_object_t *, d3d_shader_compiler_t **);
void D3D_ReleaseShaderCompiler(d3d_shader_compiler_t *);
HRESULT D3D_CompilePixelShader(vlc_object_t *, const d3d_shader_compiler_t *,

14
modules/video_output/win32/direct3d11.cpp

@ -92,7 +92,7 @@ typedef struct vout_display_sys_t
d3d11_device_t *d3d_dev = NULL;
d3d11_decoder_device_t *local_d3d_dev = NULL; // when opened without a video context
d3d_shader_compiler_t shaders = {};
d3d_shader_compiler_t *shaders = nullptr;
d3d11_quad_t picQuad;
#ifdef HAVE_D3D11_4_H
@ -356,7 +356,7 @@ static int Open(vout_display_t *vd,
d3d11_decoder_device_t *dev_sys = NULL;
int ret = D3D_InitShaderCompiler(VLC_OBJECT(vd), &sys->shaders);
int ret = D3D_CreateShaderCompiler(VLC_OBJECT(vd), &sys->shaders);
if (ret != VLC_SUCCESS)
goto error;
@ -452,7 +452,7 @@ error:
static void Close(vout_display_t *vd)
{
vout_display_sys_t *sys = static_cast<vout_display_sys_t *>(vd->sys);
D3D_ReleaseShaderCompiler(&sys->shaders);
D3D_ReleaseShaderCompiler(sys->shaders);
#ifndef VLC_WINSTORE_APP
UnhookWindowsSensors(sys->p_sensors);
CommonWindowClean(&sys->sys);
@ -1033,7 +1033,7 @@ static int Direct3D11CreateFormatResources(vout_display_t *vd, const video_forma
BogusZeroCopy(vd) || !is_d3d11_opaque(fmt->i_chroma);
d3d_shader_blob pPSBlob[DXGI_MAX_RENDER_TARGET] = { };
hr = D3D11_CompilePixelShaderBlob(vd, &sys->shaders, sys->d3d_dev,
hr = D3D11_CompilePixelShaderBlob(vd, sys->shaders, sys->d3d_dev,
&sys->display, fmt->transfer,
fmt->color_range == COLOR_RANGE_FULL,
&sys->picQuad, pPSBlob);
@ -1161,7 +1161,7 @@ static int Direct3D11CreateGenericResources(vout_display_t *vd)
if (sys->regionQuad.generic.textureFormat != NULL)
{
d3d_shader_blob pPSBlob[DXGI_MAX_RENDER_TARGET] = { };
hr = D3D11_CompilePixelShaderBlob(vd, &sys->shaders, sys->d3d_dev,
hr = D3D11_CompilePixelShaderBlob(vd, sys->shaders, sys->d3d_dev,
&sys->display, TRANSFER_FUNC_SRGB, true,
&sys->regionQuad, pPSBlob);
if (FAILED(hr))
@ -1179,7 +1179,7 @@ static int Direct3D11CreateGenericResources(vout_display_t *vd)
}
d3d_shader_blob VSBlob = { };
hr = D3D11_CompileVertexShaderBlob(VLC_OBJECT(vd), &sys->shaders, sys->d3d_dev, true, &VSBlob);
hr = D3D11_CompileVertexShaderBlob(VLC_OBJECT(vd), sys->shaders, sys->d3d_dev, true, &VSBlob);
if(FAILED(hr)) {
msg_Err(vd, "Failed to compile the flat vertex shader. (hr=0x%lX)", hr);
return VLC_EGENERIC;
@ -1191,7 +1191,7 @@ static int Direct3D11CreateGenericResources(vout_display_t *vd)
}
hr = D3D11_CompileVertexShaderBlob(VLC_OBJECT(vd), &sys->shaders, sys->d3d_dev, false, &VSBlob);
hr = D3D11_CompileVertexShaderBlob(VLC_OBJECT(vd), sys->shaders, sys->d3d_dev, false, &VSBlob);
if(FAILED(hr)) {
msg_Err(vd, "Failed to compile the 360 vertex shader. (hr=0x%lX)", hr);
return VLC_EGENERIC;

Loading…
Cancel
Save