2019-05-12 11:15:45 +08:00
|
|
|
#include "ppsspp_config.h"
|
2020-10-04 23:24:14 +02:00
|
|
|
|
2020-10-30 10:22:40 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
2020-10-04 23:24:14 +02:00
|
|
|
#include "Common/CommonWindows.h"
|
|
|
|
|
#include "Common/GPU/D3D9/D3DCompilerLoader.h"
|
|
|
|
|
#include "Common/GPU/D3D9/D3D9ShaderCompiler.h"
|
2014-09-26 21:32:22 -07:00
|
|
|
#include "Common/CommonFuncs.h"
|
2020-09-29 15:50:16 +02:00
|
|
|
#include "Common/SysError.h"
|
2020-10-30 23:58:53 +01:00
|
|
|
#include "Common/Log.h"
|
|
|
|
|
#include "Common/StringUtils.h"
|
2013-08-17 11:23:51 +02:00
|
|
|
|
2019-05-12 11:15:45 +08:00
|
|
|
struct ID3DXConstantTable;
|
|
|
|
|
|
2020-10-30 10:22:40 +01:00
|
|
|
LPD3DBLOB CompileShaderToByteCodeD3D9(const char *code, const char *target, std::string *errorMessage) {
|
2019-05-12 11:15:45 +08:00
|
|
|
LPD3DBLOB pShaderCode = nullptr;
|
|
|
|
|
LPD3DBLOB pErrorMsg = nullptr;
|
2013-08-17 11:23:51 +02:00
|
|
|
|
2014-08-17 21:29:36 +02:00
|
|
|
// Compile pixel shader.
|
2019-05-12 11:15:45 +08:00
|
|
|
HRESULT hr = dyn_D3DCompile(code,
|
|
|
|
|
(UINT)strlen(code),
|
|
|
|
|
nullptr,
|
|
|
|
|
nullptr,
|
|
|
|
|
nullptr,
|
|
|
|
|
"main",
|
2020-10-30 10:22:40 +01:00
|
|
|
target,
|
2019-05-12 11:15:45 +08:00
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
&pShaderCode,
|
|
|
|
|
&pErrorMsg);
|
2014-08-17 21:29:36 +02:00
|
|
|
|
2014-09-07 10:38:49 -07:00
|
|
|
if (pErrorMsg) {
|
2020-10-31 00:19:20 +01:00
|
|
|
*errorMessage = std::string((CHAR *)pErrorMsg->GetBufferPointer());
|
2020-10-30 23:58:53 +01:00
|
|
|
|
|
|
|
|
OutputDebugStringUTF8(LineNumberString(std::string(code)).c_str());
|
|
|
|
|
OutputDebugStringUTF8(errorMessage->c_str());
|
|
|
|
|
|
2014-09-07 10:38:49 -07:00
|
|
|
pErrorMsg->Release();
|
2020-10-31 11:31:16 +01:00
|
|
|
if (pShaderCode) {
|
|
|
|
|
pShaderCode->Release();
|
|
|
|
|
pShaderCode = nullptr;
|
|
|
|
|
}
|
2014-09-26 21:32:22 -07:00
|
|
|
} else if (FAILED(hr)) {
|
2020-10-30 10:22:40 +01:00
|
|
|
*errorMessage = GetStringErrorMsg(hr);
|
|
|
|
|
if (pShaderCode) {
|
2014-09-07 11:01:19 -07:00
|
|
|
pShaderCode->Release();
|
2020-10-30 10:22:40 +01:00
|
|
|
pShaderCode = nullptr;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2022-10-03 10:47:55 +03:00
|
|
|
errorMessage->clear();
|
2013-08-17 11:23:51 +02:00
|
|
|
}
|
|
|
|
|
|
2020-10-30 10:22:40 +01:00
|
|
|
return pShaderCode;
|
2013-08-17 11:23:51 +02:00
|
|
|
}
|
|
|
|
|
|
2020-10-30 10:22:40 +01:00
|
|
|
bool CompilePixelShaderD3D9(LPDIRECT3DDEVICE9 device, const char *code, LPDIRECT3DPIXELSHADER9 *pShader, std::string *errorMessage) {
|
2022-08-30 11:14:55 +02:00
|
|
|
LPD3DBLOB pShaderCode = CompileShaderToByteCodeD3D9(code, "ps_3_0", errorMessage);
|
2020-10-30 10:22:40 +01:00
|
|
|
if (pShaderCode) {
|
|
|
|
|
// Create pixel shader.
|
|
|
|
|
device->CreatePixelShader((DWORD*)pShaderCode->GetBufferPointer(), pShader);
|
|
|
|
|
pShaderCode->Release();
|
|
|
|
|
return true;
|
2014-09-07 11:01:19 -07:00
|
|
|
} else {
|
2013-08-17 11:23:51 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-30 10:22:40 +01:00
|
|
|
bool CompileVertexShaderD3D9(LPDIRECT3DDEVICE9 device, const char *code, LPDIRECT3DVERTEXSHADER9 *pShader, std::string *errorMessage) {
|
2022-08-30 11:14:55 +02:00
|
|
|
LPD3DBLOB pShaderCode = CompileShaderToByteCodeD3D9(code, "vs_3_0", errorMessage);
|
2020-10-30 10:22:40 +01:00
|
|
|
if (pShaderCode) {
|
|
|
|
|
// Create vertex shader.
|
|
|
|
|
device->CreateVertexShader((DWORD*)pShaderCode->GetBufferPointer(), pShader);
|
|
|
|
|
pShaderCode->Release();
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-05 20:50:17 +01:00
|
|
|
|
2018-03-23 03:18:13 +01:00
|
|
|
#endif
|