Skip to content

Commit

Permalink
Promotion from AMD internal branch for 2024.Q4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
qiaojbao committed Dec 4, 2024
2 parents 522dd55 + 3a396c7 commit 1e38df7
Show file tree
Hide file tree
Showing 486 changed files with 8,989 additions and 31,086 deletions.
119 changes: 34 additions & 85 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,112 +25,60 @@

cmake_minimum_required(VERSION 3.21)

project(VKGC LANGUAGES C CXX)
project(LLPCrepo LANGUAGES C CXX)

### Standalone LLPC build handling
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
include(cmake/CompilerStandalone.cmake)
set(LLPC_IS_STANDALONE ON)
endif()

### Find LLVM (needed by llpc_version.cmake).
include("cmake/findllvm.cmake")

### Version info ###
include(cmake/llpc_version.cmake)
if(NOT ICD_BUILD_LLPC)
set(DISABLE_LLPC_VERSION_USES_LLVM ON)
endif()

add_llpc_version_projects()

### Top-level VKGC Interface ###
add_library(vkgc INTERFACE)

### VKGC header-only library ###
add_library(vkgc_headers INTERFACE)

target_link_libraries(vkgc_headers INTERFACE llpc_version)

### Cached Project Options #############################################################################################
option(LLPC_BUILD_TOOLS "LLPC build all tools" OFF)
### Options that affect the headers ####################################################################################
#if VKI_BUILD_GFX11
if(LLPC_BUILD_GFX11)
target_compile_definitions(vkgc_headers INTERFACE VKI_BUILD_GFX11)
endif()
#endif

if(VKI_RAY_TRACING)
if(NOT LLPC_IS_STANDALONE)
target_compile_definitions(vkgc_headers INTERFACE HAVE_GPURT_SHIM)
endif()

target_compile_definitions(vkgc_headers INTERFACE VKI_RAY_TRACING)
target_compile_definitions(vkgc_headers INTERFACE GPURT_CLIENT_INTERFACE_MAJOR_VERSION=${GPURT_CLIENT_INTERFACE_MAJOR_VERSION})
endif()

target_link_libraries(vkgc INTERFACE vkgc_headers)
#if LLPC_RAY_TRACING
option(LLPC_RAY_TRACING "Enable raytracing" OFF)
#endif
#if LLPC_AMD_YUV_IMAGE
option(LLPC_AMD_YUV_IMAGE "Build with AMD_YUV_IMAGE" OFF)
#endif
#if LLPC_AMD_LVR_INTEROP
option(LLPC_AMD_LVR_INTEROP "Build with AMD_LVR_INTEROP" OFF)
#endif

