CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Common/GPU/D3D9/D3D9ShaderCompiler.cpp
Views: 1401
1
#include "ppsspp_config.h"
2
3
#ifdef _WIN32
4
5
#include "Common/CommonWindows.h"
6
#include "Common/GPU/D3D9/D3DCompilerLoader.h"
7
#include "Common/GPU/D3D9/D3D9ShaderCompiler.h"
8
#include "Common/CommonFuncs.h"
9
#include "Common/SysError.h"
10
#include "Common/Log.h"
11
#include "Common/StringUtils.h"
12
#include <wrl/client.h>
13
14
using namespace Microsoft::WRL;
15
16
struct ID3DXConstantTable;
17
18
LPD3DBLOB CompileShaderToByteCodeD3D9(const char *code, const char *target, std::string *errorMessage) {
19
ComPtr<ID3DBlob> pShaderCode;
20
ComPtr<ID3DBlob> pErrorMsg;
21
22
// Compile pixel shader.
23
HRESULT hr = dyn_D3DCompile(code,
24
(UINT)strlen(code),
25
nullptr,
26
nullptr,
27
nullptr,
28
"main",
29
target,
30
0,
31
0,
32
&pShaderCode,
33
&pErrorMsg);
34
35
if (pErrorMsg) {
36
*errorMessage = std::string((CHAR *)pErrorMsg->GetBufferPointer());
37
38
OutputDebugStringUTF8(LineNumberString(std::string(code)).c_str());
39
OutputDebugStringUTF8(errorMessage->c_str());
40
} else if (FAILED(hr)) {
41
*errorMessage = GetStringErrorMsg(hr);
42
} else {
43
errorMessage->clear();
44
}
45
46
return pShaderCode.Detach();
47
}
48
49
bool CompilePixelShaderD3D9(LPDIRECT3DDEVICE9 device, const char *code, LPDIRECT3DPIXELSHADER9 *pShader, std::string *errorMessage) {
50
ComPtr<ID3DBlob> pShaderCode = CompileShaderToByteCodeD3D9(code, "ps_3_0", errorMessage);
51
if (pShaderCode) {
52
// Create pixel shader.
53
device->CreatePixelShader((DWORD*)pShaderCode->GetBufferPointer(), pShader);
54
return true;
55
} else {
56
return false;
57
}
58
}
59
60
bool CompileVertexShaderD3D9(LPDIRECT3DDEVICE9 device, const char *code, LPDIRECT3DVERTEXSHADER9 *pShader, std::string *errorMessage) {
61
ComPtr<ID3DBlob> pShaderCode = CompileShaderToByteCodeD3D9(code, "vs_3_0", errorMessage);
62
if (pShaderCode) {
63
// Create vertex shader.
64
device->CreateVertexShader((DWORD*)pShaderCode->GetBufferPointer(), pShader);
65
return true;
66
} else {
67
return false;
68
}
69
}
70
71
#endif
72
73