Skip to content

Commit

Permalink
CMake rework, CIs added.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattparks committed May 24, 2019
1 parent 3bfe6d5 commit bb17471
Show file tree
Hide file tree
Showing 51 changed files with 341 additions and 422 deletions.
46 changes: 46 additions & 0 deletions .appveyor.yml
@@ -0,0 +1,46 @@
version: 1.0.5{build}

clone_depth: 5

build:
parallel: true
verbosity: minimal

environment:
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
ARCHITECTURE: x64
GEN: "Visual Studio 15 2017 Win64"
CFG: Debug
BUILD_OUT: "x64-Debug"
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
ARCHITECTURE: x64
GEN: "Visual Studio 15 2017 Win64"
CFG: Release
BUILD_OUT: "x64-Release"
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
ARCHITECTURE: x86
GEN: "Visual Studio 15 2017"
CFG: Debug
BUILD_OUT: "x86-Debug"
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
ARCHITECTURE: x86
GEN: "Visual Studio 15 2017"
CFG: Release
BUILD_OUT: "x86-Release"
NINJA_URL: https://github.com/ninja-build/ninja/releases/download/v1.9.0/ninja-win.zip
MSVC_HOME: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community"

install:
- git submodule update --init --recursive
# Get Ninja
- appveyor DownloadFile %NINJA_URL% -FileName ninja.zip
- 7z x ninja.zip -oC:\ninja > nul
- set PATH=C:\ninja;%PATH%
- ninja --version

