diff --git a/hecl/extern/boo b/hecl/extern/boo index 6cbd08620..bf6b4e37e 160000 --- a/hecl/extern/boo +++ b/hecl/extern/boo @@ -1 +1 @@ -Subproject commit 6cbd086204bbe0bce4ad21c179c3e4cf8ea717b8 +Subproject commit bf6b4e37e81b72532afe2b4a56201b3bea7d4c63 diff --git a/hecl/include/hecl/Runtime.hpp b/hecl/include/hecl/Runtime.hpp index e93379930..40fb4c2eb 100644 --- a/hecl/include/hecl/Runtime.hpp +++ b/hecl/include/hecl/Runtime.hpp @@ -83,7 +83,7 @@ public: uint64_t getMetaData() const {return m_meta;} /* For shader constructors that require vertex format up-front (HLSL) */ - boo::IVertexFormat* newVertexFormat(boo::IGraphicsDataFactory* factory) const; + boo::IVertexFormat* newVertexFormat(boo::IGraphicsDataFactory::Context& ctx) const; }; /** @@ -159,15 +159,19 @@ protected: virtual ShaderCachedData buildShaderFromIR(const ShaderTag& tag, const hecl::Frontend::IR& ir, hecl::Frontend::Diagnostics& diag, + boo::IGraphicsDataFactory::Context& ctx, boo::IShaderPipeline*& objOut)=0; - virtual boo::IShaderPipeline* buildShaderFromCache(const ShaderCachedData& data)=0; + virtual boo::IShaderPipeline* buildShaderFromCache(const ShaderCachedData& data, + boo::IGraphicsDataFactory::Context& ctx)=0; virtual ShaderCachedData buildExtendedShaderFromIR(const ShaderTag& tag, const hecl::Frontend::IR& ir, hecl::Frontend::Diagnostics& diag, const std::vector& extensionSlots, + boo::IGraphicsDataFactory::Context& ctx, FReturnExtensionShader returnFunc)=0; virtual void buildExtendedShaderFromCache(const ShaderCachedData& data, const std::vector& extensionSlots, + boo::IGraphicsDataFactory::Context& ctx, FReturnExtensionShader returnFunc)=0; public: virtual ~IShaderBackendFactory() {} @@ -200,8 +204,10 @@ class ShaderCacheManager void bootstrapIndex(); ShaderCachedData lookupData(const Hash& hash); bool addData(const ShaderCachedData& data); - boo::IShaderPipeline* buildFromCache(const ShaderCachedData& foundData); - std::vector buildExtendedFromCache(const ShaderCachedData& foundData); + boo::IShaderPipeline* buildFromCache(const ShaderCachedData& foundData, + boo::IGraphicsDataFactory::Context& ctx); + std::vector buildExtendedFromCache(const ShaderCachedData& foundData, + boo::IGraphicsDataFactory::Context& ctx); public: ShaderCacheManager(const FileStoreManager& storeMgr, boo::IGraphicsDataFactory* gfxFactory, @@ -216,13 +222,17 @@ public: void setRenderTargetSamples(unsigned samps) {m_factory->m_rtHint = samps;} boo::IShaderPipeline* buildShader(const ShaderTag& tag, const std::string& source, - const std::string& diagName); + const std::string& diagName, + boo::IGraphicsDataFactory::Context& ctx); boo::IShaderPipeline* buildShader(const ShaderTag& tag, const hecl::Frontend::IR& ir, - const std::string& diagName); + const std::string& diagName, + boo::IGraphicsDataFactory::Context& ctx); std::vector buildExtendedShader(const ShaderTag& tag, const std::string& source, - const std::string& diagName); + const std::string& diagName, + boo::IGraphicsDataFactory::Context& ctx); std::vector buildExtendedShader(const ShaderTag& tag, const hecl::Frontend::IR& ir, - const std::string& diagName); + const std::string& diagName, + boo::IGraphicsDataFactory::Context& ctx); }; /** @@ -234,19 +244,19 @@ struct HMDLData boo::IGraphicsBufferS* m_ibo; boo::IVertexFormat* m_vtxFmt = nullptr; - HMDLData(boo::IGraphicsDataFactory* factory, + HMDLData(boo::IGraphicsDataFactory::Context& ctx, const void* metaData, const void* vbo, const void* ibo); /* For binding constructors that require vertex format up front (GLSL) */ - static boo::IVertexFormat* NewVertexFormat(boo::IGraphicsDataFactory* factory, const HMDLMeta& meta, + static boo::IVertexFormat* NewVertexFormat(boo::IGraphicsDataFactory::Context& ctx, const HMDLMeta& meta, boo::IGraphicsBuffer* vbo=nullptr, boo::IGraphicsBuffer* ibo=nullptr); - boo::IShaderDataBinding* newShaderDataBindng(boo::IGraphicsDataFactory* factory, + boo::IShaderDataBinding* newShaderDataBindng(boo::IGraphicsDataFactory::Context& ctx, boo::IShaderPipeline* shader, size_t ubufCount, boo::IGraphicsBuffer** ubufs, size_t texCount, boo::ITexture** texs) - {return factory->newShaderDataBinding(shader, m_vtxFmt, m_vbo, nullptr, m_ibo, - ubufCount, ubufs, texCount, texs);} + {return ctx.newShaderDataBinding(shader, m_vtxFmt, m_vbo, nullptr, m_ibo, + ubufCount, ubufs, nullptr, nullptr, texCount, texs);} }; } diff --git a/hecl/lib/Backend/GLSL.cpp b/hecl/lib/Backend/GLSL.cpp index e7d57099f..11b65d1c6 100644 --- a/hecl/lib/Backend/GLSL.cpp +++ b/hecl/lib/Backend/GLSL.cpp @@ -251,14 +251,11 @@ static const char* STD_BLOCKNAMES[] = {"HECLVertUniform"}; struct GLSLBackendFactory : IShaderBackendFactory { Backend::GLSL m_backend; - boo::GLDataFactory* m_gfxFactory; - - GLSLBackendFactory(boo::IGraphicsDataFactory* gfxFactory) - : m_gfxFactory(dynamic_cast(gfxFactory)) {} ShaderCachedData buildShaderFromIR(const ShaderTag& tag, const hecl::Frontend::IR& ir, hecl::Frontend::Diagnostics& diag, + boo::IGraphicsDataFactory::Context& ctx, boo::IShaderPipeline*& objOut) { m_backend.reset(ir, diag); @@ -273,12 +270,13 @@ struct GLSLBackendFactory : IShaderBackendFactory std::string fragSource = m_backend.makeFrag("#version 330"); cachedSz += fragSource.size() + 1; objOut = - m_gfxFactory->newShaderPipeline(vertSource.c_str(), fragSource.c_str(), - m_backend.m_texMapEnd, "texs", - 1, STD_BLOCKNAMES, - m_backend.m_blendSrc, m_backend.m_blendDst, boo::Primitive::TriStrips, - tag.getDepthTest(), tag.getDepthWrite(), - tag.getBackfaceCulling()); + static_cast(ctx). + newShaderPipeline(vertSource.c_str(), fragSource.c_str(), + m_backend.m_texMapEnd, "texs", + 1, STD_BLOCKNAMES, + m_backend.m_blendSrc, m_backend.m_blendDst, boo::Primitive::TriStrips, + tag.getDepthTest(), tag.getDepthWrite(), + tag.getBackfaceCulling()); if (!objOut) Log.report(logvisor::Fatal, "unable to build shader"); @@ -293,7 +291,8 @@ struct GLSLBackendFactory : IShaderBackendFactory return dataOut; } - boo::IShaderPipeline* buildShaderFromCache(const ShaderCachedData& data) + boo::IShaderPipeline* buildShaderFromCache(const ShaderCachedData& data, + boo::IGraphicsDataFactory::Context& ctx) { const ShaderTag& tag = data.m_tag; athena::io::MemoryReader r(data.m_data.get(), data.m_sz); @@ -303,12 +302,13 @@ struct GLSLBackendFactory : IShaderBackendFactory std::string vertSource = r.readString(); std::string fragSource = r.readString(); boo::IShaderPipeline* ret = - m_gfxFactory->newShaderPipeline(vertSource.c_str(), fragSource.c_str(), - texMapEnd, "texs", - 1, STD_BLOCKNAMES, - blendSrc, blendDst, boo::Primitive::TriStrips, - tag.getDepthTest(), tag.getDepthWrite(), - tag.getBackfaceCulling()); + static_cast(ctx). + newShaderPipeline(vertSource.c_str(), fragSource.c_str(), + texMapEnd, "texs", + 1, STD_BLOCKNAMES, + blendSrc, blendDst, boo::Primitive::TriStrips, + tag.getDepthTest(), tag.getDepthWrite(), + tag.getBackfaceCulling()); if (!ret) Log.report(logvisor::Fatal, "unable to build shader"); return ret; @@ -318,6 +318,7 @@ struct GLSLBackendFactory : IShaderBackendFactory const hecl::Frontend::IR& ir, hecl::Frontend::Diagnostics& diag, const std::vector& extensionSlots, + boo::IGraphicsDataFactory::Context& ctx, FReturnExtensionShader returnFunc) { m_backend.reset(ir, diag); @@ -336,12 +337,13 @@ struct GLSLBackendFactory : IShaderBackendFactory fragSources.push_back(m_backend.makeFrag("#version 330", slot.lighting, slot.post)); cachedSz += fragSources.back().size() + 1; boo::IShaderPipeline* ret = - m_gfxFactory->newShaderPipeline(vertSource.c_str(), fragSources.back().c_str(), - m_backend.m_texMapEnd, "texs", - 1, STD_BLOCKNAMES, - m_backend.m_blendSrc, m_backend.m_blendDst, boo::Primitive::TriStrips, - tag.getDepthTest(), tag.getDepthWrite(), - tag.getBackfaceCulling()); + static_cast(ctx). + newShaderPipeline(vertSource.c_str(), fragSources.back().c_str(), + m_backend.m_texMapEnd, "texs", + 1, STD_BLOCKNAMES, + m_backend.m_blendSrc, m_backend.m_blendDst, boo::Primitive::TriStrips, + tag.getDepthTest(), tag.getDepthWrite(), + tag.getBackfaceCulling()); if (!ret) Log.report(logvisor::Fatal, "unable to build shader"); returnFunc(ret); @@ -361,6 +363,7 @@ struct GLSLBackendFactory : IShaderBackendFactory void buildExtendedShaderFromCache(const ShaderCachedData& data, const std::vector& extensionSlots, + boo::IGraphicsDataFactory::Context& ctx, FReturnExtensionShader returnFunc) { const ShaderTag& tag = data.m_tag; @@ -373,12 +376,13 @@ struct GLSLBackendFactory : IShaderBackendFactory { std::string fragSource = r.readString(); boo::IShaderPipeline* ret = - m_gfxFactory->newShaderPipeline(vertSource.c_str(), fragSource.c_str(), - texMapEnd, "texs", - 1, STD_BLOCKNAMES, - blendSrc, blendDst, boo::Primitive::TriStrips, - tag.getDepthTest(), tag.getDepthWrite(), - tag.getBackfaceCulling()); + static_cast(ctx). + newShaderPipeline(vertSource.c_str(), fragSource.c_str(), + texMapEnd, "texs", + 1, STD_BLOCKNAMES, + blendSrc, blendDst, boo::Primitive::TriStrips, + tag.getDepthTest(), tag.getDepthWrite(), + tag.getBackfaceCulling()); if (!ret) Log.report(logvisor::Fatal, "unable to build shader"); returnFunc(ret); @@ -386,9 +390,9 @@ struct GLSLBackendFactory : IShaderBackendFactory } }; -IShaderBackendFactory* _NewGLSLBackendFactory(boo::IGraphicsDataFactory* gfxFactory) +IShaderBackendFactory* _NewGLSLBackendFactory() { - return new struct GLSLBackendFactory(gfxFactory); + return new struct GLSLBackendFactory(); } #if BOO_HAS_VULKAN @@ -396,14 +400,11 @@ IShaderBackendFactory* _NewGLSLBackendFactory(boo::IGraphicsDataFactory* gfxFact struct SPIRVBackendFactory : IShaderBackendFactory { Backend::GLSL m_backend; - boo::VulkanDataFactory* m_gfxFactory; - - SPIRVBackendFactory(boo::IGraphicsDataFactory* gfxFactory) - : m_gfxFactory(dynamic_cast(gfxFactory)) {} ShaderCachedData buildShaderFromIR(const ShaderTag& tag, const hecl::Frontend::IR& ir, hecl::Frontend::Diagnostics& diag, + boo::IGraphicsDataFactory::Context& ctx, boo::IShaderPipeline*& objOut) { m_backend.reset(ir, diag); @@ -420,11 +421,12 @@ struct SPIRVBackendFactory : IShaderBackendFactory std::vector pipelineBlob; objOut = - m_gfxFactory->newShaderPipeline(vertSource.c_str(), fragSource.c_str(), - vertBlob, fragBlob, pipelineBlob, tag.newVertexFormat(m_gfxFactory), - m_backend.m_blendSrc, m_backend.m_blendDst, boo::Primitive::TriStrips, - tag.getDepthTest(), tag.getDepthWrite(), - tag.getBackfaceCulling()); + static_cast(ctx). + newShaderPipeline(vertSource.c_str(), fragSource.c_str(), + vertBlob, fragBlob, pipelineBlob, tag.newVertexFormat(ctx), + m_backend.m_blendSrc, m_backend.m_blendDst, boo::Primitive::TriStrips, + tag.getDepthTest(), tag.getDepthWrite(), + tag.getBackfaceCulling()); if (!objOut) Log.report(logvisor::Fatal, "unable to build shader"); @@ -468,7 +470,8 @@ struct SPIRVBackendFactory : IShaderBackendFactory return dataOut; } - boo::IShaderPipeline* buildShaderFromCache(const ShaderCachedData& data) + boo::IShaderPipeline* buildShaderFromCache(const ShaderCachedData& data, + boo::IGraphicsDataFactory::Context& ctx) { const ShaderTag& tag = data.m_tag; athena::io::MemoryReader r(data.m_data.get(), data.m_sz); @@ -492,12 +495,13 @@ struct SPIRVBackendFactory : IShaderBackendFactory r.readUBytesToBuf(pipelineBlob.data(), pipelineSz); boo::IShaderPipeline* ret = - m_gfxFactory->newShaderPipeline(nullptr, nullptr, - vertBlob, fragBlob, pipelineBlob, - tag.newVertexFormat(m_gfxFactory), - blendSrc, blendDst, boo::Primitive::TriStrips, - tag.getDepthTest(), tag.getDepthWrite(), - tag.getBackfaceCulling()); + static_cast(ctx). + newShaderPipeline(nullptr, nullptr, + vertBlob, fragBlob, pipelineBlob, + tag.newVertexFormat(ctx), + blendSrc, blendDst, boo::Primitive::TriStrips, + tag.getDepthTest(), tag.getDepthWrite(), + tag.getBackfaceCulling()); if (!ret) Log.report(logvisor::Fatal, "unable to build shader"); return ret; @@ -507,6 +511,7 @@ struct SPIRVBackendFactory : IShaderBackendFactory const hecl::Frontend::IR& ir, hecl::Frontend::Diagnostics& diag, const std::vector& extensionSlots, + boo::IGraphicsDataFactory::Context& ctx, FReturnExtensionShader returnFunc) { m_backend.reset(ir, diag); @@ -527,12 +532,13 @@ struct SPIRVBackendFactory : IShaderBackendFactory fragPipeBlobs.emplace_back(); std::pair, std::vector>& fragPipeBlob = fragPipeBlobs.back(); boo::IShaderPipeline* ret = - m_gfxFactory->newShaderPipeline(vertSource.c_str(), fragSource.c_str(), - vertBlob, fragPipeBlob.first, fragPipeBlob.second, - tag.newVertexFormat(m_gfxFactory), - m_backend.m_blendSrc, m_backend.m_blendDst, boo::Primitive::TriStrips, - tag.getDepthTest(), tag.getDepthWrite(), - tag.getBackfaceCulling()); + static_cast(ctx). + newShaderPipeline(vertSource.c_str(), fragSource.c_str(), + vertBlob, fragPipeBlob.first, fragPipeBlob.second, + tag.newVertexFormat(ctx), + m_backend.m_blendSrc, m_backend.m_blendDst, boo::Primitive::TriStrips, + tag.getDepthTest(), tag.getDepthWrite(), + tag.getBackfaceCulling()); if (!ret) Log.report(logvisor::Fatal, "unable to build shader"); cachedSz += fragPipeBlob.first.size() * sizeof(unsigned int); @@ -583,6 +589,7 @@ struct SPIRVBackendFactory : IShaderBackendFactory void buildExtendedShaderFromCache(const ShaderCachedData& data, const std::vector& extensionSlots, + boo::IGraphicsDataFactory::Context& ctx, FReturnExtensionShader returnFunc) { const ShaderTag& tag = data.m_tag; @@ -609,12 +616,13 @@ struct SPIRVBackendFactory : IShaderBackendFactory r.readUBytesToBuf(pipelineBlob.data(), pipelineSz); boo::IShaderPipeline* ret = - m_gfxFactory->newShaderPipeline(nullptr, nullptr, - vertBlob, fragBlob, pipelineBlob, - tag.newVertexFormat(m_gfxFactory), - blendSrc, blendDst, boo::Primitive::TriStrips, - tag.getDepthTest(), tag.getDepthWrite(), - tag.getBackfaceCulling()); + static_cast(ctx). + newShaderPipeline(nullptr, nullptr, + vertBlob, fragBlob, pipelineBlob, + tag.newVertexFormat(ctx), + blendSrc, blendDst, boo::Primitive::TriStrips, + tag.getDepthTest(), tag.getDepthWrite(), + tag.getBackfaceCulling()); if (!ret) Log.report(logvisor::Fatal, "unable to build shader"); returnFunc(ret); @@ -622,9 +630,9 @@ struct SPIRVBackendFactory : IShaderBackendFactory } }; -IShaderBackendFactory* _NewSPIRVBackendFactory(boo::IGraphicsDataFactory* gfxFactory) +IShaderBackendFactory* _NewSPIRVBackendFactory() { - return new struct SPIRVBackendFactory(gfxFactory); + return new struct SPIRVBackendFactory(); } #endif diff --git a/hecl/lib/Runtime/HMDL.cpp b/hecl/lib/Runtime/HMDL.cpp index 3d3cd2ac2..8fd3abe7d 100644 --- a/hecl/lib/Runtime/HMDL.cpp +++ b/hecl/lib/Runtime/HMDL.cpp @@ -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 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()); } } diff --git a/hecl/lib/Runtime/ShaderCacheManager.cpp b/hecl/lib/Runtime/ShaderCacheManager.cpp index 4bb82d38e..bd143a647 100644 --- a/hecl/lib/Runtime/ShaderCacheManager.cpp +++ b/hecl/lib/Runtime/ShaderCacheManager.cpp @@ -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 -ShaderCacheManager::buildExtendedFromCache(const ShaderCachedData& foundData) +ShaderCacheManager::buildExtendedFromCache(const ShaderCachedData& foundData, + boo::IGraphicsDataFactory::Context& ctx) { std::vector 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 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 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 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, diff --git a/hecl/test/main.cpp b/hecl/test/main.cpp index c74968c6f..f0c000579 100644 --- a/hecl/test/main.cpp +++ b/hecl/test/main.cpp @@ -74,76 +74,79 @@ struct HECLApplicationCallback : boo::IApplicationCallback std::unique_lock innerLk(initmt); boo::IGraphicsDataFactory* gfxF = m_mainWindow->getLoadContextDataFactory(); - boo::SWindowRect mainWindowRect = m_mainWindow->getWindowFrame(); - renderTex = gfxF->newRenderTexture(mainWindowRect.size[0], mainWindowRect.size[1], false, false); - - /* HECL managers */ - hecl::Runtime::FileStoreManager fileMgr(app->getUniqueName()); - hecl::Runtime::ShaderCacheManager shaderMgr(fileMgr, gfxF); - - /* Compile HECL shader */ - static std::string testShader = "HECLOpaque(Texture(0, UV(0)))"; - hecl::Runtime::ShaderTag testShaderTag(testShader, 0, 1, 0, 0, 0, false, false, false); - boo::IShaderPipeline* testShaderObj = - shaderMgr.buildShader(testShaderTag, testShader, "testShader"); - - /* Generate meta structure (usually statically serialized) */ - hecl::HMDLMeta testMeta; - testMeta.topology = hecl::HMDLTopology::TriStrips; - testMeta.vertStride = 32; - testMeta.vertCount = 4; - testMeta.indexCount = 4; - testMeta.colorCount = 0; - testMeta.uvCount = 1; - testMeta.weightCount = 0; - - /* Binary form of meta structure */ - atUint8 testMetaBuf[HECL_HMDL_META_SZ]; - athena::io::MemoryWriter testMetaWriter(testMetaBuf, HECL_HMDL_META_SZ); - testMeta.write(testMetaWriter); - - /* Make Tri-strip VBO */ - struct Vert + boo::GraphicsDataToken data = + gfxF->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) -> bool { - float pos[3]; - float norm[3]; - float uv[2]; - }; - static const Vert quad[4] = - { - {{0.5,0.5},{},{1.0,1.0}}, - {{-0.5,0.5},{},{0.0,1.0}}, - {{0.5,-0.5},{},{1.0,0.0}}, - {{-0.5,-0.5},{},{0.0,0.0}} - }; + boo::SWindowRect mainWindowRect = m_mainWindow->getWindowFrame(); + renderTex = ctx.newRenderTexture(mainWindowRect.size[0], mainWindowRect.size[1], false, false); - /* Now simple IBO */ - static const uint32_t ibo[4] = {0,1,2,3}; + /* HECL managers */ + hecl::Runtime::FileStoreManager fileMgr(app->getUniqueName()); + hecl::Runtime::ShaderCacheManager shaderMgr(fileMgr, gfxF); - /* Construct quad mesh against boo factory */ - hecl::Runtime::HMDLData testData(gfxF, testMetaBuf, quad, ibo); + /* Compile HECL shader */ + static std::string testShader = "HECLOpaque(Texture(0, UV(0)))"; + hecl::Runtime::ShaderTag testShaderTag(testShader, 0, 1, 0, 0, 0, false, false, false); + boo::IShaderPipeline* testShaderObj = + shaderMgr.buildShader(testShaderTag, testShader, "testShader", ctx); - /* Make ramp texture */ - using Pixel = uint8_t[4]; - static Pixel tex[256][256]; - for (int i=0 ; i<256 ; ++i) - for (int j=0 ; j<256 ; ++j) + /* Generate meta structure (usually statically serialized) */ + hecl::HMDLMeta testMeta; + testMeta.topology = hecl::HMDLTopology::TriStrips; + testMeta.vertStride = 32; + testMeta.vertCount = 4; + testMeta.indexCount = 4; + testMeta.colorCount = 0; + testMeta.uvCount = 1; + testMeta.weightCount = 0; + + /* Binary form of meta structure */ + atUint8 testMetaBuf[HECL_HMDL_META_SZ]; + athena::io::MemoryWriter testMetaWriter(testMetaBuf, HECL_HMDL_META_SZ); + testMeta.write(testMetaWriter); + + /* Make Tri-strip VBO */ + struct Vert { - tex[i][j][0] = i; - tex[i][j][1] = j; - tex[i][j][2] = 0; - tex[i][j][3] = 0xff; - } - boo::ITexture* texture = - gfxF->newStaticTexture(256, 256, 1, boo::TextureFormat::RGBA8, tex, 256*256*4); + float pos[3]; + float norm[3]; + float uv[2]; + }; + static const Vert quad[4] = + { + {{0.5,0.5},{},{1.0,1.0}}, + {{-0.5,0.5},{},{0.0,1.0}}, + {{0.5,-0.5},{},{1.0,0.0}}, + {{-0.5,-0.5},{},{0.0,0.0}} + }; - /* Make vertex uniform buffer */ - vubo = gfxF->newDynamicBuffer(boo::BufferUse::Uniform, sizeof(VertexUBO), 1); + /* Now simple IBO */ + static const uint32_t ibo[4] = {0,1,2,3}; - /* Assemble data binding */ - binding = testData.newShaderDataBindng(gfxF, testShaderObj, 1, (boo::IGraphicsBuffer**)&vubo, 1, &texture); + /* Construct quad mesh against boo factory */ + hecl::Runtime::HMDLData testData(ctx, testMetaBuf, quad, ibo); - boo::GraphicsDataToken data = gfxF->commit(); + /* Make ramp texture */ + using Pixel = uint8_t[4]; + static Pixel tex[256][256]; + for (int i=0 ; i<256 ; ++i) + for (int j=0 ; j<256 ; ++j) + { + tex[i][j][0] = i; + tex[i][j][1] = j; + tex[i][j][2] = 0; + tex[i][j][3] = 0xff; + } + boo::ITexture* texture = + ctx.newStaticTexture(256, 256, 1, boo::TextureFormat::RGBA8, tex, 256*256*4); + + /* Make vertex uniform buffer */ + vubo = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(VertexUBO), 1); + + /* Assemble data binding */ + binding = testData.newShaderDataBindng(ctx, testShaderObj, 1, (boo::IGraphicsBuffer**)&vubo, 1, &texture); + return true; + }); /* Return control to main thread */ innerLk.unlock();