Various bug fixes

This commit is contained in:
Jack Andersen 2017-10-21 20:10:59 -10:00
parent ebad51dc2e
commit 48ec4cf6eb
10 changed files with 52 additions and 26 deletions

View File

@ -183,7 +183,7 @@ def recursive_cook(buffer, obj, version, path_hasher, parent_name):
elif obj.retro_widget_type == 'RETRO_ENRG': elif obj.retro_widget_type == 'RETRO_ENRG':
path_hash = path_hasher.hashpath32(obj.retro_energybar_texture_path) 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': elif obj.retro_widget_type == 'RETRO_METR':
buffer += struct.pack('>bbII', buffer += struct.pack('>bbII',

2
hecl/extern/boo vendored

@ -1 +1 @@
Subproject commit 7eb2b19619117c8f923d8b098e2a2d710cd3363a Subproject commit 41d225bd64a5e1840a7f4d1ea7bbd33b50cf90aa

View File

@ -4,6 +4,7 @@
#include "hecl.hpp" #include "hecl.hpp"
#include "Database.hpp" #include "Database.hpp"
#include "hecl/Blender/BlenderConnection.hpp" #include "hecl/Blender/BlenderConnection.hpp"
#include "boo/ThreadLocalPtr.hpp"
#include <list> #include <list>
#include <thread> #include <thread>
#include <mutex> #include <mutex>
@ -80,6 +81,7 @@ private:
void proc(); void proc();
}; };
std::vector<Worker> m_workers; std::vector<Worker> m_workers;
static ThreadLocalPtr<ClientProcess::Worker> ThreadWorker;
public: public:
ClientProcess(int verbosityLevel=1); ClientProcess(int verbosityLevel=1);
@ -95,6 +97,15 @@ public:
void swapCompletedQueue(std::list<std::shared_ptr<Transaction>>& queue); void swapCompletedQueue(std::list<std::shared_ptr<Transaction>>& queue);
void waitUntilComplete(); void waitUntilComplete();
void shutdown(); 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;
}
}; };
} }

View File

@ -145,6 +145,7 @@ public:
bool noDepthWrite = false; bool noDepthWrite = false;
bool noColorWrite = false; bool noColorWrite = false;
bool noAlphaWrite = false; bool noAlphaWrite = false;
bool noReflection = false;
}; };
std::vector<ExtensionSlot> m_extensionSlots; std::vector<ExtensionSlot> m_extensionSlots;
@ -164,7 +165,8 @@ public:
bool frontfaceCull = false, bool frontfaceCull = false,
bool noDepthWrite = false, bool noDepthWrite = false,
bool noColorWrite = false, bool noColorWrite = false,
bool noAlphaWrite = false) bool noAlphaWrite = false,
bool noReflection = false)
{ {
m_extensionSlots.emplace_back(); m_extensionSlots.emplace_back();
ExtensionSlot& slot = m_extensionSlots.back(); ExtensionSlot& slot = m_extensionSlots.back();
@ -181,6 +183,7 @@ public:
slot.noDepthWrite = noDepthWrite; slot.noDepthWrite = noDepthWrite;
slot.noColorWrite = noColorWrite; slot.noColorWrite = noColorWrite;
slot.noAlphaWrite = noAlphaWrite; slot.noAlphaWrite = noAlphaWrite;
slot.noReflection = noReflection;
return m_extensionSlots.size() - 1; return m_extensionSlots.size() - 1;
} }
}; };
@ -247,7 +250,7 @@ class ShaderCacheManager
}; };
std::vector<IndexEntry> m_entries; std::vector<IndexEntry> m_entries;
std::unordered_map<Hash, size_t> m_entryLookup; std::unordered_map<Hash, size_t> m_entryLookup;
std::unordered_map<Hash, std::weak_ptr<ShaderPipelines>> m_pipelineLookup; std::unordered_map<Hash, std::shared_ptr<ShaderPipelines>> m_pipelineLookup;
uint64_t m_timeHash = 0; uint64_t m_timeHash = 0;
void bootstrapIndex(); void bootstrapIndex();
@ -265,6 +268,7 @@ public:
boo::IGraphicsDataFactory* gfxFactory) boo::IGraphicsDataFactory* gfxFactory)
: ShaderCacheManager(storeMgr, gfxFactory, ShaderCacheExtensions()) {} : ShaderCacheManager(storeMgr, gfxFactory, ShaderCacheExtensions()) {}
void reload(); void reload();
void clearCachedPipelines() { m_pipelineLookup.clear(); }
/* Some platforms (like Metal) require information about the render target /* Some platforms (like Metal) require information about the render target
* for encoding the pipeline state. This must be called before building shaders */ * for encoding the pipeline state. This must be called before building shaders */

