Refactor for boo upgrades

This commit is contained in:
Jack Andersen 2017-03-13 21:03:22 -10:00
parent 21194f43db
commit 626056f3b9
6 changed files with 190 additions and 30 deletions

2
hecl/extern/boo vendored

@ -1 +1 @@
Subproject commit 73891af56a633cf2b4e047b6422f34c80230eb29
Subproject commit 05c26a535b23b1b787523e896853c3641cb888c8

View File

@ -13,14 +13,14 @@ using Diagnostics = Frontend::Diagnostics;
using SourceLocation = Frontend::SourceLocation;
using ArithmeticOp = IR::Instruction::ArithmeticOpType;
enum class TexGenSrc
enum class TexGenSrc : uint8_t
{
Position,
Normal,
UV
};
enum class BlendFactor
enum class BlendFactor : uint8_t
{
Zero,
One,
@ -37,6 +37,15 @@ enum class BlendFactor
Original = 0xff
};
enum class ZTest : uint8_t
{
None,
LEqual,
Greater,
Equal,
Original = 0xff
};
struct TextureInfo
{
TexGenSrc src;

View File

@ -135,6 +135,11 @@ public:
const Backend::TextureInfo* texs = nullptr;
Backend::BlendFactor srcFactor = Backend::BlendFactor::Original;
Backend::BlendFactor dstFactor = Backend::BlendFactor::Original;
Backend::ZTest depthTest = Backend::ZTest::Original;
bool frontfaceCull = false;
bool noDepthWrite = false;
bool noColorWrite = false;
bool noAlphaWrite = false;
};
std::vector<ExtensionSlot> m_extensionSlots;
@ -149,7 +154,12 @@ public:
unsigned registerExtensionSlot(Function lighting, Function post,
size_t blockCount, const char** blockNames,
size_t texCount, const Backend::TextureInfo* texs,
Backend::BlendFactor srcFactor, Backend::BlendFactor dstFactor)
Backend::BlendFactor srcFactor, Backend::BlendFactor dstFactor,
Backend::ZTest depthTest = Backend::ZTest::Original,
bool frontfaceCull = false,
bool noDepthWrite = false,
bool noColorWrite = false,
bool noAlphaWrite = false)
{
m_extensionSlots.emplace_back();
ExtensionSlot& slot = m_extensionSlots.back();
@ -161,6 +171,11 @@ public:
slot.texs = texs;
slot.srcFactor = srcFactor;
slot.dstFactor = dstFactor;
slot.depthTest = depthTest;
slot.frontfaceCull = frontfaceCull;
slot.noDepthWrite = noDepthWrite;
slot.noColorWrite = noColorWrite;
slot.noAlphaWrite = noAlphaWrite;
return m_extensionSlots.size() - 1;
}
};
@ -286,7 +301,8 @@ struct HMDLData
const boo::PipelineStage* ubufStages,
size_t texCount, boo::ITexture** texs)
{return ctx.newShaderDataBinding(shader, m_vtxFmt, m_vbo, nullptr, m_ibo,
ubufCount, ubufs, ubufStages, nullptr, nullptr, texCount, texs);}
ubufCount, ubufs, ubufStages, nullptr, nullptr,
texCount, texs, nullptr, nullptr);}
};
}

View File

