Skip to content

Commit

Permalink
Add android platform specific functions.
Browse files Browse the repository at this point in the history
Update generate_bindings.py to generate android platform specific device
functions.

Bug: 891060
Change-Id: I88f5b6149c4e955613b64e56c403caf2a970dd6f
Reviewed-on: https://chromium-review.googlesource.com/c/1344223
Reviewed-by: Chris Blume <[email protected]>
Reviewed-by: Antoine Labour <[email protected]>
Commit-Queue: vikas soni <[email protected]>
Cr-Commit-Position: refs/heads/master@{#609792}
  • Loading branch information
vikaschromie authored and Commit Bot committed Nov 20, 2018
1 parent edf8777 commit 5a0eb72
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 4 deletions.
51 changes: 47 additions & 4 deletions gpu/vulkan/generate_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
{ 'name': 'vkWaitForFences' },
]

VULKAN_DEVICE_FUNCTIONS_ANDROID = [
{ 'name': 'vkImportSemaphoreFdKHR' },
{ 'name': 'vkGetSemaphoreFdKHR' },
]

VULKAN_QUEUE_FUNCTIONS = [
{ 'name': 'vkQueueSubmit' },
{ 'name': 'vkQueueWaitIdle' },
Expand Down Expand Up @@ -123,8 +128,8 @@ def WriteMacros(file, functions):

def GenerateHeaderFile(file, unassociated_functions, instance_functions,
physical_device_functions, device_functions,
queue_functions, command_buffer_functions,
swapchain_functions):
device_functions_android, queue_functions,
command_buffer_functions, swapchain_functions):
"""Generates gpu/vulkan/vulkan_function_pointers.h"""