### Expose header files ################################################################################################
target_include_directories(vkgc_headers
INTERFACE
${PROJECT_SOURCE_DIR}/include
### VKGC aspects ###################################################################
# For drivers that use VKGC, as the interface to the LLPC front-end
if (FALSE
OR ICD_BUILD_LLPC
)

### external SPIRV headers #########################################################
if (NOT SPIRV_HEADERS_PATH)
if(EXISTS ${PROJECT_SOURCE_DIR}/../SPIRV-Headers)
set(SPIRV_HEADERS_PATH ${PROJECT_SOURCE_DIR}/../SPIRV-Headers CACHE PATH "The path of SPIRV headers.")
elseif(EXISTS ${PROJECT_SOURCE_DIR}/../../../../SPIRV-Headers)
set(SPIRV_HEADERS_PATH ${PROJECT_SOURCE_DIR}/../../../../SPIRV-Headers CACHE PATH "The path of SPIRV headers.")
endif()
include("cmake/vkgc.cmake")
endif()

### Interface Target ###################################################################################################
### SPIRV Interface ###
add_library(khronos_spirv_interface INTERFACE)

if(EXISTS ${SPIRV_HEADERS_PATH})
target_include_directories(khronos_spirv_interface
INTERFACE
${SPIRV_HEADERS_PATH}/include
${PROJECT_SOURCE_DIR}/include/khronos
)
if (NOT SPIRV_HEADERS_PATH_INTERNAL)
target_compile_definitions(khronos_spirv_interface
INTERFACE
EXTERNAL_SPIRV_HEADERS=1
)
endif()
else()
target_include_directories(khronos_spirv_interface
INTERFACE
${PROJECT_SOURCE_DIR}/include/khronos
)
endif()

if(LLPC_BUILD_TOOLS)
# SPVGEN
if(EXISTS ${PROJECT_SOURCE_DIR}/../spvgen)
set(XGL_SPVGEN_PATH ${PROJECT_SOURCE_DIR}/../spvgen CACHE PATH "Specify the path to SPVGEN.")
elseif(EXISTS ${PROJECT_SOURCE_DIR}/../xgl/tools/spvgen)
set(XGL_SPVGEN_PATH ${PROJECT_SOURCE_DIR}/../xgl/tools/spvgen CACHE PATH "Specify the path to SPVGEN.")
else()
set(XGL_SPVGEN_PATH ${PROJECT_SOURCE_DIR}/../../../tools/spvgen CACHE PATH "Specify the path to SPVGEN.")
### LGC for LLPC ###################################################################
if (ICD_BUILD_LLPC)
# Add LGC and its dependencies as LLVM external projects for LLPC to use.
include("cmake/lgc.cmake")
add_lgc_projects()
endif()

if(EXISTS ${XGL_SPVGEN_PATH})
set(XGL_SPVGEN_BUILD_PATH ${CMAKE_BINARY_DIR}/spvgen)
add_subdirectory(${XGL_SPVGEN_PATH} ${XGL_SPVGEN_BUILD_PATH} EXCLUDE_FROM_ALL)
endif()

endif(LLPC_BUILD_TOOLS)

if(ICD_BUILD_LLPC)
# Generate Strings for LLPC standalone tool and vkgc_gpurtshim
add_subdirectory(util ${PROJECT_BINARY_DIR}/util)
add_subdirectory(gfxruntime ${PROJECT_BINARY_DIR}/gfxruntime)
### LLVM ###########################################################################
if (LLVM_EXTERNAL_PROJECTS)
if (ICD_BUILD_LLPC AND LLPC_BUILD_TESTS)
set(LLVM_INCLUDE_TESTS ON CACHE BOOL "Force enable LLVM_INCLUDE_TESTS to include gmock" FORCE)
endif()
# Build LLVM.
include("cmake/llvm.cmake")
endif()

### VKGC build LLPC ################################################################
### Build LLPC #####################################################################
if(ICD_BUILD_LLPC)
include("cmake/compilerutils.cmake")
add_compilerutils_projects()
Expand All @@ -144,7 +92,6 @@ if(ICD_BUILD_LLPC)
add_subdirectory(llpc ${PROJECT_BINARY_DIR}/llpc)

if(LLPC_BUILD_TESTS)
set(LLVM_INCLUDE_TESTS ON CACHE BOOL "Force enable LLVM_INCLUDE_TESTS to include gmock" FORCE)
add_subdirectory(test)
endif()

Expand Down Expand Up @@ -179,9 +126,11 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
if(ICD_BUILD_LLPC)
set_property(TARGET llpc PROPERTY FOLDER Compiler)
set_property(TARGET llpcinternal PROPERTY FOLDER Compiler)
if(VKI_RAY_TRACING AND NOT LLPC_IS_STANDALONE)
#if LLPC_RAY_TRACING
if(LLPC_RAY_TRACING AND NOT LLPC_IS_STANDALONE)
set_property(TARGET vkgc_gpurtshim PROPERTY FOLDER Compiler)
endif()
#endif
set_property(TARGET vkgc_util PROPERTY FOLDER Compiler)
if (LLPC_BUILD_TOOLS)
set_property(TARGET amdllpc PROPERTY FOLDER Compiler)
Expand Down
3 changes: 2 additions & 1 deletion cmake/CompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function(set_compiler_options PROJECT_NAME ENABLE_WERROR)
target_compile_options("${PROJECT_NAME}" PRIVATE
-Werror
-Wno-error=deprecated-declarations
-Wno-error=unknown-attributes
)
endif()

Expand Down Expand Up @@ -74,7 +75,7 @@ function(set_compiler_options PROJECT_NAME ENABLE_WERROR)
-Wno-gnu-anonymous-struct
-Wno-nested-anon-types
)
if(XGL_ENABLE_LTO)
if(LLPC_ENABLE_LTO)
target_link_libraries("${PROJECT_NAME}" PRIVATE -flto=thin)
endif()
endif()
Expand Down
37 changes: 37 additions & 0 deletions cmake/findllvm.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
##
#######################################################################################################################
#
# Copyright (c) 2024 Advanced Micro Devices, Inc. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
#######################################################################################################################

