mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-08 15:04:56 +00:00
boo lambda-factory API refactor
This commit is contained in:
@@ -8,7 +8,7 @@ namespace Runtime
|
||||
{
|
||||
static logvisor::Module Log("HMDL");
|
||||
|
||||
HMDLData::HMDLData(boo::IGraphicsDataFactory* factory,
|
||||
HMDLData::HMDLData(boo::IGraphicsDataFactory::Context& ctx,
|
||||
const void* metaData, const void* vbo, const void* ibo)
|
||||
{
|
||||
HMDLMeta meta;
|
||||
@@ -19,15 +19,15 @@ HMDLData::HMDLData(boo::IGraphicsDataFactory* factory,
|
||||
if (meta.magic != 'TACO')
|
||||
Log.report(logvisor::Fatal, "invalid HMDL magic");
|
||||
|
||||
m_vbo = factory->newStaticBuffer(boo::BufferUse::Vertex, vbo, meta.vertStride, meta.vertCount);
|
||||
m_ibo = factory->newStaticBuffer(boo::BufferUse::Index, ibo, 4, meta.indexCount);
|
||||
m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, vbo, meta.vertStride, meta.vertCount);
|
||||
m_ibo = ctx.newStaticBuffer(boo::BufferUse::Index, ibo, 4, meta.indexCount);
|
||||
|
||||
if (factory->bindingNeedsVertexFormat())
|
||||
m_vtxFmt = NewVertexFormat(factory, meta, m_vbo, m_ibo);
|
||||
if (ctx.bindingNeedsVertexFormat())
|
||||
m_vtxFmt = NewVertexFormat(ctx, meta, m_vbo, m_ibo);
|
||||
}
|
||||
|
||||
/* For binding constructors that require vertex format up front (GLSL) */
|
||||
boo::IVertexFormat* HMDLData::NewVertexFormat(boo::IGraphicsDataFactory* factory, const HMDLMeta& meta,
|
||||
boo::IVertexFormat* HMDLData::NewVertexFormat(boo::IGraphicsDataFactory::Context& ctx, const HMDLMeta& meta,
|
||||
boo::IGraphicsBuffer* vbo, boo::IGraphicsBuffer* ibo)
|
||||
{
|
||||
size_t elemCount = 2 + meta.colorCount + meta.uvCount + meta.weightCount;
|
||||
@@ -60,11 +60,11 @@ boo::IVertexFormat* HMDLData::NewVertexFormat(boo::IGraphicsDataFactory* factory
|
||||
vdescs[e].semanticIdx = i;
|
||||
}
|
||||
|
||||
return factory->newVertexFormat(elemCount, vdescs.get());
|
||||
return ctx.newVertexFormat(elemCount, vdescs.get());
|
||||
}
|
||||
|
||||
/* For shader constructors that require vertex format up-front (HLSL/Metal/Vulkan) */
|
||||
boo::IVertexFormat* ShaderTag::newVertexFormat(boo::IGraphicsDataFactory *factory) const
|
||||
boo::IVertexFormat* ShaderTag::newVertexFormat(boo::IGraphicsDataFactory::Context& ctx) const
|
||||
{
|
||||
size_t elemCount = 2 + m_colorCount + m_uvCount + m_weightCount;
|
||||
std::unique_ptr<boo::VertexElementDescriptor[]> vdescs(new boo::VertexElementDescriptor[elemCount]);
|
||||
@@ -96,7 +96,7 @@ boo::IVertexFormat* ShaderTag::newVertexFormat(boo::IGraphicsDataFactory *factor
|
||||
vdescs[e].semanticIdx = i;
|
||||
}
|
||||
|
||||
return factory->newVertexFormat(elemCount, vdescs.get());
|
||||
return ctx.newVertexFormat(elemCount, vdescs.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,15 +12,15 @@ namespace hecl
|
||||
{
|
||||
namespace Runtime
|
||||
{
|
||||
IShaderBackendFactory* _NewGLSLBackendFactory(boo::IGraphicsDataFactory* gfxFactory);
|
||||
IShaderBackendFactory* _NewGLSLBackendFactory();
|
||||
#if _WIN32
|
||||
IShaderBackendFactory* _NewHLSLBackendFactory(boo::IGraphicsDataFactory* gfxFactory);
|
||||
IShaderBackendFactory* _NewHLSLBackendFactory();
|
||||
#endif
|
||||
#if BOO_HAS_METAL
|
||||
IShaderBackendFactory* _NewMetalBackendFactory(boo::IGraphicsDataFactory* gfxFactory);
|
||||
IShaderBackendFactory* _NewMetalBackendFactory();
|
||||
#endif
|
||||
#if BOO_HAS_VULKAN
|
||||
IShaderBackendFactory* _NewSPIRVBackendFactory(boo::IGraphicsDataFactory* gfxFactory);
|
||||
IShaderBackendFactory* _NewSPIRVBackendFactory();
|
||||
#endif
|
||||
|
||||
static logvisor::Module Log("ShaderCacheManager");
|
||||
@@ -116,22 +116,22 @@ ShaderCacheManager::ShaderCacheManager(const FileStoreManager& storeMgr,
|
||||
switch (plat)
|
||||
{
|
||||
case boo::IGraphicsDataFactory::Platform::OGL:
|
||||
m_factory.reset(_NewGLSLBackendFactory(gfxFactory));
|
||||
m_factory.reset(_NewGLSLBackendFactory());
|
||||
break;
|
||||
#if _WIN32
|
||||
case boo::IGraphicsDataFactory::Platform::D3D11:
|
||||
case boo::IGraphicsDataFactory::Platform::D3D12:
|
||||
m_factory.reset(_NewHLSLBackendFactory(gfxFactory));
|
||||
m_factory.reset(_NewHLSLBackendFactory());
|
||||
break;
|
||||
#endif
|
||||
#if BOO_HAS_METAL
|
||||
case boo::IGraphicsDataFactory::Platform::Metal:
|
||||
m_factory.reset(_NewMetalBackendFactory(gfxFactory));
|
||||
m_factory.reset(_NewMetalBackendFactory());
|
||||
break;
|
||||
#endif
|
||||
#if BOO_HAS_VULKAN
|
||||
case boo::IGraphicsDataFactory::Platform::Vulkan:
|
||||
m_factory.reset(_NewSPIRVBackendFactory(gfxFactory));
|
||||
m_factory.reset(_NewSPIRVBackendFactory());
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
@@ -352,41 +352,45 @@ bool ShaderCacheManager::addData(const ShaderCachedData& data)
|
||||
}
|
||||
|
||||
boo::IShaderPipeline*
|
||||
ShaderCacheManager::buildFromCache(const ShaderCachedData& foundData)
|
||||
ShaderCacheManager::buildFromCache(const ShaderCachedData& foundData,
|
||||
boo::IGraphicsDataFactory::Context& ctx)
|
||||
{
|
||||
return m_factory->buildShaderFromCache(foundData);
|
||||
return m_factory->buildShaderFromCache(foundData, ctx);
|
||||
}
|
||||
|
||||
boo::IShaderPipeline*
|
||||
ShaderCacheManager::buildShader(const ShaderTag& tag, const std::string& source,
|
||||
const std::string& diagName)
|
||||
const std::string& diagName,
|
||||
boo::IGraphicsDataFactory::Context& ctx)
|
||||
{
|
||||
ShaderCachedData foundData = lookupData(tag);
|
||||
if (foundData)
|
||||
return buildFromCache(foundData);
|
||||
return buildFromCache(foundData, ctx);
|
||||
hecl::Frontend::IR ir = FE.compileSource(source, diagName);
|
||||
return buildShader(tag, ir, diagName);
|
||||
return buildShader(tag, ir, diagName, ctx);
|
||||
}
|
||||
|
||||
boo::IShaderPipeline*
|
||||
ShaderCacheManager::buildShader(const ShaderTag& tag, const hecl::Frontend::IR& ir,
|
||||
const std::string& diagName)
|
||||
const std::string& diagName,
|
||||
boo::IGraphicsDataFactory::Context& ctx)
|
||||
{
|
||||
ShaderCachedData foundData = lookupData(tag);
|
||||
if (foundData)
|
||||
return buildFromCache(foundData);
|
||||
return buildFromCache(foundData, ctx);
|
||||
FE.getDiagnostics().reset(diagName);
|
||||
boo::IShaderPipeline* ret;
|
||||
addData(m_factory->buildShaderFromIR(tag, ir, FE.getDiagnostics(), ret));
|
||||
addData(m_factory->buildShaderFromIR(tag, ir, FE.getDiagnostics(), ctx, ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<boo::IShaderPipeline*>
|
||||
ShaderCacheManager::buildExtendedFromCache(const ShaderCachedData& foundData)
|
||||
ShaderCacheManager::buildExtendedFromCache(const ShaderCachedData& foundData,
|
||||
boo::IGraphicsDataFactory::Context& ctx)
|
||||
{
|
||||
std::vector<boo::IShaderPipeline*> shaders;
|
||||
shaders.reserve(m_extensions.m_extensionSlots.size());
|
||||
m_factory->buildExtendedShaderFromCache(foundData, m_extensions.m_extensionSlots,
|
||||
m_factory->buildExtendedShaderFromCache(foundData, m_extensions.m_extensionSlots, ctx,
|
||||
[&](boo::IShaderPipeline* shader){shaders.push_back(shader);});
|
||||
if (shaders.size() != m_extensions.m_extensionSlots.size())
|
||||
Log.report(logvisor::Fatal, "buildShaderFromCache returned %" PRISize " times, expected %" PRISize,
|
||||
@@ -396,27 +400,29 @@ ShaderCacheManager::buildExtendedFromCache(const ShaderCachedData& foundData)
|
||||
|
||||
std::vector<boo::IShaderPipeline*>
|
||||
ShaderCacheManager::buildExtendedShader(const ShaderTag& tag, const std::string& source,
|
||||
const std::string& diagName)
|
||||
const std::string& diagName,
|
||||
boo::IGraphicsDataFactory::Context& ctx)
|
||||
{
|
||||
ShaderCachedData foundData = lookupData(tag);
|
||||
if (foundData)
|
||||
return buildExtendedFromCache(foundData);
|
||||
return buildExtendedFromCache(foundData, ctx);
|
||||
hecl::Frontend::IR ir = FE.compileSource(source, diagName);
|
||||
return buildExtendedShader(tag, ir, diagName);
|
||||
return buildExtendedShader(tag, ir, diagName, ctx);
|
||||
}
|
||||
|
||||
std::vector<boo::IShaderPipeline*>
|
||||
ShaderCacheManager::buildExtendedShader(const ShaderTag& tag, const hecl::Frontend::IR& ir,
|
||||
const std::string& diagName)
|
||||
const std::string& diagName,
|
||||
boo::IGraphicsDataFactory::Context& ctx)
|
||||
{
|
||||
ShaderCachedData foundData = lookupData(tag);
|
||||
if (foundData)
|
||||
return buildExtendedFromCache(foundData);
|
||||
return buildExtendedFromCache(foundData, ctx);
|
||||
std::vector<boo::IShaderPipeline*> shaders;
|
||||
shaders.reserve(m_extensions.m_extensionSlots.size());
|
||||
FE.getDiagnostics().reset(diagName);
|
||||
ShaderCachedData data =
|
||||
m_factory->buildExtendedShaderFromIR(tag, ir, FE.getDiagnostics(), m_extensions.m_extensionSlots,
|
||||
m_factory->buildExtendedShaderFromIR(tag, ir, FE.getDiagnostics(), m_extensions.m_extensionSlots, ctx,
|
||||
[&](boo::IShaderPipeline* shader){shaders.push_back(shader);});
|
||||
if (shaders.size() != m_extensions.m_extensionSlots.size())
|
||||
Log.report(logvisor::Fatal, "buildShaderFromIR returned %" PRISize " times, expected %" PRISize,
|
||||
|
||||
Reference in New Issue
Block a user