file.write(LICENSE_AND_HEADER +
Expand All @@ -136,6 +141,7 @@ def GenerateHeaderFile(file, unassociated_functions, instance_functions,
#include <vulkan/vulkan.h>
#include "base/native_library.h"
#include "build/build_config.h"
#include "gpu/vulkan/vulkan_export.h"
namespace gpu {
Expand Down Expand Up @@ -196,6 +202,18 @@ def GenerateHeaderFile(file, unassociated_functions, instance_functions,

file.write("""\
// Android only device functions.
#if defined(OS_ANDROID)
""")

WriteFunctionDeclarations(file, device_functions_android)

file.write("""\
#endif
""")

file.write("""\
// Queue functions
""")

Expand Down Expand Up @@ -255,6 +273,17 @@ def GenerateHeaderFile(file, unassociated_functions, instance_functions,

file.write("""\
#if defined(OS_ANDROID)
""")

WriteMacros(file, device_functions_android)

file.write("""\
#endif
""")

file.write("""\
// Queue functions
""")

Expand Down Expand Up @@ -305,8 +334,8 @@ def WriteDeviceFunctionPointerInitialization(file, functions):

def GenerateSourceFile(file, unassociated_functions, instance_functions,
physical_device_functions, device_functions,
queue_functions, command_buffer_functions,
swapchain_functions):
device_functions_android, queue_functions,
command_buffer_functions, swapchain_functions):
"""Generates gpu/vulkan/vulkan_function_pointers.cc"""

file.write(LICENSE_AND_HEADER +
Expand Down Expand Up @@ -374,6 +403,18 @@ def GenerateSourceFile(file, unassociated_functions, instance_functions,

file.write("""\
#if defined(OS_ANDROID)
""")

WriteDeviceFunctionPointerInitialization(file, device_functions_android)

file.write("""\
#endif
""")

file.write("""\
// Queue functions
""")
WriteDeviceFunctionPointerInitialization(file, queue_functions)
Expand Down Expand Up @@ -425,6 +466,7 @@ def ClangFormat(filename):
GenerateHeaderFile(header_file, VULKAN_UNASSOCIATED_FUNCTIONS,
VULKAN_INSTANCE_FUNCTIONS,
VULKAN_PHYSICAL_DEVICE_FUNCTIONS, VULKAN_DEVICE_FUNCTIONS,
VULKAN_DEVICE_FUNCTIONS_ANDROID,
VULKAN_QUEUE_FUNCTIONS, VULKAN_COMMAND_BUFFER_FUNCTIONS,
VULKAN_SWAPCHAIN_FUNCTIONS)
header_file.close()
Expand All @@ -435,6 +477,7 @@ def ClangFormat(filename):
GenerateSourceFile(source_file, VULKAN_UNASSOCIATED_FUNCTIONS,
VULKAN_INSTANCE_FUNCTIONS,
VULKAN_PHYSICAL_DEVICE_FUNCTIONS, VULKAN_DEVICE_FUNCTIONS,
VULKAN_DEVICE_FUNCTIONS_ANDROID,
VULKAN_QUEUE_FUNCTIONS, VULKAN_COMMAND_BUFFER_FUNCTIONS,
VULKAN_SWAPCHAIN_FUNCTIONS)
source_file.close()
Expand Down
14 changes: 14 additions & 0 deletions gpu/vulkan/vulkan_function_pointers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,20 @@ bool VulkanFunctionPointers::BindDeviceFunctionPointers(VkDevice vk_device) {
if (!vkWaitForFencesFn)
return false;

#if defined(OS_ANDROID)

vkImportSemaphoreFdKHRFn = reinterpret_cast<PFN_vkImportSemaphoreFdKHR>(
vkGetDeviceProcAddrFn(vk_device, "vkImportSemaphoreFdKHR"));
if (!vkImportSemaphoreFdKHRFn)
return false;

vkGetSemaphoreFdKHRFn = reinterpret_cast<PFN_vkGetSemaphoreFdKHR>(
vkGetDeviceProcAddrFn(vk_device, "vkGetSemaphoreFdKHR"));
if (!vkGetSemaphoreFdKHRFn)
return false;

#endif

// Queue functions
vkQueueSubmitFn = reinterpret_cast<PFN_vkQueueSubmit>(
vkGetDeviceProcAddrFn(vk_device, "vkQueueSubmit"));
Expand Down
14 changes: 14 additions & 0 deletions gpu/vulkan/vulkan_function_pointers.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <vulkan/vulkan.h>

#include "base/native_library.h"
#include "build/build_config.h"
#include "gpu/vulkan/vulkan_export.h"

namespace gpu {
Expand Down Expand Up @@ -99,6 +100,12 @@ struct VulkanFunctionPointers {
PFN_vkUpdateDescriptorSets vkUpdateDescriptorSetsFn = nullptr;
PFN_vkWaitForFences vkWaitForFencesFn = nullptr;

// Android only device functions.
#if defined(OS_ANDROID)
PFN_vkImportSemaphoreFdKHR vkImportSemaphoreFdKHRFn = nullptr;
PFN_vkGetSemaphoreFdKHR vkGetSemaphoreFdKHRFn = nullptr;
#endif

// Queue functions
PFN_vkQueueSubmit vkQueueSubmitFn = nullptr;
PFN_vkQueueWaitIdle vkQueueWaitIdleFn = nullptr;
Expand Down Expand Up @@ -207,6 +214,13 @@ struct VulkanFunctionPointers {
gpu::GetVulkanFunctionPointers()->vkUpdateDescriptorSetsFn
#define vkWaitForFences gpu::GetVulkanFunctionPointers()->vkWaitForFencesFn

#if defined(OS_ANDROID)
#define vkImportSemaphoreFdKHR \
gpu::GetVulkanFunctionPointers()->vkImportSemaphoreFdKHRFn
#define vkGetSemaphoreFdKHR \
gpu::GetVulkanFunctionPointers()->vkGetSemaphoreFdKHRFn
#endif

// Queue functions
#define vkQueueSubmit gpu::GetVulkanFunctionPointers()->vkQueueSubmitFn
#define vkQueueWaitIdle gpu::GetVulkanFunctionPointers()->vkQueueWaitIdleFn
Expand Down

0 comments on commit 5a0eb72

Please sign in to comment.