@ -361,8 +361,8 @@ struct GLSLBackendFactory : IShaderBackendFactory
2, STD_BLOCKNAMES,
boo::BlendFactor(m_backend.m_blendSrc),
boo::BlendFactor(m_backend.m_blendDst),
tag.getPrimType(), tag.getDepthTest(),
tag.getDepthWrite(),
tag.getPrimType(), tag.getDepthTest() ? boo::ZTest::LEqual : boo::ZTest::None,
tag.getDepthWrite(), true, false,
tag.getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None);
if (!objOut)
Log.report(logvisor::Fatal, "unable to build shader");
@ -401,7 +401,8 @@ struct GLSLBackendFactory : IShaderBackendFactory
texMapEnd, STD_TEXNAMES,
2, STD_BLOCKNAMES,
blendSrc, blendDst, tag.getPrimType(),
tag.getDepthTest(), tag.getDepthWrite(),
tag.getDepthTest() ? boo::ZTest::LEqual : boo::ZTest::None,
tag.getDepthWrite(), true, false,
tag.getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None);
if (!ret)
Log.report(logvisor::Fatal, "unable to build shader");
@ -442,15 +443,37 @@ struct GLSLBackendFactory : IShaderBackendFactory
slot.lighting, slot.post, slot.texCount, slot.texs));
cachedSz += sources.back().first.size() + 1;
cachedSz += sources.back().second.size() + 1;
boo::ZTest zTest;
switch (slot.depthTest)
{
case hecl::Backend::ZTest::Original:
default:
zTest = tag.getDepthTest() ? boo::ZTest::LEqual : boo::ZTest::None;
break;
case hecl::Backend::ZTest::None:
zTest = boo::ZTest::None;
break;
case hecl::Backend::ZTest::LEqual:
zTest = boo::ZTest::LEqual;
break;
case hecl::Backend::ZTest::Greater:
zTest = boo::ZTest::Greater;
break;
case hecl::Backend::ZTest::Equal:
zTest = boo::ZTest::Equal;
break;
}
boo::IShaderPipeline* ret =
static_cast<boo::GLDataFactory::Context&>(ctx).
newShaderPipeline(sources.back().first.c_str(), sources.back().second.c_str(),
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() ? boo::CullMode::Backface : boo::CullMode::None);
tag.getPrimType(), zTest, slot.noDepthWrite ? false : tag.getDepthWrite(), !slot.noColorWrite, !slot.noAlphaWrite,
slot.frontfaceCull ? boo::CullMode::Frontface :
(tag.getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None));
if (!ret)
Log.report(logvisor::Fatal, "unable to build shader");
returnFunc(ret);
@ -503,14 +526,36 @@ struct GLSLBackendFactory : IShaderBackendFactory
if (r.hasError())
return false;
boo::ZTest zTest;
switch (slot.depthTest)
{
case hecl::Backend::ZTest::Original:
default:
zTest = tag.getDepthTest() ? boo::ZTest::LEqual : boo::ZTest::None;
break;
case hecl::Backend::ZTest::None:
zTest = boo::ZTest::None;
break;
case hecl::Backend::ZTest::LEqual:
zTest = boo::ZTest::LEqual;
break;
case hecl::Backend::ZTest::Greater:
zTest = boo::ZTest::Greater;
break;
case hecl::Backend::ZTest::Equal:
zTest = boo::ZTest::Equal;
break;
}
boo::IShaderPipeline* ret =
static_cast<boo::GLDataFactory::Context&>(ctx).
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
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() ? boo::CullMode::Backface : boo::CullMode::None);
tag.getPrimType(), zTest, slot.noDepthWrite ? false : tag.getDepthWrite(), !slot.noColorWrite, !slot.noAlphaWrite,
slot.frontfaceCull ? boo::CullMode::Frontface :
(tag.getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None));
if (!ret)
Log.report(logvisor::Fatal, "unable to build shader");
returnFunc(ret);
@ -681,7 +726,8 @@ struct SPIRVBackendFactory : IShaderBackendFactory
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.getPrimType(), tag.getDepthTest(), slot.noDepthWrite ? false : tag.getDepthWrite(),
!slot.noColorWrite, !slot.noAlphaWrite,
tag.getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None);
if (!ret)
Log.report(logvisor::Fatal, "unable to build shader");
@ -772,7 +818,8 @@ struct SPIRVBackendFactory : IShaderBackendFactory
tag.newVertexFormat(ctx),
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.getPrimType(), tag.getDepthTest(), slot.noDepthWrite ? false : tag.getDepthWrite(),
!slot.noColorWrite, !slot.noAlphaWrite,
tag.getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None);
if (!ret)
Log.report(logvisor::Fatal, "unable to build shader");

View File

@ -451,6 +451,28 @@ struct HLSLBackendFactory : IShaderBackendFactory
slot.lighting, slot.post, slot.texCount, slot.texs);
pipeBlobs.emplace_back();
Blobs& thisPipeBlobs = pipeBlobs.back();
boo::ZTest zTest;
switch (slot.depthTest)
{
case hecl::Backend::ZTest::Original:
default:
zTest = tag.getDepthTest() ? boo::ZTest::LEqual : boo::ZTest::None;
break;
case hecl::Backend::ZTest::None:
zTest = boo::ZTest::None;
break;
case hecl::Backend::ZTest::LEqual:
zTest = boo::ZTest::LEqual;
break;
case hecl::Backend::ZTest::Greater:
zTest = boo::ZTest::Greater;
break;
case hecl::Backend::ZTest::Equal:
zTest = boo::ZTest::Equal;
break;
}
boo::IShaderPipeline* ret =
static_cast<boo::ID3DDataFactory::Context&>(ctx).
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
@ -458,9 +480,9 @@ struct HLSLBackendFactory : IShaderBackendFactory
tag.newVertexFormat(ctx),
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() ? boo::CullMode::Backface : boo::CullMode::None);
tag.getPrimType(), zTest, slot.noDepthWrite ? false : tag.getDepthWrite(),
slot.frontfaceCull ? boo::CullMode::Frontface :
(tag.getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None));
if (!ret)
Log.report(logvisor::Fatal, "unable to build shader");
if (thisPipeBlobs.vert)
@ -549,6 +571,27 @@ struct HLSLBackendFactory : IShaderBackendFactory
if (r.hasError())
return false;
boo::ZTest zTest;
switch (slot.depthTest)
{
case hecl::Backend::ZTest::Original:
default:
zTest = tag.getDepthTest() ? boo::ZTest::LEqual : boo::ZTest::None;
break;
case hecl::Backend::ZTest::None:
zTest = boo::ZTest::None;
break;
case hecl::Backend::ZTest::LEqual:
zTest = boo::ZTest::LEqual;
break;
case hecl::Backend::ZTest::Greater:
zTest = boo::ZTest::Greater;
break;
case hecl::Backend::ZTest::Equal:
zTest = boo::ZTest::Equal;
break;
}
boo::IShaderPipeline* ret =
static_cast<boo::ID3DDataFactory::Context&>(ctx).
newShaderPipeline(nullptr, nullptr,
@ -556,9 +599,9 @@ struct HLSLBackendFactory : IShaderBackendFactory
tag.newVertexFormat(ctx),
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() ? boo::CullMode::Backface : boo::CullMode::None);
tag.getPrimType(), zTest, slot.noDepthWrite ? false : tag.getDepthWrite(),
slot.frontfaceCull ? boo::CullMode::Frontface :
(tag.getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None));
if (!ret)
Log.report(logvisor::Fatal, "unable to build shader");
returnFunc(ret);

