Skip to content
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
43 changes: 43 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,41 @@ plugins {
alias(libs.plugins.spotless)
}

abstract class InstallVulkanValidationLayerTask extends DefaultTask {
@Input
abstract Property<String> getLayerVersion()

@OutputFile
abstract RegularFileProperty getOutputFile()

@TaskAction
void install() {
def version = layerVersion.get()
def zipFile = new File(temporaryDir, "android-binaries-${version}.zip")
if (!zipFile.exists()) {
temporaryDir.mkdirs()
def url = new URL("https://github.com/KhronosGroup/Vulkan-ValidationLayers/releases/download/vulkan-sdk-${version}/android-binaries-${version}.zip")
url.withInputStream { input ->
zipFile.withOutputStream { output -> output << input }
}
}

def targetFile = outputFile.get().asFile
targetFile.parentFile.mkdirs()
new java.util.zip.ZipFile(zipFile).withCloseable { zip ->
def entry = zip.entries().find {
it.name.endsWith("/arm64-v8a/libVkLayer_khronos_validation.so")
}
if (entry == null) {
throw new GradleException("arm64-v8a Vulkan validation layer not found in ${zipFile.name}")
}
zip.getInputStream(entry).withCloseable { input ->
targetFile.withOutputStream { output -> output << input }
}
}
}
}

