@@ -0,0 +1,313 @@
##
#######################################################################################################################
#
# Copyright (c) 2017-2021 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.
#
#######################################################################################################################
include_guard()

macro(xgl_use_clang_compiler)
if(UNIX)
set(CMAKE_CXX_COMPILER_ID "Clang")
set(CMAKE_C_COMPILER_ID "Clang")

foreach(major RANGE 6 20)
find_program(CLANG_VER clang-${major})
if(CLANG_VER)
set(CLANG_VER ${major})
# llvm-ar named llvm-ar-6.0 on ubuntu18.04 for version 6
if(CLANG_VER EQUAL 6)
set(CLANG_VER "6.0")
endif()
break()
endif()
endforeach()

find_program(CLANG_C_COMPILER clang)
if (CLANG_C_COMPILER)
set(CMAKE_C_COMPILER ${CLANG_C_COMPILER} CACHE FILEPATH "" FORCE)
EXECUTE_PROCESS(COMMAND ${CLANG_C_COMPILER} --version OUTPUT_VARIABLE clang_full_version_string)
string(REGEX REPLACE ".*clang version ([0-9]+).*" "\\1" CLANG_VER ${clang_full_version_string})
# llvm-ar named llvm-ar-6.0 on ubuntu18.04 for version 6
if(CLANG_VER EQUAL 6)
set(CLANG_VER "6.0")
endif()
else()
find_program(CLANG_C_COMPILER clang-${CLANG_VER})
if (CLANG_C_COMPILER)
set(CMAKE_C_COMPILER ${CLANG_C_COMPILER} CACHE FILEPATH "" FORCE)
else()
message(FATAL_ERROR "clang cannot be found!")
endif()
endif()

find_program(CLANG_CXX_COMPILER clang++)
if (CLANG_CXX_COMPILER)
set(CMAKE_CXX_COMPILER ${CLANG_CXX_COMPILER} CACHE FILEPATH "" FORCE)
else()
find_program(CLANG_CXX_COMPILER clang++-${CLANG_VER})
if (CLANG_CXX_COMPILER)
set(CMAKE_CXX_COMPILER ${CLANG_CXX_COMPILER} CACHE FILEPATH "" FORCE)
else()
message(FATAL_ERROR "clang++ cannot be found!")
endif()
endif()

find_program(CLANG_AR llvm-ar)
if (CLANG_AR)
set(CMAKE_AR ${CLANG_AR} CACHE FILEPATH "" FORCE)
else()
find_program(CLANG_AR llvm-ar-${CLANG_VER})
if (CLANG_AR)
set(CMAKE_AR ${CLANG_AR} CACHE FILEPATH "" FORCE)
else()
message(FATAL_ERROR "llvm-ar cannot be found!")
endif()
endif()

find_program(CLANG_LINKER llvm-link)
if (CLANG_LINKER)
set(CMAKE_LINKER ${CLANG_LINKER} CACHE FILEPATH "" FORCE)
else()
find_program(CLANG_LINKER llvm-link-${CLANG_VER})
if (CLANG_LINKER)
set(CMAKE_LINKER ${CLANG_LINKER} CACHE FILEPATH "" FORCE)
else()
message(FATAL_ERROR "llvm-link cannot be found!")
endif()
endif()

find_program(CLANG_NM llvm-nm)
if (CLANG_NM)
set(CMAKE_NM ${CLANG_NM} CACHE FILEPATH "" FORCE)
else()
find_program(CLANG_NM llvm-nm-${CLANG_VER})
if (CLANG_NM)
set(CMAKE_NM ${CLANG_NM} CACHE FILEPATH "" FORCE)
else()
message(FATAL_ERROR "llvm-nm cannot be found!")
endif()
endif()

find_program(CLANG_OBJDUMP llvm-objdump)
if (CLANG_OBJDUMP)
set(CMAKE_OBJDUMP ${CLANG_OBJDUMP} CACHE FILEPATH "" FORCE)
else()
find_program(CLANG_OBJDUMP llvm-objdump-${CLANG_VER})
if (CLANG_OBJDUMP)
set(CMAKE_OBJDUMP ${CLANG_OBJDUMP} CACHE FILEPATH "" FORCE)
else()
message(FATAL_ERROR "llvm-objdump cannot be found!")
endif()
endif()

find_program(CLANG_RANLIB llvm-ranlib)
if (CLANG_RANLIB)
set(CMAKE_RANLIB ${CLANG_RANLIB} CACHE FILEPATH "" FORCE)
else()
find_program(CLANG_RANLIB llvm-ranlib-${CLANG_VER})
if (CLANG_RANLIB)
set(CMAKE_RANLIB ${CLANG_RANLIB} CACHE FILEPATH "" FORCE)
else()
message(FATAL_ERROR "llvm-ranlib cannot be found!")
endif()
endif()
endif()
endmacro()

macro(xgl_set_compiler)
# Before GCC7, when LTO is enabled, undefined reference error was observed when linking static libraries.
# Use the gcc-ar wrapper instead of ar, this invokes ar with the right plugin arguments
# --plugin /usr/lib/gcc/.../liblto_plugin.so
if(UNIX)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
find_program(GCC_AR gcc-ar)
if (GCC_AR)
set(CMAKE_AR ${GCC_AR})
else()
message(FATAL_ERROR "gcc-ar cannot be found!")
endif()
find_program(GCC_RANLIB gcc-ranlib)
if (GCC_RANLIB)
set(CMAKE_RANLIB ${GCC_RANLIB})
else()
message(FATAL_ERROR "gcc-ranlib cannot be found!")
endif()
endif()
endif()

# Assertions
if(XGL_ENABLE_ASSERTIONS)
# MSVC doesn't like _DEBUG on release builds.
if(NOT MSVC)
add_definitions(-D_DEBUG)
endif()
# On non-Debug builds CMake automatically defines NDEBUG, so we explicitly undefine it:
if(NOT CMAKE_BUILD_TYPE_DEBUG)
add_definitions(-UNDEBUG)

# Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines.
foreach(flags_var_to_scrub
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS_MINSIZEREL)
string(REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " "
"${flags_var_to_scrub}" "${${flags_var_to_scrub}}")
endforeach()
endif()
endif()

endmacro()

function(xgl_compiler_options TARGET)
# Set the C++ standard
set_target_properties(${TARGET} PROPERTIES
CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
POSITION_INDEPENDENT_CODE ON
)

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(${TARGET} PRIVATE
-Wall
-Wextra

# Don't warn if a structure’s initializer has some fields missing.
-Wno-missing-field-initializers

# Disable warnings about bad/undefined pointer arithmetic
-Wno-pointer-arith

# Don't warn whenever a switch statement has an index of enumerated type and
# lacks a case for one or more of the named codes of that enumeration.
-Wno-switch

# This turns off a lot of warnings related to unused code
# -Wunused-but-set-parameter
# -Wunused-but-set-variable
# -Wunused-function
# -Wunused-label
# -Wunused-local-typedefs
# -Wunused-parameter
# -Wno-unused-result
# -Wunused-variable
# -Wunused-const-variable
# -Wunused-value
-Wno-unused
)

if(ICD_ANALYSIS_WARNINGS_AS_ERRORS)
target_compile_options(${TARGET} PRIVATE
-Werror
-Wno-error=comment
-Wno-error=delete-non-abstract-non-virtual-dtor
-Wno-error=ignored-qualifiers
-Wno-error=missing-braces
-Wno-error=pointer-arith
-Wno-error=unused-parameter
)
endif()

target_compile_options(${TARGET} PRIVATE
-pthread

# Disables exception handling
-fno-exceptions

# Disable optimizations that assume strict aliasing rules
-fno-strict-aliasing

# Doesn’t guarantee the frame pointer is used in all functions.
-fno-omit-frame-pointer

# Having simple optimization on results in dramatically smaller debug builds (and they actually build faster).
# This is mostly due to constant-folding and dead-code-elimination of registers.
$<$<CONFIG:Debug>:
-Og
>
)

target_compile_options(${TARGET} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:
# Disable run time type information
# This means breaking dynamic_cast and typeid
-fno-rtti

# Do not set errno after calling math functions that are executed with a single instruction
-fno-math-errno
>)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(${TARGET} PRIVATE
# Output with color if in terminal: https://github.com/ninja-build/ninja/wiki/FAQ
-fdiagnostics-color=always
-mpreferred-stack-boundary=6
-fno-threadsafe-statics
-fmerge-all-constants
-fms-extensions
)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(${TARGET} PRIVATE
# Output with color if in terminal: https://github.com/ninja-build/ninja/wiki/FAQ
-fcolor-diagnostics

-Wthread-safety
)
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7))
target_compile_options(${TARGET} PRIVATE
-fno-delete-null-pointer-checks
)
endif()

if(TARGET_ARCHITECTURE_BITS EQUAL 32)
target_compile_options(${TARGET} PRIVATE -msse -msse2)
endif()

if(CMAKE_BUILD_TYPE_RELEASE)
target_compile_options(${TARGET} PRIVATE -O3)
if(XGL_ENABLE_LTO)
if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
if(GCC_VERSION VERSION_GREATER 5.3 OR GCC_VERSION VERSION_EQUAL 5.3)
# add global definition to enable LTO here since some components have no option
# to enable it.
add_definitions("-flto -fuse-linker-plugin -Wno-odr")
message(WARNING "LTO enabled for ${TARGET}")
endif()
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
# add global definition to enable LTO here since some components have no option
# to enable it.
add_definitions("-flto=thin")
message(WARNING "LTO enabled for ${TARGET}")
endif()
endif()
endif()
else()
message(FATAL_ERROR "Using unknown compiler")
endif()

endfunction()
@@ -0,0 +1,104 @@
##
#######################################################################################################################
#
# Copyright (c) 2017-2021 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.
#
#######################################################################################################################
include_guard()

### Helper Macros #####################################################################################################
macro(target_find_headers _target)
get_target_property(${_target}_INCLUDES_DIRS ${_target} INCLUDE_DIRECTORIES)

if(${_target}_INCLUDES_DIRS)
foreach(_include_dir IN ITEMS ${${_target}_INCLUDES_DIRS})
file(GLOB_RECURSE _include_files
LIST_DIRECTORIES false
"${_include_dir}/*.h"
"${_include_dir}/*.hpp"
)

list(APPEND ${_target}_INCLUDES ${_include_files})
endforeach()

target_sources(${_target} PRIVATE ${${_target}_INCLUDES})
endif()
endmacro()

# Source Groups Helper #############################################################################
# This helper creates source groups for generators that support them. This is primarily MSVC and
# XCode, but there are other generators that support IDE project files.
#
# Note: this only adds files that have been added to the target's SOURCES property. To add headers
# to this list, be sure that you call target_find_headers before you call target_source_groups.
macro(target_source_groups _target)
get_target_property(${_target}_SOURCES ${_target} SOURCES)
foreach(_source IN ITEMS ${${_target}_SOURCES})
set(_source ${_source})
get_filename_component(_source_path "${_source}" ABSOLUTE)
file(RELATIVE_PATH _source_path_rel "${PROJECT_SOURCE_DIR}" "${_source_path}")
get_filename_component(_source_path_rel "${_source_path_rel}" DIRECTORY)
string(REPLACE "/" "\\" _group_path "${_source_path_rel}")
source_group("${_group_path}" FILES "${_source}")
endforeach()
endmacro()

macro(xgl_append_common_sanitizer_flags)
if(NOT MSVC)
# Append -fno-omit-frame-pointer and turn on debug info to get better stack traces.
string(APPEND ICD_SANITIZER_COMPILE_FLAGS " -fno-omit-frame-pointer")
if (NOT CMAKE_BUILD_TYPE_DEBUG)
string(APPEND ICD_SANITIZER_COMPILE_FLAGS " -gline-tables-only")
else()
# Use -O1 even in debug mode, otherwise sanitizers slowdown is too large.
string(APPEND ICD_SANITIZER_COMPILE_FLAGS " -O1")
endif()
elseif(CLANG_CL)
# Keep frame pointers around.
string(APPEND ICD_SANITIZER_COMPILE_FLAGS " /Oy-")
# Always ask the linker to produce symbols with asan.
string(APPEND ICD_SANITIZER_COMPILE_FLAGS " /Z7")
string(APPEND ICD_SANITIZER_LINK_FLAGS " -debug")
endif()
endmacro()

