Files
ppsspp/Common/GPU/D3D9/D3D9ShaderCompiler.cpp

81 lines
2.0 KiB
C++
Raw Permalink Normal View History

#include "ppsspp_config.h"
#ifdef _WIN32
#include "Common/CommonWindows.h"
#include "Common/GPU/D3D9/D3DCompilerLoader.h"
#include "Common/GPU/D3D9/D3D9ShaderCompiler.h"
#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
struct ID3DXConstantTable;
LPD3DBLOB CompileShaderToByteCodeD3D9(const char *code, const char *target, std::string *errorMessage) {
LPD3DBLOB pShaderCode = nullptr;
LPD3DBLOB pErrorMsg = nullptr;
2013-08-17 11:23:51 +02:00
// Compile pixel shader.
HRESULT hr = dyn_D3DCompile(code,
(UINT)strlen(code),
nullptr,
nullptr,
nullptr,
"main",
target,
0,
0,
&pShaderCode,
&pErrorMsg);
2014-09-07 10:38:49 -07:00
if (pErrorMsg) {
*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();
if (pShaderCode) {
pShaderCode->Release();
pShaderCode = nullptr;
}
} else if (FAILED(hr)) {
*errorMessage = GetStringErrorMsg(hr);
if (pShaderCode) {
pShaderCode->Release();
pShaderCode = nullptr;
}
} else {
errorMessage->clear();
2013-08-17 11:23:51 +02:00
}
return pShaderCode;
2013-08-17 11:23:51 +02:00
}
bool CompilePixelShaderD3D9(LPDIRECT3DDEVICE9 device, const char *code, LPDIRECT3DPIXELSHADER9 *pShader, std::string *errorMessage) {
LPD3DBLOB pShaderCode = CompileShaderToByteCodeD3D9(code, "ps_3_0", errorMessage);
if (pShaderCode) {
// Create pixel shader.
device->CreatePixelShader((DWORD*)pShaderCode->GetBufferPointer(), pShader);
pShaderCode->Release();
return true;
} else {
2013-08-17 11:23:51 +02:00
return false;
}
}
bool CompileVertexShaderD3D9(LPDIRECT3DDEVICE9 device, const char *code, LPDIRECT3DVERTEXSHADER9 *pShader, std::string *errorMessage) {
LPD3DBLOB pShaderCode = CompileShaderToByteCodeD3D9(code, "vs_3_0", errorMessage);
if (pShaderCode) {
// Create vertex shader.
device->CreateVertexShader((DWORD*)pShaderCode->GetBufferPointer(), pShader);
pShaderCode->Release();
return true;
} else {
return false;
}
}
2018-03-23 03:18:13 +01:00
#endif