platform/upstream/Vulkan-Loader.git
14 months agoloader: add support for GNU/Hurd
Pino Toscano [Sun, 2 Jul 2023 16:30:58 +0000 (18:30 +0200)]
loader: add support for GNU/Hurd

* add the Hurd to COMMON_UNIX_PLATFORMS, as it is a POSIX OS
* use the Linux paths for getting the executable path (i.e. using
  /proc/self/exe): the Linux procfs provides both "self" and
  "<pid>/exe"
* follow the Linux behaviour in tests w.r.t. the platform shim
  behaviour, the test dummy binaries, and few more other bits

14 months agobuild: Update to header 1.3.256
Mike Schuchardt [Fri, 30 Jun 2023 18:53:36 +0000 (11:53 -0700)]
build: Update to header 1.3.256

- Update known-good
- Generate source

15 months agobuild: Update to header 1.3.255
Mike Schuchardt [Fri, 23 Jun 2023 17:39:22 +0000 (10:39 -0700)]
build: Update to header 1.3.255

- Update known-good
- Generate source

15 months agoAdd test for layer_prop_list out of bounds indexing
Charles Giessen [Fri, 23 Jun 2023 03:42:26 +0000 (21:42 -0600)]
Add test for layer_prop_list out of bounds indexing

This test makes sure that we correctly query for unknown functions implemented
only in a single layer while there are other layers present. This commit
successfully reproduces the error that the previous commit fixes. It was
difficult to reproduce because to get an crash, the test has to have the
instance_layer_list be in a different order than how they appear in
expanded_activated_layer_list.

15 months agoRemove indexing on layer_prop_list
Charles Giessen [Fri, 23 Jun 2023 03:36:39 +0000 (21:36 -0600)]
Remove indexing on layer_prop_list

The usage of the layer property list inside of
loader_check_layer_list_for_phys_dev_ext_address was modified when the
list changed from an array of struct loader_layer_properties, to an array
of pointers to struct loader_layer_properties. Except, the usages of
layer_prop_list were not updated in kind, leading to out of bounds indexes
when searching for unknown physical device functions in layers. This causes
crashes in the validation layer tests, which make use of this functionality.

15 months agoCleanup test layer GIPA & GDPA function exports
Charles Giessen [Fri, 23 Jun 2023 03:46:17 +0000 (21:46 -0600)]
Cleanup test layer GIPA & GDPA function exports

Splits apart the Version 0 layer into one with 'vkGetInstanceProcAddr'
and one with 'test_layerGetInstanceProcAddr' (with a similar change for
vkGetDeviceprocAddr). This is more in line with how layers in the wild
are written.

Removes the NO_PREFIX GIPA & GDPA exports as that is not supported by
the loader.

15 months agoClarify requirements for Layer Interface Version 1
Charles Giessen [Fri, 23 Jun 2023 03:45:05 +0000 (21:45 -0600)]
Clarify requirements for Layer Interface Version 1

The loader has never searched for `GetInstanceProcAddr` or `GetDeviceProcAddr`,
yet has documented that Layer Interface Version 1 supports layers that export
those functions.

15 months agocmake: Update update_deps.py logic
Juan Ramos [Wed, 21 Jun 2023 18:04:34 +0000 (12:04 -0600)]
cmake: Update update_deps.py logic

15 months agoRefactor return value of env.add_icd()
Charles Giessen [Mon, 19 Jun 2023 03:47:51 +0000 (21:47 -0600)]
Refactor return value of env.add_icd()

Make it return the driver that was just added rather than the ICD that
holds the driver, allowing for more concise code. This is because most
tests which modify the driver in some fashion do it in one go, and by
using the builder pattern, can be done all in a single statement.

15 months agoCleanup test creation of queues
Charles Giessen [Mon, 19 Jun 2023 02:52:43 +0000 (20:52 -0600)]
Cleanup test creation of queues

This commit removes queue creation from many tests because they were not a
primary part of the test. Many tests are written by first copying a previous
test and modifying it, which meant that a handful of initial tests would
include queue creation logic then get copied into many other tests where it
does not make sense.

15 months agoRefactor how tests load function pointers
Charles Giessen [Mon, 19 Jun 2023 02:08:35 +0000 (20:08 -0600)]
Refactor how tests load function pointers

The `load()` helper function exists so that tests dont need to
manually reinterpret_cast the returned value.

Also took liberty to change the names of function pointers which
come from extensions to include the extension in the name.
EX: AcquireDrmDisplay -> AcquireDrmDisplayEXT

15 months agoAdd EnumerateLayerDeviceExtensions helper to tests
Charles Giessen [Mon, 19 Jun 2023 00:30:49 +0000 (18:30 -0600)]
Add EnumerateLayerDeviceExtensions helper to tests

Removes code duplication by taking EnumerateDeviceExtensions and modifying
it to accept a layer parameter.

15 months agoRemove tests PhysicalDevice constructor overload
Charles Giessen [Mon, 19 Jun 2023 00:09:48 +0000 (18:09 -0600)]
Remove tests PhysicalDevice constructor overload

Having constructors to initialize specific values doesn't make sense when
the struct itself has extensive setter functions for the value in question.

15 months agoRefactor how tests enable WSI
Charles Giessen [Sun, 18 Jun 2023 23:44:17 +0000 (17:44 -0600)]
Refactor how tests enable WSI

Moved the various free functions to setup WSI on drivers &
instances to member functions.

