Skip to content

Commit

Permalink
R1/R2: shader compilation code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed May 28, 2018
1 parent 5187620 commit 41f23c5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 47 deletions.
35 changes: 13 additions & 22 deletions src/Layers/xrRenderPC_R1/FStaticRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,28 +771,7 @@ static HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 cons
result->constants.parse(pConstants, ShaderTypeTraits<T>::GetShaderDest());
}
else
{
Msg("! D3DXFindShaderComment %s hr == 0x%08x", file_name, _hr);
}

return _hr;
}

static HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 const buffer_size, LPCSTR const file_name, void*& result, bool const disasm)
{
HRESULT _result = E_FAIL;
if (pTarget[0] == 'p')
{
_result = create_shader(pTarget, buffer, buffer_size, file_name, (SPS*&)result, disasm);
}
else if (pTarget[0] == 'v')
{
_result = create_shader(pTarget, buffer, buffer_size, file_name, (SVS*&)result, disasm);
}
else
{
NODEFAULT;
}

if (disasm)
{
Expand All @@ -806,7 +785,19 @@ static HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 cons
_RELEASE(disasm);
}

return _result;
return _hr;
}

inline HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 const buffer_size, LPCSTR const file_name, void*& result, bool const disasm)
{
if (pTarget[0] == 'p')
return create_shader(pTarget, buffer, buffer_size, file_name, (SPS*&)result, disasm);

if (pTarget[0] == 'v')
return create_shader(pTarget, buffer, buffer_size, file_name, (SVS*&)result, disasm);

NODEFAULT;
return E_FAIL;
}

class includer : public ID3DXInclude
Expand Down
41 changes: 16 additions & 25 deletions src/Layers/xrRenderPC_R2/r2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,28 +646,7 @@ static HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 cons
result->constants.parse(pConstants, ShaderTypeTraits<T>::GetShaderDest());
}
else
{
Msg("! D3DXFindShaderComment %s hr == 0x%08x", file_name, _hr);
}

return _hr;
}

static HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 const buffer_size, LPCSTR const file_name, void*& result, bool const disasm)
{
HRESULT _result = E_FAIL;
if (pTarget[0] == 'p')
{
_result = create_shader(pTarget, buffer, buffer_size, file_name, (SPS*&)result, disasm);
}
else if (pTarget[0] == 'v')
{
_result = create_shader(pTarget, buffer, buffer_size, file_name, (SVS*&)result, disasm);
}
else
{
NODEFAULT;
}

if (disasm)
{
Expand All @@ -681,7 +660,19 @@ static HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 cons
_RELEASE(disasm);
}

return _result;
return _hr;
}

inline HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 const buffer_size, LPCSTR const file_name, void*& result, bool const disasm)
{
if (pTarget[0] == 'p')
return create_shader(pTarget, buffer, buffer_size, file_name, (SPS*&)result, disasm);

if (pTarget[0] == 'v')
return create_shader(pTarget, buffer, buffer_size, file_name, (SVS*&)result, disasm);

NODEFAULT;
return E_FAIL;
}

class includer : public ID3DXInclude
Expand Down Expand Up @@ -723,7 +714,7 @@ static inline bool match_shader_id(
LPCSTR const debug_shader_id, LPCSTR const full_shader_id, FS_FileSet const& file_set, string_path& result);

HRESULT CRender::shader_compile(LPCSTR name, DWORD const* pSrcData, UINT SrcDataLen, LPCSTR pFunctionName,
LPCSTR pTarget, DWORD Flags, void*& result)
LPCSTR pTarget, DWORD Flags, void*& result)
{
D3DXMACRO defines[128];
int def_it = 0;
Expand Down Expand Up @@ -1137,7 +1128,7 @@ HRESULT CRender::shader_compile(LPCSTR name, DWORD const* pSrcData, UINT SrcData
LPD3DXINCLUDE pInclude = (LPD3DXINCLUDE)&Includer;

_result = D3DXCompileShader((LPCSTR)pSrcData, SrcDataLen, defines, pInclude, pFunctionName, pTarget,
Flags | D3DXSHADER_USE_LEGACY_D3DX9_31_DLL, &pShaderBuf, &pErrorBuf, &pConstants);
Flags | D3DXSHADER_USE_LEGACY_D3DX9_31_DLL, &pShaderBuf, &pErrorBuf, &pConstants);
if (SUCCEEDED(_result))
{
IWriter* file = FS.w_open(file_name);
Expand All @@ -1147,7 +1138,7 @@ HRESULT CRender::shader_compile(LPCSTR name, DWORD const* pSrcData, UINT SrcData
FS.w_close(file);

_result = create_shader(pTarget, (DWORD*)pShaderBuf->GetBufferPointer(), pShaderBuf->GetBufferSize(),
file_name, result, o.disasm);
file_name, result, o.disasm);
}
else
{
Expand Down

0 comments on commit 41f23c5

Please sign in to comment.