Removed shader compiler to external executable #443
Binary file not shown.
|
@ -21,10 +21,11 @@ echo "N - dotnet"
|
|||
echo "O - tinyddsloader"
|
||||
echo "P - fmod"
|
||||
echo "Q - vswhere"
|
||||
echo "R - ShaderCompiler"
|
||||
echo ---------------------------------------------------
|
||||
echo.
|
||||
|
||||
choice /C ABCDEFGHIJKLMNOPQ
|
||||
choice /C ABCDEFGHIJKLMNOPQR
|
||||
set _e=%ERRORLEVEL%
|
||||
|
||||
if %_e%==1 goto VMA
|
||||
|
@ -44,6 +45,7 @@ if %_e%==14 goto dotnet
|
|||
if %_e%==15 goto tinyddsloader
|
||||
if %_e%==16 goto fmod
|
||||
if %_e%==17 goto vswhere
|
||||
if %_e%==18 goto ShaderCompiler
|
||||
|
||||
:VMA
|
||||
echo -----------------------VMA----------------------------
|
||||
|
@ -163,6 +165,13 @@ echo -----------------------vswhere----------------------------
|
|||
rmdir "Dependencies/vswhere" /S /Q
|
||||
mkdir "Dependencies/vswhere"
|
||||
powershell -Command "& {wget https://github.com/microsoft/vswhere/releases/download/3.1.1/vswhere.exe -OutFile "Dependencies/vswhere/vswhere.exe"}"
|
||||
if %_e%==17 (goto:done) else (goto:ShaderCompiler)
|
||||
|
||||
:ShaderCompiler
|
||||
echo ------------------ShaderCompiler------------------
|
||||
rmdir "Dependencies/ShaderCompiler" /S /Q
|
||||
mkdir "Dependencies/ShaderCompiler"
|
||||
git clone https://github.com/SHADE-DP/ShaderCompiler.git "Dependencies/ShaderCompiler"
|
||||
|
||||
:done
|
||||
echo DONE!
|
||||
|
|
|
@ -17,4 +17,5 @@ IncludeDir["VULKAN"] = "$(VULKAN_SDK)"
|
|||
IncludeDir["dotnet"] = "%{wks.location}\\Dependencies\\dotnet"
|
||||
IncludeDir["tinyddsloader"] = "%{wks.location}\\Dependencies\\tinyddsloader"
|
||||
IncludeDir["fmod"] = "%{wks.location}\\Dependencies\\fmod"
|
||||
IncludeDir["vswhere"] = "%{wks.location}\\Dependencies\\vswhere"
|
||||
IncludeDir["vswhere"] = "%{wks.location}\\Dependencies\\vswhere"
|
||||
IncludeDir["ShaderCompiler"] = "%{wks.location}\\Dependencies\\ShaderCompiler"
|
|
@ -67,7 +67,6 @@ project "SHADE_Engine"
|
|||
"vulkan-1.lib",
|
||||
"SDL2.lib",
|
||||
"SDL2main.lib",
|
||||
"shaderc_shared.lib",
|
||||
"shlwapi.lib"
|
||||
}
|
||||
|
||||
|
@ -120,9 +119,6 @@ project "SHADE_Engine"
|
|||
filter "configurations:Debug"
|
||||
postbuildcommands
|
||||
{
|
||||
"xcopy /r /y /q \"%{IncludeDir.ModelCompiler}\\bin\\Debug\\assimp-vc142-mtd.dll\" \"$(OutDir)\"",
|
||||
"xcopy /r /y /q \"%{IncludeDir.ModelCompiler}\\bin\\Debug\\ModelCompiler.exe\" \"$(OutDir)\"",
|
||||
"xcopy /r /y /q \"%{IncludeDir.FontCompiler}\\bin\\Debug\\FontCompiler.exe\" \"$(OutDir)\"",
|
||||
"xcopy /r /y /q \"%{IncludeDir.fmod}\\lib\\fmodL.dll\" \"$(OutDir)\"",
|
||||
"xcopy /r /y /q \"%{IncludeDir.fmod}\\lib\\fmodstudioL.dll\" \"$(OutDir)\"",
|
||||
"xcopy /r /y /q \"%{IncludeDir.vswhere}\\vswhere.exe\" \"$(OutDir)\""
|
||||
|
@ -131,9 +127,6 @@ project "SHADE_Engine"
|
|||
filter "configurations:Release"
|
||||
postbuildcommands
|
||||
{
|
||||
"xcopy /r /y /q \"%{IncludeDir.ModelCompiler}\\bin\\Release\\assimp-vc142-mt.dll\" \"$(OutDir)\"",
|
||||
"xcopy /r /y /q \"%{IncludeDir.ModelCompiler}\\bin\\Release\\ModelCompiler.exe\" \"$(OutDir)\"",
|
||||
"xcopy /r /y /q \"%{IncludeDir.FontCompiler}\\bin\\Release\\FontCompiler.exe\" \"$(OutDir)\"",
|
||||
"xcopy /r /y /q \"%{IncludeDir.fmod}\\lib\\fmod.dll\" \"$(OutDir)\"",
|
||||
"xcopy /r /y /q \"%{IncludeDir.fmod}\\lib\\fmodstudio.dll\" \"$(OutDir)\"",
|
||||
"xcopy /r /y /q \"%{IncludeDir.vswhere}\\vswhere.exe\" \"$(OutDir)\""
|
||||
|
@ -147,12 +140,6 @@ project "SHADE_Engine"
|
|||
"xcopy /r /y /q \"%{IncludeDir.fmod}\\lib\\fmodstudio.dll\" \"$(OutDir)\""
|
||||
}
|
||||
|
||||
filter "configurations:Publish"
|
||||
postbuildcommands
|
||||
{
|
||||
--"xcopy /r /y /q \"%{IncludeDir.assimp}\\bin\\Release\\assimp-vc142-mt.dll\" \"$(OutDir)\""
|
||||
}
|
||||
|
||||
warnings 'Extra'
|
||||
|
||||
filter "configurations:Debug"
|
||||
|
|
|
@ -1,164 +0,0 @@
|
|||
/*************************************************************************//**
|
||||
* \file SHShaderSourceCompiler.cpp
|
||||
* \author Loh Xiao Qi
|
||||
* \date 23 10 2022
|
||||
* \brief
|
||||
*
|
||||
* Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||
* disclosure of this file or its contents without the prior written consent
|
||||
* of DigiPen Institute of Technology is prohibited.
|
||||
*****************************************************************************/
|
||||
#include "SHpch.h"
|
||||
#include "SHShaderSourceCompiler.h"
|
||||
#include "shaderc/shaderc.hpp"
|
||||
#include "Events/SHEventManager.hpp"
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
std::string SHShaderSourceCompiler::CompileShaderSourceToBinary(AssetPath path, SHShaderAsset const& data) noexcept
|
||||
{
|
||||
std::string newPath{ path.string() };
|
||||
newPath = newPath.substr(0, newPath.find_last_of('.'));
|
||||
newPath += SHADER_BUILT_IN_EXTENSION.data();
|
||||
|
||||
std::ofstream file{ newPath, std::ios::binary | std::ios::out | std::ios::trunc };
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(& data.shaderType), sizeof(uint8_t)
|
||||
);
|
||||
|
||||
size_t const byteCount = sizeof(uint32_t) * data.spirvBinary.size();
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(&byteCount), sizeof(size_t)
|
||||
);
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(data.spirvBinary.data()), byteCount
|
||||
);
|
||||
|
||||
file.close();
|
||||
|
||||
return newPath;
|
||||
}
|
||||
|
||||
SHShaderAsset const* SHShaderSourceCompiler::CompileShaderSourceToMemory(std::string const& data, std::string const& name, SH_SHADER_TYPE type) noexcept
|
||||
{
|
||||
// shaderc compiler
|
||||
shaderc::Compiler compiler;
|
||||
shaderc::CompileOptions options;
|
||||
|
||||
options.AddMacroDefinition("MY_DEFINE", "1");
|
||||
|
||||
//TODO: Check if we need optimisation levels when compiling into spirv
|
||||
// Set optimization levels
|
||||
//if (opLevel != shaderc_optimization_level_zero)
|
||||
// options.SetOptimizationLevel(opLevel);
|
||||
|
||||
// Attempt to get the shaderc equivalent shader stage
|
||||
shaderc_shader_kind shaderKind;
|
||||
switch (type)
|
||||
{
|
||||
case SH_SHADER_TYPE::VERTEX:
|
||||
shaderKind = shaderc_shader_kind::shaderc_glsl_vertex_shader;
|
||||
break;
|
||||
case SH_SHADER_TYPE::FRAGMENT:
|
||||
shaderKind = shaderc_shader_kind::shaderc_glsl_fragment_shader;
|
||||
break;
|
||||
case SH_SHADER_TYPE::COMPUTE:
|
||||
shaderKind = shaderc_shader_kind::shaderc_glsl_compute_shader;
|
||||
break;
|
||||
default:
|
||||
shaderKind = shaderc_shader_kind::shaderc_glsl_vertex_shader;
|
||||
break;
|
||||
}
|
||||
|
||||
// Compile the shader and get the result
|
||||
shaderc::SpvCompilationResult compileResult = compiler.CompileGlslToSpv(data, shaderKind, name.c_str(), options);
|
||||
|
||||
if (compileResult.GetCompilationStatus() != shaderc_compilation_status_success)
|
||||
{
|
||||
SHLOG_ERROR("Shaderc failed to compile GLSL shader to binary | " + compileResult.GetErrorMessage());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto result = new SHShaderAsset();
|
||||
result->spirvBinary.resize(compileResult.end() - compileResult.begin());
|
||||
|
||||
std::ranges::copy(compileResult.begin(), compileResult.end(), result->spirvBinary.data());
|
||||
|
||||
result->name = name;
|
||||
result->shaderType = type;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
SH_SHADER_TYPE SHShaderSourceCompiler::GetShaderTypeFromFilename(std::string name) noexcept
|
||||
{
|
||||
for (auto i { 0 }; i < SHADER_TYPE_MAX_COUNT; ++i)
|
||||
{
|
||||
const auto& [SHADER_SUFFIX, SHADER_TYPE] = SHADER_IDENTIFIERS[i];
|
||||
if (name.find(SHADER_SUFFIX.data()) != std::string::npos)
|
||||
{
|
||||
return SHADER_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
return SH_SHADER_TYPE::INAVLID_TYPE;
|
||||
}
|
||||
|
||||
std::optional<AssetPath> SHShaderSourceCompiler::LoadAndCompileShader(AssetPath path) noexcept
|
||||
{
|
||||
auto type = GetShaderTypeFromFilename(path.filename().string());
|
||||
|
||||
if (type == SH_SHADER_TYPE::INAVLID_TYPE)
|
||||
{
|
||||
SHLOG_ERROR("Invalid filename for shaders, follow suffix in SHAssetMacros.h: {}", path.string());
|
||||
return {};
|
||||
}
|
||||
|
||||
path.make_preferred();
|
||||
|
||||
std::ifstream file{ path.string(), std::ios::in };
|
||||
|
||||
if (file.is_open())
|
||||
{
|
||||
std::stringstream stream;
|
||||
|
||||
stream << file.rdbuf();
|
||||
|
||||
std::string const content = stream.str();
|
||||
|
||||
auto data = CompileShaderSourceToMemory(content, path.filename().string(), type);
|
||||
|
||||
if (data == nullptr)
|
||||
{
|
||||
return{};
|
||||
}
|
||||
|
||||
return CompileShaderSourceToBinary(path, *data);
|
||||
}
|
||||
|
||||
SHLOG_ERROR("Unable to open shader file: {}", path.string());
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
std::optional<AssetPath> SHShaderSourceCompiler::CompileShaderFromString
|
||||
(std::string const& string, AssetPath path, SH_SHADER_TYPE type) noexcept
|
||||
{
|
||||
auto const data = CompileShaderSourceToMemory(string, path.filename().string(), type);
|
||||
|
||||
if (data == nullptr)
|
||||
{
|
||||
return{};
|
||||
}
|
||||
|
||||
return CompileShaderSourceToBinary(path, *data);
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
/*************************************************************************//**
|
||||
* \file SHShaderSourceCompiler.h
|
||||
* \author Loh Xiao Qi
|
||||
* \date 23 10 2022
|
||||
* \brief
|
||||
*
|
||||
* Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||
* disclosure of this file or its contents without the prior written consent
|
||||
* of DigiPen Institute of Technology is prohibited.
|
||||
*****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "Assets/SHAssetMacros.h"
|
||||
#include "Assets/Asset Types/SHShaderAsset.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
class SHShaderSourceCompiler
|
||||
{
|
||||
private:
|
||||
static std::string CompileShaderSourceToBinary(AssetPath path, SHShaderAsset const& data) noexcept;
|
||||
static SHShaderAsset const* CompileShaderSourceToMemory(std::string const& data, std::string const& name, SH_SHADER_TYPE type) noexcept;
|
||||
|
||||
static SH_SHADER_TYPE GetShaderTypeFromFilename(std::string name) noexcept;
|
||||
|
||||
public:
|
||||
static std::optional<AssetPath> LoadAndCompileShader(AssetPath path) noexcept;
|
||||
static std::optional<AssetPath> CompileShaderFromString
|
||||
(std::string const& string, AssetPath path, SH_SHADER_TYPE type) noexcept;
|
||||
};
|
||||
}
|
|
@ -78,6 +78,7 @@ constexpr std::string_view BUILT_IN_ASSET_ROOT{ "../../Built_In" };
|
|||
// COMPILER EXE
|
||||
constexpr std::string_view MODEL_COMPILER_EXE{ "ModelCompiler.exe" };
|
||||
constexpr std::string_view FONT_COMPILER_EXE{ "FontCompiler.exe" };
|
||||
constexpr std::string_view SHADER_COMPILER_EXE{ "ShaderCompiler.exe" };
|
||||
|
||||
// INTERNAL ASSET PATHS
|
||||
constexpr std::string_view SCENE_FOLDER{ "/Scenes/" };
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#include "Asset Types/SHAnimClipContainerAsset.h"
|
||||
|
||||
#include "Libraries/Compilers/SHTextureCompiler.h"
|
||||
#include "Libraries/Compilers/SHShaderSourceCompiler.h"
|
||||
|
||||
#include "Filesystem/SHFileSystem.h"
|
||||
#include <rttr/registration.h>
|
||||
|
@ -483,13 +482,13 @@ namespace SHADE
|
|||
auto const ext{ path.extension().string() };
|
||||
if (ext == GLSL_EXTENSION.data())
|
||||
{
|
||||
auto value { SHShaderSourceCompiler::LoadAndCompileShader(path) };
|
||||
if (!value.has_value())
|
||||
{
|
||||
SHLOG_ERROR("Shader compile failed: {}", path.string());
|
||||
return;
|
||||
}
|
||||
newPath = value.value();
|
||||
std::string command {SHADER_COMPILER_EXE.data()};
|
||||
command += " " + path.string();
|
||||
std::system(command.c_str());
|
||||
|
||||
std::string shaderPath = path.string().substr(0, path.string().find_last_of('.'));
|
||||
shaderPath += SHADER_BUILT_IN_EXTENSION;
|
||||
newPath = shaderPath;
|
||||
}
|
||||
else if (ext == GLTF_EXTENSION.data() || ext == FBX_EXTENSION.data())
|
||||
{
|
||||
|
|
|
@ -27,9 +27,9 @@ workspace "SHADE"
|
|||
group "Dependencies"
|
||||
include "Dependencies/FontCompiler/Dependencies/msdf"
|
||||
include "Dependencies/imgui"
|
||||
--include "Dependencies/tracy"
|
||||
include "Dependencies/yamlcpp"
|
||||
include "Dependencies/reactphysics3d"
|
||||
include "Dependencies/ModelCompiler"
|
||||
include "Dependencies/FontCompiler"
|
||||
include "Dependencies/ShaderCompiler"
|
||||
group ""
|
||||
|
|
Loading…
Reference in New Issue