View File

@ -66,7 +66,7 @@ std::string Metal::GenerateVertInStruct(unsigned col, unsigned uv, unsigned w) c
if (w)
{
for (unsigned i=0 ; i<w ; ++i, ++idx)
retval += hecl::Format(" float4 weightIn%u [[ attribute(%u) ]];\n", i, idx);
retval += hecl::Format(" float4 weightIn%u [[ attribute(%u) ]];\n", i, idx);
}
return retval + "};\n";
@ -407,7 +407,7 @@ struct MetalBackendFactory : IShaderBackendFactory
boo::BlendFactor(m_backend.m_blendSrc),
boo::BlendFactor(m_backend.m_blendDst),
tag.getPrimType(),
tag.getDepthTest(), tag.getDepthWrite(),
tag.getDepthTest() ? boo::ZTest::LEqual : boo::ZTest::None, tag.getDepthWrite(), true, true,
tag.getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None);
if (!objOut)
Log.report(logvisor::Fatal, "unable to build shader");
@ -444,7 +444,7 @@ struct MetalBackendFactory : IShaderBackendFactory
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
tag.newVertexFormat(ctx), m_rtHint,
blendSrc, blendDst, tag.getPrimType(),
tag.getDepthTest(), tag.getDepthWrite(),
tag.getDepthTest() ? boo::ZTest::LEqual : boo::ZTest::None, tag.getDepthWrite(), true, true,
tag.getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None);
if (!ret)
Log.report(logvisor::Fatal, "unable to build shader");
@ -476,15 +476,38 @@ struct MetalBackendFactory : IShaderBackendFactory
slot.lighting, slot.post, slot.texCount, slot.texs));
cachedSz += sources.back().first.size() + 1;
cachedSz += sources.back().second.size() + 1;
boo::ZTest zTest;
switch (slot.depthTest)
{
case hecl::Backend::ZTest::Original:
default:
zTest = tag.getDepthTest() ? boo::ZTest::LEqual : boo::ZTest::None;
break;
case hecl::Backend::ZTest::None:
zTest = boo::ZTest::None;
break;
case hecl::Backend::ZTest::LEqual:
zTest = boo::ZTest::LEqual;
break;
case hecl::Backend::ZTest::Greater:
zTest = boo::ZTest::Greater;
break;
case hecl::Backend::ZTest::Equal:
zTest = boo::ZTest::Equal;
break;
}
boo::IShaderPipeline* ret =
static_cast<boo::MetalDataFactory::Context&>(ctx).
newShaderPipeline(sources.back().first.c_str(), sources.back().second.c_str(),
tag.newVertexFormat(ctx), m_rtHint,
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() ? boo::CullMode::Backface : boo::CullMode::None);
tag.getPrimType(), zTest, slot.noDepthWrite ? false : tag.getDepthWrite(),
!slot.noColorWrite, !slot.noAlphaWrite,
slot.frontfaceCull ? boo::CullMode::Frontface :
(tag.getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None));
if (!ret)
Log.report(logvisor::Fatal, "unable to build shader");
returnFunc(ret);
@ -528,15 +551,37 @@ struct MetalBackendFactory : IShaderBackendFactory
if (r.hasError())
return false;
boo::ZTest zTest;
switch (slot.depthTest)
{
case hecl::Backend::ZTest::Original:
default:
zTest = tag.getDepthTest() ? boo::ZTest::LEqual : boo::ZTest::None;
break;
case hecl::Backend::ZTest::None:
zTest = boo::ZTest::None;
break;
case hecl::Backend::ZTest::LEqual:
zTest = boo::ZTest::LEqual;
break;
case hecl::Backend::ZTest::Greater:
zTest = boo::ZTest::Greater;
break;
case hecl::Backend::ZTest::Equal:
zTest = boo::ZTest::Equal;
break;
}
boo::IShaderPipeline* ret =
static_cast<boo::MetalDataFactory::Context&>(ctx).
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
tag.newVertexFormat(ctx), m_rtHint,
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() ? boo::CullMode::Backface : boo::CullMode::None);
tag.getPrimType(), zTest, slot.noDepthWrite ? false : tag.getDepthWrite(),
!slot.noColorWrite, !slot.noAlphaWrite,
slot.frontfaceCull ? boo::CullMode::Frontface :
(tag.getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None));
if (!ret)
Log.report(logvisor::Fatal, "unable to build shader");
returnFunc(ret);