Fixes for extended shaders

This commit is contained in:
Jack Andersen 2016-07-30 18:45:28 -10:00
parent 0acf4865ca
commit 9531d2bb02
7 changed files with 75 additions and 40 deletions

2
hecl/extern/boo vendored

@ -1 +1 @@
Subproject commit bec368dfe7722d348c6eb0411e349a3c731ffd58
Subproject commit 0ee594438714f38e4de982a4d51fdeaf689dd5c6

View File

@ -20,11 +20,29 @@ enum class TexGenSrc
UV
};
enum class BlendFactor
{
Zero,
One,
SrcColor,
InvSrcColor,
DstColor,
InvDstColor,
SrcAlpha,
InvSrcAlpha,
DstAlpha,
InvDstAlpha,
SrcColor1,
InvSrcColor1,
Original = 0xff
};
struct TextureInfo
{
TexGenSrc src;
int mapIdx;
int uvIdx;
int mtx;
int mtxIdx;
bool normalize;
};

View File

@ -22,7 +22,7 @@ struct GLSL : ProgrammableCommon
std::string makeFrag(const char* glslVer,
const ShaderFunction& lighting,
const ShaderFunction& post,
size_t extTexCount) const;
size_t extTexCount, const TextureInfo* extTexs) const;
private:
std::string GenerateVertInStruct(unsigned col, unsigned uv, unsigned w) const;

View File

@ -4,7 +4,6 @@
#include "Backend.hpp"
#include "hecl/Runtime.hpp"
#include <athena/DNA.hpp>
#include <boo/graphicsdev/IGraphicsDataFactory.hpp>
#include <stdint.h>
#include <stdlib.h>
#include <algorithm>
@ -20,8 +19,8 @@ struct ProgrammableCommon : IBackend
std::string m_colorExpr;
std::string m_alphaExpr;
boo::BlendFactor m_blendSrc;
boo::BlendFactor m_blendDst;
BlendFactor m_blendSrc;
BlendFactor m_blendDst;
bool m_lighting = false;
struct TexSampling

View File

@ -133,6 +133,8 @@ public:
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;
};
std::vector<ExtensionSlot> m_extensionSlots;
@ -146,7 +148,8 @@ public:
/* Strings must remain resident!! (intended to be stored static const) */
unsigned registerExtensionSlot(Function lighting, Function post,
size_t blockCount, const char** blockNames,
size_t texCount, const Backend::TextureInfo* texs)
size_t texCount, const Backend::TextureInfo* texs,
Backend::BlendFactor srcFactor, Backend::BlendFactor dstFactor)
{
m_extensionSlots.emplace_back();
ExtensionSlot& slot = m_extensionSlots.back();
@ -156,6 +159,8 @@ public:
slot.blockNames = blockNames;
slot.texCount = texCount;
slot.texs = texs;
slot.srcFactor = srcFactor;
slot.dstFactor = dstFactor;
return m_extensionSlots.size() - 1;
}
};

View File

