1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/*
* $Id$
*
* (C) 2003-2006 Gabest
* (C) 2006-2010 see AUTHORS
*
* This file is part of mplayerc.
*
* Mplayerc is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Mplayerc is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "stdafx.h"
#include "PixelShaderCompiler.h"
#include "RenderersSettings.h"
#include "../apps/mplayerc/resource.h"
CPixelShaderCompiler::CPixelShaderCompiler(IDirect3DDevice9* pD3DDev, bool fStaySilent)
: m_pD3DDev(pD3DDev)
, m_pD3DXCompileShader(NULL)
, m_pD3DXDisassembleShader(NULL)
{
HINSTANCE hDll;
hDll = GetRenderersData()->GetD3X9Dll();
if(hDll) {
m_pD3DXCompileShader = (D3DXCompileShaderPtr)GetProcAddress(hDll, "D3DXCompileShader");
m_pD3DXDisassembleShader = (D3DXDisassembleShaderPtr)GetProcAddress(hDll, "D3DXDisassembleShader");
}
if(!fStaySilent) {
if(!hDll) {
AfxMessageBox(ResStr(IDS_PIXELSHADERCOMPILER_0), MB_OK);
} else if(!m_pD3DXCompileShader || !m_pD3DXDisassembleShader) {
AfxMessageBox(ResStr(IDS_PIXELSHADERCOMPILER_1), MB_OK);
}
}
}
CPixelShaderCompiler::~CPixelShaderCompiler()
{
}
HRESULT CPixelShaderCompiler::CompileShader(
LPCSTR pSrcData,
LPCSTR pFunctionName,
LPCSTR pProfile,
DWORD Flags,
IDirect3DPixelShader9** ppPixelShader,
CString* disasm,
CString* errmsg)
{
if(!m_pD3DXCompileShader || !m_pD3DXDisassembleShader) {
return E_FAIL;
}
HRESULT hr;
CComPtr<ID3DXBuffer> pShader, pDisAsm, pErrorMsgs;
hr = m_pD3DXCompileShader(pSrcData, strlen(pSrcData), NULL, NULL, pFunctionName, pProfile, Flags, &pShader, &pErrorMsgs, NULL);
if(FAILED(hr)) {
if(errmsg) {
CStringA msg = "Unexpected compiler error";
if(pErrorMsgs) {
int len = pErrorMsgs->GetBufferSize();
memcpy(msg.GetBufferSetLength(len), pErrorMsgs->GetBufferPointer(), len);
}
*errmsg = msg;
}
return hr;
}
if(ppPixelShader) {
if(!m_pD3DDev) {
return E_FAIL;
}
hr = m_pD3DDev->CreatePixelShader((DWORD*)pShader->GetBufferPointer(), ppPixelShader);
if(FAILED(hr)) {
return hr;
}
}
if(disasm) {
hr = m_pD3DXDisassembleShader((DWORD*)pShader->GetBufferPointer(), FALSE, NULL, &pDisAsm);
if(SUCCEEDED(hr) && pDisAsm) {
*disasm = CStringA((const char*)pDisAsm->GetBufferPointer());
}
}
return S_OK;
}
|