Skip to content
This repository has been archived by the owner on Apr 7, 2021. It is now read-only.

Commit

Permalink
Various bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jackoalan committed Oct 22, 2017
1 parent f949aab commit 8439367
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 26 deletions.
2 changes: 1 addition & 1 deletion blender/hecl/frme.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion extern/boo
11 changes: 11 additions & 0 deletions include/hecl/ClientProcess.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "hecl.hpp"
#include "Database.hpp"
#include "hecl/Blender/BlenderConnection.hpp"
#include "boo/ThreadLocalPtr.hpp"
#include <list>
#include <thread>
#include <mutex>
Expand Down Expand Up @@ -80,6 +81,7 @@ class ClientProcess
void proc();
};
std::vector<Worker> m_workers;
static ThreadLocalPtr<ClientProcess::Worker> ThreadWorker;

public:
ClientProcess(int verbosityLevel=1);
Expand All @@ -95,6 +97,15 @@ class ClientProcess
void swapCompletedQueue(std::list<std::shared_ptr<Transaction>>& 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;
}
};

}
Expand Down
8 changes: 6 additions & 2 deletions include/hecl/Runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class ShaderCacheExtensions
bool noDepthWrite = false;
bool noColorWrite = false;
bool noAlphaWrite = false;
bool noReflection = false;
};
std::vector<ExtensionSlot> m_extensionSlots;

Expand All @@ -164,7 +165,8 @@ class ShaderCacheExtensions
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();
Expand All @@ -181,6 +183,7 @@ class ShaderCacheExtensions
slot.noDepthWrite = noDepthWrite;
slot.noColorWrite = noColorWrite;
slot.noAlphaWrite = noAlphaWrite;
slot.noReflection = noReflection;
return m_extensionSlots.size() - 1;
}
};
Expand Down Expand Up @@ -247,7 +250,7 @@ class ShaderCacheManager
};
std::vector<IndexEntry> m_entries;
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;
void bootstrapIndex();
Expand All @@ -265,6 +268,7 @@ class ShaderCacheManager
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 */
Expand Down
4 changes: 2 additions & 2 deletions lib/Backend/GLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
23 changes: 15 additions & 8 deletions lib/Backend/Metal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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"
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion lib/Backend/ProgrammableCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
{
Expand Down
6 changes: 4 additions & 2 deletions lib/Blender/BlenderConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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"))
Expand Down
8 changes: 7 additions & 1 deletion lib/ClientProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
#include <sys/wait.h>
#endif

#define HECL_MULTIPROCESSOR 1

namespace hecl
{
static logvisor::Module Log("hecl::ClientProcess");

ThreadLocalPtr<ClientProcess::Worker> ClientProcess::ThreadWorker;

static int GetCPUCount()
{
#if _WIN32
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -172,7 +178,7 @@ void ClientProcess::swapCompletedQueue(std::list<std::shared_ptr<Transaction>>&
void ClientProcess::waitUntilComplete()
{
std::unique_lock<std::mutex> lk(m_mutex);
while (m_pendingQueue.size() || m_inProgress)
while (isBusy())
m_waitCv.wait(lk);
}

Expand Down
12 changes: 4 additions & 8 deletions lib/Runtime/ShaderCacheManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ShaderPipelines> ret = std::make_shared<ShaderPipelines>();
ShaderCachedData foundData = lookupData(tag);
Expand Down Expand Up @@ -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<ShaderPipelines> ret = std::make_shared<ShaderPipelines>();
ShaderCachedData foundData = lookupData(tag);
Expand Down Expand Up @@ -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<ShaderPipelines> ret = std::make_shared<ShaderPipelines>();
ShaderCachedData foundData = lookupData(tag);
Expand Down Expand Up @@ -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<ShaderPipelines> ret = std::make_shared<ShaderPipelines>();
ShaderCachedData foundData = lookupData(tag);
Expand Down

0 comments on commit 8439367

Please sign in to comment.