Skip to content

Commit

Permalink
Improve output determinism and add internal ktxdiff tool for comparin…
Browse files Browse the repository at this point in the history
…g test outputs (#745)

* Implement internal ktxdiff tool for comparing test output files.
* Fix color conversion overflow.
  • Loading branch information
Császár Mátyás authored Jul 31, 2023
1 parent dab32db commit 7f67af7
Show file tree
Hide file tree
Showing 7 changed files with 564 additions and 5 deletions.
54 changes: 52 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,55 @@ else()
message(FATAL_ERROR "${CMAKE_CXX_COMPILER_ID} not yet supported.")
endif()

# To improve output determinism enable precise floating point operations globally
# This code was based on lib/astc-encoder/Source/cmake_core.cmake

# For Visual Studio prior to 2022 (compiler < 19.30) /fp:strict
# For Visual Studio 2022 (compiler >= 19.30) /fp:precise
# For Visual Studio 2022 ClangCL seems to have accidentally enabled contraction by default,
# so behaves differently to CL.exe. Use the -Xclang argument to workaround and allow access
# GNU-style switch to control contraction and force disable.

# On CMake 3.25 or older CXX_COMPILER_FRONTEND_VARIANT is not always set
if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "")
set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "${CMAKE_CXX_COMPILER_ID}")
endif()

# Compiler accepts MSVC-style command line options
set(is_msvc_fe "$<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},MSVC>")
# Compiler accepts GNU-style command line options
set(is_gnu_fe1 "$<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},GNU>")
# Compiler accepts AppleClang-style command line options, which is also GNU-style
set(is_gnu_fe2 "$<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},AppleClang>")
# Compiler accepts GNU-style command line options
set(is_gnu_fe "$<OR:${is_gnu_fe1},${is_gnu_fe2}>")

# Compiler is Visual Studio cl.exe
set(is_msvccl "$<AND:${is_msvc_fe},$<CXX_COMPILER_ID:MSVC>>")
# Compiler is Visual Studio clangcl.exe
set(is_clangcl "$<AND:${is_msvc_fe},$<CXX_COMPILER_ID:Clang>>")
# Compiler is upstream clang with the standard frontend
set(is_clang "$<AND:${is_gnu_fe},$<CXX_COMPILER_ID:Clang,AppleClang>>")

if(${is_msvccl} AND $<VERSION_LESS:$<CXX_COMPILER_VERSION>,19.30>)
add_compile_options(/fp:strict)
endif()
if(${is_msvccl} AND $<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,19.30>)
add_compile_options(/fp:precise)
endif()
if(${is_clangcl})
add_compile_options(/fp:precise)
endif()
if(${is_clangcl} AND $<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,14.0.0>)
add_compile_options(-Xclang -ffp-contract=off)
endif()
if(${is_clang} AND $<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,10.0.0>)
add_compile_options(-ffp-model=precise)
endif()
if(${is_gnu_fe})
add_compile_options(-ffp-contract=off)
endif()

set(KTX_BUILD_DIR "${CMAKE_BINARY_DIR}")

set(KTX_MAIN_SRC
Expand Down Expand Up @@ -361,10 +410,11 @@ if(WIN32)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY $<1:${KTX_BUILD_DIR}/$<CONFIG>>)
elseif(APPLE)
if(NOT IOS)
# Set a common RUNTIME_OUTPUT_DIR for all targets, so that
# INSTALL RPATH is functional in build directory as well.
# Set a common RUNTIME_OUTPUT_DIR and LIBRARY_OUTPUT_DIR for all targets,
# so that INSTALL RPATH is functional in build directory as well.
# BUILD_WITH_INSTALL_RPATH is necessary for working code signing.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY $<1:${KTX_BUILD_DIR}/$<CONFIG>>)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY $<1:${KTX_BUILD_DIR}/$<CONFIG>>)
endif()
endif()

Expand Down
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ if(KTX_FEATURE_TOOLS)

# ktx cli tool tests
if(KTX_FEATURE_TOOLS_CTS)
add_subdirectory(ktxdiff)
set(KTX_TOOLS_PATH $<TARGET_FILE:ktxtools>)
set(KTX_DIFF_PATH $<TARGET_FILE:ktxdiff>)
add_subdirectory(cts/clitests)
endif()
endif()
2 changes: 1 addition & 1 deletion tests/cts
Submodule cts updated 408 files
44 changes: 44 additions & 0 deletions tests/ktxdiff/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2022-2023 The Khronos Group Inc.
# Copyright 2022-2023 RasterGrid Kft.
# SPDX-License-Identifier: Apache-2.0


add_executable(ktxdiff
ktxdiff_main.cpp
)

set_target_properties(
ktxdiff
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED YES
)

target_include_directories(
ktxdiff
PRIVATE
.
$<TARGET_PROPERTY:ktx,INCLUDE_DIRECTORIES>
)

target_include_directories(
ktxdiff
SYSTEM
PRIVATE
${PROJECT_SOURCE_DIR}/lib
${PROJECT_SOURCE_DIR}/other_include
)

target_link_libraries(
ktxdiff
PRIVATE
ktx
${ASTCENC_LIB_TARGET}
fmt::fmt
)

target_compile_definitions(
ktxdiff
PRIVATE
$<TARGET_PROPERTY:ktx,INTERFACE_COMPILE_DEFINITIONS>
)
Loading

0 comments on commit 7f67af7

Please sign in to comment.