build_script:
- call "%MSVC_HOME%\VC\Auxiliary\Build\vcvarsall.bat" %ARCHITECTURE%
- mkdir bin\%BUILD_OUT% && cd bin\%BUILD_OUT%
- cmake -DCMAKE_BUILD_TYPE=%CFG% -GNinja ../../
- ninja
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
.vs/*
out/*
.DS_Store
76 changes: 76 additions & 0 deletions .travis.yml
@@ -0,0 +1,76 @@
matrix:
include:
# GCC 7
- os: linux
dist: xenial
sudo: required
addons: &gcc7
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- pkg-config
- cmake
- g++-7
language: cpp
compiler: gcc
env:
- COMPILER=g++-7
- GSL_CXX_STANDARD=17
- BUILD_TYPE=Release
before_install:
- sudo apt-get update -qq
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 90
# Clang 6.0
- os: linux
dist: xenial
sudo: required
addons: &clang60
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-xenial-6.0
- sourceline: 'deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-6.0 main'
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
packages:
- pkg-config
- cmake
- clang-6.0
- g++-7
language: cpp
compiler: clang
env:
- COMPILER=clang++-6.0
- GSL_CXX_STANDARD=17
- BUILD_TYPE=Release
before_install:
- sudo apt-get update -qq
- sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-6.0 1000
- sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-6.0 1000
- clang --version
# XCode 10.2
- os: osx
osx_image: xcode10.2
sudo: required
language: cpp
compiler: clang
env:
- COMPILER=clang++
- GSL_CXX_STANDARD=17
- BUILD_TYPE=Release
before_install:
- brew update
- brew install pkg-config

script:
- git submodule update --init --recursive
- mkdir bin && cd bin
- |
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=$BUILD_TYPE
make all -j$(nproc)
else
cmake .. -G "Xcode" -DCMAKE_BUILD_TYPE=$BUILD_TYPE
xcodebuild -quiet -parallelizeTargets -jobs $(sysctl -n hw.physicalcpu) -target basisu -configuration $BUILD_TYPE
fi
- cd ../
94 changes: 14 additions & 80 deletions CMakeLists.txt
@@ -1,87 +1,21 @@
project(basisu)
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(basisu VERSION 1.0.5 LANGUAGES C CXX)

cmake_minimum_required(VERSION 3.0)
option(BUILD_X64 "build 64-bit" TRUE)
option(STATIC "static linking" FALSE)
option(BUILD_SHARED_LIBS "Build Shared Libraries" ON)
option(BASISU_BUILD_TOOL "Build the tool" ON)
option(BASISU_INSTALL "Installs basis universal" ON)
option(BASISU_INSTALL_TOOL "Installs the tool" ON)

message("Initial BUILD_X64=${BUILD_X64}")
message("Initial CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
# GNU filesystem conventions
include(GNUInstallDirs)

if( NOT CMAKE_BUILD_TYPE )
set( CMAKE_BUILD_TYPE Release )
endif( NOT CMAKE_BUILD_TYPE )
# Windows build shared libraries
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

message( ${PROJECT_NAME} " build type: " ${CMAKE_BUILD_TYPE} )
find_package(Threads REQUIRED)

if (BUILD_X64)
message("Building 64-bit")
else()
message("Building 32-bit")
endif(BUILD_X64)
add_subdirectory(basisu)

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")

set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")

set(CMAKE_CXX_FLAGS -std=c++11)
set(GCC_COMPILE_FLAGS "-fvisibility=hidden -fvisibility-inlines-hidden -fPIC -fopenmp -fno-strict-aliasing -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 -Wall -Wextra -Wno-unused-local-typedefs -Wno-unused-value -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-unused-variable -Wno-reorder")

if (NOT BUILD_X64)
set(GCC_COMPILE_FLAGS "${GCC_COMPILE_FLAGS} -m32")
if(BASISU_BUILD_TOOL)
add_subdirectory(tool)
endif()

if (STATIC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_LINK_FLAGS} -static-libgcc -static-libstdc++ -static")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_LINK_FLAGS} -Wl,-rpath .")
endif(STATIC)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GCC_COMPILE_FLAGS}")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${GCC_COMPILE_FLAGS}")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${GCC_COMPILE_FLAGS} -D_DEBUG")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COMPILE_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${GCC_COMPILE_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${GCC_COMPILE_FLAGS} -D_DEBUG")

set(BASISU_SRC_LIST ${COMMON_SRC_LIST}
basisu_backend.cpp
basisu_basis_file.cpp
basisu_comp.cpp
basisu_enc.cpp
basisu_etc.cpp
basisu_frontend.cpp
basisu_global_selector_palette_helpers.cpp
basisu_gpu_texture.cpp
basisu_pvrtc1_4.cpp
basisu_resampler.cpp
basisu_resample_filters.cpp
basisu_ssim.cpp
basisu_tool.cpp
lodepng.cpp
transcoder/basisu_transcoder.cpp
)

if (APPLE)
set(BIN_DIRECTORY "bin_osx")
else()
set(BIN_DIRECTORY "bin")
endif()

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/${BIN_DIRECTORY})

add_executable(basisu ${BASISU_SRC_LIST})
target_link_libraries(basisu m pthread)

install(TARGETS basisu DESTINATION bin)

if (CMAKE_BUILD_TYPE STREQUAL Release)
if (APPLE)
add_custom_command(TARGET basisu POST_BUILD COMMAND strip -X -x ${CMAKE_SOURCE_DIR}/${BIN_DIRECTORY}/basisu)
else()
add_custom_command(TARGET basisu POST_BUILD COMMAND strip -g -X -x ${CMAKE_SOURCE_DIR}/${BIN_DIRECTORY}/basisu)
endif()
endif()

41 changes: 23 additions & 18 deletions README.md
@@ -1,4 +1,8 @@
# basis_universal

[![Build status](https://ci.appveyor.com/api/projects/status/vj7gnik7fo6indw7?svg=true)](https://ci.appveyor.com/project/Mattparks/basis_universal)
[![Build Status](https://travis-ci.org/mattparks/basis_universal.svg?branch=master)](https://travis-ci.org/mattparks/basis_universal)

Basis Universal GPU Texture and Texture Video Compression Reference Codec

Basis Universal is a ["supercompressed"](http://gamma.cs.unc.edu/GST/gst.pdf) GPU texture and texture video compression system that outputs a highly compressed intermediate file format (.basis) that can be quickly transcoded to a wide variety of GPU texture compression formats: PVRTC1 4bpp RGB, BC7 mode 6 RGB, BC1-5, ETC1, and ETC2. We will be adding ASTC RGB or RGBA, BC7 mode 4/5 RGBA, and PVRTC1 4bpp RGBA next. Basis files support non-uniform texture arrays, so cubemaps, volume textures, texture arrays, mipmap levels, video sequences, or arbitrary texture "tiles" can be stored in a single file. The compressor is able to exploit color and pattern correlations across the entire file, so multiple images with mipmaps can be stored very efficiently in a single file.
Expand All @@ -21,12 +25,13 @@ The encoder uses [lodepng](https://lodev.org/lodepng/) for loading and saving PN

### Command Line Compression Tool

The command line tool used to create, validate, and transcode/unpack .basis files is named "basisu". Run basisu without any parameters for help. Note this tool uses the reference encoder.
The command line tool used to create, validate, and transcode/unpack .basis files is named "basisuTool". Run basisuTool without any parameters for help. Note this tool uses the reference encoder.

To build basisu:

```
cmake CMakeLists.txt
mkdir bin && cd bin
cmake ..
make
```

Expand All @@ -42,23 +47,23 @@ make

To compress a sRGB image to .basis:

`basisu x.png`
`basisuTool x.png`

Note that basisu defaults to sRGB colorspace metrics. If the input is a normal map, or some other type of non-sRGB (non-photographic) texture content, be sure to use -linear to avoid extra unnecessary artifacts.

To add automatically generated mipmaps to the .basis file, at a higher than default quality level (which ranges from [1,255]):

`basisu -mipmap -mip_srgb -q 190 x.png`
`basisuTool -mipmap -mip_srgb -q 190 x.png`

There are several mipmap options that allow you to change the filter kernel, the smallest mipmap dimension, etc. The tool also supports generating cubemap files, 2D/cubemap texture arrays, etc.

To create a higher quality .basis file (one with better codebooks):

`basisu -slower x.png`
`basisuTool -slower x.png`

To unpack a .basis file to multiple .png/.ktx files:

`basisu x.basis`
`basisuTool x.basis`

The mipmapped .KTX files will be in a variety of compressed GPU texture formats (PVRTC1 4bpp, ETC1-2, BC1-5, BC7), and to my knowledge there is no single .KTX viewer tool that correctly and reliably supports every GPU texture format that we support. BC1-5 and BC7 files are viewable using AMD's Compressonator, ETC1/2 using Mali's Texture Compression Tool, and PVRTC1 using Imagination Tech's PVRTexTool. Links:

Expand All @@ -74,13 +79,13 @@ For best quality, you must supply basisu with original uncompressed source image

For the maximum possible achievable quality with the current format and encoder, use:

`basisu x.png -slower -max_endpoints 16128 -max_selectors 16128 -no_selector_rdo -no_endpoint_rdo`
`basisuTool x.png -slower -max_endpoints 16128 -max_selectors 16128 -no_selector_rdo -no_endpoint_rdo`

Note that "-no_selector_rdo -no_endpoint_rdo" are optional. Using them hurts rate distortion performance, but increases quality. An alternative is to use -selector_rdo_thresh X and -endpoint_rdo_thresh, with X ranging from [1,2] (higher=lower quality/better compression - see the tool's help text).

To compress small video sequences, say using tools like ffmpeg and VirtualDub:

'basisu -slower -tex_type video -stats -debug -multifile_printf "pic%04u.png" -multifile_num 200 -multifile_first 1 -max_selectors 16128 -max_endpoints 16128'
'basisuTool -slower -tex_type video -stats -debug -multifile_printf "pic%04u.png" -multifile_num 200 -multifile_first 1 -max_selectors 16128 -max_endpoints 16128'

The reference encoder will take a LONG time and a lot of CPU to encode video, especially with -slower. The more cores your machine has, the better. Basis is intended for smaller videos of a few dozen seconds or so. If you are very patient and have a Threadripper or Xeon workstation, you should be able to encode up to a few thousand 720P frames.

Expand All @@ -92,34 +97,34 @@ If you are doing rate distortion comparisons vs. other similar systems, be sure

### More detailed examples

`basisu x.png`\
`basisuTool x.png`\
Compress sRGB image x.png to x.basis using default settings (multiple filenames OK)

`basisu x.basis`\
`basisuTool x.basis`\
Unpack x.basis to PNG/KTX files (multiple filenames OK)

`basisu -file x.png -mipmap -mip_srgb -y_flip`\
`basisuTool -file x.png -mipmap -mip_srgb -y_flip`\
Compress a mipmapped x.basis file from an sRGB image named x.png, Y flip each source image

`basisu -validate -file x.basis`\
`basisuTool -validate -file x.basis`\
Validate x.basis (check header, check file CRC's, attempt to transcode all slices)

`basisu -unpack -file x.basis`\
`basisuTool -unpack -file x.basis`\
Validates, transcodes and unpacks x.basis to mipmapped .KTX and RGB/A .PNG files (transcodes to all supported GPU texture formats)

`basisu -q 255 -file x.png -mipmap -mip_srgb -debug -stats`\
`basisuTool -q 255 -file x.png -mipmap -mip_srgb -debug -stats`\
Compress sRGB x.png to x.basis at quality level 255 with compressor debug output/statistics

`basisu -linear -max_endpoints 16128 -max_selectors 16128 -file x.png`\
`basisuTool -linear -max_endpoints 16128 -max_selectors 16128 -file x.png`\
Compress non-sRGB x.png to x.basis using the largest supported manually specified codebook sizes

`basisu -linear -global_sel_pal -no_hybrid_sel_cb -file x.png`\
`basisuTool -linear -global_sel_pal -no_hybrid_sel_cb -file x.png`\
Compress a non-sRGB image, use virtual selector codebooks for improved compression (but slower encoding)

`basisu -linear -global_sel_pal -file x.png`\
`basisuTool -linear -global_sel_pal -file x.png`\
Compress a non-sRGB image, use hybrid selector codebooks for slightly improved compression (but slower encoding)

`basisu -tex_type video -framerate 20 -multifile_printf "x%02u.png" -multifile_first 1 -multifile_count 20`\
`basisuTool -tex_type video -framerate 20 -multifile_printf "x%02u.png" -multifile_first 1 -multifile_count 20`\
Compress a 20 sRGB source image video sequence (x01.png, x02.png, x03.png, etc.) to x01.basis


Expand Down
31 changes: 0 additions & 31 deletions basisu.sln

This file was deleted.

0 comments on commit bb17471

Please sign in to comment.