Spirv binaries are now compiled into the standard asset bundle
This commit is contained in:
@@ -521,6 +521,17 @@ KrResult KRContext::moveToBundle(const KrMoveToBundleInfo* moveToBundleInfo)
|
||||
|
||||
KrResult KRContext::compileAllShaders(const KrCompileAllShadersInfo* pCompileAllShadersInfo)
|
||||
{
|
||||
if (pCompileAllShadersInfo->bundleHandle < 0 || pCompileAllShadersInfo->bundleHandle >= m_resourceMapSize) {
|
||||
return KR_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
KRResource* bundleResource = m_resourceMap[pCompileAllShadersInfo->bundleHandle];
|
||||
if (bundleResource == nullptr) {
|
||||
return KR_ERROR_NOT_MAPPED;
|
||||
}
|
||||
KRBundle* bundle = dynamic_cast<KRBundle*>(bundleResource);
|
||||
if (bundle == nullptr) {
|
||||
return KR_ERROR_INCORRECT_TYPE;
|
||||
}
|
||||
if (pCompileAllShadersInfo->logHandle < -1 || pCompileAllShadersInfo->logHandle >= m_resourceMapSize) {
|
||||
return KR_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
@@ -538,9 +549,8 @@ KrResult KRContext::compileAllShaders(const KrCompileAllShadersInfo* pCompileAll
|
||||
m_resourceMap[pCompileAllShadersInfo->logHandle] = logResource;
|
||||
}
|
||||
|
||||
bool success = m_pShaderManager->compileAll(logResource);
|
||||
bool success = m_pShaderManager->compileAll(bundle, logResource);
|
||||
if (success) {
|
||||
// TODO - Save log to a resource
|
||||
return KR_SUCCESS;
|
||||
}
|
||||
return KR_ERROR_SHADER_COMPILE_FAILED;
|
||||
|
||||
@@ -35,6 +35,7 @@ using namespace kraken;
|
||||
|
||||
#include "../3rdparty/tinyxml2/tinyxml2.h"
|
||||
#include "../3rdparty/glslang/glslang/Public/ShaderLang.h"
|
||||
#include "../3rdparty/glslang/SPIRV/GlslangToSpv.h"
|
||||
#if defined(__APPLE__)
|
||||
|
||||
#include <sys/mman.h>
|
||||
|
||||
@@ -231,8 +231,9 @@ const TBuiltInResource DefaultTBuiltInResource = {
|
||||
} };
|
||||
|
||||
|
||||
bool KRShaderManager::compileAll(KRUnknown* logResource)
|
||||
bool KRShaderManager::compileAll(KRBundle* outputBundle, KRUnknown* logResource)
|
||||
{
|
||||
// TODO - Refactoring / cleanup needed once Vulkan shaders working...
|
||||
bool success = true;
|
||||
if (!m_initializedGlslang) {
|
||||
glslang::InitializeProcess();
|
||||
@@ -302,6 +303,40 @@ bool KRShaderManager::compileAll(KRUnknown* logResource)
|
||||
logResource->getData()->append("\n");
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (success) {
|
||||
for (int stage = 0; stage < EShLangCount; ++stage) {
|
||||
|
||||
if (program.getIntermediate((EShLanguage)stage)) {
|
||||
std::vector<unsigned int> spirv;
|
||||
spv::SpvBuildLogger logger;
|
||||
glslang::SpvOptions spvOptions;
|
||||
glslang::GlslangToSpv(*program.getIntermediate((EShLanguage)stage), spirv, &logger, &spvOptions);
|
||||
logResource->getData()->append(logger.getAllMessages().c_str());
|
||||
logResource->getData()->append("\n");
|
||||
|
||||
std::string shader_name;
|
||||
switch (stage)
|
||||
{
|
||||
case EShLangVertex:
|
||||
shader_name = vertSourceName;
|
||||
break;
|
||||
case EShLangFragment:
|
||||
shader_name = fragSourceName;
|
||||
break;
|
||||
}
|
||||
if (!shader_name.empty()) {
|
||||
KRDataBlock* data = new KRDataBlock();
|
||||
data->append(static_cast<void*>(spirv.data()), spirv.size() * sizeof(unsigned int));
|
||||
KRShader* shader = new KRShader(getContext(), shader_name, "spv", data);
|
||||
add(shader);
|
||||
if (outputBundle) {
|
||||
shader->moveToBundle(outputBundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (vertSource) {
|
||||
vertSource->getData()->unlock();
|
||||
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
KRShader *load(const std::string &name, const std::string &extension, KRDataBlock *data);
|
||||
KRShader *get(const std::string &name, const std::string &extension);
|
||||
|
||||
bool compileAll(KRUnknown* logResource);
|
||||
bool compileAll(KRBundle* outputBundle, KRUnknown* logResource);
|
||||
|
||||
const unordered_map<std::string, KRShader *> &get(const std::string &extension);
|
||||
|
||||
|
||||
@@ -184,6 +184,7 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
KrStructureType sType;
|
||||
KrResourceMapIndex bundleHandle;
|
||||
KrResourceMapIndex logHandle;
|
||||
} KrCompileAllShadersInfo;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user