2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-08 13:44:56 +00:00

Windows sync fixes for API changes

This commit is contained in:
Jack Andersen
2018-10-14 10:09:15 -10:00
parent aef455e1ab
commit 61a50aa57e
33 changed files with 767 additions and 682 deletions

View File

@@ -7,6 +7,37 @@
static logvisor::Module Log("shaderc");
#if _WIN32
#include <d3dcompiler.h>
extern pD3DCompile D3DCompilePROC;
pD3DCompile D3DCompilePROC = nullptr;
static bool FindBestD3DCompile()
{
HMODULE d3dCompilelib = LoadLibraryW(L"D3DCompiler_47.dll");
if (!d3dCompilelib)
{
d3dCompilelib = LoadLibraryW(L"D3DCompiler_46.dll");
if (!d3dCompilelib)
{
d3dCompilelib = LoadLibraryW(L"D3DCompiler_45.dll");
if (!d3dCompilelib)
{
d3dCompilelib = LoadLibraryW(L"D3DCompiler_44.dll");
if (!d3dCompilelib)
{
d3dCompilelib = LoadLibraryW(L"D3DCompiler_43.dll");
}
}
}
}
if (d3dCompilelib)
{
D3DCompilePROC = (pD3DCompile)GetProcAddress(d3dCompilelib, "D3DCompile");
return D3DCompilePROC != nullptr;
}
return false;
}
int wmain(int argc, const hecl::SystemChar** argv)
#else
int main(int argc, const hecl::SystemChar** argv)
@@ -15,6 +46,14 @@ int main(int argc, const hecl::SystemChar** argv)
logvisor::RegisterConsoleLogger();
logvisor::RegisterStandardExceptions();
#if _WIN32
if (!FindBestD3DCompile())
{
Log.report(logvisor::Info, "Unable to find D3DCompiler dll");
return 1;
}
#endif
if (argc == 1)
{
Log.report(logvisor::Info, "Usage: shaderc -o <out-base> [-D definevar=defineval]... <in-files>...");
@@ -63,7 +102,7 @@ int main(int argc, const hecl::SystemChar** argv)
}
hecl::SystemUTF8Conv conv(define);
const char* defineU8 = conv.c_str();
if (char* equals = strchr(defineU8, '='))
if (const char* equals = strchr(defineU8, '='))
c.addDefine(std::string(defineU8, equals - defineU8), equals + 1);
else
c.addDefine(defineU8, "");
@@ -87,7 +126,7 @@ int main(int argc, const hecl::SystemChar** argv)
}
hecl::SystemStringView baseName;
auto slashPos = outPath.find_last_of("/\\");
auto slashPos = outPath.find_last_of(_SYS_STR("/\\"));
if (slashPos != hecl::SystemString::npos)
baseName = outPath.data() + slashPos + 1;
else
@@ -105,22 +144,22 @@ int main(int argc, const hecl::SystemChar** argv)
return 1;
{
hecl::SystemString headerPath = outPath + _S(".hpp");
hecl::SystemString headerPath = outPath + _SYS_STR(".hpp");
athena::io::FileWriter w(headerPath);
if (w.hasError())
{
Log.report(logvisor::Error, _S("Error opening '%s' for writing"), headerPath.c_str());
Log.report(logvisor::Error, _SYS_STR("Error opening '%s' for writing"), headerPath.c_str());
return 1;
}
w.writeBytes(ret.first.data(), ret.first.size());
}
{
hecl::SystemString impPath = outPath + _S(".cpp");
hecl::SystemString impPath = outPath + _SYS_STR(".cpp");
athena::io::FileWriter w(impPath);
if (w.hasError())
{
Log.report(logvisor::Error, _S("Error opening '%s' for writing"), impPath.c_str());
Log.report(logvisor::Error, _SYS_STR("Error opening '%s' for writing"), impPath.c_str());
return 1;
}
w.writeBytes(ret.second.data(), ret.second.size());

View File

@@ -7,6 +7,7 @@
#include <regex>
#include <unordered_map>
#include <set>
#include <bitset>
using namespace std::literals;
@@ -238,24 +239,24 @@ bool Compiler::includeFile(SystemStringView file, std::string& out, int depth)
{
if (depth > 32)
{
Log.report(logvisor::Error, _S("Too many levels of includes (>32) at '%s'"), file.data());
Log.report(logvisor::Error, _SYS_STR("Too many levels of includes (>32) at '%s'"), file.data());
return false;
}
const std::string* data = getFileContents(file);
if (!data)
{
Log.report(logvisor::Error, _S("Unable to access '%s'"), file.data());
Log.report(logvisor::Error, _SYS_STR("Unable to access '%s'"), file.data());
return false;
}
const std::string& sdata = *data;
SystemString directory;
auto slashPos = file.find_last_of("/\\");
auto slashPos = file.find_last_of(_SYS_STR("/\\"));
if (slashPos != SystemString::npos)
directory = SystemString(file.begin(), file.begin() + slashPos);
else
directory = _S(".");
directory = _SYS_STR(".");
auto begin = sdata.cbegin();
auto end = sdata.cend();
@@ -274,13 +275,13 @@ bool Compiler::includeFile(SystemStringView file, std::string& out, int depth)
std::string path = subMatch[1].str();
if (path.empty())
{
Log.report(logvisor::Error, _S("Empty path provided to include in '%s'"), file.data());
Log.report(logvisor::Error, _SYS_STR("Empty path provided to include in '%s'"), file.data());
return false;
}
hecl::SystemString pathStr(hecl::SystemStringConv(path).sys_str());
if (!hecl::IsAbsolute(pathStr))
pathStr = directory + _S('/') + pathStr;
pathStr = directory + _SYS_STR('/') + pathStr;
if (!includeFile(pathStr, out, depth + 1))
return false;
}
@@ -871,58 +872,15 @@ bool Compiler::compileFile(SystemStringView file, std::string_view baseName, std
}
out.first += "\n";
out.first += "#define OPENGL_STAGES_";
out.first += "#define STAGES_";
out.first += baseName;
out.first += "(P, S)";
for (const auto& shader : shaderStageUses)
{
out.first += " \\\n";
out.first += "STAGE_SPECIALIZATIONS(::StageObject_";
out.first += "::StageObject_";
out.first += shader.first;
out.first += ", hecl::PlatformType::OpenGL)";
}
out.first += "\n";
out.first += "#define VULKAN_STAGES_";
out.first += baseName;
for (const auto& shader : shaderStageUses)
{
out.first += " \\\n";
out.first += "STAGE_SPECIALIZATIONS(::StageObject_";
out.first += shader.first;
out.first += ", hecl::PlatformType::Vulkan)";
}
out.first += "\n";
out.first += "#define D3D11_STAGES_";
out.first += baseName;
for (const auto& shader : shaderStageUses)
{
out.first += " \\\n";
out.first += "STAGE_SPECIALIZATIONS(::StageObject_";
out.first += shader.first;
out.first += ", hecl::PlatformType::D3D11)";
}
out.first += "\n";
out.first += "#define METAL_STAGES_";
out.first += baseName;
for (const auto& shader : shaderStageUses)
{
out.first += " \\\n";
out.first += "STAGE_SPECIALIZATIONS(::StageObject_";
out.first += shader.first;
out.first += ", hecl::PlatformType::Metal)";
}
out.first += "\n";
out.first += "#define NX_STAGES_";
out.first += baseName;
for (const auto& shader : shaderStageUses)
{
out.first += " \\\n";
out.first += "STAGE_SPECIALIZATIONS(::StageObject_";
out.first += shader.first;
out.first += ", hecl::PlatformType::NX)";
out.first += "<P, S>,";
}
out.first += "\n";