15 months agoUse [[maybe_unused]] in tests
Charles Giessen [Sun, 18 Jun 2023 22:42:29 +0000 (16:42 -0600)]
Use [[maybe_unused]] in tests

Many components of the test framework have functions where not all parameters
are used, necessitating marking the parameter as unused. Before C++17, this was
done with `(void)parameter;` syntax, but now can be done more cleanly.

15 months agoRemove unnecessary constructors in tests
Charles Giessen [Sun, 18 Jun 2023 22:34:44 +0000 (16:34 -0600)]
Remove unnecessary constructors in tests

C++11 does not allow aggregate initialization for types with default values.
Thus, many structs used in the tests had to have constructors written which only
filled in values. With C++17, these constructors can be removed and aggregate
initialization used in many places.

This commit also provides default values for previously undefined structs to
prevent any bugs deriving from uninitialized data.

15 months agoUpdate tests to require a C++17 compiler
Charles Giessen [Fri, 16 Jun 2023 21:09:00 +0000 (15:09 -0600)]
Update tests to require a C++17 compiler

15 months agoCleanup BUILD.md
Charles Giessen [Fri, 16 Jun 2023 21:06:23 +0000 (15:06 -0600)]
Cleanup BUILD.md

Removes a lot of unnecessary text, fixes a few places that still
referred to Vulkan-ValidationLayers, replaces usage of CMake
options in the form `-DOPTION=...` with `-D OPTION=...`, moves a
few blocks of text to be in a more sensible order, and adds a
brief description of the build requirements like needing a C99
compiler.

15 months agoAdd ENABLE_WERROR to github actions
Charles Giessen [Fri, 16 Jun 2023 18:20:48 +0000 (12:20 -0600)]
Add ENABLE_WERROR to github actions

Makes github actions fail if there are any warnings generated.

15 months agoAdd and fix warnings for unused functions and parameters
Charles Giessen [Thu, 15 Jun 2023 21:47:23 +0000 (15:47 -0600)]
Add and fix warnings for unused functions and parameters

These warnings were disabled, and this commit enables them.
It also fixes the many warnings that were present but were silenced. This
includes many unused parameters that could be safely removed. But it also
required marking some parameters as `(void)param;` to indicate to the
compiler that the parameter is infact required. If a function is a stub
function, then instead all of the names of the parameters were removed.

The biggest change is for vk_dispatch_table_helper.h which had stubs for
every device function. Rather than try to mark every parameter as unused
it was simpler to remove all stub functions, which aren't useful for
testing anyhow. Tests should crash rather than silently continue anyhow.

15 months agobuild: Update to header 1.3.254
Mike Schuchardt [Fri, 16 Jun 2023 16:30:02 +0000 (09:30 -0700)]
build: Update to header 1.3.254

- Update known-good
- Generate source

15 months agoMark thread_safe_strtok as inline
Charles Giessen [Thu, 15 Jun 2023 20:18:14 +0000 (14:18 -0600)]
Mark thread_safe_strtok as inline

Because the function definition lives in a header, it needs to be marked inline
to prevent compiler warnings stating that "thread_safe_strtok is unused".

15 months agoloader: fix 32-bit jwasm compilation
Christopher Degawa [Tue, 13 Jun 2023 12:57:19 +0000 (07:57 -0500)]
loader: fix 32-bit jwasm compilation

jwasm, and by extension uasm, requires setting a cpu model to at least
386 in order to set the model to flat.

References:
https://github.com/JWasm/JWasm/blob/7218960b65d69216693a655d928eb4c2fb6b505c/cpumodel.c#L330-L332
https://github.com/Terraspace/UASM/blob/bffb18461dd541479064990c3b2750ab50ae23e2/cpumodel.c#L326-L328

Signed-off-by: Christopher Degawa <ccom@randomderp.com>
15 months agoUse CMAKE_MSVC_RUNTIME_LIBRARY to set desired C runtime for windows
Charles Giessen [Tue, 13 Jun 2023 04:52:52 +0000 (22:52 -0600)]
Use CMAKE_MSVC_RUNTIME_LIBRARY to set desired C runtime for windows

CMake 3.15 added the capability to directly set the desired C runtime
used. The loader itself should use -MT, or multithreaded static, so
that it statically links in the C runtime into itself. The tests use -MD,
or multithreaded dynamic because they share allocations between the various
dll's and .exe boundaries.

The TESTS_STANDARD_CXX_PROPERTIES makes setting the MSVC_RUNTIME_LIBRARY
easier across the many various components that need it set.

15 months agoSimply usage of LOADER_STANDARD_C_PROPERTIES in cmake
Charles Giessen [Tue, 13 Jun 2023 05:34:24 +0000 (23:34 -0600)]
Simply usage of LOADER_STANDARD_C_PROPERTIES in cmake

LOADER_STANDARD_C_PROPERTIES and LOADER_STANDARD_CXX_PROPERTIES included
PROPERTIES, which made it difficult to compose with other properties.
Removing PROPERTIES and adding it to every use of LOADER_STANDARD_C_PROPERTIES
makes the cmake code easier to understand.

15 months agoFix EnvVarWrapper overwriting values
Charles Giessen [Sun, 11 Jun 2023 00:00:56 +0000 (18:00 -0600)]
Fix EnvVarWrapper overwriting values

When EnvVarWrapper gets created, it clobbers the existing value of the
environment variable if it exists. When running multiple tests in a row
inside of a single process, the values set by the loader_testing_main.cpp
should be what every test is initialized with. To make that happen,
EnvVarWrapper now will save the existing value if it exists, then re-apply
it during its destructor.

