mirror of https://github.com/AxioDL/metaforce.git
Merge pull request #16 from lioncash/string
hecl/Compilers: Amend minor string related code
This commit is contained in:
commit
ff7e95546b
|
@ -12,35 +12,35 @@ using PlatformEnum = boo::IGraphicsDataFactory::Platform;
|
||||||
struct Null {};
|
struct Null {};
|
||||||
struct OpenGL {
|
struct OpenGL {
|
||||||
static constexpr PlatformEnum Enum = PlatformEnum::OpenGL;
|
static constexpr PlatformEnum Enum = PlatformEnum::OpenGL;
|
||||||
static const char* Name;
|
static constexpr char Name[] = "OpenGL";
|
||||||
#if BOO_HAS_GL
|
#if BOO_HAS_GL
|
||||||
using Context = boo::GLDataFactory::Context;
|
using Context = boo::GLDataFactory::Context;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
struct D3D11 {
|
struct D3D11 {
|
||||||
static constexpr PlatformEnum Enum = PlatformEnum::D3D11;
|
static constexpr PlatformEnum Enum = PlatformEnum::D3D11;
|
||||||
static const char* Name;
|
static constexpr char Name[] = "D3D11";
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
using Context = boo::D3D11DataFactory::Context;
|
using Context = boo::D3D11DataFactory::Context;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
struct Metal {
|
struct Metal {
|
||||||
static constexpr PlatformEnum Enum = PlatformEnum::Metal;
|
static constexpr PlatformEnum Enum = PlatformEnum::Metal;
|
||||||
static const char* Name;
|
static constexpr char Name[] = "Metal";
|
||||||
#if BOO_HAS_METAL
|
#if BOO_HAS_METAL
|
||||||
using Context = boo::MetalDataFactory::Context;
|
using Context = boo::MetalDataFactory::Context;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
struct Vulkan {
|
struct Vulkan {
|
||||||
static constexpr PlatformEnum Enum = PlatformEnum::Vulkan;
|
static constexpr PlatformEnum Enum = PlatformEnum::Vulkan;
|
||||||
static const char* Name;
|
static constexpr char Name[] = "Vulkan";
|
||||||
#if BOO_HAS_VULKAN
|
#if BOO_HAS_VULKAN
|
||||||
using Context = boo::VulkanDataFactory::Context;
|
using Context = boo::VulkanDataFactory::Context;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
struct NX {
|
struct NX {
|
||||||
static constexpr PlatformEnum Enum = PlatformEnum::NX;
|
static constexpr PlatformEnum Enum = PlatformEnum::NX;
|
||||||
static const char* Name;
|
static constexpr char Name[] = "NX";
|
||||||
#if BOO_HAS_NX
|
#if BOO_HAS_NX
|
||||||
using Context = boo::NXDataFactory::Context;
|
using Context = boo::NXDataFactory::Context;
|
||||||
#endif
|
#endif
|
||||||
|
@ -51,27 +51,27 @@ namespace PipelineStage {
|
||||||
using StageEnum = boo::PipelineStage;
|
using StageEnum = boo::PipelineStage;
|
||||||
struct Null {
|
struct Null {
|
||||||
static constexpr StageEnum Enum = StageEnum::Null;
|
static constexpr StageEnum Enum = StageEnum::Null;
|
||||||
static const char* Name;
|
static constexpr char Name[] = "Null";
|
||||||
};
|
};
|
||||||
struct Vertex {
|
struct Vertex {
|
||||||
static constexpr StageEnum Enum = StageEnum::Vertex;
|
static constexpr StageEnum Enum = StageEnum::Vertex;
|
||||||
static const char* Name;
|
static constexpr char Name[] = "Vertex";
|
||||||
};
|
};
|
||||||
struct Fragment {
|
struct Fragment {
|
||||||
static constexpr StageEnum Enum = StageEnum::Fragment;
|
static constexpr StageEnum Enum = StageEnum::Fragment;
|
||||||
static const char* Name;
|
static constexpr char Name[] = "Fragment";
|
||||||
};
|
};
|
||||||
struct Geometry {
|
struct Geometry {
|
||||||
static constexpr StageEnum Enum = StageEnum::Geometry;
|
static constexpr StageEnum Enum = StageEnum::Geometry;
|
||||||
static const char* Name;
|
static constexpr char Name[] = "Geometry";
|
||||||
};
|
};
|
||||||
struct Control {
|
struct Control {
|
||||||
static constexpr StageEnum Enum = StageEnum::Control;
|
static constexpr StageEnum Enum = StageEnum::Control;
|
||||||
static const char* Name;
|
static constexpr char Name[] = "Control";
|
||||||
};
|
};
|
||||||
struct Evaluation {
|
struct Evaluation {
|
||||||
static constexpr StageEnum Enum = StageEnum::Evaluation;
|
static constexpr StageEnum Enum = StageEnum::Evaluation;
|
||||||
static const char* Name;
|
static constexpr char Name[] = "Evaluation";
|
||||||
};
|
};
|
||||||
} // namespace PipelineStage
|
} // namespace PipelineStage
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
#include "hecl/Compilers.hpp"
|
#include "hecl/Compilers.hpp"
|
||||||
#include "boo/graphicsdev/GLSLMacros.hpp"
|
#include <boo/graphicsdev/GLSLMacros.hpp>
|
||||||
#include "logvisor/logvisor.hpp"
|
#include <logvisor/logvisor.hpp>
|
||||||
|
|
||||||
#include <glslang/Public/ShaderLang.h>
|
#include <glslang/Public/ShaderLang.h>
|
||||||
#include <StandAlone/ResourceLimits.h>
|
#include <StandAlone/ResourceLimits.h>
|
||||||
#include <SPIRV/GlslangToSpv.h>
|
#include <SPIRV/GlslangToSpv.h>
|
||||||
#include <SPIRV/disassemble.h>
|
#include <SPIRV/disassemble.h>
|
||||||
|
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
#include <d3dcompiler.h>
|
#include <d3dcompiler.h>
|
||||||
extern pD3DCompile D3DCompilePROC;
|
extern pD3DCompile D3DCompilePROC;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __APPLE__
|
#if __APPLE__
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -17,23 +20,6 @@ extern pD3DCompile D3DCompilePROC;
|
||||||
namespace hecl {
|
namespace hecl {
|
||||||
logvisor::Module Log("hecl::Compilers");
|
logvisor::Module Log("hecl::Compilers");
|
||||||
|
|
||||||
namespace PlatformType {
|
|
||||||
const char* OpenGL::Name = "OpenGL";
|
|
||||||
const char* Vulkan::Name = "Vulkan";
|
|
||||||
const char* D3D11::Name = "D3D11";
|
|
||||||
const char* Metal::Name = "Metal";
|
|
||||||
const char* NX::Name = "NX";
|
|
||||||
} // namespace PlatformType
|
|
||||||
|
|
||||||
namespace PipelineStage {
|
|
||||||
const char* Null::Name = "Null";
|
|
||||||
const char* Vertex::Name = "Vertex";
|
|
||||||
const char* Fragment::Name = "Fragment";
|
|
||||||
const char* Geometry::Name = "Geometry";
|
|
||||||
const char* Control::Name = "Control";
|
|
||||||
const char* Evaluation::Name = "Evaluation";
|
|
||||||
} // namespace PipelineStage
|
|
||||||
|
|
||||||
template <typename P>
|
template <typename P>
|
||||||
struct ShaderCompiler {};
|
struct ShaderCompiler {};
|
||||||
|
|
||||||
|
@ -99,7 +85,7 @@ struct ShaderCompiler<PlatformType::D3D11> {
|
||||||
ComPtr<ID3DBlob> blobOut;
|
ComPtr<ID3DBlob> blobOut;
|
||||||
if (FAILED(D3DCompilePROC(text.data(), text.size(), "Boo HLSL Source", nullptr, nullptr, "main",
|
if (FAILED(D3DCompilePROC(text.data(), text.size(), "Boo HLSL Source", nullptr, nullptr, "main",
|
||||||
D3DShaderTypes[int(S::Enum)], BOO_D3DCOMPILE_FLAG, 0, &blobOut, &errBlob))) {
|
D3DShaderTypes[int(S::Enum)], BOO_D3DCOMPILE_FLAG, 0, &blobOut, &errBlob))) {
|
||||||
printf("%s\n", text.data());
|
fmt::print(fmt("{}\n"), text);
|
||||||
Log.report(logvisor::Fatal, fmt("error compiling shader: {}"), (char*)errBlob->GetBufferPointer());
|
Log.report(logvisor::Fatal, fmt("error compiling shader: {}"), (char*)errBlob->GetBufferPointer());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -124,7 +110,7 @@ struct ShaderCompiler<PlatformType::Metal> {
|
||||||
|
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if (!pid) {
|
if (!pid) {
|
||||||
execlp("xcrun", "xcrun", "-sdk", "macosx", "metal", "--version", NULL);
|
execlp("xcrun", "xcrun", "-sdk", "macosx", "metal", "--version", nullptr);
|
||||||
/* xcrun returns 72 if metal command not found;
|
/* xcrun returns 72 if metal command not found;
|
||||||
* emulate that if xcrun not found */
|
* emulate that if xcrun not found */
|
||||||
exit(72);
|
exit(72);
|
||||||
|
@ -180,8 +166,8 @@ struct ShaderCompiler<PlatformType::Metal> {
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
"-gline-tables-only", "-MO",
|
"-gline-tables-only", "-MO",
|
||||||
#endif
|
#endif
|
||||||
"-", NULL);
|
"-", nullptr);
|
||||||
fprintf(stderr, "execlp fail %s\n", strerror(errno));
|
fmt::print(stderr, fmt("execlp fail {}\n"), strerror(errno));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
close(compilerIn[0]);
|
close(compilerIn[0]);
|
||||||
|
@ -196,8 +182,8 @@ struct ShaderCompiler<PlatformType::Metal> {
|
||||||
close(compilerIn[1]);
|
close(compilerIn[1]);
|
||||||
|
|
||||||
/* metallib doesn't like outputting to a pipe, so temp file will have to do */
|
/* metallib doesn't like outputting to a pipe, so temp file will have to do */
|
||||||
execlp("xcrun", "xcrun", "-sdk", "macosx", "metallib", "-", "-o", libFile.c_str(), NULL);
|
execlp("xcrun", "xcrun", "-sdk", "macosx", "metallib", "-", "-o", libFile.c_str(), nullptr);
|
||||||
fprintf(stderr, "execlp fail %s\n", strerror(errno));
|
fmt::print(stderr, fmt("execlp fail {}\n"), strerror(errno));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
close(compilerOut[0]);
|
close(compilerOut[0]);
|
||||||
|
@ -208,7 +194,7 @@ struct ShaderCompiler<PlatformType::Metal> {
|
||||||
while (inRem) {
|
while (inRem) {
|
||||||
ssize_t writeRes = write(compilerIn[1], inPtr, inRem);
|
ssize_t writeRes = write(compilerIn[1], inPtr, inRem);
|
||||||
if (writeRes < 0) {
|
if (writeRes < 0) {
|
||||||
fprintf(stderr, "write fail %s\n", strerror(errno));
|
fmt::print(stderr, fmt("write fail {}\n"), strerror(errno));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
inPtr += writeRes;
|
inPtr += writeRes;
|
||||||
|
@ -221,7 +207,7 @@ struct ShaderCompiler<PlatformType::Metal> {
|
||||||
while (waitpid(compilerPid, &compilerStat, 0) < 0) {
|
while (waitpid(compilerPid, &compilerStat, 0) < 0) {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
Log.report(logvisor::Fatal, fmt("waitpid fail %s"), strerror(errno));
|
Log.report(logvisor::Fatal, fmt("waitpid fail {}"), strerror(errno));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,7 +219,7 @@ struct ShaderCompiler<PlatformType::Metal> {
|
||||||
while (waitpid(linkerPid, &linkerStat, 0) < 0) {
|
while (waitpid(linkerPid, &linkerStat, 0) < 0) {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
Log.report(logvisor::Fatal, fmt("waitpid fail %s"), strerror(errno));
|
Log.report(logvisor::Fatal, fmt("waitpid fail {}"), strerror(errno));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue