Skip to content
Open
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
1 change: 1 addition & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ source_group("\\" FILES ${SRC})

# select target type based on platform
if(ANDROID)
list(APPEND SRC android/sample_list_jni.cpp)
if(CMAKE_VS_NsightTegra_VERSION)
list(APPEND SRC ${CMAKE_CURRENT_SOURCE_DIR}/android/AndroidManifest.xml)
endif()
Expand Down
59 changes: 59 additions & 0 deletions app/android/sample_list_jni.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* Copyright (c) 2026, Holochip Corporation
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// Lists the available samples to the Android launcher activity.
//
// This lives in the app, rather than in the framework, because it needs the generated sample registry (apps.h), and the
// framework must not depend on the registry.

#include <jni.h>

#include "apps.h"

extern "C"
{
JNIEXPORT jobjectArray JNICALL
Java_com_khronos_vulkan_1samples_SampleLauncherActivity_getSamples(JNIEnv *env, jobject thiz)
{
auto sample_list = apps::get_samples();

jclass c = env->FindClass("com/khronos/vulkan_samples/model/Sample");
jmethodID constructor = env->GetMethodID(c, "<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V");
jobjectArray j_sample_list = env->NewObjectArray(sample_list.size(), c, 0);

for (int sample_index = 0; sample_index < sample_list.size(); sample_index++)
{
const apps::SampleInfo *sample_info = reinterpret_cast<apps::SampleInfo *>(sample_list[sample_index]);

jstring id = env->NewStringUTF(sample_info->id.c_str());
jstring category = env->NewStringUTF(sample_info->category.c_str());
jstring author = env->NewStringUTF(sample_info->author.c_str());
jstring name = env->NewStringUTF(sample_info->name.c_str());
jstring desc = env->NewStringUTF(sample_info->description.c_str());

jobjectArray j_tag_list = env->NewObjectArray(sample_info->tags.size(), env->FindClass("java/lang/String"), env->NewStringUTF(""));
for (int tag_index = 0; tag_index < sample_info->tags.size(); ++tag_index)
{
env->SetObjectArrayElement(j_tag_list, tag_index, env->NewStringUTF(sample_info->tags[tag_index].c_str()));
}

env->SetObjectArrayElement(j_sample_list, sample_index, env->NewObject(c, constructor, id, category, author, name, desc, j_tag_list));
}

return j_sample_list;
}
}
21 changes: 14 additions & 7 deletions app/apps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2024, Arm Limited and Contributors
# Copyright (c) 2020-2026, Arm Limited and Contributors
#
# SPDX-License-Identifier: Apache-2.0
#
Expand Down Expand Up @@ -62,18 +62,25 @@ set(SRC
add_library(${PROJECT_NAME} STATIC ${SRC})

target_link_libraries(${PROJECT_NAME} PUBLIC framework)
target_include_directories(${PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/samples)

# Link all samples
set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) # must match the PCH owner
if(VKB_USE_PCH)
target_precompile_headers(${PROJECT_NAME} REUSE_FROM framework)
endif()
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
# apps.cpp includes "<category>/<sample>/<sample>.h"
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/samples)

# Link all samples.
# PRIVATE on purpose: apps.cpp is the only thing that needs the samples' headers, and the samples' include directories
# must not propagate to everything that links apps (that used to add ~200 -I paths to every compilation command).
# The static libraries are still passed to the linker of the final executable (CMake's $<LINK_ONLY:...>).
set(PROJECT_ID_LIST ${TOTAL_SAMPLE_ID_LIST})
foreach(ID ${PROJECT_ID_LIST})
if(TARGET ${ID})
get_target_property(TARGET_TYPE ${ID} TYPE)

if(TARGET_TYPE STREQUAL "OBJECT_LIBRARY" OR TARGET_TYPE STREQUAL "STATIC_LIBRARY")
target_link_libraries(${PROJECT_NAME} PUBLIC ${ID})
target_link_libraries(${PROJECT_NAME} PRIVATE ${ID})
endif()
endif()
endforeach()
Expand Down
42 changes: 2 additions & 40 deletions app/apps/apps.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2020-2024, Arm Limited and Contributors
/* Copyright (c) 2020-2026, Arm Limited and Contributors
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -17,13 +17,10 @@

#pragma once

#include <functional>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>

#include "platform/application.h"
#include "platform/app_info.h"

/*
*
Expand All @@ -35,41 +32,6 @@

namespace apps
{
using CreateFunc = std::function<std::unique_ptr<vkb::Application>()>;

/*
* Apps - Used by Vulkan Samples to load a vkb::Applicaiton with the creation function (CreateFunc create).
*/

class AppInfo
{
public:
AppInfo(const std::string &id, const CreateFunc &create) :
id(id), create(create)
{}

std::string id;
CreateFunc create;
};

/*
* Samples - These are individual applications which show different usages and optimizations of the Vulkan API
*/