15 months agoAdd tests for longer version strings
Charles Giessen [Sat, 10 Jun 2023 23:59:22 +0000 (17:59 -0600)]
Add tests for longer version strings

Include tests which exercise parsing logic for versions longer than
a single character.

15 months agoReplace strok with threadsafe versions
Charles Giessen [Sat, 10 Jun 2023 23:56:31 +0000 (17:56 -0600)]
Replace strok with threadsafe versions

strtok is not threadsafe, which was previously not a problem thanks to the
'read json' mutex. But since that was removed, it left strtok potentially
corrupting data as multiple threads try to use it. The fix is to replace
strtok with platform specific threadsafe versions, namely strtok_s for
windows platforms and strtok_r for unix platforms.

15 months agoBetter handle missing settings file
Tony-LunarG [Mon, 12 Jun 2023 16:59:47 +0000 (10:59 -0600)]
Better handle missing settings file

15 months agobuild: Update to header 1.3.253
Mike Schuchardt [Mon, 12 Jun 2023 15:05:00 +0000 (08:05 -0700)]
build: Update to header 1.3.253

- Update known-good
- Generate source

15 months agoFix USE_MASM=OFF in github actions
Charles Giessen [Wed, 7 Jun 2023 18:38:29 +0000 (12:38 -0600)]
Fix USE_MASM=OFF in github actions

The windows_vs-no-asm was incorrectly setup, causing the assembler to
be found when it should have used the fallback path.

15 months agoChange settings file location
Charles Giessen [Wed, 7 Jun 2023 17:28:47 +0000 (11:28 -0600)]
Change settings file location

Move the settings registry to "LoaderSettings" and the unix location
to "loader_settings.d".

The  validation layers looks for the settings file on windows in
"SOFTWARE/Khronos/Vulkan/Settings" but doesn't check the file name.
To maintain compatibility, the loader's settings file needs to be
in a different location.

15 months agoDisable MinGW Github Actions run
Charles Giessen [Wed, 7 Jun 2023 17:09:44 +0000 (11:09 -0600)]
Disable MinGW Github Actions run

MinGW uses JWASM to compile the assembly code. This commit disables that run
for the time being because github actions currently doesn't have JWASM setup.
While work could be done to get it working, it is low priority.

15 months agoSilence MINGW error about casting functions
Charles Giessen [Wed, 7 Jun 2023 16:19:33 +0000 (10:19 -0600)]
Silence MINGW error about casting functions

When compiling with MinGW, GCC emits a warning:
"error: cast between incompatible function types from 'FARPROC' to ..."

GCC doesn't like the cast after calls to GetProcAddress, so
casting to void* first fixes the warning.

15 months agoFix fallback unknown function build logic
Charles Giessen [Mon, 5 Jun 2023 20:48:32 +0000 (14:48 -0600)]
Fix fallback unknown function build logic

The build logic for enabling the unknown function support when ASM code doesn't
work or is disabled was broken. This fixes it by consolidating the various code
paths as well as making sure it is enabled when it should be.

This also fixes the fallback path for macOS by making sure to only modify the
names of functions if and only if the corresponding assembly code is active.

15 months agoAdd CI runs for unknown function fallbacks
Charles Giessen [Mon, 5 Jun 2023 20:45:48 +0000 (14:45 -0600)]
Add CI runs for unknown function fallbacks

There is C code that is used when the ASM support for unknown function fails to build
or the ASM build is explicitly disabled. This previously had no tests for these code
paths. Now there is a Github actions run for each platform, such as linux, windows,
macOS, as well as 32 bit linux and mingw.

15 months agoci: Add MinGW build
juan-lunarg [Mon, 5 Jun 2023 19:16:59 +0000 (12:16 -0700)]
ci: Add MinGW build

15 months agoRemove inclusion of winsock2.h
Charles Giessen [Sat, 3 Jun 2023 22:17:52 +0000 (16:17 -0600)]
Remove inclusion of winsock2.h

The header is unused and causes compilation issues due to the header needing
to be included before windows.h

15 months agoloader: Add void to function arguments
John Bauman [Fri, 2 Jun 2023 16:31:05 +0000 (16:31 +0000)]
loader: Add void to function arguments

UBSan was detecting a function type mismatch for these module
ctor/dtors since libc expects the function type to be void (*)(void)
rather than just void (*)().

15 months agoMake assembly work on macOS
Charles Giessen [Tue, 30 May 2023 21:42:09 +0000 (15:42 -0600)]
Make assembly work on macOS

The assembly for unknown function support did not need too many changes to
make it compile, link, and pass all tests on macOS.

The main change is working around the ABI of macOS, namely that C symbols have
an underscore prepended. To workaround this, the __asm("name") syntax was
used to make sure the symbols weren't modified. All of the declarations in
dev_ext_trampoline.c and phys_dev_ext.c need the
change, but so does loader_log because it gets called by the asm code.

Additionally, the .hidden attribute is only present for the ELF output. So
that has to be removed during compilation on macOS.

15 months agoRemove loader.aps
Charles Giessen [Tue, 30 May 2023 19:56:44 +0000 (13:56 -0600)]
Remove loader.aps

The aps file is a Visual Studio binary file that is a compiled version of
loader.rc used by resource editors. The documentation calls out that this
file should not be checked into source control, so it can be safely removed.

