upscaler: init at 1.4.0 (#356497)

This commit is contained in:
Aleksana 2024-11-20 14:07:57 +08:00 committed by GitHub
commit d0df7756df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 298 additions and 0 deletions

View File

@ -0,0 +1,92 @@
{
lib,
fetchFromGitLab,
glib,
gtk4,
meson,
ninja,
gitUpdater,
desktop-file-utils,
appstream,
blueprint-compiler,
python3Packages,
pkg-config,
libadwaita,
wrapGAppsHook4,
upscayl-ncnn,
}:
python3Packages.buildPythonApplication rec {
pname = "upscaler";
version = "1.4.0";
pyproject = false; # meson instead of pyproject
src = fetchFromGitLab {
domain = "gitlab.gnome.org";
owner = "World";
repo = "Upscaler";
rev = version;
hash = "sha256-Dy8tykIbK5o0XulurG+TxORZZSxfRe5Kjh6aGpsh+0Y=";
};
passthru.updateScript = gitUpdater { };
postPatch = ''
substituteInPlace upscaler/window.py \
--replace-fail '"upscayl-bin",' '"${lib.getExe upscayl-ncnn}",'
'';
strictDeps = true;
nativeBuildInputs = [
wrapGAppsHook4
meson
ninja
desktop-file-utils
appstream
blueprint-compiler
pkg-config
gtk4
glib
];
dependencies = with python3Packages; [
pygobject3
pillow
vulkan
];
buildInputs = [
libadwaita
upscayl-ncnn
];
mesonFlags = [
(lib.mesonBool "network_tests" false)
];
# NOTE: `postCheck` is intentionally not used here, as the entire checkPhase
# is skipped by `buildPythonApplication`
# https://github.com/NixOS/nixpkgs/blob/9d4343b7b27a3e6f08fc22ead568233ff24bbbde/pkgs/development/interpreters/python/mk-python-derivation.nix#L296
postInstallCheck = ''
mesonCheckPhase
'';
dontWrapGApps = true;
makeWrapperArgs = [ "\${gappsWrapperArgs[@]}" ];
meta = {
description = "Upscale and enhance images";
homepage = "https://tesk.page/upscaler";
license = lib.licenses.gpl3Only;
maintainers = with lib.maintainers; [
grimmauld
getchoo
aleksana
];
mainProgram = "upscaler";
platforms = lib.platforms.linux;
};
}

View File

@ -0,0 +1,27 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7e4da27..85cf911 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -106,20 +106,13 @@ if(USE_SYSTEM_NCNN)
message(STATUS "Using glslang install located at ${GLSLANG_TARGET_DIR}")
find_package(Threads)
+ find_package(glslang REQUIRED)
+ find_package(SPIRV-Tools-opt REQUIRED)
- include("${GLSLANG_TARGET_DIR}/OSDependentTargets.cmake")
- include("${GLSLANG_TARGET_DIR}/OGLCompilerTargets.cmake")
if(EXISTS "${GLSLANG_TARGET_DIR}/HLSLTargets.cmake")
# hlsl support can be optional
include("${GLSLANG_TARGET_DIR}/HLSLTargets.cmake")
endif()
- include("${GLSLANG_TARGET_DIR}/glslangTargets.cmake")
- include("${GLSLANG_TARGET_DIR}/SPIRVTargets.cmake")
-
- if (NOT TARGET glslang OR NOT TARGET SPIRV)
- message(WARNING "glslang or SPIRV target not found! USE_SYSTEM_NCNN will be turned off.")
- set(USE_SYSTEM_NCNN OFF)
- endif()
endif()
endif()

View File

@ -0,0 +1,22 @@
diff --git a/main.cpp b/main.cpp
index 9d44c3d..40d2b27 100644
--- a/main.cpp
+++ b/main.cpp
@@ -207,7 +207,7 @@ static void print_usage()
fprintf(stderr, " -w width resize output to a width (default=W:default), use '-r help' for more details\n");
fprintf(stderr, " -c compress compression of the output image, default 0 and varies to 100\n");
fprintf(stderr, " -t tile-size tile size (>=32/0=auto, default=0) can be 0,0,0 for multi-gpu\n");
- fprintf(stderr, " -m model-path folder path to the pre-trained models. default=models\n");
+ fprintf(stderr, " -m model-path folder path to the pre-trained models. default=REPLACE_MODELS\n");
fprintf(stderr, " -n model-name model name (default=realesrgan-x4plus, can be realesr-animevideov3 | realesrgan-x4plus-anime | realesrnet-x4plus or any other model)\n");
fprintf(stderr, " -g gpu-id gpu device to use (default=auto) can be 0,1,2 for multi-gpu\n");
fprintf(stderr, " -j load:proc:save thread count for load/proc/save (default=1:2:2) can be 1:2,2,2:2 for multi-gpu\n");
@@ -688,7 +688,7 @@ int main(int argc, char **argv)
bool resizeProvided = false;
bool hasCustomWidth = false;
std::vector<int> tilesize;
- path_t model = PATHSTR("models");
+ path_t model = PATHSTR("REPLACE_MODELS");
path_t modelname = PATHSTR("realesrgan-x4plus");
std::vector<int> gpuid;
int jobs_load = 1;

View File

@ -0,0 +1,92 @@
{
cmake,
fetchFromGitHub,
fetchzip,
glslang,
installShellFiles,
lib,
libwebp,
ncnn,
stdenv,
vulkan-headers,
vulkan-loader,
}:
# upscayl-ncnn is a fork of /pkgs/by-name/re/realesrgan-ncnn-vulkan, so the nix package is basically the same.
stdenv.mkDerivation (finalAttrs: {
pname = "upscayl-ncnn";
version = "20240601-103425";
src = fetchFromGitHub {
owner = "upscayl";
repo = "upscayl-ncnn";
rev = "refs/tags/${finalAttrs.version}";
hash = "sha256-rGnjL+sU5x3VXHnvuYXVdxGmHdj9eBkIZK3CwL89lN0=";
};
models = fetchzip {
# Choose the newst release from https://github.com/xinntao/Real-ESRGAN/releases to update
url = "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-ubuntu.zip";
hash = "sha256-1YiPzv1eGnHrazJFRvl37+C1F2xnoEbN0UQYkxLT+JQ=";
stripRoot = false;
};
patches = [
./cmakelists.patch
./models_path.patch
];
sourceRoot = "${finalAttrs.src.name}/src";
postPatch = ''
substituteInPlace main.cpp --replace REPLACE_MODELS $out/share/models
'';
nativeBuildInputs = [
cmake
glslang
installShellFiles
];
cmakeFlags = [
(lib.cmakeBool "USE_SYSTEM_NCNN" true)
(lib.cmakeBool "USE_SYSTEM_WEBP" true)
(lib.cmakeFeature "GLSLANG_TARGET_DIR" "${glslang}/lib/cmake")
];
buildInputs = [
vulkan-loader
libwebp
ncnn
vulkan-headers
glslang
];
installPhase = ''
runHook preInstall
mkdir -p $out/share
installBin upscayl-bin
ln -s ${finalAttrs.models}/models $out/share
runHook postInstall
'';
env.NIX_LDFLAGS = lib.optionalString stdenv.hostPlatform.isLinux "-rpath ${
lib.makeLibraryPath [ vulkan-loader ]
}";
meta = {
changelog = "https://github.com/upscayl/upscayl-ncnn/releases/tag/${finalAttrs.version}";
description = "Upscayl backend powered by the NCNN framework and Real-ESRGAN architecture";
homepage = "https://github.com/upscayl/upscayl-ncnn";
license = lib.licenses.agpl3Only;
mainProgram = "upscayl-bin";
maintainers = with lib.maintainers; [
grimmauld
getchoo
];
platforms = lib.platforms.all;
};
})