if (NOT LLPC_LLVM_SRC_PATH)
# Find LLVM source. Allow client driver to override using its own name for overlay builds.
set(DEFAULT_LLPC_LLVM_SRC_PATH ${XGL_LLVM_SRC_PATH})
if (NOT DEFAULT_LLPC_LLVM_SRC_PATH)
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/../../../imported/llvm-project/llvm)
set(DEFAULT_LLPC_LLVM_SRC_PATH ${CMAKE_CURRENT_LIST_DIR}/../../../imported/llvm-project/llvm)
elseif(EXISTS ${CMAKE_CURRENT_LIST_DIR}/../../llvm-project/llvm)
set(DEFAULT_LLPC_LLVM_SRC_PATH ${CMAKE_CURRENT_LIST_DIR}/../../llvm-project/llvm)
endif()
endif()
set(LLPC_LLVM_SRC_PATH ${DEFAULT_LLPC_LLVM_SRC_PATH} CACHE PATH "Specify the path to LLVM.")
endif()
2 changes: 2 additions & 0 deletions cmake/llpc_version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

set(LLPC_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/..")

include("${LLPC_SOURCE_DIR}/cmake/findllvm.cmake")

macro(add_llpc_version_projects)
if (NOT TARGET llpc_version)
# Force the binary directory to account for the possibility that LLPC is
Expand Down
129 changes: 129 additions & 0 deletions cmake/llvm.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
##
#######################################################################################################################
#
# Copyright (c) 2024 Advanced Micro Devices, Inc. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
#######################################################################################################################

# Build LLVM, using previously set up LLVM_EXTERNAL_PROJECTS and LLVM_EXTERNAL_*_SOURCE_DIR.
# Relies on findllvm.cmake being run first.

if (NOT LLPC_LLVM_SRC_PATH)
message(FATAL_ERROR "No LLPC_LLVM_SRC_PATH specified")
endif()

# Set cached options.
set(LLVMRAYTRACING_BUILD_TESTS ${LLPC_BUILD_TESTS})
set(LLVM_TARGETS_TO_BUILD AMDGPU CACHE STRING "LLVM targets to build")
set(LLVM_BUILD_TESTS OFF CACHE BOOL "LLVM build tests")
set(LLVM_BUILD_TOOLS ${LLPC_BUILD_LLVM_TOOLS} CACHE BOOL "LLVM build tools")
set(LLVM_BUILD_UTILS OFF CACHE BOOL "LLVM build utils")
set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "LLVM include docs")
set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "LLVM include examples")
set(LLVM_INCLUDE_GO_TESTS OFF CACHE BOOL "LLVM include go tests")
set(LLVM_INCLUDE_TESTS ${LLPC_BUILD_TESTS} CACHE BOOL "LLVM include tests")
set(LLVM_INCLUDE_TOOLS ON CACHE BOOL "LLVM include tools")
set(LLVM_INCLUDE_UTILS ON CACHE BOOL "LLVM include utils")
set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "LLVM enable terminfo")
set(LLVM_RAM_PER_TABLEGEN_JOB 4000 CACHE STRING "LLVM RAM per tablegen job")
set(LLVM_RAM_PER_LINK_JOB 5000 CACHE STRING "LLVM RAM per link job")
if(CMAKE_BUILD_TYPE_DEBUG)
# Build optimized version of llvm-tblgen even in debug builds, for faster build times.
set(LLVM_OPTIMIZED_TABLEGEN ON CACHE BOOL "Build optimized llvm-tblgen")
#if _WIN32
if(LLVM_OPTIMIZED_TABLEGEN AND WIN32 AND (CMAKE_GENERATOR MATCHES "Ninja"))
# LLVM implements the Release build of llvm-tblgen as a cross-compile target, which fails to find
# our DK-based toolchain (created with amd_generate_msvc_toolchain). However, we can inject the toolchain
# argument into LLVM's add_custom_target that sets up this cross-compile build.
# See: llvm-project/llvm/cmake/modules/CrossCompile.cmake
set(CROSS_TOOLCHAIN_FLAGS_NATIVE "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}" CACHE STRING
"Toolchain flags for native build" FORCE)
endif()
#endif
endif()