15 months agoAdd clang-cl run to github actions CI
Charles Giessen [Wed, 31 May 2023 03:59:59 +0000 (21:59 -0600)]
Add clang-cl run to github actions CI

Chromium builds use clang-cl so best to make sure we don't break them.

15 months agoRemove unused variable for clang-cl on windows
Charles Giessen [Tue, 30 May 2023 16:37:46 +0000 (10:37 -0600)]
Remove unused variable for clang-cl on windows

read_data_files_in_search_paths' `relative_path` is only used on unix
platforms but is defined for all platforms. This causes clang-cl to
warn about it, and causes the build to fail when ENABLE_WERROR is on.

The fix is to *not* define the offending variable on windows. Makes the
code more annoying to read due to the excessive #if #else macros, but
that is the simplest change.

15 months agobuild: Update to header 1.3.251
Mike Schuchardt [Tue, 30 May 2023 22:53:28 +0000 (15:53 -0700)]
build: Update to header 1.3.251

- Update known-good
- Generate source

15 months agoRemove foward declaration of VkResult and VkFlags
Charles Giessen [Tue, 30 May 2023 15:55:59 +0000 (09:55 -0600)]
Remove foward declaration of VkResult and VkFlags

While it is nice to forward declare the 1 type needed, it is better to include
vulkan.h since the enum forward declaration is a microsoft specific extension.

15 months agoFix issues found with clang-tidy
Charles Giessen [Mon, 29 May 2023 23:06:06 +0000 (17:06 -0600)]
Fix issues found with clang-tidy

clang-tidy found numerous issues, roughly divided into three categories:
* Unused variables
* strcpy is unsafe
* NULL dereference due to missing NULL check

15 months agoUse strncpy in loader_add_environment_layers
Charles Giessen [Mon, 29 May 2023 21:04:43 +0000 (15:04 -0600)]
Use strncpy in loader_add_environment_layers

15 months agoPropagate OOM in more places
Charles Giessen [Mon, 29 May 2023 21:03:59 +0000 (15:03 -0600)]
Propagate OOM in more places

15 months agoAdd NULL checks to cJSON helper functions
Charles Giessen [Mon, 29 May 2023 21:02:04 +0000 (15:02 -0600)]
Add NULL checks to cJSON helper functions

15 months agoSeparate meta layer verification & update logic
Charles Giessen [Mon, 29 May 2023 20:58:01 +0000 (14:58 -0600)]
Separate meta layer verification & update logic

verify_meta_layer_component_layers previously would update the extension lists
of valid meta layers, which possibly allocates memory. The function had no
way to report OOM so instead, the updating of extension lists was added to a
separate function that gets called for successfully verified meta layers. Now
that the updating is moved out, the function can be simplified to return
false if any check fails.

This commit also cleans up verify_all_meta_layers such that the OOM is
propagated upwards if necessary, including modifying any callers of that
function.

15 months agoAdd loader settings file
Charles Giessen [Sat, 6 May 2023 05:26:52 +0000 (23:26 -0600)]
Add loader settings file

The loader settings file is a json file that enables external tools, such as
VkConfig to precisely enable and order the layers. This mirrors the
functionality of the override meta layer but by not being a layer, is able to
be much more cleanly implemented.

The primary capability of the settings file is to be able to dictate the
order of all layers regardless of their type. If the loader detects a settings
file, it will use the order provided in it. It has similar functionality for
applying a setting per-application as well as globally. A new feature is the
ability to dictate the 'global' logging behavior, eg overriding the
VK_LOADER_DEBUG environment variable.

Settings are per-instance, so if an application destroys its instance and
creates a new one, it will get the most up to date settings file. There is
a 'global' settings file used for pre-instance functions, and is updated on
every call that makes use of the settings (aka all global functions except for
vkGetInstanceProcAddr).

Most of the new code lives in settings.h and settings.c but changes were made
to loader_scan_for_layers, loader_scan_for_implicit_layers,
loader_enable_instance_layers, and loader_validate_instance_extensions.

15 months agoModify test framework surface creation helpers
Charles Giessen [Sat, 13 May 2023 18:03:52 +0000 (12:03 -0600)]
Modify test framework surface creation helpers

The surface creation helper functions were overloaded with a function that
only needs the VulkanFunctions* and VkInstance paramters, which allows them
to be used in the Out Of Memory allocation callback tests. To facilitate this
change, the return value of create_surface was changed to a straight VkResult,
requiring calling code to check that the result value is what they expect.

15 months agoAdd header files to source file list in CMake
Charles Giessen [Fri, 12 May 2023 22:21:18 +0000 (16:21 -0600)]
Add header files to source file list in CMake

Gives a better experience for Visual Studio and XCode developers.

15 months agoUse braces consistently in new helper functions
Charles Giessen [Fri, 12 May 2023 22:25:12 +0000 (16:25 -0600)]
Use braces consistently in new helper functions

15 months agoRemove guard for C++ in cJSON.h
Charles Giessen [Fri, 12 May 2023 22:22:56 +0000 (16:22 -0600)]
Remove guard for C++ in cJSON.h

The cJSON.h library is only used by C code, so the macro guard for C++ is not
needed.

15 months agoFix cJSON_print using wrong allocation scope
Charles Giessen [Sun, 14 May 2023 04:33:18 +0000 (22:33 -0600)]
Fix cJSON_print using wrong allocation scope

