From 1f15133dd985442af20d42a96fbcd0007f03bd2b Mon Sep 17 00:00:00 2001 From: yum Date: Tue, 21 Mar 2023 17:13:32 -0700 Subject: Reduce texture memory usage for English speakers We used to populate 7 4k textures + 1 2k texture for all users. Now if the user has configured `bytes_per_char=1` in the Unity panel, we just populate a single 512x512 texture containing the first 128 ASCII characters. This reduces texture memory usage by 99.74%, from 134.67 MB to 340 KB. --- GUI/GUI/GUI/PythonWrapper.cpp | 52 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) (limited to 'GUI') diff --git a/GUI/GUI/GUI/PythonWrapper.cpp b/GUI/GUI/GUI/PythonWrapper.cpp index 0337072..f920a43 100644 --- a/GUI/GUI/GUI/PythonWrapper.cpp +++ b/GUI/GUI/GUI/PythonWrapper.cpp @@ -567,12 +567,16 @@ bool PythonWrapper::GenerateAnimator( std::filesystem::path tastt_animator_path = tastt_generated_dir_path / unity_animator_generated_name; + const int texture_rows = (config.bytes_per_char == 1 ? 8 : 64); + const int texture_cols = (config.bytes_per_char == 1 ? 16 : 128); { Log(out, "Generating shader for {}x{} board (pass 0)...", config.rows, config.cols); if (!InvokeWithArgs({ generate_shader_path, "--bytes_per_char", std::to_string(config.bytes_per_char), - "--rows", std::to_string(config.rows), - "--cols", std::to_string(config.cols), + "--board_rows", std::to_string(config.rows), + "--board_cols", std::to_string(config.cols), + "--texture_rows", std::to_string(texture_rows), + "--texture_cols", std::to_string(texture_cols), "--shader_template", shader_template_path, "--shader_path", shader_path }, "Failed to generate shader", out)) { @@ -585,14 +589,17 @@ bool PythonWrapper::GenerateAnimator( std::string py_stdout, py_stderr; if (!InvokeWithArgs({ generate_shader_path, "--bytes_per_char", std::to_string(config.bytes_per_char), - "--rows", std::to_string(config.rows), - "--cols", std::to_string(config.cols), + "--board_rows", std::to_string(config.rows), + "--board_cols", std::to_string(config.cols), + "--texture_rows", std::to_string(texture_rows), + "--texture_cols", std::to_string(texture_cols), "--shader_template", shader_lighting_template_path, "--shader_path", shader_lighting_path }, "Failed to generate shader", out)) { return false; } } +#if 0 { Log(out, "Generating emotes... "); @@ -622,6 +629,7 @@ bool PythonWrapper::GenerateAnimator( return false; } } +#endif { Log(out, "Creating {}\n", tastt_generated_dir_path.string()); std::filesystem::create_directories(tastt_generated_dir_path); @@ -682,6 +690,42 @@ bool PythonWrapper::GenerateAnimator( } Log(out, "success!\n"); } + if (config.bytes_per_char == 1) { + Log(out, "Applying texture memory optimization for English speakers... "); + std::error_code err; + for (int i = 0; i < 8; i++) { + std::filesystem::remove(tastt_fonts_path / ("Bitmaps/font-" + std::to_string(i) + ".png"), err); + if (err.value()) { + Log(out, "failed!\n"); + Log(out, "Error removing unicode texture: {} ({})\n", err.message(), err.value()); + return false; + } + if (i != 0) { + std::filesystem::remove(tastt_fonts_path / ("Bitmaps/font-" + std::to_string(i) + ".png.meta"), err); + if (err.value()) { + Log(out, "failed!\n"); + Log(out, "Error removing unicode texture metadata: {} ({})\n", err.message(), err.value()); + return false; + } + } + } + std::filesystem::remove(tastt_fonts_path / "Bitmaps/emotes.png", err); + if (err.value()) { + Log(out, "failed!\n"); + Log(out, "Error removing emotes texture: {} ({})\n", err.message(), err.value()); + return false; + } + + Log(out, "success!\n"); + } else { + std::error_code err; + if (!std::filesystem::remove(tastt_fonts_path / "Bitmaps/font-ascii.png.meta", err)) { + Log(out, "failed!\n"); + Log(out, "Error: {} ({})\n", err.message(), err.value()); + return false; + } + Log(out, "success!\n"); + } { Log(out, "Generating guid.map... "); if (!InvokeWithArgs({ libunity_path, "guid_map", -- cgit v1.2.3