diff --git a/pkgs/by-name/re/realcugan-ncnn-vulkan/cmakelists.patch b/pkgs/by-name/re/realcugan-ncnn-vulkan/cmakelists.patch new file mode 100644 index 0000000000000..78b5289ded14a --- /dev/null +++ b/pkgs/by-name/re/realcugan-ncnn-vulkan/cmakelists.patch @@ -0,0 +1,27 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index dac535d..59f6e5b 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -62,20 +62,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() + diff --git a/pkgs/by-name/re/realcugan-ncnn-vulkan/models_path.patch b/pkgs/by-name/re/realcugan-ncnn-vulkan/models_path.patch new file mode 100644 index 0000000000000..b4229ec971034 --- /dev/null +++ b/pkgs/by-name/re/realcugan-ncnn-vulkan/models_path.patch @@ -0,0 +1,22 @@ +diff --git a/main.cpp b/main.cpp +index bd78c99..75f162f 100644 +--- a/main.cpp ++++ b/main.cpp +@@ -109,7 +109,7 @@ static void print_usage() + fprintf(stdout, " -s scale upscale ratio (1/2/3/4, default=2)\n"); + fprintf(stdout, " -t tile-size tile size (>=32/0=auto, default=0) can be 0,0,0 for multi-gpu\n"); + fprintf(stdout, " -c syncgap-mode sync gap mode (0/1/2/3, default=3)\n"); +- fprintf(stdout, " -m model-path realcugan model path (default=models-se)\n"); ++ fprintf(stdout, " -m model-path realcugan model path (default=REPLACE_MODELS)\n"); + fprintf(stdout, " -g gpu-id gpu device to use (-1=cpu, default=auto) can be 0,1,2 for multi-gpu\n"); + fprintf(stdout, " -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"); + fprintf(stdout, " -x enable tta mode\n"); +@@ -442,7 +442,7 @@ int main(int argc, char** argv) + int noise = -1; + int scale = 2; + std::vector tilesize; +- path_t model = PATHSTR("models-se"); ++ path_t model = PATHSTR("REPLACE_MODELS"); + std::vector gpuid; + int jobs_load = 1; + std::vector jobs_proc; diff --git a/pkgs/by-name/re/realcugan-ncnn-vulkan/package.nix b/pkgs/by-name/re/realcugan-ncnn-vulkan/package.nix new file mode 100644 index 0000000000000..34a5583cfa5d2 --- /dev/null +++ b/pkgs/by-name/re/realcugan-ncnn-vulkan/package.nix @@ -0,0 +1,71 @@ +{ + lib, + stdenv, + fetchzip, + fetchFromGitHub, + cmake, + vulkan-headers, + vulkan-loader, + glslang, + libwebp, + ncnn, +}: +stdenv.mkDerivation rec { + pname = "realcugan-ncnn-vulkan"; + version = "20220728"; + + src = fetchFromGitHub { + owner = "nihui"; + repo = "realcugan-ncnn-vulkan"; + rev = version; + hash = "sha256-P3Y1B8m1+mpFinacwnvBE2vU150jj6Q12IS6QYNRZ6A="; + }; + sourceRoot = "${src.name}/src"; + + models = fetchzip { + url = "https://github.com/nihui/realcugan-ncnn-vulkan/releases/download/20220728/realcugan-ncnn-vulkan-20220728-ubuntu.zip"; + sha256 = "sha256-71C6taL2Zr1exG5HEXOLy1j9ZMKgkMJjTgNi2hiA7xk="; + }; + + patches = [ + ./cmakelists.patch + ./models_path.patch + ]; + + cmakeFlags = [ + (lib.cmakeBool "USE_SYSTEM_NCNN" true) + (lib.cmakeBool "USE_SYSTEM_WEBP" true) + (lib.cmakeFeature "GLSLANG_TARGET_DIR" "${glslang}/lib/cmake") + ]; + + nativeBuildInputs = [ cmake ]; + buildInputs = [ + vulkan-headers + vulkan-loader + glslang + libwebp + ncnn + ]; + + postPatch = '' + substituteInPlace main.cpp --replace REPLACE_MODELS $out/share/models-se + ''; + + installPhase = '' + runHook preInstall + mkdir -p $out/bin $out/share + cp realcugan-ncnn-vulkan $out/bin/ + + cp -r ${models}/models-{nose,pro,se} $out/share + runHook postInstall + ''; + + meta = with lib; { + description = "Real-cugan converter ncnn version, runs fast on intel / amd / nvidia / apple-silicon GPU with vulkan"; + homepage = "https://github.com/nihui/realcugan-ncnn-vulkan"; + license = licenses.mit; + maintainers = with maintainers; [ iynaix ]; + mainProgram = "realcugan-ncnn-vulkan"; + platforms = platforms.all; + }; +}