Because cJSON_print uses cJSON_malloc, it meant that all calls to cJSON_print
used the command allocation scope. With the change to directly store the strings
returned by cJSON, this meant that various strings were being stored in the
instance that were not allocated with the instance scope. This fixes that.

This commit also adds a safeguard to ensure the cJSON object is cleaned up if
loader_get_json fails

15 months agoRefactor to not use fixed length strings
Charles Giessen [Sun, 7 May 2023 22:52:04 +0000 (16:52 -0600)]
Refactor to not use fixed length strings

Many places in the loader stored paths in fixed length strings. This has
two major downsides, firstly that the loader could not support paths greater
than 1024 characters, and secondly that it greatly increased the memory
overhead needed for an instance. The memory pressure was something in the
order of 100kb+, most of which was completely empty strings.

To facilitate this change, the loader_layer_list type was added along with
several utility functions to create string lists, destroy string lists,
add elements to a string list, etc. The liberal use of the new type allows
for a lot of duplicate code to be deleted - as much of the layer parsing
logic was just to manage the various arrays of strings.

The loader_layer_properties struct now contains many char*'s and
loader_string_lists, and owns any of the strings inside of it. Compared to
before the commit, the loader_layer_properties struct is a mere 700 bytes
large versus the 11kb it was before.

loader_data_files is just a list of strings, so was replaced with the new
loader_string_list type, along with removal of any custom functions that
created/destroyed it.

One downside of the change is that various places in the loader used the
fact that a string was never NULL to not need to do a nullptr check. Because
many strings were just char arrays with a value of 0 throughout, the logic
was not needed. Switching to char*'s required adding NULL checks in various
places, such as loader_getenv and loader_secure_getenv.

The combine_manifest_directory_and_library_path function is the most
complex change in the entire commit. It implements behavior that was
duplicated between two separate places (layer and driver loading). The previous
logic also used dirname(), which required creating a new string to use. The
new function implements the behavior of dirname without the extra string.
It also will reuse a passed in string if appropriate - removing another
potential string copy.

loader_read_layer_json was refactored to be much easier to follow as well as
using the various json parsing utility functions that make it easy to get
strings, lists of strings, etc. The refactor changed the logic to only add
the loader_layer_properties structure to the list if it is successfully parsed,
rather than having to remove the properties if it fails in any way. Also the
macros were removed since they decreased readibility for marginal deduplication.
Before this commit, cJSON_Print was called many times in loader_read_layer_json,
which returns a newly allocated string, only for the data to be copied out of
it into a char array, then immediately freeing the allocated string. Now, those
allocations are put into the properties struct, saving a stack alloc & memcpy
per string.

15 months agoTurn layer lists into lists of pointers
Charles Giessen [Sun, 7 May 2023 19:46:55 +0000 (13:46 -0600)]
Turn layer lists into lists of pointers

The expanded_activated_layer_list and app_activated_layer_list now are lists of
pointers to the instance_layer_list of actual layers. This change was done to
remove the very large copies done to store the various layer lists.

This commit introduces a new type, loader_pointer_layer_list, which is a simple
list like structure for holding the pointers to the loader_layer_properties.

This commit moves the responsibility of unloading layers from
expanded_activated_layer_list to the instance_layer_list, meaning that closing of
libraries is now done during the calls to loader_delete_layer_list_and_properties.
loader_delete_layer_list_and_properties is also now called after the return from
vkDestroyInstance, since layer libraries need to stay alive until after they get a
chance to clean themselves up.

loader_add_layer_properties_to_list was modified to only ever add one layer at a
time, since all uses of it did this and it makes the definition easier to follow.

15 months agoMeta layers now dont add layers more than once
Charles Giessen [Fri, 12 May 2023 00:48:33 +0000 (18:48 -0600)]
Meta layers now dont add layers more than once

The check to make sure a layer isn't being added more than once was not present
for component layers of meta layers. Now, component layers from meta layers are
only added if they haven't been added before.

15 months agoRemove layer list copies from loader_device
Charles Giessen [Sun, 7 May 2023 17:04:34 +0000 (11:04 -0600)]
Remove layer list copies from loader_device

The layer lists do not need to be separate from the instance - as layers that
are active on a device must also be active on the instance. This saves unecessary
storage and allocations.

The concern of being able to create devices in multiple threads is alleviated
because device creation is a read-only process, so there is no contention. As
well as the instance must be valid (not destroyed) so that means the layer data
must also be available.

15 months agoRemove DEFAULT_VK_DRIVERS_PATH macro define
Charles Giessen [Sun, 7 May 2023 00:24:47 +0000 (18:24 -0600)]
Remove DEFAULT_VK_DRIVERS_PATH macro define

DEFAULT_VK_DRIVERS_PATH was undocumented and a compile time build - so anyone
using it would need to rebuild. VK_DRIVER_FILES and VK_ICD_FILENAMES are
environment variables which serve the same purpose without the need to recompile.

15 months agoAdd tests for system installed binaries
Charles Giessen [Thu, 11 May 2023 18:52:50 +0000 (12:52 -0600)]
Add tests for system installed binaries

When library_path in a manifest doesn't contain any directory separators, it
signals to the loader that the library name should be passed directly to
dlopen/LoadLibrary and for those functions to use the dynamic linkers default
search paths. This commit adds tests that do that, as well as sets up the
required functionality to implement this behavior in the test framework. For
Unix systems, this involves redirecting dlopen so that it loads the correct
binary - rather than relying on dlopen to find it for us. For Windows, we
use AddDllDirectory to modify LoadLibrary's search path as well as
SetDefaultDllDirectory to change LoadLibrary's behavior to do what we want.