View File

@ -0,0 +1,63 @@
{
buildPythonPackage,
cffi,
fetchFromGitHub,
inflection,
jinja2,
lib,
pysdl2,
setuptools,
vulkan-loader,
wheel,
xmltodict,
}:
buildPythonPackage rec {
pname = "vulkan";
version = "1.3.275.1";
pyproject = true;
src = fetchFromGitHub {
owner = "realitix";
repo = "vulkan";
rev = "refs/tags/${version}";
hash = "sha256-b1jHNKdHF7pIC6H4O2yxy36Ppb60J0uN2P0WaCw51Gc=";
};
postPatch = ''
substituteInPlace vulkan/_vulkan.py \
--replace-fail 'lib = ffi.dlopen(name)' 'lib = ffi.dlopen("${vulkan-loader}/lib/" + name)'
'';
buildInputs = [
vulkan-loader
];
build-system = [
setuptools
wheel
];
dependencies = [
inflection
jinja2
pysdl2
xmltodict
cffi
];
pythonImportsCheck = [
"vulkan"
];
meta = {
description = "Ultimate Python binding for Vulkan API";
homepage = "https://github.com/realitix/vulkan";
license = lib.licenses.asl20;
platforms = lib.platforms.linux;
maintainers = with lib.maintainers; [
grimmauld
getchoo
];
};
}

View File

@ -17565,6 +17565,8 @@ self: super: with self; {
vulcan-api = callPackage ../development/python-modules/vulcan-api { };
vulkan = callPackage ../development/python-modules/vulkan { };
vultr = callPackage ../development/python-modules/vultr { };
vulture = callPackage ../development/python-modules/vulture { };