Vulkan Updates

This commit is contained in:
Jack Andersen 2016-02-22 16:33:29 -10:00
parent 41ecea7a37
commit d76fcf0f5b
10 changed files with 52 additions and 56 deletions

View File

@ -24,6 +24,7 @@ set(BOO_INCLUDE_DIR extern/libBoo/include)
add_subdirectory(bintoc)
add_subdirectory(extern)
add_definitions(${BOO_SYS_DEFINES})
include_directories(include ${LOG_VISOR_INCLUDE_DIR} ${ATHENA_INCLUDE_DIR} ${BOO_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR})
add_subdirectory(lib)
add_subdirectory(blender)

2
hecl/extern/libBoo vendored

@ -1 +1 @@
Subproject commit 8bfb883d59cbd88c858f034622d95324a6d266fa
Subproject commit 74e2f47bcf698801c80cbaf474cf253a76681d8f

View File

@ -1,12 +1,6 @@
#ifndef HECLBACKEND_METAL_HPP
#define HECLBACKEND_METAL_HPP
#if __APPLE__
#include "ProgrammableCommon.hpp"
#include <Availability.h>
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101100
#define HECL_HAS_METAL 1
#if BOO_HAS_METAL
namespace HECL
{
@ -39,9 +33,5 @@ private:
}
}
#else
#define HECL_HAS_METAL 0
#endif
#endif // __APPLE__
#endif // BOO_HAS_METAL
#endif // HECLBACKEND_METAL_HPP

View File

