From 48ec4cf6ebdc50a31406c477e1465a9136ef43c2 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sat, 21 Oct 2017 20:10:59 -1000 Subject: [PATCH] Various bug fixes --- hecl/blender/hecl/frme.py | 2 +- hecl/extern/boo | 2 +- hecl/include/hecl/ClientProcess.hpp | 11 +++++++++++ hecl/include/hecl/Runtime.hpp | 8 ++++++-- hecl/lib/Backend/GLSL.cpp | 4 ++-- hecl/lib/Backend/Metal.cpp | 23 +++++++++++++++-------- hecl/lib/Backend/ProgrammableCommon.cpp | 2 +- hecl/lib/Blender/BlenderConnection.cpp | 6 ++++-- hecl/lib/ClientProcess.cpp | 8 +++++++- hecl/lib/Runtime/ShaderCacheManager.cpp | 12 ++++-------- 10 files changed, 52 insertions(+), 26 deletions(-) diff --git a/hecl/blender/hecl/frme.py b/hecl/blender/hecl/frme.py index d07c82cb9..e9ceb157d 100644 --- a/hecl/blender/hecl/frme.py +++ b/hecl/blender/hecl/frme.py @@ -183,7 +183,7 @@ def recursive_cook(buffer, obj, version, path_hasher, parent_name): elif obj.retro_widget_type == 'RETRO_ENRG': path_hash = path_hasher.hashpath32(obj.retro_energybar_texture_path) - buffer += struct.pack('>ffff', path_hash) + buffer += struct.pack('>I', path_hash) elif obj.retro_widget_type == 'RETRO_METR': buffer += struct.pack('>bbII', diff --git a/hecl/extern/boo b/hecl/extern/boo index 7eb2b1961..41d225bd6 160000 --- a/hecl/extern/boo +++ b/hecl/extern/boo @@ -1 +1 @@ -Subproject commit 7eb2b19619117c8f923d8b098e2a2d710cd3363a +Subproject commit 41d225bd64a5e1840a7f4d1ea7bbd33b50cf90aa diff --git a/hecl/include/hecl/ClientProcess.hpp b/hecl/include/hecl/ClientProcess.hpp index 3f576fffb..9729dc6ce 100644 --- a/hecl/include/hecl/ClientProcess.hpp +++ b/hecl/include/hecl/ClientProcess.hpp @@ -4,6 +4,7 @@ #include "hecl.hpp" #include "Database.hpp" #include "hecl/Blender/BlenderConnection.hpp" +#include "boo/ThreadLocalPtr.hpp" #include #include #include @@ -80,6 +81,7 @@ private: void proc(); }; std::vector m_workers; + static ThreadLocalPtr ThreadWorker; public: ClientProcess(int verbosityLevel=1); @@ -95,6 +97,15 @@ public: void swapCompletedQueue(std::list>& queue); void waitUntilComplete(); void shutdown(); + bool isBusy() const { return m_pendingQueue.size() || m_inProgress; } + + static int GetThreadWorkerIdx() + { + Worker* w = ThreadWorker.get(); + if (w) + return w->m_idx; + return -1; + } }; } diff --git a/hecl/include/hecl/Runtime.hpp b/hecl/include/hecl/Runtime.hpp index eac15de9a..409297859 100644 --- a/hecl/include/hecl/Runtime.hpp +++ b/hecl/include/hecl/Runtime.hpp @@ -145,6 +145,7 @@ public: bool noDepthWrite = false; bool noColorWrite = false; bool noAlphaWrite = false; + bool noReflection = false; }; std::vector m_extensionSlots; @@ -164,7 +165,8 @@ public: bool frontfaceCull = false, bool noDepthWrite = false, bool noColorWrite = false, - bool noAlphaWrite = false) + bool noAlphaWrite = false, + bool noReflection = false) { m_extensionSlots.emplace_back(); ExtensionSlot& slot = m_extensionSlots.back(); @@ -181,6 +183,7 @@ public: slot.noDepthWrite = noDepthWrite; slot.noColorWrite = noColorWrite; slot.noAlphaWrite = noAlphaWrite; + slot.noReflection = noReflection; return m_extensionSlots.size() - 1; } }; @@ -247,7 +250,7 @@ class ShaderCacheManager }; std::vector m_entries; std::unordered_map m_entryLookup; - std::unordered_map> m_pipelineLookup; + std::unordered_map> m_pipelineLookup; uint64_t m_timeHash = 0; void bootstrapIndex(); @@ -265,6 +268,7 @@ public: boo::IGraphicsDataFactory* gfxFactory) : ShaderCacheManager(storeMgr, gfxFactory, ShaderCacheExtensions()) {} void reload(); + void clearCachedPipelines() { m_pipelineLookup.clear(); } /* Some platforms (like Metal) require information about the render target * for encoding the pipeline state. This must be called before building shaders */ diff --git a/hecl/lib/Backend/GLSL.cpp b/hecl/lib/Backend/GLSL.cpp index be20ce6b4..a03d3de7e 100644 --- a/hecl/lib/Backend/GLSL.cpp +++ b/hecl/lib/Backend/GLSL.cpp @@ -216,8 +216,8 @@ std::string GLSL::makeVert(const char* glslVer, unsigned col, unsigned uv, unsig } if (reflectionType != ReflectionType::None) - retval += " vtf.reflectTcgs[0] = normalize((indMtx * vec4(v.posIn, 1.0)).xz) * vec2(0.5, 0.5) + vec2(0.5, 0.5);\n" - " vtf.reflectTcgs[1] = (reflectMtx * vec4(v.posIn, 1.0)).xy;\n" + retval += " vtf.reflectTcgs[0] = normalize((indMtx * vec4(posIn, 1.0)).xz) * vec2(0.5, 0.5) + vec2(0.5, 0.5);\n" + " vtf.reflectTcgs[1] = (reflectMtx * vec4(posIn, 1.0)).xy;\n" " vtf.reflectAlpha = reflectAlpha;\n"; return retval + "}\n"; diff --git a/hecl/lib/Backend/Metal.cpp b/hecl/lib/Backend/Metal.cpp index fa6576771..ed95a3d06 100644 --- a/hecl/lib/Backend/Metal.cpp +++ b/hecl/lib/Backend/Metal.cpp @@ -396,10 +396,8 @@ std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alp { if (lighting.m_entry) { - if (!strncmp(lighting.m_entry, "EXT", 3)) - retval += " float4 lighting = " + lightingEntry + "(" + blockCall + ", vtf.mvPos, vtf.mvNorm, vtf, " + (extTexCall.size() ? (extTexCall + ", ") : "") + ");\n"; - else - retval += " float4 lighting = " + lightingEntry + "(" + blockCall + ", vtf.mvPos, vtf.mvNorm, vtf);\n"; + retval += " float4 lighting = " + lightingEntry + "(" + blockCall + ", vtf.mvPos, vtf.mvNorm, vtf" + + (!strncmp(lighting.m_entry, "EXT", 3) ? (extTexCall.size() ? (", " + extTexCall) : "") : "") + ");\n"; } else retval += " float4 lighting = float4(1.0,1.0,1.0,1.0);\n"; @@ -413,11 +411,19 @@ std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alp std::string reflectionExpr = GenerateReflectionExpr(reflectionType); if (m_alphaExpr.size()) - retval += " out.color = " + postEntry + "(" + (postEntry.size() ? ("vtf, " + (blockCall.size() ? (blockCall + ", ") : "") + (extTexCall.size() ? (extTexCall + ", ") : "")) : "") + + { + retval += " out.color = " + postEntry + "(" + + (postEntry.size() ? ("vtf, " + (blockCall.size() ? (blockCall + ", ") : "") + + (!strncmp(post.m_entry, "EXT", 3) ? (extTexCall.size() ? (extTexCall + ", ") : "") : "")) : "") + "float4(" + m_colorExpr + " + " + reflectionExpr + ", " + m_alphaExpr + ")) * mulColor;\n"; + } else - retval += " out.color = " + postEntry + "(" + (postEntry.size() ? ("vtf, " + (blockCall.size() ? (blockCall + ", ") : "") + (extTexCall.size() ? (extTexCall + ", ") : "")) : "") + + { + retval += " out.color = " + postEntry + "(" + + (postEntry.size() ? ("vtf, " + (blockCall.size() ? (blockCall + ", ") : "") + + (!strncmp(post.m_entry, "EXT", 3) ? (extTexCall.size() ? (extTexCall + ", ") : "") : "")) : "") + "float4(" + m_colorExpr + " + " + reflectionExpr + ", 1.0)) * mulColor;\n"; + } return retval + (alphaTest ? GenerateAlphaTest() : "") + " //out.depth = 1.0 - float(int((1.0 - vtf.mvpPos.z) * 16777216.0)) / 16777216.0;\n" @@ -526,10 +532,11 @@ struct MetalBackendFactory : IShaderBackendFactory { sources.emplace_back(m_backend.makeVert(tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(), tag.getSkinSlotCount(), tag.getTexMtxCount(), slot.texCount, slot.texs, - tag.getReflectionType()), + slot.noReflection ? Backend::ReflectionType::None : tag.getReflectionType()), m_backend.makeFrag(slot.blockCount, slot.blockNames, tag.getDepthWrite() && m_backend.m_blendDst == hecl::Backend::BlendFactor::InvSrcAlpha, - tag.getReflectionType(), slot.lighting, slot.post, slot.texCount, slot.texs)); + slot.noReflection ? Backend::ReflectionType::None : tag.getReflectionType(), + slot.lighting, slot.post, slot.texCount, slot.texs)); cachedSz += sources.back().first.size() + 1; cachedSz += sources.back().second.size() + 1; diff --git a/hecl/lib/Backend/ProgrammableCommon.cpp b/hecl/lib/Backend/ProgrammableCommon.cpp index 63a67444c..4ce5ef339 100644 --- a/hecl/lib/Backend/ProgrammableCommon.cpp +++ b/hecl/lib/Backend/ProgrammableCommon.cpp @@ -191,7 +191,7 @@ std::string ProgrammableCommon::RecursiveTraceAlpha(const IR& ir, Diagnostics& d { const IR::Instruction& idxInst = inst.getChildInst(ir, 0); unsigned idx = unsigned(idxInst.getImmVec().vec[0]); - return EmitColorRegUseAlpha(idx); + return toSwizzle ? EmitColorRegUseRaw(idx) : EmitColorRegUseAlpha(idx); } else if (!name.compare("Lighting")) { diff --git a/hecl/lib/Blender/BlenderConnection.cpp b/hecl/lib/Blender/BlenderConnection.cpp index 53f423cbf..b4b43d5e6 100644 --- a/hecl/lib/Blender/BlenderConnection.cpp +++ b/hecl/lib/Blender/BlenderConnection.cpp @@ -518,7 +518,8 @@ BlenderConnection::BlenderConnection(int verbosityLevel) InstallAddon(blenderAddonPath.c_str()); ++installAttempt; if (installAttempt >= 2) - BlenderLog.report(logvisor::Fatal, _S("unable to install blender addon using '%s'"), blenderAddonPath.c_str()); + BlenderLog.report(logvisor::Fatal, _S("unable to install blender addon using '%s'"), + blenderAddonPath.c_str()); continue; } else if (!strcmp(lineBuf, "ADDONINSTALLED")) @@ -600,7 +601,8 @@ bool BlenderConnection::createBlend(const ProjectPath& path, BlendType type) "BlenderConnection::createBlend() musn't be called with stream active"); return false; } - _writeStr(("CREATE \"" + path.getAbsolutePathUTF8() + "\" " + BlendTypeStrs[int(type)] + " \"" + m_startupBlend + "\"").c_str()); + _writeStr(("CREATE \"" + path.getAbsolutePathUTF8() + "\" " + BlendTypeStrs[int(type)] + + " \"" + m_startupBlend + "\"").c_str()); char lineBuf[256]; _readStr(lineBuf, sizeof(lineBuf)); if (!strcmp(lineBuf, "FINISHED")) diff --git a/hecl/lib/ClientProcess.cpp b/hecl/lib/ClientProcess.cpp index 82f684803..a081095e1 100644 --- a/hecl/lib/ClientProcess.cpp +++ b/hecl/lib/ClientProcess.cpp @@ -10,10 +10,14 @@ #include #endif +#define HECL_MULTIPROCESSOR 1 + namespace hecl { static logvisor::Module Log("hecl::ClientProcess"); +ThreadLocalPtr ClientProcess::ThreadWorker; + static int GetCPUCount() { #if _WIN32 @@ -68,6 +72,8 @@ ClientProcess::Worker::Worker(ClientProcess& proc, int idx) void ClientProcess::Worker::proc() { + ClientProcess::ThreadWorker.reset(this); + char thrName[64]; snprintf(thrName, 64, "HECL Client Worker %d", m_idx); logvisor::RegisterThreadName(thrName); @@ -172,7 +178,7 @@ void ClientProcess::swapCompletedQueue(std::list>& void ClientProcess::waitUntilComplete() { std::unique_lock lk(m_mutex); - while (m_pendingQueue.size() || m_inProgress) + while (isBusy()) m_waitCv.wait(lk); } diff --git a/hecl/lib/Runtime/ShaderCacheManager.cpp b/hecl/lib/Runtime/ShaderCacheManager.cpp index 560a7e138..a14e5cdea 100644 --- a/hecl/lib/Runtime/ShaderCacheManager.cpp +++ b/hecl/lib/Runtime/ShaderCacheManager.cpp @@ -384,8 +384,7 @@ ShaderCacheManager::buildShader(const ShaderTag& tag, const std::string& source, { auto search = m_pipelineLookup.find(tag); if (search != m_pipelineLookup.cend()) - if (auto ret = search->second.lock()) - return ret; + return search->second; std::shared_ptr ret = std::make_shared(); ShaderCachedData foundData = lookupData(tag); @@ -432,8 +431,7 @@ ShaderCacheManager::buildShader(const ShaderTag& tag, const hecl::Frontend::IR& { auto search = m_pipelineLookup.find(tag); if (search != m_pipelineLookup.cend()) - if (auto ret = search->second.lock()) - return ret; + return search->second; std::shared_ptr ret = std::make_shared(); ShaderCachedData foundData = lookupData(tag); @@ -494,8 +492,7 @@ ShaderCacheManager::buildExtendedShader(const ShaderTag& tag, const std::string& { auto search = m_pipelineLookup.find(tag); if (search != m_pipelineLookup.cend()) - if (auto ret = search->second.lock()) - return ret; + return search->second; std::shared_ptr ret = std::make_shared(); ShaderCachedData foundData = lookupData(tag); @@ -545,8 +542,7 @@ ShaderCacheManager::buildExtendedShader(const ShaderTag& tag, const hecl::Fronte { auto search = m_pipelineLookup.find(tag); if (search != m_pipelineLookup.cend()) - if (auto ret = search->second.lock()) - return ret; + return search->second; std::shared_ptr ret = std::make_shared(); ShaderCachedData foundData = lookupData(tag);