From d395f4a79ec50d78b0cff0a8263ad76d6cbb9878 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Mon, 15 Oct 2018 17:15:05 -1000 Subject: [PATCH] macOS build fixes --- hecl/extern/boo | 2 +- hecl/include/hecl/Backend/Backend.hpp | 11 +- hecl/include/hecl/Backend/GLSL.hpp | 6 +- hecl/include/hecl/Backend/HLSL.hpp | 6 +- hecl/include/hecl/Compilers.hpp | 16 +- hecl/include/hecl/Pipeline.hpp | 5 +- hecl/include/hecl/PipelineBase.hpp | 29 ++- hecl/lib/Backend/GLSL.cpp | 5 +- hecl/lib/Backend/HLSL.cpp | 6 +- hecl/lib/Compilers.cpp | 318 +++++++++++++++----------- hecl/lib/Pipeline.cpp | 5 +- hecl/shaderc/shaderc.cpp | 6 +- 12 files changed, 252 insertions(+), 163 deletions(-) diff --git a/hecl/extern/boo b/hecl/extern/boo index 592ffa137..65c99ad76 160000 --- a/hecl/extern/boo +++ b/hecl/extern/boo @@ -1 +1 @@ -Subproject commit 592ffa1372a363cc8a5a3c64fee5f4b1f76eb079 +Subproject commit 65c99ad7697b2a6e1ad1a2212bc8de7b98d7e608 diff --git a/hecl/include/hecl/Backend/Backend.hpp b/hecl/include/hecl/Backend/Backend.hpp index 45c1cfcef..51b9d1034 100644 --- a/hecl/include/hecl/Backend/Backend.hpp +++ b/hecl/include/hecl/Backend/Backend.hpp @@ -178,6 +178,8 @@ struct ExtensionSlot { Function lighting; Function post; + size_t blockCount = 0; + const char** blockNames = nullptr; size_t texCount = 0; const Backend::TextureInfo* texs = nullptr; Backend::BlendFactor srcFactor = Backend::BlendFactor::Original; @@ -190,7 +192,9 @@ struct ExtensionSlot bool noAlphaOverwrite = false; bool noReflection = false; - ExtensionSlot(size_t texCount = 0, + ExtensionSlot(size_t blockCount = 0, + const char** blockNames = nullptr, + size_t texCount = 0, const Backend::TextureInfo* texs = nullptr, Backend::BlendFactor srcFactor = Backend::BlendFactor::Original, Backend::BlendFactor dstFactor = Backend::BlendFactor::Original, @@ -201,8 +205,9 @@ struct ExtensionSlot bool noAlphaWrite = false, bool noAlphaOverwrite = false, bool noReflection = false) - : texCount(texCount), texs(texs), srcFactor(srcFactor), dstFactor(dstFactor), depthTest(depthTest), - cullMode(cullMode), noDepthWrite(noDepthWrite), noColorWrite(noColorWrite), noAlphaWrite(noAlphaWrite), + : blockCount(blockCount), blockNames(blockNames), texCount(texCount), texs(texs), + srcFactor(srcFactor), dstFactor(dstFactor), depthTest(depthTest), cullMode(cullMode), + noDepthWrite(noDepthWrite), noColorWrite(noColorWrite), noAlphaWrite(noAlphaWrite), noAlphaOverwrite(noAlphaOverwrite), noReflection(noReflection) {} mutable uint64_t m_hash = 0; diff --git a/hecl/include/hecl/Backend/GLSL.hpp b/hecl/include/hecl/Backend/GLSL.hpp index 7783e0aec..8c5760c0b 100644 --- a/hecl/include/hecl/Backend/GLSL.hpp +++ b/hecl/include/hecl/Backend/GLSL.hpp @@ -14,9 +14,11 @@ struct GLSL : ProgrammableCommon std::string makeVert(unsigned col, unsigned uv, unsigned w, unsigned skinSlots, size_t extTexCount, const TextureInfo* extTexs, ReflectionType reflectionType) const; - std::string makeFrag(bool alphaTest, ReflectionType reflectionType, + std::string makeFrag(size_t blockCount, const char** blockNames, + bool alphaTest, ReflectionType reflectionType, const Function& lighting=Function()) const; - std::string makeFrag(bool alphaTest, + std::string makeFrag(size_t blockCount, const char** blockNames, + bool alphaTest, ReflectionType reflectionType, const Function& lighting, const Function& post, diff --git a/hecl/include/hecl/Backend/HLSL.hpp b/hecl/include/hecl/Backend/HLSL.hpp index f8c65e845..d5c97da9c 100644 --- a/hecl/include/hecl/Backend/HLSL.hpp +++ b/hecl/include/hecl/Backend/HLSL.hpp @@ -11,9 +11,11 @@ struct HLSL : ProgrammableCommon std::string makeVert(unsigned col, unsigned uv, unsigned w, unsigned skinSlots, size_t extTexCount, const TextureInfo* extTexs, ReflectionType reflectionType) const; - std::string makeFrag(bool alphaTest, ReflectionType reflectionType, + std::string makeFrag(size_t blockCount, const char** blockNames, + bool alphaTest, ReflectionType reflectionType, const Function& lighting=Function()) const; - std::string makeFrag(bool alphaTest, ReflectionType reflectionType, + std::string makeFrag(size_t blockCount, const char** blockNames, + bool alphaTest, ReflectionType reflectionType, const Function& lighting, const Function& post, size_t extTexCount, const TextureInfo* extTexs) const; diff --git a/hecl/include/hecl/Compilers.hpp b/hecl/include/hecl/Compilers.hpp index 5ec0647ae..f5b32c9b1 100644 --- a/hecl/include/hecl/Compilers.hpp +++ b/hecl/include/hecl/Compilers.hpp @@ -50,7 +50,21 @@ struct Control { static constexpr StageEnum Enum = StageEnum::Control; static co struct Evaluation { static constexpr StageEnum Enum = StageEnum::Evaluation; static const char* Name; }; } +#ifdef __APPLE__ +using StageBinaryData = std::shared_ptr; +static inline StageBinaryData MakeStageBinaryData(size_t sz) +{ + return StageBinaryData(new uint8_t[sz], std::default_delete{}); +} +#else +using StageBinaryData = std::shared_ptr; +static inline StageBinaryData MakeStageBinaryData(size_t sz) +{ + return StageBinaryData(new uint8_t[sz]); +} +#endif + template -std::pair, size_t> CompileShader(std::string_view text); +std::pair CompileShader(std::string_view text); } diff --git a/hecl/include/hecl/Pipeline.hpp b/hecl/include/hecl/Pipeline.hpp index b8a1545b6..3d6a7f94e 100644 --- a/hecl/include/hecl/Pipeline.hpp +++ b/hecl/include/hecl/Pipeline.hpp @@ -77,8 +77,8 @@ public: } std::string makeFrag() const { - return m_backend.makeFrag(m_tag.getDepthWrite() && - m_backend.m_blendDst == hecl::Backend::BlendFactor::InvSrcAlpha, + return m_backend.makeFrag(m_extension.blockCount, m_extension.blockNames, + m_tag.getDepthWrite() && m_backend.m_blendDst == hecl::Backend::BlendFactor::InvSrcAlpha, m_tag.getReflectionType(), m_extension.lighting, m_extension.post, m_extension.texCount, m_extension.texs); } @@ -631,6 +631,7 @@ inline std::unique_ptr NewPipelineConverter(boo::IGraphic #endif #if BOO_HAS_METAL case boo::IGraphicsDataFactory::Platform::Metal: + setenv("HECL_NO_METAL_COMPILER", "1", 1); return std::make_unique>(gfxF); #endif #if BOO_HAS_NX diff --git a/hecl/include/hecl/PipelineBase.hpp b/hecl/include/hecl/PipelineBase.hpp index f4871ca76..b109c81f7 100644 --- a/hecl/include/hecl/PipelineBase.hpp +++ b/hecl/include/hecl/PipelineBase.hpp @@ -73,7 +73,7 @@ public: template class StageBinary : public StageRep { - std::shared_ptr m_ownedData; + StageBinaryData m_ownedData; const uint8_t* m_data = nullptr; size_t m_size = 0; uint64_t m_hash = 0; @@ -86,11 +86,11 @@ public: StageBinary(const uint8_t* data, size_t size) : m_data(data), m_size(size) { m_hash = XXH64(m_data, m_size, 0); } - StageBinary(std::shared_ptr data, size_t size) + StageBinary(StageBinaryData data, size_t size) : m_ownedData(std::move(data)), m_data(m_ownedData.get()), m_size(size) { m_hash = XXH64(m_data, m_size, 0); } - explicit StageBinary(std::pair, size_t> data) + explicit StageBinary(std::pair data) : StageBinary(data.first, data.second) {} StageBinary(StageConverter& conv, FactoryCtx& ctx, const StageSourceText& in) : StageBinary(CompileShader(in.text())) {} @@ -162,7 +162,9 @@ public: } template StageCollection(PipelineConverter

& conv, FactoryCtx& ctx, const I& in, - typename std::enable_if_t>* = 0) + typename std::enable_if_t, + std::negation>>>* = 0) { m_vertex = conv.getVertexConverter().convert(ctx, in); m_fragment = conv.getFragmentConverter().convert(ctx, in); @@ -175,6 +177,20 @@ public: m_additionalInfo = in.PipelineInfo; MakeHash(); } + template + StageCollection(PipelineConverter

& conv, FactoryCtx& ctx, const I& in, + typename std::enable_if_t, + std::is_same>>* = 0) + { + m_vertex = conv.getVertexConverter().convert(ctx, in); + m_fragment = conv.getFragmentConverter().convert(ctx, in); + if (in.HasTessellation) + m_evaluation = conv.getEvaluationConverter().convert(ctx, in); + m_vtxFmt = in.VtxFmt; + m_additionalInfo = in.PipelineInfo; + MakeHash(); + } StageCollection(const T& vertex, const T& fragment, const T& geometry, @@ -189,7 +205,7 @@ public: } -#if 0 +#ifndef _WIN32 #define _STAGEOBJECT_PROTOTYPE_DECLARATIONS(T, P) \ template <> const hecl::StageBinary \ T::Prototype; \ @@ -201,8 +217,9 @@ template <> const hecl::StageBinary \ T::Prototype; \ template <> const hecl::StageBinary \ T::Prototype; -#endif +#else #define _STAGEOBJECT_PROTOTYPE_DECLARATIONS(T, P) +#endif #define STAGEOBJECT_PROTOTYPE_DECLARATIONS(T) \ _STAGEOBJECT_PROTOTYPE_DECLARATIONS(T, hecl::PlatformType::OpenGL) \ diff --git a/hecl/lib/Backend/GLSL.cpp b/hecl/lib/Backend/GLSL.cpp index 02e141fa7..7586647c9 100644 --- a/hecl/lib/Backend/GLSL.cpp +++ b/hecl/lib/Backend/GLSL.cpp @@ -220,7 +220,7 @@ std::string GLSL::makeVert(unsigned col, unsigned uv, unsigned w, return retval + "}\n"; } -std::string GLSL::makeFrag(bool alphaTest, +std::string GLSL::makeFrag(size_t blockCount, const char** blockNames, bool alphaTest, ReflectionType reflectionType, const Function& lighting) const { std::string lightingSrc; @@ -282,7 +282,8 @@ std::string GLSL::makeFrag(bool alphaTest, return retval + (alphaTest ? GenerateAlphaTest() : "") + "}\n"; } -std::string GLSL::makeFrag(bool alphaTest, +std::string GLSL::makeFrag(size_t blockCount, const char** blockNames, + bool alphaTest, ReflectionType reflectionType, const Function& lighting, const Function& post, diff --git a/hecl/lib/Backend/HLSL.cpp b/hecl/lib/Backend/HLSL.cpp index 81da87373..99d1303d8 100644 --- a/hecl/lib/Backend/HLSL.cpp +++ b/hecl/lib/Backend/HLSL.cpp @@ -214,7 +214,8 @@ std::string HLSL::makeVert(unsigned col, unsigned uv, unsigned w, "}\n"; } -std::string HLSL::makeFrag(bool alphaTest, ReflectionType reflectionType, +std::string HLSL::makeFrag(size_t blockCount, const char** blockNames, + bool alphaTest, ReflectionType reflectionType, const Function& lighting) const { std::string lightingSrc; @@ -271,7 +272,8 @@ std::string HLSL::makeFrag(bool alphaTest, ReflectionType reflectionType, return retval + (alphaTest ? GenerateAlphaTest() : "") + " return colorOut;\n}\n"; } -std::string HLSL::makeFrag(bool alphaTest, ReflectionType reflectionType, +std::string HLSL::makeFrag(size_t blockCount, const char** blockNames, + bool alphaTest, ReflectionType reflectionType, const Function& lighting, const Function& post, size_t extTexCount, const TextureInfo* extTexs) const diff --git a/hecl/lib/Compilers.cpp b/hecl/lib/Compilers.cpp index 697520531..438bb3084 100644 --- a/hecl/lib/Compilers.cpp +++ b/hecl/lib/Compilers.cpp @@ -1,16 +1,18 @@ #include "hecl/Compilers.hpp" #include "boo/graphicsdev/GLSLMacros.hpp" #include "logvisor/logvisor.hpp" -#if BOO_HAS_VULKAN #include #include #include #include -#endif #if _WIN32 #include extern pD3DCompile D3DCompilePROC; #endif +#if __APPLE__ +#include +#include +#endif namespace hecl { @@ -40,13 +42,13 @@ template struct ShaderCompiler {}; template<> struct ShaderCompiler { template - static std::pair, size_t> Compile(std::string_view text) + static std::pair Compile(std::string_view text) { std::string str = "#version 330\n"; str += BOO_GLSL_BINDING_HEAD; str += text; - std::pair, size_t> ret(new uint8_t[str.size() + 1], str.size() + 1); - memcpy(ret.first.get(), str.data(), str.size() + 1); + std::pair ret(MakeStageBinaryData(str.size() + 1), str.size() + 1); + memcpy(ret.first.get(), str.data(), ret.second); return ret; } }; @@ -64,7 +66,7 @@ template<> struct ShaderCompiler }; template - static std::pair, size_t> Compile(std::string_view text) + static std::pair Compile(std::string_view text) { EShLanguage lang = ShaderTypes[int(S::Enum)]; const EShMessages messages = EShMessages(EShMsgSpvRules | EShMsgVulkanRules); @@ -88,7 +90,7 @@ template<> struct ShaderCompiler std::vector out; glslang::GlslangToSpv(*prog.getIntermediate(lang), out); - std::pair, size_t> ret(new uint8_t[out.size() * 4], out.size() * 4); + std::pair ret(MakeStageBinaryData(out.size() * 4), out.size() * 4); memcpy(ret.first.get(), out.data(), ret.second); return ret; } @@ -112,7 +114,7 @@ template<> struct ShaderCompiler #define BOO_D3DCOMPILE_FLAG D3DCOMPILE_OPTIMIZATION_LEVEL3 #endif template - static std::pair, size_t> Compile(std::string_view text) + static std::pair Compile(std::string_view text) { ComPtr errBlob; ComPtr blobOut; @@ -123,13 +125,176 @@ template<> struct ShaderCompiler Log.report(logvisor::Fatal, "error compiling shader: %s", errBlob->GetBufferPointer()); return {}; } - std::pair, size_t> ret(new uint8_t[blobOut->GetBufferSize()], blobOut->GetBufferSize()); + std::pair ret(MakeStageBinaryData(blobOut->GetBufferSize()), + blobOut->GetBufferSize()); memcpy(ret.first.get(), blobOut->GetBufferPointer(), blobOut->GetBufferSize()); return ret; } }; #endif +#if __APPLE__ +template<> struct ShaderCompiler +{ + static bool m_didCompilerSearch; + static bool m_hasCompiler; + + static bool SearchForCompiler() + { + m_didCompilerSearch = true; + const char* no_metal_compiler = getenv("HECL_NO_METAL_COMPILER"); + if (no_metal_compiler && atoi(no_metal_compiler)) + return false; + + pid_t pid = fork(); + if (!pid) + { + execlp("xcrun", "xcrun", "-sdk", "macosx", "metal", NULL); + /* xcrun returns 72 if metal command not found; + * emulate that if xcrun not found */ + exit(72); + } + + int status, ret; + while ((ret = waitpid(pid, &status, 0)) < 0 && errno == EINTR) {} + if (ret < 0) + return false; + return WEXITSTATUS(status) == 1; + } + + template + static std::pair Compile(std::string_view text) + { + if (!m_didCompilerSearch) + m_hasCompiler = SearchForCompiler(); + + std::string str = "#include \n" + "using namespace metal;\n"; + str += text; + std::pair ret; + + if (!m_hasCompiler) + { + /* First byte unset to indicate source data */ + ret.first = MakeStageBinaryData(str.size() + 2); + ret.first.get()[0] = 0; + ret.second = str.size() + 2; + memcpy(&ret.first.get()[1], str.data(), str.size() + 1); + } + else + { + int compilerOut[2]; + int compilerIn[2]; + pipe(compilerOut); + pipe(compilerIn); + + pid_t pid = getpid(); + const char* tmpdir = getenv("TMPDIR"); + char libFile[1024]; + snprintf(libFile, 1024, "%sboo_metal_shader%d.metallib", tmpdir, pid); + + /* Pipe source write to compiler */ + pid_t compilerPid = fork(); + if (!compilerPid) + { + dup2(compilerIn[0], STDIN_FILENO); + dup2(compilerOut[1], STDOUT_FILENO); + + close(compilerOut[0]); + close(compilerOut[1]); + close(compilerIn[0]); + close(compilerIn[1]); + + execlp("xcrun", "xcrun", "-sdk", "macosx", "metal", "-o", "/dev/stdout", "-Wno-unused-variable", + "-Wno-unused-const-variable", "-Wno-unused-function", "-c", "-x", "metal", "-", NULL); + fprintf(stderr, "execlp fail %s\n", strerror(errno)); + exit(1); + } + close(compilerIn[0]); + close(compilerOut[1]); + + /* Pipe compiler to linker */ + pid_t linkerPid = fork(); + if (!linkerPid) + { + dup2(compilerOut[0], STDIN_FILENO); + + close(compilerOut[0]); + close(compilerIn[1]); + + /* metallib doesn't like outputting to a pipe, so temp file will have to do */ + execlp("xcrun", "xcrun", "-sdk", "macosx", "metallib", "-", "-o", libFile, NULL); + fprintf(stderr, "execlp fail %s\n", strerror(errno)); + exit(1); + } + close(compilerOut[0]); + + /* Stream in source */ + const char* inPtr = str.data(); + size_t inRem = str.size(); + while (inRem) + { + ssize_t writeRes = write(compilerIn[1], inPtr, inRem); + if (writeRes < 0) + { + fprintf(stderr, "write fail %s\n", strerror(errno)); + break; + } + inPtr += writeRes; + inRem -= writeRes; + } + close(compilerIn[1]); + + /* Wait for completion */ + int compilerStat, linkerStat; + while (waitpid(compilerPid, &compilerStat, 0) < 0) + { + if (errno == EINTR) + continue; + Log.report(logvisor::Fatal, "waitpid fail %s", strerror(errno)); + return {}; + } + + if (WEXITSTATUS(compilerStat)) + { + Log.report(logvisor::Fatal, "compile fail"); + return {}; + } + + while (waitpid(linkerPid, &linkerStat, 0) < 0) + { + if (errno == EINTR) + continue; + Log.report(logvisor::Fatal, "waitpid fail %s", strerror(errno)); + return {}; + } + + if (WEXITSTATUS(linkerStat)) + { + Log.report(logvisor::Fatal, "link fail"); + return {}; + } + + /* Copy temp file into buffer with first byte set to indicate binary data */ + FILE* fin = fopen(libFile, "rb"); + fseek(fin, 0, SEEK_END); + long libLen = ftell(fin); + fseek(fin, 0, SEEK_SET); + ret.first = MakeStageBinaryData(libLen + 1); + ret.first.get()[0] = 1; + ret.second = libLen + 1; + fread(&ret.first.get()[1], 1, libLen, fin); + fclose(fin); + unlink(libFile); + } + + return ret; + } +}; +bool ShaderCompiler::m_didCompilerSearch = false; +bool ShaderCompiler::m_hasCompiler = false; +#endif + #if HECL_NOUVEAU_NX template<> struct ShaderCompiler { @@ -147,16 +312,16 @@ template<> struct ShaderCompiler #endif template -std::pair, size_t> CompileShader(std::string_view text) +std::pair CompileShader(std::string_view text) { return ShaderCompiler

::template Compile(text); } #define SPECIALIZE_COMPILE_SHADER(P) \ -template std::pair, size_t> CompileShader(std::string_view text); \ -template std::pair, size_t> CompileShader(std::string_view text); \ -template std::pair, size_t> CompileShader(std::string_view text); \ -template std::pair, size_t> CompileShader(std::string_view text); \ -template std::pair, size_t> CompileShader(std::string_view text); +template std::pair CompileShader(std::string_view text); \ +template std::pair CompileShader(std::string_view text); \ +template std::pair CompileShader(std::string_view text); \ +template std::pair CompileShader(std::string_view text); \ +template std::pair CompileShader(std::string_view text); SPECIALIZE_COMPILE_SHADER(PlatformType::OpenGL) SPECIALIZE_COMPILE_SHADER(PlatformType::Vulkan) #if _WIN32 @@ -169,127 +334,4 @@ SPECIALIZE_COMPILE_SHADER(PlatformType::Metal) SPECIALIZE_COMPILE_SHADER(PlatformType::NX) #endif -#if BOO_HAS_METAL -static int HasMetalCompiler = -1; - -static void CheckForMetalCompiler() -{ - pid_t pid = fork(); - if (!pid) - { - execlp("xcrun", "xcrun", "-sdk", "macosx", "metal", NULL); - /* xcrun returns 72 if metal command not found; - * emulate that if xcrun not found */ - exit(72); - } - - int status, ret; - while ((ret = waitpid(pid, &status, 0)) < 0 && errno == EINTR) {} - if (ret < 0) - HasMetalCompiler = 0; - else - HasMetalCompiler = WEXITSTATUS(status) == 1; -} - -template<> -std::vector CompileShader(std::string_view text, PipelineStage stage) -{ - if (HasMetalCompiler == -1) - CheckForMetalCompiler(); - - std::vector blobOut; - if (!HasMetalCompiler) - { - /* Cache the source if there's no compiler */ - size_t sourceLen = strlen(source); - - /* First byte unset to indicate source data */ - blobOut.resize(sourceLen + 2); - memcpy(&blobOut[1], source, sourceLen); - } - else - { - /* Cache the binary otherwise */ - int compilerOut[2]; - int compilerIn[2]; - pipe(compilerOut); - pipe(compilerIn); - - /* Pipe source write to compiler */ - pid_t compilerPid = fork(); - if (!compilerPid) - { - dup2(compilerIn[0], STDIN_FILENO); - dup2(compilerOut[1], STDOUT_FILENO); - - close(compilerOut[0]); - close(compilerOut[1]); - close(compilerIn[0]); - close(compilerIn[1]); - - execlp("xcrun", "xcrun", "-sdk", "macosx", "metal", "-o", "/dev/stdout", "-Wno-unused-variable", - "-Wno-unused-const-variable", "-Wno-unused-function", "-x", "metal", "-", NULL); - fprintf(stderr, "execlp fail %s\n", strerror(errno)); - exit(1); - } - close(compilerIn[0]); - close(compilerOut[1]); - - /* Pipe compiler to linker */ - pid_t linkerPid = fork(); - if (!linkerPid) - { - dup2(compilerOut[0], STDIN_FILENO); - - close(compilerOut[0]); - close(compilerIn[1]); - - /* metallib doesn't like outputting to a pipe, so temp file will have to do */ - execlp("xcrun", "xcrun", "-sdk", "macosx", "metallib", "-", "-o", m_libfile, NULL); - fprintf(stderr, "execlp fail %s\n", strerror(errno)); - exit(1); - } - close(compilerOut[0]); - - /* Stream in source */ - const char* inPtr = source; - size_t inRem = strlen(source); - while (inRem) - { - ssize_t writeRes = write(compilerIn[1], inPtr, inRem); - if (writeRes < 0) - { - fprintf(stderr, "write fail %s\n", strerror(errno)); - break; - } - inPtr += writeRes; - inRem -= writeRes; - } - close(compilerIn[1]); - - /* Wait for completion */ - int compilerStat, linkerStat; - if (waitpid(compilerPid, &compilerStat, 0) < 0 || waitpid(linkerPid, &linkerStat, 0) < 0) - { - fprintf(stderr, "waitpid fail %s\n", strerror(errno)); - return {}; - } - - if (WEXITSTATUS(compilerStat) || WEXITSTATUS(linkerStat)) - return {}; - - /* Copy temp file into buffer with first byte set to indicate binary data */ - FILE* fin = fopen(m_libfile, "rb"); - fseek(fin, 0, SEEK_END); - long libLen = ftell(fin); - fseek(fin, 0, SEEK_SET); - blobOut.resize(libLen + 1); - blobOut[0] = 1; - fread(&blobOut[1], 1, libLen, fin); - fclose(fin); - } - return blobOut; -} -#endif - } diff --git a/hecl/lib/Pipeline.cpp b/hecl/lib/Pipeline.cpp index 0440f155e..87b7baadb 100644 --- a/hecl/lib/Pipeline.cpp +++ b/hecl/lib/Pipeline.cpp @@ -64,9 +64,10 @@ void StageConverter::loadFromStream(FactoryCtx& ctx, ShaderCacheZipStream& { uint64_t hash = r.readUint64Big(); uint32_t size = r.readUint32Big(); - std::shared_ptr data(new uint8_t[size]); + StageBinaryData data = MakeStageBinaryData(size); r.readUBytesToBuf(data.get(), size); - m_stageCache.insert(std::make_pair(hash, Do(ctx, StageBinary(data, size)))); + m_stageCache.insert(std::make_pair(hash, + Do(ctx, StageBinary(data, size)))); } } diff --git a/hecl/shaderc/shaderc.cpp b/hecl/shaderc/shaderc.cpp index 66fc12bbf..2b0b07ff2 100644 --- a/hecl/shaderc/shaderc.cpp +++ b/hecl/shaderc/shaderc.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include using namespace std::literals; @@ -100,7 +102,7 @@ struct CompileStageAction template static bool Do(const std::string& name, const std::string& basename, const std::string& stage, std::string& implOut) { - std::pair, size_t> data = CompileShader(stage); + std::pair data = CompileShader(stage); if (data.second == 0) return false; @@ -109,7 +111,7 @@ struct CompileStageAction { implOut += " "; for (int j = 0; j < 10 && i < data.second ; ++i, ++j) - implOut += Format("0x%02X, ", data.first[i]); + implOut += Format("0x%02X, ", data.first.get()[i]); implOut += "\n"; } implOut += "};\n\n";