Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Vulkan SDK for macOS CI. #688

Merged
merged 6 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# environment variables so it is easier to explicitly specify the linux
# jobs.
os: osx
osx_image: xcode13.2
osx_image: xcode14.2

language: cpp

Expand All @@ -31,7 +31,7 @@ env:
- GIT_LFS_SKIP_SMUDGE: 1
- PACKAGE: NO
- REL_DESC_FILE: "$BUILD_DIR/rel_desc.md"
- VULKAN_SDK_VER: "1.2.176.1"
- VULKAN_SDK_VER: "1.3.243.0"
# This is just to tell the Vulkan install script where to install.
- VULKAN_INSTALL_DIR: "$HOME/VulkanSDK/$VULKAN_SDK_VER"
- VULKAN_SDK: "$VULKAN_INSTALL_DIR/macOS"
Expand Down
23 changes: 22 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ else()
endif()

set(KTX_MAIN_SRC
include/KHR/khr_df.h
include/ktx.h
lib/basis_sgd.h
lib/basis_transcode.cpp
Expand Down Expand Up @@ -303,7 +304,11 @@ macro(commom_lib_settings lib write)
endif()

set_target_properties(${lib} PROPERTIES
PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/include/ktx.h
PUBLIC_HEADER
# "${CMAKE_CURRENT_SOURCE_DIR}/include/ktx.h;${CMAKE_CURRENT_SOURCE_DIR}/include/KHR/khr_df.h"
# Omit khr_df.h. Its installation has to be handled separately to
# workaround CMake's failure to preserve the directory hierarchy.
"${CMAKE_CURRENT_SOURCE_DIR}/include/ktx.h"
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME "YES"
Expand Down Expand Up @@ -992,6 +997,22 @@ else()
)
endif()

# Use of this to install KHR/khr_df.h is due to CMake's failure to
# preserve the include source folder hierarchy.
# See https://gitlab.kitware.com/cmake/cmake/-/issues/16739.
if (IOS)
set_source_files_properties(
include/KHR/khr_df.h
PROPERTIES MACOSX_PACKAGE_LOCATION Headers/KHR
)
else()
include(GNUInstallDirs)
install(FILES include/KHR/khr_df.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/KHR
COMPONENT dev
)
endif()

install(EXPORT KTXTargets
FILE KtxTargets.cmake
NAMESPACE KTX::
Expand Down
4 changes: 2 additions & 2 deletions ci_scripts/build_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export PATH="${VULKAN_SDK}/bin:$PATH"
# destination args can be expanded to a single word.
OSX_XCODE_OPTIONS=(-alltargets -destination "platform=OS X,arch=x86_64")
IOS_XCODE_OPTIONS=(-alltargets -destination "generic/platform=iOS" -destination "platform=iOS Simulator,OS=latest")
XCODE_CODESIGN_ENV='CODE_SIGN_IDENTITY= CODE_SIGN_ENTITLEMENTS= CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO'
XCODE_NO_CODESIGN_ENV='CODE_SIGN_IDENTITY= CODE_SIGN_ENTITLEMENTS= CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO'

if which -s xcpretty ; then
function handle_compiler_output() {
Expand Down Expand Up @@ -107,7 +107,7 @@ do
if [ -n "$MACOS_CERTIFICATES_P12" -a "$config" = "Release" ]; then
cmake --build . --config $config | handle_compiler_output
else
cmake --build . --config $config -- CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO | handle_compiler_output
cmake --build . --config $config -- $XCODE_NO_CODESIGN_ENV | handle_compiler_output
fi

# Rosetta 2 should let x86_64 tests run on an Apple Silicon Mac hence the -o.
Expand Down
2 changes: 1 addition & 1 deletion ci_scripts/install_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if [ "$FEATURE_LOADTESTS" = "ON" ]; then
os_codename=${os_codename#VERSION_CODENAME=}

echo "Download Vulkan SDK"
wget -O - https://packages.lunarg.com/lunarg-signing-key-pub.asc | sudo apt-key add -
wget --no-verbose -O - https://packages.lunarg.com/lunarg-signing-key-pub.asc | sudo apt-key add -
sudo wget -O /etc/apt/sources.list.d/lunarg-vulkan-$VULKAN_SDK_VER-$os_codename.list https://packages.lunarg.com/vulkan/$VULKAN_SDK_VER/lunarg-vulkan-$VULKAN_SDK_VER-$os_codename.list
echo "Install Vulkan SDK"
sudo apt update
Expand Down
12 changes: 9 additions & 3 deletions ci_scripts/install_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ done

FEATURE_LOADTESTS=${FEATURE_LOADTESTS:-ON}
PLATFORM=${PLATFORM:-macOS}
VULKAN_SDK_VER=${VULKAN_SDK_VER:-1.3.243.0}

git lfs install
git lfs version
Expand All @@ -30,10 +31,15 @@ if [ "$FEATURE_LOADTESTS" = "ON" ]; then

# Current dir. is .../build/{KhronosGroup,msc-}/KTX-Software. cd to 'build'.
pushd ../..
wget -O vulkansdk-macos-$VULKAN_SDK_VER.dmg https://sdk.lunarg.com/sdk/download/$VULKAN_SDK_VER/mac/vulkansdk-macos-$VULKAN_SDK_VER.dmg?Human=true
curl -s -S -o vulkansdk-macos-$VULKAN_SDK_VER.dmg https://sdk.lunarg.com/sdk/download/$VULKAN_SDK_VER/mac/vulkansdk-macos-$VULKAN_SDK_VER.dmg?Human=true
hdiutil attach vulkansdk-macos-$VULKAN_SDK_VER.dmg
sudo /Volumes/vulkansdk-macos-$VULKAN_SDK_VER/InstallVulkan.app/Contents/macOS/InstallVulkan --root "$VULKAN_INSTALL_DIR" --accept-licenses --default-answer --confirm-command install
hdiutil detach /Volumes/vulkansdk-macos-$VULKAN_SDK_VER
sudo /Volumes/VulkanSDK/InstallVulkan.app/Contents/MacOS/InstallVulkan --root "$VULKAN_INSTALL_DIR" --accept-licenses --default-answer --confirm-command install
#hdiutil detach /Volumes/VulkanSDK
set +e
while hdiutil detach /Volumes/VulkanSDK; es=$?; [[ $ss -eq 16 ]]; do
lsof /Volumes/VulkanSDK
sleep 10
done
rm vulkansdk-macos-$VULKAN_SDK_VER.dmg
popd
fi
File renamed without changes.
9 changes: 9 additions & 0 deletions include/ktx.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <stdbool.h>
#include <sys/types.h>

#include <KHR/khr_df.h>

/*
* Don't use khrplatform.h in order not to break apps existing
* before these definitions were needed.
Expand Down Expand Up @@ -1058,9 +1060,16 @@ ktxTexture2_GetComponentInfo(ktxTexture2* This, ktx_uint32_t* numComponents,
KTX_API ktx_uint32_t KTX_APIENTRY
ktxTexture2_GetNumComponents(ktxTexture2* This);

KTX_API khr_df_transfer_e KTX_APIENTRY
ktxTexture2_GetOETF_e(ktxTexture2* This);

// For backward compatibility
KTX_API ktx_uint32_t KTX_APIENTRY
ktxTexture2_GetOETF(ktxTexture2* This);

KTX_API khr_df_model_e KTX_APIENTRY
ktxTexture2_GetColorModel_e(ktxTexture2* This);

KTX_API ktx_bool_t KTX_APIENTRY
ktxTexture2_GetPremultipliedAlpha(ktxTexture2* This);

Expand Down
3 changes: 1 addition & 2 deletions lib/glloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -925,8 +925,7 @@ ktxTexture1_GLUpload(ktxTexture1* This, GLuint* pTexture, GLenum* pTarget,
formatInfo.glInternalformat = This->glInternalformat;
formatInfo.glBaseInternalformat = This->glBaseInternalformat;
formatInfo.glType = This->glType;
formatInfo.glFormat = This->glFormat;


result = ktxTexture_GLUploadPrivate(ktxTexture(This), &formatInfo,
pTexture, pTarget, pGlerror);

Expand Down
11 changes: 10 additions & 1 deletion lib/mainpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,16 @@ if (ktxTexture2_NeedsTranscoding(texture)) {
// supported and pick a format. For example
vk::PhysicalDeviceFeatures deviceFeatures;
vkctx.gpu.getFeatures(&deviceFeatures);
if (deviceFeatures.textureCompressionETC2)
khr_df_model_e colorModel = ktxTexture2_GetColorModel_e(texture);
if (colorModel == KHR_DF_MODEL_UASTC
&& deviceFeatures.textureCompressionASTC_LDR) {
tf = KTX_TTF_ASTC_4x4_RGBA;
} else if (colorModel == KHR_DF_MODEL_ETC1S
&& deviceFeatures.textureCompressionETC2) {
tf = KTX_TTF_ETC;
} else if (deviceFeatures.textureCompressionASTC_LDR) {
tf = KTX_TTF_ASTC_4x4_RGBA;
} else if (deviceFeatures.textureCompressionETC2)
tf = KTX_TTF_ETC2_RGBA;
else if (deviceFeatures.textureCompressionBC)
tf = KTX_TTF_BC3_RGBA;
Expand Down
40 changes: 36 additions & 4 deletions lib/texture2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1758,22 +1758,54 @@ ktxTexture2_GetImageOffset(ktxTexture2* This, ktx_uint32_t level,
*
* @param[in] This pointer to the ktxTexture2 object of interest.
*
* @return A KHR_DF enum value specifying the OETF.
* @return A @c khr_df_transfer enum value specifying the OETF.
*/
khr_df_transfer_e
ktxTexture2_GetOETF_e(ktxTexture2* This)
{
return KHR_DFDVAL(This->pDfd+1, TRANSFER);
}

/**
* @memberof ktxTexture2
* @~English
* @brief Retrieve the opto-electrical transfer function of the images.
* @deprecated Retained for backward compatibility. Use ktxTexture2\_GetOETF\_e()
*
* @param[in] This pointer to the ktxTexture2 object of interest.
*
* @return A @c khr_df_transfer enum value specifying the OETF, returned as
* @c ktx_uint32_t.
*/
ktx_uint32_t
ktxTexture2_GetOETF(ktxTexture2* This)
{
return KHR_DFDVAL(This->pDfd+1, TRANSFER);
}

/**
* @memberof ktxTexture2
* @~English
* @brief Retrieve the DFD color model of the images.
*
* @param[in] This pointer to the ktxTexture2 object of interest.
*
* @return A @c khr_df_transfer enum value specifying the color model.
*/
khr_df_model_e
ktxTexture2_GetColorModel_e(ktxTexture2* This)
{
return KHR_DFDVAL(This->pDfd+1, MODEL);
}

/**
* @memberof ktxTexture2
* @~English
* @brief Retrieve whether the RGB components have been premultiplied by the alpha component.
*
* @param[in] This pointer to the ktxTexture2 object of interest.
*
* @return KTX_TRUE if the components are premultiplied, KTX_FALSE otherwise.
* @return KTX\_TRUE if the components are premultiplied, KTX_FALSE otherwise.
*/
ktx_bool_t
ktxTexture2_GetPremultipliedAlpha(ktxTexture2* This)
Expand All @@ -1784,14 +1816,14 @@ ktxTexture2_GetPremultipliedAlpha(ktxTexture2* This)
/**
* @memberof ktxTexture2
* @~English
* @brief Query if the texture is in a transcodable format.
* @brief Query if the images are in a transcodable format.
*
* @param[in] This pointer to the ktxTexture2 object of interest.
*/
ktx_bool_t
ktxTexture2_NeedsTranscoding(ktxTexture2* This)
{
if (This->supercompressionScheme == KTX_SS_BASIS_LZ)
if (KHR_DFDVAL(This->pDfd + 1, MODEL) == KHR_DF_MODEL_ETC1S)
return true;
else if (KHR_DFDVAL(This->pDfd + 1, MODEL) == KHR_DF_MODEL_UASTC)
return true;
Expand Down
1 change: 1 addition & 0 deletions tests/loadtests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ if(APPLE AND IOS)
find_library(CoreMotion_LIBRARY CoreMotion)
find_library(Foundation_LIBRARY Foundation)
find_library(GameController_LIBRARY GameController)
find_library(IOSurface_LIBRARY IOSurface)
find_library(Metal_LIBRARY Metal)
find_library(OpenGLES_LIBRARY OpenGLES)
find_library(QuartzCore_LIBRARY QuartzCore)
Expand Down
44 changes: 25 additions & 19 deletions tests/loadtests/glloadtests/utils/GLTextureTranscoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,17 @@
class TextureTranscoder {
public:
TextureTranscoder() {
compressedTexFeatures features;

determineCompressedTexFeatures(features);
if (features.astc_ldr)
tf = KTX_TTF_ASTC_4x4_RGBA;
else if (features.bc3)
tf = KTX_TTF_BC1_OR_3;
else if (features.etc2)
tf = KTX_TTF_ETC; // Let transcoder decide between RGB or RGBA
else if (features.pvrtc1)
tf = KTX_TTF_PVRTC1_4_RGBA;
else if (features.etc1)
tf = KTX_TTF_ETC1_RGB;
determineCompressedTexFeatures(deviceFeatures);
if (deviceFeatures.astc_ldr)
defaultTf = KTX_TTF_ASTC_4x4_RGBA;
else if (deviceFeatures.bc3)
defaultTf = KTX_TTF_BC1_OR_3;
else if (deviceFeatures.etc2)
defaultTf = KTX_TTF_ETC; // Let transcoder decide RGB or RGBA
else if (deviceFeatures.pvrtc1)
defaultTf = KTX_TTF_PVRTC1_4_RGBA;
else if (deviceFeatures.etc1)
defaultTf = KTX_TTF_ETC1_RGB;
else {
std::stringstream message;

Expand All @@ -52,8 +50,19 @@ class TextureTranscoder {
void transcode(ktxTexture2* kTexture,
ktx_transcode_fmt_e otf = KTX_TTF_NOSELECTION) {
KTX_error_code ktxresult;
if (otf != KTX_TTF_NOSELECTION)
ktx_transcode_fmt_e tf;
if (otf != KTX_TTF_NOSELECTION) {
tf = otf;
} else {
khr_df_model_e colorModel = ktxTexture2_GetColorModel_e(kTexture);
if (colorModel == KHR_DF_MODEL_UASTC && deviceFeatures.astc_ldr) {
tf = KTX_TTF_ASTC_4x4_RGBA;
} else if (colorModel == KHR_DF_MODEL_ETC1S && deviceFeatures.etc2) {
tf = KTX_TTF_ETC;
} else {
tf = defaultTf;
}
}
ktxresult = ktxTexture2_TranscodeBasis(kTexture, tf, 0);
if (KTX_SUCCESS != ktxresult) {
std::stringstream message;
Expand All @@ -65,11 +74,8 @@ class TextureTranscoder {
}
}

ktx_transcode_fmt_e getFormat() { return tf; }


protected:
ktx_transcode_fmt_e tf;
ktx_transcode_fmt_e defaultTf;

struct compressedTexFeatures {
bool astc_ldr;
Expand All @@ -83,7 +89,7 @@ class TextureTranscoder {
bool pvrtc_srgb;
bool pvrtc2;
bool rgtc;
};
} deviceFeatures;

void determineCompressedTexFeatures(compressedTexFeatures& features) {
ktx_int32_t numCompressedFormats;
Expand Down
1 change: 1 addition & 0 deletions tests/loadtests/vkloadtests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ if(APPLE)
${CoreHaptics_LIBRARY}
${Foundation_LIBRARY}
${GameController_LIBRARY}
${IOSurface_LIBRARY}
${Metal_LIBRARY}
${MOLTENVK_FRAMEWORK}
${OpenGLES_LIBRARY}
Expand Down
28 changes: 19 additions & 9 deletions tests/loadtests/vkloadtests/utils/VulkanTextureTranscoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@
class TextureTranscoder {
public:
TextureTranscoder(VulkanContext& vkctx) {
vk::PhysicalDeviceFeatures deviceFeatures;
vkctx.gpu.getFeatures(&deviceFeatures);

if (deviceFeatures.textureCompressionASTC_LDR)
tf = KTX_TTF_ASTC_4x4_RGBA;
defaultTf = KTX_TTF_ASTC_4x4_RGBA;
else if (deviceFeatures.textureCompressionETC2)
tf = KTX_TTF_ETC;
defaultTf = KTX_TTF_ETC;
else if (deviceFeatures.textureCompressionBC)
tf = KTX_TTF_BC1_OR_3;
defaultTf = KTX_TTF_BC1_OR_3;
else if (vkctx.enabledDeviceExtensions.pvrtc) {
tf = KTX_TTF_PVRTC2_4_RGBA;
defaultTf = KTX_TTF_PVRTC2_4_RGBA;
} else {
std::stringstream message;

Expand All @@ -37,6 +36,19 @@ class TextureTranscoder {

void transcode(ktxTexture2* kTexture) {
KTX_error_code ktxresult;
ktx_transcode_fmt_e tf;
khr_df_model_e colorModel = ktxTexture2_GetColorModel_e(kTexture);

if (colorModel == KHR_DF_MODEL_UASTC
&& deviceFeatures.textureCompressionASTC_LDR) {
tf = KTX_TTF_ASTC_4x4_RGBA;
} else if (colorModel == KHR_DF_MODEL_ETC1S
&& deviceFeatures.textureCompressionETC2) {
tf = KTX_TTF_ETC;
} else {
tf = defaultTf;
}

ktxresult = ktxTexture2_TranscodeBasis(kTexture, tf, 0);
if (KTX_SUCCESS != ktxresult) {
std::stringstream message;
Expand All @@ -48,9 +60,7 @@ class TextureTranscoder {
}
}

ktx_transcode_fmt_e getFormat() { return tf; }

protected:
ktx_transcode_fmt_e tf;

ktx_transcode_fmt_e defaultTf;
vk::PhysicalDeviceFeatures deviceFeatures;
};
2 changes: 1 addition & 1 deletion utils/scapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ scApp::encode(ktxTexture2* texture, const string& swizzle,
{
ktx_error_code_e result;

ktx_uint32_t oetf = ktxTexture2_GetOETF(texture);
khr_df_transfer_e oetf = ktxTexture2_GetOETF_e(texture);
if (options.normalMode && oetf != KHR_DF_TRANSFER_LINEAR) {
cerr << name << ": "
<< "--normal_mode specified but input file(s) are not "
Expand Down