[WIP] Continue working on pipeline

This commit is contained in:
Piotr Krygier committed 2025-06-20 13:44:33 +02:00
1 parent f8eb98ddf4
commit daed76f02f
28 files changed
+443 -2132

No files matched your search

+1 -1
View File
@@ -25,7 +25,7 @@ BraceWrapping:
BeforeCatch: false
BeforeElse: false
ColumnLimit: 80
ColumnLimit: 120
# Pointer star next to type, not variable name
DerivePointerAlignment: false
-11
View File
@@ -1,11 +0,0 @@
set(FREE_TYPE_DIR "/usr/")
find_library(
freetype
NAMES freetype
HINTS ${FREE_TYPE_DIR}/lib/x86_64-linux-gnu
)
set(FreeType_INCLUDE_DIR "${FREE_TYPE_DIR}/include/freetype2/")
-3
View File
@@ -1,3 +0,0 @@
set(STB_DIR "/usr/include")
set(stb_INCLUDE_DIR "${STB_DIR}/")
-17
View File
@@ -1,17 +0,0 @@
set(CMOCK_DIR "${PROJECT_SOURCE_DIR}/third_party/cmock/")
find_library(
cmock
NAMES cmock
HINTS ${CMOCK_DIR}/build/src/
)
find_library(
unity
NAMES unity
HINTS ${CMOCK_DIR}/build/vendor/unity/src/
)
set(cmock_INCLUDE_DIR "${CMOCK_DIR}/src/")
set(unity_INCLUDE_DIR "${CMOCK_DIR}/vendor/unity/src/")
-10
View File
@@ -1,10 +0,0 @@
set(CRITERION_DIR "${PROJECT_SOURCE_DIR}/third_party/Criterion/")
find_library(
criterion
NAMES criterion
HINTS ${CRITERION_DIR}/build/src
)
set(criterion_INCLUDE_DIR "${CRITERION_DIR}/include/")
@@ -1,611 +0,0 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindPackageHandleStandardArgs
-----------------------------
This module provides functions intended to be used in :ref:`Find Modules`
implementing :command:`find_package(<PackageName>)` calls.
.. command:: find_package_handle_standard_args
This command handles the ``REQUIRED``, ``QUIET`` and version-related
arguments of :command:`find_package`. It also sets the
``<PackageName>_FOUND`` variable. The package is considered found if all
variables listed contain valid results, e.g. valid filepaths.
There are two signatures:
.. code-block:: cmake
find_package_handle_standard_args(<PackageName>
(DEFAULT_MSG|<custom-failure-message>)
<required-var>...
)
find_package_handle_standard_args(<PackageName>
[FOUND_VAR <result-var>]
[REQUIRED_VARS <required-var>...]
[VERSION_VAR <version-var>]
[HANDLE_VERSION_RANGE]
[HANDLE_COMPONENTS]
[CONFIG_MODE]
[NAME_MISMATCHED]
[REASON_FAILURE_MESSAGE <reason-failure-message>]
[FAIL_MESSAGE <custom-failure-message>]
)
The ``<PackageName>_FOUND`` variable will be set to ``TRUE`` if all
the variables ``<required-var>...`` are valid and any optional
constraints are satisfied, and ``FALSE`` otherwise. A success or
failure message may be displayed based on the results and on
whether the ``REQUIRED`` and/or ``QUIET`` option was given to
the :command:`find_package` call.
The options are:
``(DEFAULT_MSG|<custom-failure-message>)``
In the simple signature this specifies the failure message.
Use ``DEFAULT_MSG`` to ask for a default message to be computed
(recommended). Not valid in the full signature.
``FOUND_VAR <result-var>``
.. deprecated:: 3.3
Specifies either ``<PackageName>_FOUND`` or
``<PACKAGENAME>_FOUND`` as the result variable. This exists only
for compatibility with older versions of CMake and is now ignored.
Result variables of both names are always set for compatibility.
``REQUIRED_VARS <required-var>...``
Specify the variables which are required for this package.
These may be named in the generated failure message asking the
user to set the missing variable values. Therefore these should
typically be cache entries such as ``FOO_LIBRARY`` and not output
variables like ``FOO_LIBRARIES``.
.. versionchanged:: 3.18
If ``HANDLE_COMPONENTS`` is specified, this option can be omitted.
``VERSION_VAR <version-var>``
Specify the name of a variable that holds the version of the package
that has been found. This version will be checked against the
(potentially) specified required version given to the
:command:`find_package` call, including its ``EXACT`` option.
The default messages include information about the required
version and the version which has been actually found, both
if the version is ok or not.
``HANDLE_VERSION_RANGE``
.. versionadded:: 3.19
Enable handling of a version range, if one is specified. Without this
option, a developer warning will be displayed if a version range is
specified.
``HANDLE_COMPONENTS``
Enable handling of package components. In this case, the command
will report which components have been found and which are missing,
and the ``<PackageName>_FOUND`` variable will be set to ``FALSE``
if any of the required components (i.e. not the ones listed after
the ``OPTIONAL_COMPONENTS`` option of :command:`find_package`) are
missing.
``CONFIG_MODE``
Specify that the calling find module is a wrapper around a
call to ``find_package(<PackageName> NO_MODULE)``. This implies
a ``VERSION_VAR`` value of ``<PackageName>_VERSION``. The command
will automatically check whether the package configuration file
was found.
``REASON_FAILURE_MESSAGE <reason-failure-message>``
.. versionadded:: 3.16
Specify a custom message of the reason for the failure which will be
appended to the default generated message.
``FAIL_MESSAGE <custom-failure-message>``
Specify a custom failure message instead of using the default
generated message. Not recommended.
``NAME_MISMATCHED``
.. versionadded:: 3.17
Indicate that the ``<PackageName>`` does not match
``${CMAKE_FIND_PACKAGE_NAME}``. This is usually a mistake and raises a
warning, but it may be intentional for usage of the command for components
of a larger package.
Example for the simple signature:
.. code-block:: cmake
find_package_handle_standard_args(LibXml2 DEFAULT_MSG
LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR)
The ``LibXml2`` package is considered to be found if both
``LIBXML2_LIBRARY`` and ``LIBXML2_INCLUDE_DIR`` are valid.
Then also ``LibXml2_FOUND`` is set to ``TRUE``. If it is not found
and ``REQUIRED`` was used, it fails with a
:command:`message(FATAL_ERROR)`, independent whether ``QUIET`` was
used or not. If it is found, success will be reported, including
the content of the first ``<required-var>``. On repeated CMake runs,
the same message will not be printed again.
.. note::
If ``<PackageName>`` does not match ``CMAKE_FIND_PACKAGE_NAME`` for the
calling module, a warning that there is a mismatch is given. The
``FPHSA_NAME_MISMATCHED`` variable may be set to bypass the warning if using
the old signature and the ``NAME_MISMATCHED`` argument using the new
signature. To avoid forcing the caller to require newer versions of CMake for
usage, the variable's value will be used if defined when the
``NAME_MISMATCHED`` argument is not passed for the new signature (but using
both is an error)..
Example for the full signature:
.. code-block:: cmake
find_package_handle_standard_args(LibArchive
REQUIRED_VARS LibArchive_LIBRARY LibArchive_INCLUDE_DIR
VERSION_VAR LibArchive_VERSION)
In this case, the ``LibArchive`` package is considered to be found if
both ``LibArchive_LIBRARY`` and ``LibArchive_INCLUDE_DIR`` are valid.
Also the version of ``LibArchive`` will be checked by using the version
contained in ``LibArchive_VERSION``. Since no ``FAIL_MESSAGE`` is given,
the default messages will be printed.
Another example for the full signature:
.. code-block:: cmake
find_package(Automoc4 QUIET NO_MODULE HINTS /opt/automoc4)
find_package_handle_standard_args(Automoc4 CONFIG_MODE)
In this case, a ``FindAutmoc4.cmake`` module wraps a call to
``find_package(Automoc4 NO_MODULE)`` and adds an additional search
directory for ``automoc4``. Then the call to
``find_package_handle_standard_args`` produces a proper success/failure
message.
.. command:: find_package_check_version
.. versionadded:: 3.19
Helper function which can be used to check if a ``<version>`` is valid
against version-related arguments of :command:`find_package`.
.. code-block:: cmake
find_package_check_version(<version> <result-var>
[HANDLE_VERSION_RANGE]
[RESULT_MESSAGE_VARIABLE <message-var>]
)
The ``<result-var>`` will hold a boolean value giving the result of the check.
The options are:
``HANDLE_VERSION_RANGE``
Enable handling of a version range, if one is specified. Without this
option, a developer warning will be displayed if a version range is
specified.
``RESULT_MESSAGE_VARIABLE <message-var>``
Specify a variable to get back a message describing the result of the check.
Example for the usage:
.. code-block:: cmake
find_package_check_version(1.2.3 result HANDLE_VERSION_RANGE
RESULT_MESSAGE_VARIABLE reason)
if (result)
message (STATUS "${reason}")
else()
message (FATAL_ERROR "${reason}")
endif()
#]=======================================================================]
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageMessage.cmake)
cmake_policy(PUSH)
# numbers and boolean constants
cmake_policy (SET CMP0012 NEW)
# IN_LIST operator
cmake_policy (SET CMP0057 NEW)
# internal helper macro
macro(_FPHSA_FAILURE_MESSAGE _msg)
set (__msg "${_msg}")
if (FPHSA_REASON_FAILURE_MESSAGE)
string(APPEND __msg "\n Reason given by package: ${FPHSA_REASON_FAILURE_MESSAGE}\n")
endif()
if (${_NAME}_FIND_REQUIRED)
message(FATAL_ERROR "${__msg}")
else ()
if (NOT ${_NAME}_FIND_QUIETLY)
message(STATUS "${__msg}")
endif ()
endif ()
endmacro()
# internal helper macro to generate the failure message when used in CONFIG_MODE:
macro(_FPHSA_HANDLE_FAILURE_CONFIG_MODE)
# <PackageName>_CONFIG is set, but FOUND is false, this means that some other of the REQUIRED_VARS was not found:
if(${_NAME}_CONFIG)
_FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: missing:${MISSING_VARS} (found ${${_NAME}_CONFIG} ${VERSION_MSG})")
else()
# If _CONSIDERED_CONFIGS is set, the config-file has been found, but no suitable version.
# List them all in the error message:
if(${_NAME}_CONSIDERED_CONFIGS)
set(configsText "")
list(LENGTH ${_NAME}_CONSIDERED_CONFIGS configsCount)
math(EXPR configsCount "${configsCount} - 1")
foreach(currentConfigIndex RANGE ${configsCount})
list(GET ${_NAME}_CONSIDERED_CONFIGS ${currentConfigIndex} filename)
list(GET ${_NAME}_CONSIDERED_VERSIONS ${currentConfigIndex} version)
string(APPEND configsText "\n ${filename} (version ${version})")
endforeach()
if (${_NAME}_NOT_FOUND_MESSAGE)
if (FPHSA_REASON_FAILURE_MESSAGE)
string(PREPEND FPHSA_REASON_FAILURE_MESSAGE "${${_NAME}_NOT_FOUND_MESSAGE}\n ")
else()
set(FPHSA_REASON_FAILURE_MESSAGE "${${_NAME}_NOT_FOUND_MESSAGE}")
endif()
else()
string(APPEND configsText "\n")
endif()
_FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE} ${VERSION_MSG}, checked the following files:${configsText}")
else()
# Simple case: No Config-file was found at all:
_FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: found neither ${_NAME}Config.cmake nor ${_NAME_LOWER}-config.cmake ${VERSION_MSG}")
endif()
endif()
endmacro()
function(FIND_PACKAGE_CHECK_VERSION version result)
cmake_parse_arguments (PARSE_ARGV 2 FPCV "HANDLE_VERSION_RANGE;NO_AUTHOR_WARNING_VERSION_RANGE" "RESULT_MESSAGE_VARIABLE" "")
if (FPCV_UNPARSED_ARGUMENTS)
message (FATAL_ERROR "find_package_check_version(): ${FPCV_UNPARSED_ARGUMENTS}: unexpected arguments")
endif()
if ("RESULT_MESSAGE_VARIABLE" IN_LIST FPCV_KEYWORDS_MISSING_VALUES)
message (FATAL_ERROR "find_package_check_version(): RESULT_MESSAGE_VARIABLE expects an argument")
endif()
set (${result} FALSE PARENT_SCOPE)
if (FPCV_RESULT_MESSAGE_VARIABLE)
unset (${FPCV_RESULT_MESSAGE_VARIABLE} PARENT_SCOPE)
endif()
if (_CMAKE_FPHSA_PACKAGE_NAME)
set (package "${_CMAKE_FPHSA_PACKAGE_NAME}")
elseif (CMAKE_FIND_PACKAGE_NAME)
set (package "${CMAKE_FIND_PACKAGE_NAME}")
else()
message (FATAL_ERROR "find_package_check_version(): Cannot be used outside a 'Find Module'")
endif()
if (NOT FPCV_NO_AUTHOR_WARNING_VERSION_RANGE
AND ${package}_FIND_VERSION_RANGE AND NOT FPCV_HANDLE_VERSION_RANGE)
message(AUTHOR_WARNING
"`find_package()` specify a version range but the option "
"HANDLE_VERSION_RANGE` is not passed to `find_package_check_version()`. "
"Only the lower endpoint of the range will be used.")
endif()
set (version_ok FALSE)
unset (version_msg)
if (FPCV_HANDLE_VERSION_RANGE AND ${package}_FIND_VERSION_RANGE)
if ((${package}_FIND_VERSION_RANGE_MIN STREQUAL "INCLUDE"
AND version VERSION_GREATER_EQUAL ${package}_FIND_VERSION_MIN)
AND ((${package}_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE"
AND version VERSION_LESS_EQUAL ${package}_FIND_VERSION_MAX)
OR (${package}_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE"
AND version VERSION_LESS ${package}_FIND_VERSION_MAX)))
set (version_ok TRUE)
set(version_msg "(found suitable version \"${version}\", required range is \"${${package}_FIND_VERSION_RANGE}\")")
else()
set(version_msg "Found unsuitable version \"${version}\", required range is \"${${package}_FIND_VERSION_RANGE}\"")
endif()
elseif (DEFINED ${package}_FIND_VERSION)
if(${package}_FIND_VERSION_EXACT) # exact version required
# count the dots in the version string
string(REGEX REPLACE "[^.]" "" version_dots "${version}")
# add one dot because there is one dot more than there are components
string(LENGTH "${version_dots}." version_dots)
if (version_dots GREATER ${package}_FIND_VERSION_COUNT)
# Because of the C++ implementation of find_package() ${package}_FIND_VERSION_COUNT
# is at most 4 here. Therefore a simple lookup table is used.
if (${package}_FIND_VERSION_COUNT EQUAL 1)
set(version_regex "[^.]*")
elseif (${package}_FIND_VERSION_COUNT EQUAL 2)
set(version_regex "[^.]*\\.[^.]*")
elseif (${package}_FIND_VERSION_COUNT EQUAL 3)
set(version_regex "[^.]*\\.[^.]*\\.[^.]*")
else()
set(version_regex "[^.]*\\.[^.]*\\.[^.]*\\.[^.]*")
endif()
string(REGEX REPLACE "^(${version_regex})\\..*" "\\1" version_head "${version}")
if (NOT ${package}_FIND_VERSION VERSION_EQUAL version_head)
set(version_msg "Found unsuitable version \"${version}\", but required is exact version \"${${package}_FIND_VERSION}\"")
else ()
set(version_ok TRUE)
set(version_msg "(found suitable exact version \"${_FOUND_VERSION}\")")
endif ()
else ()
if (NOT ${package}_FIND_VERSION VERSION_EQUAL version)
set(version_msg "Found unsuitable version \"${version}\", but required is exact version \"${${package}_FIND_VERSION}\"")
else ()
set(version_ok TRUE)
set(version_msg "(found suitable exact version \"${version}\")")
endif ()
endif ()
else() # minimum version
if (${package}_FIND_VERSION VERSION_GREATER version)
set(version_msg "Found unsuitable version \"${version}\", but required is at least \"${${package}_FIND_VERSION}\"")
else()
set(version_ok TRUE)
set(version_msg "(found suitable version \"${version}\", minimum required is \"${${package}_FIND_VERSION}\")")
endif()
endif()
else ()
set(version_ok TRUE)
set(version_msg "(found version \"${version}\")")
endif()
set (${result} ${version_ok} PARENT_SCOPE)
if (FPCV_RESULT_MESSAGE_VARIABLE)
set (${FPCV_RESULT_MESSAGE_VARIABLE} "${version_msg}" PARENT_SCOPE)
endif()
endfunction()
function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG)
# Set up the arguments for `cmake_parse_arguments`.
set(options CONFIG_MODE HANDLE_COMPONENTS NAME_MISMATCHED HANDLE_VERSION_RANGE)
set(oneValueArgs FAIL_MESSAGE REASON_FAILURE_MESSAGE VERSION_VAR FOUND_VAR)
set(multiValueArgs REQUIRED_VARS)
# Check whether we are in 'simple' or 'extended' mode:
set(_KEYWORDS_FOR_EXTENDED_MODE ${options} ${oneValueArgs} ${multiValueArgs} )
list(FIND _KEYWORDS_FOR_EXTENDED_MODE "${_FIRST_ARG}" INDEX)
unset(FPHSA_NAME_MISMATCHED_override)
if (DEFINED FPHSA_NAME_MISMATCHED)
# If the variable NAME_MISMATCHED variable is set, error if it is passed as
# an argument. The former is for old signatures, the latter is for new
# signatures.
list(FIND ARGN "NAME_MISMATCHED" name_mismatched_idx)
if (NOT name_mismatched_idx EQUAL "-1")
message(FATAL_ERROR
"The `NAME_MISMATCHED` argument may only be specified by the argument or "
"the variable, not both.")
endif ()
# But use the variable if it is not an argument to avoid forcing minimum
# CMake version bumps for calling modules.
set(FPHSA_NAME_MISMATCHED_override "${FPHSA_NAME_MISMATCHED}")
endif ()
if(${INDEX} EQUAL -1)
set(FPHSA_FAIL_MESSAGE ${_FIRST_ARG})
set(FPHSA_REQUIRED_VARS ${ARGN})
set(FPHSA_VERSION_VAR)
else()
cmake_parse_arguments(FPHSA "${options}" "${oneValueArgs}" "${multiValueArgs}" ${_FIRST_ARG} ${ARGN})
if(FPHSA_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Unknown keywords given to FIND_PACKAGE_HANDLE_STANDARD_ARGS(): \"${FPHSA_UNPARSED_ARGUMENTS}\"")
endif()
if(NOT FPHSA_FAIL_MESSAGE)
set(FPHSA_FAIL_MESSAGE "DEFAULT_MSG")
endif()
# In config-mode, we rely on the variable <PackageName>_CONFIG, which is set by find_package()
# when it successfully found the config-file, including version checking:
if(FPHSA_CONFIG_MODE)
list(INSERT FPHSA_REQUIRED_VARS 0 ${_NAME}_CONFIG)
list(REMOVE_DUPLICATES FPHSA_REQUIRED_VARS)
set(FPHSA_VERSION_VAR ${_NAME}_VERSION)
endif()
if(NOT FPHSA_REQUIRED_VARS AND NOT FPHSA_HANDLE_COMPONENTS)
message(FATAL_ERROR "No REQUIRED_VARS specified for FIND_PACKAGE_HANDLE_STANDARD_ARGS()")
endif()
endif()
if (DEFINED FPHSA_NAME_MISMATCHED_override)
set(FPHSA_NAME_MISMATCHED "${FPHSA_NAME_MISMATCHED_override}")
endif ()
if (DEFINED CMAKE_FIND_PACKAGE_NAME
AND NOT FPHSA_NAME_MISMATCHED
AND NOT _NAME STREQUAL CMAKE_FIND_PACKAGE_NAME)
message(AUTHOR_WARNING
"The package name passed to `find_package_handle_standard_args` "
"(${_NAME}) does not match the name of the calling package "
"(${CMAKE_FIND_PACKAGE_NAME}). This can lead to problems in calling "
"code that expects `find_package` result variables (e.g., `_FOUND`) "
"to follow a certain pattern.")
endif ()
if (${_NAME}_FIND_VERSION_RANGE AND NOT FPHSA_HANDLE_VERSION_RANGE)
message(AUTHOR_WARNING
"`find_package()` specify a version range but the module ${_NAME} does "
"not support this capability. Only the lower endpoint of the range "
"will be used.")
endif()
# to propagate package name to FIND_PACKAGE_CHECK_VERSION
set(_CMAKE_FPHSA_PACKAGE_NAME "${_NAME}")
# now that we collected all arguments, process them
if("x${FPHSA_FAIL_MESSAGE}" STREQUAL "xDEFAULT_MSG")
set(FPHSA_FAIL_MESSAGE "Could NOT find ${_NAME}")
endif()
if (FPHSA_REQUIRED_VARS)
list(GET FPHSA_REQUIRED_VARS 0 _FIRST_REQUIRED_VAR)
endif()
string(TOUPPER ${_NAME} _NAME_UPPER)
string(TOLOWER ${_NAME} _NAME_LOWER)
if(FPHSA_FOUND_VAR)
set(_FOUND_VAR_UPPER ${_NAME_UPPER}_FOUND)
set(_FOUND_VAR_MIXED ${_NAME}_FOUND)
if(FPHSA_FOUND_VAR STREQUAL _FOUND_VAR_MIXED OR FPHSA_FOUND_VAR STREQUAL _FOUND_VAR_UPPER)
set(_FOUND_VAR ${FPHSA_FOUND_VAR})
else()
message(FATAL_ERROR "The argument for FOUND_VAR is \"${FPHSA_FOUND_VAR}\", but only \"${_FOUND_VAR_MIXED}\" and \"${_FOUND_VAR_UPPER}\" are valid names.")
endif()
else()
set(_FOUND_VAR ${_NAME_UPPER}_FOUND)
endif()
# collect all variables which were not found, so they can be printed, so the
# user knows better what went wrong (#6375)
set(MISSING_VARS "")
set(DETAILS "")
# check if all passed variables are valid
set(FPHSA_FOUND_${_NAME} TRUE)
foreach(_CURRENT_VAR ${FPHSA_REQUIRED_VARS})
if(NOT ${_CURRENT_VAR})
set(FPHSA_FOUND_${_NAME} FALSE)
string(APPEND MISSING_VARS " ${_CURRENT_VAR}")
else()
string(APPEND DETAILS "[${${_CURRENT_VAR}}]")
endif()
endforeach()
if(FPHSA_FOUND_${_NAME})
set(${_NAME}_FOUND TRUE)
set(${_NAME_UPPER}_FOUND TRUE)
else()
set(${_NAME}_FOUND FALSE)
set(${_NAME_UPPER}_FOUND FALSE)
endif()
# component handling
unset(FOUND_COMPONENTS_MSG)
unset(MISSING_COMPONENTS_MSG)
if(FPHSA_HANDLE_COMPONENTS)
foreach(comp ${${_NAME}_FIND_COMPONENTS})
if(${_NAME}_${comp}_FOUND)
if(NOT DEFINED FOUND_COMPONENTS_MSG)
set(FOUND_COMPONENTS_MSG "found components:")
endif()
string(APPEND FOUND_COMPONENTS_MSG " ${comp}")
else()
if(NOT DEFINED MISSING_COMPONENTS_MSG)
set(MISSING_COMPONENTS_MSG "missing components:")
endif()
string(APPEND MISSING_COMPONENTS_MSG " ${comp}")
if(${_NAME}_FIND_REQUIRED_${comp})
set(${_NAME}_FOUND FALSE)
string(APPEND MISSING_VARS " ${comp}")
endif()
endif()
endforeach()
set(COMPONENT_MSG "${FOUND_COMPONENTS_MSG} ${MISSING_COMPONENTS_MSG}")
string(APPEND DETAILS "[c${COMPONENT_MSG}]")
endif()
# version handling:
set(VERSION_MSG "")
set(VERSION_OK TRUE)
# check that the version variable is not empty to avoid emitting a misleading
# message (i.e. `Found unsuitable version ""`)
if (DEFINED ${_NAME}_FIND_VERSION)
if(DEFINED ${FPHSA_VERSION_VAR})
if(NOT "${${FPHSA_VERSION_VAR}}" STREQUAL "")
set(_FOUND_VERSION ${${FPHSA_VERSION_VAR}})
if (FPHSA_HANDLE_VERSION_RANGE)
set (FPCV_HANDLE_VERSION_RANGE HANDLE_VERSION_RANGE)
else()
set(FPCV_HANDLE_VERSION_RANGE NO_AUTHOR_WARNING_VERSION_RANGE)
endif()
find_package_check_version ("${_FOUND_VERSION}" VERSION_OK RESULT_MESSAGE_VARIABLE VERSION_MSG
${FPCV_HANDLE_VERSION_RANGE})
else()
set(VERSION_OK FALSE)
endif()
endif()
if("${${FPHSA_VERSION_VAR}}" STREQUAL "")
# if the package was not found, but a version was given, add that to the output:
if(${_NAME}_FIND_VERSION_EXACT)
set(VERSION_MSG "(Required is exact version \"${${_NAME}_FIND_VERSION}\")")
elseif (FPHSA_HANDLE_VERSION_RANGE AND ${_NAME}_FIND_VERSION_RANGE)
set(VERSION_MSG "(Required is version range \"${${_NAME}_FIND_VERSION_RANGE}\")")
else()
set(VERSION_MSG "(Required is at least version \"${${_NAME}_FIND_VERSION}\")")
endif()
endif()
else ()
# Check with DEFINED as the found version may be 0.
if(DEFINED ${FPHSA_VERSION_VAR})
set(VERSION_MSG "(found version \"${${FPHSA_VERSION_VAR}}\")")
endif()
endif ()
if(VERSION_OK)
string(APPEND DETAILS "[v${${FPHSA_VERSION_VAR}}(${${_NAME}_FIND_VERSION})]")
else()
set(${_NAME}_FOUND FALSE)
endif()
# print the result:
if (${_NAME}_FOUND)
FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME}: ${${_FIRST_REQUIRED_VAR}} ${VERSION_MSG} ${COMPONENT_MSG}" "${DETAILS}")
else ()
if(FPHSA_CONFIG_MODE)
_FPHSA_HANDLE_FAILURE_CONFIG_MODE()
else()
if(NOT VERSION_OK)
set(RESULT_MSG)
if (_FIRST_REQUIRED_VAR)
string (APPEND RESULT_MSG "found ${${_FIRST_REQUIRED_VAR}}")
endif()
if (COMPONENT_MSG)
if (RESULT_MSG)
string (APPEND RESULT_MSG ", ")
endif()
string (APPEND RESULT_MSG "${FOUND_COMPONENTS_MSG}")
endif()
_FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: ${VERSION_MSG} (${RESULT_MSG})")
else()
_FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE} (missing:${MISSING_VARS}) ${VERSION_MSG}")
endif()
endif()
endif ()
set(${_NAME}_FOUND ${${_NAME}_FOUND} PARENT_SCOPE)
set(${_NAME_UPPER}_FOUND ${${_NAME}_FOUND} PARENT_SCOPE)
endfunction()
cmake_policy(POP)
-48
View File
@@ -1,48 +0,0 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindPackageMessage
------------------
.. code-block:: cmake
find_package_message(<name> "message for user" "find result details")
This function is intended to be used in FindXXX.cmake modules files.
It will print a message once for each unique find result. This is
useful for telling the user where a package was found. The first
argument specifies the name (XXX) of the package. The second argument
specifies the message to display. The third argument lists details
about the find result so that if they change the message will be
displayed again. The macro also obeys the QUIET argument to the
find_package command.
Example:
.. code-block:: cmake
if(X11_FOUND)
find_package_message(X11 "Found X11: ${X11_X11_LIB}"
"[${X11_X11_LIB}][${X11_INCLUDE_DIR}]")
else()
...
endif()
#]=======================================================================]
function(find_package_message pkg msg details)
# Avoid printing a message repeatedly for the same find result.
if(NOT ${pkg}_FIND_QUIETLY)
string(REPLACE "\n" "" details "${details}")
set(DETAILS_VAR FIND_PACKAGE_MESSAGE_DETAILS_${pkg})
if(NOT "${details}" STREQUAL "${${DETAILS_VAR}}")
# The message has not yet been printed.
message(STATUS "${msg}")
# Save the find details in the cache to avoid printing the same
# message again.
set("${DETAILS_VAR}" "${details}"
CACHE INTERNAL "Details about finding ${pkg}")
endif()
endif()
endfunction()
-897
View File
@@ -1,897 +0,0 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindVulkan
----------
.. versionadded:: 3.7
Find Vulkan, which is a low-overhead, cross-platform 3D graphics
and computing API.
Optional COMPONENTS
^^^^^^^^^^^^^^^^^^^
.. versionadded:: 3.24
This module respects several optional COMPONENTS.
There are corresponding imported targets for each of these.
``glslc``
The SPIR-V compiler.
``glslangValidator``
The ``glslangValidator`` tool.
``glslang``
The SPIR-V generator library.
``shaderc_combined``
The static library for Vulkan shader compilation.
``SPIRV-Tools``
Tools to process SPIR-V modules.
``MoltenVK``
On macOS, an additional component ``MoltenVK`` is available.
``dxc``
.. versionadded:: 3.25
The DirectX Shader Compiler.
The ``glslc`` and ``glslangValidator`` components are provided even
if not explicitly requested (for backward compatibility).
IMPORTED Targets
^^^^^^^^^^^^^^^^
This module defines :prop_tgt:`IMPORTED` targets if Vulkan has been found:
``Vulkan::Vulkan``
The main Vulkan library.
``Vulkan::glslc``
.. versionadded:: 3.19
The GLSLC SPIR-V compiler, if it has been found.
``Vulkan::Headers``
.. versionadded:: 3.21
Provides just Vulkan headers include paths, if found. No library is
included in this target. This can be useful for applications that
load Vulkan library dynamically.
``Vulkan::glslangValidator``
.. versionadded:: 3.21
The glslangValidator tool, if found. It is used to compile GLSL and
HLSL shaders into SPIR-V.
``Vulkan::glslang``
.. versionadded:: 3.24
Defined if SDK has the Khronos-reference front-end shader parser and SPIR-V
generator library (glslang).
``Vulkan::shaderc_combined``
.. versionadded:: 3.24
Defined if SDK has the Google static library for Vulkan shader compilation
(shaderc_combined).
``Vulkan::SPIRV-Tools``
.. versionadded:: 3.24
Defined if SDK has the Khronos library to process SPIR-V modules
(SPIRV-Tools).
``Vulkan::MoltenVK``
.. versionadded:: 3.24
Defined if SDK has the Khronos library which implement a subset of Vulkan API
over Apple Metal graphics framework. (MoltenVK).
``Vulkan::volk``
.. versionadded:: 3.25
Defined if SDK has the Vulkan meta-loader (volk).
``Vulkan::dxc_lib``
.. versionadded:: 3.25
Defined if SDK has the DirectX shader compiler library.
``Vulkan::dxc_exe``
.. versionadded:: 3.25
Defined if SDK has the DirectX shader compiler CLI tool.
Result Variables
^^^^^^^^^^^^^^^^
This module defines the following variables:
``Vulkan_FOUND``
set to true if Vulkan was found
``Vulkan_INCLUDE_DIRS``
include directories for Vulkan
``Vulkan_LIBRARIES``
link against this library to use Vulkan
``Vulkan_VERSION``
.. versionadded:: 3.23
value from ``vulkan/vulkan_core.h``
``Vulkan_glslc_FOUND``
.. versionadded:: 3.24
True, if the SDK has the glslc executable.
``Vulkan_glslangValidator_FOUND``
.. versionadded:: 3.24
True, if the SDK has the glslangValidator executable.
``Vulkan_glslang_FOUND``
.. versionadded:: 3.24
True, if the SDK has the glslang library.
``Vulkan_shaderc_combined_FOUND``
.. versionadded:: 3.24
True, if the SDK has the shaderc_combined library.
``Vulkan_SPIRV-Tools_FOUND``
.. versionadded:: 3.24
True, if the SDK has the SPIRV-Tools library.
``Vulkan_MoltenVK_FOUND``
.. versionadded:: 3.24
True, if the SDK has the MoltenVK library.
``Vulkan_volk_FOUND``
.. versionadded:: 3.25
True, if the SDK has the volk library.
``Vulkan_dxc_lib_FOUND``
.. versionadded:: 3.25
True, if the SDK has the DirectX shader compiler library.
``Vulkan_dxc_exe_FOUND``
.. versionadded:: 3.25
True, if the SDK has the DirectX shader compiler CLI tool.
The module will also defines these cache variables:
``Vulkan_INCLUDE_DIR``
the Vulkan include directory
``Vulkan_LIBRARY``
the path to the Vulkan library
``Vulkan_GLSLC_EXECUTABLE``
the path to the GLSL SPIR-V compiler
``Vulkan_GLSLANG_VALIDATOR_EXECUTABLE``
the path to the glslangValidator tool
``Vulkan_glslang_LIBRARY``
.. versionadded:: 3.24
Path to the glslang library.
``Vulkan_shaderc_combined_LIBRARY``
.. versionadded:: 3.24
Path to the shaderc_combined library.
``Vulkan_SPIRV-Tools_LIBRARY``
.. versionadded:: 3.24
Path to the SPIRV-Tools library.
``Vulkan_MoltenVK_LIBRARY``
.. versionadded:: 3.24
Path to the MoltenVK library.
``Vulkan_volk_LIBRARY``
.. versionadded:: 3.25
Path to the volk library.
``Vulkan_dxc_LIBRARY``
.. versionadded:: 3.25
Path to the DirectX shader compiler library.
``Vulkan_dxc_EXECUTABLE``
.. versionadded:: 3.25
Path to the DirectX shader compiler CLI tool.
Hints
^^^^^
.. versionadded:: 3.18
The ``VULKAN_SDK`` environment variable optionally specifies the
location of the Vulkan SDK root directory for the given
architecture. It is typically set by sourcing the toplevel
``setup-env.sh`` script of the Vulkan SDK directory into the shell
environment.
#]=======================================================================]
cmake_policy(PUSH)
cmake_policy(SET CMP0057 NEW)
set(VULKAN_SDK "${PROJECT_SOURCE_DIR}/third_party/vulkan/x86_64")
set(Vulkan_ROOT ${VULKAN_SDK})
# Provide compatibility with a common invalid component request that
# was silently ignored prior to CMake 3.24.
if("FATAL_ERROR" IN_LIST Vulkan_FIND_COMPONENTS)
message(AUTHOR_WARNING
"Ignoring unknown component 'FATAL_ERROR'.\n"
"The find_package() command documents no such argument."
)
list(REMOVE_ITEM Vulkan_FIND_COMPONENTS "FATAL_ERROR")
endif()
# For backward compatibility as `FindVulkan` in previous CMake versions allow to retrieve `glslc`
# and `glslangValidator` without requesting the corresponding component.
if(NOT glslc IN_LIST Vulkan_FIND_COMPONENTS)
list(APPEND Vulkan_FIND_COMPONENTS glslc)
endif()
if(NOT glslangValidator IN_LIST Vulkan_FIND_COMPONENTS)
list(APPEND Vulkan_FIND_COMPONENTS glslangValidator)
endif()
if(WIN32)
set(_Vulkan_library_name vulkan-1)
set(_Vulkan_hint_include_search_paths
"${VULKAN_SDK}/include"
)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_Vulkan_hint_executable_search_paths
"${VULKAN_SDK}/bin"
)
set(_Vulkan_hint_library_search_paths
"${VULKAN_SDK}/lib"
"${VULKAN_SDK}/bin"
)
else()
set(_Vulkan_hint_executable_search_paths
"${VULKAN_SDK}/bin32"
"${VULKAN_SDK}/bin"
)
set(_Vulkan_hint_library_search_paths
"${VULKAN_SDK}/lib32"
"${VULKAN_SDK}/bin32"
"${VULKAN_SDK}/lib"
"${VULKAN_SDK}/bin"
)
endif()
else()
set(_Vulkan_library_name vulkan)
set(_Vulkan_hint_include_search_paths
"${VULKAN_SDK}/include"
)
set(_Vulkan_hint_executable_search_paths
"${VULKAN_SDK}/bin"
)
set(_Vulkan_hint_library_search_paths
"${VULKAN_SDK}/lib"
)
endif()
if(APPLE AND DEFINED {VULKAN_SDK})
cmake_path(SET _MoltenVK_path NORMALIZE "${VULKAN_SDK}/../MoltenVK")
if(EXISTS "${_MoltenVK_path}")
list(APPEND _Vulkan_hint_include_search_paths
"${_MoltenVK_path}/include"
)
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
list(APPEND _Vulkan_hint_library_search_paths
"${_MoltenVK_path}/dylib/iOS"
)
elseif(CMAKE_SYSTEM_NAME STREQUAL "tvOS")
list(APPEND _Vulkan_hint_library_search_paths
"${_MoltenVK_path}/dylib/tvOS"
)
else()
list(APPEND _Vulkan_hint_library_search_paths
"${_MoltenVK_path}/dylib/macOS"
)
endif()
endif()
unset(_MoltenVK_path)
endif()
find_path(Vulkan_INCLUDE_DIR
NAMES vulkan/vulkan.h
HINTS
${_Vulkan_hint_include_search_paths}
)
mark_as_advanced(Vulkan_INCLUDE_DIR)
find_library(Vulkan_LIBRARY
NAMES ${_Vulkan_library_name}
NO_DEFAULT_PATH
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_LIBRARY)
if(glslc IN_LIST Vulkan_FIND_COMPONENTS)
find_program(Vulkan_GLSLC_EXECUTABLE
NAMES glslc
HINTS
${_Vulkan_hint_executable_search_paths}
)
mark_as_advanced(Vulkan_GLSLC_EXECUTABLE)
endif()
if(glslangValidator IN_LIST Vulkan_FIND_COMPONENTS)
find_program(Vulkan_GLSLANG_VALIDATOR_EXECUTABLE
NAMES glslangValidator
HINTS
${_Vulkan_hint_executable_search_paths}
)
mark_as_advanced(Vulkan_GLSLANG_VALIDATOR_EXECUTABLE)
endif()
if(glslang IN_LIST Vulkan_FIND_COMPONENTS)
find_library(Vulkan_glslang-spirv_LIBRARY
NAMES SPIRV
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-spirv_LIBRARY)
find_library(Vulkan_glslang-spirv_DEBUG_LIBRARY
NAMES SPIRVd
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-spirv_DEBUG_LIBRARY)
find_library(Vulkan_glslang-oglcompiler_LIBRARY
NAMES OGLCompiler
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-oglcompiler_LIBRARY)
find_library(Vulkan_glslang-oglcompiler_DEBUG_LIBRARY
NAMES OGLCompilerd
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-oglcompiler_DEBUG_LIBRARY)
find_library(Vulkan_glslang-osdependent_LIBRARY
NAMES OSDependent
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-osdependent_LIBRARY)
find_library(Vulkan_glslang-osdependent_DEBUG_LIBRARY
NAMES OSDependentd
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-osdependent_DEBUG_LIBRARY)
find_library(Vulkan_glslang-machineindependent_LIBRARY
NAMES MachineIndependent
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-machineindependent_LIBRARY)
find_library(Vulkan_glslang-machineindependent_DEBUG_LIBRARY
NAMES MachineIndependentd
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-machineindependent_DEBUG_LIBRARY)
find_library(Vulkan_glslang-genericcodegen_LIBRARY
NAMES GenericCodeGen
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-genericcodegen_LIBRARY)
find_library(Vulkan_glslang-genericcodegen_DEBUG_LIBRARY
NAMES GenericCodeGend
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang-genericcodegen_DEBUG_LIBRARY)
find_library(Vulkan_glslang_LIBRARY
NAMES glslang
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang_LIBRARY)
find_library(Vulkan_glslang_DEBUG_LIBRARY
NAMES glslangd
HINTS
${_Vulkan_hint_library_search_paths}
)
mark_as_advanced(Vulkan_glslang_DEBUG_LIBRARY)
endif()
if(shaderc_combined IN_LIST Vulkan_FIND_COMPONENTS)
find_library(Vulkan_shaderc_combined_LIBRARY
NAMES shaderc_combined
HINTS
${_Vulkan_hint_library_search_paths})
mark_as_advanced(Vulkan_shaderc_combined_LIBRARY)
find_library(Vulkan_shaderc_combined_DEBUG_LIBRARY
NAMES shaderc_combinedd
HINTS
${_Vulkan_hint_library_search_paths})
mark_as_advanced(Vulkan_shaderc_combined_DEBUG_LIBRARY)
endif()
if(SPIRV-Tools IN_LIST Vulkan_FIND_COMPONENTS)
find_library(Vulkan_SPIRV-Tools_LIBRARY
NAMES SPIRV-Tools
HINTS
${_Vulkan_hint_library_search_paths})
mark_as_advanced(Vulkan_SPIRV-Tools_LIBRARY)
find_library(Vulkan_SPIRV-Tools_DEBUG_LIBRARY
NAMES SPIRV-Toolsd
HINTS
${_Vulkan_hint_library_search_paths})
mark_as_advanced(Vulkan_SPIRV-Tools_DEBUG_LIBRARY)
endif()
if(MoltenVK IN_LIST Vulkan_FIND_COMPONENTS)
find_library(Vulkan_MoltenVK_LIBRARY
NAMES MoltenVK
HINTS
${_Vulkan_hint_library_search_paths})
mark_as_advanced(Vulkan_MoltenVK_LIBRARY)
find_path(Vulkan_MoltenVK_INCLUDE_DIR
NAMES MoltenVK/mvk_vulkan.h
HINTS
${_Vulkan_hint_include_search_paths}
)
mark_as_advanced(Vulkan_MoltenVK_INCLUDE_DIR)
endif()
if(volk IN_LIST Vulkan_FIND_COMPONENTS)
find_library(Vulkan_volk_LIBRARY
NAMES volk
HINTS
${_Vulkan_hint_library_search_paths})
mark_as_advanced(Vulkan_Volk_LIBRARY)
endif()
if (dxc IN_LIST Vulkan_FIND_COMPONENTS)
find_library(Vulkan_dxc_LIBRARY
NAMES dxcompiler
HINTS
${_Vulkan_hint_library_search_paths})
mark_as_advanced(Vulkan_dxc_LIBRARY)
find_program(Vulkan_dxc_EXECUTABLE
NAMES dxc
HINTS
${_Vulkan_hint_executable_search_paths})
mark_as_advanced(Vulkan_dxc_EXECUTABLE)
endif()
if(Vulkan_GLSLC_EXECUTABLE)
set(Vulkan_glslc_FOUND TRUE)
else()
set(Vulkan_glslc_FOUND FALSE)
endif()
if(Vulkan_GLSLANG_VALIDATOR_EXECUTABLE)
set(Vulkan_glslangValidator_FOUND TRUE)
else()
set(Vulkan_glslangValidator_FOUND FALSE)
endif()
if (Vulkan_dxc_EXECUTABLE)
set(Vulkan_dxc_exe_FOUND TRUE)
else()
set(Vulkan_dxc_exe_FOUND FALSE)
endif()
function(_Vulkan_set_library_component_found component)
cmake_parse_arguments(PARSE_ARGV 1 _ARG
"NO_WARNING"
""
"DEPENDENT_COMPONENTS")
set(all_dependent_component_found TRUE)
foreach(dependent_component IN LISTS _ARG_DEPENDENT_COMPONENTS)
if(NOT Vulkan_${dependent_component}_FOUND)
set(all_dependent_component_found FALSE)
break()
endif()
endforeach()
if(all_dependent_component_found AND (Vulkan_${component}_LIBRARY OR Vulkan_${component}_DEBUG_LIBRARY))
set(Vulkan_${component}_FOUND TRUE PARENT_SCOPE)
# For Windows Vulkan SDK, third party tools binaries are provided with different MSVC ABI:
# - Release binaries uses a runtime library
# - Debug binaries uses a debug runtime library
# This lead to incompatibilities in linking for some configuration types due to CMake-default or project-configured selected MSVC ABI.
if(WIN32 AND NOT _ARG_NO_WARNING)
if(NOT Vulkan_${component}_LIBRARY)
message(WARNING
"Library ${component} for Release configuration is missing, imported target Vulkan::${component} may not be able to link when targeting this build configuration due to incompatible MSVC ABI.")
endif()
if(NOT Vulkan_${component}_DEBUG_LIBRARY)
message(WARNING
"Library ${component} for Debug configuration is missing, imported target Vulkan::${component} may not be able to link when targeting this build configuration due to incompatible MSVC ABI. Consider re-installing the Vulkan SDK and request debug libraries to fix this warning.")
endif()
endif()
else()
set(Vulkan_${component}_FOUND FALSE PARENT_SCOPE)
endif()
endfunction()
_Vulkan_set_library_component_found(glslang-spirv NO_WARNING)
_Vulkan_set_library_component_found(glslang-oglcompiler NO_WARNING)
_Vulkan_set_library_component_found(glslang-osdependent NO_WARNING)
_Vulkan_set_library_component_found(glslang-machineindependent NO_WARNING)
_Vulkan_set_library_component_found(glslang-genericcodegen NO_WARNING)
_Vulkan_set_library_component_found(glslang
DEPENDENT_COMPONENTS
glslang-spirv
glslang-oglcompiler
glslang-osdependent
glslang-machineindependent
glslang-genericcodegen)
_Vulkan_set_library_component_found(shaderc_combined)
_Vulkan_set_library_component_found(SPIRV-Tools)
_Vulkan_set_library_component_found(volk)
_Vulkan_set_library_component_found(dxc)
if(Vulkan_MoltenVK_INCLUDE_DIR AND Vulkan_MoltenVK_LIBRARY)
set(Vulkan_MoltenVK_FOUND TRUE)
else()
set(Vulkan_MoltenVK_FOUND FALSE)
endif()
set(Vulkan_LIBRARIES ${Vulkan_LIBRARY})
set(Vulkan_INCLUDE_DIRS ${Vulkan_INCLUDE_DIR})
# detect version e.g 1.2.189
set(Vulkan_VERSION "")
if(Vulkan_INCLUDE_DIR)
set(VULKAN_CORE_H ${Vulkan_INCLUDE_DIR}/vulkan/vulkan_core.h)
if(EXISTS ${VULKAN_CORE_H})
file(STRINGS ${VULKAN_CORE_H} VulkanHeaderVersionLine REGEX "^#define VK_HEADER_VERSION ")
string(REGEX MATCHALL "[0-9]+" VulkanHeaderVersion "${VulkanHeaderVersionLine}")
file(STRINGS ${VULKAN_CORE_H} VulkanHeaderVersionLine2 REGEX "^#define VK_HEADER_VERSION_COMPLETE ")
string(REGEX MATCHALL "[0-9]+" VulkanHeaderVersion2 "${VulkanHeaderVersionLine2}")
list(LENGTH VulkanHeaderVersion2 _len)
# versions >= 1.2.175 have an additional numbers in front of e.g. '0, 1, 2' instead of '1, 2'
if(_len EQUAL 3)
list(REMOVE_AT VulkanHeaderVersion2 0)
endif()
list(APPEND VulkanHeaderVersion2 ${VulkanHeaderVersion})
list(JOIN VulkanHeaderVersion2 "." Vulkan_VERSION)
endif()
endif()
if(Vulkan_MoltenVK_FOUND)
set(Vulkan_MoltenVK_VERSION "")
if(Vulkan_MoltenVK_INCLUDE_DIR)
set(VK_MVK_MOLTENVK_H ${Vulkan_MoltenVK_INCLUDE_DIR}/MoltenVK/vk_mvk_moltenvk.h)
if(EXISTS ${VK_MVK_MOLTENVK_H})
file(STRINGS ${VK_MVK_MOLTENVK_H} _Vulkan_MoltenVK_VERSION_MAJOR REGEX "^#define MVK_VERSION_MAJOR ")
string(REGEX MATCHALL "[0-9]+" _Vulkan_MoltenVK_VERSION_MAJOR "${_Vulkan_MoltenVK_VERSION_MAJOR}")
file(STRINGS ${VK_MVK_MOLTENVK_H} _Vulkan_MoltenVK_VERSION_MINOR REGEX "^#define MVK_VERSION_MINOR ")
string(REGEX MATCHALL "[0-9]+" _Vulkan_MoltenVK_VERSION_MINOR "${_Vulkan_MoltenVK_VERSION_MINOR}")
file(STRINGS ${VK_MVK_MOLTENVK_H} _Vulkan_MoltenVK_VERSION_PATCH REGEX "^#define MVK_VERSION_PATCH ")
string(REGEX MATCHALL "[0-9]+" _Vulkan_MoltenVK_VERSION_PATCH "${_Vulkan_MoltenVK_VERSION_PATCH}")
set(Vulkan_MoltenVK_VERSION "${_Vulkan_MoltenVK_VERSION_MAJOR}.${_Vulkan_MoltenVK_VERSION_MINOR}.${_Vulkan_MoltenVK_VERSION_PATCH}")
unset(_Vulkan_MoltenVK_VERSION_MAJOR)
unset(_Vulkan_MoltenVK_VERSION_MINOR)
unset(_Vulkan_MoltenVK_VERSION_PATCH)
endif()
endif()
endif()
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
find_package_handle_standard_args(Vulkan
REQUIRED_VARS
Vulkan_LIBRARY
Vulkan_INCLUDE_DIR
VERSION_VAR
Vulkan_VERSION
HANDLE_COMPONENTS
)
if(Vulkan_FOUND AND NOT TARGET Vulkan::Vulkan)
add_library(Vulkan::Vulkan UNKNOWN IMPORTED)
set_target_properties(Vulkan::Vulkan PROPERTIES
IMPORTED_LOCATION "${Vulkan_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
endif()
if(Vulkan_FOUND AND NOT TARGET Vulkan::Headers)
add_library(Vulkan::Headers INTERFACE IMPORTED)
set_target_properties(Vulkan::Headers PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
endif()
if(Vulkan_FOUND AND Vulkan_GLSLC_EXECUTABLE AND NOT TARGET Vulkan::glslc)
add_executable(Vulkan::glslc IMPORTED)
set_property(TARGET Vulkan::glslc PROPERTY IMPORTED_LOCATION "${Vulkan_GLSLC_EXECUTABLE}")
endif()
if(Vulkan_FOUND AND Vulkan_GLSLANG_VALIDATOR_EXECUTABLE AND NOT TARGET Vulkan::glslangValidator)
add_executable(Vulkan::glslangValidator IMPORTED)
set_property(TARGET Vulkan::glslangValidator PROPERTY IMPORTED_LOCATION "${Vulkan_GLSLANG_VALIDATOR_EXECUTABLE}")
endif()
if(Vulkan_FOUND)
if((Vulkan_glslang-spirv_LIBRARY OR Vulkan_glslang-spirv_DEBUG_LIBRARY) AND NOT TARGET Vulkan::glslang-spirv)
add_library(Vulkan::glslang-spirv STATIC IMPORTED)
set_property(TARGET Vulkan::glslang-spirv
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
if(Vulkan_glslang-spirv_LIBRARY)
set_property(TARGET Vulkan::glslang-spirv APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::glslang-spirv
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_glslang-spirv_LIBRARY}")
endif()
if(Vulkan_glslang-spirv_DEBUG_LIBRARY)
set_property(TARGET Vulkan::glslang-spirv APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Debug)
set_property(TARGET Vulkan::glslang-spirv
PROPERTY
IMPORTED_LOCATION_DEBUG "${Vulkan_glslang-spirv_DEBUG_LIBRARY}")
endif()
endif()
if((Vulkan_glslang-oglcompiler_LIBRARY OR Vulkan_glslang-oglcompiler_DEBUG_LIBRARY) AND NOT TARGET Vulkan::glslang-oglcompiler)
add_library(Vulkan::glslang-oglcompiler STATIC IMPORTED)
set_property(TARGET Vulkan::glslang-oglcompiler
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
if(Vulkan_glslang-oglcompiler_LIBRARY)
set_property(TARGET Vulkan::glslang-oglcompiler APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::glslang-oglcompiler
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_glslang-oglcompiler_LIBRARY}")
endif()
if(Vulkan_glslang-oglcompiler_DEBUG_LIBRARY)
set_property(TARGET Vulkan::glslang-oglcompiler APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Debug)
set_property(TARGET Vulkan::glslang-oglcompiler
PROPERTY
IMPORTED_LOCATION_DEBUG "${Vulkan_glslang-oglcompiler_DEBUG_LIBRARY}")
endif()
endif()
if((Vulkan_glslang-osdependent_LIBRARY OR Vulkan_glslang-osdependent_DEBUG_LIBRARY) AND NOT TARGET Vulkan::glslang-osdependent)
add_library(Vulkan::glslang-osdependent STATIC IMPORTED)
set_property(TARGET Vulkan::glslang-osdependent
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
if(Vulkan_glslang-osdependent_LIBRARY)
set_property(TARGET Vulkan::glslang-osdependent APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::glslang-osdependent
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_glslang-osdependent_LIBRARY}")
endif()
if(Vulkan_glslang-osdependent_DEBUG_LIBRARY)
set_property(TARGET Vulkan::glslang-osdependent APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Debug)
set_property(TARGET Vulkan::glslang-osdependent
PROPERTY
IMPORTED_LOCATION_DEBUG "${Vulkan_glslang-osdependent_DEBUG_LIBRARY}")
endif()
endif()
if((Vulkan_glslang-machineindependent_LIBRARY OR Vulkan_glslang-machineindependent_DEBUG_LIBRARY) AND NOT TARGET Vulkan::glslang-machineindependent)
add_library(Vulkan::glslang-machineindependent STATIC IMPORTED)
set_property(TARGET Vulkan::glslang-machineindependent
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
if(Vulkan_glslang-machineindependent_LIBRARY)
set_property(TARGET Vulkan::glslang-machineindependent APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::glslang-machineindependent
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_glslang-machineindependent_LIBRARY}")
endif()
if(Vulkan_glslang-machineindependent_DEBUG_LIBRARY)
set_property(TARGET Vulkan::glslang-machineindependent APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Debug)
set_property(TARGET Vulkan::glslang-machineindependent
PROPERTY
IMPORTED_LOCATION_DEBUG "${Vulkan_glslang-machineindependent_DEBUG_LIBRARY}")
endif()
endif()
if((Vulkan_glslang-genericcodegen_LIBRARY OR Vulkan_glslang-genericcodegen_DEBUG_LIBRARY) AND NOT TARGET Vulkan::glslang-genericcodegen)
add_library(Vulkan::glslang-genericcodegen STATIC IMPORTED)
set_property(TARGET Vulkan::glslang-genericcodegen
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
if(Vulkan_glslang-genericcodegen_LIBRARY)
set_property(TARGET Vulkan::glslang-genericcodegen APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::glslang-genericcodegen
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_glslang-genericcodegen_LIBRARY}")
endif()
if(Vulkan_glslang-genericcodegen_DEBUG_LIBRARY)
set_property(TARGET Vulkan::glslang-genericcodegen APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Debug)
set_property(TARGET Vulkan::glslang-genericcodegen
PROPERTY
IMPORTED_LOCATION_DEBUG "${Vulkan_glslang-genericcodegen_DEBUG_LIBRARY}")
endif()
endif()
if((Vulkan_glslang_LIBRARY OR Vulkan_glslang_DEBUG_LIBRARY)
AND TARGET Vulkan::glslang-spirv
AND TARGET Vulkan::glslang-oglcompiler
AND TARGET Vulkan::glslang-osdependent
AND TARGET Vulkan::glslang-machineindependent
AND TARGET Vulkan::glslang-genericcodegen
AND NOT TARGET Vulkan::glslang)
add_library(Vulkan::glslang STATIC IMPORTED)
set_property(TARGET Vulkan::glslang
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
if(Vulkan_glslang_LIBRARY)
set_property(TARGET Vulkan::glslang APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::glslang
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_glslang_LIBRARY}")
endif()
if(Vulkan_glslang_DEBUG_LIBRARY)
set_property(TARGET Vulkan::glslang APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Debug)
set_property(TARGET Vulkan::glslang
PROPERTY
IMPORTED_LOCATION_DEBUG "${Vulkan_glslang_DEBUG_LIBRARY}")
endif()
target_link_libraries(Vulkan::glslang
INTERFACE
Vulkan::glslang-spirv
Vulkan::glslang-oglcompiler
Vulkan::glslang-osdependent
Vulkan::glslang-machineindependent
Vulkan::glslang-genericcodegen
)
endif()
if((Vulkan_shaderc_combined_LIBRARY OR Vulkan_shaderc_combined_DEBUG_LIBRARY) AND NOT TARGET Vulkan::shaderc_combined)
add_library(Vulkan::shaderc_combined STATIC IMPORTED)
set_property(TARGET Vulkan::shaderc_combined
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
if(Vulkan_shaderc_combined_LIBRARY)
set_property(TARGET Vulkan::shaderc_combined APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::shaderc_combined
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_shaderc_combined_LIBRARY}")
endif()
if(Vulkan_shaderc_combined_DEBUG_LIBRARY)
set_property(TARGET Vulkan::shaderc_combined APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Debug)
set_property(TARGET Vulkan::shaderc_combined
PROPERTY
IMPORTED_LOCATION_DEBUG "${Vulkan_shaderc_combined_DEBUG_LIBRARY}")
endif()
if(UNIX)
find_package(Threads REQUIRED)
target_link_libraries(Vulkan::shaderc_combined
INTERFACE
Threads::Threads)
endif()
endif()
if((Vulkan_SPIRV-Tools_LIBRARY OR Vulkan_SPIRV-Tools_DEBUG_LIBRARY) AND NOT TARGET Vulkan::SPIRV-Tools)
add_library(Vulkan::SPIRV-Tools STATIC IMPORTED)
set_property(TARGET Vulkan::SPIRV-Tools
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
if(Vulkan_SPIRV-Tools_LIBRARY)
set_property(TARGET Vulkan::SPIRV-Tools APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::SPIRV-Tools
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_SPIRV-Tools_LIBRARY}")
endif()
if(Vulkan_SPIRV-Tools_DEBUG_LIBRARY)
set_property(TARGET Vulkan::SPIRV-Tools APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Debug)
set_property(TARGET Vulkan::SPIRV-Tools
PROPERTY
IMPORTED_LOCATION_DEBUG "${Vulkan_SPIRV-Tools_DEBUG_LIBRARY}")
endif()
endif()
if(Vulkan_volk_LIBRARY AND NOT TARGET Vulkan::volk)
add_library(Vulkan::volk STATIC IMPORTED)
set_property(TARGET Vulkan::volk
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
set_property(TARGET Vulkan::volk APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::volk APPEND
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_volk_LIBRARY}")
if (NOT WIN32)
set_property(TARGET Vulkan::volk APPEND
PROPERTY
IMPORTED_LINK_INTERFACE_LIBRARIES dl)
endif()
endif()
if (Vulkan_dxc_LIBRARY AND NOT TARGET Vulkan::dxc_lib)
add_library(Vulkan::dxc_lib STATIC IMPORTED)
set_property(TARGET Vulkan::dxc_lib
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
set_property(TARGET Vulkan::dxc_lib APPEND
PROPERTY
IMPORTED_CONFIGURATIONS Release)
set_property(TARGET Vulkan::dxc_lib APPEND
PROPERTY
IMPORTED_LOCATION_RELEASE "${Vulkan_dxc_LIBRARY}")
endif()
if(Vulkan_dxc_EXECUTABLE AND NOT TARGET Vulkan::dxc_exe)
add_executable(Vulkan::dxc_exe IMPORTED)
set_property(TARGET Vulkan::dxc_exe PROPERTY IMPORTED_LOCATION "${Vulkan_dxc_EXECUTABLE}")
endif()
endif()
if(Vulkan_MoltenVK_FOUND)
if(Vulkan_MoltenVK_LIBRARY AND NOT TARGET Vulkan::MoltenVK)
add_library(Vulkan::MoltenVK SHARED IMPORTED)
set_target_properties(Vulkan::MoltenVK
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_MoltenVK_INCLUDE_DIR}"
IMPORTED_LOCATION "${Vulkan_MoltenVK_LIBRARY}"
)
endif()
endif()
unset(_Vulkan_library_name)
unset(_Vulkan_hint_include_search_paths)
unset(_Vulkan_hint_executable_search_paths)
unset(_Vulkan_hint_library_search_paths)
cmake_policy(POP)
-10
View File
@@ -1,10 +0,0 @@
set(GLFW3_DIR "${PROJECT_SOURCE_DIR}/third_party/GLFW/")
find_library(
glfw
NAMES glfw
HINTS ${GLFW3_DIR}/build/src
)
set(glfw3_INCLUDE_DIR "${GLFW3_DIR}/include/")
-10
View File
@@ -1,10 +0,0 @@
set(VMA_DIR "${PROJECT_SOURCE_DIR}/third_party/vma/")
find_file(
vma_header
NAMES vk_mem_alloc.h
HINTS ${VMA_DIR}/include
)
set(vma_INCLUDE_DIR "${VMA_DIR}/include")
+184 -83
View File
@@ -22,18 +22,25 @@
#include "vulkan/vulkan_core.h"
#include "vulkan_errors.h"
RSE_LINKED_LIST_DEFINE(descriptor_set_layout_list_t,
VkDescriptorSetLayoutBinding);
RSE_LINKED_LIST_DEFINE(descriptor_set_layout_list_t, VkDescriptorSetLayoutBinding);
struct descriptor_t
{
uint32_t binding;
VkDescriptorType type;
uint32_t descriptors_count;
uint32_t descriptor_count;
VkShaderStageFlags shader_stages;
VkSampler immutable_sampler;
};
RSE_LINKED_LIST_DEFINE(descriptors_list_t, struct descriptor_t);
RSE_LINKED_LIST_DEFINE(descriptor_set_list_t, struct descriptor_t);
struct descriptor_set_handle_t
{
VkDescriptorSet descriptor_sets;
VkDescriptorPool descriptor_pool;
VkDescriptorSetLayout descriptor_sets_layout;
};
/* FIXME: When new descriptors are introduced to Vulkan, this enum has to be
* updated */
@@ -59,40 +66,37 @@ enum descriptor_type_id_t
DESCRIPTOR_TYPE_ID_MAX_ENUM,
};
struct descriptors_data_t
rse_err_t descriptor_add_set(struct descriptor_set_list_t* descriptor_set_list, uint32_t binding, VkDescriptorType type,
uint32_t descriptor_count, VkShaderStageFlags shader_stages, VkSampler sampler)
{
VkDescriptorPool pool;
VkDescriptorSet set;
struct descriptor_set_layout_list_t layouts_list;
};
rse_err_t descriptor_add(struct descriptors_list_t* descriptors_list,
uint32_t binding, VkDescriptorType type,
uint32_t descriptors_count,
VkShaderStageFlags shader_stages, VkSampler sampler)
{
struct descriptor_t descriptor = {.binding = binding,
struct descriptor_t descriptor_sets = {.binding = binding,
.type = type,
.descriptors_count = descriptors_count,
.descriptor_count = descriptor_count,
.shader_stages = shader_stages,
.immutable_sampler = sampler};
RSE_LINKED_LIST_PUSH_BACK(descriptors_list, descriptor);
RSE_LINKED_LIST_PUSH_BACK(descriptor_set_list, descriptor_sets);
return RSE_ERROR_NO_ERROR;
}
rse_err_t descriptors_build(struct graphics_context_t* context,
struct descriptors_list_t* descriptors)
rse_err_t descriptors_build(struct graphics_context_t* context, struct descriptor_set_list_t* descriptors,
struct descriptor_set_handle_t* descriptor_set_handle)
{
VkDescriptorPoolCreateInfo pool_create_info = {};
VkDescriptorPoolCreateFlags pool_create_flags = 0U;
VkDescriptorPool descriptor_pool = VK_NULL_HANDLE;
VkDescriptorPoolSize pool_sizes[DESCRIPTOR_TYPE_ID_MAX_ENUM] = {};
VkDescriptorPoolSize requested_pool_sizes[DESCRIPTOR_TYPE_ID_MAX_ENUM] = {};
uint32_t pool_max_sets = 0;
size_t pool_size_count = 0U;
size_t iterator = 0U;
size_t pool_size_count = 0U;
uint32_t pool_max_sets = 0U;
uint32_t sets_per_type = 0U;
VkDescriptorPool descriptor_pool = VK_NULL_HANDLE;
VkDescriptorPoolCreateInfo pool_create_info = {0};
VkDescriptorPoolCreateFlags pool_create_flags = 0U; // TODO: Flags not set anywhere
VkDescriptorPoolSize pool_sizes[DESCRIPTOR_TYPE_ID_MAX_ENUM] = {0};
VkDescriptorPoolSize requested_pool_sizes[DESCRIPTOR_TYPE_ID_MAX_ENUM] = {0};
VkDescriptorSetAllocateInfo alloc_info = {0};
VkDescriptorSetLayoutBinding layout_bindings[DESCRIPTOR_TYPE_ID_MAX_ENUM] = {0};
VkDescriptorSetLayoutCreateInfo layout_create_info = {0};
VkDescriptorSetLayout set_layout = VK_NULL_HANDLE;
VkDescriptorSet descriptor_sets = VK_NULL_HANDLE;
if (NULL == context) {
LOGF(_("Provided NULL context\n"));
@@ -100,118 +104,193 @@ rse_err_t descriptors_build(struct graphics_context_t* context,
return RSE_ERROR_NULL_POINTER;
}
iterator = 0U;
RSE_LINKED_LIST_FOREACH(descriptors, descriptor)
{
switch (descriptor->data.type) {
case VK_DESCRIPTOR_TYPE_SAMPLER:
pool_sizes[DESCRIPTOR_TYPE_SAMPLER_ID].type =
VK_DESCRIPTOR_TYPE_SAMPLER;
pool_sizes[DESCRIPTOR_TYPE_SAMPLER_ID].type = VK_DESCRIPTOR_TYPE_SAMPLER;
pool_sizes[DESCRIPTOR_TYPE_SAMPLER_ID].descriptorCount++;
break;
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
pool_sizes[DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER_ID].type =
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
pool_sizes[DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER_ID]
.descriptorCount++;
pool_sizes[DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER_ID].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
pool_sizes[DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER_ID].descriptorCount++;
break;
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
pool_sizes[DESCRIPTOR_TYPE_SAMPLED_IMAGE_ID].type =
VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
pool_sizes[DESCRIPTOR_TYPE_SAMPLED_IMAGE_ID].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
pool_sizes[DESCRIPTOR_TYPE_SAMPLED_IMAGE_ID].descriptorCount++;
break;
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
pool_sizes[DESCRIPTOR_TYPE_STORAGE_IMAGE_ID].type =
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
pool_sizes[DESCRIPTOR_TYPE_STORAGE_IMAGE_ID].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
pool_sizes[DESCRIPTOR_TYPE_STORAGE_IMAGE_ID].descriptorCount++;
break;
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
pool_sizes[DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER_ID].type =
VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
pool_sizes[DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER_ID]
.descriptorCount++;
pool_sizes[DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER_ID].type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
pool_sizes[DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER_ID].descriptorCount++;
break;
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
pool_sizes[DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER_ID].type =
VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
pool_sizes[DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER_ID]
.descriptorCount++;
pool_sizes[DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER_ID].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
pool_sizes[DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER_ID].descriptorCount++;
break;
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
pool_sizes[DESCRIPTOR_TYPE_UNIFORM_BUFFER_ID].type =
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
pool_sizes[DESCRIPTOR_TYPE_UNIFORM_BUFFER_ID].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
pool_sizes[DESCRIPTOR_TYPE_UNIFORM_BUFFER_ID].descriptorCount++;
break;
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
pool_sizes[DESCRIPTOR_TYPE_STORAGE_BUFFER_ID].type =
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
pool_sizes[DESCRIPTOR_TYPE_STORAGE_BUFFER_ID].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
pool_sizes[DESCRIPTOR_TYPE_STORAGE_BUFFER_ID].descriptorCount++;
break;
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
pool_sizes[DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC_ID].type =
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
pool_sizes[DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC_ID]
.descriptorCount++;
pool_sizes[DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC_ID].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
pool_sizes[DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC_ID].descriptorCount++;
break;
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
pool_sizes[DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC_ID].type =
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC;
pool_sizes[DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC_ID]
.descriptorCount++;
pool_sizes[DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC_ID].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC;
pool_sizes[DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC_ID].descriptorCount++;
break;
case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
pool_sizes[DESCRIPTOR_TYPE_INPUT_ATTACHMENT_ID].type =
VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
pool_sizes[DESCRIPTOR_TYPE_INPUT_ATTACHMENT_ID]
.descriptorCount++;
pool_sizes[DESCRIPTOR_TYPE_INPUT_ATTACHMENT_ID].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
pool_sizes[DESCRIPTOR_TYPE_INPUT_ATTACHMENT_ID].descriptorCount++;
break;
case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK:
pool_sizes[DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_ID].type =
VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK;
pool_sizes[DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_ID]
.descriptorCount++;
pool_sizes[DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_ID].type = VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK;
pool_sizes[DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_ID].descriptorCount++;
break;
case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR:
pool_sizes[DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR_ID].type =
VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR;
pool_sizes[DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR_ID]
.descriptorCount++;
pool_sizes[DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR_ID].descriptorCount++;
break;
case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV:
pool_sizes[DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV_ID].type =
VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV;
pool_sizes[DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV_ID]
.descriptorCount++;
pool_sizes[DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV_ID].descriptorCount++;
break;
case VK_DESCRIPTOR_TYPE_SAMPLE_WEIGHT_IMAGE_QCOM:
pool_sizes[DESCRIPTOR_TYPE_SAMPLE_WEIGHT_IMAGE_QCOM_ID].type =
VK_DESCRIPTOR_TYPE_SAMPLE_WEIGHT_IMAGE_QCOM;
pool_sizes[DESCRIPTOR_TYPE_SAMPLE_WEIGHT_IMAGE_QCOM_ID]
.descriptorCount++;
pool_sizes[DESCRIPTOR_TYPE_SAMPLE_WEIGHT_IMAGE_QCOM_ID].descriptorCount++;
break;
case VK_DESCRIPTOR_TYPE_BLOCK_MATCH_IMAGE_QCOM:
pool_sizes[DESCRIPTOR_TYPE_BLOCK_MATCH_IMAGE_QCOM_ID].type =
VK_DESCRIPTOR_TYPE_BLOCK_MATCH_IMAGE_QCOM;
pool_sizes[DESCRIPTOR_TYPE_BLOCK_MATCH_IMAGE_QCOM_ID]
.descriptorCount++;
pool_sizes[DESCRIPTOR_TYPE_BLOCK_MATCH_IMAGE_QCOM_ID].type = VK_DESCRIPTOR_TYPE_BLOCK_MATCH_IMAGE_QCOM;
pool_sizes[DESCRIPTOR_TYPE_BLOCK_MATCH_IMAGE_QCOM_ID].descriptorCount++;
break;
case VK_DESCRIPTOR_TYPE_MUTABLE_EXT:
pool_sizes[DESCRIPTOR_TYPE_MUTABLE_EXT_ID].type =
VK_DESCRIPTOR_TYPE_MUTABLE_EXT;
pool_sizes[DESCRIPTOR_TYPE_MUTABLE_EXT_ID].type = VK_DESCRIPTOR_TYPE_MUTABLE_EXT;
pool_sizes[DESCRIPTOR_TYPE_MUTABLE_EXT_ID].descriptorCount++;
break;
default:
LOGF(_("Invalid descriptor type provided\n"));
return VULKAN_ERROR_UNKNOWN_DESCRIPTOR_TYPE;
}
layout_bindings[iterator].binding = descriptor->data.binding;
layout_bindings[iterator].descriptorCount = descriptor->data.descriptor_count;
layout_bindings[iterator].descriptorType = descriptor->data.type;
layout_bindings[iterator].pImmutableSamplers = descriptor->data.immutable_sampler;
layout_bindings[iterator].stageFlags = descriptor->data.shader_stages;
iterator++;
}
layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
layout_create_info.bindingCount = iterator;
layout_create_info.pBindings = layout_bindings;
if (VK_SUCCESS != vkCreateDescriptorSetLayout(context->device, &layout_create_info, NULL, &set_layout)) {
LOGF(_("Failed to create descriptor sets layout\n"));
return VULKAN_ERROR_DESCRIPTOR_SET_LAYOUT_CREATION_FAILED;
}
/* Another loop. Seems bit too many? TODO: Optimize this later.
* What I'm doing here is calculating minimum viable number of pool max sets. This is a bit tricky, as
* (unintuitively) we have to select the MINIMUM number of sets, not maximum. This makes sense, but is difficult to
* wrap headr around */
RSE_LINKED_LIST_FOREACH(descriptors, descriptor)
{
switch (descriptor->data.type) {
case VK_DESCRIPTOR_TYPE_SAMPLER:
sets_per_type =
pool_sizes[DESCRIPTOR_TYPE_SAMPLER_ID].descriptorCount / descriptor->data.descriptor_count;
break;
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
sets_per_type = pool_sizes[DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER_ID].descriptorCount /
descriptor->data.descriptor_count;
break;
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
sets_per_type =
pool_sizes[DESCRIPTOR_TYPE_SAMPLED_IMAGE_ID].descriptorCount / descriptor->data.descriptor_count;
break;
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
sets_per_type =
pool_sizes[DESCRIPTOR_TYPE_STORAGE_IMAGE_ID].descriptorCount / descriptor->data.descriptor_count;
break;
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
sets_per_type = pool_sizes[DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER_ID].descriptorCount /
descriptor->data.descriptor_count;
break;
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
sets_per_type = pool_sizes[DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER_ID].descriptorCount /
descriptor->data.descriptor_count;
break;
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
sets_per_type =
pool_sizes[DESCRIPTOR_TYPE_UNIFORM_BUFFER_ID].descriptorCount / descriptor->data.descriptor_count;
break;
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
sets_per_type =
pool_sizes[DESCRIPTOR_TYPE_STORAGE_BUFFER_ID].descriptorCount / descriptor->data.descriptor_count;
break;
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
sets_per_type = pool_sizes[DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC_ID].descriptorCount /
descriptor->data.descriptor_count;
break;
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
sets_per_type = pool_sizes[DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC_ID].descriptorCount /
descriptor->data.descriptor_count;
break;
case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
sets_per_type =
pool_sizes[DESCRIPTOR_TYPE_INPUT_ATTACHMENT_ID].descriptorCount / descriptor->data.descriptor_count;
break;
case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK:
sets_per_type = pool_sizes[DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_ID].descriptorCount /
descriptor->data.descriptor_count;
break;
case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR:
sets_per_type = pool_sizes[DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR_ID].descriptorCount /
descriptor->data.descriptor_count;
break;
case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV:
sets_per_type = pool_sizes[DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV_ID].descriptorCount /
descriptor->data.descriptor_count;
break;
case VK_DESCRIPTOR_TYPE_SAMPLE_WEIGHT_IMAGE_QCOM:
sets_per_type = pool_sizes[DESCRIPTOR_TYPE_SAMPLE_WEIGHT_IMAGE_QCOM_ID].descriptorCount /
descriptor->data.descriptor_count;
break;
case VK_DESCRIPTOR_TYPE_BLOCK_MATCH_IMAGE_QCOM:
sets_per_type = pool_sizes[DESCRIPTOR_TYPE_BLOCK_MATCH_IMAGE_QCOM_ID].descriptorCount /
descriptor->data.descriptor_count;
break;
case VK_DESCRIPTOR_TYPE_MUTABLE_EXT:
sets_per_type =
pool_sizes[DESCRIPTOR_TYPE_MUTABLE_EXT_ID].descriptorCount / descriptor->data.descriptor_count;
break;
default:
LOGF(_("Invalid descriptor type provided\n"));
return VULKAN_ERROR_UNKNOWN_DESCRIPTOR_TYPE;
}
if (pool_max_sets == 0 || pool_max_sets > sets_per_type) {
pool_max_sets = sets_per_type;
}
}
/* Allocate pool based on layout */
/* create array of required descriptors */
for (iterator = 0U; iterator < DESCRIPTOR_TYPE_ID_MAX_ENUM; ++iterator) {
if (pool_sizes[iterator].descriptorCount > 0) {
requested_pool_sizes[pool_size_count].type =
pool_sizes[iterator].type;
requested_pool_sizes[pool_size_count].descriptorCount =
pool_sizes[iterator].descriptorCount;
requested_pool_sizes[pool_size_count].type = pool_sizes[iterator].type;
requested_pool_sizes[pool_size_count].descriptorCount = pool_sizes[iterator].descriptorCount;
pool_size_count++;
}
}
@@ -219,10 +298,32 @@ rse_err_t descriptors_build(struct graphics_context_t* context,
pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
pool_create_info.pNext = NULL;
pool_create_info.flags = pool_create_flags;
pool_create_info.maxSets =
0; // FIXME: Calculate number of sets based on layout
pool_create_info.maxSets = pool_max_sets;
pool_create_info.poolSizeCount = pool_size_count;
pool_create_info.pPoolSizes = requested_pool_sizes;
if (VK_SUCCESS != vkCreateDescriptorPool(context->device, &pool_create_info, NULL, &descriptor_pool)) {
LOGF(_("Failed to create descriptor pool\n"));
return VULKAN_ERROR_DESCRIPTOR_POOL_CREATION_FAILED;
}
/* Allocate descriptors from the pool */
alloc_info.descriptorPool = &descriptor_pool;
alloc_info.descriptorSetCount =
pool_max_sets; /* TODO: Always allocating maximum number of sets? This might get weird */
alloc_info.pSetLayouts = set_layout;
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
if (VK_SUCCESS != vkAllocateDescriptorSets(context->device, &alloc_info, &descriptor_sets)) {
LOGF(_("Failed to create descriptor sets\n"));
return VULKAN_ERROR_DESCRIPTOR_SET_CREATION_FAILED;
}
descriptor_set_handle->descriptor_pool = descriptor_pool;
descriptor_set_handle->descriptor_sets = descriptor_sets;
descriptor_set_handle->descriptor_sets_layout = set_layout;
return RSE_ERROR_NO_ERROR;
}
rse_err_t descriptor_get_layouts()
+27 -1
View File
@@ -12,6 +12,32 @@
#ifndef DESCRIPTOR_BUILDER_H
#define DESCRIPTOR_BUILDER_H
struct descriptors_list_t;
struct descriptor_set_handle_t;
struct descriptor_set_list_t;
/**
* @brief Add descriptor set to provided list
*
* @param descriptor_set_list List to be filled
* @param binding Descriptors binding
* @param type Type of descriptors
* @param descriptor_count Number of descriptors in this set
* @param shader_stages In what stages this descriptors will be used
* @param sampler If descriptor set is a sampler, provide it here
* @return rse_err_t RSE_ERROR_NO_ERROR on success, error code on failure
*/
rse_err_t descriptor_add_set(struct descriptor_set_list_t* descriptor_set_list, uint32_t binding, VkDescriptorType type,
uint32_t descriptor_count, VkShaderStageFlags shader_stages, VkSampler sampler);
/**
* @brief Allocate descriptor sets from provided list. The data will be stored in opaque descriptor handle
*
* @param context Graphics context
* @param descriptors List of descriptors to build descriptor handle from.
* @param descriptor_set_handle Opaque descriptor handle object.
* @return rse_err_t RSE_ERROR_NO_ERROR on success, error code on failure
*/
rse_err_t descriptors_build(struct graphics_context_t* context, struct descriptor_set_list_t* descriptors,
struct descriptor_set_handle_t* descriptor_set_handle);
#endif // !DESCRIPTOR_BUILDER_H
+7 -15
View File
@@ -12,15 +12,15 @@
#ifndef GRAPHICS_CONTEXT_H
#define GRAPHICS_CONTEXT_H
#include <GLFW/glfw3.h>
#include <stdbool.h>
#include <stdint.h>
#include <vma/vk_mem_alloc.h>
#include <vulkan/vulkan.h>
#include "utilities/linked_list.h"
#include "vulkan/vulkan_core.h"
#include "vulkan_commons.h"
#include "utilities/linked_list.h"
#include <stdint.h>
#include <stdbool.h>
#include <vulkan/vulkan.h>
#include <vk_mem_alloc.h>
#include <GLFW/glfw3.h>
#define MAX_MESH_NUMBER 256
#define MAX_INSTANCE_NUMBER 256
@@ -31,9 +31,7 @@
*/
#define RSE_MAX_IMAGE_COUNT 256
#define MAX_DESCRIPTOR_SETS 16
#define MAX_PIPELINE_COUNT 16
#define MAX_DESCRIPTOR_POOLS_COUNT (16)
RSE_LINKED_LIST_DEFINE(shader_module_list_t, VkShaderModule);
@@ -89,7 +87,6 @@ struct mesh_t
struct pipeline_internal_t
{
size_t pipelines_count;
size_t descriptor_set_layouts_count;
VkPipeline pipelines[MAX_PIPELINE_COUNT];
VkPipelineLayout pipeline_layout;
};
@@ -102,12 +99,9 @@ struct graphics_context_t
VkInstance instance;
VkQueue graphics_queue;
VmaAllocator allocator;
VkSampler sampler;
VkPhysicalDevice physical_device;
VkCommandPool command_pool;
VkCommandBuffer command_buffers[SWAP_BUFFER_COUNT];
VkDescriptorSet descriptor_sets[SWAP_BUFFER_COUNT];
VkDescriptorSet descriptor_sets_bindless;
VkImageView* swapchain_image_views;
VkExtent2D swapchain_extent;
VkRenderPass render_pass;
@@ -119,8 +113,6 @@ struct graphics_context_t
VkSemaphore image_available_semaphores[SWAP_BUFFER_COUNT];
VkSemaphore render_finished_semaphores[SWAP_BUFFER_COUNT];
VkFence in_flight_fences[SWAP_BUFFER_COUNT];
VkDescriptorPool descriptor_pool;
VkDescriptorPool descriptor_pool_bindless;
struct pipeline_internal_t pipelines_data;
#ifndef NDEBUG
VkDebugUtilsMessengerEXT debug_messenger;
+67 -128
View File
@@ -14,6 +14,7 @@
#include <assert.h>
#include <stdint.h>
#include "descriptor_builder.h"
#include "src/graphics_context.h"
#include "utilities/commons.h"
#include "utilities/errors_common.h"
@@ -27,15 +28,14 @@
#define MAX_BINDLESS_RESOURCES 1000
RSE_LINKED_LIST_DEFINE(vertex_binding_list_t, VkVertexInputBindingDescription);
RSE_LINKED_LIST_DEFINE(shader_attribute_list_t,
VkVertexInputAttributeDescription);
RSE_LINKED_LIST_DEFINE(shader_attribute_list_t, VkVertexInputAttributeDescription);
RSE_LINKED_LIST_DEFINE(dynamic_state_list_t, VkDynamicState);
RSE_LINKED_LIST_DEFINE(pipeline_infos_list_t, VkGraphicsPipelineCreateInfo);
RSE_STACK_DEFINE(required_dynamic_states_t, VkDynamicState, 16U);
struct pipeline_t {
struct pipeline_t
{
VkPipeline pipeline;
uint8_t id;
/* Shader stages */
@@ -66,11 +66,10 @@ struct pipeline_t {
* @param binary_data Shader compiled code
* @return rse_err_t RSE_ERROR_NO_ERROR on success
*/
static rse_err_t create_shader_module(struct graphics_context_t* context,
struct pipeline_t* pipeline,
static rse_err_t create_shader_module(struct graphics_context_t* context, struct pipeline_t* pipeline,
const char* binary_data, size_t data_size)
{
VkShaderModuleCreateInfo create_info = {};
VkShaderModuleCreateInfo create_info = {0};
create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
create_info.pNext = NULL;
@@ -81,8 +80,7 @@ static rse_err_t create_shader_module(struct graphics_context_t* context,
RSE_LINKED_LIST_PUSH_FRONT(context->shader_modules, (VkShaderModule){0});
if (VK_SUCCESS !=
vkCreateShaderModule(context->device, &create_info, NULL,
&RSE_LINKED_LIST_FRONT(context->shader_modules))) {
vkCreateShaderModule(context->device, &create_info, NULL, &RSE_LINKED_LIST_FRONT(context->shader_modules))) {
LOGF(_("Failed to create a shader\n"));
return VULKAN_ERROR_SHADER_CREATION_FAILED;
}
@@ -93,8 +91,7 @@ static rse_err_t create_shader_module(struct graphics_context_t* context,
static rse_err_t pipeline_add_input_assembly(struct pipeline_t* pipeline)
{
/* For now input assebly is hardcoded */
pipeline->input_assembly.sType =
VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
pipeline->input_assembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
pipeline->input_assembly.pNext = NULL;
pipeline->input_assembly.flags = 0U;
pipeline->input_assembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
@@ -106,27 +103,20 @@ static rse_err_t pipeline_add_input_assembly(struct pipeline_t* pipeline)
static rse_err_t pipeline_add_viewport_state(struct pipeline_t* pipeline)
{
/* For now viewport is hardcoded */
pipeline->viewport_state.sType =
VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
pipeline->viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
pipeline->viewport_state.pNext = NULL;
pipeline->viewport_state.flags = 0U;
pipeline->viewport_state.viewportCount = 1U;
pipeline->viewport_state.pViewports =
NULL; /* This is set during rendering */
pipeline->viewport_state.pViewports = NULL; /* This is set during rendering */
pipeline->viewport_state.scissorCount = 1U;
pipeline->viewport_state.pScissors =
NULL; /* This is set during rendering */
pipeline->viewport_state.pScissors = NULL; /* This is set during rendering */
if (pipeline->viewport_state.pViewports == NULL ||
pipeline->viewport_state.viewportCount == 0U) {
RSE_STACK_PUSH(pipeline->required_dynamic_states,
VK_DYNAMIC_STATE_VIEWPORT);
if (pipeline->viewport_state.pViewports == NULL || pipeline->viewport_state.viewportCount == 0U) {
RSE_STACK_PUSH(pipeline->required_dynamic_states, VK_DYNAMIC_STATE_VIEWPORT);
}
if (pipeline->viewport_state.pScissors == NULL ||
pipeline->viewport_state.scissorCount == 0U) {
RSE_STACK_PUSH(pipeline->required_dynamic_states,
VK_DYNAMIC_STATE_SCISSOR);
if (pipeline->viewport_state.pScissors == NULL || pipeline->viewport_state.scissorCount == 0U) {
RSE_STACK_PUSH(pipeline->required_dynamic_states, VK_DYNAMIC_STATE_SCISSOR);
}
return RSE_ERROR_NO_ERROR;
@@ -135,14 +125,11 @@ static rse_err_t pipeline_add_viewport_state(struct pipeline_t* pipeline)
static rse_err_t pipeline_add_rasterizer(struct pipeline_t* pipeline)
{
/* For now rasterizer is hardcoded */
pipeline->rasterizer.sType =
VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
pipeline->rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
pipeline->rasterizer.pNext = NULL;
pipeline->rasterizer.flags = 0U;
pipeline->rasterizer.depthClampEnable =
VK_FALSE; /* VK_TRUE to play with shadow maps */
pipeline->rasterizer.rasterizerDiscardEnable =
VK_FALSE; /* Disable/Enable output to framebuffer*/
pipeline->rasterizer.depthClampEnable = VK_FALSE; /* VK_TRUE to play with shadow maps */
pipeline->rasterizer.rasterizerDiscardEnable = VK_FALSE; /* Disable/Enable output to framebuffer*/
pipeline->rasterizer.polygonMode = VK_POLYGON_MODE_FILL;
pipeline->rasterizer.cullMode = VK_CULL_MODE_BACK_BIT;
pipeline->rasterizer.frontFace = VK_FRONT_FACE_CLOCKWISE;
@@ -158,8 +145,7 @@ static rse_err_t pipeline_add_rasterizer(struct pipeline_t* pipeline)
static rse_err_t pipeline_add_multisampling(struct pipeline_t* pipeline)
{
/* For now multisampling is hardcoded */
pipeline->multisampling.sType =
VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
pipeline->multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
pipeline->multisampling.pNext = NULL;
pipeline->multisampling.flags = 0U;
pipeline->multisampling.rasterizationSamples = VK_SAMPLE_COUNT_8_BIT;
@@ -176,20 +162,16 @@ static rse_err_t pipeline_add_color_blending(struct pipeline_t* pipeline)
{
/* For now color blending is hardcoded */
pipeline->color_blend_attachment.colorWriteMask =
VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT |
VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
pipeline->color_blend_attachment.blendEnable = VK_TRUE;
pipeline->color_blend_attachment.srcColorBlendFactor =
VK_BLEND_FACTOR_SRC_ALPHA;
pipeline->color_blend_attachment.dstColorBlendFactor =
VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
pipeline->color_blend_attachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
pipeline->color_blend_attachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
pipeline->color_blend_attachment.colorBlendOp = VK_BLEND_OP_ADD;
pipeline->color_blend_attachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
pipeline->color_blend_attachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
pipeline->color_blend_attachment.alphaBlendOp = VK_BLEND_OP_ADD;
pipeline->color_blending.sType =
VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
pipeline->color_blending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
pipeline->color_blending.pNext = NULL;
pipeline->color_blending.flags = 0U;
pipeline->color_blending.logicOpEnable = VK_FALSE;
@@ -207,8 +189,7 @@ static rse_err_t pipeline_add_color_blending(struct pipeline_t* pipeline)
static rse_err_t pipeline_add_depth_stencil(struct pipeline_t* pipeline)
{
/* For now depth stencil is hardcoded */
pipeline->depth_stencil.sType =
VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
pipeline->depth_stencil.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
pipeline->depth_stencil.pNext = NULL;
pipeline->depth_stencil.flags = 0U;
pipeline->depth_stencil.depthTestEnable = VK_TRUE;
@@ -228,21 +209,23 @@ static rse_err_t pipeline_add_depth_stencil(struct pipeline_t* pipeline)
* @return rse_err_t RSE_ERROR_NO_ERROR on success. Possible errors:
* VULKAN_ERROR_PIPELINE_LAYOUT_CREATION_FAILED
*/
static rse_err_t create_pipeline_layout(struct graphics_context_t* context)
static rse_err_t create_pipeline_layout(struct graphics_context_t* context,
struct descriptors_set_handle_t* descriptor_set_handle)
{
VkPipelineLayoutCreateInfo create_info = {};
uint32_t descriptor_set_layouts_count = 0;
VkDescriptorSetLayout descriptor_set_layouts = VK_NULL_HANDLE;
VkPipelineLayoutCreateInfo create_info = {0};
create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
create_info.pNext = NULL;
create_info.flags = 0U;
create_info.setLayoutCount =
context->pipelines_data.descriptor_set_layouts_count;
create_info.setLayoutCount = context->pipelines_data.descriptor_set_layouts_count;
create_info.pSetLayouts = context->pipelines_data.descriptor_set_layouts;
create_info.pushConstantRangeCount = 0U;
create_info.pPushConstantRanges = NULL;
if (VK_SUCCESS !=
vkCreatePipelineLayout(context->device, &create_info, NULL,
&context->pipelines_data.pipeline_layout)) {
vkCreatePipelineLayout(context->device, &create_info, NULL, &context->pipelines_data.pipeline_layout)) {
LOGF(_("Failed to create pipeline layout\n"));
return VULKAN_ERROR_PIPELINE_LAYOUT_CREATION_FAILED;
}
@@ -265,24 +248,18 @@ static void pipeline_builder_cleanup(struct pipeline_infos_list_t* pipelines)
VkDynamicState* dynamic_states = NULL;
for (size_t i = 0; i < pipeline_count; i++) {
VkGraphicsPipelineCreateInfo* pipeline_info =
&RSE_LINKED_LIST_FRONT(pipelines);
VkGraphicsPipelineCreateInfo* pipeline_info = &RSE_LINKED_LIST_FRONT(pipelines);
if (pipeline_info != NULL) {
vertex_bindings =
(VkVertexInputBindingDescription*)pipeline_info
->pVertexInputState->pVertexBindingDescriptions;
(VkVertexInputBindingDescription*)pipeline_info->pVertexInputState->pVertexBindingDescriptions;
shader_attributes =
(VkVertexInputAttributeDescription*)pipeline_info
->pVertexInputState->pVertexAttributeDescriptions;
(VkVertexInputAttributeDescription*)pipeline_info->pVertexInputState->pVertexAttributeDescriptions;
dynamic_states =
(VkDynamicState*)pipeline_info->pDynamicState->pDynamicStates;
dynamic_states = (VkDynamicState*)pipeline_info->pDynamicState->pDynamicStates;
rse_free((VkPipelineVertexInputStateCreateInfo*)
pipeline_info->pVertexInputState);
rse_free((VkPipelineDynamicStateCreateInfo*)
pipeline_info->pDynamicState);
rse_free((VkPipelineVertexInputStateCreateInfo*)pipeline_info->pVertexInputState);
rse_free((VkPipelineDynamicStateCreateInfo*)pipeline_info->pDynamicState);
rse_free(vertex_bindings);
rse_free(shader_attributes);
rse_free(dynamic_states);
@@ -295,8 +272,7 @@ static void pipeline_builder_cleanup(struct pipeline_infos_list_t* pipelines)
}
}
rse_err_t pipeline_add_dynamic_state(struct pipeline_t* pipeline,
VkDynamicState dynamic_state)
rse_err_t pipeline_add_dynamic_state(struct pipeline_t* pipeline, VkDynamicState dynamic_state)
{
if (dynamic_state >= VK_DYNAMIC_STATE_MAX_ENUM) {
LOGF(_("Invalid dynamic state in pipeline\n"));
@@ -327,10 +303,8 @@ rse_err_t pipeline_builder_init(struct pipeline_t** pipeline)
return status;
}
rse_err_t pipeline_add_shader_stage(struct graphics_context_t* context,
struct pipeline_t* pipeline,
const char* shader_path,
const VkShaderStageFlagBits shader_stage)
rse_err_t pipeline_add_shader_stage(struct graphics_context_t* context, struct pipeline_t* pipeline,
const char* shader_path, const VkShaderStageFlagBits shader_stage)
{
size_t i = 0;
rse_err_t status = RSE_ERROR_NO_ERROR;
@@ -359,26 +333,22 @@ rse_err_t pipeline_add_shader_stage(struct graphics_context_t* context,
STATUS_CHECK(create_shader_module(context, pipeline, buffer, buffer_size));
free(buffer);
pipeline->shader_stages[i].sType =
VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
pipeline->shader_stages[i].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
pipeline->shader_stages[i].pNext = NULL;
pipeline->shader_stages[i].flags = 0U;
pipeline->shader_stages[i].stage = shader_stage;
pipeline->shader_stages[i].module = RSE_LINKED_LIST_FRONT(
context->shader_modules); /* This is automatically updated during
shader module creation */
pipeline->shader_stages[i].module = RSE_LINKED_LIST_FRONT(context->shader_modules); /* This is automatically updated
during shader module creation */
pipeline->shader_stages[i].pName = "main";
pipeline->shader_stages[i].pSpecializationInfo = NULL;
return status;
}
rse_err_t pipeline_add_vertex_input_binding(struct pipeline_t* pipeline,
const uint8_t binding,
const uint8_t stride,
rse_err_t pipeline_add_vertex_input_binding(struct pipeline_t* pipeline, const uint8_t binding, const uint8_t stride,
const VkVertexInputRate input_rate)
{
VkVertexInputBindingDescription binding_pipeline_description = {};
VkVertexInputBindingDescription binding_pipeline_description = {0};
if (input_rate >= VK_VERTEX_INPUT_RATE_MAX_ENUM) {
LOGF(_("Invalid vertex input rate\n"));
return VULKAN_ERROR_PIPELINE_INVALID_VERTEX_INPUT_RATE;
@@ -388,18 +358,14 @@ rse_err_t pipeline_add_vertex_input_binding(struct pipeline_t* pipeline,
binding_pipeline_description.stride = stride;
binding_pipeline_description.inputRate = input_rate;
RSE_LINKED_LIST_PUSH_FRONT(pipeline->vertex_bindings,
binding_pipeline_description);
RSE_LINKED_LIST_PUSH_FRONT(pipeline->vertex_bindings, binding_pipeline_description);
return RSE_ERROR_NO_ERROR;
}
rse_err_t pipeline_add_vertex_input_attribute(struct pipeline_t* pipeline,
const uint8_t binding,
const uint8_t location,
const VkFormat format,
const uint8_t offset)
rse_err_t pipeline_add_vertex_input_attribute(struct pipeline_t* pipeline, const uint8_t binding,
const uint8_t location, const VkFormat format, const uint8_t offset)
{
VkVertexInputAttributeDescription attribute_description = {};
VkVertexInputAttributeDescription attribute_description = {0};
if (binding >= 16U) {
LOGF(_("Invalid binding in pipeline attribute description\n"));
return VULKAN_ERROR_PIPELINE_INVALID_BINDING;
@@ -414,14 +380,12 @@ rse_err_t pipeline_add_vertex_input_attribute(struct pipeline_t* pipeline,
attribute_description.format = format;
attribute_description.offset = offset;
RSE_LINKED_LIST_PUSH_FRONT(pipeline->shader_attributes,
attribute_description);
RSE_LINKED_LIST_PUSH_FRONT(pipeline->shader_attributes, attribute_description);
return RSE_ERROR_NO_ERROR;
}
rse_err_t pipelines_build(struct graphics_context_t* context,
struct pipeline_infos_list_t* pipelines_infos_list)
rse_err_t pipelines_build(struct graphics_context_t* context, struct pipeline_infos_list_t* pipelines_infos_list)
{
assert(NULL != context);
assert(NULL != pipelines_infos_list);
@@ -435,8 +399,7 @@ rse_err_t pipelines_build(struct graphics_context_t* context,
STATUS_CHECK(create_pipeline_layout(context));
rse_malloc(pipeline_infos,
sizeof(VkGraphicsPipelineCreateInfo) * pipelines_count);
rse_malloc(pipeline_infos, sizeof(VkGraphicsPipelineCreateInfo) * pipelines_count);
RSE_LINKED_LIST_TO_ARRAY(pipelines_infos_list, pipeline_infos);
@@ -446,9 +409,7 @@ rse_err_t pipelines_build(struct graphics_context_t* context,
pipeline_infos[i].layout = context->pipelines_data.pipeline_layout;
}
if (VK_SUCCESS !=
vkCreateGraphicsPipelines(context->device, VK_NULL_HANDLE,
pipelines_count, pipeline_infos, NULL,
if (VK_SUCCESS != vkCreateGraphicsPipelines(context->device, VK_NULL_HANDLE, pipelines_count, pipeline_infos, NULL,
context->pipelines_data.pipelines)) {
LOGF(_("Failed to create graphics pipelines\n"));
status = VULKAN_ERROR_GRAPHICSPIPELINE_CREATION_FAILED;
@@ -460,13 +421,12 @@ rse_err_t pipelines_build(struct graphics_context_t* context,
return status;
}
rse_err_t add_pipeline(const struct graphics_context_t* context,
struct pipeline_t* pipeline,
rse_err_t add_pipeline(const struct graphics_context_t* context, struct pipeline_t* pipeline,
struct pipeline_infos_list_t** pipelines_infos)
{
/* Check for send and required dynamic states */
rse_err_t status = RSE_ERROR_NO_ERROR;
VkGraphicsPipelineCreateInfo pipeline_info = {};
VkGraphicsPipelineCreateInfo pipeline_info = {0};
size_t vertex_bindings_count = 0U;
VkVertexInputBindingDescription* vertex_bindings = NULL;
@@ -483,8 +443,7 @@ rse_err_t add_pipeline(const struct graphics_context_t* context,
while (RSE_STACK_IS_EMPTY(pipeline->required_dynamic_states) == 0) {
dynamic_state_found = 0;
VkDynamicState dynamic_state =
RSE_STACK_POP(pipeline->required_dynamic_states);
VkDynamicState dynamic_state = RSE_STACK_POP(pipeline->required_dynamic_states);
RSE_LINKED_LIST_FOREACH(pipeline->dynamic_states, dynamic_state_ptr)
{
if (dynamic_state_ptr->data == dynamic_state) {
@@ -525,12 +484,9 @@ rse_err_t add_pipeline(const struct graphics_context_t* context,
}
/* Convert linked list to array */
vertex_bindings_count =
RSE_LINKED_LIST_TO_ARRAY(pipeline->vertex_bindings, vertex_bindings);
shader_attributes_count = RSE_LINKED_LIST_TO_ARRAY(
pipeline->shader_attributes, shader_attributes);
dynamic_states_count =
RSE_LINKED_LIST_TO_ARRAY(pipeline->dynamic_states, dynamic_states);
vertex_bindings_count = RSE_LINKED_LIST_TO_ARRAY(pipeline->vertex_bindings, vertex_bindings);
shader_attributes_count = RSE_LINKED_LIST_TO_ARRAY(pipeline->shader_attributes, shader_attributes);
dynamic_states_count = RSE_LINKED_LIST_TO_ARRAY(pipeline->dynamic_states, dynamic_states);
/* Build constant pipeline. TODO: Some parts may be customizable */
pipeline_add_input_assembly(pipeline);
@@ -546,16 +502,13 @@ rse_err_t add_pipeline(const struct graphics_context_t* context,
pipeline_info.stageCount = pipeline->shader_stages_count;
pipeline_info.pStages = pipeline->shader_stages;
rse_malloc(vertex_bindings_ci,
sizeof(VkPipelineVertexInputStateCreateInfo));
vertex_bindings_ci->sType =
VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
rse_malloc(vertex_bindings_ci, sizeof(VkPipelineVertexInputStateCreateInfo));
vertex_bindings_ci->sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
vertex_bindings_ci->pNext = NULL;
vertex_bindings_ci->flags = 0U;
vertex_bindings_ci->vertexBindingDescriptionCount = vertex_bindings_count;
vertex_bindings_ci->pVertexBindingDescriptions = vertex_bindings;
vertex_bindings_ci->vertexAttributeDescriptionCount =
shader_attributes_count;
vertex_bindings_ci->vertexAttributeDescriptionCount = shader_attributes_count;
vertex_bindings_ci->pVertexAttributeDescriptions = shader_attributes;
pipeline_info.pVertexInputState = vertex_bindings_ci;
@@ -568,8 +521,7 @@ rse_err_t add_pipeline(const struct graphics_context_t* context,
pipeline_info.pColorBlendState = &pipeline->color_blending;
rse_malloc(dynamic_states_ci, sizeof(VkPipelineDynamicStateCreateInfo));
dynamic_states_ci->sType =
VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
dynamic_states_ci->sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
dynamic_states_ci->pNext = NULL;
dynamic_states_ci->flags = 0U;
dynamic_states_ci->dynamicStateCount = dynamic_states_count;
@@ -579,8 +531,7 @@ rse_err_t add_pipeline(const struct graphics_context_t* context,
pipeline_info.layout = context->pipelines_data.pipeline_layout;
pipeline_info.renderPass = context->render_pass;
pipeline_info.subpass = 0;
pipeline_info.basePipelineHandle =
VK_NULL_HANDLE; // TODO: Add possiblity do derive from another pipeline
pipeline_info.basePipelineHandle = VK_NULL_HANDLE; // TODO: Add possiblity do derive from another pipeline
pipeline_info.basePipelineIndex = -1;
RSE_LINKED_LIST_PUSH_BACK(*pipelines_infos, pipeline_info);
@@ -594,25 +545,13 @@ void destroy_pipelines(struct graphics_context_t* context)
for (i = 0; i < context->pipelines_data.pipelines_count; i++) {
if (context->pipelines_data.pipelines[i] != VK_NULL_HANDLE) {
vkDestroyPipeline(context->device,
context->pipelines_data.pipelines[i], NULL);
}
}
for (i = 0; i < context->pipelines_data.descriptor_set_layouts_count; i++) {
if (context->pipelines_data.descriptor_set_layouts[i] !=
VK_NULL_HANDLE) {
vkDestroyDescriptorSetLayout(
context->device,
context->pipelines_data.descriptor_set_layouts[i], NULL);
vkDestroyPipeline(context->device, context->pipelines_data.pipelines[i], NULL);
}
}
for (i = 0; i < shader_modules_count; i++) {
if (RSE_LINKED_LIST_FRONT(context->shader_modules) != VK_NULL_HANDLE) {
vkDestroyShaderModule(
context->device, RSE_LINKED_LIST_FRONT(context->shader_modules),
NULL);
vkDestroyShaderModule(context->device, RSE_LINKED_LIST_FRONT(context->shader_modules), NULL);
}
RSE_LINKED_LIST_POP_FRONT(context->shader_modules);
}
+9 -34
View File
@@ -14,6 +14,7 @@
#include <vulkan/vulkan.h>
#include <vulkan/vulkan_core.h>
#include "graphics_context.h"
#include "utilities/commons.h"
#include "utilities/linked_list.h"
@@ -41,7 +42,8 @@ rse_err_t pipeline_builder_init(struct pipeline_t** pipeline);
* @param[in] shader_stage Shader stage to add
* @return RSE_SUCCESS on success, error code otherwise
*/
rse_err_t pipeline_add_shader_stage(struct graphics_context_t* context, struct pipeline_t* pipeline, const char* shader_path, const VkShaderStageFlagBits shader_stage);
rse_err_t pipeline_add_shader_stage(struct graphics_context_t* context, struct pipeline_t* pipeline,
const char* shader_path, const VkShaderStageFlagBits shader_stage);
/**
* @brief Add vertex input binding to pipeline
@@ -66,9 +68,7 @@ rse_err_t pipeline_add_vertex_input_binding(struct pipeline_t* pipeline, const u
* @return RSE_SUCCESS on success, error code otherwise
*/
rse_err_t pipeline_add_vertex_input_attribute(struct pipeline_t* pipeline, const uint8_t binding,
const uint8_t location,
const VkFormat format,
const uint8_t offset);
const uint8_t location, const VkFormat format, const uint8_t offset);
/**
* @brief Add dynamic state to pipeline
@@ -80,40 +80,14 @@ rse_err_t pipeline_add_vertex_input_attribute(struct pipeline_t* pipeline, const
rse_err_t pipeline_add_dynamic_state(struct pipeline_t* pipeline, const VkDynamicState dynamic_state);
/**
* @brief Add descriptor pool
*
* @param[in] context Graphics context handle
* @param[in] pipeline Pipeline to add descriptor pool to
* @param[in] descriptor_type Type of descriptors to be stored in this pool.
* @return RSE_SUCCESS on success, error code otherwise
*/
rse_err_t pipeline_add_descriptor_pool(struct graphics_context_t* context,
struct pipeline_t* pipeline,
enum VkDescriptorType descriptor_type);
/**
* @brief Add required dynamic state to pipeline
*
* @param[in] context Graphics context handle
* @param[in] binding_infos Binding infos to add
* @param[in] binding_count Number of binding infos
* @param[out] descriptor_set_index Index of descriptor set
* @return RSE_SUCCESS on success, error code otherwise
*/
rse_err_t pipeline_add_descriptor_layout(struct graphics_context_t* context,
struct binding_info_t* binding_infos,
size_t binding_count,
size_t* descriptor_set_index);
/**
* @brief Build pipeline from added components. This function should be called after adding all necessary components. After call, pipeline is ready to be used and all added components are cleared, ready for next pipeline to be built.
* @brief Build pipeline from added components. This function should be called after adding all necessary components.
* After call, pipeline is ready to be used and all added components are cleared, ready for next pipeline to be built.
*
* param[in/out] context Graphics context handle
* @param[in] pipeline Pipelines list to build
* @return RSE_SUCCESS on success, error code otherwise
*/
rse_err_t pipelines_build(struct graphics_context_t* context,
struct pipeline_infos_list_t* pipelines);
rse_err_t pipelines_build(struct graphics_context_t* context, struct pipeline_infos_list_t* pipelines);
/**
* @brief Add pipeline to list of pipelines
@@ -123,7 +97,8 @@ rse_err_t pipelines_build(struct graphics_context_t* context,
* @param[out] pipeline_info List of pipelines infos, where new info should be added
* @return RSE_SUCCESS on success, error code otherwise
*/
rse_err_t add_pipeline(const struct graphics_context_t* context, struct pipeline_t* pipeline, struct pipeline_infos_list_t** pipelines);
rse_err_t add_pipeline(const struct graphics_context_t* context, struct pipeline_t* pipeline,
struct pipeline_infos_list_t** pipelines);
/**
* @brief Destroy all pipelines
+35 -42
View File
@@ -1,19 +1,20 @@
#include "rse_graphics.h"
#include "utilities/localization.h"
#include "window.h"
#include "vulkan_base.h"
#include "descriptor_builder.h"
#include "graphics_context.h"
#include "math.h"
#include "mesh_controller.h"
#include "vulkan_commons.h"
#include "pipeline_builder.h"
#include "utilities/logger.h"
#include "utilities/commons.h"
#include "utilities/errors_common.h"
#include "graphics_context.h"
#include "utilities/localization.h"
#include "utilities/logger.h"
#include "vulkan_base.h"
#include "vulkan_commons.h"
#include "window.h"
#include "math.h"
struct rse_graphics_context_t {
struct rse_graphics_context_t
{
struct graphics_context_t* context;
};
@@ -46,7 +47,8 @@ void rse_graphics_test_function(struct rse_graphics_context_t* rse_context)
size_t ubo_index = 0;
size_t sampler_index = 0;
struct pipeline_t* pipeline = NULL;
struct binding_info_t binding_infos[2] = {0};
struct descriptor_set_list_t* descriptor_set_list;
struct descriptor_set_handle_t* descriptor_set_handle;
struct pipeline_infos_list_t* pipeline_infos = NULL;
// status = load_texture_from_file("../../test_image.jpg", &tex_id_2);
@@ -71,27 +73,18 @@ void rse_graphics_test_function(struct rse_graphics_context_t* rse_context)
uint16_t indices[] = {0, 1, 2, 2, 3, 0};
uint16_t mesh_id = create_mesh(context, vertices, indices, 6, 6);
create_mesh_instance(context, mesh_id, (struct instance_data_t){
{0.0f, 0.0f, 2.4f},
{0.0f, 0.0f, math_deg_to_radians(45.0f)},
1.0f,
tex_id_2
});
create_mesh_instance(
context, mesh_id,
(struct instance_data_t){{0.0f, 0.0f, 2.4f}, {0.0f, 0.0f, math_deg_to_radians(45.0f)}, 1.0f, tex_id_2});
create_mesh_instance(context, mesh_id, (struct instance_data_t){
{-0.5f, 0.0f, -1.0f},
{0.0f, 0.0f, math_deg_to_radians(10.0f)},
1.0f,
tex_id_2
});
create_mesh_instance(
context, mesh_id,
(struct instance_data_t){{-0.5f, 0.0f, -1.0f}, {0.0f, 0.0f, math_deg_to_radians(10.0f)}, 1.0f, tex_id_2});
mesh_id = create_mesh(context, vertices2, indices, 6, 6);
create_mesh_instance(context, mesh_id, (struct instance_data_t){
{2.0f, 1.0f, 0.0f},
{0.0f, 0.0f, math_deg_to_radians(0.0f)},
1.0f,
tex_id_2
});
create_mesh_instance(
context, mesh_id,
(struct instance_data_t){{2.0f, 1.0f, 0.0f}, {0.0f, 0.0f, math_deg_to_radians(0.0f)}, 1.0f, tex_id_2});
// fonts_load_from_file("/usr/share/fonts/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-Medium.ttf");
// print_text("Hello World!", (struct vec3_t){-1.0f, 0.0f, 0.9f}, 0.3f);
@@ -100,7 +93,8 @@ void rse_graphics_test_function(struct rse_graphics_context_t* rse_context)
pipeline_builder_init(&pipeline);
pipeline_add_shader_stage(context, pipeline, "../graphics/shaders/shader.vert.num", VK_SHADER_STAGE_VERTEX_BIT);
pipeline_add_shader_stage(context, pipeline, "../graphics/shaders/solid_objects.frag.num", VK_SHADER_STAGE_FRAGMENT_BIT);
pipeline_add_shader_stage(context, pipeline, "../graphics/shaders/solid_objects.frag.num",
VK_SHADER_STAGE_FRAGMENT_BIT);
pipeline_add_vertex_input_binding(pipeline, 0, sizeof(struct vertex_t), VK_VERTEX_INPUT_RATE_VERTEX);
pipeline_add_vertex_input_binding(pipeline, 1, sizeof(struct vertex_t), VK_VERTEX_INPUT_RATE_INSTANCE);
@@ -108,27 +102,26 @@ void rse_graphics_test_function(struct rse_graphics_context_t* rse_context)
pipeline_add_vertex_input_attribute(pipeline, 0, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(struct vertex_t, pos));
pipeline_add_vertex_input_attribute(pipeline, 0, 1, VK_FORMAT_R32G32B32_SFLOAT, offsetof(struct vertex_t, color));
pipeline_add_vertex_input_attribute(pipeline, 0, 2, VK_FORMAT_R32G32_SFLOAT, offsetof(struct vertex_t, tex_coords));
pipeline_add_vertex_input_attribute(pipeline, 1, 3, VK_FORMAT_R32G32B32_SFLOAT, offsetof(struct instance_data_t, pos));
pipeline_add_vertex_input_attribute(pipeline, 1, 4, VK_FORMAT_R32G32B32_SFLOAT, offsetof(struct instance_data_t, rot));
pipeline_add_vertex_input_attribute(pipeline, 1, 3, VK_FORMAT_R32G32B32_SFLOAT,
offsetof(struct instance_data_t, pos));
pipeline_add_vertex_input_attribute(pipeline, 1, 4, VK_FORMAT_R32G32B32_SFLOAT,
offsetof(struct instance_data_t, rot));
pipeline_add_vertex_input_attribute(pipeline, 1, 5, VK_FORMAT_R32_SFLOAT, offsetof(struct instance_data_t, scale));
pipeline_add_vertex_input_attribute(pipeline, 1, 6, VK_FORMAT_R32_UINT, offsetof(struct instance_data_t, texture_id));
pipeline_add_vertex_input_attribute(pipeline, 1, 6, VK_FORMAT_R32_UINT,
offsetof(struct instance_data_t, texture_id));
pipeline_add_dynamic_state(pipeline, VK_DYNAMIC_STATE_VIEWPORT);
pipeline_add_dynamic_state(pipeline, VK_DYNAMIC_STATE_SCISSOR);
binding_infos[0].binding = 0;
binding_infos[0].descriptor_type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
binding_infos[0].stage_flags = VK_SHADER_STAGE_VERTEX_BIT;
VkSampler sampler = VK_NULL_HANDLE;
binding_infos[1].binding = 1;
binding_infos[1].descriptor_type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
binding_infos[1].stage_flags = VK_SHADER_STAGE_FRAGMENT_BIT;
create_sampler(context, sampler);
pipeline_add_descriptor_pool(context, pipeline, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
pipeline_add_descriptor_pool(context, pipeline, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER);
descriptor_add_set(descriptor_set_list, 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, VK_SHADER_STAGE_VERTEX_BIT, NULL);
descriptor_add_set(descriptor_set_list, 1, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1,
VK_SHADER_STAGE_FRAGMENT_BIT, sampler);
pipeline_add_descriptor_layout(context, &binding_infos[0], 1, &ubo_index);
pipeline_add_descriptor_layout(context, &binding_infos[1], 1, &sampler_index);
descriptors_build(context, descriptor_set_list, descriptor_set_handle);
add_pipeline(context, pipeline, &pipeline_infos);
+5 -1
View File
@@ -11,6 +11,7 @@
/* VMA allows C linkage, but it must be compiled as a CPP file. This file takes cares of it */
#define VMA_IMPLEMENTATION
#ifdef __unix__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
@@ -20,6 +21,9 @@
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
#pragma GCC diagnostic ignored "-Wswitch"
#pragma GCC diagnostic ignored "-Wparentheses"
#endif
#include <cstdio>
#include "vk_mem_alloc.h"
#include "vma/vk_mem_alloc.h"
#ifdef __unix__
#pragma GCC diagnostic pop
#endif
+19 -27
View File
@@ -12,20 +12,8 @@
#include "vulkan_base.h"
#include <GLFW/glfw3.h>
/* We are building with -Werror flag on, but there are some warning in VMA implementation. Thus diagnostic push */
// #pragma GCC diagnostic push
// #pragma GCC diagnostic ignored "-Wunused-function"
// #pragma GCC diagnostic ignored "-Wunused-variable"
// #pragma GCC diagnostic ignored "-Wpedantic"
// #pragma GCC diagnostic ignored "-Wignored-qualifiers"
// #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
// #pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
// #pragma GCC diagnostic ignored "-Wswitch"
// #pragma GCC diagnostic ignored "-Wparentheses"
#include "utilities/localization.h"
#include "vk_mem_alloc.h"
// #pragma GCC diagnostic pop
#include <vma/vk_mem_alloc.h>
#include "utilities/commons.h"
#include "utilities/errors_common.h"
@@ -363,19 +351,21 @@ static rse_err_t pick_physical_device(VkInstance instance, VkPhysicalDevice* phy
*/
static rse_err_t create_device(struct graphics_context_t* context)
{
size_t device_queues_count = 0;
uint32_t queue_families_property_count = 0U;
ssize_t graphics_family_idx = -1;
ssize_t presentation_familiy_idx = -1;
VkQueueFamilyProperties* queue_family_properties = NULL;
VkDeviceCreateInfo device_create_info = {0};
VkDeviceQueueCreateInfo device_queue_createinfos[2] = {0};
bool graphics_family_found = false;
bool presentation_familiy_found = false;
float* graphics_familiy_queue_priorities = NULL;
float* presentation_familiy_queue_priorities = NULL;
uint32_t device_queues_count = 0;
uint32_t graphics_family_idx = 0;
uint32_t presentation_familiy_idx = 0;
uint32_t queue_families_property_count = 0U;
uint32_t enabled_device_extensions_count = 2;
VkBool32 bindless_supported = VK_FALSE;
VkDeviceCreateInfo device_create_info = {0};
VkQueueFamilyProperties* queue_family_properties = NULL;
VkDeviceQueueCreateInfo device_queue_createinfos[2] = {0};
VkPhysicalDeviceFeatures2 physical_features2 = {0};
VkPhysicalDeviceDescriptorIndexingFeatures indexing_features = {0};
VkBool32 bindless_supported = VK_FALSE;
uint32_t enabled_device_extensions_count = 2;
const char* enabled_device_extensions_names[] = {
"VK_KHR_swapchain",
"VK_EXT_descriptor_indexing",
@@ -405,12 +395,13 @@ static rse_err_t create_device(struct graphics_context_t* context)
* queues. */
{
size_t numberOfQueues = 0;
for (size_t familyIdx = 0; familyIdx < queue_families_property_count; ++familyIdx) {
for (uint32_t familyIdx = 0; familyIdx < queue_families_property_count; ++familyIdx) {
LOGI("Checking queue: %ld", familyIdx);
if (queue_family_properties[familyIdx].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
if (queue_family_properties[familyIdx].queueCount > numberOfQueues) {
graphics_family_idx = familyIdx;
LOGI("Setting graphics family idx to %d", familyIdx);
graphics_family_found = true;
LOGI("Setting graphics family idx to %ld", familyIdx);
numberOfQueues = queue_family_properties[familyIdx].queueCount;
device_queues_count++;
}
@@ -421,13 +412,14 @@ static rse_err_t create_device(struct graphics_context_t* context)
vkGetPhysicalDeviceSurfaceSupportKHR(context->physical_device, familyIdx, context->surface, &presentSupport);
if (presentSupport) {
presentation_familiy_idx = familyIdx;
presentation_familiy_found = true;
/* If this is the same queue family as in graphics family, don't increase queue count */
if (presentation_familiy_idx != graphics_family_idx) {
device_queues_count++;
}
}
if (graphics_family_idx > 0 && presentation_familiy_idx > 0) {
if (graphics_family_found && presentation_familiy_found) {
break;
}
}
@@ -529,10 +521,10 @@ static rse_err_t create_memory_allocator(struct graphics_context_t* context)
*/
static rse_err_t create_sync_objects(struct graphics_context_t* context)
{
VkSemaphoreCreateInfo semaphore_info = {};
VkSemaphoreCreateInfo semaphore_info = {0};
semaphore_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
VkFenceCreateInfo fenceInfo = {};
VkFenceCreateInfo fenceInfo = {0};
fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
+4 -4
View File
@@ -26,7 +26,7 @@
static void copy_buffer(struct graphics_context_t* context, VkBuffer src, VkBuffer dst, VkDeviceSize size, VkDeviceSize dest_offset)
{
/* Vulkan buffers can only be copied using command buffers */
VkBufferCopy copy_region = {};
VkBufferCopy copy_region = {0};
VkCommandBuffer command_buffer = {0};
command_buffer = begin_single_time_command(context);
@@ -152,8 +152,8 @@ rse_err_t create_buffer(struct graphics_context_t* context, const VkDeviceSize s
const VmaAllocationCreateFlags allocation_flags,
struct vulkan_buffer_t* buffer)
{
VkBufferCreateInfo vertex_buffer_info = {};
VmaAllocationCreateInfo create_info = {};
VkBufferCreateInfo vertex_buffer_info = {0};
VmaAllocationCreateInfo create_info = {0};
vertex_buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
vertex_buffer_info.pNext = NULL;
@@ -194,7 +194,7 @@ void destroy_buffer(struct graphics_context_t* context, struct vulkan_buffer_t*
void update_uniform_buffers(struct graphics_context_t* context)
{
struct uniform_buffer_object_t ubo = {};
struct uniform_buffer_object_t ubo = {0};
struct vec3_t eye = {0};
struct vec3_t center = {0};
struct vec3_t up = {0};
+1 -1
View File
@@ -5,7 +5,7 @@
#include "utilities/commons.h"
#include "graphics_context.h"
#include "vk_mem_alloc.h"
#include <vma/vk_mem_alloc.h>
#include <stdint.h>
+2 -1
View File
@@ -12,7 +12,8 @@
#ifndef VULKAN_COMMANDS_H
#define VULKAN_COMMANDS_H
#include "vk_mem_alloc.h"
#include <vma/vk_mem_alloc.h>
#include "utilities/commons.h"
#include "graphics_context.h"
+1 -1
View File
@@ -15,7 +15,7 @@
#include "math.h"
#include <vulkan/vulkan.h>
#include <vk_mem_alloc.h>
#include <vma/vk_mem_alloc.h>
#include <stdalign.h>
+3
View File
@@ -57,6 +57,9 @@ enum vulkan_error_t
VULKAN_ERROR_DRAW_FAILED,
VULKAN_ERROR_PIPELINE_ALREADY_INITIALIZED,
VULKAN_ERROR_UNKNOWN_DESCRIPTOR_TYPE,
VULKAN_ERROR_DESCRIPTOR_SET_LAYOUT_CREATION_FAILED,
VULKAN_ERROR_DESCRIPTOR_SET_CREATION_FAILED,
VULKAN_ERROR_DESCRIPTOR_POOL_CREATION_FAILED,
};
#endif
+53 -112
View File
@@ -28,7 +28,7 @@
* @param[in/out] context Graphics context to create sampler in
* @return RSE_ERROR_NO_ERROR on success, error code otherwise
*/
static rse_err_t create_sampler(struct graphics_context_t* context)
rse_err_t create_sampler(struct graphics_context_t* context, VkSampler sampler)
{
VkSamplerCreateInfo create_info = {0};
@@ -51,8 +51,7 @@ static rse_err_t create_sampler(struct graphics_context_t* context)
create_info.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK;
create_info.unnormalizedCoordinates = VK_FALSE;
if (VK_SUCCESS != vkCreateSampler(context->device, &create_info, NULL,
&context->sampler)) {
if (VK_SUCCESS != vkCreateSampler(context->device, &create_info, NULL, &sampler)) {
LOGF("Failed to create image view");
return 1;
}
@@ -60,26 +59,20 @@ static rse_err_t create_sampler(struct graphics_context_t* context)
return RSE_ERROR_NO_ERROR;
}
static rse_err_t find_supported_format(struct graphics_context_t* context,
const VkFormat* candidates,
size_t candidates_count,
VkImageTiling tiling,
VkFormatFeatureFlags features,
static rse_err_t find_supported_format(struct graphics_context_t* context, const VkFormat* candidates,
size_t candidates_count, VkImageTiling tiling, VkFormatFeatureFlags features,
VkFormat* found_format)
{
size_t i = 0U;
for (i = 0U; i < candidates_count; ++i) {
VkFormatProperties props;
vkGetPhysicalDeviceFormatProperties(context->physical_device,
candidates[i], &props);
vkGetPhysicalDeviceFormatProperties(context->physical_device, candidates[i], &props);
if (tiling == VK_IMAGE_TILING_LINEAR &&
(props.linearTilingFeatures & features) == features) {
if (tiling == VK_IMAGE_TILING_LINEAR && (props.linearTilingFeatures & features) == features) {
*found_format = candidates[i];
return RSE_ERROR_NO_ERROR;
} else if (tiling == VK_IMAGE_TILING_OPTIMAL &&
(props.optimalTilingFeatures & features) == features) {
} else if (tiling == VK_IMAGE_TILING_OPTIMAL && (props.optimalTilingFeatures & features) == features) {
*found_format = candidates[i];
return RSE_ERROR_NO_ERROR;
}
@@ -89,12 +82,9 @@ static rse_err_t find_supported_format(struct graphics_context_t* context,
return VULKAN_ERROR_FORMAT_NOT_FOUND;
}
static rse_err_t create_image(struct graphics_context_t* context,
struct vulkan_image_t* image, uint32_t width,
uint32_t height, VkFormat format,
VkSampleCountFlagBits maa_samples,
VkImageUsageFlags usage,
VmaAllocationCreateFlags allocationFlags)
static rse_err_t create_image(struct graphics_context_t* context, struct vulkan_image_t* image, uint32_t width,
uint32_t height, VkFormat format, VkSampleCountFlagBits maa_samples,
VkImageUsageFlags usage, VmaAllocationCreateFlags allocationFlags)
{
VkExtent3D image_extent = {0};
VkImageCreateInfo image_info = {0};
@@ -115,8 +105,7 @@ static rse_err_t create_image(struct graphics_context_t* context,
image_info.samples = maa_samples;
image_info.tiling = VK_IMAGE_TILING_OPTIMAL;
image_info.usage = usage;
image_info.sharingMode =
VK_SHARING_MODE_EXCLUSIVE; // TODO: Change if used by more than one
image_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; // TODO: Change if used by more than one
// queue family
image_info.queueFamilyIndexCount = 0U;
image_info.pQueueFamilyIndices = NULL;
@@ -131,10 +120,8 @@ static rse_err_t create_image(struct graphics_context_t* context,
alloc_create_info.pUserData = NULL;
alloc_create_info.priority = 1.0f;
if (VK_SUCCESS != vmaCreateImage(context->allocator, &image_info,
&alloc_create_info, &image->image,
&image->allocation,
&image->allocation_info)) {
if (VK_SUCCESS != vmaCreateImage(context->allocator, &image_info, &alloc_create_info, &image->image,
&image->allocation, &image->allocation_info)) {
LOGF(_("Failed to create image\n"));
return VULKAN_ERROR_IMAGE_NOT_CREATED;
}
@@ -142,9 +129,7 @@ static rse_err_t create_image(struct graphics_context_t* context,
return RSE_ERROR_NO_ERROR;
}
static rse_err_t create_image_view(struct graphics_context_t* context,
struct vulkan_image_t* image,
VkFormat format,
static rse_err_t create_image_view(struct graphics_context_t* context, struct vulkan_image_t* image, VkFormat format,
VkImageAspectFlags aspectFlags)
{
VkImageViewCreateInfo image_view_create_info = {0};
@@ -165,9 +150,7 @@ static rse_err_t create_image_view(struct graphics_context_t* context,
image_view_create_info.subresourceRange.baseArrayLayer = 0U;
image_view_create_info.subresourceRange.layerCount = 1U;
if (VK_SUCCESS != vkCreateImageView(context->device,
&image_view_create_info, NULL,
&image->image_view)) {
if (VK_SUCCESS != vkCreateImageView(context->device, &image_view_create_info, NULL, &image->image_view)) {
LOGF(_("Failed to create swapchain image view\n"));
return VULKAN_ERROR_SWAPCHAIN_IMVIEW_CREATION_FAILED;
}
@@ -180,20 +163,14 @@ rse_err_t create_color_resource(struct graphics_context_t* context)
VkFormat color_format = IMAGE_FORMAT;
VkSurfaceCapabilitiesKHR physical_device_surface_capabilities;
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
context->physical_device, context->surface,
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(context->physical_device, context->surface,
&physical_device_surface_capabilities);
STATUS_CHECK(
create_image(context, &context->color_image,
physical_device_surface_capabilities.currentExtent.width,
physical_device_surface_capabilities.currentExtent.height,
color_format, VK_SAMPLE_COUNT_8_BIT,
VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT |
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
0U));
STATUS_CHECK(create_image_view(context, &context->color_image, color_format,
VK_IMAGE_ASPECT_COLOR_BIT));
STATUS_CHECK(create_image(context, &context->color_image, physical_device_surface_capabilities.currentExtent.width,
physical_device_surface_capabilities.currentExtent.height, color_format,
VK_SAMPLE_COUNT_8_BIT,
VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0U));
STATUS_CHECK(create_image_view(context, &context->color_image, color_format, VK_IMAGE_ASPECT_COLOR_BIT));
return status;
}
@@ -205,18 +182,13 @@ rse_err_t create_depth_resources(struct graphics_context_t* context)
VkSurfaceCapabilitiesKHR physical_device_surface_capabilities;
STATUS_CHECK(find_depth_format(context, &depth_format));
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
context->physical_device, context->surface,
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(context->physical_device, context->surface,
&physical_device_surface_capabilities);
STATUS_CHECK(
create_image(context, &context->depth_image,
physical_device_surface_capabilities.currentExtent.width,
physical_device_surface_capabilities.currentExtent.height,
depth_format, VK_SAMPLE_COUNT_8_BIT,
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0U));
STATUS_CHECK(create_image_view(context, &context->depth_image, depth_format,
VK_IMAGE_ASPECT_DEPTH_BIT));
STATUS_CHECK(create_image(context, &context->depth_image, physical_device_surface_capabilities.currentExtent.width,
physical_device_surface_capabilities.currentExtent.height, depth_format,
VK_SAMPLE_COUNT_8_BIT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0U));
STATUS_CHECK(create_image_view(context, &context->depth_image, depth_format, VK_IMAGE_ASPECT_DEPTH_BIT));
return status;
}
@@ -228,8 +200,7 @@ rse_err_t create_depth_resources(struct graphics_context_t* context)
* @param[out] format_size Format size in bytes to return
* @return RSE_ERROR_NO_ERROR on success, error code otherwise
*/
static rse_err_t format_to_pixel_size(VkFormat format,
VkDeviceSize* format_size)
static rse_err_t format_to_pixel_size(VkFormat format, VkDeviceSize* format_size)
{
switch (format) {
case VK_FORMAT_R8_SRGB:
@@ -252,10 +223,8 @@ static rse_err_t format_to_pixel_size(VkFormat format,
return RSE_ERROR_NO_ERROR;
}
static rse_err_t transition_image_layout(struct graphics_context_t* context,
struct vulkan_image_t* image,
VkImageLayout old_layout,
VkImageLayout new_layout)
static rse_err_t transition_image_layout(struct graphics_context_t* context, struct vulkan_image_t* image,
VkImageLayout old_layout, VkImageLayout new_layout)
{
VkImageSubresourceRange range = {0};
VkImageMemoryBarrier image_barrier = {0};
@@ -280,8 +249,7 @@ static rse_err_t transition_image_layout(struct graphics_context_t* context,
image_barrier.image = image->image;
image_barrier.subresourceRange = range;
if (old_layout == VK_IMAGE_LAYOUT_UNDEFINED &&
new_layout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
if (old_layout == VK_IMAGE_LAYOUT_UNDEFINED && new_layout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
image_barrier.srcAccessMask = 0;
image_barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
@@ -299,18 +267,14 @@ static rse_err_t transition_image_layout(struct graphics_context_t* context,
}
command_buffer = begin_single_time_command(context);
vkCmdPipelineBarrier(command_buffer, source_stage, destination_stage, 0, 0,
NULL, 0, NULL, 1, &image_barrier);
vkCmdPipelineBarrier(command_buffer, source_stage, destination_stage, 0, 0, NULL, 0, NULL, 1, &image_barrier);
end_single_time_comands(context, command_buffer);
return RSE_ERROR_NO_ERROR;
}
static rse_err_t create_textured_image(struct graphics_context_t* context,
uint32_t width, uint32_t height,
VkFormat format,
const unsigned char* pixels,
uint16_t* texture_id)
static rse_err_t create_textured_image(struct graphics_context_t* context, uint32_t width, uint32_t height,
VkFormat format, const unsigned char* pixels, uint16_t* texture_id)
{
rse_err_t status = RSE_ERROR_NO_ERROR;
struct vulkan_buffer_t staging_buffer = {0};
@@ -345,9 +309,7 @@ static rse_err_t create_textured_image(struct graphics_context_t* context,
staging_buffer_size = staging_buffer_size * width * height;
STATUS_CHECK(create_image(
context, free_texture_image, width, height, format,
VK_SAMPLE_COUNT_8_BIT,
STATUS_CHECK(create_image(context, free_texture_image, width, height, format, VK_SAMPLE_COUNT_8_BIT,
VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT));
@@ -382,19 +344,14 @@ static rse_err_t create_textured_image(struct graphics_context_t* context,
// &image_barrier);
// end_single_time_comands(command_buffer);
transition_image_layout(context, free_texture_image,
VK_IMAGE_LAYOUT_UNDEFINED,
transition_image_layout(context, free_texture_image, VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
/* Copy pixel data to GPU memory */
STATUS_CHECK(create_buffer(
context, staging_buffer_size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
VMA_MEMORY_USAGE_AUTO_PREFER_HOST,
VMA_ALLOCATION_CREATE_MAPPED_BIT |
VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
&staging_buffer));
context, staging_buffer_size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VMA_MEMORY_USAGE_AUTO_PREFER_HOST,
VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT, &staging_buffer));
memcpy(staging_buffer.allocation_info.pMappedData, pixels,
staging_buffer_size);
memcpy(staging_buffer.allocation_info.pMappedData, pixels, staging_buffer_size);
copy_region.bufferOffset = 0U;
copy_region.bufferRowLength = 0U;
@@ -409,14 +366,12 @@ static rse_err_t create_textured_image(struct graphics_context_t* context,
copy_region.imageExtent = image_extent;
command_buffer = begin_single_time_command(context);
vkCmdCopyBufferToImage(
command_buffer, staging_buffer.buffer, free_texture_image->image,
vkCmdCopyBufferToImage(command_buffer, staging_buffer.buffer, free_texture_image->image,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
end_single_time_comands(context, command_buffer);
destroy_buffer(context, &staging_buffer);
transition_image_layout(context, free_texture_image,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
transition_image_layout(context, free_texture_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
// /* Change image layout for shaders to be able to read it */
@@ -438,8 +393,7 @@ static rse_err_t create_textured_image(struct graphics_context_t* context,
// &image_barrier);
// end_single_time_comands(command_buffer);
STATUS_CHECK(create_image_view(context, free_texture_image, format,
VK_IMAGE_ASPECT_COLOR_BIT));
STATUS_CHECK(create_image_view(context, free_texture_image, format, VK_IMAGE_ASPECT_COLOR_BIT));
free_texture_image->id_taken = IMAGE_TAKEN;
return RSE_ERROR_NO_ERROR;
@@ -449,29 +403,24 @@ rse_err_t init_vulkan_images(struct graphics_context_t* context)
{
rse_err_t status = RSE_ERROR_NO_ERROR;
STATUS_CHECK(create_sampler(context));
STATUS_CHECK(create_depth_resources(context));
STATUS_CHECK(create_color_resource(context));
return status;
}
rse_err_t load_texture_from_bitmat(struct graphics_context_t* context,
const unsigned char* pixel_buffer, int width,
int height, uint16_t* texture_id,
VkFormat color_format)
rse_err_t load_texture_from_bitmat(struct graphics_context_t* context, const unsigned char* pixel_buffer, int width,
int height, uint16_t* texture_id, VkFormat color_format)
{
rse_err_t status = RSE_ERROR_NO_ERROR;
/* Create actual Vulkan Image */
STATUS_CHECK(create_textured_image(context, width, height, color_format,
pixel_buffer, texture_id));
STATUS_CHECK(create_textured_image(context, width, height, color_format, pixel_buffer, texture_id));
return status;
}
rse_err_t load_texture_from_file(struct graphics_context_t* context,
const char* file_path, uint16_t* texture_id)
rse_err_t load_texture_from_file(struct graphics_context_t* context, const char* file_path, uint16_t* texture_id)
{
rse_err_t status = RSE_ERROR_NO_ERROR;
int width = 0;
@@ -479,16 +428,14 @@ rse_err_t load_texture_from_file(struct graphics_context_t* context,
int channels = 0;
stbi_uc* pixel_buffer = NULL;
pixel_buffer =
stbi_load(file_path, &width, &height, &channels, STBI_rgb_alpha);
pixel_buffer = stbi_load(file_path, &width, &height, &channels, STBI_rgb_alpha);
if (pixel_buffer == NULL) {
LOGE("Failed to load texture from file: %s", file_path);
return -1;
}
STATUS_CHECK(load_texture_from_bitmat(context, pixel_buffer, width, height,
texture_id, VK_FORMAT_R8G8B8A8_SRGB));
STATUS_CHECK(load_texture_from_bitmat(context, pixel_buffer, width, height, texture_id, VK_FORMAT_R8G8B8A8_SRGB));
stbi_image_free(pixel_buffer);
@@ -503,10 +450,8 @@ void destroy_textures(struct graphics_context_t* context)
for (i = 0U; i < RSE_MAX_IMAGE_COUNT; ++i) {
if (context->texture_images[i].id_taken == IMAGE_TAKEN) {
vkDestroyImageView(context->device,
context->texture_images[i].image_view, NULL);
vmaDestroyImage(context->allocator,
context->texture_images[i].image,
vkDestroyImageView(context->device, context->texture_images[i].image_view, NULL);
vmaDestroyImage(context->allocator, context->texture_images[i].image,
context->texture_images[i].allocation);
}
}
@@ -515,15 +460,13 @@ void destroy_textures(struct graphics_context_t* context)
void destroy_depth_resource(struct graphics_context_t* context)
{
vkDestroyImageView(context->device, context->depth_image.image_view, NULL);
vmaDestroyImage(context->allocator, context->depth_image.image,
context->depth_image.allocation);
vmaDestroyImage(context->allocator, context->depth_image.image, context->depth_image.allocation);
}
void destroy_color_resource(struct graphics_context_t* context)
{
vkDestroyImageView(context->device, context->color_image.image_view, NULL);
vmaDestroyImage(context->allocator, context->color_image.image,
context->color_image.allocation);
vmaDestroyImage(context->allocator, context->color_image.image, context->color_image.allocation);
}
uint8_t image_exists(struct graphics_context_t* context, uint8_t image_id)
@@ -545,15 +488,13 @@ size_t get_textures_count(struct graphics_context_t* context)
return count;
}
rse_err_t find_depth_format(struct graphics_context_t* context,
VkFormat* found_format)
rse_err_t find_depth_format(struct graphics_context_t* context, VkFormat* found_format)
{
#define formats_count 3
rse_err_t status;
VkFormat formats[formats_count] = {VK_FORMAT_D32_SFLOAT};
STATUS_CHECK(find_supported_format(
context, formats, formats_count, VK_IMAGE_TILING_OPTIMAL,
STATUS_CHECK(find_supported_format(context, formats, formats_count, VK_IMAGE_TILING_OPTIMAL,
VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT, found_format));
return status;
+8 -8
View File
@@ -9,18 +9,15 @@
*
*/
#ifndef TEXTURE_H
#define TEXTURE_H
#include "utilities/file_utils.h"
#include "utilities/commons.h"
#include "graphics_context.h"
#include "vulkan/vulkan_core.h"
#include <stdint.h>
#include "graphics_context.h"
#include "utilities/commons.h"
#include "utilities/file_utils.h"
#include "vulkan/vulkan_core.h"
#define IMAGE_FORMAT VK_FORMAT_B8G8R8A8_SRGB;
@@ -40,7 +37,8 @@ rse_err_t init_vulkan_images(struct graphics_context_t* context);
* @param texture_id Texture ID will be set up here
* @return rse_err_t RSE_ERROR_NO_ERROR on success
*/
rse_err_t load_texture_from_bitmat(struct graphics_context_t* context, const unsigned char* pixel_buffer, int width, int height, uint16_t* texture_id, VkFormat color_format);
rse_err_t load_texture_from_bitmat(struct graphics_context_t* context, const unsigned char* pixel_buffer, int width,
int height, uint16_t* texture_id, VkFormat color_format);
/**
* @brief Loads image from file, for later to be used as a texture
@@ -85,4 +83,6 @@ void destroy_color_resource(struct graphics_context_t* context);
rse_err_t create_depth_resources(struct graphics_context_t* context);
void destroy_depth_resource(struct graphics_context_t* context);
rse_err_t create_sampler(struct graphics_context_t* context, VkSampler sampler);
#endif /* TEXTURE_H */
+17 -4
View File
@@ -5,9 +5,16 @@
void read_file(const char* file_name, size_t* bytes_count, char* buffer)
{
FILE* file;
errno_t err = 0;
FILE* file = NULL;
err = fopen_s(&file, file_name, "rb");
if (0 != err) {
perror("Failed to open file");
return;
}
file = fopen(file_name, "rb");
fseek(file, 0, SEEK_END);
*bytes_count = ftell(file);
rewind(file);
@@ -26,9 +33,15 @@ void read_file(const char* file_name, size_t* bytes_count, char* buffer)
void write_to_file(const char* file_name, size_t bytes_count, char* buffer)
{
FILE* file;
errno_t err = 0;
FILE* file = NULL;
file = fopen(file_name, "wb");
err = fopen_s(&file, file_name, "wb");
if (0 != err) {
perror("Failed to open file.");
return;
}
fwrite(buffer, bytes_count, 1, file);
fclose(file);
-24
View File
@@ -1,24 +0,0 @@
#include "utilities/task.h"
uint8_t create_task(thread_t* thread_id, thread_worker_t callback, void* args)
{
uint8_t result = 0;
result = pthread_create(thread_id, NULL, callback, args);
return result; //TODO: Do error handling
}
uint8_t task_join(thread_t* thread_id)
{
uint8_t result = 0;
result = pthread_join(*thread_id, NULL);
return result; //TODO: Do error handling
}
void task_exit()
{
pthread_exit(NULL);
}
-28
View File
@@ -1,28 +0,0 @@
/**
* @file task.h
* @author Piotr Krygier (everyonecancode@gmail.com)
* @brief Threads wrapper
* @version 0.1
* @date 2023-08-14
*
* @copyright Copyright (c) 2023
*
*/
#ifndef THREADS_H
#define THREADS_H
#include <stdint.h>
#ifdef __linux__
#include <pthread.h>
typedef pthread_t thread_t;
#endif
typedef void*(*thread_worker_t)(void*);
uint8_t create_task(thread_t* thread_id, thread_worker_t callback, void* args);
uint8_t task_join(thread_t* thread_id);
void task_exit(void);
#endif /* THREADS_H */