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
21 changes: 21 additions & 0 deletions .github/workflows/win_msvc_dbg_x64_cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,32 @@ jobs:
cd vcpkg
.\bootstrap-vcpkg.bat

- name: Install depot_tools
shell: cmd
run: |
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git ..\depot_tools
set "PATH=%CD%\..\depot_tools;%PATH%"
gclient

- name: Set up Python 3.x
uses: actions/setup-python@v2
with:
python-version: '3.x'

- uses: actions/checkout@v2
with:
path: test
fetch-depth: 0

- name: Sync code for main branch (with patch)
shell: cmd
run: |
set "PATH=%CD%\..\depot_tools;%PATH%"
set "DEPOT_TOOLS_WIN_TOOLCHAIN=0"
cd test
copy scripts\standalone.gclient .gclient
gclient sync

- name: Generate project for main branch (with patch)
shell: cmd
run: |
Expand Down
30 changes: 23 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,44 @@ set(GPGMM_INCLUDE_DIR "${GPGMM_ROOT_DIR}/src/include")
# option(name description default)
# If a variable is not already defined with the given name, otherwise the
# function does nothing.
# Simplifies customization by projects that use Dawn as a dependency.
function (option_if_not_defined name description default)
if(NOT DEFINED ${name})
option(${name} ${description} ${default})
endif()
endfunction()

# set_if_not_defined(name value description)
# Behaves like:
# set(${name} ${value} CACHE STRING ${description})
# If a variable is not already defined with the given name, otherwise the
# function does nothing.
function (set_if_not_defined name value description)
if(NOT DEFINED ${name})
set(${name} ${value} CACHE STRING ${description})
endif()
endfunction()

# Default values for the backend-enabling options
set(ENABLE_D3D12 OFF)
set(ENABLE_VULKAN OFF)
set(ENABLE_VK OFF)
if (WIN32)
set(ENABLE_D3D12 ON)
if (NOT WINDOWS_STORE)
# Enable Vulkan in win32 compilation only
# since UWP only supports d3d
set(ENABLE_VULKAN ON)
set(ENABLE_VK ON)
endif()
elseif(UNIX)
set(ENABLE_VULKAN ON)
set(ENABLE_VK ON)
endif()

option_if_not_defined(GPGMM_ENABLE_D3D12 "Enable compilation of the D3D12 backend" ${ENABLE_D3D12})
option_if_not_defined(GPGMM_ENABLE_VULKAN "Enable compilation of the Vulkan backend" ${ENABLE_VULKAN})
option_if_not_defined(GPGMM_ENABLE_VK "Enable compilation of the Vulkan backend" ${ENABLE_VK})

set_if_not_defined(GPGMM_THIRD_PARTY_DIR "${GPGMM_SOURCE_DIR}/third_party" "Directory in which to find third-party dependencies.")
set_if_not_defined(GPGMM_VK_DEPS_DIR "${GPGMM_THIRD_PARTY_DIR}/vulkan-deps" "Directory in which to find vulkan-deps")
set_if_not_defined(GPGMM_VK_HEADERS_DIR "${GPGMM_VK_DEPS_DIR}/vulkan-headers/src" "Directory in which to find Vulkan-Headers")
set_if_not_defined(GPGMM_VK_TOOLS_DIR "${GPGMM_VK_DEPS_DIR}/vulkan-tools/src" "Directory in which to find Vulkan-Tools")

option_if_not_defined(GPGMM_ALWAYS_ASSERT "Enable assertions on all build types" OFF)