@ -159,7 +159,7 @@ protected:
virtual ShaderCachedData buildShaderFromIR(const ShaderTag& tag,
const HECL::Frontend::IR& ir,
HECL::Frontend::Diagnostics& diag,
boo::IShaderPipeline** objOut)=0;
boo::IShaderPipeline*& objOut)=0;
virtual boo::IShaderPipeline* buildShaderFromCache(const ShaderCachedData& data)=0;
virtual ShaderCachedData buildExtendedShaderFromIR(const ShaderTag& tag,
const HECL::Frontend::IR& ir,

View File

@ -259,7 +259,7 @@ struct GLSLBackendFactory : IShaderBackendFactory
ShaderCachedData buildShaderFromIR(const ShaderTag& tag,
const HECL::Frontend::IR& ir,
HECL::Frontend::Diagnostics& diag,
boo::IShaderPipeline** objOut)
boo::IShaderPipeline*& objOut)
{
m_backend.reset(ir, diag);
size_t cachedSz = 3;
@ -272,14 +272,14 @@ struct GLSLBackendFactory : IShaderBackendFactory
std::string fragSource = m_backend.makeFrag("#version 330");
cachedSz += fragSource.size() + 1;
*objOut =
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,
tag.getDepthTest(), tag.getDepthWrite(),
tag.getBackfaceCulling());
if (!*objOut)
if (!objOut)
Log.report(LogVisor::FatalError, "unable to build shader");
ShaderCachedData dataOut(tag, cachedSz);
@ -386,6 +386,13 @@ struct GLSLBackendFactory : IShaderBackendFactory
}
};
IShaderBackendFactory* _NewGLSLBackendFactory(boo::IGraphicsDataFactory* gfxFactory)
{
return new struct GLSLBackendFactory(gfxFactory);
}
#if BOO_HAS_VULKAN
struct SPIRVBackendFactory : IShaderBackendFactory
{
Backend::GLSL m_backend;
@ -397,7 +404,7 @@ struct SPIRVBackendFactory : IShaderBackendFactory
ShaderCachedData buildShaderFromIR(const ShaderTag& tag,
const HECL::Frontend::IR& ir,
HECL::Frontend::Diagnostics& diag,
boo::IShaderPipeline** objOut)
boo::IShaderPipeline*& objOut)
{
m_backend.reset(ir, diag);
@ -410,17 +417,15 @@ struct SPIRVBackendFactory : IShaderBackendFactory
std::vector<unsigned int> vertBlob;
std::vector<unsigned int> fragBlob;
std::vector<unsigned int> pipelineBlob;
std::vector<unsigned char> pipelineBlob;
*objOut =
objOut =
m_gfxFactory->newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
vertBlob, fragBlob, pipelineBlob,
m_backend.m_texMapEnd, "texs",
1, STD_BLOCKNAMES,
vertBlob, fragBlob, pipelineBlob, tag.newVertexFormat(m_gfxFactory),
m_backend.m_blendSrc, m_backend.m_blendDst,
tag.getDepthTest(), tag.getDepthWrite(),
tag.getBackfaceCulling());
if (!*objOut)
if (!objOut)
Log.report(LogVisor::FatalError, "unable to build shader");
@ -482,15 +487,14 @@ struct SPIRVBackendFactory : IShaderBackendFactory
r.readUBytesToBuf(fragBlob.data(), fragSz);
atUint32 pipelineSz = r.readUint32Big();
std::vector<unsigned int> pipelineBlob(pipelineSz / sizeof(unsigned int));
std::vector<unsigned char> pipelineBlob(pipelineSz);
if (pipelineSz)
r.readUBytesToBuf(pipelineBlob.data(), pipelineSz);
boo::IShaderPipeline* ret =
m_gfxFactory->newShaderPipeline(nullptr, nullptr,
vertBlob, fragBlob, pipelineBlob,
texCount, "texs",
1, STD_BLOCKNAMES,
tag.newVertexFormat(m_gfxFactory),
blendSrc, blendDst,
tag.getDepthTest(), tag.getDepthWrite(),
tag.getBackfaceCulling());
@ -513,7 +517,7 @@ struct SPIRVBackendFactory : IShaderBackendFactory
tag.getSkinSlotCount(), tag.getTexMtxCount());
std::vector<unsigned int> vertBlob;
std::vector<std::pair<std::vector<unsigned int>, std::vector<unsigned int>>> fragPipeBlobs;
std::vector<std::pair<std::vector<unsigned int>, std::vector<unsigned char>>> fragPipeBlobs;
fragPipeBlobs.reserve(extensionSlots.size());
size_t cachedSz = 7 + 8 * extensionSlots.size();
@ -521,19 +525,18 @@ struct SPIRVBackendFactory : IShaderBackendFactory
{
std::string fragSource = m_backend.makeFrag("#version 330", slot.lighting, slot.post);
fragPipeBlobs.emplace_back();
std::pair<std::vector<unsigned int>, std::vector<unsigned int>>& fragPipeBlob = fragPipeBlobs.back();
std::pair<std::vector<unsigned int>, std::vector<unsigned char>>& fragPipeBlob = fragPipeBlobs.back();
boo::IShaderPipeline* ret =
m_gfxFactory->newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
vertBlob, fragPipeBlob.first, fragPipeBlob.second,
m_backend.m_texMapEnd, "texs",
1, STD_BLOCKNAMES,
tag.newVertexFormat(m_gfxFactory),
m_backend.m_blendSrc, m_backend.m_blendDst,
tag.getDepthTest(), tag.getDepthWrite(),
tag.getBackfaceCulling());
if (!ret)
Log.report(LogVisor::FatalError, "unable to build shader");
cachedSz += fragPipeBlob.first.size() * sizeof(unsigned int);
cachedSz += fragPipeBlob.second.size() * sizeof(unsigned int);
cachedSz += fragPipeBlob.second.size();
returnFunc(ret);
}
size_t vertBlobSz = vertBlob.size() * sizeof(unsigned int);
@ -554,10 +557,10 @@ struct SPIRVBackendFactory : IShaderBackendFactory
else
w.writeUint32Big(0);
for (const std::pair<std::vector<unsigned int>, std::vector<unsigned int>>& fragPipeBlob : fragPipeBlobs)
for (const std::pair<std::vector<unsigned int>, std::vector<unsigned char>>& fragPipeBlob : fragPipeBlobs)
{
size_t fragBlobSz = fragPipeBlob.first.size() * sizeof(unsigned int);
size_t pipeBlobSz = fragPipeBlob.second.size() * sizeof(unsigned int);
size_t pipeBlobSz = fragPipeBlob.second.size();
if (fragBlobSz)
{
w.writeUint32Big(fragBlobSz);
@ -601,15 +604,14 @@ struct SPIRVBackendFactory : IShaderBackendFactory
r.readUBytesToBuf(fragBlob.data(), fragSz);
atUint32 pipelineSz = r.readUint32Big();
std::vector<unsigned int> pipelineBlob(pipelineSz / sizeof(unsigned int));
std::vector<unsigned char> pipelineBlob(pipelineSz);
if (pipelineSz)
r.readUBytesToBuf(pipelineBlob.data(), pipelineSz);
boo::IShaderPipeline* ret =
m_gfxFactory->newShaderPipeline(nullptr, nullptr,
vertBlob, fragBlob, pipelineBlob,
texCount, "texs",
1, STD_BLOCKNAMES,
tag.newVertexFormat(m_gfxFactory),
blendSrc, blendDst,
tag.getDepthTest(), tag.getDepthWrite(),
tag.getBackfaceCulling());
@ -620,16 +622,12 @@ struct SPIRVBackendFactory : IShaderBackendFactory
}
};
IShaderBackendFactory* _NewGLSLBackendFactory(boo::IGraphicsDataFactory* gfxFactory)
{
return new struct GLSLBackendFactory(gfxFactory);
}
IShaderBackendFactory* _NewSPIRVBackendFactory(boo::IGraphicsDataFactory* gfxFactory)
{
//return new struct SPIRVBackendFactory(gfxFactory);
return nullptr;
return new struct SPIRVBackendFactory(gfxFactory);
}
#endif
}
}

View File

