Skip to content

Commit

Permalink
Merge pull request #36919 from nekomatata/android-vulkan-rendering
Browse files Browse the repository at this point in the history
Vulkan rendering support on Android
  • Loading branch information
akien-mga authored Apr 8, 2020
2 parents b3310a0 + e167af3 commit 23d786d
Show file tree
Hide file tree
Showing 35 changed files with 1,377 additions and 860 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ project.properties
platform/android/java/lib/.cxx/
platform/android/java/libs/*
platform/android/java/app/libs/*
platform/android/java/lib/.cxx/*

# General c++ generated files
*.lib
Expand Down
12 changes: 11 additions & 1 deletion drivers/vulkan/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ Import("env")

env.add_source_files(env.drivers_sources, "*.cpp")

if env["builtin_vulkan"]:
if env["platform"] == "android":
# Use NDK Vulkan headers
thirdparty_dir = env["ANDROID_NDK_ROOT"] + "/sources/third_party/vulkan/src"
thirdparty_includes = [
thirdparty_dir,
thirdparty_dir + "/include",
thirdparty_dir + "/layers",
thirdparty_dir + "/layers/generated",
]
env.Prepend(CPPPATH=thirdparty_includes)
elif env["builtin_vulkan"]:
# Use bundled Vulkan headers
thirdparty_dir = "#thirdparty/vulkan"
env.Prepend(CPPPATH=[thirdparty_dir, thirdparty_dir + "/include", thirdparty_dir + "/loader"])
Expand Down
12 changes: 9 additions & 3 deletions drivers/vulkan/rendering_device_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1565,15 +1565,20 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T
image_create_info.pNext = nullptr;
image_create_info.flags = 0;

VkImageFormatListCreateInfoKHR format_list_create_info;
Vector<VkFormat> allowed_formats;

#ifndef _MSC_VER
#warning TODO check for support via RenderingDevice to enable on mobile when possible
#endif
// vkCreateImage fails with format list on Android (VK_ERROR_OUT_OF_HOST_MEMORY)
#ifndef ANDROID_ENABLED
if (p_format.shareable_formats.size()) {
image_create_info.flags |= VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;

Vector<VkFormat> allowed_formats;
for (int i = 0; i < p_format.shareable_formats.size(); i++) {
allowed_formats.push_back(vulkan_formats[p_format.shareable_formats[i]]);
}

VkImageFormatListCreateInfoKHR format_list_create_info;
format_list_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR;
format_list_create_info.pNext = nullptr;
format_list_create_info.viewFormatCount = allowed_formats.size();
Expand All @@ -1585,6 +1590,7 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T
ERR_FAIL_COND_V_MSG(p_view.format_override != DATA_FORMAT_MAX && p_format.shareable_formats.find(p_view.format_override) == -1, RID(),
"If supplied a list of shareable formats, the current view format override must be present in the list");
}
#endif
if (p_format.type == TEXTURE_TYPE_CUBE || p_format.type == TEXTURE_TYPE_CUBE_ARRAY) {
image_create_info.flags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
}
Expand Down
2 changes: 2 additions & 0 deletions drivers/vulkan/rendering_device_vulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
#include "servers/rendering/rendering_device.h"

#ifdef DEBUG_ENABLED
#ifndef _DEBUG
#define _DEBUG
#endif
#endif
#include "vk_mem_alloc.h"
#include <vulkan/vulkan.h>
//todo:
Expand Down
4 changes: 2 additions & 2 deletions drivers/vulkan/vulkan_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ class VulkanContext {
FRAME_LAG = 2
};

bool use_validation_layers;

VkInstance inst;
VkSurfaceKHR surface;
VkPhysicalDevice gpu;
Expand Down Expand Up @@ -181,6 +179,8 @@ class VulkanContext {

bool buffers_prepared;

bool use_validation_layers;

public:
VkDevice get_device();
VkPhysicalDevice get_physical_device();
Expand Down
4 changes: 2 additions & 2 deletions platform/android/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ android_files = [
"java_godot_io_wrapper.cpp",
"jni_utils.cpp",
"android_keys_utils.cpp",
"vulkan/vk_renderer_jni.cpp",
"plugin/godot_plugin_jni.cpp",
"display_server_android.cpp",
"vulkan/vulkan_context_android.cpp",
]

env_android = env.Clone()
Expand Down
8 changes: 4 additions & 4 deletions platform/android/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_opts():

return [
("ANDROID_NDK_ROOT", "Path to the Android NDK", os.environ.get("ANDROID_NDK_ROOT", 0)),
("ndk_platform", 'Target platform (android-<api>, e.g. "android-18")', "android-18"),
("ndk_platform", 'Target platform (android-<api>, e.g. "android-24")', "android-24"),
EnumVariable("android_arch", "Target architecture", "armv7", ("armv7", "arm64v8", "x86", "x86_64")),
BoolVariable("android_neon", "Enable NEON support (armv7 only)", True),
]
Expand Down Expand Up @@ -102,7 +102,7 @@ def mySpawn(sh, escape, cmd, args, env):
neon_text = ""
if env["android_arch"] == "armv7" and env["android_neon"]:
neon_text = " (with NEON)"
print("Building for Android (" + env["android_arch"] + ")" + neon_text)
print("Building for Android, platform " + env["ndk_platform"] + " (" + env["android_arch"] + ")" + neon_text)

can_vectorize = True
if env["android_arch"] == "x86":
Expand Down Expand Up @@ -314,8 +314,8 @@ def mySpawn(sh, escape, cmd, args, env):
)

env.Prepend(CPPPATH=["#platform/android"])
env.Append(CPPDEFINES=["ANDROID_ENABLED", "UNIX_ENABLED", "NO_FCNTL"])
env.Append(LIBS=["OpenSLES", "EGL", "GLESv3", "GLESv2", "android", "log", "z", "dl"])
env.Append(CPPDEFINES=["ANDROID_ENABLED", "UNIX_ENABLED", "VULKAN_ENABLED", "NO_FCNTL"])
env.Append(LIBS=["OpenSLES", "EGL", "GLESv2", "vulkan", "android", "log", "z", "dl"])


# Return NDK version string in source.properties (adapted from the Chromium project).
Expand Down
Loading

0 comments on commit 23d786d

Please sign in to comment.