Expand All @@ -91,8 +106,8 @@ endif()
if (GPGMM_ENABLE_D3D12)
target_compile_definitions(gpgmm_common_config INTERFACE "GPGMM_ENABLE_D3D12")
endif()
if (GPGMM_ENABLE_VULKAN)
target_compile_definitions(gpgmm_common_config INTERFACE "GPGMM_ENABLE_VULKAN")
if (GPGMM_ENABLE_VK)
target_compile_definitions(gpgmm_common_config INTERFACE "GPGMM_ENABLE_VK")
endif()
if (WIN32)
target_compile_definitions(gpgmm_common_config INTERFACE "NOMINMAX" "WIN32_LEAN_AND_MEAN")
Expand All @@ -103,4 +118,5 @@ set(CMAKE_CXX_STANDARD "14")
################################################################################
# Build subdirectories
################################################################################
add_subdirectory(third_party)
add_subdirectory(src/gpgmm)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ To build with a backend, please set the corresponding argument from following ta
| Backend | Build argument |
|---------|--------------|
| DirectX 12 | `gpgmm_enable_d3d12=true` (default on winos) |
| Vulkan | `gpgmm_enable_vulkan=true` |
| Vulkan | `gpgmm_enable_vk=true` |

### Build

Expand Down
27 changes: 25 additions & 2 deletions build_overrides/gpgmm_features.gni
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 The GPMM Authors
# Copyright 2021 The GPGMM Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,9 +37,13 @@ declare_args() {
# Sets -dGPGMM_FORCE_TRACING
gpgmm_force_tracing = false

# Enables the compilation of the D3D12 backend.
# Enables the compilation of the DirectX 12 backend.
gpgmm_enable_d3d12 = is_win

# Enables the compilation of the Vulkan backend
gpgmm_enable_vk = is_linux || is_chromeos || (is_win && !gpgmm_is_winuwp) ||
is_fuchsia || is_android

# Enables compilation of Dawn's end2end tests.
gpgmm_enable_dawn = checkout_dawn

Expand All @@ -66,3 +70,22 @@ declare_args() {
# Sets -dGPGMM_ENABLE_DEVICE_CHECKS
gpgmm_enable_device_checks = false
}

