Use our own checked in Vulkan header to build skia source code.

Core Skia will always include our own SkiaVulkan.h which basically just
includes vulkan_core.h. All platform vulkan specific stuff must be
include by the client in their own vulkan.h file. Our public interface
is set up that we only use vulkan objects that will be present in all
versions of vulkan headers that the client could include.

Bug: skia:
Change-Id: I6673fd91498eabcc923d65d20f2b5e0a89b4ccf6
Reviewed-on: https://skia-review.googlesource.com/142985
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Greg Daniel 2018-08-01 09:23:57 -04:00 committed by Skia Commit-Bot
parent 7e26aa235f
commit da16cce7d9
10 changed files with 89 additions and 243 deletions

View File

@ -43,6 +43,7 @@ declare_args() {
skia_enable_spirv_validation = is_skia_dev_build && is_debug
skia_enable_tools = is_skia_dev_build
skia_enable_vulkan_debug_layers = is_skia_dev_build && is_debug
skia_vulkan_header = "" # temporary as we remove the use from clients
skia_qt_path = getenv("QT_PATH")
skia_compile_processors = false
skia_generate_workarounds = false
@ -614,11 +615,7 @@ optional("gpu") {
}
if (skia_use_vulkan) {
# TODO: We should make this deps be //third_party/vulkan and then update clients to have a
# //third_party/vulkan directory in their trees so they can set up the vulkan library however
# they want. For example this would allow us to remove the fuchsia specific vulkan code in our
# vulkan files.
public_deps += [ "third_party/vulkan" ]
public_defines += [ "SK_VULKAN" ]
deps += [ "third_party/vulkanmemoryallocator" ]
sources += skia_vk_sources
if (skia_enable_vulkan_debug_layers) {
@ -826,6 +823,7 @@ component("skia") {
":fontmgr_empty",
":fontmgr_fontconfig",
":fontmgr_fuchsia",
":gpu",
":heif",
":hsw",
":jpeg",
@ -842,12 +840,6 @@ component("skia") {
":xml",
]
# We need the public deps here for Vulkan. Our third_party/vulkan target sets some defines that
# need to get propagated up to the tools that depend on :skia and thus :gpu.
public_deps = [
":gpu",
]
# This file (and all GN files in Skia) are designed to work with an
# empty sources assignment filter; we handle all that explicitly.
# We clear the filter here for clients who may have set up a global filter.
@ -992,10 +984,6 @@ if (skia_enable_tools) {
config("skia.h_config") {
include_dirs = [ "$target_gen_dir" ]
if (skia_use_vulkan) {
# So we can get the header which includes vulkan
include_dirs += [ "tools/gpu/vk" ]
}
}
action("skia.h") {
public_configs = [ ":skia.h_config" ]
@ -1230,12 +1218,42 @@ if (skia_enable_tools) {
}
}
config("moltenvk_config") {
if (defined(skia_moltenvk_path) && skia_moltenvk_path != "") {
if (is_ios) {
moltenvk_framework_path = "$skia_moltenvk_path/MoltenVK/iOS"
} else {
moltenvk_framework_path = "$skia_moltenvk_path/MoltenVK/macOS"
}
cflags = [ "-F$moltenvk_framework_path" ]
ldflags = [ "-F$moltenvk_framework_path" ]
libs = [
"MoltenVK.framework",
"Metal.framework",
"IOSurface.framework",
"QuartzCore.framework",
"Foundation.framework",
]
if (is_ios) {
libs += [ "UIKit.framework" ]
} else {
libs += [ "IOKit.framework" ]
}
defines = [ "SK_MOLTENVK" ]
}
}
source_set("moltenvk") {
public_configs = [ ":moltenvk_config" ]
}
test_lib("gpu_tool_utils") {
public_include_dirs = []
public_defines = []
public_include_dirs += [ "tools/gpu" ]
deps = []
public_deps = []
sources = [
"tools/gpu/GrContextFactory.cpp",
"tools/gpu/GrTest.cpp",
@ -1279,8 +1297,12 @@ if (skia_enable_tools) {
sources += [ "tools/gpu/gl/angle/GLTestContext_angle.cpp" ]
}
if (skia_use_vulkan) {
public_include_dirs += [ "third_party/vulkan" ]
sources += [ "tools/gpu/vk/VkTestContext.cpp" ]
sources += [ "tools/gpu/vk/VkTestUtils.cpp" ]
if (defined(skia_moltenvk_path) && skia_moltenvk_path != "") {
public_deps += [ ":moltenvk" ]
}
}
if (skia_use_metal) {
sources += [ "tools/gpu/mtl/MtlTestContext.mm" ]
@ -1301,6 +1323,8 @@ if (skia_enable_tools) {
]
deps = [
":flags",
]
public_deps = [
":gpu_tool_utils",
]
}
@ -1354,12 +1378,12 @@ if (skia_enable_tools) {
defines += [ "SK_TOOLS_REQUIRE_RESOURCES" ]
}
deps = [
":common_flags",
":experimental_svg_model",
":flags",
"//third_party/libpng",
]
public_deps = [
":common_flags",
"//third_party/jsoncpp",
]
}
@ -1370,12 +1394,14 @@ if (skia_enable_tools) {
sources = gm_sources
deps = [
":flags",
":gpu_tool_utils",
":skia",
":tool_utils",
"modules/skottie",
"modules/sksg",
]
public_deps = [
":gpu_tool_utils",
]
}
import("gn/tests.gni")

View File

@ -218,7 +218,6 @@ gn_args = {
'skia_use_vulkan': 'true',
'target_cpu': '"none"',
'target_os': '"android"',
'skia_vulkan_header': '"Skia_Vulkan_Android.h"',
}
js = gn_to_bp_utils.GenerateJSONFromGN(gn_args)
@ -262,11 +261,6 @@ nanobench_srcs = {s for s in nanobench_srcs if not s.endswith('.h')}
cflags = gn_to_bp_utils.CleanupCFlags(cflags)
cflags_cc = gn_to_bp_utils.CleanupCCFlags(cflags_cc)
# We need to add the include path to the vulkan defines and header file set in
# then skia_vulkan_header gn arg that is used for framework builds.
local_includes.add("platform_tools/android/vulkan")
export_includes.add("platform_tools/android/vulkan")
here = os.path.dirname(__file__)
defs = gn_to_bp_utils.GetArchSources(os.path.join(here, 'opts.gni'))

View File

@ -13,122 +13,10 @@
#ifdef SK_VULKAN
#ifdef SK_VULKAN_HEADER
#include SK_VULKAN_HEADER // IWYU pragma: export
#else
// This is deprecated and all clients should define their own custum header shim that sets up
// defines and includes the vulkan.h header. Then they should define SK_VULKAN_HEADER or set the
// skia_vulkan_header in gn to point to their custom header.
# if defined(SK_BUILD_FOR_WIN)
# if !defined(VK_USE_PLATFORM_WIN32_KHR)
# define VK_USE_PLATFORM_WIN32_KHR
# endif
# elif defined(SK_BUILD_FOR_ANDROID)
# if !defined(VK_USE_PLATFORM_ANDROID_KHR)
# define VK_USE_PLATFORM_ANDROID_KHR
# endif
# elif defined(SK_BUILD_FOR_UNIX)
# if defined(__Fuchsia__)
# if !defined(VK_USE_PLATFORM_MAGMA_KHR)
# define VK_USE_PLATFORM_MAGMA_KHR
# endif
# else
# if !defined(VK_USE_PLATFORM_XCB_KHR)
# define VK_USE_PLATFORM_XCB_KHR
# endif
# endif
# endif
// We create our own function table and never directly call any functions via vk*(). So no need to
// include the prototype functions.
# if !defined(VK_NO_PROTOTYPES) && !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
# define VK_NO_PROTOTYPES
# endif
# include <vulkan/vulkan.h> // IWYU pragma: export
#endif // SK_VULKAN_HEADER
#define SKIA_REQUIRED_VULKAN_HEADER_VERSION 17
#if VK_HEADER_VERSION < SKIA_REQUIRED_VULKAN_HEADER_VERSION
#error "Vulkan header version is too low"
#ifndef VULKAN_H_
#include "../../../third_party/vulkan/SkiaVulkan.h"
#endif
// The AMD VulkanMemoryAllocator needs the objects from this extension to be declared.
#ifndef VK_KHR_get_memory_requirements2
#define VK_KHR_get_memory_requirements2 1
#define VK_KHR_GET_MEMORY_REQUIREMENTS_2_SPEC_VERSION 1
#define VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME "VK_KHR_get_memory_requirements2"
typedef struct VkBufferMemoryRequirementsInfo2KHR {
VkStructureType sType;
const void* pNext;
VkBuffer buffer;
} VkBufferMemoryRequirementsInfo2KHR;
typedef struct VkImageMemoryRequirementsInfo2KHR {
VkStructureType sType;
const void* pNext;
VkImage image;
} VkImageMemoryRequirementsInfo2KHR;
typedef struct VkImageSparseMemoryRequirementsInfo2KHR {
VkStructureType sType;
const void* pNext;
VkImage image;
} VkImageSparseMemoryRequirementsInfo2KHR;
typedef struct VkMemoryRequirements2KHR {
VkStructureType sType;
void* pNext;
VkMemoryRequirements memoryRequirements;
} VkMemoryRequirements2KHR;
typedef struct VkSparseImageMemoryRequirements2KHR {
VkStructureType sType;
void* pNext;
VkSparseImageMemoryRequirements memoryRequirements;
} VkSparseImageMemoryRequirements2KHR;
typedef void (VKAPI_PTR *PFN_vkGetImageMemoryRequirements2KHR)(VkDevice device, const VkImageMemoryRequirementsInfo2KHR* pInfo, VkMemoryRequirements2KHR* pMemoryRequirements);
typedef void (VKAPI_PTR *PFN_vkGetBufferMemoryRequirements2KHR)(VkDevice device, const VkBufferMemoryRequirementsInfo2KHR* pInfo, VkMemoryRequirements2KHR* pMemoryRequirements);
typedef void (VKAPI_PTR *PFN_vkGetImageSparseMemoryRequirements2KHR)(VkDevice device, const VkImageSparseMemoryRequirementsInfo2KHR* pInfo, uint32_t* pSparseMemoryRequirementCount, VkSparseImageMemoryRequirements2KHR* pSparseMemoryRequirements);
static constexpr VkStructureType VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2_KHR = (VkStructureType) 1000146000;
static constexpr VkStructureType VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2_KHR = (VkStructureType) 1000146001;
static constexpr VkStructureType VK_STRUCTURE_TYPE_IMAGE_SPARSE_MEMORY_REQUIREMENTS_INFO_2_KHR = (VkStructureType) 1000146002;
static constexpr VkStructureType VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR = (VkStructureType) 1000146003;
static constexpr VkStructureType VK_STRUCTURE_TYPE_SPARSE_IMAGE_MEMORY_REQUIREMENTS_2_KHR = (VkStructureType) 1000146004;
#endif // VK_KHR_get_memory_requirements2
// Also needed for VulkanMemoryAllocator
#ifndef VK_KHR_dedicated_allocation
#define VK_KHR_dedicated_allocation 1
#define VK_KHR_DEDICATED_ALLOCATION_SPEC_VERSION 3
#define VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME "VK_KHR_dedicated_allocation"
typedef struct VkMemoryDedicatedRequirementsKHR {
VkStructureType sType;
void* pNext;
VkBool32 prefersDedicatedAllocation;
VkBool32 requiresDedicatedAllocation;
} VkMemoryDedicatedRequirementsKHR;
typedef struct VkMemoryDedicatedAllocateInfoKHR {
VkStructureType sType;
const void* pNext;
VkImage image;
VkBuffer buffer;
} VkMemoryDedicatedAllocateInfoKHR;
static constexpr VkStructureType VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR = (VkStructureType) 1000127000;
static constexpr VkStructureType VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR = (VkStructureType) 1000127001;
#endif // VK_KHR_dedicated_allocation
#endif
#endif

View File

@ -1,73 +0,0 @@
# Copyright 2018 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
if (is_fuchsia) {
import("//build/vulkan/config.gni")
}
declare_args() {
skia_vulkan_header = ""
skia_tools_vulkan_header_dir = ""
# When buliding on Android we get the header via the NDK so no need for any extra path.
if (is_fuchsia) {
skia_tools_vulkan_header_dir = "$fuchsia_vulkan_sdk/include"
} else if (is_linux || is_win) {
if (defined(skia_vulkan_sdk) && skia_vulkan_sdk != "") {
skia_tools_vulkan_header_dir = "$skia_vulkan_sdk/include"
}
}
}
config("moltenvk") {
if (defined(skia_moltenvk_path) && skia_moltenvk_path != "") {
if (is_ios) {
moltenvk_framework_path = "$skia_moltenvk_path/MoltenVK/iOS"
} else {
moltenvk_framework_path = "$skia_moltenvk_path/MoltenVK/macOS"
}
cflags = [
"-F$moltenvk_framework_path",
"-isystem$skia_moltenvk_path/MoltenVK/include", # for <vulkan/vulkan.h>
]
ldflags = [ "-F$moltenvk_framework_path" ]
libs = [
"MoltenVK.framework",
"Metal.framework",
"IOSurface.framework",
"QuartzCore.framework",
"Foundation.framework",
]
if (is_ios) {
libs += [ "UIKit.framework" ]
} else {
libs += [ "IOKit.framework" ]
}
defines = [ "SK_MOLTENVK" ]
}
}
config("vulkan_config") {
include_dirs = []
configs = []
if (skia_tools_vulkan_header_dir != "") {
include_dirs += [ skia_tools_vulkan_header_dir ]
}
defines = [ "SK_VULKAN" ]
if (skia_vulkan_header != "") {
defines += [ "SK_VULKAN_HEADER=\"$skia_vulkan_header\"" ]
} else if (defined(is_skia_standalone) && is_skia_standalone &&
!is_official_build) {
defines += [ "SK_VULKAN_HEADER=\"GrVulkanDefines.h\"" ]
}
if (defined(skia_moltenvk_path) && skia_moltenvk_path != "") {
configs += [ ":moltenvk" ]
}
}
source_set("vulkan") {
public_configs = [ ":vulkan_config" ]
}

8
third_party/vulkan/SkiaVulkan.h vendored Normal file
View File

@ -0,0 +1,8 @@
/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "vulkan/vulkan_core.h"

View File

@ -10,9 +10,11 @@ config("vulkanmemoryallocator_public") {
source_set("vulkanmemoryallocator") {
public_configs = [ ":vulkanmemoryallocator_public" ]
include_dirs = [ "../vulkan" ]
# Need to add this so when we include GrVkDefines.h it internally can find SkTypes.h which is
# needed in case the user set defines in SkUserConfig.h.
include_dirs = [ "../../include/core" ]
include_dirs += [ "../../include/core" ]
include_dirs += [ "../../include/config" ]
if (defined(is_skia_standalone) && is_skia_standalone && !is_official_build) {
include_dirs += [ "../../tools/gpu/vk" ]
@ -24,12 +26,6 @@ source_set("vulkanmemoryallocator") {
"GrVulkanMemoryAllocator.h",
]
# TODO: As described in the main skia BUILD.gn file we eventually want to move this to be
# //third_party/vulkan once clients have created their own //third_party/vulkan directory.
deps = [
"../vulkan",
]
# Warnings are just noise if we're not maintaining the code.
if (is_win) {
cflags = [ "/w" ]

View File

@ -12,7 +12,7 @@
#ifndef GrVulkanMemoryAllocator_DEFINED
#define GrVulkanMemoryAllocator_DEFINED
#include "../../include/gpu/vk/GrVkDefines.h"
#include "../vulkan/SkiaVulkan.h"
#include "include/vk_mem_alloc.h"
#endif

View File

@ -10,29 +10,34 @@
#include "SkTypes.h"
#ifdef SK_MOLTENVK
#include <MoltenVk/mvk_vulkan.h>
#else
#if defined(SK_BUILD_FOR_WIN)
# if !defined(VK_USE_PLATFORM_WIN32_KHR)
# define VK_USE_PLATFORM_WIN32_KHR
# endif
#elif defined(SK_BUILD_FOR_ANDROID)
# if !defined(VK_USE_PLATFORM_ANDROID_KHR)
# define VK_USE_PLATFORM_ANDROID_KHR
# endif
#elif defined(SK_BUILD_FOR_UNIX)
# if !defined(VK_USE_PLATFORM_XCB_KHR)
# define VK_USE_PLATFORM_XCB_KHR
# endif
#endif
// We create our own function table and never directly call any functions via vk*(). So no
// need to include the prototype functions.
#if !defined(VK_NO_PROTOTYPES)
#define VK_NO_PROTOTYPES
#endif
#include <vulkan/vulkan.h> // IWYU pragma: export
#endif
#if defined(SK_BUILD_FOR_WIN)
# if !defined(VK_USE_PLATFORM_WIN32_KHR)
# define VK_USE_PLATFORM_WIN32_KHR
# endif
#elif defined(SK_BUILD_FOR_ANDROID)
# if !defined(VK_USE_PLATFORM_ANDROID_KHR)
# define VK_USE_PLATFORM_ANDROID_KHR
# endif
#elif defined(SK_BUILD_FOR_UNIX)
# if !defined(VK_USE_PLATFORM_XCB_KHR)
# define VK_USE_PLATFORM_XCB_KHR
# endif
#elif defined(SK_BUILD_FOR_MAC)
# if !defined(VK_USE_PLATFORM_MACOS_MVK)
# define VK_USE_PLATFORM_MACOS_MVK
# endif
#elif defined(SK_BUILD_FOR_IOS)
# if !defined(VK_USE_PLATFORM_IOS_MVK)
# define VK_USE_PLATFORM_IOS_MVK
# endif
#endif
// We create our own function table and never directly call any functions via vk*(). So no
// need to include the prototype functions. We do them for molten vk however.
#if !defined(SK_MOLTENVK) && !defined(VK_NO_PROTOTYPES)
#define VK_NO_PROTOTYPES
#endif
#include <vulkan/vulkan.h> // IWYU pragma: export
#endif

View File

@ -12,6 +12,7 @@
#ifdef SK_VULKAN
#include "GrVulkanDefines.h"
#include "vk/GrVkBackendContext.h"
namespace sk_gpu_test {

View File

@ -12,6 +12,7 @@
#ifdef SK_VULKAN
#include "GrVulkanDefines.h"
#include "vk/GrVkBackendContext.h"
#include "vk/GrVkTypes.h"
#include <functional>