15 months agoFix tests dying if an exception is thrown.
Charles Giessen [Sat, 6 May 2023 05:42:28 +0000 (23:42 -0600)]
Fix tests dying if an exception is thrown.

The test framework will generate an exception if any googletest assertion fails.
However, if there already is an ongoing exception, we do not want to throw
another one. Thus, we check if std::current_exception() is nullptr, and only
throw our own exception if it is nullptr.

15 months agoSignificantly reduce duplicate layer scanning code
Charles Giessen [Sat, 6 May 2023 04:45:19 +0000 (22:45 -0600)]
Significantly reduce duplicate layer scanning code

The layer scan functions had a pattern of calling loader_get_data_files,
parse the json found, and put the resulting parsed loader_layer_properties
into the output instance_layers list. This pattern was done twice in each
layer scan function, so in total 4 times. Thus, it was ripe for pulling the
common code into a new function, loader_parse_instance_layers().

The one bit of logic not shared between the two paths is whether or not the
layers being scanned are implicit or explicit. This is made easy by the fact
that the manifest_type dictates whether to parse the scanned manifests as
implicit or explicit layers.

Also, the code to get the override path was identical - but was copy pasted.
Moving it into a separate function cleans up the functions quite
siginificantly.

15 months agoRemove redundant clear when scanning for layers
Charles Giessen [Sat, 6 May 2023 04:06:24 +0000 (22:06 -0600)]
Remove redundant clear when scanning for layers

All callers of loader_scan_for_implicit_layers and loader_scan_for_layers
clear out instance_layers before calling, making the call to
loader_delete_layer_list_and_properties redundant.

Also reordered the local variable declaration order to match.

15 months agoRemove useless lock & comment out cJSON error handling
Charles Giessen [Sat, 6 May 2023 03:59:25 +0000 (21:59 -0600)]
Remove useless lock & comment out cJSON error handling

Because the error handling mechanism used a static variable, that meant that to
use cJSON_GetErrorPtr required a lock. This error function was never used, meaning
the lock that was there wasn't guarding any resource. cJSON doesn't have any non
const static variables.

This commit removes the lock and any associated code, which was improperly handled
in loader_scan_for_layers anyhow (potentially unlocking an already unlocked mutex).

15 months agoRemove useless if check in loader_scan_for_layers
Charles Giessen [Sat, 6 May 2023 03:37:20 +0000 (21:37 -0600)]
Remove useless if check in loader_scan_for_layers

The for loop will automatically skip the logic if manifest_files.count is zero.

15 months agoRemove redundant variable in loader_scan_for_layers
Charles Giessen [Sat, 6 May 2023 03:33:53 +0000 (21:33 -0600)]
Remove redundant variable in loader_scan_for_layers

total_count would only ever be non-zero if manifest_files.count is non zero, thus
it doesn't ever impact the control flow used.

15 months agoPass inst rather than NULL during layer scanning
Charles Giessen [Sat, 6 May 2023 03:30:23 +0000 (21:30 -0600)]
Pass inst rather than NULL during layer scanning

This commit fixes a bug in loader_scan_for_layers where the getting of filter
environment variables used NULL rather than the already available inst handle.

15 months agoMove library list allocation to out of layer search function
Charles Giessen [Sat, 6 May 2023 03:28:50 +0000 (21:28 -0600)]
Move library list allocation to out of layer search function

The allocation of the library list shouldn't be happening in the call to
loader_scan_for_implicit_layers.

15 months agoFix log.h to use #pragma once
Charles Giessen [Fri, 5 May 2023 23:28:21 +0000 (17:28 -0600)]
Fix log.h to use #pragma once

Also only include whats absolutely necessary and forward declare the rest.

15 months agoInclude Hive in windows registry logs
Charles Giessen [Fri, 5 May 2023 20:39:03 +0000 (14:39 -0600)]
Include Hive in windows registry logs

Which hive is being queried is useful information to have, this commit adds the
HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE hive strings to the appropriate log
messages.

15 months agoMake Allocation tests less noisy
Charles Giessen [Fri, 5 May 2023 19:49:14 +0000 (13:49 -0600)]
Make Allocation tests less noisy

The allocation tests will flood the output, change the debug log to only
issue error and warning level messages.

15 months agoAdd test utilities for getting instance layers and extensions
Charles Giessen [Thu, 4 May 2023 23:32:19 +0000 (17:32 -0600)]
Add test utilities for getting instance layers and extensions

Since it is incredibly common for tests to query the instance layers and
extensions, add helper functions to ease the enumeration of them and place the
results into an output vector, as well as check that the expected count is
equalt to the real count.

The GetActiveLayers function which did not take an expected count was removed
as tests should always know the exact number of layers that are present.

ASSERT_NO_FATAL_FAILURE was added to anyplace that queried extensions or layers
but requested a count of 0. This was done to insure that future maintainers do
not remove the seemingly redudant query of 0, as it is very much a part of the
test code since there are EXPECT macros inside the respective enumeration
utility functions.

15 months agoAdd unsecured manifest location to tests
Charles Giessen [Thu, 4 May 2023 17:45:22 +0000 (11:45 -0600)]
Add unsecured manifest location to tests