@ -248,7 +248,7 @@ struct HLSLBackendFactory : IShaderBackendFactory
ShaderCachedData buildShaderFromIR(const ShaderTag& tag,
const HECL::Frontend::IR& ir,
HECL::Frontend::Diagnostics& diag,
boo::IShaderPipeline** objOut)
boo::IShaderPipeline*& objOut)
{
m_backend.reset(ir, diag);
@ -260,7 +260,7 @@ struct HLSLBackendFactory : IShaderBackendFactory
ComPtr<ID3DBlob> vertBlob;
ComPtr<ID3DBlob> fragBlob;
ComPtr<ID3DBlob> pipelineBlob;
*objOut =
objOut =
m_gfxFactory->newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
vertBlob, fragBlob, pipelineBlob,
tag.newVertexFormat(m_gfxFactory),

View File

@ -1,5 +1,5 @@
#include "HECL/Backend/Metal.hpp"
#if HECL_HAS_METAL
#if BOO_HAS_METAL
#include "HECL/Runtime.hpp"
#include <Athena/MemoryReader.hpp>
#include <Athena/MemoryWriter.hpp>
@ -263,7 +263,7 @@ struct MetalBackendFactory : IShaderBackendFactory
ShaderCachedData buildShaderFromIR(const ShaderTag& tag,
const HECL::Frontend::IR& ir,
HECL::Frontend::Diagnostics& diag,
boo::IShaderPipeline** objOut)
boo::IShaderPipeline*& objOut)
{
if (!m_rtHint)
Log.report(LogVisor::FatalError,
@ -279,7 +279,7 @@ struct MetalBackendFactory : IShaderBackendFactory
std::string fragSource = m_backend.makeFrag();
cachedSz += fragSource.size() + 1;
*objOut =
objOut =
m_gfxFactory->newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
tag.newVertexFormat(m_gfxFactory), m_rtHint,
m_backend.m_blendSrc, m_backend.m_blendDst,

View File

@ -63,7 +63,7 @@ boo::IVertexFormat* HMDLData::NewVertexFormat(boo::IGraphicsDataFactory* factory
return factory->newVertexFormat(elemCount, vdescs.get());
}
/* For shader constructors that require vertex format up-front (HLSL) */
/* For shader constructors that require vertex format up-front (HLSL/Metal/Vulkan) */
boo::IVertexFormat* ShaderTag::newVertexFormat(boo::IGraphicsDataFactory *factory) const
{
size_t elemCount = 2 + m_colorCount + m_uvCount + m_weightCount;

View File

@ -6,9 +6,7 @@
#include <ctime>
#include "HECL/Backend/GLSL.hpp"
#if __APPLE__
#include "HECL/Backend/Metal.hpp"
#endif
namespace HECL
{
@ -17,9 +15,13 @@ namespace Runtime
IShaderBackendFactory* _NewGLSLBackendFactory(boo::IGraphicsDataFactory* gfxFactory);
#if _WIN32
IShaderBackendFactory* _NewHLSLBackendFactory(boo::IGraphicsDataFactory* gfxFactory);
#elif __APPLE__
#endif
#if BOO_HAS_METAL
IShaderBackendFactory* _NewMetalBackendFactory(boo::IGraphicsDataFactory* gfxFactory);
#endif
#if BOO_HAS_VULKAN
IShaderBackendFactory* _NewSPIRVBackendFactory(boo::IGraphicsDataFactory* gfxFactory);
#endif
static LogVisor::LogModule Log("ShaderCacheManager");
static uint64_t IDX_MAGIC = SBig(uint64_t(0xDEADFEEDC001D00D));
@ -121,10 +123,16 @@ ShaderCacheManager::ShaderCacheManager(const FileStoreManager& storeMgr,
case boo::IGraphicsDataFactory::Platform::D3D12:
m_factory.reset(_NewHLSLBackendFactory(gfxFactory));
break;
#elif __APPLE__ && HECL_HAS_METAL
#endif
#if BOO_HAS_METAL
case boo::IGraphicsDataFactory::Platform::Metal:
m_factory.reset(_NewMetalBackendFactory(gfxFactory));
break;
#endif
#if BOO_HAS_VULKAN
case boo::IGraphicsDataFactory::Platform::Vulkan:
m_factory.reset(_NewSPIRVBackendFactory(gfxFactory));
break;
#endif
default:
Log.report(LogVisor::FatalError, _S("unsupported backend %s"), gfxFactory->platformName());
@ -369,7 +377,7 @@ ShaderCacheManager::buildShader(const ShaderTag& tag, const HECL::Frontend::IR&
return buildFromCache(foundData);
FE.getDiagnostics().reset(diagName);
boo::IShaderPipeline* ret;
addData(m_factory->buildShaderFromIR(tag, ir, FE.getDiagnostics(), &ret));
addData(m_factory->buildShaderFromIR(tag, ir, FE.getDiagnostics(), ret));
return ret;
}

View File

@ -191,7 +191,6 @@ struct HECLApplicationCallback : boo::IApplicationCallback
float rgba[] = {sinf(frameIdx / 60.0), cosf(frameIdx / 60.0), 0.0, 1.0};
gfxQ->setClearColor(rgba);
gfxQ->clearTarget();
gfxQ->setDrawPrimitive(boo::Primitive::TriStrips);
vuboData.modelview[3][0] = sinf(frameIdx / 60.0) * 0.5;
vuboData.modelview[3][1] = cosf(frameIdx / 60.0) * 0.5;