Skip to content

Commit

Permalink
refactor: realcugan (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tohrusky authored Dec 29, 2023
1 parent ee91689 commit 17ba60e
Show file tree
Hide file tree
Showing 23 changed files with 4,295 additions and 46 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/CI-Linux-x64-Clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ on:
- LICENSE
workflow_dispatch:

env:
GITHUB_ACTIONS: true

jobs:
Linux-x64-Clang:
strategy:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/CI-Linux-x64-GCC.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ on:
- LICENSE
workflow_dispatch:

env:
GITHUB_ACTIONS: true

jobs:
Linux-x64-GCC:
strategy:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/CI-MacOS-Universal-Clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:
workflow_dispatch:

env:
GITHUB_ACTIONS: true
DEVELOPER_DIR: /Applications/Xcode_14.2.app/Contents/Developer

jobs:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/CI-Windows-x64-MSVC.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ on:
- LICENSE
workflow_dispatch:

env:
GITHUB_ACTIONS: true

jobs:
windows:
strategy:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
workflow_dispatch:

env:
GITHUB_ACTIONS: true
DEVELOPER_DIR: /Applications/Xcode_14.2.app/Contents/Developer

jobs:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/test_pip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
- cron: "0 19 * 1 *"
workflow_dispatch:

env:
GITHUB_ACTIONS: true

jobs:
test:
strategy:
Expand Down
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "src/pybind11"]
path = src/pybind11
url = https://github.com/pybind/pybind11
[submodule "src/realcugan-ncnn-vulkan"]
path = src/realcugan-ncnn-vulkan
url = https://github.com/nihui/realcugan-ncnn-vulkan
[submodule "src/realcugan-ncnn-vulkan/src/ncnn"]
path = src/realcugan-ncnn-vulkan/src/ncnn
url = https://github.com/Tencent/ncnn
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ repos:
rev: v1.7.1
hooks:
- id: mypy
args: [src, tests]
args: [src/realcugan_ncnn_py, tests]
pass_filenames: false
additional_dependencies:
- types-requests
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ license = {text = "BSD-3-Clause"}
name = "realcugan-ncnn-py"
readme = "README.md"
requires-python = ">=3.8"
version = "1.3.2"
version = "1.3.3"

[project.urls]
Homepage = "https://github.com/Final2x/realcugan-ncnn-py"
Expand Down
36 changes: 1 addition & 35 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,40 +230,6 @@ if(NOT USE_SYSTEM_NCNN)
add_subdirectory("realcugan-ncnn-vulkan/src/ncnn")
endif()

if(USE_SYSTEM_WEBP)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
find_package(WebP)
if(NOT TARGET webp)
message(WARNING "webp target not found! USE_SYSTEM_WEBP will be turned off.")
set(USE_SYSTEM_WEBP OFF)
endif()
endif()

if(NOT USE_SYSTEM_WEBP)
# build libwebp library
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/realcugan-ncnn-vulkan/src/libwebp/CMakeLists.txt")
message(FATAL_ERROR "The submodules were not downloaded! Please update submodules with \"git submodule update --init --recursive\" and try again.")
endif()

option(WEBP_ENABLE_SIMD "" ON)
option(WEBP_BUILD_ANIM_UTILS "" OFF)
option(WEBP_BUILD_CWEBP "" OFF)
option(WEBP_BUILD_DWEBP "" OFF)
option(WEBP_BUILD_GIF2WEBP "" OFF)
option(WEBP_BUILD_IMG2WEBP "" OFF)
option(WEBP_BUILD_VWEBP "" OFF)
option(WEBP_BUILD_WEBPINFO "" OFF)
option(WEBP_BUILD_WEBPMUX "" OFF)
option(WEBP_BUILD_EXTRAS "" OFF)
option(WEBP_BUILD_WEBP_JS "" OFF)
option(WEBP_NEAR_LOSSLESS "" OFF)
option(WEBP_ENABLE_SWAP_16BIT_CSP "" OFF)

add_subdirectory(realcugan-ncnn-vulkan/src/libwebp)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/realcugan-ncnn-vulkan/src/libwebp/src)
endif()

realcugan_add_shader(realcugan_preproc.comp)
realcugan_add_shader(realcugan_postproc.comp)
realcugan_add_shader(realcugan_4x_postproc.comp)
Expand Down Expand Up @@ -308,4 +274,4 @@ if(USE_STATIC_MOLTENVK)
${CoreFoundation})
endif()

target_link_libraries(realcugan_ncnn_vulkan_wrapper PRIVATE ${REALCUGAN_LINK_LIBRARIES})
target_link_libraries(realcugan_ncnn_vulkan_wrapper PRIVATE ${REALCUGAN_LINK_LIBRARIES})
1 change: 0 additions & 1 deletion src/realcugan-ncnn-vulkan
Submodule realcugan-ncnn-vulkan deleted from 395302
21 changes: 21 additions & 0 deletions src/realcugan-ncnn-vulkan/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2019 nihui

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
22 changes: 22 additions & 0 deletions src/realcugan-ncnn-vulkan/src/generate_shader_comp_header.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

# must define SHADER_COMP_HEADER SHADER_SRC

file(READ ${SHADER_SRC} comp_data)

# skip leading comment
string(FIND "${comp_data}" "#version" version_start)
string(SUBSTRING "${comp_data}" ${version_start} -1 comp_data)

# remove whitespace
string(REGEX REPLACE "\n +" "\n" comp_data "${comp_data}")

get_filename_component(SHADER_SRC_NAME_WE ${SHADER_SRC} NAME_WE)

# text to hex
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${SHADER_SRC_NAME_WE}.text2hex.txt "${comp_data}")
file(READ ${CMAKE_CURRENT_BINARY_DIR}/${SHADER_SRC_NAME_WE}.text2hex.txt comp_data_hex HEX)
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," comp_data_hex ${comp_data_hex})
string(FIND "${comp_data_hex}" "," tail_comma REVERSE)
string(SUBSTRING "${comp_data_hex}" 0 ${tail_comma} comp_data_hex)

file(WRITE ${SHADER_COMP_HEADER} "static const char ${SHADER_SRC_NAME_WE}_comp_data[] = {${comp_data_hex}};\n")
1 change: 1 addition & 0 deletions src/realcugan-ncnn-vulkan/src/ncnn
Submodule ncnn added at 066614
Loading

0 comments on commit 17ba60e

Please sign in to comment.