Meta layer should not be loaded if it originated from an unsecured location.
This commit contains the necessary changes needed to test layers & drivers that
live in the user local directory on linux and HKEY_CURRENT_USER on windows.

15 months agoCleanup JSON output in tests with utility
Charles Giessen [Tue, 2 May 2023 01:55:22 +0000 (19:55 -0600)]
Cleanup JSON output in tests with utility

Got tired of writing manual json output code, and moved the necessary
formatting logic into an easy to use utility. Makes the code MUCH cleaner and
easier to follow. Plus, it is now trivial to create JSON files so it will be
much easier to test the loader's parsing code.

15 months agoAdd GetActiveLayers function helper in tests
Charles Giessen [Tue, 2 May 2023 17:11:28 +0000 (11:11 -0600)]
Add GetActiveLayers function helper in tests

GetActiveLayers call vkEnumerateDeviceLayerProperties - which the loader treats
as the list of active layers. This helper function cleans up a lot of tests by
moving the exact same logic repeated many dozens of times into a single
location.

This commit also moves the EnumerateDeviceExtensions into the InstWrapper as a
helper, and updated its interface to require the requested extension count.

15 months agoMake EnvVarWrapper remove env-vars initially
Charles Giessen [Fri, 28 Apr 2023 19:05:16 +0000 (13:05 -0600)]
Make EnvVarWrapper remove env-vars initially

When an EnvVarWrapper object is created, it will now remove the env-var instead
of leaving the value unset (in the case of no initial value being given). This
is preferrable because it prevents external state from creeping in accidentally
if the test forgot to provide a value.

15 months agoAdd helper parsing functions to cJSON
Charles Giessen [Fri, 28 Apr 2023 18:59:41 +0000 (12:59 -0600)]
Add helper parsing functions to cJSON

Since parsing an array of strings and strings from json files is very common,
this commit adds helper functions to do exactly that.

15 months agoRefactor loader_log for clarity and performance
Charles Giessen [Wed, 26 Apr 2023 22:52:00 +0000 (16:52 -0600)]
Refactor loader_log for clarity and performance

Use strncat more efficiently by always starting at the place where the last
character was written. Also does not strncat the message and instead writes
that directly to the output stream. This allows shortening the character
buffer since the max possible length for the prefix is the only thing
written.

15 months agoRename log level to reflect its global status
Charles Giessen [Wed, 26 Apr 2023 22:47:25 +0000 (16:47 -0600)]
Rename log level to reflect its global status

The log level is set only during dynamic initializatoin, rather than during any
specific vulkan call. This commit renames the log to reflect this global
nature of the debug level.

15 months agoMake cJSON not add double quotes to strings
Charles Giessen [Tue, 25 Apr 2023 23:20:36 +0000 (17:20 -0600)]
Make cJSON not add double quotes to strings

In JSON, strings are surrounded with double quotes. Because the loader is
only using cJSON_Print to 'get' the underlying string, we have to strip away
the quotes. To do that, we have to create a new string and copy it over. That
is unnecessary if cJSON didn't add the quotes in the first place. This commit
does just that, but leaves the original code commented out in case it needs
to be reverted.

Note that in many places the loader still does a strcpy to place the string
into a char array, but this commit seeks to do the minimal set of changes to
accomplish the stated goal. Removing the rest of the strcpy's would require
more invasive work to make sure all the char*'s are deleted when they should
be.

15 months agoMove loader_get_json to cJSON
Charles Giessen [Tue, 25 Apr 2023 20:32:00 +0000 (14:32 -0600)]
Move loader_get_json to cJSON

Since opening a json file and reading it into a cJSON structure is done in
every source file that wishes to read json files, it is helpful to pull the
loader_get_json function into the source file.

15 months agoAdd FrameworkSettings to more easily configure the framework
Charles Giessen [Mon, 24 Apr 2023 18:28:49 +0000 (12:28 -0600)]
Add FrameworkSettings to more easily configure the framework

Introduce the FrameworkSettings struct to allow tests to easy and clearly
configure the basic settings of the FrameworkEnvironment. The previous
method just used overloaded constructors which is difficult to read compared
to an explicit structure that contains all the settings.

15 months agoCreate Dummy function just for windows_initialization
Charles Giessen [Fri, 21 Apr 2023 23:23:41 +0000 (17:23 -0600)]
Create Dummy function just for windows_initialization

The function call to get the current dll on windows requires the address of a
function inside the dll. Rather than use loader_debug_init, create a dedicated
function for this purpose.

15 months agoci: Test pkg-config and installation
juan-lunarg [Mon, 29 May 2023 19:18:48 +0000 (13:18 -0600)]
ci: Test pkg-config and installation

closes #1204

15 months agocmake: Don't install GTEST along with vulkan loader
juan-lunarg [Mon, 29 May 2023 19:30:04 +0000 (13:30 -0600)]
cmake: Don't install GTEST along with vulkan loader

15 months agocmake: Add LOADER_CODEGEN
juan-lunarg [Mon, 29 May 2023 17:06:04 +0000 (11:06 -0600)]
cmake: Add LOADER_CODEGEN

15 months agodocs: Document LOADER_CODEGEN
juan-lunarg [Mon, 29 May 2023 17:05:40 +0000 (11:05 -0600)]
docs: Document LOADER_CODEGEN

16 months agoLOADER_USE_UNSAFE_FILE_SEARCH
juan-lunarg [Fri, 26 May 2023 17:42:53 +0000 (11:42 -0600)]
LOADER_USE_UNSAFE_FILE_SEARCH

