update xmake
This commit is contained in:
parent
2120ebb7d2
commit
357f9005ff
147
engine/3rdparty/assimp/xmake.lua
vendored
147
engine/3rdparty/assimp/xmake.lua
vendored
@ -1,147 +0,0 @@
|
||||
package("assimp")
|
||||
set_homepage("https://assimp.org")
|
||||
set_description("Portable Open-Source library to import various well-known 3D model formats in a uniform manner")
|
||||
set_license("BSD-3-Clause")
|
||||
|
||||
set_urls("https://github.com/assimp/assimp/archive/refs/tags/$(version).zip",
|
||||
"https://github.com/assimp/assimp.git")
|
||||
add_versions("v5.4.0", "0f3698e9ba0110df0b636dbdd95706e7e28d443ff3dbaf5828926c23bfff778d")
|
||||
|
||||
if not is_host("windows") then
|
||||
add_extsources("pkgconfig::assimp")
|
||||
end
|
||||
|
||||
if is_plat("mingw") and is_subhost("msys") then
|
||||
add_extsources("pacman::assimp")
|
||||
elseif is_plat("linux") then
|
||||
add_extsources("pacman::assimp", "apt::libassimp-dev")
|
||||
elseif is_plat("macosx") then
|
||||
add_extsources("brew::assimp")
|
||||
end
|
||||
|
||||
add_configs("build_tools", {description = "Build the supplementary tools for Assimp.", default = false, type = "boolean"})
|
||||
add_configs("double_precision", {description = "Enable double precision processing.", default = false, type = "boolean"})
|
||||
add_configs("no_export", {description = "Disable Assimp's export functionality (reduces library size).", default = false, type = "boolean"})
|
||||
add_configs("android_jniiosysystem", {description = "Enable Android JNI IOSystem support.", default = false, type = "boolean"})
|
||||
add_configs("asan", {description = "Enable AddressSanitizer.", default = false, type = "boolean"})
|
||||
add_configs("ubsan", {description = "Enable Undefined Behavior sanitizer.", default = false, type = "boolean"})
|
||||
|
||||
add_deps("cmake", "minizip", "zlib")
|
||||
|
||||
if is_plat("windows") then
|
||||
add_syslinks("advapi32")
|
||||
end
|
||||
|
||||
if on_check then
|
||||
on_check("android", function (package)
|
||||
import("core.tool.toolchain")
|
||||
local ndk = toolchain.load("ndk", {plat = package:plat(), arch = package:arch()})
|
||||
local ndk_sdkver = ndk:config("ndk_sdkver")
|
||||
assert(ndk_sdkver and tonumber(ndk_sdkver) >= 26, "package(assimp): need ndk api level >= 26 for android")
|
||||
end)
|
||||
end
|
||||
|
||||
on_load(function (package)
|
||||
if not package:gitref() then
|
||||
if package:version():le("5.1.0") then
|
||||
package:add("deps", "irrxml")
|
||||
end
|
||||
if package:version():eq("5.3.0") then
|
||||
package:add("deps", "utfcpp")
|
||||
package:add("defines", "ASSIMP_USE_HUNTER")
|
||||
end
|
||||
end
|
||||
if package:is_plat("linux", "macosx") and package:config("shared") then
|
||||
package:add("links", "assimp" .. (package:is_debug() and "d" or ""))
|
||||
end
|
||||
end)
|
||||
|
||||
on_install(function (package)
|
||||
if package:is_plat("android") then
|
||||
import("core.tool.toolchain")
|
||||
local ndk = toolchain.load("ndk", {plat = package:plat(), arch = package:arch()})
|
||||
local ndk_sdkver = ndk:config("ndk_sdkver")
|
||||
assert(ndk_sdkver and tonumber(ndk_sdkver) >= 26, "package(assimp): need ndk api level >= 26 for android")
|
||||
end
|
||||
|
||||
local configs = {"-DASSIMP_BUILD_SAMPLES=OFF",
|
||||
"-DASSIMP_BUILD_TESTS=OFF",
|
||||
"-DASSIMP_BUILD_DOCS=OFF",
|
||||
"-DASSIMP_BUILD_FRAMEWORK=OFF",
|
||||
"-DASSIMP_INSTALL_PDB=ON",
|
||||
"-DASSIMP_INJECT_DEBUG_POSTFIX=ON",
|
||||
"-DASSIMP_BUILD_ZLIB=OFF",
|
||||
"-DSYSTEM_IRRXML=ON",
|
||||
"-DASSIMP_WARNINGS_AS_ERRORS=OFF"}
|
||||
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
|
||||
|
||||
local function add_config_arg(config_name, cmake_name)
|
||||
table.insert(configs, "-D" .. cmake_name .. "=" .. (package:config(config_name) and "ON" or "OFF"))
|
||||
end
|
||||
add_config_arg("shared", "BUILD_SHARED_LIBS")
|
||||
add_config_arg("double_precision", "ASSIMP_DOUBLE_PRECISION")
|
||||
add_config_arg("no_export", "ASSIMP_NO_EXPORT")
|
||||
add_config_arg("asan", "ASSIMP_ASAN")
|
||||
add_config_arg("ubsan", "ASSIMP_UBSAN")
|
||||
|
||||
if package:is_plat("android") then
|
||||
add_config_arg("android_jniiosysystem", "ASSIMP_ANDROID_JNIIOSYSTEM")
|
||||
end
|
||||
if package:is_plat("windows", "linux", "macosx", "mingw") then
|
||||
add_config_arg("build_tools", "ASSIMP_BUILD_ASSIMP_TOOLS")
|
||||
else
|
||||
table.insert(configs, "-DASSIMP_BUILD_ASSIMP_TOOLS=OFF")
|
||||
end
|
||||
|
||||
-- ASSIMP_WARNINGS_AS_ERRORS maybe does not work for some old versions
|
||||
for _, cmakefile in ipairs(table.join("CMakeLists.txt", os.files("**/CMakeLists.txt"))) do
|
||||
if package:is_plat("windows") then
|
||||
io.replace(cmakefile, "/W4 /WX", "", {plain = true})
|
||||
else
|
||||
io.replace(cmakefile, "-Werror", "", {plain = true})
|
||||
end
|
||||
end
|
||||
-- fix cmake_install failed
|
||||
if not package:gitref() and package:version():ge("v5.3.0") and package:is_plat("windows") and package:is_debug() then
|
||||
io.replace("code/CMakeLists.txt", "IF(GENERATOR_IS_MULTI_CONFIG)", "IF(TRUE)", {plain = true})
|
||||
end
|
||||
if package:is_plat("mingw") and package:version():lt("v5.1.5") then
|
||||
-- CMAKE_COMPILER_IS_MINGW has been removed: https://github.com/assimp/assimp/pull/4311
|
||||
io.replace("CMakeLists.txt", "CMAKE_COMPILER_IS_MINGW", "MINGW", {plain = true})
|
||||
end
|
||||
|
||||
-- Assimp CMakeLists doesn't find minizip on Windows
|
||||
local packagedeps
|
||||
if package:is_plat("windows") then
|
||||
local minizip = package:dep("minizip")
|
||||
if minizip and not minizip:is_system() then
|
||||
packagedeps = table.join2(packagedeps or {}, "minizip")
|
||||
end
|
||||
end
|
||||
|
||||
local zlib = package:dep("zlib")
|
||||
if zlib and not zlib:is_system() then
|
||||
local fetchinfo = zlib:fetch({external = false})
|
||||
if fetchinfo then
|
||||
local includedirs = fetchinfo.includedirs or fetchinfo.sysincludedirs
|
||||
if includedirs and #includedirs > 0 then
|
||||
table.insert(configs, "-DZLIB_INCLUDE_DIR=" .. table.concat(includedirs, " "))
|
||||
end
|
||||
local libfiles = fetchinfo.libfiles
|
||||
if libfiles then
|
||||
table.insert(configs, "-DZLIB_LIBRARY=" .. table.concat(libfiles, " "))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
import("package.tools.cmake").install(package, configs, {packagedeps = packagedeps})
|
||||
|
||||
-- copy pdb
|
||||
if package:is_plat("windows") then
|
||||
if package:config("shared") then
|
||||
os.trycp(path.join(package:buildir(), "bin", "**.pdb"), package:installdir("bin"))
|
||||
else
|
||||
os.trycp(path.join(package:buildir(), "lib", "**.pdb"), package:installdir("lib"))
|
||||
end
|
||||
end
|
||||
end)
|
||||
42
engine/3rdparty/json/xmake.lua
vendored
42
engine/3rdparty/json/xmake.lua
vendored
@ -1,42 +0,0 @@
|
||||
package("nlohmann_json")
|
||||
|
||||
set_homepage("https://nlohmann.github.io/json/")
|
||||
set_description("JSON for Modern C++")
|
||||
set_license("MIT")
|
||||
|
||||
add_urls("https://github.com/nlohmann/json/archive/$(version).tar.gz",
|
||||
"https://github.com/nlohmann/json.git")
|
||||
add_versions("v3.11.3", "0d8ef5af7f9794e3263480193c491549b2ba6cc74bb018906202ada498a79406")
|
||||
add_versions("v3.11.2", "d69f9deb6a75e2580465c6c4c5111b89c4dc2fa94e3a85fcd2ffcd9a143d9273")
|
||||
add_versions("v3.10.5", "5daca6ca216495edf89d167f808d1d03c4a4d929cef7da5e10f135ae1540c7e4")
|
||||
add_versions("v3.10.0", "eb8b07806efa5f95b349766ccc7a8ec2348f3b2ee9975ad879259a371aea8084")
|
||||
add_versions("v3.9.1", "4cf0df69731494668bdd6460ed8cb269b68de9c19ad8c27abc24cd72605b2d5b")
|
||||
|
||||
add_configs("cmake", {description = "Use cmake buildsystem", default = false, type = "boolean"})
|
||||
|
||||
if is_plat("mingw") and is_subhost("msys") then
|
||||
add_extsources("pacman::nlohmann-json")
|
||||
elseif is_plat("linux") then
|
||||
add_extsources("pacman::nlohmann-json", "apt::nlohmann-json3-dev")
|
||||
elseif is_plat("macosx") then
|
||||
add_extsources("brew::nlohmann-json")
|
||||
end
|
||||
|
||||
on_load(function (package)
|
||||
if package:config("cmake") then
|
||||
package:add("deps", "cmake")
|
||||
end
|
||||
end)
|
||||
|
||||
on_install(function (package)
|
||||
if package:config("cmake") then
|
||||
local configs = {"-DJSON_BuildTests=OFF"}
|
||||
import("package.tools.cmake").install(package, configs)
|
||||
else
|
||||
if os.isdir("include") then
|
||||
os.cp("include", package:installdir())
|
||||
else
|
||||
os.cp("*", package:installdir("include"))
|
||||
end
|
||||
end
|
||||
end)
|
||||
45
engine/3rdparty/tinyobjloader/xmake.lua
vendored
45
engine/3rdparty/tinyobjloader/xmake.lua
vendored
@ -1,45 +0,0 @@
|
||||
package("tinyobjloader")
|
||||
|
||||
set_homepage("https://github.com/tinyobjloader/tinyobjloader")
|
||||
set_description("Tiny but powerful single file wavefront obj loader")
|
||||
set_license("MIT")
|
||||
|
||||
add_urls("https://github.com/tinyobjloader/tinyobjloader/archive/$(version).tar.gz")
|
||||
add_urls("https://github.com/tinyobjloader/tinyobjloader.git")
|
||||
add_versions("v1.0.7", "b9d08b675ba54b9cb00ffc99eaba7616d0f7e6f6b8947a7e118474e97d942129")
|
||||
add_versions("v2.0.0rc10", "e1bc2e5547b562d33ca4a90b581717984a70d58113d83208dbc97c82e137b9fe")
|
||||
|
||||
add_configs("double", {description = "Use double precision floating numbers.", default = false, type = "boolean"})
|
||||
if is_plat("windows") then
|
||||
add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
|
||||
end
|
||||
|
||||
on_load(function (package)
|
||||
if package:config("double") then
|
||||
package:add("defines", "TINYOBJLOADER_USE_DOUBLE")
|
||||
end
|
||||
end)
|
||||
|
||||
on_install("macosx", "linux", "windows", "mingw", "android", "iphoneos", function (package)
|
||||
io.writefile("xmake.lua", string.format([[
|
||||
add_rules("mode.debug", "mode.release")
|
||||
add_rules("utils.install.cmake_importfiles")
|
||||
target("tinyobjloader")
|
||||
set_kind("$(kind)")
|
||||
%s
|
||||
add_files("tiny_obj_loader.cc")
|
||||
add_headerfiles("tiny_obj_loader.h")
|
||||
]], package:config("double") and "add_defines(\"TINYOBJLOADER_USE_DOUBLE\")" or ""))
|
||||
import("package.tools.xmake").install(package)
|
||||
end)
|
||||
|
||||
on_test(function (package)
|
||||
assert(package:check_cxxsnippets({test = [[
|
||||
#include <vector>
|
||||
void test() {
|
||||
tinyobj::attrib_t attrib;
|
||||
std::vector<tinyobj::shape_t> shapes;
|
||||
std::vector<tinyobj::material_t> materials;
|
||||
}
|
||||
]]}, {configs = {languages = "c++14"}, includes = "tiny_obj_loader.h"}))
|
||||
end)
|
||||
6
engine/3rdparty/xmake.lua
vendored
6
engine/3rdparty/xmake.lua
vendored
@ -1,8 +1,6 @@
|
||||
|
||||
includes("**/xmake.lua")
|
||||
add_requires("spdlog")
|
||||
add_requires("tinyobjloader")
|
||||
add_requires("vulkansdk")
|
||||
add_requires("assimp v5.4.0")
|
||||
add_requires("nlohmann_json")
|
||||
add_requires("assimp","nlohmann_json")
|
||||
add_requires("benchmark")
|
||||
add_requires("vulkansdk", "glslang","spirv-cross", "spirv-tools", "shaderc")
|
||||
27
engine/3rdparty/zlib/include/meta/hash.h
vendored
Normal file
27
engine/3rdparty/zlib/include/meta/hash.h
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
#include <string_view>
|
||||
namespace meta
|
||||
{
|
||||
template <class T>
|
||||
constexpr inline void hash_combine(size_t& seed, const T& v) noexcept
|
||||
{
|
||||
std::hash<T> hasher;
|
||||
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
}
|
||||
constexpr inline size_t string_hash(std::string_view str) noexcept
|
||||
{
|
||||
constexpr size_t fnv_offset_basis = 0xcbf29ce484222325;
|
||||
constexpr size_t fnv_prime = 0x100000001b3;
|
||||
|
||||
auto hash = fnv_offset_basis;
|
||||
for (auto& elem : str)
|
||||
{
|
||||
hash *= fnv_prime;
|
||||
hash ^= elem;
|
||||
}
|
||||
hash *= fnv_prime;
|
||||
hash ^= 0;
|
||||
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
@ -6,12 +6,6 @@ namespace engineapi
|
||||
{
|
||||
using std::string;
|
||||
using std::string_view;
|
||||
template <class T>
|
||||
constexpr inline void hash_combine(size_t& seed, const T& v) noexcept
|
||||
{
|
||||
std::hash<T> hasher;
|
||||
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
}
|
||||
struct Guid
|
||||
{
|
||||
UPROPERTY({})
|
||||
@ -84,19 +78,4 @@ namespace engineapi
|
||||
}
|
||||
};
|
||||
}
|
||||
// Specialize std::hash
|
||||
namespace std
|
||||
{
|
||||
template<> struct hash<engineapi::Guid>
|
||||
{
|
||||
size_t operator()(const engineapi::Guid& guid) const noexcept
|
||||
{
|
||||
const size_t* p = reinterpret_cast<const size_t*>(&guid);
|
||||
size_t seed = 0;
|
||||
engineapi::hash_combine(seed, p[0]);
|
||||
engineapi::hash_combine(seed, p[1]);
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
}
|
||||
#include "guid_gen.inl"
|
||||
#include "guid.inl"
|
||||
16
engine/src/engine/asset/res/guid.inl
Normal file
16
engine/src/engine/asset/res/guid.inl
Normal file
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include "meta/hash.h"
|
||||
namespace std
|
||||
{
|
||||
template<> struct hash<engineapi::Guid>
|
||||
{
|
||||
size_t operator()(const engineapi::Guid& guid) const noexcept
|
||||
{
|
||||
const size_t* p = reinterpret_cast<const size_t*>(&guid);
|
||||
size_t seed = 0;
|
||||
meta::hash_combine(seed, p[0]);
|
||||
meta::hash_combine(seed, p[1]);
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -6,17 +6,26 @@ namespace engineapi
|
||||
{
|
||||
struct SerializedMeta
|
||||
{
|
||||
UPROPERTY({})
|
||||
Guid guid;
|
||||
UPROPERTY({})
|
||||
string name;
|
||||
UPROPERTY({})
|
||||
string t_hash{};
|
||||
UPROPERTY({})
|
||||
string metadata;
|
||||
};
|
||||
struct ResourceBundle;
|
||||
|
||||
struct MetaBundle
|
||||
{
|
||||
UPROPERTY({})
|
||||
vector<SerializedMeta> metadatas;
|
||||
|
||||
MetaBundle() = default;
|
||||
|
||||
template<typename T>
|
||||
const SerializedMeta* FetchMeta() const;
|
||||
};
|
||||
}
|
||||
#include "meta_bundle.inl"
|
||||
#include "meta_bundle_gen.inl"
|
||||
@ -1,6 +1,15 @@
|
||||
#pragma once
|
||||
#include "meta_bundle.h"
|
||||
namespace engineapi
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
inline const SerializedMeta* MetaBundle::FetchMeta() const
|
||||
{
|
||||
string_view name = type_name<T>().View();
|
||||
for (auto& elem : metadatas)
|
||||
{
|
||||
if (string_view(elem.t_hash) == name)
|
||||
return &elem;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@ -2,7 +2,6 @@
|
||||
#include <string>
|
||||
#include "zstd/table.h"
|
||||
#include "UTemplate/Type.hpp"
|
||||
#include <filesystem>
|
||||
namespace engineapi
|
||||
{
|
||||
using std::string;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#include "resource_bundle.inl"
|
||||
#include "resource_bundle.h"
|
||||
|
||||
namespace engineapi
|
||||
{
|
||||
|
||||
@ -7,6 +7,11 @@ namespace engineapi
|
||||
struct ResourceBundle
|
||||
{
|
||||
ResourceBundle() = default;
|
||||
template<typename Res> // conversion from single resource
|
||||
ResourceBundle(const RscHandle<Res>& handle);
|
||||
// will reshuffle vector and invalidate span, but you shouldn't be accessing vector directly anyway so this is ok
|
||||
template<typename T> void Add(RscHandle<T> handle);
|
||||
|
||||
private:
|
||||
struct sub_array { short index = 0, count = 0; };
|
||||
|
||||
@ -14,3 +19,4 @@ namespace engineapi
|
||||
array<sub_array, ResourceCount> subarrays;
|
||||
};
|
||||
}
|
||||
#include "resource_bundle.inl"
|
||||
@ -1,7 +1,27 @@
|
||||
#pragma once
|
||||
#include "resource_bundle.h"
|
||||
|
||||
namespace engineapi
|
||||
{
|
||||
template<typename Res>
|
||||
inline ResourceBundle::ResourceBundle(const RscHandle<Res>& handle)
|
||||
{
|
||||
Add(handle);
|
||||
}
|
||||
template<typename T>
|
||||
inline void ResourceBundle::Add(RscHandle<T> handle)
|
||||
{
|
||||
auto& sub_arr = subarrays[ResourceID<T>];
|
||||
auto new_ind = sub_arr.index + sub_arr.count++;
|
||||
|
||||
|
||||
// make space for new resource
|
||||
handles.emplace_back();
|
||||
std::move_backward(handles.data() + new_ind, handles.data() + handles.size() - 1, handles.data() + handles.size());
|
||||
|
||||
// assign new resource
|
||||
handles[new_ind] = handle;
|
||||
|
||||
// push back all subsequent resources
|
||||
for (auto& elem : span<sub_array>{ &sub_arr + 1, subarrays.data() + subarrays.size() })
|
||||
++elem.index;
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,40 @@
|
||||
#pragma once
|
||||
#include "type.h"
|
||||
namespace engineapi {
|
||||
template<typename Res>
|
||||
struct RscHandle;
|
||||
template<typename Res>
|
||||
class Resource
|
||||
{
|
||||
public:
|
||||
using BaseResource = Res;
|
||||
|
||||
RscHandle<Res> GetHandle() const { return mHandle; }
|
||||
Resource() = default;
|
||||
private:
|
||||
RscHandle<Res> mHandle;
|
||||
|
||||
friend class ResourceManager;
|
||||
};
|
||||
using Resources = std::tuple<
|
||||
class Scene
|
||||
, class Shader
|
||||
>;
|
||||
template<typename Resource>
|
||||
constexpr auto ResourceID = index_in_tuple_v<Resource, Resources>;
|
||||
concept is_resource_v = requires { typename Resource::BaseResource; };
|
||||
|
||||
template<typename Resource, typename Enable = void>
|
||||
struct ResourceID_impl {
|
||||
static constexpr auto value() { return index_in_tuple_v<Resource, Resources>; }
|
||||
};
|
||||
|
||||
template<typename Resource>
|
||||
struct ResourceID_impl<Resource, std::enable_if_t<is_resource_v<Resource>>> {
|
||||
static constexpr auto value() { return index_in_tuple_v<typename Resource::BaseResource, Resources>; }
|
||||
};
|
||||
|
||||
template<typename Resource>
|
||||
constexpr auto ResourceID = ResourceID_impl<Resource>::value();
|
||||
|
||||
constexpr auto ResourceCount = std::tuple_size_v<Resources>;
|
||||
}
|
||||
@ -13,9 +13,6 @@ namespace engineapi
|
||||
|
||||
size_t GenericResourceHandle::resource_id() const
|
||||
{
|
||||
return std::visit([](const auto& handle)
|
||||
{
|
||||
return ResourceID<typename std::decay_t<decltype(handle)>::Resource>;
|
||||
}, *this);
|
||||
return std::visit([](const auto& handle) { return handle.RscID(); }, *this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,10 +7,10 @@ namespace engineapi
|
||||
template<typename Res>
|
||||
struct RscHandle
|
||||
{
|
||||
using Resource = Res;
|
||||
Guid guid{};
|
||||
|
||||
constexpr size_t RscID()const { return ResourceID<Res>; }
|
||||
constexpr RscHandle() noexcept = default;
|
||||
constexpr RscHandle(const Guid& guid) noexcept : guid{ guid } {}
|
||||
};
|
||||
|
||||
struct GenericResourceHandle
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
#include "meta/variant.inl"
|
||||
#include "meta/tuple.inl"
|
||||
#include "meta/comparable.inl"
|
||||
#include "meta/hash.h"
|
||||
#include "zstd/span.h"
|
||||
#include "zstd/table.h"
|
||||
#include <vector>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#include "resource_manager.inl"
|
||||
#include "resource_manager.h"
|
||||
#include "file_manager.h"
|
||||
#include "yaml/yaml.h"
|
||||
namespace engineapi {
|
||||
|
||||
@ -39,6 +39,13 @@ namespace engineapi {
|
||||
auto& GetTable() {
|
||||
return *reinterpret_cast<ResourceStorage<Res>*> (mResourceTable[ResourceID<Res>].get());
|
||||
}
|
||||
template<typename Res, typename ... Args>
|
||||
[[nodiscard]] RscHandle<Res> LoaderEmplaceResource(Args&& ... args) {
|
||||
return LoaderEmplaceResource<Res>(Guid::Make(), args...);
|
||||
};
|
||||
template<typename Res, typename ... Args>
|
||||
[[nodiscard]] RscHandle<Res> LoaderEmplaceResource(Guid, Args&& ... args);
|
||||
|
||||
IFileLoader* GetLoader(Name extension);
|
||||
template<typename FLoader, typename ... Args>
|
||||
FLoader& RegisterLoader(Name ext, Args&& ... args);
|
||||
@ -53,7 +60,7 @@ namespace engineapi {
|
||||
{
|
||||
bool dirty{ false };
|
||||
std::optional<string> path{ std::nullopt };
|
||||
shared_ptr<R> resource; // note: make atomic
|
||||
R* resource;
|
||||
|
||||
// meta data
|
||||
shared_ptr<void> userdata;
|
||||
@ -62,3 +69,4 @@ namespace engineapi {
|
||||
bool valid() const { return s_cast<bool>(resource); }
|
||||
};
|
||||
}
|
||||
#include "resource_manager.inl"
|
||||
@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include "resource_manager.h"
|
||||
namespace engineapi {
|
||||
class IFileLoader
|
||||
{
|
||||
@ -34,6 +33,18 @@ namespace engineapi {
|
||||
|
||||
using ResourceHelper = ResourceManager_detail<Resources>;
|
||||
}
|
||||
template<typename Res, typename ...Args>
|
||||
inline RscHandle<Res> ResourceManager::LoaderEmplaceResource(Guid guid, Args && ...args)
|
||||
{
|
||||
auto& table = GetTable<Res>();
|
||||
auto& control_block = table[guid]; // don't care just replace
|
||||
// attempt to put on other thread
|
||||
{
|
||||
control_block.resource = new Res(std::forward<Args>(args)...);
|
||||
control_block.resource->mHandle = RscHandle<Res>{ guid };
|
||||
}
|
||||
return RscHandle<Res>{guid};
|
||||
}
|
||||
template<typename FLoader, typename ...Args>
|
||||
inline FLoader& ResourceManager::RegisterLoader(Name ext, Args && ...args)
|
||||
{
|
||||
|
||||
@ -1,2 +1,3 @@
|
||||
#pragma once
|
||||
#include "asset/render/asset_struct.h"
|
||||
#include "asset/res/resource_handle.h"
|
||||
@ -6,7 +6,7 @@ namespace engineapi {
|
||||
Material::Material(string_view name, uint32_t flags)
|
||||
:Asset(name, flags)
|
||||
{
|
||||
mShader = new Shader(name, flags);
|
||||
//mShader = new Shader(name, flags);
|
||||
}
|
||||
Material::~Material()
|
||||
{
|
||||
|
||||
@ -2,27 +2,19 @@
|
||||
#include "asset/file_manager.h"
|
||||
#include "../renderapi.h"
|
||||
namespace engineapi {
|
||||
Shader::Shader(string_view name, uint32_t flags)
|
||||
:Asset(name, flags)
|
||||
Shader::Shader()
|
||||
{
|
||||
BeginLoad();
|
||||
|
||||
}
|
||||
Shader::~Shader()
|
||||
{
|
||||
}
|
||||
void Shader::BeginLoad()
|
||||
{
|
||||
json data = FileManager::LoadJsonFile(PackagePath::AbsolutePath(mName) + ".json");
|
||||
RenderAPI::GetSingletonPtr()->LoadShader(this);
|
||||
//ShaderProperty
|
||||
//mInfo.vertProperties.baseProperties.push_back
|
||||
}
|
||||
vector<char> Shader::GetVertData()
|
||||
{
|
||||
return FileManager::LoadBinaryFile(PackagePath::AbsolutePath(mName) + ".vert.spv");
|
||||
return FileManager::LoadBinaryFile(PackagePath::AbsolutePath("") + ".vert.spv");
|
||||
}
|
||||
vector<char> Shader::GetFragData()
|
||||
{
|
||||
return FileManager::LoadBinaryFile(PackagePath::AbsolutePath(mName) + ".frag.spv");
|
||||
return FileManager::LoadBinaryFile(PackagePath::AbsolutePath("") + ".frag.spv");
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,15 +2,12 @@
|
||||
#include "asset_render.h"
|
||||
|
||||
namespace engineapi {
|
||||
class Shader : public Asset {
|
||||
protected:
|
||||
class Shader : public Resource<Shader> {
|
||||
uint32_t mId;
|
||||
ShaderInfo mInfo;
|
||||
public:
|
||||
Shader(string_view name, uint32_t flags);
|
||||
Shader();
|
||||
~Shader();
|
||||
void BeginLoad()override;
|
||||
|
||||
uint32_t& GetID() {
|
||||
return mId;
|
||||
}
|
||||
|
||||
@ -1,8 +1,34 @@
|
||||
#include "vulkan_glsl_loader.h"
|
||||
#include "vulkanapi/tool/glsl_to_spirv.h"
|
||||
#include "asset/file_manager.h"
|
||||
#include "render/asset/shader.h"
|
||||
namespace engineapi {
|
||||
vk::ShaderStageFlagBits GetShaderType(string_view ext)
|
||||
{
|
||||
switch (string_hash(ext))
|
||||
{
|
||||
case string_hash(".vert"): return vk::ShaderStageFlagBits::eVertex;
|
||||
case string_hash(".geom"): return vk::ShaderStageFlagBits::eGeometry;
|
||||
case string_hash(".tese"): return vk::ShaderStageFlagBits::eTessellationEvaluation;
|
||||
case string_hash(".tesc"): return vk::ShaderStageFlagBits::eTessellationControl;
|
||||
case string_hash(".frag"): return vk::ShaderStageFlagBits::eFragment;
|
||||
case string_hash(".comp"): return vk::ShaderStageFlagBits::eCompute;
|
||||
default: return vk::ShaderStageFlagBits::eAll;
|
||||
}
|
||||
}
|
||||
//string PreprocessGlsl(string glsl);
|
||||
ResourceBundle VulkanGlslLoader::LoadFile(PackagePath handle, const MetaBundle& meta)
|
||||
{
|
||||
return ResourceBundle();
|
||||
auto m = meta.FetchMeta<Shader>();
|
||||
auto program = m ? ResourceManager::GetSingleton().LoaderEmplaceResource<Shader>(m->guid)
|
||||
: ResourceManager::GetSingleton().LoaderEmplaceResource<Shader>();
|
||||
string glsl = FileManager::LoadTextFile(handle.AbsolutePath());
|
||||
auto shader_enum = GetShaderType(handle.GetExtension());
|
||||
glsl = vulkanapi::GlslToSpirv::PreprocessGlsl(glsl);
|
||||
auto spirv = vulkanapi::GlslToSpirv::spirv(glsl, shader_enum);
|
||||
//if (spirv)
|
||||
//program->Load(shader_enum, {}, string_view{ r_cast<const char*>(spirv->data()),hlp::buffer_size(*spirv) }, glsl);
|
||||
return program;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "asset/resource_manager.inl"
|
||||
#include "asset/resource_manager.h"
|
||||
namespace engineapi {
|
||||
class VulkanGlslLoader : public IFileLoader
|
||||
{
|
||||
|
||||
89
engine/src/engine/vulkanapi/tool/glsl_to_spirv.cpp
Normal file
89
engine/src/engine/vulkanapi/tool/glsl_to_spirv.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
#include "glsl_to_spirv.h"
|
||||
#include "zstd/table.h"
|
||||
#include "meta/hash.h"
|
||||
#include "yaml/yaml.h"
|
||||
#include <shaderc/shaderc.hpp>
|
||||
#include <vector>
|
||||
namespace vulkanapi
|
||||
{
|
||||
using std::vector;
|
||||
using zstd::hash_table;
|
||||
constexpr auto replacer = R"(
|
||||
#ifdef OGL
|
||||
#define U_LAYOUT(SET, BIND)
|
||||
#define S_LAYOUT(SET, BIND)
|
||||
#define BLOCK(X) struct X
|
||||
#endif
|
||||
#ifdef VULKAN
|
||||
#define U_LAYOUT(SET, BIND) layout(std140, set = SET, binding = BIND)
|
||||
#define S_LAYOUT(SET, BIND) layout(set = SET, binding = BIND)
|
||||
#define BLOCK(X) X
|
||||
#endif
|
||||
)";
|
||||
shaderc_shader_kind ConvertStageSC(vk::ShaderStageFlagBits stage)
|
||||
{
|
||||
static hash_table< vk::ShaderStageFlagBits, shaderc_shader_kind> conv
|
||||
{
|
||||
{ vk::ShaderStageFlagBits::eVertex ,shaderc_shader_kind::shaderc_vertex_shader },
|
||||
{ vk::ShaderStageFlagBits::eFragment ,shaderc_shader_kind::shaderc_fragment_shader },
|
||||
{ vk::ShaderStageFlagBits::eGeometry ,shaderc_shader_kind::shaderc_geometry_shader },
|
||||
{ vk::ShaderStageFlagBits::eTessellationControl ,shaderc_shader_kind::shaderc_tess_control_shader },
|
||||
{ vk::ShaderStageFlagBits::eTessellationEvaluation,shaderc_shader_kind::shaderc_tess_evaluation_shader },
|
||||
};
|
||||
auto itr = conv.find(stage);
|
||||
return itr->second;
|
||||
}
|
||||
string GlslToSpirv::PreprocessGlsl(string glsl)
|
||||
{
|
||||
string shader_code = glsl;
|
||||
|
||||
//shader_code = ProcessIncludes(shader_code);
|
||||
|
||||
auto version_pos = shader_code.find("#version");
|
||||
auto version_end = shader_code.find("\n", version_pos);
|
||||
|
||||
return shader_code.substr(0, version_end) + replacer + shader_code.substr(version_end, shader_code.size() - version_end);
|
||||
}
|
||||
std::optional<std::vector<unsigned int>> GlslToSpirv::spirv(string_view glsl, vk::ShaderStageFlagBits v_stage, string_view code_id)
|
||||
{
|
||||
string val = static_cast<string>(glsl);
|
||||
std::optional<std::vector<unsigned int>> spirv_out;
|
||||
{
|
||||
shaderc::Compiler compiler;
|
||||
shaderc::CompileOptions opt;
|
||||
opt.SetTargetEnvironment(shaderc_target_env::shaderc_target_env_vulkan, 0);
|
||||
auto result = compiler.CompileGlslToSpv(val, ConvertStageSC(v_stage), code_id.data(), opt);
|
||||
if (result.GetCompilationStatus() == shaderc_compilation_status::shaderc_compilation_status_success)
|
||||
spirv_out = vector<unsigned int>{ result.begin(),result.end() };
|
||||
else
|
||||
{
|
||||
string filename = "/" + string{ code_id } + YAML::Text_Serialize(meta::string_hash(glsl));
|
||||
auto err_m = result.GetErrorMessage();
|
||||
auto err_msg = err_m.c_str();
|
||||
//LOG_TO(LogPool::GFX, "%s", err_msg);
|
||||
try
|
||||
{
|
||||
/*
|
||||
auto path = string{ Core::GetSystem<FileSystem>().GetAppDataDir() } +"/idk";
|
||||
if (!std::filesystem::exists(path.sv()))
|
||||
std::filesystem::create_directory(path.sv());
|
||||
path += "/shader_err";
|
||||
if (!std::filesystem::exists(path.sv()))
|
||||
std::filesystem::create_directory(path.sv());
|
||||
auto out_file = path + filename;
|
||||
std::ofstream out{ out_file };
|
||||
out << val;
|
||||
out << " /* Error Message: \n" << err_msg << "\n*///";
|
||||
/*out.close();
|
||||
*/
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
//LOG_TO(LogPool::GFX, "Failed to output glsl [%s] that generated the above error.", filename.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
return spirv_out;
|
||||
}
|
||||
|
||||
}
|
||||
16
engine/src/engine/vulkanapi/tool/glsl_to_spirv.h
Normal file
16
engine/src/engine/vulkanapi/tool/glsl_to_spirv.h
Normal file
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include "vulkan/vulkan.hpp"
|
||||
#include <glslang/public/ShaderLang.h>
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
namespace vulkanapi
|
||||
{
|
||||
using std::string_view;
|
||||
using std::string;
|
||||
class GlslToSpirv
|
||||
{
|
||||
public:
|
||||
static string PreprocessGlsl(string glsl);
|
||||
static std::optional<std::vector<unsigned int>> spirv(string_view glsl, vk::ShaderStageFlagBits v_stage, string_view code_id = "unknown_shader");
|
||||
};
|
||||
}
|
||||
@ -315,7 +315,7 @@ namespace vulkanapi {
|
||||
vkDestroyShaderModule(device.Ptr(), shaderModule.second, nullptr);
|
||||
|
||||
auto vulkan_pipeline = GetNextPipeline(shader->GetID());
|
||||
vulkan_pipeline->name = shader->GetName();
|
||||
vulkan_pipeline->name = "";//shader->GetName();
|
||||
vulkan_pipeline->pipeline = pipeLine;
|
||||
vulkan_pipeline->inUse = true;
|
||||
vulkan_pipeline->pipelineLayout = pipelineLayout;
|
||||
|
||||
@ -7,7 +7,9 @@ target("zengine")
|
||||
set_rundir(".")
|
||||
add_rules("volk.env", "glsl.env")
|
||||
add_rules("c++.codegen",{
|
||||
files = {"src/engine/render/meta/*.h", "src/engine/asset/res/guid.h"}
|
||||
files = {"src/engine/render/meta/*.h",
|
||||
"src/engine/asset/res/guid.h",
|
||||
"src/engine/asset/res/meta_bundle.h",}
|
||||
})
|
||||
add_deps("zlog","zlib")
|
||||
add_defines("VULKAN_API")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user