Create d3dx_compile_shader_from_file

This commit is contained in:
twinaphex 2018-01-07 11:52:32 +01:00
parent 3ab8f017d9
commit e90a71d9f5
3 changed files with 84 additions and 25 deletions

View File

@ -52,6 +52,18 @@ static bool dylib_initialized = false;
#if defined(HAVE_D3D9)
typedef IDirect3D9 *(__stdcall *D3DCreate_t)(UINT);
#ifdef HAVE_D3DX
typedef HRESULT (__stdcall
*D3DCompileShaderFromFile_t)(
LPCTSTR pSrcFile,
const D3DXMACRO *pDefines,
LPD3DXINCLUDE pInclude,
LPCSTR pFunctionName,
LPCSTR pProfile,
DWORD Flags,
LPD3DXBUFFER *ppShader,
LPD3DXBUFFER *ppErrorMsgs,
LPD3DXCONSTANTTABLE *ppConstantTable);
typedef HRESULT (__stdcall
*D3DCreateTextureFromFile_t)(
LPDIRECT3DDEVICE9 pDevice,
@ -107,6 +119,9 @@ typedef HRESULT (__stdcall
#ifdef HAVE_D3DX
static D3DXCreateFontIndirect_t D3DCreateFontIndirect;
static D3DCreateTextureFromFile_t D3DCreateTextureFromFile;
#ifdef HAVE_D3D9
static D3DCompileShaderFromFile_t D3DCompileShaderFromFile;
#endif
#endif
static D3DCreate_t D3DCreate;
@ -212,12 +227,14 @@ bool d3d_initialize_symbols(void)
D3DCreateFontIndirect = (D3DXCreateFontIndirect_t)dylib_proc(g_d3dx_dll, "D3DXCreateFontIndirectA");
#endif
D3DCreateTextureFromFile = (D3DCreateTextureFromFile_t)dylib_proc(g_d3dx_dll, "D3DXCreateTextureFromFileExA");
D3DCompileShaderFromFile = (D3DCompileShaderFromFile_t)dylib_proc(g_d3dx_dll, "D3DXCompileShaderFromFile");
#endif
#else
D3DCreate = Direct3DCreate9;
#ifdef HAVE_D3DX
D3DCreateFontIndirect = D3DXCreateFontIndirect;
D3DCreateTextureFromFile = D3DXCreateTextureFromFileExA;
D3DCompileShaderFromFile = D3DXCompileShaderFromFile;
#endif
#endif
#elif defined(HAVE_D3D8)
@ -1590,3 +1607,34 @@ void d3dxbuffer_release(void *data)
#endif
#endif
}
bool d3dx_compile_shader_from_file(
const char *src,
const void *pdefines,
void *pinclude,
const char *pfunctionname,
const char *pprofile,
unsigned flags,
void *ppshader,
void *pperrormsgs,
void *ppconstanttable)
{
#ifdef HAVE_D3DX
if (D3DCompileShaderFromFile)
{
if (D3DCompileShaderFromFile(
(LPCTSTR)src,
(const D3DXMACRO*)pdefines,
(LPD3DXINCLUDE)pinclude,
(LPCSTR)pfunctionname,
(LPCSTR)pprofile,
(DWORD)flags,
(LPD3DXBUFFER*)ppshader,
(LPD3DXBUFFER*)pperrormsgs,
(LPD3DXCONSTANTTABLE*)ppconstanttable) < 0)
return false;
return true;
}
#endif
return false;
}

View File

@ -208,6 +208,17 @@ void d3dxbuffer_release(void *data);
D3DTEXTUREFILTERTYPE d3d_translate_filter(unsigned type);
bool d3dx_compile_shader_from_file(
const char *src,
const void *pdefines,
void *pinclude,
const char *pfunctionname,
const char *pprofile,
unsigned flags,
void *ppshader,
void *pperrormsgs,
void *ppconstanttable);
RETRO_END_DECLS
#endif

View File

@ -232,7 +232,7 @@ static bool hlsl_compile_program(
void *program_data,
struct shader_program_info *program_info)
{
HRESULT ret, ret_fp, ret_vp;
HRESULT ret;
hlsl_shader_data_t *hlsl = (hlsl_shader_data_t*)data;
d3d_video_t *d3d = (d3d_video_t*)hlsl->d3d;
struct shader_program_hlsl_data *program = (struct shader_program_hlsl_data*)program_data;
@ -247,42 +247,42 @@ static bool hlsl_compile_program(
if (program_info->is_file)
{
ret_fp = D3DXCompileShaderFromFile(program_info->combined, NULL, NULL,
"main_fragment", "ps_3_0", 0, &code_f, &listing_f, &program->f_ctable);
ret_vp = D3DXCompileShaderFromFile(program_info->combined, NULL, NULL,
"main_vertex", "vs_3_0", 0, &code_v, &listing_v, &program->v_ctable);
if (!d3dx_compile_shader_from_file(program_info->combined, NULL, NULL,
"main_fragment", "ps_3_0", 0, &code_f, &listing_f, &program->f_ctable))
goto error;
if (!d3dx_compile_shader_from_file(program_info->combined, NULL, NULL,
"main_vertex", "vs_3_0", 0, &code_v, &listing_v, &program->v_ctable))
goto error;
}
else
{
/* TODO - crashes currently - to do with 'end of line' of stock shader */
ret_fp = D3DXCompileShader(program_info->combined, strlen(program_info->combined), NULL, NULL,
"main_fragment", "ps_3_0", 0, &code_f, &listing_f, &program->f_ctable );
ret_vp = D3DXCompileShader(program_info->combined, strlen(program_info->combined), NULL, NULL,
"main_vertex", "vs_3_0", 0, &code_v, &listing_v, &program->v_ctable );
}
if (ret_fp < 0 || ret_vp < 0 || listing_v || listing_f)
{
RARCH_ERR("Cg/HLSL error:\n");
if(listing_f)
RARCH_ERR("Fragment:\n%s\n", (char*)ID3DXConstantTable_GetBufferPointer(listing_f));
if(listing_v)
RARCH_ERR("Vertex:\n%s\n", (char*)ID3DXConstantTable_GetBufferPointer(listing_v));
ret = false;
goto end;
if (D3DXCompileShader(program_info->combined, strlen(program_info->combined), NULL, NULL,
"main_fragment", "ps_3_0", 0, &code_f, &listing_f, &program->f_ctable ) > 0)
goto error;
if (D3DXCompileShader(program_info->combined, strlen(program_info->combined), NULL, NULL,
"main_vertex", "vs_3_0", 0, &code_v, &listing_v, &program->v_ctable ) > 0)
goto error;
}
d3d_create_pixel_shader(d3dr, (const DWORD*)ID3DXConstantTable_GetBufferPointer(code_f), &program->fprg);
d3d_create_vertex_shader(d3dr, (const DWORD*)ID3DXConstantTable_GetBufferPointer(code_v), &program->vprg);
d3dxbuffer_release((void*)code_f);
d3dxbuffer_release((void*)code_v);
goto end;
error:
RARCH_ERR("Cg/HLSL error:\n");
if(listing_f)
RARCH_ERR("Fragment:\n%s\n", (char*)ID3DXConstantTable_GetBufferPointer(listing_f));
if(listing_v)
RARCH_ERR("Vertex:\n%s\n", (char*)ID3DXConstantTable_GetBufferPointer(listing_v));
ret = false;
end:
if (listing_f)
d3dxbuffer_release((void*)listing_f);
if (listing_v)
d3dxbuffer_release((void*)listing_v);
d3dxbuffer_release((void*)listing_f);
d3dxbuffer_release((void*)listing_v);
return ret;
}