macro(xgl_append_gcov_coverage_flags)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
# This option is used to compile and link code instrumented for coverage analysis.
# The option --coverage is a synonym for -fprofile-arcs -ftest-coverage (when compiling) and -lgcov (when linking)
# Ref link: https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#Instrumentation-Options
string(APPEND ICD_GCOV_COMPILE_FLAGS " --coverage")
string(APPEND ICD_GCOV_LINK_FLAGS " --coverage")

if (NOT CMAKE_BUILD_TYPE_DEBUG)
# Use -O0 even in not debug mode, otherwise code coverage is not accurate.
string(APPEND ICD_GCOV_COMPILE_FLAGS " -O0")
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
string(APPEND ICD_GCOV_COMPILE_FLAGS " -Xclang -coverage-cfg-checksum")
string(APPEND ICD_GCOV_COMPILE_FLAGS " -Xclang -coverage-no-function-names-in-data")
string(APPEND ICD_GCOV_COMPILE_FLAGS " -Xclang -coverage-version='408*'")
endif()
else()
message(FATAL_ERROR "Unknown compiler ID: ${CMAKE_CXX_COMPILER_ID}")
endif()
endmacro()
@@ -0,0 +1,83 @@
##
#######################################################################################################################
#
# Copyright (c) 2017-2021 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.
#
#######################################################################################################################
include_guard()

macro(xgl_options)

### Cached Project Options #############################################################################################

option(XGL_ENABLE_LTO "Build with LTO enabled?" ON)

option(XGL_ENABLE_GCOV "Build with gcov source code coverage?" OFF)

option(XGL_BUILD_VEGA20 "Build open source vulkan for Vega20?" ON)

option(XGL_BUILD_GFX103 "Build open source vulkan for GFX103" ON)

option(XGL_BUILD_NAVI22 "Build open source vulkan for Navi22" ON)

option(XGL_BUILD_LIT "Build with Lit test?" OFF)

option(XGL_BUILD_CACHE_CREATOR "Build cache-creator tools?" OFF)

#if VKI_KHR_SHADER_SUBGROUP_EXTENDED_TYPES
option(VKI_KHR_SHADER_SUBGROUP_EXTENDED_TYPES "Build vulkan with KHR_SHADER_SUBGROUP_EXTENDED_TYPES" OFF)
#endif

#if VKI_EXPOSE_SW_DECOMPRESS
option(VKI_EXPOSE_SW_DECOMPRESS "Expose SW_DECOMPRESS" OFF)
#endif

#if VKI_3RD_PARTY_IP_PROPERTY_ID
option(VKI_3RD_PARTY_IP_PROPERTY_ID "Build vulkan with 3RD_PARTY_IP_PROPERTY_ID" OFF)
#endif

#if VKI_EXT_EXTENDED_DYNAMIC_STATE
option(VKI_EXT_EXTENDED_DYNAMIC_STATE "Build vulkan with EXTENDED_DYNAMIC_STATE extention" OFF)
#endif

option(ICD_BUILD_LLPC "Build LLPC?" ON)

option(ICD_BUILD_LLPCONLY "Build LLPC Only?" OFF)

option(XGL_LLVM_UPSTREAM "Build with upstreamed LLVM?" OFF)

option(XGL_ENABLE_ASSERTIONS "Enable assertions in release builds" OFF)

option(ICD_GPUOPEN_DEVMODE_BUILD "Build ${PROJECT_NAME} with GPU Open Developer Mode driver support?" ON)

option(ICD_MEMTRACK "Turn on memory tracking?" ${CMAKE_BUILD_TYPE_DEBUG})

if (NOT WIN32)
option(BUILD_WAYLAND_SUPPORT "Build XGL with Wayland support" ON)

option(BUILD_XLIB_XRANDR_SUPPORT "Build Xlib with xrandr 1.6 support" OFF)

option(BUILD_DRI3_SUPPORT "Build XGL with Dri3 support" ON)
endif()

option(ICD_ANALYSIS_WARNINGS_AS_ERRORS "Warnings as errors?" OFF)

endmacro()
@@ -0,0 +1,233 @@
##
#######################################################################################################################
#
# Copyright (c) 2017-2021 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.
#
#######################################################################################################################
include_guard()

macro(xgl_get_version)

# This will become the value of PAL_CLIENT_INTERFACE_MAJOR_VERSION. It describes the version of the PAL interface
# that the ICD supports. PAL uses this value to enable backwards-compatibility for older interface versions. It must
# be updated on each PAL promotion after handling all of the interface changes described in palLib.h.
file(STRINGS icd/make/importdefs PAL_MAJOR_VERSION REGEX "^ICD_PAL_CLIENT_MAJOR_VERSION = [0-9]+")

if(PAL_MAJOR_VERSION STREQUAL "")
message(STATUS "Failed to find ICD_PAL_CLIENT_MAJOR_VERSION")
else()
string(REGEX REPLACE "ICD_PAL_CLIENT_MAJOR_VERSION = " "" PAL_MAJOR_VERSION ${PAL_MAJOR_VERSION})
message(STATUS "Detected ICD_PAL_CLIENT_MAJOR_VERSION is " ${PAL_MAJOR_VERSION})
endif()

set(ICD_PAL_CLIENT_MAJOR_VERSION ${PAL_MAJOR_VERSION})

# Handle MINOR_VERSION in the same way
file(STRINGS icd/make/importdefs PAL_MINOR_VERSION REGEX "^ICD_PAL_CLIENT_MINOR_VERSION = [0-9]+")

if(PAL_MINOR_VERSION STREQUAL "")
message(STATUS "Failed to find ICD_PAL_CLIENT_MINOR_VERSION")
else()
string(REGEX REPLACE "ICD_PAL_CLIENT_MINOR_VERSION = " "" PAL_MINOR_VERSION ${PAL_MINOR_VERSION})
message(STATUS "Detected ICD_PAL_CLIENT_MINOR_VERSION is " ${PAL_MINOR_VERSION})
endif()

set(ICD_PAL_CLIENT_MINOR_VERSION ${PAL_MINOR_VERSION})

# This will become the value of LLPC_CLIENT_INTERFACE_MAJOR_VERSION. It describes the version of the LLPC interface
# that the ICD supports. LLPC uses this value to enable backwards-compatibility for older interface versions. It must
# be updated on each LLPC promotion after handling all of the interface changes described in llpc.h
file(STRINGS icd/make/importdefs LLPC_MAJOR_VERSION REGEX "^ICD_LLPC_CLIENT_MAJOR_VERSION = [0-9]+")

if(LLPC_MAJOR_VERSION STREQUAL "")
message(STATUS "Failed to find ICD_LLPC_CLIENT_MAJOR_VERSION")
else()
string(REGEX REPLACE "ICD_LLPC_CLIENT_MAJOR_VERSION = " "" LLPC_MAJOR_VERSION ${LLPC_MAJOR_VERSION})
message(STATUS "Detected ICD_LLPC_CLIENT_MAJOR_VERSION is " ${LLPC_MAJOR_VERSION})
endif()

set(ICD_LLPC_CLIENT_MAJOR_VERSION ${LLPC_MAJOR_VERSION})

# This will become the value of GPUOPEN_CLIENT_INTERFACE_MAJOR_VERSION. It describes the version of the GPUOPEN interface
# that the ICD supports.
if(ICD_GPUOPEN_DEVMODE_BUILD)
file(STRINGS icd/make/importdefs GPUOPEN_MAJOR_VERSION REGEX "^ICD_GPUOPEN_CLIENT_MAJOR_VERSION = [0-9]+")

if(GPUOPEN_MAJOR_VERSION STREQUAL "")
message(STATUS "Failed to find ICD_GPUOPEN_CLIENT_MAJOR_VERSION")
else()
string(REGEX REPLACE "ICD_GPUOPEN_CLIENT_MAJOR_VERSION = " "" GPUOPEN_MAJOR_VERSION ${GPUOPEN_MAJOR_VERSION})
message(STATUS "Detected ICD_GPUOPEN_CLIENT_MAJOR_VERSION is " ${GPUOPEN_MAJOR_VERSION})
endif()
set(GPUOPEN_CLIENT_INTERFACE_MAJOR_VERSION ${GPUOPEN_MAJOR_VERSION})
endif()

endmacro()

macro(xgl_get_path)
# icd path
set(XGL_ICD_PATH ${PROJECT_SOURCE_DIR}/icd CACHE PATH "The path of xgl, it is read-only.")

# XGL cache creator tool
set(XGL_CACHE_CREATOR_PATH ${PROJECT_SOURCE_DIR}/tools/cache_creator CACHE PATH "Path to the cache creator tool")

# PAL path
if(EXISTS ${PROJECT_SOURCE_DIR}/../pal)
set(XGL_PAL_PATH ${PROJECT_SOURCE_DIR}/../pal CACHE PATH "Specify the path to the PAL project.")
endif()

# VKGC path
if (EXISTS ${XGL_ICD_PATH}/api/compiler/CMakeLists.txt)
set(XGL_VKGC_PATH ${XGL_ICD_PATH}/api/compiler CACHE PATH "Specify the path to the compiler." FORCE)
else()
# On github, the default repo name is llpc instead of compiler
set(XGL_VKGC_PATH ${PROJECT_SOURCE_DIR}/../llpc CACHE PATH "Specify the path to the llpc repository." FORCE)
endif()

# external Vulkan headers path
if(EXISTS ${PROJECT_SOURCE_DIR}/../Vulkan-Headers)
set(VULKAN_HEADERS_PATH ${PROJECT_SOURCE_DIR}/../Vulkan-Headers CACHE PATH "The path of Vulkan headers.")
endif()

# Metrohash path
if(EXISTS ${PROJECT_SOURCE_DIR}/../MetroHash)
set(XGL_METROHASH_PATH ${PROJECT_SOURCE_DIR}/../MetroHash CACHE PATH "The path of metrohash.")
else()
set(XGL_METROHASH_PATH ${PROJECT_SOURCE_DIR}/../third_party/metrohash CACHE PATH "The path of metrohash.")
endif()

# cwpack path
if(EXISTS ${PROJECT_SOURCE_DIR}/../CWPack)
set(XGL_CWPACK_PATH ${PROJECT_SOURCE_DIR}/../CWPack CACHE PATH "The path of cwpack.")
else()
set(XGL_CWPACK_PATH ${PROJECT_SOURCE_DIR}/../third_party/cwpack CACHE PATH "The path of cwpack.")
endif()
endmacro()

macro(xgl_overrides_pal)
### For PAL ###########################################################################################################
set(PAL_BUILD_JEMALLOC OFF CACHE BOOL "Force jemalloc off" FORCE)

set(PAL_CLIENT_INTERFACE_MAJOR_VERSION ${ICD_PAL_CLIENT_MAJOR_VERSION} CACHE STRING "${PROJECT_NAME} override." FORCE)

set(PAL_CLIENT_INTERFACE_MINOR_VERSION ${ICD_PAL_CLIENT_MINOR_VERSION} CACHE STRING "${PROJECT_NAME} override." FORCE)

set(PAL_CLIENT "VULKAN" CACHE STRING "${PROJECT_NAME} override." FORCE)

set(PAL_ENABLE_LTO ${XGL_ENABLE_LTO} CACHE BOOL "XGL override to build PAL with LTO support" FORCE)

set(PAL_MEMTRACK ${ICD_MEMTRACK} CACHE BOOL "${PROJECT_NAME} override." FORCE)

set(PAL_BUILD_GPUOPEN ${ICD_GPUOPEN_DEVMODE_BUILD} CACHE BOOL "${PROJECT_NAME} override." FORCE)

set(PAL_BUILD_RAVEN2 ON CACHE BOOL "${PROJECT_NAME} override." FORCE)

set(PAL_BUILD_RENOIR ON CACHE BOOL "${PROJECT_NAME} override." FORCE)

set(PAL_BUILD_VEGA20 ${XGL_BUILD_VEGA20} CACHE BOOL "${PROJECT_NAME} override." FORCE)

set(PAL_BUILD_GFX10 ON CACHE BOOL "${PROJECT_NAME} override." FORCE)

set(PAL_BUILD_NAVI14 ON CACHE BOOL "${PROJECT_NAME} override." FORCE)

set(PAL_BUILD_GFX103 ${XGL_BUILD_GFX103} CACHE BOOL "${PROJECT_NAME} override." FORCE)

set(PAL_BUILD_NAVI21 ON CACHE BOOL "${PROJECT_NAME} override." FORCE)

set(PAL_BUILD_NAVI22 ${XGL_BUILD_NAVI22} CACHE BOOL "${PROJECT_NAME} override." FORCE)

# Wayland
set(PAL_BUILD_WAYLAND ${BUILD_WAYLAND_SUPPORT} CACHE BOOL "Build PAL with Wayland support" FORCE)

