commit 9535fa69dea066fba008c4252e9de2e35cca800a
parent c586130ec748d5f8c05072625d3bf6557f145511
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 27 Oct 2023 15:22:34 +0200
Merge branch 'release_0.9'
Diffstat:
| M | .gitignore | | | 13 | ++++++++----- |
| A | Makefile | | | 224 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| M | README.md | | | 104 | ++++++++++++++++++++++++++++++++++++++++++------------------------------------- |
| D | cmake/CMakeLists.txt | | | 196 | ------------------------------------------------------------------------------- |
| A | config.mk | | | 105 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | make.sh | | | 143 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | ssf.pc.in | | | 12 | ++++++++++++ |
7 files changed, 547 insertions(+), 250 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,10 +1,13 @@
.gitignore
-CMakeCache.txt
-CMakeFiles
-Makefile
-tmp
[Bb]uild*
*.sw[po]
-*.[ao]
+*.[aod]
+*.so
*~
+test*
+!test*.[ch]
+.config
+.simd
+.test
tags
+*.pc
diff --git a/Makefile b/Makefile
@@ -0,0 +1,224 @@
+# Copyright (C) 2016-2018, 2021-2023 |Méso|Star> (contact@meso-star.com)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+.POSIX:
+.SUFFIXES: # Clean up default inference rules
+
+include config.mk
+
+LIBNAME_STATIC = libssf.a
+LIBNAME_SHARED = libssf.so
+LIBNAME = $(LIBNAME_$(LIB_TYPE))
+
+################################################################################
+# Star-3D building
+################################################################################
+SRC =\
+ src/ssf.c\
+ src/ssf_beckmann_distribution.c\
+ src/ssf_blinn_distribution.c\
+ src/ssf_bsdf.c\
+ src/ssf_fresnel.c\
+ src/ssf_fresnel_constant.c\
+ src/ssf_fresnel_dielectric_conductor.c\
+ src/ssf_fresnel_dielectric_dielectric.c\
+ src/ssf_fresnel_no_op.c\
+ src/ssf_lambertian_reflection.c\
+ src/ssf_microfacet_distribution.c\
+ src/ssf_microfacet_reflection.c\
+ src/ssf_phase.c\
+ src/ssf_phase_discrete.c\
+ src/ssf_phase_hg.c\
+ src/ssf_phase_rayleigh.c\
+ src/ssf_phase_rdgfa.c\
+ src/ssf_pillbox_distribution.c\
+ src/ssf_specular_dielectric_dielectric_interface.c\
+ src/ssf_specular_reflection.c\
+ src/ssf_thin_specular_dielectric.c
+OBJ = $(SRC:.c=.o)
+DEP = $(SRC:.c=.d)
+
+build_library:
+
+build_library__: .config $(DEP)
+ @$(MAKE) -f.simd -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) \
+ $$(if [ -n "$(LIBNAME)" ]; then\
+ echo "$(LIBNAME)";\
+ else\
+ echo "$(LIBNAME_SHARED)";\
+ fi)
+
+$(DEP) $(OBJ): config.mk .simd
+
+$(LIBNAME_SHARED): $(OBJ)
+ $(CC) $(CFLAGS_SO) $(CFLAGS_SIMD) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(DPDC_LIBS)
+
+$(LIBNAME_STATIC): libssf.o
+ $(AR) -rc $@ $?
+ $(RANLIB) $@
+
+libssf.o: $(OBJ)
+ $(LD) -r $(OBJ) -o $@
+ $(OBJCOPY) $(OCPFLAGS) $@
+
+.config: config.mk .simd
+ @if [ "$(SIMD_WIDTH)" = "128" ] || [ "$(SIMD_WIDTH)" = "256" ]; then \
+ if ! $(PKG_CONFIG) --atleast-version $(RSIMD_VERSION) rsimd; then \
+ echo "rsimd $(RSIMD_VERSION) not found"; exit 1; fi; fi
+ @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \
+ echo "rsys $(RSYS_VERSION) not found"; exit 1; fi
+ @if ! $(PKG_CONFIG) --atleast-version $(SSP_VERSION) star-sp; then \
+ echo "star-sp $(SSP_VERSION) not found"; exit 1; fi
+ @echo "config done" > $@
+
+.simd: make.sh config.mk
+ @$(SHELL) make.sh config_simd $(MAKE) > $@
+
+.SUFFIXES: .c .d .o
+.c.d:
+ @$(CC) $(CFLAGS_SO) $(CFLAGS_SIMD) $(DPDC_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@
+
+.c.o:
+ $(CC) $(CFLAGS_SO) $(CFLAGS_SIMD) $(DPDC_CFLAGS) -DSSF_SHARED_BUILD -c $< -o $@
+
+################################################################################
+# Miscellaneous targets
+################################################################################
+all: build_library build_tests
+
+clean: clean_test
+ rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME)
+ rm -f .config .simd .test libssf.o ssf.pc ssf-local.pc
+
+distclean: clean
+ rm -f $(DEP) $(TEST_DEP)
+
+lint:
+ shellcheck -o all make.sh
+
+build_library build_tests pkg: .simd
+ @$(MAKE) -f.simd -fMakefile $@__
+
+################################################################################
+# Installation
+################################################################################
+PKG_RSIMD = rsimd >= $(RSIMD_VERSION),
+PKG_SIMD_128 = $(PKG_RSIMD)
+PKG_SIMD_256 = $(PKG_RSIMD)
+PKG_SIMD = $(PKG_SIMD_$(SIMD_WIDTH))
+
+pkg__:
+ sed -e 's#@PREFIX@#$(PREFIX)#g'\
+ -e 's#@VERSION@#$(VERSION)#g'\
+ -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
+ -e 's#@SSP_VERSION@#$(SSP_VERSION)#g'\
+ -e 's#@SIMD@#$(PKG_SIMD)#g'\
+ ssf.pc.in > ssf.pc
+
+ssf-local.pc: ssf.pc.in .simd
+ sed -e '1d'\
+ -e 's#^includedir=.*#includedir=./src/#'\
+ -e 's#^libdir=.*#libdir=./#'\
+ -e 's#@VERSION@#$(VERSION)#g'\
+ -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
+ -e 's#@SSP_VERSION@#$(SSP_VERSION)#g'\
+ -e 's#@SIMD@#$(PKG_SIMD)#g'\
+ ssf.pc.in > $@
+
+install: build_library pkg
+ @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME)
+ @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" ssf.pc
+ @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/ssf.h
+ @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/star-sf" COPYING README.md
+
+uninstall:
+ rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)"
+ rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/ssf.pc"
+ rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-sf/COPYING"
+ rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-sf/README.md"
+ rm -f "$(DESTDIR)$(PREFIX)/include/star/ssf.h"
+
+################################################################################
+# Tests
+################################################################################
+TEST_SRC =\
+ src/test_ssf_beckmann_distribution.c\
+ src/test_ssf_blinn_distribution.c\
+ src/test_ssf_bsdf.c\
+ src/test_ssf_fresnel.c\
+ src/test_ssf_fresnel_constant.c\
+ src/test_ssf_fresnel_dielectric_conductor.c\
+ src/test_ssf_fresnel_dielectric_dielectric.c\
+ src/test_ssf_fresnel_no_op.c\
+ src/test_ssf_lambertian_reflection.c\
+ src/test_ssf_microfacet_distribution.c\
+ src/test_ssf_microfacet_reflection.c\
+ src/test_ssf_phase.c\
+ src/test_ssf_phase_discrete.c\
+ src/test_ssf_phase_hg.c\
+ src/test_ssf_phase_rayleigh.c\
+ src/test_ssf_phase_rdgfa.c\
+ src/test_ssf_pillbox_distribution.c\
+ src/test_ssf_specular_dielectric_dielectric_reflection.c\
+ src/test_ssf_specular_reflection.c\
+ src/test_ssf_thin_specular_dielectric.c
+TEST_OBJ = $(TEST_SRC:.c=.o)
+TEST_DEP = $(TEST_SRC:.c=.d)
+
+PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG)
+SSF_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags ssf-local.pc)
+SSF_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs ssf-local.pc)
+
+build_tests__: build_library $(TEST_DEP) .test ssf-local.pc
+ @$(MAKE) -fMakefile -f.test $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) test_bin
+
+test: build_tests .simd
+ @$(SHELL) make.sh run_test $(TEST_SRC)
+
+.test: Makefile
+ @$(SHELL) make.sh config_test $(TEST_SRC) > .test
+
+clean_test:
+ @$(SHELL) make.sh clean_test $(TEST_SRC)
+
+$(TEST_DEP): config.mk ssf-local.pc
+ @$(CC) $(CFLAGS_EXE) $(SSF_CFLAGS) $(RSYS_CFLAGS) $(SSP_CFLAGS) -MM -MT \
+ "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
+
+$(TEST_OBJ): config.mk ssf-local.pc
+ $(CC) $(CFLAGS_EXE) $(SSF_CFLAGS) $(RSYS_CFLAGS) $(SSP_CFLAGS) -c $(@:.o=.c) -o $@
+
+test_ssf_beckmann_distribution \
+test_ssf_blinn_distribution \
+test_ssf_bsdf \
+test_ssf_fresnel \
+test_ssf_fresnel_constant \
+test_ssf_fresnel_dielectric_conductor \
+test_ssf_fresnel_dielectric_dielectric \
+test_ssf_fresnel_no_op \
+test_ssf_lambertian_reflection \
+test_ssf_microfacet_distribution \
+test_ssf_microfacet_reflection \
+test_ssf_phase \
+test_ssf_phase_discrete \
+test_ssf_phase_hg \
+test_ssf_phase_rayleigh \
+test_ssf_phase_rdgfa \
+test_ssf_pillbox_distribution \
+test_ssf_specular_dielectric_dielectric_reflection \
+test_ssf_specular_reflection \
+test_ssf_thin_specular_dielectric \
+: config.mk ssf-local.pc $(LIBNAME)
+ $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(SSF_LIBS) $(RSYS_LIBS) $(SSP_LIBS) -lm
diff --git a/README.md b/README.md
@@ -1,35 +1,40 @@
-# Star-ScatteringFunctions
-
-This library provides a set of abstractions to describe the way the light is
-scattered with respect to a geometric optics model. It defines interfaces to
-describe Bidirectional Scattering Distribution Functions, microfacet
-distributions, Fresnel terms and phase functions. Several built-in
-implementation of these interfaces are provided as specular, lambertian and
-microfacet reflections, Beckmann and Blinn microfacet distributions,
-dielectric/dielectric and dielectric/conductor Fresnel terms, Henyey &
-Greenstein and Rayleigh phase functions, etc.
-
-## How to build
-
-The library uses [CMake](http://www.cmake.org) and the
-[RCMake](https://gitlab.com/vaplv/rcmake/#tab-readme) package to build. It also
-depends on the [Star-SP](https://gitlab.com/meso-star/star-sp/#tab-readme) and
-the [RSys](https://gitlab.com/vaplv/rsys/#tab-readme) libraries. The
-[RSIMD](https://gitlab.com/vaplv/rsimd) library is an optional dependency
-which, if installed, is used to speed up the configuration of the RDG-FA phase
-function.
-
-First ensure that CMake is installed on your system. Then install the RCMake
-package as well as all the aforementioned prerequisites. Finally generate the
-project from the `cmake/CMakeLists.txt` file by appending to the
-`CMAKE_PREFIX_PATH` variable the install directories of its dependencies.
+# Star Scattering Functions
+
+This library provides a set of data structures to describe how light is
+scattered on the surface or in volume. From these interfaces, it
+implements several Bidirectional Scattering Distribution Functions,
+microfacet distributions, Fresnel terms or even phase functions. See the
+`ssf.h` header file for a full list of proposed implementations
+
+## Requirements
+
+- C compiler
+- POSIX make
+- pkg-config
+- [RSys](https://gitlab.com/vaplv/rsys)
+- [Star-SP](https://gitlab.com/meso-star/star-sp)
+- [RSIMD](https://gitlab.com/vaplv/rsimd) (optional)
+
+## Installation
+
+Edit config.mk as needed, then run
+
+ make clean install
## Release notes
+### Version 0.9
+
+- Replace CMake by Makefile as build system.
+- Update compiler and linker flags to increase the security and
+ robustness of generated binaries.
+- Provide a pkg-config file to link the library as an external
+ dependency.
+
### Version 0.8
-Added support for discrete phase functions, i.e. phase functions whose values
-are only defined for a set of angles.
+Added support for discrete phase functions, i.e. phase functions whose
+values are only defined for a set of angles.
### Version 0.7.2
@@ -38,8 +43,8 @@ compilation errors with gcc 11 but introduces API breaks.
### Version 0.7.1
-Fix the evaluation of the RDG-FA phase function: the incident direction was
-reversed.
+Fix the evaluation of the RDG-FA phase function: the incident direction
+was reversed.
### Version 0.7
@@ -48,16 +53,16 @@ Add a built-in phase function using the
### Version 0.6
-- Add the phase function API allowing the user to define, sample and evaluate a
- phase function.
-- Provide built-in implementation of the Henyey & Greenstein, and the Rayleigh
- phase functions.
+- Add the phase function API allowing the user to define, sample and
+ evaluate a phase function.
+- Provide built-in implementation of the Henyey & Greenstein, and the
+ Rayleigh phase functions.
### Version 0.5
- Add the pillbox microfacet distribution.
-- Update the version of the RSys dependency to 0.6: replace the deprecated
- `[N]CHECK` macros by the new macro `CHK`.
+- Update the version of the RSys dependency to 0.6: replace the
+ deprecated `[N]CHECK` macros by the new macro `CHK`.
### Version 0.4
@@ -68,24 +73,25 @@ Add a built-in phase function using the
### Version 0.3
-- A BSDF is no more a composition of BxDFs: the caller writes directly the
- comportment of the BSDF without intermediary abstractions. As a result,
- built-in BxDFs become built-in BSDFs and the BxDF data structure and
- functions are removed from the API.
+- A BSDF is no more a composition of BxDFs: the caller writes directly
+ the comportment of the BSDF without intermediary abstractions. As a
+ result, built-in BxDFs become built-in BSDFs and the BxDF data
+ structure and functions are removed from the API.
### Version 0.2
-- Fix the thin-dielectric material to ensure the energy conservation property.
-- Add the `ssf_specular_dielectric_dielectric_interface` BxDF. This scattering
- function could be built by combining the `ssf_specular_reflection` and the
- `ssf_specular_transmission` BxDFs into a BSDF but such combination does not
- ensure the energy conservation property due to weaknesses into the BSDF
- interface.
+- Fix the thin-dielectric material to ensure the energy conservation
+ property.
+- Add the `ssf_specular_dielectric_dielectric_interface` BxDF. This
+ scattering function could be built by combining the
+ `ssf_specular_reflection` and the `ssf_specular_transmission` BxDFs
+ into a BSDF but such combination does not ensure the energy
+ conservation property due to weaknesses into the BSDF interface.
## License
-Copyright (C) 2016-2018, 2021-2023 |Méso|Star> (<contact@meso-star.com>).
-Star-ScatteringFunctions is free software released under the GPL v3+ license.
-You are welcome to redistribute it under certain conditions; refer to the
-COPYING file for details.
+Copyright (C) 2016-2018, 2021-2023 |Méso|Star> (contact@meso-star.com)
+Star-SF is free software released under the GPL v3+ license. You are
+welcome to redistribute it under certain conditions; refer to the
+COPYING file for details.
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -1,196 +0,0 @@
-# Copyright (C) 2016-2018, 2021-2023 |Méso|Star> (contact@meso-star.com)
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-cmake_minimum_required(VERSION 3.1)
-project(ssf C)
-enable_testing()
-
-option(NO_TEST "Do not compile the test pograms" OFF)
-
-set(SSF_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src)
-
-################################################################################
-# Dependencies
-################################################################################
-find_package(RCMake 0.4 REQUIRED)
-find_package(RSys 0.6 REQUIRED)
-find_package(StarSP 0.12 REQUIRED)
-find_package(RSIMD 0.3)
-if(RSIMD_FOUND)
- option(USE_SIMD "Use SIMD instruction sets" ON)
-endif()
-
-set(CMAKE_MODULE_PATH ${RCMAKE_SOURCE_DIR})
-include(rcmake)
-include(rcmake_runtime)
-
-include_directories(${RSys_INCLUDE_DIR} ${StarSP_INCLUDE_DIR})
-
-set(_dependencies RSys StarSP)
-
-if(USE_SIMD)
- include_directories(${RSIMD_INCLUDE_DIR})
- set(_dependencies ${_dependencies} RSIMD)
-endif()
-
-rcmake_append_runtime_dirs(_runtime_dirs ${_dependencies})
-
-################################################################################
-# Check SIMD support
-################################################################################
-if(NOT USE_SIMD)
- message(STATUS "Do not use the SIMD instruction sets")
-else()
- message(STATUS "Use the SIMD instruction sets")
-
- option(SSF_USE_SIMD_128 "Enable the SIMD-128 instruction sets" ON)
- option(SSF_USE_SIMD_256 "Enable the SIMD-256 instruction sets" ON)
-
- if(SSF_USE_SIMD_128 AND NOT RSIMD_SSE2)
- get_property(_docstring CACHE SSF_USE_SIMD_128 PROPERTY HELPSTRING)
- set(SSF_USE_SIMD_128 OFF CACHE BOOL ${_docstring} FORCE)
- endif()
- if(SSF_USE_SIMD_256 AND NOT RSIMD_AVX)
- get_property(_docstring CACHE SSF_USE_SIMD_256 PROPERTY HELPSTRING)
- set(SSF_USE_SIMD_256 OFF CACHE BOOL ${_docstring} FORCE)
- endif()
-
- if(SSF_USE_SIMD_128)
- set(_simd_size "${_simd_size};SSF_USE_SIMD_128")
- endif()
-
- if(SSF_USE_SIMD_256)
- set(_simd_size "${_simd_size};SSF_USE_SIMD_256")
- endif()
-endif()
-
-################################################################################
-# Define targets
-################################################################################
-set(VERSION_MAJOR 0)
-set(VERSION_MINOR 8)
-set(VERSION_PATCH 0)
-set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
-
-set(SSF_FILES_DOC COPYING README.md)
-set(SSF_FILES_INC_API ssf.h)
-set(SSF_FILES_INC
- ssf_bsdf_c.h
- ssf_fresnel_c.h
- ssf_microfacet_distribution_c.h
- ssf_optics.h
- ssf_phase_c.h)
-set(SSF_FILES_SRC
- ssf.c
- ssf_beckmann_distribution.c
- ssf_blinn_distribution.c
- ssf_bsdf.c
- ssf_fresnel.c
- ssf_fresnel_constant.c
- ssf_fresnel_dielectric_conductor.c
- ssf_fresnel_dielectric_dielectric.c
- ssf_fresnel_no_op.c
- ssf_lambertian_reflection.c
- ssf_microfacet_distribution.c
- ssf_microfacet_reflection.c
- ssf_phase.c
- ssf_phase_discrete.c
- ssf_phase_hg.c
- ssf_phase_rayleigh.c
- ssf_phase_rdgfa.c
- ssf_pillbox_distribution.c
- ssf_specular_dielectric_dielectric_interface.c
- ssf_specular_reflection.c
- ssf_thin_specular_dielectric.c)
-rcmake_prepend_path(SSF_FILES_SRC ${SSF_SOURCE_DIR})
-rcmake_prepend_path(SSF_FILES_INC ${SSF_SOURCE_DIR})
-rcmake_prepend_path(SSF_FILES_INC_API ${SSF_SOURCE_DIR})
-rcmake_prepend_path(SSF_FILES_DOC ${PROJECT_SOURCE_DIR}/../)
-
-if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_GNUCC)
- set(_dependencies ${_dependencies} m)
-endif()
-
-add_library(ssf SHARED ${SSF_FILES_INC} ${SSF_FILES_SRC})
-target_link_libraries(ssf ${_dependencies})
-set_target_properties(ssf PROPERTIES
- DEFINE_SYMBOL SSF_SHARED_BUILD
- COMPILE_DEFINITIONS "${_simd_size}"
- VERSION ${VERSION}
- SOVERSION ${VERSION_MAJOR})
-
-rcmake_setup_devel(ssf StarSF ${VERSION} star/ssf_version.h)
-
-################################################################################
-# Define tests
-################################################################################
-if(NOT NO_TEST)
-
- function(build_test _name)
- add_executable(${_name} ${SSF_SOURCE_DIR}/${_name}.c)
- target_link_libraries(${_name} ssf RSys StarSP ${MATH_LIB})
- endfunction()
-
- function(register_test _name)
- add_test(${_name} ${ARGN})
- endfunction()
-
- function(new_test _name)
- build_test(${_name} ${ARGN})
- register_test(${_name} ${_name})
- endfunction()
-
- new_test(test_ssf_beckmann_distribution)
- new_test(test_ssf_blinn_distribution)
- new_test(test_ssf_pillbox_distribution)
- new_test(test_ssf_bsdf)
- new_test(test_ssf_fresnel)
- new_test(test_ssf_fresnel_constant)
- new_test(test_ssf_fresnel_dielectric_conductor)
- new_test(test_ssf_fresnel_dielectric_dielectric)
- new_test(test_ssf_fresnel_no_op)
- new_test(test_ssf_lambertian_reflection)
- new_test(test_ssf_microfacet_distribution)
- new_test(test_ssf_microfacet_reflection)
- new_test(test_ssf_phase)
- new_test(test_ssf_phase_discrete)
- new_test(test_ssf_phase_hg)
- new_test(test_ssf_phase_rayleigh)
- new_test(test_ssf_specular_dielectric_dielectric_reflection)
- new_test(test_ssf_specular_reflection)
- new_test(test_ssf_thin_specular_dielectric)
-
- build_test(test_ssf_phase_rdgfa)
- register_test(test_ssf_phase_rdgfa_simd_none test_ssf_phase_rdgfa simd_none)
- if(SSF_USE_SIMD_128)
- register_test(test_ssf_phase_rdgfa_simd_128 test_ssf_phase_rdgfa simd_128)
- endif()
- if(SSF_USE_SIMD_256)
- register_test(test_ssf_phase_rdgfa_simd_256 test_ssf_phase_rdgfa simd_256)
- endif()
-
- rcmake_copy_runtime_libraries(test_ssf_beckmann_distribution)
-endif()
-
-################################################################################
-# Install directories
-################################################################################
-install(TARGETS ssf
- ARCHIVE DESTINATION lib
- LIBRARY DESTINATION lib
- RUNTIME DESTINATION bin)
-install(FILES ${SSF_FILES_INC_API} DESTINATION include/star/)
-install(FILES ${SSF_FILES_DOC} DESTINATION share/doc/star-sf/)
-
diff --git a/config.mk b/config.mk
@@ -0,0 +1,105 @@
+VERSION = 0.9.0
+PREFIX = /usr/local
+
+LIB_TYPE = SHARED
+#LIB_TYPE = STATIC
+
+BUILD_TYPE = RELEASE
+#BUILD_TYPE = DEBUG
+
+# If not set, SIMD WIDTH is retrieved from host CPU
+#SIMD_WIDTH = NONE
+#SIMD_WIDTH = 128
+#SIMD_WIDTH = 256
+
+################################################################################
+# Tools
+################################################################################
+AR = ar
+CC = cc
+LD = ld
+OBJCOPY = objcopy
+PKG_CONFIG = pkg-config
+RANLIB = ranlib
+
+################################################################################
+# Dependencies
+################################################################################
+PCFLAGS_STATIC = --static
+PCFLAGS = $(PCFLAGS_$(LIB_TYPE))
+
+RSIMD_VERSION = 0.5
+RSIMD_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsimd)
+RSIMD_CFLAGS_128 = $(RSIMD_CFLAGS)
+RSIMD_CFLAGS_256 = $(RSIMD_CFLAGS)
+RSIMD_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsimd)
+RSIMD_LIBS_128 = $(RSIMD_LIBS)
+RSIMD_LIBS_256 = $(RSIMD_LIBS)
+
+RSYS_VERSION = 0.14
+RSYS_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys)
+RSYS_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys)
+
+SSP_VERSION = 0.14
+SSP_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags star-sp)
+SSP_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs star-sp)
+
+DPDC_CFLAGS_SIMD_128 = $(RSIMD_CFLAGS)
+DPDC_CFLAGS_SIMD_256 = $(RSIMD_CFLAGS)
+DPDC_LIBS_SIMD_128 = $(RSIMD_LIBS)
+DPDC_LIBS_SIMD_256 = $(RSIMD_LIBS)
+
+DPDC_CFLAGS = $(RSIMD_CFLAGS_$(SIMD_WIDTH)) $(RSYS_CFLAGS) $(SSP_CFLAGS)
+DPDC_LIBS = $(RSIMD_LIBS_$(SIMD_WIDTH)) $(RSYS_LIBS) $(SSP_LIBS) -lm
+
+################################################################################
+# Compilation options
+################################################################################
+WFLAGS =\
+ -Wall\
+ -Wcast-align\
+ -Wconversion\
+ -Wextra\
+ -Wmissing-declarations\
+ -Wmissing-prototypes\
+ -Wshadow
+
+CFLAGS_SIMD_128 = -DSSF_USE_SIMD_128
+CFLAGS_SIMD_256 = $(CFLAGS_SIMD_128) -DSSF_USE_SIMD_256
+CFLAGS_SIMD = $(CFLAGS_SIMD_$(SIMD_WIDTH))
+
+CFLAGS_HARDENED =\
+ -D_FORTIFY_SOURCES=2\
+ -fcf-protection=full\
+ -fstack-clash-protection\
+ -fstack-protector-strong
+
+CFLAGS_COMMON =\
+ -std=c89\
+ -pedantic\
+ -fvisibility=hidden\
+ -fstrict-aliasing\
+ $(CFLAGS_HARDENED)\
+ $(WFLAGS)\
+
+CFLAGS_DEBUG = -g $(CFLAGS_COMMON)
+CFLAGS_RELEASE = -O2 -DNDEBUG $(CFLAGS_COMMON)
+CFLAGS = $(CFLAGS_$(BUILD_TYPE))
+
+CFLAGS_SO = $(CFLAGS) -fPIC
+CFLAGS_EXE = $(CFLAGS) -fPIE
+
+################################################################################
+# Linker options
+################################################################################
+LDFLAGS_HARDENED = -Wl,-z,relro,-z,now
+LDFLAGS_DEBUG = $(LDFLAGS_HARDENED)
+LDFLAGS_RELEASE = -s $(LDFLAGS_HARDENED)
+LDFLAGS = $(LDFLAGS_$(BUILD_TYPE))
+
+LDFLAGS_SO = $(LDFLAGS) -shared -Wl,--no-undefined
+LDFLAGS_EXE = $(LDFLAGS) -pie
+
+OCPFLAGS_DEBUG = --localize-hidden
+OCPFLAGS_RELEASE = --localize-hidden --strip-unneeded
+OCPFLAGS = $(OCPFLAGS_$(BUILD_TYPE))
diff --git a/make.sh b/make.sh
@@ -0,0 +1,143 @@
+#!/bin/sh
+
+# Copyright (C) 2016-2018, 2021-2023 |Méso|Star> (contact@meso-star.com)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+set -e
+
+################################################################################
+# Helper functions
+################################################################################
+# Print the value of a variable in config.mk
+showvar()
+{
+ make="$1"
+ # To avoid messages from Make being displayed instead of the value of the
+ # queried variable, we redirect its output to /dev/null and open a new file
+ # descriptor to stdout to print the variable
+<< EOF "${make}" -f 3>&1 1>/dev/null 2>&1 - || kill -HUP $$
+.POSIX:
+include config.mk
+showvar:
+ @1>&3 echo \$($2)
+EOF
+ exec 3<&- # Close file descriptor 3
+}
+
+check_cpuflag()
+{
+ sed -n "/^flags[[:blank:]]\{1,\}:/{p;q}" /proc/cpuinfo \
+| sed "s/.*[[:blank:]]\{1,\}\($1\)[[:blank:]]\{1,\}.*/\1/"
+}
+
+################################################################################
+# Main functions
+################################################################################
+config_simd()
+{
+ make="$1"
+ simd_width="$(showvar "${make}" SIMD_WIDTH)"
+ pkg_config="$(showvar "${make}" PKG_CONFIG)"
+ avx="$(check_cpuflag avx)"
+ if [ -z "${simd_width}" ]; then
+ if ! ${pkg_config} --exists rsimd; then
+ simd_width="NONE"
+ elif [ -n "${avx}" ]; then
+ simd_width="256"
+ else
+ simd_width="128"
+ fi
+ fi
+ printf "SIMD_WIDTH = %s\n" "${simd_width}"
+}
+
+config_test()
+{
+ for i in "$@"; do
+ test=$(basename "${i}" ".c")
+ test_list="${test_list} ${test}"
+ printf "%s: src/%s.o\n" "${test}" "${test}"
+ done
+ printf "test_bin: %s\n" "${test_list}"
+}
+
+check()
+{
+ name="$1"
+ prog="$2"
+ shift 2
+
+ printf "%s " "${name}"
+ if ./"${prog}" "$@" > /dev/null 2>&1; then
+ printf "\033[1;32mOK\033[m\n"
+ else
+ printf "\033[1;31mError\033[m\n"
+ fi 2> /dev/null
+}
+
+run_test()
+{
+ for i in "$@"; do
+ test=$(basename "${i}" ".c")
+ if [ "${test}" != "test_ssf_phase_rdgfa" ]; then
+ check "${test}" "${test}"
+ else
+ macro="SIMD_WIDTH"
+ value="[^[:blank:]]\{0,\}"
+ spaces="[[:space:]]\{0,\}"
+ simd_width=$(sed "s/${macro}${spaces}=${spaces}\(${value}\)${spaces}$/\1/" .simd)
+ if [ "${simd_width}" = "256" ]; then
+ check "${test}_simd_256" "${test}" simd_256
+ fi
+ if [ "${simd_width}" = "256" ] || [ "${simd_width}" = 128 ]; then
+ check "${test}_simd_128" "${test}" simd_128
+ fi
+ check "${test}_simd_none" "${test}" simd_none
+ fi
+ done 2> /dev/null
+}
+
+clean_test()
+{
+ for i in "$@"; do
+ rm -f "$(basename "${i}" ".c")"
+ done
+}
+
+install()
+{
+ prefix=$1
+ shift 1
+
+ for i in "$@"; do
+ # Remove the "src" directory and append the "prefix"
+ dst="${prefix}/${i#*/}"
+
+ # Create the Install directory if required
+ dir="${dst%/*}"
+ if [ ! -d "${dir}" ]; then
+ mkdir -p "${dir}"
+ fi
+
+ if cmp -s "${i}" "${dst}"; then
+ printf "Up to date %s\n" "${dst}"
+ else
+ printf "Installing %s\n" "${dst}"
+ cp "${i}" "${dst}"
+ fi
+ done
+}
+
+"$@"
diff --git a/ssf.pc.in b/ssf.pc.in
@@ -0,0 +1,12 @@
+prefix=@PREFIX@
+includedir=${prefix}/include
+libdir=${prefix}/lib
+
+Requires: rsys >= @RSYS_VERSION@
+Requires.private: @SIMD@ star-sp >= @SSP_VERSION@
+Name: Star Scattering Functions
+Description: Star-SF library
+Version: @VERSION@
+Libs: -L${libdir} -lssf
+Libs.private: -lm
+CFlags: -I${includedir}