# Declare separately since both depend on |gpgmm_enable_vk| and GN does not allow
# args to depend on another args in the same declare_args().
declare_args() {
# Uses our built version of the Vulkan validation layers
gpgmm_enable_vk_validation_layers =
gpgmm_enable_vk && ((is_linux && !is_chromeos) || is_win || is_mac)

# Uses our built version of the Vulkan loader on platforms where we can't
# assume to have one present at the system level.
gpgmm_enable_vk_loader =
gpgmm_enable_vk && (is_mac || (is_linux && !is_android))

# Configures Vulkan functions by statically importing them (ie. importing the Vulkan loader symbols).
gpgmm_vk_static_functions = true

# Configures Vulkan functions by dynamically importing them (ie. using vkGetInstanceProcAddr and vkGetDeviceProcAddr).
gpgmm_vk_dynamic_functions = false
}
26 changes: 26 additions & 0 deletions build_overrides/gpgmm_overrides_with_defaults.gni
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,29 @@ if (!defined(gpgmm_googletest_dir)) {
if (!defined(gpgmm_jsoncpp_dir)) {
gpgmm_jsoncpp_dir = "//third_party/jsoncpp"
}

if (!defined(gpgmm_vk_deps_dir)) {
gpgmm_vk_deps_dir = "//third_party/vulkan-deps"
if (gpgmm_standalone) {
gpgmm_vk_deps_dir = "${gpgmm_root_dir}/third_party/vulkan-deps"
}
}

if (!defined(gpgmm_vk_headers_dir)) {
gpgmm_vk_headers_dir = "${gpgmm_vk_deps_dir}/vulkan-headers/src"
}

if (!defined(gpgmm_vk_loader_dir)) {
gpgmm_vk_loader_dir = ""
if (gpgmm_standalone) {
gpgmm_vk_loader_dir = "${gpgmm_vk_deps_dir}/vulkan-loader/src"
}
}

if (!defined(gpgmm_vk_tools_dir)) {
gpgmm_vk_tools_dir = "${gpgmm_vk_deps_dir}/vulkan-tools/src"
}

if (!defined(gpgmm_vk_validation_layers_dir)) {
gpgmm_vk_validation_layers_dir = ""
}
8 changes: 8 additions & 0 deletions build_overrides/vulkan_loader.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build_overrides/vulkan_common.gni")

# When Vulkan-loader is statically linked, we must use this extension.
vulkan_loader_shared = true
1 change: 0 additions & 1 deletion build_overrides/vulkan_validation_layers.gni
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import("//build_overrides/vulkan_common.gni")

vulkan_headers_dir = "//third_party/vulkan-deps/vulkan-headers/src"
vvl_spirv_tools_dir = "//third_party/vulkan-deps/spirv-tools/src"
vvl_glslang_dir = "//third_party/vulkan-deps/glslang/src"

Expand Down
2 changes: 1 addition & 1 deletion scripts/webnn.deps
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ deps = {
'condition': 'gpgmm_standalone',
},
'third_party/vulkan-deps': {
'url': '{chromium_git}/vulkan-deps@b2b44c000ee6dd3beaf2a381bbc9a24a270c84a1',
'url': '{chromium_git}/vulkan-deps@7e9ab0686bf4d4fa9c52eeb8def33b2057624987',
'condition': 'gpgmm_standalone',
},
'third_party/jsoncpp/source': {
Expand Down
81 changes: 68 additions & 13 deletions src/gpgmm/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ if (is_mac) {
}

# The VVLs are an optional dependency, only use it if the path has been set.
# enable_vulkan_validation_layers = gpgmm_enable_vulkan_validation_layers &&
# gpgmm_vulkan_validation_layers_dir != ""
# if (enable_vulkan_validation_layers) {
# import("//build_overrides/vulkan_validation_layers.gni")
# }
enable_vk_validation_layers =
gpgmm_enable_vk_validation_layers && gpgmm_vk_validation_layers_dir != ""
if (enable_vk_validation_layers) {
import("//build_overrides/vulkan_validation_layers.gni")
}

# The Vulkan loader is an optional dependency, only use it if the path has been
# set.
# if (gpgmm_enable_vulkan) {
# enable_vulkan_loader =
# gpgmm_enable_vulkan_loader && gpgmm_vulkan_loader_dir != ""
# }
if (gpgmm_enable_vk) {
enable_vk_loader = gpgmm_vk_static_functions ||
(gpgmm_enable_vk_loader && gpgmm_vk_loader_dir != "")
}

config("gpgmm_common_config") {
configs = [ "${gpgmm_root_dir}/src/gpgmm/common:gpgmm_common_config" ]
Expand All @@ -61,17 +61,20 @@ config("gpgmm_common_config") {
}
}

# Config that adds the @executable_path rpath if needed so that Swiftshader or the Vulkan loader are found.
config("gpgmm_vulkan_rpath") {
if (is_mac && gpgmm_enable_vulkan &&
(use_swiftshader || enable_vulkan_loader)) {
# Config that adds the @executable_path rpath if needed so the Vulkan loader are found.
config("vulkan_rpath") {
if (is_mac && gpgmm_enable_vk && enable_vk_loader) {
ldflags = [
"-rpath",
"@executable_path/",
]
}
}

config("vulkan_tools_include") {
include_dirs = [ "${gpgmm_vk_tools_dir}" ]
}

# Public gpgmm headers so they can be publicly visible for
# dependencies of gpgmm
source_set("gpgmm_headers") {
Expand Down Expand Up @@ -116,6 +119,10 @@ source_set("gpgmm_sources") {
defines += [ "GPGMM_ENABLE_DEVICE_CHECKS" ]
}

if (gpgmm_vk_static_functions) {
defines += [ "GPGMM_STATIC_VULKAN_FUNCTIONS" ]
}

libs = []
data_deps = []

Expand Down Expand Up @@ -242,6 +249,42 @@ source_set("gpgmm_sources") {
"d3d12/d3d12_platform.h",
]
}

if (gpgmm_enable_vk) {
configs += [ ":vulkan_tools_include" ]
deps += [ "${gpgmm_vk_tools_dir}:vulkan_tools_headers" ]
public_deps = [ "${gpgmm_vk_headers_dir}:vulkan_headers" ]

sources += [
"vk/CapsVk.cpp",
"vk/CapsVk.h",
"vk/DeviceMemoryAllocatorVk.cpp",
"vk/DeviceMemoryAllocatorVk.h",
"vk/DeviceMemoryVk.cpp",
"vk/DeviceMemoryVk.h",
"vk/ErrorVk.h",
"vk/FunctionsVk.cpp",
"vk/FunctionsVk.h",
"vk/ResourceAllocatorVk.cpp",
"vk/ResourceAllocatorVk.h",
]

if (enable_vk_validation_layers) {
defines += [
"GPGMM_ENABLE_VK_VALIDATION_LAYERS",
"GPGMM_VK_DATA_DIR=\"$vulkan_data_subdir\"",
]
}

if (enable_vk_loader) {
# Loader must be a linked dependency when using importing functions statically.
if (gpgmm_vk_static_functions) {
deps += [ "${gpgmm_vk_loader_dir}:libvulkan" ]
} else {
data_deps += [ "${gpgmm_vk_loader_dir}:libvulkan" ]
}
}
}
}

# Defines the type of target for GN to build.
Expand All @@ -258,4 +301,16 @@ if (gpgmm_shared_library) {
target(target_type, "gpgmm") {
public_deps = [ ":gpgmm_headers" ]
deps = [ ":gpgmm_sources" ]
public_configs = [ ":vulkan_rpath" ]

if (gpgmm_enable_vk) {
if (enable_vk_validation_layers) {
data_deps =
[ "${gpgmm_vk_validation_layers_dir}:vulkan_validation_layers" ]
if (!is_android) {
data_deps +=
[ "${gpgmm_vk_validation_layers_dir}:vulkan_gen_json_files" ]
}
}
}
}
21 changes: 20 additions & 1 deletion src/gpgmm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,26 @@ if (GPGMM_ENABLE_D3D12)
target_link_libraries(gpgmm PRIVATE dxguid.lib)
endif()

# TODO: GPGMM_ENABLE_VULKAN
if (GPGMM_ENABLE_VK)
target_sources(gpgmm PRIVATE
"vk/CapsVk.cpp"
"vk/CapsVk.h"
"vk/DeviceMemoryAllocatorVk.cpp"
"vk/DeviceMemoryAllocatorVk.h"
"vk/DeviceMemoryVk.cpp"
"vk/DeviceMemoryVk.h"
"vk/ErrorVk.h"
"vk/ResourceAllocatorVk.cpp"
"vk/ResourceAllocatorVk.h"
"vk/FunctionsVk.cpp"
"vk/FunctionsVk.h"
"vk/vk_platform.h"
)

target_link_libraries(gpgmm PUBLIC Vulkan-Headers)
target_include_directories(gpgmm PRIVATE ${GPGMM_VK_TOOLS_DIR})

endif()

################################################################################
# Build subdirectories
Expand Down
35 changes: 35 additions & 0 deletions src/gpgmm/vk/BackendVk.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2021 The GPGMM Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef GPGMM_VK_BACKENDVK_H_
#define GPGMM_VK_BACKENDVK_H_

#include "gpgmm/Backend.h"

namespace gpgmm { namespace vk {

class DeviceMemory;

struct BackendTrait {
using MemoryType = DeviceMemory;
};

template <typename T>
auto ToBackend(T&& common) -> decltype(gpgmm::ToBackend<BackendTrait>(common)) {
return gpgmm::ToBackend<BackendTrait>(common);
}

}} // namespace gpgmm::vk

#endif // GPGMM_VK_BACKENDVK_H_
Loading