# Dri3
set(PAL_BUILD_DRI3 ${BUILD_DRI3_SUPPORT} CACHE BOOL "PAL build with Dri3 enabled" FORCE)

#if VKI_3RD_PARTY_IP_PROPERTY_ID
set(PAL_3RD_PARTY_IP_PROPERTY_ID ${VKI_3RD_PARTY_IP_PROPERTY_ID})
#endif

if(EXISTS ${XGL_METROHASH_PATH})
set(PAL_METROHASH_PATH ${XGL_METROHASH_PATH} CACHE PATH "${PROJECT_NAME} override." FORCE)
endif()

if(EXISTS ${XGL_CWPACK_PATH})
set(PAL_CWPACK_PATH ${XGL_CWPACK_PATH} CACHE PATH "${PROJECT_NAME} override." FORCE)
endif()

endmacro()

macro(xgl_overrides_vkgc)
### For LLPC ##########################################################################################################
set(LLPC_CLIENT_INTERFACE_MAJOR_VERSION ${ICD_LLPC_CLIENT_MAJOR_VERSION} CACHE STRING "${PROJECT_NAME} override." FORCE)

if(ICD_BUILD_LLPC)

set(LLPC_BUILD_LIT ${XGL_BUILD_LIT} CACHE BOOL "${PROJECT_NAME} override." FORCE)

set(LLPC_BUILD_NAVI22 ${XGL_BUILD_NAVI22} CACHE BOOL "${PROJECT_NAME} override." FORCE)

set(LLPC_BUILD_RAVEN2 ON CACHE BOOL "${PROJECT_NAME} override." FORCE)

set(LLPC_BUILD_VEGA20 ${XGL_BUILD_VEGA20} CACHE BOOL "${PROJECT_NAME} override." FORCE)

set(LLPC_ENABLE_WERROR ${ICD_ANALYSIS_WARNINGS_AS_ERRORS} CACHE BOOL "${PROJECT_NAME} override." FORCE)
endif()

endmacro()

macro(xgl_overrides)

xgl_get_version()

xgl_get_path()

if(ICD_BUILD_LLPCONLY)
set(ICD_BUILD_LLPC ON CACHE BOOL "ICD_BUILD_LLPCONLY override." FORCE)
endif()

if(NOT ICD_BUILD_LLPC)
set(XGL_LLVM_UPSTREAM OFF CACHE BOOL "XGL_LLVM_UPSTREAM is overrided to false." FORCE)
endif()

set(XGL_USE_SANITIZER "" CACHE STRING "Build with sanitizers, e.g. Address;Undefined")

if(XGL_USE_SANITIZER)
set(LLVM_USE_SANITIZER "${XGL_USE_SANITIZER}" CACHE BOOL "LLVM_USE_SANITIZER is overridden." FORCE)
endif()

if(XGL_ENABLE_ASSERTIONS)
set(LLVM_ENABLE_ASSERTIONS "${XGL_ENABLE_ASSERTIONS}" CACHE BOOL "LLVM_ENABLE_ASSERTIONS is overridden." FORCE)
endif()

set(VAM_ENABLE_WERROR ${ICD_ANALYSIS_WARNINGS_AS_ERRORS} CACHE BOOL "${PROJECT_NAME} override." FORCE)

set(ADDR_ENABLE_WERROR ${ICD_ANALYSIS_WARNINGS_AS_ERRORS} CACHE BOOL "${PROJECT_NAME} override." FORCE)

set(METROHASH_ENABLE_WERROR ${ICD_ANALYSIS_WARNINGS_AS_ERRORS} CACHE BOOL "${PROJECT_NAME} override." FORCE)

xgl_overrides_pal()

xgl_overrides_vkgc()

### XCB required ######################################################################################################
set(XCB_REQUIRED ON)

endmacro()
@@ -23,193 +23,40 @@
#
#######################################################################################################################
add_library(xgl SHARED)

set(ICD_TARGET amdvlk${TARGET_ARCHITECTURE_BITS})
set_target_properties(xgl PROPERTIES OUTPUT_NAME ${ICD_TARGET})
set_target_properties(xgl PROPERTIES PREFIX "")

install(TARGETS xgl DESTINATION ${CMAKE_SOURCE_DIR}/lib/${CMAKE_BUILD_TYPE})

### Compiler Options ###################################################################################################
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
if(ICD_ANALYSIS_WARNINGS_AS_ERRORS)
target_compile_options(xgl PRIVATE
-Werror
-Wno-error=comment
-Wno-error=pointer-arith
)
endif()
xgl_compiler_options(xgl)

target_compile_options(xgl PRIVATE
-fno-exceptions
-fno-strict-aliasing
-pthread
)
# Add global compile option to enable position independent code (we get link errors for clang/lld otherwise)
# Add global compile option to enable position independent code (we get link errors for clang/lld otherwise)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options(-fPIC)

target_compile_options(xgl PRIVATE $<$<COMPILE_LANGUAGE:CXX>:
-fno-math-errno
-fno-rtti
-std=c++14
-Wno-missing-field-initializers
-Wno-pointer-arith
-Wno-switch
-Wno-unused
-Wno-unused-parameter
>)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(xgl PRIVATE
# Output with color if in terminal: https://github.com/ninja-build/ninja/wiki/FAQ
-fdiagnostics-color=always
-mpreferred-stack-boundary=6
-fno-threadsafe-statics
-fmerge-all-constants
-fms-extensions
)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(xgl PRIVATE
# Output with color if in terminal: https://github.com/ninja-build/ninja/wiki/FAQ
-fcolor-diagnostics
)
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7))
target_compile_options(xgl PRIVATE
-fno-delete-null-pointer-checks
)
endif()

if(TARGET_ARCHITECTURE_BITS EQUAL 32)
target_compile_options(xgl PRIVATE -msse -msse2)
endif()

if(CMAKE_BUILD_TYPE_RELEASE)
target_compile_options(xgl PRIVATE -O3)
if(XGL_ENABLE_LTO)
if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
if(GCC_VERSION VERSION_GREATER 5.3 OR GCC_VERSION VERSION_EQUAL 5.3)
# add global definition to enable LTO here since some components have no option
# to enable it.
add_definitions("-flto -fuse-linker-plugin -Wno-odr")
message(WARNING "LTO enabled for XGL")
endif()
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
# add global definition to enable LTO here since some components have no option
# to enable it.
add_definitions("-flto=thin")
message(WARNING "LTO enabled for XGL")
endif()
endif()
endif()
else()
message(FATAL_ERROR "Using unknown compiler")
endif()

### Build Definitions ##################################################################################################
target_compile_definitions(xgl PRIVATE ${TARGET_ARCHITECTURE_ENDIANESS}ENDIAN_CPU)
target_compile_definitions(xgl PRIVATE PAL_BUILD_GFX9=1)
target_compile_definitions(xgl PRIVATE PAL_BUILD_GFX10)

# Internal developer build

if(ICD_BUILD_LLPC)
target_compile_definitions(xgl PRIVATE ICD_BUILD_LLPC)
endif()

target_compile_definitions(xgl PRIVATE PAL_BUILD_RAVEN2)

target_compile_definitions(xgl PRIVATE PAL_BUILD_RENOIR)

target_compile_definitions(xgl PRIVATE PAL_BUILD_VEGA20)

if(XGL_BUILD_NAVI22)
target_compile_definitions(xgl PRIVATE VKI_BUILD_NAVI22=1)
endif()

if(TARGET_ARCHITECTURE_BITS EQUAL 32)
target_compile_definitions(xgl PRIVATE ICD_X86_BUILD)
elseif(TARGET_ARCHITECTURE_BITS EQUAL 64)
target_compile_definitions(xgl PRIVATE ICD_X64_BUILD)
endif()

# Turn on the memory tracker if enabled.
if(ICD_MEMTRACK)
target_compile_definitions(xgl PRIVATE ICD_MEMTRACK)
endif()

# Enable relevant GPUOpen preprocessor definitions
if(ICD_GPUOPEN_DEVMODE_BUILD)
target_compile_definitions(xgl PRIVATE ICD_GPUOPEN_DEVMODE_BUILD)
# The name of the variable below must match the one in the GpuOpen CMakeLists.txt
endif()

target_compile_definitions(xgl PRIVATE PAL_CLIENT_INTERFACE_MAJOR_VERSION=${PAL_CLIENT_INTERFACE_MAJOR_VERSION})
target_compile_definitions(xgl PRIVATE PAL_CLIENT_INTERFACE_MAJOR_VERSION_SUPPORTS_SHADER_CACHE_EXPECTED_ENTRIES=${PAL_CLIENT_INTERFACE_MAJOR_VERSION})
target_compile_definitions(xgl PRIVATE PAL_CLIENT_INTERFACE_MINOR_VERSION=${PAL_CLIENT_INTERFACE_MINOR_VERSION})

target_compile_definitions(xgl PRIVATE LLPC_CLIENT_INTERFACE_MAJOR_VERSION=${LLPC_CLIENT_INTERFACE_MAJOR_VERSION})
### Build Definitions #################################################################################################
xgl_set_compile_definitions()

### Include Directories ################################################################################################
if (BUILD_WAYLAND_SUPPORT)
target_compile_definitions(xgl PRIVATE VK_USE_PLATFORM_WAYLAND_KHR)
target_include_directories(xgl PUBLIC ${WAYLAND_INCLUDE_DIRS})
endif()

set(XCB_REQUIRED ON)
if(XCB_REQUIRED)
find_package(XCB)
endif()
if (${XCB_RANDR_LEASE})
target_compile_definitions(xgl PRIVATE VK_USE_PLATFORM_XLIB_XRANDR_EXT=1)
endif()

if(UNIX AND XCB_REQUIRED)
target_compile_definitions(xgl PRIVATE VK_USE_PLATFORM_XCB_KHR)
target_compile_definitions(xgl PRIVATE VK_USE_PLATFORM_XLIB_KHR)
endif()

#if VKI_KHR_DISPLAY
if(VKI_KHR_DISPLAY)
target_compile_definitions(xgl PRIVATE VKI_KHR_DISPLAY)
endif()
#endif
#if VKI_NORMALIZED_TRIG_FUNCTIONS
if(VKI_NORMALIZED_TRIG_FUNCTIONS)
target_compile_definitions(xgl PRIVATE VKI_NORMALIZED_TRIG_FUNCTIONS)
endif()
#endif

### Include Directories ################################################################################################