class SampleInfo : public AppInfo
{
public:
SampleInfo(const std::string &id, const CreateFunc &create, const std::string &category, const std::string &author, const std::string &name, const std::string &description, const std::vector<std::string> &tags = {}) :
AppInfo(id, create), category(category), author(author), name(name), description(description), tags(tags)
{}

std::string category;
std::string author;
std::string name;
std::string description;
std::vector<std::string> tags;
};

/**
* @brief Get a specific app
*
Expand Down
14 changes: 9 additions & 5 deletions app/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[[
Copyright (c) 2019-2023, Arm Limited and Contributors
Copyright (c) 2019-2026, Arm Limited and Contributors

SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -96,7 +96,11 @@ foreach(PLUGIN IN LISTS PLUGINS)
endforeach()

add_library(plugins OBJECT ${SRC_FILES})
target_include_directories(plugins PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} $<TARGET_PROPERTY:apps,INTERFACE_INCLUDE_DIRECTORIES> $<TARGET_PROPERTY:framework,INTERFACE_INCLUDE_DIRECTORIES>)
target_compile_options(plugins PRIVATE $<TARGET_PROPERTY:apps,INTERFACE_COMPILE_OPTIONS> $<TARGET_PROPERTY:framework,INTERFACE_COMPILE_OPTIONS>)
target_compile_features(plugins PRIVATE $<TARGET_PROPERTY:apps,INTERFACE_COMPILE_FEATURES> $<TARGET_PROPERTY:framework,INTERFACE_COMPILE_FEATURES>)
target_compile_definitions(plugins PRIVATE $<TARGET_PROPERTY:apps,INTERFACE_COMPILE_DEFINITIONS> $<TARGET_PROPERTY:framework,INTERFACE_COMPILE_DEFINITIONS>)
target_include_directories(plugins PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
# PRIVATE: plugins are only consumed by the vulkan_samples executable (which links them directly). Nothing else
# needs plugins' include directories or compile definitions.
target_link_libraries(plugins PRIVATE apps framework)
set_target_properties(plugins PROPERTIES POSITION_INDEPENDENT_CODE ON) # must match the PCH owner
if(VKB_USE_PCH)
target_precompile_headers(plugins REUSE_FROM framework)
endif()
1 change: 1 addition & 0 deletions bldsys/cmake/global_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ set(VKB_WSI_SELECTION "XCB" CACHE STRING "Select WSI target (XCB, XLIB, WAYLAND,
set(VKB_CLANG_TIDY OFF CACHE STRING "Use CMake Clang Tidy integration")
set(VKB_CLANG_TIDY_EXTRAS "-header-filter=framework,samples,app;-checks=-*,google-*,-google-runtime-references;--fix;--fix-errors" CACHE STRING "Clang Tidy Parameters")
set(VKB_PROFILING OFF CACHE BOOL "Enable Tracy profiling")
set(VKB_USE_PCH ON CACHE BOOL "Use a precompiled header (shared by framework and samples) for vulkan.hpp, glm, spdlog. Greatly reduces build times.")
set(VKB_SKIP_SLANG_SHADER_COMPILATION OFF CACHE BOOL "Skips compilation for Slang shader")

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin/${CMAKE_BUILD_TYPE}/${TARGET_ARCH}")
Expand Down
8 changes: 8 additions & 0 deletions bldsys/cmake/sample_helper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,17 @@ elseif(${TARGET_TYPE} STREQUAL "Test")
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)

# reuse the framework's precompiled header instead of parsing vulkan.hpp/glm/spdlog again in every sample
# (a PCH can only be reused when the language flags match, e.g. samples that set CMAKE_CXX_EXTENSIONS OFF cannot)
if(VKB_USE_PCH AND (NOT DEFINED CMAKE_CXX_EXTENSIONS OR CMAKE_CXX_EXTENSIONS))
target_precompile_headers(${PROJECT_NAME} REUSE_FROM framework)
endif()

# # inherit include directories from framework target
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(${PROJECT_NAME} PRIVATE framework)
# a few samples use plugin headers (e.g. benchmark_mode); one directory, not propagated to consumers
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/app/plugins)

# Link against extra project specific libraries
if(TARGET_LIBS)
Expand Down
26 changes: 23 additions & 3 deletions framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ set(CORE_FILES

set(PLATFORM_FILES
# Header Files
platform/app_info.h
platform/application.h
platform/platform.h
platform/window.h
Expand Down Expand Up @@ -452,7 +453,11 @@ if(${VKB_WARNINGS_AS_ERRORS})
endif()
endif()

target_include_directories(${PROJECT_NAME} PUBLIC $<TARGET_PROPERTY:plugins,INCLUDE_DIRECTORIES> ${CMAKE_CURRENT_SOURCE_DIR})
# NB: the framework must not depend on the app (apps/plugins), which depends on it and on every sample. Do not add
# include directories or libraries from app/ here; they would leak into every sample's compile command.
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
# platform.cpp only needs the header-only plugin tag lookup (force_close.h); PRIVATE so it does not leak to consumers.
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/app/plugins)

# Link third party libraries
target_link_libraries(${PROJECT_NAME} PUBLIC
Expand All @@ -467,8 +472,7 @@ target_link_libraries(${PROJECT_NAME} PUBLIC
glm
vma
spirv-cross-glsl
spdlog
plugins)
spdlog)

if(${NEED_LINK_ATOMIC})
target_link_libraries(${PROJECT_NAME} PUBLIC atomic)
Expand All @@ -489,6 +493,22 @@ else()
endif()
endif()

# Precompiled header (common/pch.h) with the heavy, stable headers: vulkan.hpp, glm, spdlog/fmt, the standard library and
# the sample base classes (which pull in most of the framework). Parsing these dominated the compile time of nearly every
# translation unit. The samples, apps and plugins reuse this PCH (REUSE_FROM framework), so it is built only once.
# Translation units that define a header-only library's *_IMPLEMENTATION macro before including it cannot use a PCH that
# already includes that header, so they opt out.
if(VKB_USE_PCH)
target_precompile_headers(${PROJECT_NAME} PRIVATE
"$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/common/pch.h>")
set_source_files_properties(
api_vulkan_sample.cpp # VMA_IMPLEMENTATION
gltf_loader.cpp # TINYGLTF_IMPLEMENTATION
scene_graph/components/image/stb.cpp # STB_IMAGE_IMPLEMENTATION
scene_graph/components/image.cpp # STB_IMAGE_RESIZE_IMPLEMENTATION
PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
endif()

if(VKB_DO_CLANG_TIDY)
set_target_properties(framework PROPERTIES CXX_CLANG_TIDY "${VKB_DO_CLANG_TIDY}")
endif()
Expand Down
50 changes: 50 additions & 0 deletions framework/common/pch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* Copyright (c) 2026, Holochip Corporation
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

// Precompiled header shared by the framework, the samples, the sample registry (apps) and the plugins.
//
// Only add stable headers that are expensive to parse. Every change to a header listed here (or included by one)
// rebuilds everything, as it already would without a PCH.
//
// Translation units that define a *_IMPLEMENTATION macro (VMA_IMPLEMENTATION, TINYGLTF_IMPLEMENTATION,
// STB_*_IMPLEMENTATION) before including the library header must not use this PCH, because it already includes those
// headers. They are listed with SKIP_PRECOMPILE_HEADERS in framework/CMakeLists.txt.

#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>

#include <fmt/format.h>
#include <spdlog/spdlog.h>

#include <vulkan/vulkan.hpp>

#include "common/glm_common.h"

// Sample base classes: these pull in most of the framework
#include "api_vulkan_sample.h"
#include "common/vk_common.h"
#include "hpp_api_vulkan_sample.h"
#include "vulkan_sample.h"
35 changes: 0 additions & 35 deletions framework/platform/android/android_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,46 +29,11 @@
#include <spdlog/sinks/android_sink.h>
#include <spdlog/sinks/basic_file_sink.h>

#include "apps.h"
#include "common/strings.h"
#include "core/util/logging.hpp"
#include "platform/android/android_window.h"
#include "platform/input_events.h"

extern "C"
{
JNIEXPORT jobjectArray JNICALL
Java_com_khronos_vulkan_1samples_SampleLauncherActivity_getSamples(JNIEnv *env, jobject thiz)
{
auto sample_list = apps::get_samples();

jclass c = env->FindClass("com/khronos/vulkan_samples/model/Sample");
jmethodID constructor = env->GetMethodID(c, "<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V");
jobjectArray j_sample_list = env->NewObjectArray(sample_list.size(), c, 0);

for (int sample_index = 0; sample_index < sample_list.size(); sample_index++)
{
const apps::SampleInfo *sample_info = reinterpret_cast<apps::SampleInfo *>(sample_list[sample_index]);

jstring id = env->NewStringUTF(sample_info->id.c_str());
jstring category = env->NewStringUTF(sample_info->category.c_str());
jstring author = env->NewStringUTF(sample_info->author.c_str());
jstring name = env->NewStringUTF(sample_info->name.c_str());
jstring desc = env->NewStringUTF(sample_info->description.c_str());

jobjectArray j_tag_list = env->NewObjectArray(sample_info->tags.size(), env->FindClass("java/lang/String"), env->NewStringUTF(""));
for (int tag_index = 0; tag_index < sample_info->tags.size(); ++tag_index)
{
env->SetObjectArrayElement(j_tag_list, tag_index, env->NewStringUTF(sample_info->tags[tag_index].c_str()));
}

env->SetObjectArrayElement(j_sample_list, sample_index, env->NewObject(c, constructor, id, category, author, name, desc, j_tag_list));
}

return j_sample_list;
}
}

namespace vkb
{
namespace
Expand Down
Loading
Loading