@ -169,14 +169,13 @@ std::string GLSL::makeVert(const char* glslVer, unsigned col, unsigned uv, unsig
for (int i=0 ; i<extTexCount ; ++i)
{
const TextureInfo& extTex = extTexs[i];
if (extTex.mtx < 0)
if (extTex.mtxIdx < 0)
retval += hecl::Format(" vtf.extTcgs[%u] = %s;\n", extIdx,
EmitTexGenSource2(extTex.src, extTex.uvIdx).c_str());
else
retval += hecl::Format(" vtf.extTcgs[%u] = (texMtxs[%u].postMtx * vec4(%s((texMtxs[%u].mtx * %s).xyz), 1.0)).xy;\n",
extIdx, extTex.mtx,
extTex.normalize ? "normalize" : "", extTex.mtx,
EmitTexGenSource4(extTex.src, extTex.uvIdx).c_str());
extIdx, extTex.mtxIdx, extTex.normalize ? "normalize" : "",
extTex.mtxIdx, EmitTexGenSource4(extTex.src, extTex.uvIdx).c_str());
++extIdx;
}
@ -227,7 +226,7 @@ std::string GLSL::makeFrag(const char* glslVer,
std::string GLSL::makeFrag(const char* glslVer,
const ShaderFunction& lighting,
const ShaderFunction& post,
size_t extTexCount) const
size_t extTexCount, const TextureInfo* extTexs) const
{
std::string lightingSrc;
if (lighting.m_source)
@ -245,6 +244,13 @@ std::string GLSL::makeFrag(const char* glslVer,
for (unsigned i=0 ; i<m_texMapEnd ; ++i)
texMapDecl += hecl::Format("TBINDING%u uniform sampler2D tex%u;\n", i, i);
for (int i=0 ; i<extTexCount ; ++i)
{
const TextureInfo& extTex = extTexs[i];
texMapDecl += hecl::Format("TBINDING%u uniform sampler2D tex%u;\n",
extTex.mapIdx, extTex.mapIdx);
}
std::string retval = std::string(glslVer) + "\n" BOO_GLSL_BINDING_HEAD +
GenerateVertToFragStruct(extTexCount) +
"\nlayout(location=0) out vec4 colorOut;\n" +
@ -324,9 +330,10 @@ struct GLSLBackendFactory : IShaderBackendFactory
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
m_backend.m_texMapEnd, STD_TEXNAMES,
2, STD_BLOCKNAMES,
m_backend.m_blendSrc, m_backend.m_blendDst, tag.getPrimType(),
tag.getDepthTest(), tag.getDepthWrite(),
tag.getBackfaceCulling());
boo::BlendFactor(m_backend.m_blendSrc),
boo::BlendFactor(m_backend.m_blendDst),
tag.getPrimType(), tag.getDepthTest(),
tag.getDepthWrite(), tag.getBackfaceCulling());
if (!objOut)
Log.report(logvisor::Fatal, "unable to build shader");
@ -397,16 +404,17 @@ struct GLSLBackendFactory : IShaderBackendFactory
tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(),
tag.getSkinSlotCount(), tag.getTexMtxCount(), slot.texCount,
slot.texs),
m_backend.makeFrag("#version 330", slot.lighting, slot.post, slot.texCount));
m_backend.makeFrag("#version 330", slot.lighting, slot.post, slot.texCount, slot.texs));
cachedSz += sources.back().first.size() + 1;
cachedSz += sources.back().second.size() + 1;
boo::IShaderPipeline* ret =
static_cast<boo::GLDataFactory::Context&>(ctx).
newShaderPipeline(sources.back().first.c_str(), sources.back().second.c_str(),
m_backend.m_texMapEnd, STD_TEXNAMES, bc, bn,
m_backend.m_blendSrc, m_backend.m_blendDst, tag.getPrimType(),
tag.getDepthTest(), tag.getDepthWrite(),
tag.getBackfaceCulling());
8, STD_TEXNAMES, bc, bn,
boo::BlendFactor((slot.srcFactor == hecl::Backend::BlendFactor::Original) ? m_backend.m_blendSrc : slot.srcFactor),
boo::BlendFactor((slot.dstFactor == hecl::Backend::BlendFactor::Original) ? m_backend.m_blendDst : slot.dstFactor),
tag.getPrimType(), tag.getDepthTest(),
tag.getDepthWrite(), tag.getBackfaceCulling());
if (!ret)
Log.report(logvisor::Fatal, "unable to build shader");
returnFunc(ret);
@ -434,8 +442,8 @@ struct GLSLBackendFactory : IShaderBackendFactory
const ShaderTag& tag = data.m_tag;
athena::io::MemoryReader r(data.m_data.get(), data.m_sz);
atUint8 texMapEnd = r.readUByte();
boo::BlendFactor blendSrc = boo::BlendFactor(r.readUByte());
boo::BlendFactor blendDst = boo::BlendFactor(r.readUByte());
hecl::Backend::BlendFactor blendSrc = hecl::Backend::BlendFactor(r.readUByte());
hecl::Backend::BlendFactor blendDst = hecl::Backend::BlendFactor(r.readUByte());
if (texMapEnd > 8)
Log.report(logvisor::Fatal, "maximum of 8 texture maps supported");
@ -455,9 +463,10 @@ struct GLSLBackendFactory : IShaderBackendFactory
boo::IShaderPipeline* ret =
static_cast<boo::GLDataFactory::Context&>(ctx).
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
texMapEnd, STD_TEXNAMES, bc, bn,
blendSrc, blendDst, tag.getPrimType(),
tag.getDepthTest(), tag.getDepthWrite(),
8, STD_TEXNAMES, bc, bn,
boo::BlendFactor((slot.srcFactor == hecl::Backend::BlendFactor::Original) ? blendSrc : slot.srcFactor),
boo::BlendFactor((slot.dstFactor == hecl::Backend::BlendFactor::Original) ? blendDst : slot.dstFactor),
tag.getPrimType(), tag.getDepthTest(), tag.getDepthWrite(),
tag.getBackfaceCulling());
if (!ret)
Log.report(logvisor::Fatal, "unable to build shader");
@ -500,8 +509,8 @@ struct SPIRVBackendFactory : IShaderBackendFactory
static_cast<boo::VulkanDataFactory::Context&>(ctx).
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
vertBlob, fragBlob, pipelineBlob, tag.newVertexFormat(ctx),
m_backend.m_blendSrc, m_backend.m_blendDst, tag.getPrimType(),
tag.getDepthTest(), tag.getDepthWrite(),
boo::BlendFactor(m_backend.m_blendSrc), boo::BlendFactor(m_backend.m_blendDst),
tag.getPrimType(), tag.getDepthTest(), tag.getDepthWrite(),
tag.getBackfaceCulling());
if (!objOut)
Log.report(logvisor::Fatal, "unable to build shader");
@ -609,7 +618,7 @@ struct SPIRVBackendFactory : IShaderBackendFactory
tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(),
tag.getSkinSlotCount(), tag.getTexMtxCount(), slot.texCount, slot.texs);
std::string fragSource = m_backend.makeFrag("#version 330", slot.lighting, slot.post, slot.texCount);
std::string fragSource = m_backend.makeFrag("#version 330", slot.lighting, slot.post, slot.texCount, slot.texs);
pipeBlobs.emplace_back();
Blobs& pipeBlob = pipeBlobs.back();
boo::IShaderPipeline* ret =
@ -617,8 +626,11 @@ struct SPIRVBackendFactory : IShaderBackendFactory
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
pipeBlob.vert, pipeBlob.frag, pipeBlob.pipeline,
tag.newVertexFormat(ctx),
m_backend.m_blendSrc, m_backend.m_blendDst, tag.getPrimType(),
tag.getDepthTest(), tag.getDepthWrite(),
boo::BlendFactor((slot.srcFactor == hecl::Backend::BlendFactor::Original) ?
m_backend.m_blendSrc : slot.srcFactor),
boo::BlendFactor((slot.dstFactor == hecl::Backend::BlendFactor::Original) ?
m_backend.m_blendDst : slot.dstFactor),
tag.getPrimType(), tag.getDepthTest(), tag.getDepthWrite(),
tag.getBackfaceCulling());
if (!ret)
Log.report(logvisor::Fatal, "unable to build shader");
@ -676,8 +688,8 @@ struct SPIRVBackendFactory : IShaderBackendFactory
const ShaderTag& tag = data.m_tag;
athena::io::MemoryReader r(data.m_data.get(), data.m_sz);
size_t texCount = size_t(r.readByte());
boo::BlendFactor blendSrc = boo::BlendFactor(r.readUByte());
boo::BlendFactor blendDst = boo::BlendFactor(r.readUByte());
hecl::Backend::BlendFactor blendSrc = hecl::Backend::BlendFactor(r.readUByte());
hecl::Backend::BlendFactor blendDst = hecl::Backend::BlendFactor(r.readUByte());
for (const ShaderCacheExtensions::ExtensionSlot& slot : extensionSlots)
{
@ -701,8 +713,9 @@ struct SPIRVBackendFactory : IShaderBackendFactory
newShaderPipeline(nullptr, nullptr,
vertBlob, fragBlob, pipelineBlob,
tag.newVertexFormat(ctx),
blendSrc, blendDst, tag.getPrimType(),
tag.getDepthTest(), tag.getDepthWrite(),
boo::BlendFactor((slot.srcFactor == hecl::Backend::BlendFactor::Original) ? blendSrc : slot.srcFactor),
boo::BlendFactor((slot.dstFactor == hecl::Backend::BlendFactor::Original) ? blendDst : slot.dstFactor),
tag.getPrimType(), tag.getDepthTest(), tag.getDepthWrite(),
tag.getBackfaceCulling());
if (!ret)
Log.report(logvisor::Fatal, "unable to build shader");

View File

@ -267,19 +267,19 @@ void ProgrammableCommon::reset(const IR& ir, Diagnostics& diag, const char* back
bool doAlpha = false;
if (!rootCall.m_call.m_name.compare("HECLOpaque"))
{
m_blendSrc = boo::BlendFactor::One;
m_blendDst = boo::BlendFactor::Zero;
m_blendSrc = BlendFactor::One;
m_blendDst = BlendFactor::Zero;
}
else if (!rootCall.m_call.m_name.compare("HECLAlpha"))
{
m_blendSrc = boo::BlendFactor::SrcAlpha;
m_blendDst = boo::BlendFactor::InvSrcAlpha;
m_blendSrc = BlendFactor::SrcAlpha;
m_blendDst = BlendFactor::InvSrcAlpha;
doAlpha = true;
}
else if (!rootCall.m_call.m_name.compare("HECLAdditive"))
{
m_blendSrc = boo::BlendFactor::SrcAlpha;
m_blendDst = boo::BlendFactor::One;
m_blendSrc = BlendFactor::SrcAlpha;
m_blendDst = BlendFactor::One;
doAlpha = true;
}
else