target_include_directories(xgl PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(xgl PRIVATE imported)

target_include_directories(xgl PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
api
api/include
${XGL_VKGC_PATH}/include
)

target_include_directories(xgl PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

#if VKI_KHR_DEFERRED_HOST_OPERATIONS
if(VKI_KHR_DEFERRED_HOST_OPERATIONS)
target_compile_definitions(xgl PRIVATE VKI_KHR_DEFERRED_HOST_OPERATIONS)
endif()
#endif

#if VKI_EXPOSE_EXT_CONDITIONAL_RENDERING
if(VKI_EXPOSE_EXT_CONDITIONAL_RENDERING)
target_compile_definitions(xgl PRIVATE VKI_EXPOSE_EXT_CONDITIONAL_RENDERING)
endif()
#endif

### XGL Subprojects ####################################################################################################
### PAL ########################################################################
# PAL
add_subdirectory(${XGL_PAL_PATH} ${PROJECT_BINARY_DIR}/pal)

### XGL cache creator tool ####################################################
# XGL cache creator tool
if(XGL_BUILD_CACHE_CREATOR)
if(NOT ICD_BUILD_LLPC)
message(FATAL_ERROR "Cannot build cache-creator tools without LLPC")
@@ -219,36 +66,7 @@ endif()

### XGL Sources ########################################################################################################

### ICD api ####################################################################

### ICD Auto-generated Shader Profiles Files ###########################################################################
# ICD_GENDIR Path to the code generation tools
set(ICD_GENDIR ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate)

# ICD shader profile code generation main script
set(ICD_GEN_SHADER_PROFILE_SCRIPTS ${ICD_GENDIR}/genShaderProfile.py ${ICD_GENDIR}/shaderProfileTemplate.py)

set(ICD_SHADER_PROFILE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/api/appopt)

set(ICD_SHADER_PROFILE_SOURCE_FILES_DIR
${ICD_SHADER_PROFILE_DIR}/shader_profiles
)

add_custom_command(
OUTPUT ${ICD_SHADER_PROFILE_DIR}/g_shader_profile.cpp ${ICD_SHADER_PROFILE_DIR}/g_shader_profile.h
COMMAND ${PYTHON_CMD} ${ICD_GENDIR}/genShaderProfile.py ${ICD_SHADER_PROFILE_DIR}/shader_profiles
DEPENDS ${ICD_GEN_SHADER_PROFILE_SCRIPTS} ${ICD_SHADER_PROFILE_SOURCE_FILES_DIR}
COMMENT "Generating shader profiles code from all profile.json files"
)

add_custom_target(
GenerateShaderProfiles
DEPENDS ${ICD_GEN_SHADER_PROFILE_SCRIPTS} ${ICD_SHADER_PROFILE_SOURCE_FILES_DIR}
COMMENT "Checking if re-generation is required for shader profiles"
)

add_dependencies(xgl GenerateShaderProfiles)

### ICD api ###################################################################
target_sources(xgl PRIVATE
api/app_profile.cpp
api/app_resource_optimizer.cpp
@@ -317,6 +135,12 @@ target_sources(xgl PRIVATE
api/icd_main.cpp
)

if(ICD_BUILD_LLPC)
target_sources(xgl PRIVATE
api/compiler_solution_llpc.cpp
)
endif()

# vk_physical_device.cpp uses the __DATE__ and __TIME__ macros to generate a pipelineCacheUUID.
# The following rule forces vk_physical_device.cpp to be re-compiled on every build, so that
# an up-to-date time/date is always used regardless of which files were touched since the last build.
@@ -332,7 +156,35 @@ add_custom_target(

add_dependencies(xgl RebuildVkPhysicalDevice)

### ICD Auto-generated String Files ####################################################################################
### ICD Auto-generated Shader Profiles Files ##################################
# ICD_GENDIR Path to the code generation tools
set(ICD_GENDIR ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate)

# ICD shader profile code generation main script
set(ICD_GEN_SHADER_PROFILE_SCRIPTS ${ICD_GENDIR}/genShaderProfile.py ${ICD_GENDIR}/shaderProfileTemplate.py)

set(ICD_SHADER_PROFILE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/api/appopt)

set(ICD_SHADER_PROFILE_SOURCE_FILES_DIR
${ICD_SHADER_PROFILE_DIR}/shader_profiles
)

add_custom_command(
OUTPUT ${ICD_SHADER_PROFILE_DIR}/g_shader_profile.cpp ${ICD_SHADER_PROFILE_DIR}/g_shader_profile.h
COMMAND ${PYTHON_CMD} ${ICD_GENDIR}/genShaderProfile.py ${ICD_SHADER_PROFILE_DIR}/shader_profiles
DEPENDS ${ICD_GEN_SHADER_PROFILE_SCRIPTS} ${ICD_SHADER_PROFILE_SOURCE_FILES_DIR}
COMMENT "Generating shader profiles code from all profile.json files"
)

add_custom_target(
GenerateShaderProfiles
DEPENDS ${ICD_GEN_SHADER_PROFILE_SCRIPTS} ${ICD_SHADER_PROFILE_SOURCE_FILES_DIR}
COMMENT "Checking if re-generation is required for shader profiles"
)

add_dependencies(xgl GenerateShaderProfiles)

### ICD Auto-generated String Files ###########################################
set(ICD_STRING_DIR ${CMAKE_CURRENT_SOURCE_DIR}/api/strings)
# ICD settings code generation main script
set(ICD_GEN_STRINGS ${ICD_STRING_DIR}/generate_strings.py)
@@ -369,46 +221,7 @@ add_dependencies(xgl RunVKStringsGenerator)

target_sources(xgl PRIVATE api/strings/strings.cpp)

# Or for a separate lib: icdapi
# add_subdirectory(${XGL_API_PATH} ${PROJECT_BINARY_DIR}/api)
# target_link_libraries(xgl api)

### ICD api/sqtt ###############################################################
target_sources(xgl PRIVATE
api/sqtt/sqtt_layer.cpp
api/sqtt/sqtt_mgr.cpp
api/sqtt/sqtt_object_mgr.cpp
)

# Or for a separate lib: icdapisqtt
# add_subdirectory(api/sqtt ${PROJECT_BINARY_DIR}/api/sqtt)
# target_link_libraries(xgl sqtt)

### ICD api/devmode ############################################################
if(ICD_GPUOPEN_DEVMODE_BUILD)
target_sources(xgl PRIVATE api/devmode/devmode_mgr.cpp)

# Or for a separate lib: icdapidevmode
# add_subdirectory(api/devmode ${PROJECT_BINARY_DIR}/api/devmode)
# target_link_libraries(xgl devmode)
endif()

if(ICD_BUILD_LLPC)
target_sources(xgl PRIVATE
api/compiler_solution_llpc.cpp
)
endif()

### ICD layer ##################################################################
target_sources(xgl PRIVATE
layers/query_dlist.cpp
layers/vk_layer_all_null_devices.cpp
layers/vk_layer_switchable_graphics.cpp
)

### ICD Android interface ######################################################

### ICD Auto-generated Files ###########################################################################################
### ICD Auto-generated Settings Files #########################################
# ICD settings code generation main script
set(ICD_GEN_SETTINGS ${ICD_GENDIR}/genSettingsCode.py)

@@ -440,8 +253,26 @@ target_sources(xgl PRIVATE
settings/settings.cpp
)

### XGL VKGC ####
target_link_libraries(xgl PRIVATE vkgc)
### ICD api/sqtt ##############################################################
target_sources(xgl PRIVATE
api/sqtt/sqtt_layer.cpp
api/sqtt/sqtt_mgr.cpp
api/sqtt/sqtt_object_mgr.cpp
)

### ICD api/devmode ###########################################################
if(ICD_GPUOPEN_DEVMODE_BUILD)
target_sources(xgl PRIVATE api/devmode/devmode_mgr.cpp)
endif()

### ICD layer ##################################################################
target_sources(xgl PRIVATE
layers/query_dlist.cpp
layers/vk_layer_all_null_devices.cpp
layers/vk_layer_switchable_graphics.cpp
)

### ICD Android interface ######################################################

### Link Libraries #####################################################################################################
if (UNIX)
@@ -482,6 +313,7 @@ if (UNIX)

endif()

target_link_libraries(xgl PRIVATE vkgc)
target_link_libraries(xgl PRIVATE pal)
target_link_libraries(xgl PRIVATE khronos_vulkan_interface)

@@ -504,3 +336,16 @@ target_find_headers(xgl)
if(MSVC)
target_source_groups(xgl)
endif()

### ICD loader configuration ###########################################################################################
if(UNIX)
include(GNUInstallDirs)
if(TARGET_ARCHITECTURE_BITS EQUAL 64)
set(ISABITS "64")
else()
set(ISABITS "32")
endif()
set(AMDVLK_INSTALL_PATH ${CMAKE_INSTALL_FULL_LIBDIR})
configure_file(Loader/LunarG/Lnx/amd-icd.json amd_icd${ISABITS}.json @ONLY)
endif()

@@ -1,12 +1,14 @@
{
"file_format_version": "1.0.0",
"ICD": {
"api_version": "1.2.170"
"library_path": "@AMDVLK_INSTALL_PATH@/amdvlk@ISABITS@.so",
"api_version": "1.2.173"
},
"layer": {
"name": "VK_LAYER_AMD_switchable_graphics",
"name": "VK_LAYER_AMD_switchable_graphics_@ISABITS@",
"type": "GLOBAL",
"api_version": "1.2.170",
"library_path": "@AMDVLK_INSTALL_PATH@/amdvlk@ISABITS@.so",
"api_version": "1.2.173",
"implementation_version": "1",
"description": "AMD switchable graphics layer",
"functions": {
@@ -862,8 +862,8 @@ AppProfile ScanApplicationProfile(
// You can uncomment these if you need to add new hashes for specific strings (which is
// hopefully never). DON'T LEAVE THIS UNCOMMENTED:
//
// Util::MetroHash::Hash hash = {};
// Util::MetroHash128::Hash(reinterpret_cast<const uint8_t*>(pTestPattern), strlen(pTestPattern), hash.bytes);
//Util::MetroHash::Hash hash = {};
//Util::MetroHash128::Hash(reinterpret_cast<const uint8_t*>(pTestPattern), strlen(pTestPattern), hash.bytes);

AppProfile profile = AppProfile::Default;

@@ -95,6 +95,29 @@ void ResourceOptimizer::ApplyProfileToImageCreateInfo(
}
}

// =====================================================================================================================
void ResourceOptimizer::ApplyProfileToImageViewCreateInfo(
const ResourceProfile& profile,
const ResourceOptimizerKey& resourceKey,
Pal::ImageViewInfo* pViewInfo) const
{
VK_ASSERT(pViewInfo != nullptr);
for (uint32_t entry = 0; entry < profile.entryCount; ++entry)
{
const ResourceProfileEntry& profileEntry = profile.entries[entry];

if (ResourcePatternMatchesResource(profileEntry.pattern, resourceKey))
{
const auto& resourceCreate = profileEntry.action.resourceCreate;

if (resourceCreate.apply.mallNoAlloc)
{
pViewInfo->flags.bypassMallRead = 1;
pViewInfo->flags.bypassMallWrite = 1;
}
}
}
}
// =====================================================================================================================
void ResourceOptimizer::OverrideImageCreateInfo(
const ResourceOptimizerKey& resourceKey,
@@ -109,7 +132,19 @@ void ResourceOptimizer::OverrideImageCreateInfo(
#endif

}
// =====================================================================================================================
void ResourceOptimizer::OverrideImageViewCreateInfo(
const ResourceOptimizerKey& resourceKey,
Pal::ImageViewInfo* pPalViewInfo) const
{
ApplyProfileToImageViewCreateInfo(m_appProfile, resourceKey, pPalViewInfo);

ApplyProfileToImageViewCreateInfo(m_tuningProfile, resourceKey, pPalViewInfo);

#if ICD_RUNTIME_APP_PROFILE
ApplyProfileToImageViewCreateInfo(m_runtimeProfile, resourceKey, pPalViewInfo);
#endif
}
// =====================================================================================================================
ResourceOptimizer::~ResourceOptimizer()
{
@@ -118,7 +153,7 @@ ResourceOptimizer::~ResourceOptimizer()
// =====================================================================================================================
bool ResourceOptimizer::ResourcePatternMatchesResource(
const ResourceProfilePattern& pattern,
const ResourceOptimizerKey& resourceKey)
const ResourceOptimizerKey& resourceKey) const
{
if (pattern.match.always)
{
@@ -0,0 +1,17 @@
{
"entries": [
{
"pattern": {
"cs": {
"stageActive": true,
"codeHash": "0x151B4F8C25C76937 D3CA0B94C0F09B4E"
}
},
"action": {
"cs": {
"forceLoopUnrollCount": 2
}
}
}
]
}
@@ -85,6 +85,7 @@ enum class AppProfile : uint32_t
WarThunder, // WarThunder by Gaijin Distribution Kft
Quake2RTX, // Quake2 RTX
Valheim, // Valheim by Coffee Stain Studios
EvilGenius2, // Evil Genius 2

IdTechEngine, // id Tech Engine (Default)
Feral3DEngine, // Feral3D Engine (Default)
@@ -34,6 +34,7 @@
#pragma once

#include "palImage.h"
#include "palDevice.h"

// Forward declare Util classes used in this file
namespace Util
@@ -112,7 +113,8 @@ struct ResourceProfileAction
struct
{
uint32_t dccMode : 1; // Only valid for image resources
uint32_t reserved : 31;
uint32_t mallNoAlloc : 1;
uint32_t reserved : 30;
};
uint32_t u32All;
} apply;
@@ -156,15 +158,24 @@ class ResourceOptimizer
const ResourceOptimizerKey& resourceKey,
Pal::ImageCreateInfo* pPalCreateInfo);

void OverrideImageViewCreateInfo(
const ResourceOptimizerKey& resourceKey,
Pal::ImageViewInfo* pPalViewInfo) const;

private:
void ApplyProfileToImageCreateInfo(
const ResourceProfile& profile,
const ResourceOptimizerKey& resourceKey,
Pal::ImageCreateInfo* pCreateInfo);

void ApplyProfileToImageViewCreateInfo(
const ResourceProfile& profile,
const ResourceOptimizerKey& resourceKey,
Pal::ImageViewInfo* pViewInfo) const;

bool ResourcePatternMatchesResource(
const ResourceProfilePattern& pattern,
const ResourceOptimizerKey& resourceKey);
const ResourceOptimizerKey& resourceKey) const;

void BuildTuningProfile();
void BuildAppProfile();
@@ -122,6 +122,7 @@ typedef enum {
VK_ICD_WSI_PLATFORM_DIRECTFB,
VK_ICD_WSI_PLATFORM_VI,
VK_ICD_WSI_PLATFORM_GGP,
VK_ICD_WSI_PLATFORM_SCREEN,
} VkIcdWsiPlatform;

typedef struct {
@@ -233,4 +234,12 @@ typedef struct {
} VkIcdSurfaceVi;
#endif // VK_USE_PLATFORM_VI_NN

#ifdef VK_USE_PLATFORM_SCREEN_QNX
typedef struct {
VkIcdSurfaceBase base;
struct _screen_context *context;
struct _screen_window *window;
} VkIcdSurfaceScreen;
#endif // VK_USE_PLATFORM_SCREEN_QNX

#endif // VKICD_H
@@ -80,6 +80,12 @@
#endif


#ifdef VK_USE_PLATFORM_SCREEN_QNX
#include <screen/screen.h>
#include "vulkan_screen.h"
#endif


#ifdef VK_ENABLE_BETA_EXTENSIONS
#include "vulkan_beta.h"
#endif
@@ -43,7 +43,7 @@ extern "C" {
#define VK_API_VERSION_1_0 VK_MAKE_VERSION(1, 0, 0)// Patch version should always be set to 0

// Version of this file
#define VK_HEADER_VERSION 170
#define VK_HEADER_VERSION 173

// Complete version of this file
#define VK_HEADER_VERSION_COMPLETE VK_MAKE_VERSION(1, 2, VK_HEADER_VERSION)
@@ -468,8 +468,12 @@ typedef enum VkStructureType {
VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT = 1000158005,
VK_STRUCTURE_TYPE_VALIDATION_CACHE_CREATE_INFO_EXT = 1000160000,
VK_STRUCTURE_TYPE_SHADER_MODULE_VALIDATION_CACHE_CREATE_INFO_EXT = 1000160001,
#ifdef VK_ENABLE_BETA_EXTENSIONS
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PORTABILITY_SUBSET_FEATURES_KHR = 1000163000,
#endif
#ifdef VK_ENABLE_BETA_EXTENSIONS
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PORTABILITY_SUBSET_PROPERTIES_KHR = 1000163001,
#endif
VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_SHADING_RATE_IMAGE_STATE_CREATE_INFO_NV = 1000164000,
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADING_RATE_IMAGE_FEATURES_NV = 1000164001,
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADING_RATE_IMAGE_PROPERTIES_NV = 1000164002,
@@ -634,6 +638,12 @@ typedef enum VkStructureType {
VK_STRUCTURE_TYPE_DIRECTFB_SURFACE_CREATE_INFO_EXT = 1000346000,
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MUTABLE_DESCRIPTOR_TYPE_FEATURES_VALVE = 1000351000,
VK_STRUCTURE_TYPE_MUTABLE_DESCRIPTOR_TYPE_CREATE_INFO_VALVE = 1000351002,
VK_STRUCTURE_TYPE_IMPORT_MEMORY_ZIRCON_HANDLE_INFO_FUCHSIA = 1000364000,
VK_STRUCTURE_TYPE_MEMORY_ZIRCON_HANDLE_PROPERTIES_FUCHSIA = 1000364001,
VK_STRUCTURE_TYPE_MEMORY_GET_ZIRCON_HANDLE_INFO_FUCHSIA = 1000364002,
VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_ZIRCON_HANDLE_INFO_FUCHSIA = 1000365000,
VK_STRUCTURE_TYPE_SEMAPHORE_GET_ZIRCON_HANDLE_INFO_FUCHSIA = 1000365001,
VK_STRUCTURE_TYPE_SCREEN_SURFACE_CREATE_INFO_QNX = 1000378000,
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES,
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES,
VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT,
@@ -4192,6 +4202,7 @@ typedef enum VkExternalMemoryHandleTypeFlagBits {
VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID = 0x00000400,
VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT = 0x00000080,
VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_MAPPED_FOREIGN_MEMORY_BIT_EXT = 0x00000100,
VK_EXTERNAL_MEMORY_HANDLE_TYPE_ZIRCON_VMO_BIT_FUCHSIA = 0x00000800,
VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT,
VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT,
VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT,
@@ -4256,6 +4267,7 @@ typedef enum VkExternalSemaphoreHandleTypeFlagBits {
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT = 0x00000004,
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE_BIT = 0x00000008,
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT = 0x00000010,
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_ZIRCON_EVENT_BIT_FUCHSIA = 0x00000080,
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D11_FENCE_BIT = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE_BIT,
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT,
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT,
@@ -7573,6 +7585,8 @@ static const VkPipelineStageFlags2KHR VK_PIPELINE_STAGE_2_CLEAR_BIT_KHR = 0x8000
static const VkPipelineStageFlags2KHR VK_PIPELINE_STAGE_2_INDEX_INPUT_BIT_KHR = 0x1000000000ULL;
static const VkPipelineStageFlags2KHR VK_PIPELINE_STAGE_2_VERTEX_ATTRIBUTE_INPUT_BIT_KHR = 0x2000000000ULL;
static const VkPipelineStageFlags2KHR VK_PIPELINE_STAGE_2_PRE_RASTERIZATION_SHADERS_BIT_KHR = 0x4000000000ULL;
static const VkPipelineStageFlags2KHR VK_PIPELINE_STAGE_2_RESERVED_26_BIT_KHR = 0x04000000;
static const VkPipelineStageFlags2KHR VK_PIPELINE_STAGE_2_RESERVED_27_BIT_KHR = 0x08000000;
static const VkPipelineStageFlags2KHR VK_PIPELINE_STAGE_2_TRANSFORM_FEEDBACK_BIT_EXT = 0x01000000;
static const VkPipelineStageFlags2KHR VK_PIPELINE_STAGE_2_CONDITIONAL_RENDERING_BIT_EXT = 0x00040000;
static const VkPipelineStageFlags2KHR VK_PIPELINE_STAGE_2_COMMAND_PREPROCESS_BIT_NV = 0x00020000;
@@ -7610,6 +7624,10 @@ static const VkAccessFlags2KHR VK_ACCESS_2_MEMORY_WRITE_BIT_KHR = 0x00010000;
static const VkAccessFlags2KHR VK_ACCESS_2_SHADER_SAMPLED_READ_BIT_KHR = 0x100000000ULL;
static const VkAccessFlags2KHR VK_ACCESS_2_SHADER_STORAGE_READ_BIT_KHR = 0x200000000ULL;
static const VkAccessFlags2KHR VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT_KHR = 0x400000000ULL;
static const VkAccessFlags2KHR VK_ACCESS_2_RESERVED_READ_35_BIT_KHR = 0x800000000ULL;
static const VkAccessFlags2KHR VK_ACCESS_2_RESERVED_WRITE_36_BIT_KHR = 0x1000000000ULL;
static const VkAccessFlags2KHR VK_ACCESS_2_RESERVED_READ_37_BIT_KHR = 0x2000000000ULL;
static const VkAccessFlags2KHR VK_ACCESS_2_RESERVED_WRITE_38_BIT_KHR = 0x4000000000ULL;
static const VkAccessFlags2KHR VK_ACCESS_2_TRANSFORM_FEEDBACK_WRITE_BIT_EXT = 0x02000000;
static const VkAccessFlags2KHR VK_ACCESS_2_TRANSFORM_FEEDBACK_COUNTER_READ_BIT_EXT = 0x04000000;
static const VkAccessFlags2KHR VK_ACCESS_2_TRANSFORM_FEEDBACK_COUNTER_WRITE_BIT_EXT = 0x08000000;
@@ -40,6 +40,80 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateImagePipeSurfaceFUCHSIA(
VkSurfaceKHR* pSurface);
#endif


#define VK_FUCHSIA_external_memory 1
#define VK_FUCHSIA_EXTERNAL_MEMORY_SPEC_VERSION 1
#define VK_FUCHSIA_EXTERNAL_MEMORY_EXTENSION_NAME "VK_FUCHSIA_external_memory"
typedef struct VkImportMemoryZirconHandleInfoFUCHSIA {
VkStructureType sType;
const void* pNext;
VkExternalMemoryHandleTypeFlagBits handleType;
zx_handle_t handle;
} VkImportMemoryZirconHandleInfoFUCHSIA;

typedef struct VkMemoryZirconHandlePropertiesFUCHSIA {
VkStructureType sType;
void* pNext;
uint32_t memoryTypeBits;
} VkMemoryZirconHandlePropertiesFUCHSIA;

typedef struct VkMemoryGetZirconHandleInfoFUCHSIA {
VkStructureType sType;
const void* pNext;
VkDeviceMemory memory;
VkExternalMemoryHandleTypeFlagBits handleType;
} VkMemoryGetZirconHandleInfoFUCHSIA;

typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryZirconHandleFUCHSIA)(VkDevice device, const VkMemoryGetZirconHandleInfoFUCHSIA* pGetZirconHandleInfo, zx_handle_t* pZirconHandle);
typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryZirconHandlePropertiesFUCHSIA)(VkDevice device, VkExternalMemoryHandleTypeFlagBits handleType, zx_handle_t zirconHandle, VkMemoryZirconHandlePropertiesFUCHSIA* pMemoryZirconHandleProperties);

#ifndef VK_NO_PROTOTYPES
VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryZirconHandleFUCHSIA(
VkDevice device,
const VkMemoryGetZirconHandleInfoFUCHSIA* pGetZirconHandleInfo,
zx_handle_t* pZirconHandle);

VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryZirconHandlePropertiesFUCHSIA(
VkDevice device,
VkExternalMemoryHandleTypeFlagBits handleType,
zx_handle_t zirconHandle,
VkMemoryZirconHandlePropertiesFUCHSIA* pMemoryZirconHandleProperties);
#endif


#define VK_FUCHSIA_external_semaphore 1
#define VK_FUCHSIA_EXTERNAL_SEMAPHORE_SPEC_VERSION 1
#define VK_FUCHSIA_EXTERNAL_SEMAPHORE_EXTENSION_NAME "VK_FUCHSIA_external_semaphore"
typedef struct VkImportSemaphoreZirconHandleInfoFUCHSIA {
VkStructureType sType;
const void* pNext;
VkSemaphore semaphore;
VkSemaphoreImportFlags flags;
VkExternalSemaphoreHandleTypeFlagBits handleType;
zx_handle_t zirconHandle;
} VkImportSemaphoreZirconHandleInfoFUCHSIA;

typedef struct VkSemaphoreGetZirconHandleInfoFUCHSIA {
VkStructureType sType;
const void* pNext;
VkSemaphore semaphore;
VkExternalSemaphoreHandleTypeFlagBits handleType;
} VkSemaphoreGetZirconHandleInfoFUCHSIA;

typedef VkResult (VKAPI_PTR *PFN_vkImportSemaphoreZirconHandleFUCHSIA)(VkDevice device, const VkImportSemaphoreZirconHandleInfoFUCHSIA* pImportSemaphoreZirconHandleInfo);
typedef VkResult (VKAPI_PTR *PFN_vkGetSemaphoreZirconHandleFUCHSIA)(VkDevice device, const VkSemaphoreGetZirconHandleInfoFUCHSIA* pGetZirconHandleInfo, zx_handle_t* pZirconHandle);

#ifndef VK_NO_PROTOTYPES
VKAPI_ATTR VkResult VKAPI_CALL vkImportSemaphoreZirconHandleFUCHSIA(
VkDevice device,
const VkImportSemaphoreZirconHandleInfoFUCHSIA* pImportSemaphoreZirconHandleInfo);

VKAPI_ATTR VkResult VKAPI_CALL vkGetSemaphoreZirconHandleFUCHSIA(
VkDevice device,
const VkSemaphoreGetZirconHandleInfoFUCHSIA* pGetZirconHandleInfo,
zx_handle_t* pZirconHandle);
#endif

#ifdef __cplusplus
}
#endif
@@ -0,0 +1,54 @@
#ifndef VULKAN_SCREEN_H_
#define VULKAN_SCREEN_H_ 1

/*
** Copyright 2015-2021 The Khronos Group Inc.
**
** SPDX-License-Identifier: Apache-2.0
*/

/*
** This header is generated from the Khronos Vulkan XML API Registry.
**
*/


#ifdef __cplusplus
extern "C" {
#endif



#define VK_QNX_screen_surface 1
#define VK_QNX_SCREEN_SURFACE_SPEC_VERSION 1
#define VK_QNX_SCREEN_SURFACE_EXTENSION_NAME "VK_QNX_screen_surface"
typedef VkFlags VkScreenSurfaceCreateFlagsQNX;
typedef struct VkScreenSurfaceCreateInfoQNX {
VkStructureType sType;
const void* pNext;
VkScreenSurfaceCreateFlagsQNX flags;
struct _screen_context* context;
struct _screen_window* window;
} VkScreenSurfaceCreateInfoQNX;

typedef VkResult (VKAPI_PTR *PFN_vkCreateScreenSurfaceQNX)(VkInstance instance, const VkScreenSurfaceCreateInfoQNX* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceScreenPresentationSupportQNX)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, struct _screen_window* window);

#ifndef VK_NO_PROTOTYPES
VKAPI_ATTR VkResult VKAPI_CALL vkCreateScreenSurfaceQNX(
VkInstance instance,
const VkScreenSurfaceCreateInfoQNX* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkSurfaceKHR* pSurface);

VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceScreenPresentationSupportQNX(
VkPhysicalDevice physicalDevice,
uint32_t queueFamilyIndex,
struct _screen_window* window);
#endif

#ifdef __cplusplus
}
#endif

#endif
@@ -154,6 +154,9 @@ struct PerGpuRenderState

// VB bindings in source non-SRD form
Pal::BufferViewInfo vbBindings[Pal::MaxVertexBuffers];

// The max stack size required by the pipelines referenced in this command buffer
uint32_t maxPipelineStackSize;
};

// Members of CmdBufferRenderState that are the same for each GPU
@@ -977,7 +980,16 @@ class CmdBuffer

PerGpuRenderState* PerGpuState(uint32 deviceIdx)
{
PerGpuRenderState* pPerGpuState = static_cast<PerGpuRenderState*>(Util::VoidPtrInc(this, sizeof(*this)));
PerGpuRenderState* pPerGpuState =
static_cast<PerGpuRenderState*>(Util::VoidPtrInc(this, sizeof(*this)));

return &pPerGpuState[deviceIdx];
}

const PerGpuRenderState* PerGpuState(uint32 deviceIdx) const
{
const PerGpuRenderState* pPerGpuState =
static_cast<const PerGpuRenderState*>(Util::VoidPtrInc(this, sizeof(*this)));

return &pPerGpuState[deviceIdx];
}
@@ -1121,6 +1133,12 @@ class CmdBuffer
void ResetVertexBuffer();
void UpdateVertexBufferStrides(const GraphicsPipeline* pPipeline);

VK_INLINE void UpdateLargestPipelineStackSize(const uint32_t deviceIndex, const uint32_t pipelineStackSize)
{
PerGpuState(deviceIndex)->maxPipelineStackSize =
Util::Max(PerGpuState(deviceIndex)->maxPipelineStackSize, pipelineStackSize);
}

union CmdBufferFlags
{
uint32_t u32All;
@@ -97,9 +97,6 @@ class ComputePipeline : public Pipeline, public NonDispatchable<VkPipeline, Comp
uint32_t staticStateMask,
uint64_t apiHash);

void CreateStaticState();
void DestroyStaticState(const VkAllocationCallbacks* pAllocator);

// Converted creation info parameters of the Vulkan compute pipeline
struct CreateInfo
{
@@ -114,13 +111,6 @@ class ComputePipeline : public Pipeline, public NonDispatchable<VkPipeline, Comp
const VkComputePipelineCreateInfo* pIn,
CreateInfo* pOutInfo);

static VkResult CreateComputePipelineBinaries(
Device* pDevice,
PipelineCache* pPipelineCache,
CreateInfo* pCreateInfo,
size_t pipelineBinarySizes[MaxPalDevices],
void* pPipelineBinaries[MaxPalDevices]);

static uint64_t BuildApiHash(
const VkComputePipelineCreateInfo* pCreateInfo,
Util::MetroHash::Hash* pBaseHash);
@@ -363,6 +363,9 @@ class Device
VK_FORCEINLINE ResourceOptimizer* GetResourceOptimizer()
{ return &m_resourceOptimizer; }

VK_FORCEINLINE const ResourceOptimizer* GetResourceOptimizer() const
{ return &m_resourceOptimizer; }

VK_FORCEINLINE bool IsMultiGpu() const
{ return m_palDeviceCount > 1; }

@@ -54,6 +54,7 @@
#define VK_KHR_SYNCHRONIZATION2_SPEC_VERSION VK_KHR_SYNCHRONIZATION_2_SPEC_VERSION

// EXT macros
#define VK_EXT_EXTENDED_DYNAMIC_STATE2_SPEC_VERSION VK_EXT_EXTENDED_DYNAMIC_STATE_2_SPEC_VERSION
#define VK_EXT_ROBUSTNESS2_SPEC_VERSION VK_EXT_ROBUSTNESS_2_SPEC_VERSION
#define VK_EXT_SWAPCHAIN_COLORSPACE_EXTENSION_NAME VK_EXT_SWAPCHAIN_COLOR_SPACE_EXTENSION_NAME
#define VK_EXT_SWAPCHAIN_COLORSPACE_SPEC_VERSION VK_EXT_SWAPCHAIN_COLOR_SPACE_SPEC_VERSION
@@ -202,6 +202,9 @@ class Image : public NonDispatchable<VkImage, Image>
VK_FORCEINLINE const ImageBarrierPolicy& GetBarrierPolicy() const
{ return m_barrierPolicy; }

VK_FORCEINLINE const ResourceOptimizerKey& GetResourceKey() const
{ return m_ResourceKey; }

// Returns true if the image has a color format.
VK_FORCEINLINE bool IsColorFormat() const
{ return m_internalFlags.isColorFormat == 1; }
@@ -246,7 +249,6 @@ class Image : public NonDispatchable<VkImage, Image>
uint32_t androidPresentable : 1; // True if this image is created as Android presentable image.
uint32_t externalPinnedHost : 1; // True if image backing memory is compatible with pinned sysmem.
uint32_t externalD3DHandle : 1; // True if image is backed by a D3D11 image
uint32_t externalAhbHandle : 1; // Ture if image is backed by Android Hardware Buffer
uint32_t isColorFormat : 1; // True if the image has a color format
uint32_t isYuvFormat : 1; // True if the image has a yuv format
uint32_t isExternalFormat : 1; // True if the image has undefined external format.
@@ -258,7 +260,7 @@ class Image : public NonDispatchable<VkImage, Image>
uint32_t sampleLocsCompatDepth : 1; // VK_IMAGE_CREATE_SAMPLE_LOCATIONS_COMPATIBLE_DEPTH_BIT_EXT
uint32_t linear : 1; // True if the image has VK_IMAGE_TILING_LINEAR
uint32_t isProtected : 1; // VK_IMAGE_CREATE_PROTECTED_BIT
uint32_t reserved : 12;
uint32_t reserved : 13;
};
uint32_t u32All;
};
@@ -287,7 +289,8 @@ class Image : public NonDispatchable<VkImage, Image>
VkSampleCountFlagBits imageSamples,
VkImageUsageFlags usage,
VkImageUsageFlags stencilUsage,
ImageFlags internalFlags);
ImageFlags internalFlags,
const ResourceOptimizerKey& resourceKey);

// Compute size required for the object. One copy of PerGpuInfo is included in the object and we need
// to add space for any additional GPUs.
@@ -310,14 +313,6 @@ class Image : public NonDispatchable<VkImage, Image>
const VkImageCreateInfo* pCreateInfo,
ResourceOptimizerKey* pResourceKey);

static VkResult CreateFromAndroidHwBufferHandle(
Device* pDevice,
const VkImageCreateInfo* pImageCreateInfo,
const Pal::ImageCreateInfo& palCreateInfo,
uint64_t externalFormat,
ImageFlags internalFlags,
VkImage* pImage);

uint32_t m_mipLevels; // This is the amount of mip levels contained in the image.
// We need this to support VK_WHOLE_SIZE during
// memory barrier creation
@@ -353,6 +348,8 @@ class Image : public NonDispatchable<VkImage, Image>
// bound. Android swapchain is implemented in loader.Presentable image
// use this member to track the gpuMemory created from external handle.

ResourceOptimizerKey m_ResourceKey;

// This goes last. The memory for the rest of the array is calculated dynamically based on the number of GPUs in
// use.
PerGpuInfo m_perGpu[1];
@@ -283,9 +283,6 @@ class FullscreenMgr

uint32_t m_vidPnSourceId; // Video present source identifier
Mode m_mode; // Indicates the Presentation mode we are using

static bool s_forceFullscreenReacquire; // Used to force fullscreen reacquire when dealing with multiple
// instances of this class across swapchains
};

// =====================================================================================================================
@@ -31,7 +31,7 @@
open_copyright = '''/*
***********************************************************************************************************************
*
* Copyright (c) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved.
* Copyright (c) 2014-2021 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
@@ -405,10 +405,7 @@ VkResult CmdBuffer::Create(
palCreateInfo.queueType = pDevice->GetQueueFamilyPalQueueType(queueFamilyIndex);
palCreateInfo.engineType = pDevice->GetQueueFamilyPalEngineType(queueFamilyIndex);
palCreateInfo.flags.nested = (pAllocateInfo->level > VK_COMMAND_BUFFER_LEVEL_PRIMARY) ? 1 : 0;
if (pDevice->GetRuntimeSettings().enableDispatchTunneling)
{
palCreateInfo.flags.dispatchTunneling = 1;
}
palCreateInfo.flags.dispatchTunneling = 1;

// Allocate system memory for the command buffer objects
Pal::Result palResult;
@@ -1313,6 +1310,7 @@ void CmdBuffer::ResetPipelineState()
pPerGpuState->viewport.horzDiscardRatio = 1.0f;
pPerGpuState->viewport.vertDiscardRatio = 1.0f;
pPerGpuState->viewport.depthRange = Pal::DepthRange::ZeroToOne;
pPerGpuState->maxPipelineStackSize = 0;

deviceIdx++;
}
@@ -1524,16 +1522,9 @@ void CmdBuffer::BindPipeline(
{
DbgBarrierPreCmd(DbgBarrierBindPipeline);

PipelineBindPoint apiBindPoint;
Pal::PipelineBindPoint palBindPoint;

ConvertPipelineBindPoint(pipelineBindPoint, &palBindPoint, &apiBindPoint);

const UserDataLayout* pNewUserDataLayout = nullptr;

switch (apiBindPoint)
switch (pipelineBindPoint)
{
case PipelineBindCompute:
case VK_PIPELINE_BIND_POINT_COMPUTE:
{
const ComputePipeline* pPipeline = ComputePipeline::ObjectFromHandle(pipeline);

@@ -1552,7 +1543,7 @@ void CmdBuffer::BindPipeline(
break;
}

case PipelineBindGraphics:
case VK_PIPELINE_BIND_POINT_GRAPHICS:
{
const GraphicsPipeline* pPipeline = GraphicsPipeline::ObjectFromHandle(pipeline);

@@ -231,6 +231,8 @@ Device::Device(
{
memset(m_pBltMsaaState, 0, sizeof(m_pBltMsaaState));

memset(m_pQueues, 0, sizeof(m_pQueues));

m_maxVrsShadingRate = {0, 0};

for (uint32_t deviceIdx = 0; deviceIdx < palDeviceCount; ++deviceIdx)
@@ -1222,8 +1224,7 @@ VkResult Device::Create(
}
}

// Free memory
(*pDispatchableDevice)->FreeApiObject(pInstance->GetAllocCallbacks(), pMemory);
(*pDispatchableDevice)->Destroy(pAllocator);
}
else
{
@@ -1268,7 +1269,7 @@ VkResult Device::Initialize(
const bool deviceCoherentMemoryEnabled,
const bool attachmentFragmentShadingRate,
bool scalarBlockLayoutEnabled,
const ExtendedRobustness& extendedRobustnessEnabled)
const ExtendedRobustness& extendedRobustnessEnabled)
{
// Initialize the internal memory manager
VkResult result = m_internalMemMgr.Init();
@@ -766,7 +766,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vk_icdNegotiateLoaderICDInterfaceVersion(
// InterfaceVersion 3 - was introduced at 1.0.30, therefore we reject all older versions of the loader.

static constexpr uint32_t MinDriverSupportedInterfaceVersion = 3;
static constexpr uint32_t MaxDriverSupportedInterfaceVersion = 5;
static constexpr uint32_t MaxDriverSupportedInterfaceVersion = 6;

if (*pVersion < MinDriverSupportedInterfaceVersion)
{
@@ -147,7 +147,8 @@ Image::Image(
VkSampleCountFlagBits imageSamples,
VkImageUsageFlags usage,
VkImageUsageFlags stencilUsage,
ImageFlags internalFlags)
ImageFlags internalFlags,
const ResourceOptimizerKey& resourceKey)
:
m_mipLevels(mipLevels),
m_arraySize(arraySize),
@@ -158,7 +159,8 @@ Image::Image(
m_tileSize(tileSize),
m_barrierPolicy(barrierPolicy),
m_pSwapChain(nullptr),
m_pImageMemory(nullptr)
m_pImageMemory(nullptr),
m_ResourceKey(resourceKey)
{
m_internalFlags.u32All = internalFlags.u32All;

@@ -527,11 +529,6 @@ VkResult Image::Create(
{
imageFlags.externalPinnedHost = true;
}

if (pExtInfo->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)
{
imageFlags.externalAhbHandle = true;
}
}

break;
@@ -661,52 +658,58 @@ VkResult Image::Create(
const Pal::GfxIpLevel gfxLevel = pDevice->VkPhysicalDevice(DefaultDeviceIndex)->PalProperties().gfxLevel;
if (((palCreateInfo.extent.width * palCreateInfo.extent.height) >
(settings.disableSmallSurfColorCompressionSize * settings.disableSmallSurfColorCompressionSize)) &&
(Formats::IsColorFormat(createInfoFormat)) &&
((gfxLevel > Pal::GfxIpLevel::GfxIp9) || (palCreateInfo.usageFlags.shaderWrite == false)))
{
// Enable DCC beyond what PAL does by default for color attachments
if ((settings.forceEnableDcc == ForceDccForColorAttachments) &&
(pCreateInfo->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT))
{
palCreateInfo.metadataMode = Pal::MetadataMode::ForceEnabled;
}
const uint32_t forceEnableDccMask = settings.forceEnableDcc;

const uint32_t bpp = Pal::Formats::BitsPerPixel(palCreateInfo.swizzledFormat.format);
const bool isShaderStorage = (pCreateInfo->usage & VK_IMAGE_USAGE_STORAGE_BIT);

if (Formats::IsColorFormat(createInfoFormat))
if (isShaderStorage &&
((forceEnableDccMask & ForceDccDefault) == 0) &&
((forceEnableDccMask & ForceDisableDcc) == 0))
{
uint32_t bpp = Pal::Formats::BitsPerPixel(palCreateInfo.swizzledFormat.format);
const bool isColorAttachment = (pCreateInfo->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);

// Enable DCC for shader storage resource with 32 <= bpp < 64
if ((settings.forceEnableDcc == ForceDccFor32BppShaderStorage) &&
(pCreateInfo->usage & VK_IMAGE_USAGE_STORAGE_BIT) &&
(bpp >= 32) && (bpp < 64))
{
palCreateInfo.metadataMode = Pal::MetadataMode::ForceEnabled;
}
const bool is2DShaderStorageImage = (pCreateInfo->imageType & VK_IMAGE_TYPE_2D);
const bool is3DShaderStorageImage = (pCreateInfo->imageType & VK_IMAGE_TYPE_3D);

// Enable DCC for shader storage resource with bpp >= 64
if ((settings.forceEnableDcc == ForceDccFor64BppShaderStorage) &&
(pCreateInfo->usage & VK_IMAGE_USAGE_STORAGE_BIT) &&
(bpp >= 64))
{
palCreateInfo.metadataMode = Pal::MetadataMode::ForceEnabled;
}
// Enable DCC beyond what PAL does by default for color attachments
const bool shouldForceDccForCA = Util::TestAnyFlagSet(forceEnableDccMask, ForceDccForColorAttachments) && isColorAttachment;
const bool shouldForceDccForNonCAShaderStorage =
Util::TestAnyFlagSet(forceEnableDccMask, ForceDccForNonColorAttachmentShaderStorage) && (!isColorAttachment);

// Turn DCC on/off for identified cases where memory bandwidth is not the bottleneck to improve latency.
// PAL may do this implicitly, so specify force enabled instead of default.
if (settings.dccBitsPerPixelThreshold != UINT_MAX)
{
palCreateInfo.metadataMode = (bpp < settings.dccBitsPerPixelThreshold) ?
Pal::MetadataMode::Disabled : Pal::MetadataMode::ForceEnabled;
}
const bool shouldForceDccFor2D = Util::TestAnyFlagSet(forceEnableDccMask, ForceDccFor2DShaderStorage) && is2DShaderStorageImage;
const bool shouldForceDccFor3D = Util::TestAnyFlagSet(forceEnableDccMask, ForceDccFor3DShaderStorage) && is3DShaderStorageImage;

const bool shouldForceDccFor32Bpp =
Util::TestAnyFlagSet(forceEnableDccMask, ForceDccFor32BppShaderStorage) && (bpp >= 32) && (bpp < 64);

const bool shouldForceDccFor64Bpp =
Util::TestAnyFlagSet(forceEnableDccMask, ForceDccFor64BppShaderStorage) && (bpp >= 64);

if ((settings.forceEnableDcc == ForceDccForCaSs2d3dGreaterThanOrEqual32bpp) &&
(pCreateInfo->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) &&
(pCreateInfo->usage & VK_IMAGE_USAGE_STORAGE_BIT) &&
((pCreateInfo->imageType & VK_IMAGE_TYPE_2D) || (pCreateInfo->imageType & VK_IMAGE_TYPE_3D)) &&
(bpp >= 32))
const bool shouldForceDccForAllBpp =
((Util::TestAnyFlagSet(forceEnableDccMask, ForceDccFor32BppShaderStorage) == false) &&
(Util::TestAnyFlagSet(forceEnableDccMask, ForceDccFor64BppShaderStorage) == false));

// To force enable shader storage DCC, at least one of 2D/3D and one of CA/non-CA need to be set
if ((shouldForceDccFor2D || shouldForceDccFor3D) &&
(shouldForceDccForCA || shouldForceDccForNonCAShaderStorage) &&
(shouldForceDccFor32Bpp || shouldForceDccFor64Bpp || shouldForceDccForAllBpp))
{
palCreateInfo.metadataMode = Pal::MetadataMode::ForceEnabled;
}
}

// This setting should only really be used for Vega20.
// Turn DCC on/off for identified cases where memory bandwidth is not the bottleneck to improve latency.
// PAL may do this implicitly, so specify force enabled instead of default.
if (settings.dccBitsPerPixelThreshold != UINT_MAX)
{
palCreateInfo.metadataMode = (bpp < settings.dccBitsPerPixelThreshold) ?
Pal::MetadataMode::Disabled : Pal::MetadataMode::ForceEnabled;
}
}

// a. If devs don't enable the extension: can keep DCC enabled for UAVs with mips
@@ -737,7 +740,7 @@ VkResult Image::Create(
// We must not use any metadata if sparse aliasing is enabled or
// settings.forceEnableDcc is equal to ForceDisableDcc.
if ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_ALIASED_BIT) ||
(settings.forceEnableDcc == ForceDisableDcc))
((settings.forceEnableDcc & ForceDisableDcc) != 0))
{
palCreateInfo.metadataMode = Pal::MetadataMode::Disabled;
}
@@ -790,19 +793,6 @@ VkResult Image::Create(
return result;
}

if (imageFlags.externalAhbHandle)
{
result = Image::CreateFromAndroidHwBufferHandle(
pDevice,
pCreateInfo,
palCreateInfo,
createInfoFormat,
imageFlags,
pImage);

return result;
}

// Calculate required system memory size
const size_t apiSize = ObjectSize(pDevice);
size_t totalSize = apiSize;
@@ -906,7 +896,8 @@ VkResult Image::Create(
pCreateInfo->samples,
pCreateInfo->usage,
stencilUsage,
imageFlags);
imageFlags,
resourceKey);

imageHandle = Image::HandleFromVoidPointer(pMemory);
}
@@ -944,111 +935,6 @@ VkResult Image::Create(
return result;
}

// =====================================================================================================================
// Create a new image object from Android Hardware Buffer handle
VkResult Image::CreateFromAndroidHwBufferHandle(
Device* pDevice,
const VkImageCreateInfo* pImageCreateInfo,
const Pal::ImageCreateInfo& palCreateInfo,
uint64_t externalFormat,
ImageFlags internalFlags,
VkImage* pImage)
{
VkResult result = VkResult::VK_SUCCESS;
const size_t apiSize = ObjectSize(pDevice);
size_t palImgSize = 0;
size_t totalSize = 0;
void* pMemory = nullptr;
Pal::Result palResult = Pal::Result::Success;
const VkAllocationCallbacks* pAllocator = pDevice->VkInstance()->GetAllocCallbacks();

palImgSize = pDevice->PalDevice(DefaultDeviceIndex)->GetImageSize(palCreateInfo, &palResult);
VK_ASSERT(palResult == Pal::Result::Success);

totalSize = apiSize + palImgSize;

// Allocate system memory for objects
pMemory = pDevice->AllocApiObject(pAllocator, totalSize);

if (pMemory == nullptr)
{
result = VK_ERROR_OUT_OF_HOST_MEMORY;
}

// Create PAL images
Pal::IImage* pPalImages[MaxPalDevices] = {};
void* pPalImgAddr = Util::VoidPtrInc(pMemory, apiSize);
size_t palImgOffset = 0;

palResult = pDevice->PalDevice(DefaultDeviceIndex)->CreateImage(
palCreateInfo,
Util::VoidPtrInc(pPalImgAddr, palImgOffset),
&pPalImages[DefaultDeviceIndex]);

palImgOffset += palImgSize;

if (palResult != Pal::Result::Success)
{
result = VK_ERROR_INITIALIZATION_FAILED;
}

VkImage imageHandle = VK_NULL_HANDLE;

if (result == VK_SUCCESS)
{
// Create barrier policy for the image.
ImageBarrierPolicy barrierPolicy(pDevice,
pImageCreateInfo->usage,
pImageCreateInfo->sharingMode,
pImageCreateInfo->queueFamilyIndexCount,
pImageCreateInfo->pQueueFamilyIndices,
pImageCreateInfo->samples > VK_SAMPLE_COUNT_1_BIT,
pImageCreateInfo->format);

VkExtent3D dummyTileSize = {};

// Construct API image object.
VK_PLACEMENT_NEW (pMemory) Image(
pDevice,
pAllocator,
pImageCreateInfo->flags,
pPalImages,
nullptr,
barrierPolicy,
dummyTileSize,
palCreateInfo.mipLevels,
palCreateInfo.arraySize,
(externalFormat == 0) ? pImageCreateInfo->format : static_cast<VkFormat>(externalFormat),
pImageCreateInfo->samples,
pImageCreateInfo->usage,
pImageCreateInfo->usage,
internalFlags);

imageHandle = Image::HandleFromVoidPointer(pMemory);
}

if (result == VK_SUCCESS)
{
*pImage = imageHandle;
}
else
{
if (imageHandle != VK_NULL_HANDLE)
{
Image::ObjectFromHandle(imageHandle)->Destroy(pDevice, pAllocator);
}
else
{
pPalImages[DefaultDeviceIndex]->Destroy();
}

// Failure in creating the PAL image object. Free system memory and return error.
pDevice->FreeApiObject(pAllocator, pMemory);
}

return result;
}

// =====================================================================================================================
// Create a new image object
VkResult Image::CreatePresentableImage(
@@ -1188,6 +1074,24 @@ VkResult Image::CreatePresentableImage(
// stencil usage will be treated same as usage if no separate stencil usage is specified.
VkImageUsageFlags stencilUsageFlags = imageUsageFlags;

ResourceOptimizerKey resourceKey;
VkImageCreateInfo imageCreateInfo = {};
imageCreateInfo.flags = 0;
imageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
imageCreateInfo.format = imageFormat;
imageCreateInfo.extent = { pCreateInfo->extent.width, pCreateInfo->extent.height, 1};
imageCreateInfo.mipLevels = 1;
imageCreateInfo.arrayLayers = 1;
imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
imageCreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
imageCreateInfo.usage = imageUsageFlags;
imageCreateInfo.sharingMode = sharingMode;
imageCreateInfo.queueFamilyIndexCount = queueFamilyIndexCount;
imageCreateInfo.pQueueFamilyIndices = pQueueFamilyIndices;
imageCreateInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;

BuildResourceKey(&imageCreateInfo, &resourceKey);

// Construct API image object.
VK_PLACEMENT_NEW (pImgObjMemory) Image(
pDevice,
@@ -1203,7 +1107,8 @@ VkResult Image::CreatePresentableImage(
VK_SAMPLE_COUNT_1_BIT,
imageUsageFlags,
stencilUsageFlags,
imageFlags);
imageFlags,
resourceKey);

*pImage = Image::HandleFromVoidPointer(pImgObjMemory);

@@ -146,6 +146,8 @@ void ImageView::BuildImageSrds(
(Pal::LayoutShaderRead | Pal::LayoutShaderFmaskBasedRead));
info.possibleLayouts.engines = Pal::LayoutUniversalEngine | Pal::LayoutComputeEngine;

pDevice->GetResourceOptimizer()->OverrideImageViewCreateInfo(pImage->GetResourceKey(), &info);

// Bypass Mall cache read/write if no alloc policy is set for SRDs. This global setting applies to every image view SRD
// and takes precedence over other shader non-storage resource/shader storage resource settings
if (Util::TestAnyFlagSet(settings.mallNoAllocResourcePolicy, MallNoAllocImageViewSrds))
@@ -158,9 +158,7 @@ VkResult Instance::Create(
const VkAllocationCallbacks* pAllocCb = pAllocator;
const VkApplicationInfo* pAppInfo = pCreateInfo->pApplicationInfo;

// It's temporary for vulkancts-imgtec.
if ((pAllocCb == nullptr) ||
((pAllocCb->pfnAllocation == nullptr) && (pAllocCb->pfnFree == nullptr)))
if (pAllocCb == nullptr)
{
pAllocCb = &allocator::g_DefaultAllocCallback;
}
@@ -713,6 +711,9 @@ VkResult Instance::Destroy(void)
// Free memory
FreeMem(this);

// __gcov_flush() is used to flush code coverage data to files. It would be called by Android native process when it
// exits. But for Android apk process, it should be called explicitly.

// Cannot fail.
return VK_SUCCESS;
}
@@ -733,6 +734,9 @@ VkResult Instance::EnumeratePhysicalDevices(
return m_pPhysicalDeviceManager->EnumeratePhysicalDevices(pPhysicalDeviceCount, pPhysicalDevices);
}

// =====================================================================================================================
// Enumerates the GPUs in the system.

// =====================================================================================================================
// Returns whether a device extension is available.
bool Instance::IsDeviceExtensionAvailable(DeviceExtensions::ExtensionId id) const
@@ -209,7 +209,7 @@ VkResult Memory::Create(
if (pExtInfo->handleTypes &
VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)
{
sharedViaAndroidHwBuf = true;
sharedViaAndroidHwBuf = true;
}
#endif
createInfo.flags.interprocess = 1;
@@ -768,7 +768,7 @@ VkResult Memory::OpenExternalSharedImage(
#if defined(__unix__)
palOpenInfo.resourceInfo.handleType = Pal::HandleType::DmaBufFd;
#endif

palOpenInfo.flags.perSubresInit = pBoundImage->PalImage(DefaultDeviceIndex)->GetImageCreateInfo().flags.perSubresInit;
Pal::Result palResult = Pal::Result::Success;
const bool openedViaName = (importInfo.handle == 0);
if (openedViaName)
@@ -2837,7 +2837,6 @@ VkResult PhysicalDevice::GetSurfaceCapabilities2KHR(
VkSurfaceCapabilities2KHR* pSurfaceCapabilities) const
{
VkResult result = VK_SUCCESS;
bool fullScreenExplicitEnabled = false;
Pal::OsDisplayHandle displayHandle = 0;
VkSurfaceKHR surface = VK_NULL_HANDLE;

@@ -4194,12 +4193,7 @@ void PhysicalDevice::GetPhysicalDeviceSubgroupProperties(
VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT |
VK_SHADER_STAGE_GEOMETRY_BIT |
VK_SHADER_STAGE_FRAGMENT_BIT |
VK_SHADER_STAGE_COMPUTE_BIT |
VK_SHADER_STAGE_RAYGEN_BIT_KHR |
VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR |
VK_SHADER_STAGE_MISS_BIT_KHR |
VK_SHADER_STAGE_INTERSECTION_BIT_KHR |
VK_SHADER_STAGE_CALLABLE_BIT_KHR;
VK_SHADER_STAGE_COMPUTE_BIT;

*pSupportedOperations = VK_SUBGROUP_FEATURE_BASIC_BIT |
VK_SUBGROUP_FEATURE_VOTE_BIT |
@@ -4638,8 +4632,7 @@ void PhysicalDevice::GetPhysicalDeviceBufferAddressFeatures(
*pBufferDeviceAddress = VK_TRUE;
*pBufferDeviceAddressCaptureReplay =
PalProperties().gfxipProperties.flags.supportCaptureReplay ? VK_TRUE : VK_FALSE;
*pBufferDeviceAddressMultiDevice =
PalProperties().gfxipProperties.flags.supportCaptureReplay ? VK_TRUE : VK_FALSE;
*pBufferDeviceAddressMultiDevice = VK_FALSE;
}
}

@@ -458,6 +458,10 @@ VkResult Queue::Submit(

perSubQueueInfo.cmdBufferCount = 0;

#if PAL_CLIENT_INTERFACE_MAJOR_VERSION >= 663
palSubmitInfo.stackSizeInDwords = 0;
#endif

const uint32_t deviceMask = 1 << deviceIdx;

for (uint32_t i = 0; i < cmdBufferCount; ++i)
@@ -475,6 +479,13 @@ VkResult Queue::Submit(
{

pPalCmdBuffers[perSubQueueInfo.cmdBufferCount++] = cmdBuf.PalCmdBuffer(deviceIdx);

#if PAL_CLIENT_INTERFACE_MAJOR_VERSION >= 663
const uint32_t stackSizeInDwords =
Util::NumBytesToNumDwords(cmdBuf.PerGpuState(deviceIdx)->maxPipelineStackSize);
palSubmitInfo.stackSizeInDwords =
Util::Max(palSubmitInfo.stackSizeInDwords, stackSizeInDwords);
#endif
}
else
{
@@ -1272,9 +1283,9 @@ VkResult Queue::BindSparseEntry(
// Calculate the extents in tiles
const VkExtent3D extentInTiles =
{
Util::Pow2Align(bind.extent.width, tileSize.width) / tileSize.width,
Util::Pow2Align(bind.extent.height, tileSize.height) / tileSize.height,
Util::Pow2Align(bind.extent.depth, tileSize.depth) / tileSize.depth
Util::RoundUpToMultiple(bind.extent.width, tileSize.width) / tileSize.width,
Util::RoundUpToMultiple(bind.extent.height, tileSize.height) / tileSize.height,
Util::RoundUpToMultiple(bind.extent.depth, tileSize.depth) / tileSize.depth
};

// Calculate byte size to remap per row
@@ -521,10 +521,16 @@ VKAPI_ATTR VkResult VKAPI_CALL vkGetSemaphoreFdKHR(
const VkSemaphoreGetFdInfoKHR* pGetFdInfo,
int* pFd)
{
return Semaphore::ObjectFromHandle(pGetFdInfo->semaphore)->GetShareHandle(
Pal::OsExternalHandle handle = 0;

VkResult result = Semaphore::ObjectFromHandle(pGetFdInfo->semaphore)->GetShareHandle(
ApiDevice::ObjectFromHandle(device),
pGetFdInfo->handleType,
reinterpret_cast<Pal::OsExternalHandle*>(pFd));
&handle);

*pFd = static_cast<int>(handle);

return result;
}
#endif

@@ -54,7 +54,6 @@
namespace vk
{
// Default to true
bool FullscreenMgr::s_forceFullscreenReacquire = true;
bool SwapChain::s_forceTurboSyncEnable = true;

static bool EnableFullScreen(
@@ -954,13 +953,6 @@ FullscreenMgr::FullscreenMgr(
bool FullscreenMgr::TryEnterExclusive(
SwapChain* pSwapChain)
{
// If we need to force resync with PAL
if (s_forceFullscreenReacquire == true)
{
m_exclusiveModeFlags.acquired = 0;
s_forceFullscreenReacquire = false;
}

// If we are not perma-disabled
if (m_exclusiveModeFlags.disabled == 0)
{
@@ -1040,7 +1032,6 @@ bool FullscreenMgr::TryExitExclusive(
{
Pal::Result palResult = m_pScreen->ReleaseFullscreenOwnership();

s_forceFullscreenReacquire = true;
VK_ASSERT((m_exclusiveModeFlags.acquired == 0) || (palResult == Pal::Result::Success));
}

@@ -71,8 +71,9 @@ static PFN_vkVoidFunction GetInstanceProcAddrSG(
// implementation for the layer interface
if (pFunc == nullptr)
{
Util::MutexAuto lock(&g_traceMutex);
g_traceMutex.Lock();
NextLinkFuncPointers nextLinkFuncs = *(g_pDispatchTables->FindKey(instance));
g_traceMutex.Unlock();
pFunc = reinterpret_cast<void*>(nextLinkFuncs.pfnGetInstanceProcAddr(instance, pName));
}

@@ -190,8 +191,9 @@ VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDevices_SG(
uint32_t* pPhysicalDeviceCount,
VkPhysicalDevice* pPhysicalDevices)
{
Util::MutexAuto lock(&g_traceMutex);
g_traceMutex.Lock();
NextLinkFuncPointers nextLinkFuncs = *g_pDispatchTables->FindKey(instance);
g_traceMutex.Unlock();
VkResult result = VK_SUCCESS;
const VkAllocationCallbacks* pAllocCb = &allocator::g_DefaultAllocCallback;
VK_ASSERT(pAllocCb != nullptr);
@@ -354,8 +356,9 @@ static VkResult vkEnumeratePhysicalDeviceGroupsComm(
VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties,
PFN_EnumPhysDeviceGroupsFunc pEnumPhysDeviceGroupsFunc)
{
Util::MutexAuto lock(&g_traceMutex);
g_traceMutex.Lock();
NextLinkFuncPointers nextLinkFuncs = *g_pDispatchTables->FindKey(instance);
g_traceMutex.Unlock();
VkResult result = VK_SUCCESS;
const VkAllocationCallbacks* pAllocCb = &allocator::g_DefaultAllocCallback;
VK_ASSERT(pAllocCb != nullptr);
@@ -504,11 +507,13 @@ VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDeviceGroupsKHR_SG(
uint32_t* pPhysicalDeviceGroupCount,
VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties)
{
Util::MutexAuto lock(&g_traceMutex);
g_traceMutex.Lock();
PFN_EnumPhysDeviceGroupsFunc pEnumPhysDeviceGroupsFunc = (*(g_pDispatchTables->FindKey(instance))).pfnEnumeratePhysicalDeviceGroupsKHR;
g_traceMutex.Unlock();
return vkEnumeratePhysicalDeviceGroupsComm(instance,
pPhysicalDeviceGroupCount,
pPhysicalDeviceGroupProperties,
(*(g_pDispatchTables->FindKey(instance))).pfnEnumeratePhysicalDeviceGroupsKHR);
pEnumPhysDeviceGroupsFunc);
}

// =====================================================================================================================
@@ -519,11 +524,13 @@ VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDeviceGroups_SG(
uint32_t* pPhysicalDeviceGroupCount,
VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties)
{
Util::MutexAuto lock(&g_traceMutex);
g_traceMutex.Lock();
PFN_EnumPhysDeviceGroupsFunc pEnumPhysDeviceGroupsFunc = (*(g_pDispatchTables->FindKey(instance))).pfnEnumeratePhysicalDeviceGroups;
g_traceMutex.Unlock();
return vkEnumeratePhysicalDeviceGroupsComm(instance,
pPhysicalDeviceGroupCount,
pPhysicalDeviceGroupProperties,
(*(g_pDispatchTables->FindKey(instance))).pfnEnumeratePhysicalDeviceGroups);
pEnumPhysDeviceGroupsFunc);
}

// Helper macro used to create an entry for the "primary" entry point implementation (i.e. the one that goes straight
@@ -26,7 +26,7 @@
# This will become the value of PAL_CLIENT_INTERFACE_MAJOR_VERSION. It describes the version of the PAL interface
# that the ICD supports. PAL uses this value to enable backwards-compatibility for older interface versions. It must
# be updated on each PAL promotion after handling all of the interface changes described in palLib.h.
ICD_PAL_CLIENT_MAJOR_VERSION = 659
ICD_PAL_CLIENT_MAJOR_VERSION = 664
ICD_PAL_CLIENT_MINOR_VERSION = 0

# This will become the value of GPUOPEN_CLIENT_INTERFACE_MAJOR_VERSION if ICD_GPUOPEN_DEVMODE_BUILD=1. It describes