task checkSubmodules {
// Resolve the file path during the configuration phase so we don't
// pass the Gradle Project object into the execution closure (which breaks the Configuration Cache).
Expand All @@ -23,6 +58,11 @@ task checkSubmodules {

preBuild.dependsOn(checkSubmodules)

def installVulkanValidationLayer = tasks.register("installVulkanValidationLayer", InstallVulkanValidationLayerTask) {
layerVersion.set("1.4.341.0")
outputFile.set(layout.projectDirectory.file("src/debug/jniLibs/arm64-v8a/libVkLayer_khronos_validation.so"))
}

ksp {
arg("room.schemaLocation", "$projectDir/schemas")
}
Expand Down Expand Up @@ -164,6 +204,9 @@ android {

applicationVariants.configureEach { variant ->
if (variant.buildType.name == "debug") {
tasks.named("pre${variant.name.capitalize()}Build").configure {
dependsOn installVulkanValidationLayer
}
variant.outputs.configureEach { output ->
output.outputFileName = "${variant.flavorName}.apk"
}
Expand Down
8 changes: 8 additions & 0 deletions app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application>
<meta-data
android:name="com.android.graphics.injectLayers.enable"
android:value="true" />
</application>
</manifest>
Binary file not shown.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
Expand Down
90 changes: 86 additions & 4 deletions app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,84 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -Wno-unused-function -Wimplicit-function
add_subdirectory(patchelf)
add_subdirectory(adrenotools)

# Add Winlator shared library
# ----------------------------------------------------------------------------
# SPIR-V shader compilation
# Each .glsl is compiled by glslc (shipped with the NDK) into a .spv binary,
# then converted to a C uint32_t array via bin2c.cmake. Headers are emitted
# under ${CMAKE_CURRENT_BINARY_DIR}/shaders/*.spv.h and included from vk_renderer.c.
# ----------------------------------------------------------------------------

# Locate glslc shipped with the NDK. ANDROID_NDK is provided by the Android Gradle plugin.
if(NOT DEFINED ANDROID_NDK)
message(FATAL_ERROR "ANDROID_NDK not defined; this project must be built via the Android Gradle plugin")
endif()

if(CMAKE_HOST_WIN32)
set(GLSLC_HOST_TAG "windows-x86_64")
set(GLSLC_EXE_NAME "glslc.exe")
elseif(CMAKE_HOST_APPLE)
set(GLSLC_HOST_TAG "darwin-x86_64")
set(GLSLC_EXE_NAME "glslc")
else()
set(GLSLC_HOST_TAG "linux-x86_64")
set(GLSLC_EXE_NAME "glslc")
endif()

set(GLSLC "${ANDROID_NDK}/shader-tools/${GLSLC_HOST_TAG}/${GLSLC_EXE_NAME}")
if(NOT EXISTS "${GLSLC}")
message(FATAL_ERROR "glslc not found at ${GLSLC}; check NDK installation")
endif()

set(SHADER_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/winlator/vk/shaders")
set(SHADER_OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/shaders")
file(MAKE_DIRECTORY "${SHADER_OUT_DIR}")

set(BIN2C_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/winlator/vk/bin2c.cmake")

# (input filename without extension, var name, stage)
set(SHADER_LIST
"window:vert:window_vert"
"window:frag:window_frag"
"cursor:frag:cursor_frag"
"quad:vert:quad_vert"
"blit:frag:blit_frag"
"effect_crt:frag:effect_crt_frag"
"effect_fsr:frag:effect_fsr_frag"
"effect_hdr:frag:effect_hdr_frag"
"effect_natural:frag:effect_natural_frag"
)

set(SHADER_HEADERS "")
foreach(entry ${SHADER_LIST})
string(REPLACE ":" ";" parts ${entry})
list(GET parts 0 base)
list(GET parts 1 stage)
list(GET parts 2 var)
set(input "${SHADER_SRC_DIR}/${base}.${stage}")
set(spv "${SHADER_OUT_DIR}/${var}.spv")
set(hdr "${SHADER_OUT_DIR}/${var}.spv.h")

add_custom_command(
OUTPUT "${hdr}"
COMMAND "${GLSLC}" --target-env=vulkan1.1 -O "${input}" -o "${spv}"
COMMAND "${CMAKE_COMMAND}"
-DINPUT_FILE=${spv}
-DOUTPUT_FILE=${hdr}
-DVAR_NAME=${var}
-P "${BIN2C_SCRIPT}"
DEPENDS "${input}" "${BIN2C_SCRIPT}"
COMMENT "Compiling shader ${base}.${stage} -> ${var}.spv.h"
VERBATIM
)
list(APPEND SHADER_HEADERS "${hdr}")
endforeach()

add_custom_target(winlator_shaders DEPENDS ${SHADER_HEADERS})

# ----------------------------------------------------------------------------
# Winlator native library (X-server, AHB, Vulkan compositor, helpers)
# ----------------------------------------------------------------------------

add_library(winlator SHARED
winlator/drawable.c
winlator/gpu_image.c
Expand All @@ -16,6 +93,8 @@ add_library(winlator SHARED
winlator/alsa_client.c
winlator/process_lifecycle.c
winlator/vulkan.c
winlator/vk/vk_image.c
winlator/vk/vk_renderer.c
xz/native_xz_stream.c
xz/xz_embedded/xz_crc32.c
xz/xz_embedded/xz_crc64.c
Expand All @@ -24,6 +103,8 @@ add_library(winlator SHARED
xz/xz_embedded/xz_dec_stream.c
)

add_dependencies(winlator winlator_shaders)

target_compile_options(winlator PRIVATE -Wall -Wextra)
target_compile_definitions(winlator PRIVATE
XZ_USE_CRC64
Expand All @@ -36,19 +117,20 @@ target_compile_definitions(winlator PRIVATE
XZ_DEC_POWERPC
XZ_DEC_IA64
XZ_DEC_SPARC
VK_USE_PLATFORM_ANDROID_KHR
)
target_include_directories(winlator PRIVATE
xz/xz_embedded
winlator/vk
${CMAKE_CURRENT_BINARY_DIR}
)

target_link_libraries(winlator
log
android
jnigraphics
aaudio
EGL
GLESv2
GLESv3
vulkan
adrenotools
)

Expand Down
55 changes: 0 additions & 55 deletions app/src/main/cpp/virglrenderer/CMakeLists.txt

This file was deleted.

Loading