# This will greatly speed up debug builds because we won't be listing all the symbols with llvm-nm.
set(LLVM_BUILD_LLVM_C_DYLIB OFF CACHE BOOL "LLVM build LLVM-C dylib")

# Remove /nologo from CMAKE_RC_FLAGS to avoid getting an error from specifying it twice in LLVM.
if (CMAKE_RC_FLAGS)
string(REPLACE "/nologo" "" CMAKE_RC_FLAGS ${CMAKE_RC_FLAGS})
endif()

# Build LLVM.
if (NOT LLPC_LLVM_BUILD_PATH)
set(LLPC_LLVM_BUILD_PATH ${PROJECT_BINARY_DIR}/llvm)
endif()
if (ICD_BUILD_LLPC)
add_subdirectory(${LLPC_LLVM_SRC_PATH} ${LLPC_LLVM_BUILD_PATH})
else()
add_subdirectory(${LLPC_LLVM_SRC_PATH} ${LLPC_LLVM_BUILD_PATH} EXCLUDE_FROM_ALL)
endif()

# Get LLVMConfig onto cmake path.
list(APPEND CMAKE_MODULE_PATH
"${LLPC_LLVM_BUILD_PATH}/lib/cmake/llvm"
"${LLPC_LLVM_BUILD_PATH}/${CMAKE_CFG_INTDIR}/lib/cmake/llvm" # Workaround for VS generator with older LLVM.
)

# Export LLVM build path for client driver.
# TODO: Change uses to LLPC_LLVM_BUILD_PATH.
set(XGL_LLVM_BUILD_PATH ${LLPC_LLVM_BUILD_PATH} PARENT_SCOPE)

# Extract LLVM revision number for code outside the LLPC repository to use.
file(READ "${LLPC_LLVM_SRC_PATH}/include/llvm/Config/llvm-config.h.cmake" LLVM_CONFIG_HEADER)
string(REGEX MATCH "#define LLVM_MAIN_REVISION ([0-9]+)" "\\1" _ "${LLVM_CONFIG_HEADER}")
set(LLVM_MAIN_REVISION "${CMAKE_MATCH_1}")
set(LLVM_MAIN_REVISION ${LLVM_MAIN_REVISION} PARENT_SCOPE)

# Some of the games using old versions of the tcmalloc lib are crashing
# when allocating aligned memory. C++17 enables aligned new by default,
# so we need to disable it to prevent those crashes.
if (ICD_BUILD_LLPC AND NOT WIN32)
llvm_map_components_to_libnames(llvm_libs
AMDGPUAsmParser
AMDGPUCodeGen
AMDGPUDisassembler
AMDGPUInfo
Analysis
BinaryFormat
Core
Coroutines
BitReader
BitWriter
CodeGen
InstCombine
ipo
IRPrinter
IRReader
Linker
LTO
MC
Passes
ScalarOpts
Support
Target
TransformUtils
)
foreach (lib ${llvm_libs})
target_compile_options(${lib} PRIVATE "-fno-aligned-new")
endforeach()
endif()
Loading

0 comments on commit 1e38df7

Please sign in to comment.