Added KrCompileAllShaders and stub implementation

This commit is contained in:
2020-08-06 18:15:58 -07:00
parent b405c3014f
commit 78172b5abc
9 changed files with 77 additions and 10 deletions

View File

@@ -237,7 +237,7 @@ SET(STANDARD_ASSET_BUNDLE "${CMAKE_BINARY_DIR}/output/assets/standard_assets.krb
add_custom_command( add_custom_command(
OUTPUT ${STANDARD_ASSET_BUNDLE} OUTPUT ${STANDARD_ASSET_BUNDLE}
COMMAND kraken_convert -o ${STANDARD_ASSET_BUNDLE} ${KRAKEN_STANDARD_ASSETS} COMMAND kraken_convert -c -o ${STANDARD_ASSET_BUNDLE} ${KRAKEN_STANDARD_ASSETS}
DEPENDS kraken_convert ${KRAKEN_STANDARD_ASSETS} DEPENDS kraken_convert ${KRAKEN_STANDARD_ASSETS}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Creating Standard Assets" COMMENT "Creating Standard Assets"

View File

@@ -106,6 +106,7 @@ KRContext::KRContext(const KrInitializeInfo* initializeInfo)
#endif #endif
createDeviceContexts(); createDeviceContexts();
glslang::InitializeProcess();
} }
KRContext::~KRContext() { KRContext::~KRContext() {
@@ -170,6 +171,7 @@ KRContext::~KRContext() {
delete m_resourceMap; delete m_resourceMap;
m_resourceMap = NULL; m_resourceMap = NULL;
} }
glslang::FinalizeProcess();
} }
void KRContext::SetLogCallback(log_callback *log_callback, void *user_data) void KRContext::SetLogCallback(log_callback *log_callback, void *user_data)
@@ -493,6 +495,15 @@ KrResult KRContext::moveToBundle(const KrMoveToBundleInfo* moveToBundleInfo)
return resource->moveToBundle(bundle); return resource->moveToBundle(bundle);
} }
KrResult KRContext::compileAllShaders(const KrCompileAllShadersInfo* pCompileAllShadersInfo) {
bool success = m_pShaderManager->compileAll();
if (success) {
// TODO - Save log to a resource
return KR_SUCCESS;
}
return KR_ERROR_SHADER_COMPILE_FAILED;
}
KrResult KRContext::saveResource(const KrSaveResourceInfo* saveResourceInfo) KrResult KRContext::saveResource(const KrSaveResourceInfo* saveResourceInfo)
{ {
if (saveResourceInfo->resourceHandle < 0 || saveResourceInfo->resourceHandle >= m_resourceMapSize) { if (saveResourceInfo->resourceHandle < 0 || saveResourceInfo->resourceHandle >= m_resourceMapSize) {

View File

@@ -51,6 +51,8 @@ public:
KrResult unmapResource(const KrUnmapResourceInfo* unmapResourceInfo); KrResult unmapResource(const KrUnmapResourceInfo* unmapResourceInfo);
KrResult saveResource(const KrSaveResourceInfo* saveResourceInfo); KrResult saveResource(const KrSaveResourceInfo* saveResourceInfo);
KrResult compileAllShaders(const KrCompileAllShadersInfo* pCompileAllShadersInfo);
KrResult createScene(const KrCreateSceneInfo* createSceneInfo); KrResult createScene(const KrCreateSceneInfo* createSceneInfo);
KrResult findNodeByName(const KrFindNodeByNameInfo* pFindNodeByNameInfo); KrResult findNodeByName(const KrFindNodeByNameInfo* pFindNodeByNameInfo);
KrResult findAdjacentNodes(const KrFindAdjacentNodesInfo* pFindAdjacentNodesInfo); KrResult findAdjacentNodes(const KrFindAdjacentNodesInfo* pFindAdjacentNodesInfo);

View File

@@ -34,6 +34,7 @@ using namespace kraken;
#include <stdio.h> #include <stdio.h>
#include "../3rdparty/tinyxml2/tinyxml2.h" #include "../3rdparty/tinyxml2/tinyxml2.h"
#include "../3rdparty/glslang/glslang/Public/ShaderLang.h"
#if defined(__APPLE__) #if defined(__APPLE__)
#include <sys/mman.h> #include <sys/mman.h>

View File

@@ -115,3 +115,8 @@ const unordered_map<std::string, KRShader *> &KRShaderManager::get(const std::st
return m_shaders[lower_extension]; return m_shaders[lower_extension];
} }
bool KRShaderManager::compileAll()
{
return true;
}

View File

@@ -52,7 +52,8 @@ public:
KRShader *load(const std::string &name, const std::string &extension, KRDataBlock *data); KRShader *load(const std::string &name, const std::string &extension, KRDataBlock *data);
KRShader *get(const std::string &name, const std::string &extension); KRShader *get(const std::string &name, const std::string &extension);
bool compileAll();
const unordered_map<std::string, KRShader *> &get(const std::string &extension); const unordered_map<std::string, KRShader *> &get(const std::string &extension);

View File

@@ -114,6 +114,14 @@ KrResult KrMoveToBundle(const KrMoveToBundleInfo* pMoveToBundleInfo)
return sContext->moveToBundle(pMoveToBundleInfo); return sContext->moveToBundle(pMoveToBundleInfo);
} }
KrResult KrCompileAllShaders(const KrCompileAllShadersInfo* pCompileAllShadersInfo)
{
if (!sContext) {
return KR_ERROR_NOT_INITIALIZED;
}
return sContext->compileAllShaders(pCompileAllShadersInfo);
}
KrResult KrCreateScene(const KrCreateSceneInfo* pCreateSceneInfo) KrResult KrCreateScene(const KrCreateSceneInfo* pCreateSceneInfo)
{ {
if (!sContext) { if (!sContext) {

View File

@@ -50,6 +50,7 @@ typedef enum {
KR_ERROR_VULKAN_REQUIRED, KR_ERROR_VULKAN_REQUIRED,
KR_ERROR_VULKAN_SWAP_CHAIN, KR_ERROR_VULKAN_SWAP_CHAIN,
KR_ERROR_NO_DEVICE, KR_ERROR_NO_DEVICE,
KR_ERROR_SHADER_COMPILE_FAILED,
KR_ERROR_UNEXPECTED = 0x10000000, KR_ERROR_UNEXPECTED = 0x10000000,
KR_RESULT_MAX_ENUM = 0x7FFFFFFF KR_RESULT_MAX_ENUM = 0x7FFFFFFF
} KrResult; } KrResult;
@@ -69,6 +70,8 @@ typedef enum {
KR_STRUCTURE_TYPE_CREATE_BUNDLE, KR_STRUCTURE_TYPE_CREATE_BUNDLE,
KR_STRUCTURE_TYPE_MOVE_TO_BUNDLE, KR_STRUCTURE_TYPE_MOVE_TO_BUNDLE,
KR_STRUCTURE_TYPE_COMPILE_ALL_SHADERS,
KR_STRUCTURE_TYPE_CREATE_SCENE = 0x00020000, KR_STRUCTURE_TYPE_CREATE_SCENE = 0x00020000,
KR_STRUCTURE_TYPE_FIND_NODE_BY_NAME = 0x00030000, KR_STRUCTURE_TYPE_FIND_NODE_BY_NAME = 0x00030000,
@@ -165,6 +168,11 @@ typedef struct {
KrResourceMapIndex bundleHandle; KrResourceMapIndex bundleHandle;
} KrMoveToBundleInfo; } KrMoveToBundleInfo;
typedef struct {
KrStructureType sType;
KrResourceMapIndex logHandle;
} KrCompileAllShadersInfo;
typedef struct { typedef struct {
KrStructureType sType; KrStructureType sType;
const char* pSceneName; const char* pSceneName;
@@ -395,6 +403,8 @@ KrResult KrCreateBundle(const KrCreateBundleInfo* pCreateBundleInfo);
KrResult KrMoveToBundle(const KrMoveToBundleInfo* pMoveToBundleInfo); KrResult KrMoveToBundle(const KrMoveToBundleInfo* pMoveToBundleInfo);
KrResult KrInitNodeInfo(KrNodeInfo* pNodeInfo, KrStructureType nodeType); KrResult KrInitNodeInfo(KrNodeInfo* pNodeInfo, KrStructureType nodeType);
KrResult KrCompileAllShaders(const KrCompileAllShadersInfo* pCompileAllShadersInfo);
KrResult KrCreateScene(const KrCreateSceneInfo* pCreateSceneInfo); KrResult KrCreateScene(const KrCreateSceneInfo* pCreateSceneInfo);
KrResult KrFindNodeByName(const KrFindNodeByNameInfo* pFindNodeByNameInfo); KrResult KrFindNodeByName(const KrFindNodeByNameInfo* pFindNodeByNameInfo);
KrResult KrFindAdjacentNodes(const KrFindAdjacentNodesInfo* pFindAdjacentNodesInfo); KrResult KrFindAdjacentNodes(const KrFindAdjacentNodesInfo* pFindAdjacentNodesInfo);

View File

@@ -5,8 +5,15 @@
using namespace kraken; using namespace kraken;
enum ResourceMapping {
output_bundle = 0,
loaded_resource = 1,
shader_compile_log = 2,
};
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {
bool failed = false;
printf("Kraken Convert\n"); printf("Kraken Convert\n");
printf("Initializing Kraken...\n"); printf("Initializing Kraken...\n");
KrInitializeInfo init_info = {}; KrInitializeInfo init_info = {};
@@ -20,7 +27,7 @@ int main( int argc, char *argv[] )
KrCreateBundleInfo create_bundle_info = {}; KrCreateBundleInfo create_bundle_info = {};
create_bundle_info.sType = KR_STRUCTURE_TYPE_CREATE_BUNDLE; create_bundle_info.sType = KR_STRUCTURE_TYPE_CREATE_BUNDLE;
create_bundle_info.resourceHandle = 0; create_bundle_info.resourceHandle = ResourceMapping::output_bundle;
create_bundle_info.pBundleName = "output"; create_bundle_info.pBundleName = "output";
res = KrCreateBundle(&create_bundle_info); res = KrCreateBundle(&create_bundle_info);
if (res != KR_SUCCESS) { if (res != KR_SUCCESS) {
@@ -31,15 +38,16 @@ int main( int argc, char *argv[] )
KrLoadResourceInfo load_resource_info = {}; KrLoadResourceInfo load_resource_info = {};
load_resource_info.sType = KR_STRUCTURE_TYPE_LOAD_RESOURCE; load_resource_info.sType = KR_STRUCTURE_TYPE_LOAD_RESOURCE;
load_resource_info.resourceHandle = 1; load_resource_info.resourceHandle = ResourceMapping::loaded_resource;
KrMoveToBundleInfo move_to_bundle_info = {}; KrMoveToBundleInfo move_to_bundle_info = {};
move_to_bundle_info.sType = KR_STRUCTURE_TYPE_MOVE_TO_BUNDLE; move_to_bundle_info.sType = KR_STRUCTURE_TYPE_MOVE_TO_BUNDLE;
move_to_bundle_info.bundleHandle = 0; move_to_bundle_info.bundleHandle = ResourceMapping::output_bundle;
char* output_bundle = nullptr; char* output_bundle = nullptr;
bool compile_shaders = false;
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc && !failed; i++) {
char *arg = argv[i]; char *arg = argv[i];
if (arg[0] == '-') { if (arg[0] == '-') {
continue; continue;
@@ -50,6 +58,9 @@ int main( int argc, char *argv[] )
case 'o': case 'o':
output_bundle = arg; output_bundle = arg;
break; break;
case 'c':
compile_shaders = true;
break;
default: default:
printf("Unknown command: -%c\n", command); printf("Unknown command: -%c\n", command);
break; break;
@@ -62,31 +73,49 @@ int main( int argc, char *argv[] )
res = KrLoadResource(&load_resource_info); res = KrLoadResource(&load_resource_info);
if (res != KR_SUCCESS) { if (res != KR_SUCCESS) {
printf("[FAIL] (KrLoadResource)\n"); printf("[FAIL] (KrLoadResource)\n");
failed = true;
continue; continue;
} }
move_to_bundle_info.resourceHandle = 1; move_to_bundle_info.resourceHandle = ResourceMapping::loaded_resource;
res = KrMoveToBundle(&move_to_bundle_info); res = KrMoveToBundle(&move_to_bundle_info);
if (res != KR_SUCCESS) { if (res != KR_SUCCESS) {
printf("[FAIL] (KrMoveToBundle)\n"); printf("[FAIL] (KrMoveToBundle)\n");
failed = true;
continue; continue;
} }
printf("[GOOD]\n"); printf("[GOOD]\n");
} }
if (output_bundle) { if (compile_shaders && !failed) {
printf("Compiling Shaders...\n");
KrCompileAllShadersInfo compile_all_shaders_info = {};
compile_all_shaders_info.sType = KR_STRUCTURE_TYPE_COMPILE_ALL_SHADERS;
compile_all_shaders_info.logHandle = ResourceMapping::shader_compile_log;
res = KrCompileAllShaders(&compile_all_shaders_info);
if (res != KR_SUCCESS) {
printf("[FAIL] (Error %i)\n", res);
failed = true;
}
else {
printf("[GOOD]\n");
}
}
if (output_bundle && !failed) {
printf("Bundling %s... ", output_bundle); printf("Bundling %s... ", output_bundle);
KrSaveResourceInfo save_resource_info = {}; KrSaveResourceInfo save_resource_info = {};
save_resource_info.sType = KR_STRUCTURE_TYPE_SAVE_RESOURCE; save_resource_info.sType = KR_STRUCTURE_TYPE_SAVE_RESOURCE;
save_resource_info.resourceHandle = 0; save_resource_info.resourceHandle = ResourceMapping::output_bundle;
save_resource_info.pResourcePath = output_bundle; save_resource_info.pResourcePath = output_bundle;
res = KrSaveResource(&save_resource_info); res = KrSaveResource(&save_resource_info);
if (res != KR_SUCCESS) { if (res != KR_SUCCESS) {
printf("[FAIL] (Error %i)\n", res); printf("[FAIL] (Error %i)\n", res);
failed = true;
} else { } else {
printf("[GOOD]\n"); printf("[GOOD]\n");
} }
} }
KrShutdown(); KrShutdown();
return 0; return failed ? 1 : 0;
} }