Skip to content

Commit

Permalink
Fix Vulkan diagnostics
Browse files Browse the repository at this point in the history
Signed-off-by: renderexpert <[email protected]>
  • Loading branch information
renderexpert authored and biodranik committed Mar 20, 2024
1 parent 72eb143 commit 7339f25
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 22 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ option(SKIP_QT_GUI "Skip building of Qt GUI" OFF)
option(BUILD_MAPSHOT "Build mapshot tool" OFF)
option(USE_PCH "Use precompiled headers" OFF)
option(NJOBS "Number of parallel processes" OFF)
option(ENABLE_VULKAN_DIAGNOSTICS "Enable Vulkan diagnostics" OFF)

if (NJOBS)
message(STATUS "Number of parallel processes: ${NJOBS}")
Expand Down Expand Up @@ -181,6 +182,11 @@ if (USE_HEAPPROF)
message(STATUS "Heap Profiler is enabled")
endif()

if (ENABLE_VULKAN_DIAGNOSTICS)
message(WARNING "Vulkan diagnostics are enabled. Be aware of performance impact!")
add_definitions(-DENABLE_VULKAN_DIAGNOSTICS)
endif()

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Set environment variables
Expand Down
1 change: 1 addition & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ local.properties
.project
lint.xml
.gradletasknamecache

19 changes: 6 additions & 13 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,19 @@ android {
def njobs = ''
if (project.hasProperty('njobs')) njobs = project.getProperty('njobs')

def enableVulkanDiagnostics = 'OFF'
if (project.hasProperty('enableVulkanDiagnostics')) {
enableVulkanDiagnostics = project.getProperty('enableVulkanDiagnostics')
}

cmake {
cppFlags '-fexceptions', '-frtti'
// There is no sense to enable sections without gcc's --gc-sections flag.
cFlags '-fno-function-sections', '-fno-data-sections',
'-Wno-extern-c-compat'
arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_static',
"-DOS=$osName", '-DSKIP_TESTS=ON', '-DSKIP_TOOLS=ON', "-DUSE_PCH=$pchFlag",
"-DNJOBS=$njobs"
"-DNJOBS=$njobs", "-DENABLE_VULKAN_DIAGNOSTICS=$enableVulkanDiagnostics"
targets 'organicmaps'
}
}
Expand Down Expand Up @@ -339,18 +344,6 @@ android {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
packagingOptions.jniLibs {
excludes += [
'lib/**/libVkLayer_khronos_validation.so',
'lib/**/libVkLayer_core_validation.so',
'lib/**/libVkLayer_threading.so',
'lib/**/libVkLayer_image.so',
'lib/**/libVkLayer_parameter_validation.so',
'lib/**/libVkLayer_object_tracker.so',
'lib/**/libVkLayer_swapchain.so',
'lib/**/libVkLayer_unique_objects.so',
]
}
}

dependencies {
Expand Down
2 changes: 2 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ android.native.buildOutput=verbose
android.nonTransitiveRClass=true
android.nonFinalResIds=false

enableVulkanDiagnostics=OFF

# Autogenerated by tools/unix/generate_localizations.sh
supportedLocalizations=af,ar,az,be,bg,ca,cs,da,de,el,en,en_GB,es,es_MX,et,eu,fa,fi,fr,fr_CA,iw,hi,hu,in,it,ja,ko,lt,mr,nb,nl,pl,pt,pt_BR,ro,ru,sk,sv,sw,th,tr,uk,vi,zh,zh_HK,zh_MO,zh_TW
16 changes: 16 additions & 0 deletions docs/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,22 @@ If you are low on RAM, disk space or traffic there are ways to reduce system req
- make sure the emulator uses [hardware acceleration](https://developer.android.com/studio/run/emulator-acceleration);
- don't use emulator, debug on a hardware device instead.
#### Enable Vulkan Validation
1. Download Vulkan Validation Layers
```bash
./tools/android/download_vulkan_validation_layers.py
```
2. Set `enableVulkanDiagnostics=ON` in `gradle.properties`.
If you build the app from command line, the parameter can be passed via command line.
E.g.
```
./gradlew -Parm64 -PenableVulkanDiagnostics=ON runGoogleDebug
```
## iOS app
### Preparing
Expand Down
10 changes: 1 addition & 9 deletions drape/vulkan/vulkan_layers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,9 @@ char const * const kDeviceExtensions[] =
"VK_KHR_swapchain"
};

// DO NOT reorder. The order matters here.
char const * const kValidationLayers[] =
{
"VK_LAYER_GOOGLE_threading",
"VK_LAYER_LUNARG_device_limits",
"VK_LAYER_LUNARG_core_validation",
"VK_LAYER_LUNARG_image",
"VK_LAYER_LUNARG_object_tracker",
"VK_LAYER_LUNARG_parameter_validation",
"VK_LAYER_LUNARG_swapchain",
"VK_LAYER_GOOGLE_unique_objects",
"VK_LAYER_KHRONOS_validation",
};

std::vector<char const *> CheckLayers(std::vector<VkLayerProperties> const & props)
Expand Down
41 changes: 41 additions & 0 deletions tools/android/download_vulkan_validation_layers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3

import requests
import zipfile
import os
import shutil

def download_vulkan_validation_layers():
# Step 1: Download zip archive
url = "https://github.com/KhronosGroup/Vulkan-ValidationLayers/releases/download/vulkan-sdk-1.3.275.0/android-binaries-1.3.275.0.zip"
download_path = "vulkan_sdk.zip"

print("Downloading zip archive...")
response = requests.get(url)
with open(download_path, "wb") as f:
f.write(response.content)
print("Download complete.")

# Step 2: Unzip archive
unzip_dir = "vulkan_sdk"
print("Unzipping archive...")
with zipfile.ZipFile(download_path, "r") as zip_ref:
zip_ref.extractall(unzip_dir)
print("Unzip complete.")

# Step 3: Rename unpacked folder to "jniLibs" and move it to "android/app/src/main"
unpacked_folder = os.listdir(unzip_dir)[0]
jniLibs_path = os.path.join(unzip_dir, "jniLibs")
os.rename(os.path.join(unzip_dir, unpacked_folder), jniLibs_path)
destination_path = "android/app/src/main"
shutil.move(jniLibs_path, destination_path)
print("Deploy complete.")

# Clean up downloaded zip file and empty directories
os.remove(download_path)
os.rmdir(unzip_dir)
print("Clean up complete.")


if __name__ == '__main__':
download_vulkan_validation_layers()

0 comments on commit 7339f25

Please sign in to comment.