Adding benchmark

This commit is contained in:
Dynamitos
2024-07-05 12:02:46 +02:00
parent 8418cdbd11
commit fd8dc5ed0f
47 changed files with 1071 additions and 1010 deletions
+84 -99
View File
@@ -56,119 +56,104 @@ PTextureAsset TextureLoader::getPlaceholderTexture() { return placeholderAsset;
}
void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset) {
// manually transcode ktx textures using toktx
if (args.filePath.extension().compare("ktx") != 0) {
auto ktxFile = args.filePath;
ktxFile.replace_extension("ktx");
std::stringstream ss;
ss << "toktx --encode etc1s ";
if (args.type == TextureImportType::TEXTURE_NORMAL) {
// ss << "--normal_mode ";
}
if (args.type == TextureImportType::TEXTURE_CUBEMAP) {
}
ss << ktxFile << " " << args.filePath;
system(ss.str().c_str());
args.filePath = ktxFile;
int totalWidth = 0, totalHeight = 0, n = 0;
unsigned char* data = stbi_load(args.filePath.string().c_str(), &totalWidth, &totalHeight, &n, 0);
ktxTexture2* kTexture = nullptr;
VkFormat format;
switch (n) {
case 1:
format = VK_FORMAT_R8_UNORM;
break;
case 2:
format = VK_FORMAT_R8G8_UNORM;
break;
case 3:
format = VK_FORMAT_R8G8B8_UNORM;
break;
case 4:
format = VK_FORMAT_R8G8B8A8_UNORM;
break;
}
ktxTextureCreateInfo createInfo = {
.vkFormat = (uint32)format,
.baseDepth = 1,
.numLevels = 1,
.numLayers = 1,
.isArray = false,
.generateMipmaps = false,
};
ktxTexture2* ktxHandle;
KTX_ASSERT(ktxTexture_CreateFromNamedFile(args.filePath.string().c_str(), 0, (ktxTexture**)&ktxHandle));
if (args.type == TextureImportType::TEXTURE_CUBEMAP) {
uint32 faceWidth = totalWidth / 4;
// uint32 faceHeight = totalHeight / 3;
// Cube map
createInfo.baseWidth = totalWidth / 4;
createInfo.baseHeight = totalHeight / 3;
createInfo.numFaces = 6;
createInfo.numDimensions = 2;
// int totalWidth = 0, totalHeight = 0, n = 0;
// unsigned char* data = stbi_load(args.filePath.string().c_str(), &totalWidth, &totalHeight, &n, 4);
// ktxTexture2* kTexture = nullptr;
// VkFormat format = VK_FORMAT_R8G8B8A8_UNORM;
// ktxTextureCreateInfo createInfo = {
// .vkFormat = (uint32)format,
// .baseDepth = 1,
// .numLevels = 1,
// .numLayers = 1,
// .isArray = false,
// .generateMipmaps = false,
// };
//
// if (args.type == TextureImportType::TEXTURE_CUBEMAP)
//{
// uint32 faceWidth = totalWidth / 4;
// // uint32 faceHeight = totalHeight / 3;
// // Cube map
// createInfo.baseWidth = totalWidth / 4;
// createInfo.baseHeight = totalHeight / 3;
// createInfo.numFaces = 6;
// createInfo.numDimensions = 2;
KTX_ASSERT(ktxTexture2_Create(&createInfo, KTX_TEXTURE_CREATE_ALLOC_STORAGE, &kTexture));
// KTX_ASSERT(ktxTexture2_Create(&createInfo,
// KTX_TEXTURE_CREATE_ALLOC_STORAGE,
// &kTexture));
auto loadCubeFace = [n, &kTexture, faceWidth, totalWidth, &data](int xPos, int yPos, int faceName) {
std::vector<unsigned char> vec(faceWidth * faceWidth * n);
for (uint32 y = 0; y < faceWidth; ++y) {
for (uint32 x = 0; x < faceWidth; ++x) {
int imgX = x + (xPos * faceWidth);
int imgY = y + (yPos * faceWidth);
std::memcpy(&vec[(x + (faceWidth * y)) * n], &data[(imgX + (totalWidth * imgY)) * n], n);
}
}
ktxTexture_SetImageFromMemory(ktxTexture(kTexture), 0, 0, faceName, vec.data(), vec.size());
};
loadCubeFace(2, 1, 0); // +X
loadCubeFace(0, 1, 1); // -X
loadCubeFace(1, 0, 2); // +Y
loadCubeFace(1, 2, 3); // -Y
loadCubeFace(1, 1, 4); // +Z
loadCubeFace(3, 1, 5); // -Z
} else {
createInfo.baseWidth = totalWidth;
createInfo.baseHeight = totalHeight;
createInfo.numFaces = 1;
createInfo.numDimensions = 1 + (totalHeight > 1);
// auto loadCubeFace = [&kTexture, &faceWidth, &totalWidth, &data](int xPos, int yPos, int faceName)
// {
// std::vector<unsigned char> vec(faceWidth * faceWidth * 4);
// for (uint32 y = 0; y < faceWidth; ++y)
// {
// for (uint32 x = 0; x < faceWidth; ++x)
// {
// int imgX = x + (xPos * faceWidth);
// int imgY = y + (yPos * faceWidth);
// std::memcpy(&vec[(x + (faceWidth * y)) * 4], &data[(imgX + (totalWidth * imgY)) * 4], 4);
// }
// }
// ktxTexture_SetImageFromMemory(ktxTexture(kTexture),
// 0, 0, faceName, vec.data(), vec.size());
// };
// loadCubeFace(2, 1, 0); // +X
// loadCubeFace(0, 1, 1); // -X
// loadCubeFace(1, 0, 2); // +Y
// loadCubeFace(1, 2, 3); // -Y
// loadCubeFace(1, 1, 4); // +Z
// loadCubeFace(3, 1, 5); // -Z
//}
// else
//{
// createInfo.baseWidth = totalWidth;
// createInfo.baseHeight = totalHeight;
// createInfo.numFaces = 1;
// createInfo.numDimensions = 1 + (totalHeight > 1);
ktxTexture2_Create(&createInfo, KTX_TEXTURE_CREATE_ALLOC_STORAGE, &kTexture);
// ktxTexture2_Create(&createInfo,
// KTX_TEXTURE_CREATE_ALLOC_STORAGE,
// &kTexture);
ktxTexture_SetImageFromMemory(ktxTexture(kTexture), 0, 0, 0, data, totalWidth * totalHeight * n * sizeof(unsigned char));
}
ktxBasisParams basisParams = {
.structSize = sizeof(ktxBasisParams),
.uastc = true,
.threadCount = std::thread::hardware_concurrency() - 2,
.uastcFlags = KTX_PACK_UASTC_LEVEL_SLOWER,
.uastcRDO = true,
};
KTX_ASSERT(ktxTexture2_CompressBasisEx(kTexture, &basisParams));
// ktxTexture_SetImageFromMemory(ktxTexture(kTexture),
// 0, 0, 0, data, totalWidth * totalHeight * n * sizeof(unsigned char));
//}
// ktxTexture_WriteToNamedFile(ktxTexture(kTexture), args.filePath.replace_extension(".ktx").string().c_str());
KTX_ASSERT(ktxTexture2_DeflateZstd(kTexture, 20));
// ktxBasisParams basisParams = {
// .structSize = sizeof(ktxBasisParams),
// .uastc = true,
// .threadCount = std::thread::hardware_concurrency(),
// .normalMap = normalMap,
// .uastcFlags = KTX_PACK_UASTC_LEVEL_VERYSLOW,
// .uastcRDO = true,
// .uastcRDOQualityScalar = 1,
// };
// KTX_ASSERT(ktxTexture2_CompressBasisEx(kTexture, &basisParams));
// KTX_ASSERT(ktxTexture2_DeflateZstd(kTexture, 3));
char writer[100];
snprintf(writer, sizeof(writer), "%s version %s", "SeeleEngine", "0.0.1");
ktxHashList_AddKVPair(&kTexture->kvDataHead, KTX_WRITER_KEY, (ktx_uint32_t)strlen(writer) + 1, writer);
// char writer[100];
// snprintf(writer, sizeof(writer), "%s version %s", "SeeleEngine", "0.0.1");
// ktxHashList_AddKVPair(&kTexture->kvDataHead, KTX_WRITER_KEY,
// (ktx_uint32_t)strlen(writer) + 1,
// writer);
uint8* texData;
size_t texSize;
KTX_ASSERT(ktxTexture_WriteToMemory(ktxTexture(kTexture), &texData, &texSize));
// uint8* texData;
// size_t texSize;
// KTX_ASSERT(ktxTexture_WriteToMemory(ktxTexture(kTexture), &texData, &texSize));
//
// stbi_image_free(data);
ktxTexture_WriteToNamedFile(ktxTexture(kTexture), args.filePath.filename().replace_extension(".ktx").generic_string().c_str());
Array<uint8> serialized(texSize);
std::memcpy(serialized.data(), texData, texSize);
stbi_image_free(data);
ktxTexture_Destroy(ktxTexture(kTexture));
if (textureAsset->getName().empty()) {
return;
}
textureAsset->setTexture(std::move(serialized));
std::string path = (std::filesystem::path(args.importPath) / textureAsset->getName()).string().append(".asset");
auto assetStream = AssetRegistry::createWriteStream(std::move(path), std::ios::binary);
ArchiveBuffer buffer(graphics);
@@ -179,7 +164,7 @@ void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset) {
// write folder
Serialization::save(buffer, textureAsset->getFolderPath());
// write asset data
Serialization::save(buffer, args.filePath.string());
textureAsset->save(buffer);
buffer.writeToStream(assetStream);
+28
View File
@@ -18,3 +18,31 @@ void PlayView::commitUpdate() { GameView::commitUpdate(); }
void PlayView::prepareRender() { GameView::prepareRender(); }
void PlayView::render() { GameView::render(); }
void PlayView::keyCallback(KeyCode code, InputAction action, KeyModifier modifier) {
GameView::keyCallback(code, action, modifier);
if (code == KeyCode::KEY_P && action == InputAction::RELEASE) {
getGlobals().usePositionOnly = !getGlobals().usePositionOnly;
std::cout << "Use Pos only " << getGlobals().usePositionOnly << std::endl;
}
if (code == KeyCode::KEY_O && action == InputAction::RELEASE) {
getGlobals().useDepthCulling = !getGlobals().useDepthCulling;
std::cout << "Use Depth Culling " << getGlobals().useDepthCulling << std::endl;
}
if (code == KeyCode::KEY_L && action == InputAction::RELEASE) {
getGlobals().useLightCulling = !getGlobals().useLightCulling;
std::cout << "Use Light Culling " << getGlobals().useLightCulling << std::endl;
}
if (code == KeyCode::KEY_G && action == InputAction::RELEASE) {
Component::Camera cam;
Component::Transform tra;
scene->view<Component::Camera, Component::Transform>([&cam, &tra](Component::Camera& c, Component::Transform& t) {
if (c.mainCamera) {
tra = t;
cam = c;
}
});
std::cout << cam.getCameraPosition() << std::endl;
std::cout << tra.getRotation() << std::endl;
}
}
+2
View File
@@ -13,6 +13,8 @@ class PlayView : public GameView {
virtual void prepareRender() override;
virtual void render() override;
virtual void keyCallback(Seele::KeyCode code, Seele::InputAction action, Seele::KeyModifier modifier) override;
private:
};
+56 -55
View File
@@ -39,70 +39,72 @@ int main() {
std::filesystem::path binaryPath = sourcePath / "cmake" / "libMeshShadingDemo.so";
#endif
std::filesystem::path cmakePath = outputPath / "cmake";
if (true) {
#ifdef __APPLE__
graphics = new Metal::Graphics();
graphics = new Metal::Graphics();
#else
graphics = new Vulkan::Graphics();
graphics = new Vulkan::Graphics();
#endif
GraphicsInitializer initializer;
graphics->init(initializer);
StaticMeshVertexData* vd = StaticMeshVertexData::getInstance();
vd->init(graphics);
GraphicsInitializer initializer;
graphics->init(initializer);
StaticMeshVertexData* vd = StaticMeshVertexData::getInstance();
vd->init(graphics);
OWindowManager windowManager = new WindowManager();
AssetRegistry::init(sourcePath / "Assets", graphics);
AssetImporter::init(graphics);
AssetImporter::importFont(FontImportArgs{
.filePath = "./fonts/Calibri.ttf",
});
AssetImporter::importMesh(MeshImportArgs{
.filePath = sourcePath / "import/models/cube.fbx",
});
AssetImporter::importTexture(TextureImportArgs{
.filePath = sourcePath / "import/textures/skyboxsun5deg_tn.jpg",
.type = TextureImportType::TEXTURE_CUBEMAP,
});
AssetImporter::importMesh(MeshImportArgs{
.filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.fbx",
.importPath = "Whitechapel",
});
AssetImporter::importMesh(MeshImportArgs{
.filePath = sourcePath / "import/models/city-suburbs/source/city-suburbs.obj",
.importPath = "suburbs",
});
vd->commitMeshes();
WindowCreateInfo mainWindowInfo = {
.width = 1920,
.height = 1080,
.title = "SeeleEngine",
.preferredFormat = Gfx::SE_FORMAT_B8G8R8A8_SRGB,
};
auto window = windowManager->addWindow(graphics, mainWindowInfo);
ViewportCreateInfo sceneViewInfo = {
.dimensions =
{
.size = {1920, 1080},
.offset = {0, 0},
},
.numSamples = Gfx::SE_SAMPLE_COUNT_1_BIT,
};
OGameView sceneView = new Editor::PlayView(graphics, window, sceneViewInfo, binaryPath.generic_string());
sceneView->setFocused();
OWindowManager windowManager = new WindowManager();
AssetRegistry::init(sourcePath / "Assets", graphics);
AssetImporter::init(graphics);
// AssetImporter::importFont(FontImportArgs{
// .filePath = "./fonts/Calibri.ttf",
// });
AssetImporter::importMesh(MeshImportArgs{
.filePath = sourcePath / "import/models/cube.fbx",
});
AssetImporter::importTexture(TextureImportArgs{
.filePath = sourcePath / "import/textures/skyboxsun5deg_tn.jpg",
.type = TextureImportType::TEXTURE_CUBEMAP,
});
AssetImporter::importMesh(MeshImportArgs{
.filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.fbx",
.importPath = "Whitechapel",
});
// AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/city-suburbs/source/city-suburbs.obj",
// .importPath = "suburbs",
// });
vd->commitMeshes();
WindowCreateInfo mainWindowInfo = {
.width = 1920,
.height = 1080,
.title = "SeeleEngine",
.preferredFormat = Gfx::SE_FORMAT_B8G8R8A8_SRGB,
};
auto window = windowManager->addWindow(graphics, mainWindowInfo);
ViewportCreateInfo sceneViewInfo = {
.dimensions =
{
.size = {1920, 1080},
.offset = {0, 0},
},
.numSamples = Gfx::SE_SAMPLE_COUNT_4_BIT,
};
OGameView sceneView = new Editor::PlayView(graphics, window, sceneViewInfo, binaryPath.generic_string());
sceneView->setFocused();
while (windowManager->isActive()) {
windowManager->render();
}
vd->destroy();
// export game
if (false) {
while (windowManager->isActive() && getGlobals().running) {
windowManager->render();
}
vd->destroy();
// export game
} else {
std::filesystem::create_directories(outputPath);
std::system(fmt::format("cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DGAME_TITLE=\"{}\" -DGAME_DESTINATION=\"{}\" "
std::system(fmt::format("cmake -DCMAKE_BUILD_TYPE=Release -DGAME_TITLE=\"{}\" -DGAME_DESTINATION=\"{}\" "
"-DGAME_BINARY=\"{}\" -P ./cmake/ExportProject.cmake",
gameName, outputPath.generic_string(), binaryPath.generic_string())
.c_str());
std::system(fmt::format("cmake -S {} -B {}", cmakePath.generic_string(), cmakePath.generic_string()).c_str());
std::system(fmt::format("cmake -S {} -B {}", cmakePath.generic_string(), outputPath.generic_string()).c_str());
std::system(fmt::format("cmake --build {}", cmakePath.generic_string()).c_str());
std::filesystem::copy(binaryPath, outputPath, std::filesystem::copy_options::recursive);
std::filesystem::copy(sourcePath / "Assets", outputPath / "Assets", std::filesystem::copy_options::recursive);
std::filesystem::copy("shaders", outputPath / "shaders", std::filesystem::copy_options::recursive);
std::filesystem::copy("textures", outputPath / "textures", std::filesystem::copy_options::recursive);
@@ -110,7 +112,6 @@ int main() {
std::filesystem::copy_file("assimp-vc143-mt.dll", outputPath / "assimp-vc143-mt.dll");
std::filesystem::copy_file("slang.dll", outputPath / "slang.dll");
std::filesystem::copy_file("slang-glslang.dll", outputPath / "slang-glslang.dll");
std::filesystem::copy_file("slang-llvm.dll", outputPath / "slang-llvm.dll");
#endif
}
return 0;