View File

@ -216,8 +216,8 @@ std::string GLSL::makeVert(const char* glslVer, unsigned col, unsigned uv, unsig
} }
if (reflectionType != ReflectionType::None) 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" 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(v.posIn, 1.0)).xy;\n" " vtf.reflectTcgs[1] = (reflectMtx * vec4(posIn, 1.0)).xy;\n"
" vtf.reflectAlpha = reflectAlpha;\n"; " vtf.reflectAlpha = reflectAlpha;\n";
return retval + "}\n"; return retval + "}\n";

View File

@ -396,10 +396,8 @@ std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alp
{ {
if (lighting.m_entry) if (lighting.m_entry)
{ {
if (!strncmp(lighting.m_entry, "EXT", 3)) retval += " float4 lighting = " + lightingEntry + "(" + blockCall + ", vtf.mvPos, vtf.mvNorm, vtf" +
retval += " float4 lighting = " + lightingEntry + "(" + blockCall + ", vtf.mvPos, vtf.mvNorm, vtf, " + (extTexCall.size() ? (extTexCall + ", ") : "") + ");\n"; (!strncmp(lighting.m_entry, "EXT", 3) ? (extTexCall.size() ? (", " + extTexCall) : "") : "") + ");\n";
else
retval += " float4 lighting = " + lightingEntry + "(" + blockCall + ", vtf.mvPos, vtf.mvNorm, vtf);\n";
} }
else else
retval += " float4 lighting = float4(1.0,1.0,1.0,1.0);\n"; 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); std::string reflectionExpr = GenerateReflectionExpr(reflectionType);
if (m_alphaExpr.size()) 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"; "float4(" + m_colorExpr + " + " + reflectionExpr + ", " + m_alphaExpr + ")) * mulColor;\n";
}
else 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"; "float4(" + m_colorExpr + " + " + reflectionExpr + ", 1.0)) * mulColor;\n";
}
return retval + (alphaTest ? GenerateAlphaTest() : "") + return retval + (alphaTest ? GenerateAlphaTest() : "") +
" //out.depth = 1.0 - float(int((1.0 - vtf.mvpPos.z) * 16777216.0)) / 16777216.0;\n" " //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(), sources.emplace_back(m_backend.makeVert(tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(),
tag.getSkinSlotCount(), tag.getTexMtxCount(), slot.texCount, slot.texs, tag.getSkinSlotCount(), tag.getTexMtxCount(), slot.texCount, slot.texs,
tag.getReflectionType()), slot.noReflection ? Backend::ReflectionType::None : tag.getReflectionType()),
m_backend.makeFrag(slot.blockCount, slot.blockNames, m_backend.makeFrag(slot.blockCount, slot.blockNames,
tag.getDepthWrite() && m_backend.m_blendDst == hecl::Backend::BlendFactor::InvSrcAlpha, 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().first.size() + 1;
cachedSz += sources.back().second.size() + 1; cachedSz += sources.back().second.size() + 1;

View File

@ -191,7 +191,7 @@ std::string ProgrammableCommon::RecursiveTraceAlpha(const IR& ir, Diagnostics& d
{ {
const IR::Instruction& idxInst = inst.getChildInst(ir, 0); const IR::Instruction& idxInst = inst.getChildInst(ir, 0);
unsigned idx = unsigned(idxInst.getImmVec().vec[0]); unsigned idx = unsigned(idxInst.getImmVec().vec[0]);
return EmitColorRegUseAlpha(idx); return toSwizzle ? EmitColorRegUseRaw(idx) : EmitColorRegUseAlpha(idx);
} }
else if (!name.compare("Lighting")) else if (!name.compare("Lighting"))
{ {

View File

@ -518,7 +518,8 @@ BlenderConnection::BlenderConnection(int verbosityLevel)
InstallAddon(blenderAddonPath.c_str()); InstallAddon(blenderAddonPath.c_str());
++installAttempt; ++installAttempt;
if (installAttempt >= 2) 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; continue;
} }
else if (!strcmp(lineBuf, "ADDONINSTALLED")) 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"); "BlenderConnection::createBlend() musn't be called with stream active");
return false; 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]; char lineBuf[256];
_readStr(lineBuf, sizeof(lineBuf)); _readStr(lineBuf, sizeof(lineBuf));
if (!strcmp(lineBuf, "FINISHED")) if (!strcmp(lineBuf, "FINISHED"))

View File

@ -10,10 +10,14 @@
#include <sys/wait.h> #include <sys/wait.h>
#endif #endif
#define HECL_MULTIPROCESSOR 1
namespace hecl namespace hecl
{ {
static logvisor::Module Log("hecl::ClientProcess"); static logvisor::Module Log("hecl::ClientProcess");
ThreadLocalPtr<ClientProcess::Worker> ClientProcess::ThreadWorker;
static int GetCPUCount() static int GetCPUCount()
{ {
#if _WIN32 #if _WIN32
@ -68,6 +72,8 @@ ClientProcess::Worker::Worker(ClientProcess& proc, int idx)
void ClientProcess::Worker::proc() void ClientProcess::Worker::proc()
{ {
ClientProcess::ThreadWorker.reset(this);
char thrName[64]; char thrName[64];
snprintf(thrName, 64, "HECL Client Worker %d", m_idx); snprintf(thrName, 64, "HECL Client Worker %d", m_idx);
logvisor::RegisterThreadName(thrName); logvisor::RegisterThreadName(thrName);
@ -172,7 +178,7 @@ void ClientProcess::swapCompletedQueue(std::list<std::shared_ptr<Transaction>>&
void ClientProcess::waitUntilComplete() void ClientProcess::waitUntilComplete()
{ {
std::unique_lock<std::mutex> lk(m_mutex); std::unique_lock<std::mutex> lk(m_mutex);
while (m_pendingQueue.size() || m_inProgress) while (isBusy())
m_waitCv.wait(lk); m_waitCv.wait(lk);
} }

View File

@ -384,8 +384,7 @@ ShaderCacheManager::buildShader(const ShaderTag& tag, const std::string& source,
{ {
auto search = m_pipelineLookup.find(tag); auto search = m_pipelineLookup.find(tag);
if (search != m_pipelineLookup.cend()) if (search != m_pipelineLookup.cend())
if (auto ret = search->second.lock()) return search->second;
return ret;
std::shared_ptr<ShaderPipelines> ret = std::make_shared<ShaderPipelines>(); std::shared_ptr<ShaderPipelines> ret = std::make_shared<ShaderPipelines>();
ShaderCachedData foundData = lookupData(tag); ShaderCachedData foundData = lookupData(tag);
@ -432,8 +431,7 @@ ShaderCacheManager::buildShader(const ShaderTag& tag, const hecl::Frontend::IR&
{ {
auto search = m_pipelineLookup.find(tag); auto search = m_pipelineLookup.find(tag);
if (search != m_pipelineLookup.cend()) if (search != m_pipelineLookup.cend())
if (auto ret = search->second.lock()) return search->second;
return ret;
std::shared_ptr<ShaderPipelines> ret = std::make_shared<ShaderPipelines>(); std::shared_ptr<ShaderPipelines> ret = std::make_shared<ShaderPipelines>();
ShaderCachedData foundData = lookupData(tag); ShaderCachedData foundData = lookupData(tag);
@ -494,8 +492,7 @@ ShaderCacheManager::buildExtendedShader(const ShaderTag& tag, const std::string&
{ {
auto search = m_pipelineLookup.find(tag); auto search = m_pipelineLookup.find(tag);
if (search != m_pipelineLookup.cend()) if (search != m_pipelineLookup.cend())
if (auto ret = search->second.lock()) return search->second;
return ret;
std::shared_ptr<ShaderPipelines> ret = std::make_shared<ShaderPipelines>(); std::shared_ptr<ShaderPipelines> ret = std::make_shared<ShaderPipelines>();
ShaderCachedData foundData = lookupData(tag); ShaderCachedData foundData = lookupData(tag);
@ -545,8 +542,7 @@ ShaderCacheManager::buildExtendedShader(const ShaderTag& tag, const hecl::Fronte
{ {
auto search = m_pipelineLookup.find(tag); auto search = m_pipelineLookup.find(tag);
if (search != m_pipelineLookup.cend()) if (search != m_pipelineLookup.cend())
if (auto ret = search->second.lock()) return search->second;
return ret;
std::shared_ptr<ShaderPipelines> ret = std::make_shared<ShaderPipelines>(); std::shared_ptr<ShaderPipelines> ret = std::make_shared<ShaderPipelines>();
ShaderCachedData foundData = lookupData(tag); ShaderCachedData foundData = lookupData(tag);