Make LOADER_USE_UNSAFE_FILE_SEARCH a CMake option.

Allows validation layers to disable safe search to work around
permissions issues on Github Actions.

16 months agoAdd a test for loader_gpa_instance_terminator
Charles Giessen [Sat, 20 May 2023 22:01:48 +0000 (16:01 -0600)]
Add a test for loader_gpa_instance_terminator

When loader_gpa_instance_terminator is called during vkCreateDevice, it should
use the terminator functions for the instance, which gets stored in struct
loader_instance's terminator_dispatch. This test is accomplished by querying
vkEnumerateDeviceExtensionProperties using the vkGetInstanceProcAddr provided
by chainInfo->u.pLayerInfo->pfnNextGetInstanceProcAddr and comparing the
function pointer with the one queried during vkCreateInstance.

16 months agoMake ChainInfo nextGIPA work in vkCreateDevice
Charles Giessen [Sat, 20 May 2023 21:52:27 +0000 (15:52 -0600)]
Make ChainInfo nextGIPA work in vkCreateDevice

Layers are given chainInfo during instance and device creation. This contains
vkGetInstanceProcAddr (GIPA) that corresponds to the next layer in the chain,
and if there is none, the loader's GIPA terminator. During vkCreateInstance
the instance dispatch table contains the terminators for instance functions.
After vkCreateInstance returns up the call chain, these terminators get
overwritten by calling GIPA on the first layer in the chain.

The problem is that after vkCreateInstance, the instance dispatch table
is being used by loader_gpa_instance_terminator, resulting in the wrong
function being returned to a layer who calls it.

This problem typically only shows up during vkCreateDevice, because the
chainInfo is given to each layer and that chainInfo contains a "nextGIPA".
Except, only the last layer gets a pointer to loader_gpa_instance_terminator,
as every other layer gets the GIPA of the next layer in the chain. Still,
this last layer should not be getting a pointer to the first function in
the chain.

The solution is to stash the terminator dispatch table after returning up
the vkCreateInstance chain but before overwriting the dispatch table with
the first layer in each function chain. Then, inside of
loader_gpa_instance_terminator check if we are still inside of
vkCreateInstance or not.

16 months agoModify test layer binary names correctly
Charles Giessen [Sat, 20 May 2023 21:48:04 +0000 (15:48 -0600)]
Modify test layer binary names correctly

When creating test layer binaries, the test framework appends a unique
identifier, specifically `_X` where X is a unique number.
Previously, this was appended at the very end, like so:
`libtest_layer.so_0`
Now, the `_X` is added before the file extension, like so:
`libtest_layer_0.so`

16 months agoMake loader_get_icd_and_device check for a NULL device
Charles Giessen [Thu, 18 May 2023 21:47:11 +0000 (15:47 -0600)]
Make loader_get_icd_and_device check for a NULL device

When loader_get_icd_and_device() is called with a NULL device handle, this
results in comparisons with NULL. If loader_get_dispatch(dev-icd_device) also
returns NULL (due to it being the wrong icd) then loader_get_icd_and_device
will compare NULL to NULL, get true, and return the wrong icd.

Simply checking if loader_get_dispatch(device) is NULL then returning NULL
immediately prevents this situation.

16 months agoFix crash from layers creating devices on different physical devices
Charles Giessen [Thu, 18 May 2023 21:34:30 +0000 (15:34 -0600)]
Fix crash from layers creating devices on different physical devices

The magic value for the device dispatch table was being set after calling down
the layer chain rather than before. This is wrong because of the situation when
layers create devices from different physical devices, the magic value using
the default value of zero means that loader_get_icd_and_device will return the
wrong loader_icd_term, leading to crashes elsewhere.

The fix is to set the magic value right after the dispatch table is allocated.

This commit adds tests for both drivers being created from the same physical
device and from different physical devices.

16 months agoDon't export Vulkan functions when building the loader statically
Geoff Lang [Tue, 16 May 2023 15:59:30 +0000 (11:59 -0400)]
Don't export Vulkan functions when building the loader statically

If the loader is linked statically, there is no need to export all
vulkan functions from the linking application. This issue showed up
in ANGLE which would export all GLES and Vulkan functions on Mac.

16 months agoAdded libgcc-s1:i386 to linux-32 Github actions
Charles Giessen [Tue, 16 May 2023 21:06:59 +0000 (15:06 -0600)]
Added libgcc-s1:i386 to linux-32 Github actions

Also split out the setup commands into separate run statements rather than
have them string together.

16 months agocmake: Fix LOADER_DISABLE_DYNAMIC_LIBRARY_UNLOADING
juan-lunarg [Mon, 8 May 2023 18:13:48 +0000 (12:13 -0600)]
cmake: Fix LOADER_DISABLE_DYNAMIC_LIBRARY_UNLOADING

16 months agoci: Test LOADER_DISABLE_DYNAMIC_LIBRARY_UNLOADING
juan-lunarg [Mon, 8 May 2023 18:26:30 +0000 (12:26 -0600)]
ci: Test LOADER_DISABLE_DYNAMIC_LIBRARY_UNLOADING

16 months agoFix LOADER_DISABLE_DYNAMIC_LIBRARY_UNLOADING WIN32 support
juan-lunarg [Sat, 6 May 2023 00:11:11 +0000 (18:11 -0600)]
Fix LOADER_DISABLE_DYNAMIC_LIBRARY_UNLOADING WIN32 support