Commit Graph

266 Commits

Author SHA1 Message Date
Charles Giessen
23a050bc76 Guard loader.instances access with mutex.
While the adding and removing of data from this global linked list
was guarded, GetInstanceProcAddr & GetDeviceProcAddr did not have
such guards. This results in race conditions that were detected with
thread sanitizer. This commit adds a mutex solely for the
loader.instances global variable.
2022-10-12 10:48:16 -06:00
Charles Giessen
0c7685be41 Initialize properly when statically linked
Previously, the loader supported static linking. This capability was restricted
to MacOS only, however the necessary functionality was never implemented. This
commit adds the required code to properly initialize the loader when statically
linked with MacOS

Since the test framework was designed to dynamically load everything, it would
require significant rearchitecting to support it. As such, a simple verification
executable was added to the live_verification folder, instead of full support
in the test framework.
2022-07-07 14:41:01 -06:00
Charles Giessen
9308d2f8f1 Fix crashes from OOM in vkDestroyInstance
Various situations could cause an OOM to turn into a hard crash due to double freeing
of memory that was improperly cleaned up. Also fixed memory leaks when layers would
report OOM.
2022-05-27 17:25:52 -06:00
Charles Giessen
a9543c5ac3 Make portability drivers not load by default
Unless the portability enumeration extension is enabled and the create instance flags
contain VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR, do not enumerate drivers that
contain `is_portability_driver` in their JSON Manifest. This is phase 2 of the release
for the VK_KHR_portability_enumeration extension.

An error message will be printed when no drivers were reported but there was a
portability driver which was skipped over.
2022-05-04 15:40:27 -06:00
Charles Giessen
36a82e0de8 Correctly check for NULL in loader_get_dispatch 2022-05-03 13:39:00 -06:00
Charles Giessen
a06dd5484a Clean up version checking logic
Add a few helper functions to simplify checking that a X.Y.Z version is sufficient.
2022-04-04 19:17:07 -06:00
Charles Giessen
2ded39d6f8 Remove hasing of unknown functions
Use a simple linear search instead. This greatly simplifies the logic and
reduces the places for the logic to go awry.
2022-03-14 23:31:26 -06:00
Charles Giessen
b5e6d4cb07 Move unknown function logic into dedicated file
unknown_function_handling.c now holds all of the unknown function handling
logic.
2022-03-14 23:31:26 -06:00
Mark Young
46abc7dc4e Add "additive" environment variables
Add "additive" environment variables for adding additional layer
paths or driver JSON files instead of replacing default ones.

Also, rename VK_ICD_FILENAMES to VK_DRIVER_FILES since we're trying
to remove references to ICDs because software driver implementations
of Vulkan aren't ICDs (but continue to support the old name as well).

Added documentation around these changes to reflect the new name and
the new variables.
2022-03-04 15:38:46 -07:00
Mark Young
0a19663fef Loader single EnumPhysDev call through layers
The loader trampoline previously would query all devices every time
vkEnumeratePhysicalDevices was called.
To do this, it would make two calls every time:
  - First, it would ignore the passed in user values
  - Second, it would query the total number of available devices.
  - Third, it would query the values for every available device

This resulted in layers reporting 2 vkEnumeratePhysicalDevices call for
every 1 the application made which could get very polluted in output.
It didn't break any functionality, just made things messy.

This change removes that behavior and adds a bunch of test cases to verify
nothing broke in the move.
2022-02-16 08:29:42 -07:00
Mark Young
b21acf16e7 Update loader to include handle validation
Validate the Vulkan dispatchable handles (VkInstance, VkPhysicalDevice, etc) for
any trampoline functions the loader uses to query the dispatch table from.
This is so we can at least report errors before something bad happens.

Also, add tests to the test framework to catch this case.  Right now they simply
check to make sure we aborted, but they don't know why the loader aborted.
Eventually, we need to come back and check the loader messages and make sure it
aborted for the reasons we want.

Fix a generator warning in dispatch_table_helper_generator.py where a compare was
the wrong type.

Fixes GH Issue #64.
2021-11-19 10:32:13 -07:00
Charles Giessen
e1dc222803 loader: Move struct decls to loader_common.h
Not all structs declarations in loader.h were moved to loader_common.h. This
caused compilation errors due to not having the struct declaration available
in the headers it was needed.
2021-09-10 14:25:29 -06:00
Charles Giessen
6bc2075122 loader: Move Windows logic to dedicated file
Relocated most windows specific functionality into loader_windows.h/.c
This removes the need for loader.c to include windows specific header files.
2021-09-09 11:28:56 -06:00
Charles Giessen
8138a8d83d loader: Make logging and getenv their own headers
This commit pulls the logging capabilities into a single log.h/.c file and does
the same for the getenv functionality.
2021-09-09 11:28:56 -06:00
Charles Giessen
353e139411 loader: Move allocation functions to a header
Functions pertainting to allocation (malloc, realloc, free) have been moved to
their own translation unit for better organizational purposes.
2021-09-09 11:28:56 -06:00
Charles Giessen
903a17df86 loader: Remove TLS
The only purpose TLS was serving was as a channel for allocation callbacks to
be useable inside cJSON and dirent_on_windows. TLS didn't solve any specific
threading problem. Instead it served as an information channel. On top of that,
the only time when the TLS was used was inside vkCreateInstance as the
pre-instance calls would have the TLS pointer to loader_instance be set to
NULL.
2021-09-09 11:28:56 -06:00
Charles Giessen
f676060468 loader: Move loader struct defs into common file
This commit separates the structure definitions from the function declarations.
The reason to do this is to allow splitting of loader.h/.c functionality into
individual headers, which may require access to these structs but don't need to
know about the other functions.
2021-09-09 11:28:56 -06:00
Charles Giessen
7d46bb6db9 loader: Update Copyright for 2021 2021-09-09 11:28:56 -06:00
Charles Giessen
17624a2df6 loader: Use #pragma once everywhere
The #pragma once include guard is sufficiently widespread enough to allow
usage of it everywhere.
2021-09-09 11:28:56 -06:00
Charles Giessen
e4e0b936e5 loader: Update Copyright 2021-09-09 11:28:56 -06:00
Charles Giessen
d81a521e03 loader: Move layer cleanup to a single function
Previously the logic to free all the components of loader_layer_properties was spread
across a half dozen different places, resulting in leaks. This commit moves the logic
into a single location, centralizing the process and making it easier to add new
fields to the loader_layer_properties struct.
2021-09-09 11:14:49 -06:00
Charles Giessen
20cf221e72 loader: Make all loader functions use snake_case
Before it was a mix of camelCase, PascalCase, and snake_case.

"Vulkan" functions, like terminator_GetPhysicalDeviceProperties, remain in camelCase.
This way it looks visually similar with the actual vulkan functions they correspond to.
2021-09-03 11:11:25 -06:00
Mark Young
1941128d41 Add layer and implementation-specific logging
Add logging that will allow end-users to specifically just look at
messages for layers and implementations/ICDs.
Setting VK_LOADER_DEBUG to include one of the following:
  - layer        : enables layer-specific logging
  - implem       : enables implementation/ICD-specific logging
2021-08-10 12:10:47 -06:00
Mark Young
9e43839765 Fix loader_log messages to use LOADER_ log levels
The loader_log messages were using the DEBUG_REPORT log levels
which just happened to coincide with the existing LOADER_ log levels.
Going forward, to add layer logging in its own level, this would not
have worked.
2021-08-10 12:10:47 -06:00
Mike Gorchak
684c2a6873 Add support for QNX platform. 2021-04-06 14:52:51 -06:00
J.D. Rouan
d7928a19e2 Add GGP WSI platform support to Vulkan-Loader
Add GGP WSI platform support to Vulkan-Loader. GGP is Google Games
Platform, the platform for Stadia.
2020-11-23 09:12:55 -07:00
Craig Stout
f3b74dc777 Add support for VK_FUCHSIA_imagepipe_surface 2020-10-26 17:59:09 -06:00
Lenny Komow
363a95a9b5 loader: Sort physical devices on Windows
This change adds a mechanism to allow sorting of physical devices
and physical device groups on Windows 10 if a driver supports a new
interface.
2020-08-14 14:38:31 -06:00
Lenny Komow
61bf3be73c loader: Make invalid std val layer an error
Standard validation was changed to khronos validation. This change
moves the warning when illegally using standard validation to an
error that will not allow a user to continue and will tell the user
to use khronos validation.

Change-Id: Iaeae6cffa4494a299f408033569163a7c61d3105
2020-08-07 13:29:39 -06:00
Nicolas Caramelli
fa696ca02c loader: Add support for directfb surface extension
The new VK_EXT_directfb_surface extension is a WSI extension and
thereforce needs loader support like the other surface extensions.
2020-07-07 10:33:54 -06:00
Charles Giessen
ead2b57f2e loader: add per-application override layer settings
An array of strings was added to the override layer to provide
per-application overrides. The loader will now look for an override profile
which contains an app_key entry that matches the path & name of the currently
running executable. Previous behavior with a global override still works as
intended.

This changes is in conjunction with the VkConfig rewrite to allow for more
than one override profile to be enabled.

Changes to be committed:
	modified:   loader/loader.c
	modified:   loader/loader.h
	modified:   loader/vk_loader_platform.h

Change-Id: I9ddbc98a098d48064110db6c29998eddb336fcda
2020-05-26 09:52:38 -06:00
Charles Giessen
3e390a1597 loader: Preload ICD use its own mutex
Previously, if a layer called a pre-instance function
while being initialized (inside vkCreateInstance) a deadlock
would occur because the preload icd call used the same mutex.

Change-Id: I085ecfbcab26d746d77ca8466b4f63a13f6bea10
2020-05-15 13:18:31 -06:00
Charles Giessen
95a4ccd0f9 loader: Preload ICD's to speed up common path
The ideal of having the loader be stateless causes serious slowdowns
in application startup due to the need to load then unload ICD's
repeatedly while calling pre vkCreateInstance functions. By pre-
loading the ICD's which are found using loader_icd_scan, the
unecessary reloading of ICD's is avoided.

The preloaded ICD's will be unloaded with vkDestroyInstance. This
allows subsequent vkCreateInstance calls to use the most recent ICD
on the system, preventing issue where a new driver was installed
but an application couldn't use it unless they unloaded the loader
library completely.

Changes to be committed:
	modified:   loader/loader.c
	modified:   loader/loader.h
	modified:   loader/trampoline.c

Change-Id: Id169f94bea15e569b75c3a663b25444cc6c52c40
2020-04-10 19:39:11 -06:00
Charles Giessen
e8d7d8813e loader: add null check to loaderValidateLayers
The loader will now make sure to check if utf8 is null before
validating the string, preventing needless segfaults.

Change-Id: I48139e56719e3c518b85f2ded1ca0b682447413f
2020-02-04 14:36:08 -07:00
Lenny Komow
a4f41ae869 loader: Fix debug utils terminators being skipped
Change-Id: I9e08b59669bd301e3c5361ae4ea16102461fb34b
2020-02-03 03:19:32 -07:00
Lenny Komow
08d344208e loader: Remove code for building a static loader
Change-Id: Id795e795a52ace1bf3c0c0fdbc5aed19d05bef01
2019-11-21 16:50:59 -07:00
Lenny Komow
a1b5e441b3 loader: Add support for metal surfaces
The adds support for the VK_EXT_metal_surface extension

Change-Id: Ibb1c21e19fb053fe332ea075c3d32de59f7f8881
2019-09-18 18:01:52 -06:00
Felix Dörre
0679472c1f layers: formatting 2019-04-29 16:13:15 -06:00
Felix Dörre
1efbf5115f layers: fix compile problems for WIN32 2019-04-29 16:13:15 -06:00
Felix Dörre
893bb561e7 cleanup: address review findings 2019-04-29 16:13:15 -06:00
Felix Dörre
e97e0a1a3d layers: add layer callbacks for device creation 2019-04-29 16:13:15 -06:00
Felix Dörre
34c3c5aeee loader: use more specific arguments 2019-04-29 16:13:15 -06:00
Felix Dörre
b2223847ab trampoline: extract device cration routine 2019-04-29 16:13:15 -06:00
Bryan Law-Smith
5730569e72 loader: VK_EXT_headless_surface additions
As VK_EXT_headless_surface is a WSI extension, supporting it
requires changes to the loader. This commit makes the necessary
changes, which are mostly straightforward plumbing.

However, this commit also includes a minor tweak to avoid a
segmentation fault when an implicitly enabled layer provides
support for an instance extension.
2019-04-26 15:23:45 -06:00
Mike Schuchardt
1df2ebd329 scripts: Update known-good for 1.1.106 header
Changes:
- Integrate upstream script changes: We have to plumb-through the new
conventions object to continue using the makeCParamDecl utility function
- Add GGP to available platforms
- Add handling for extension dependencies: Previously, the codegen for
loader trampolines could not handle an extension command that depends on
more than one extension being present. This removes that limitation
- Add checks for device extensions: This adds a check for two functions
at device creation time:
  * VK_KHR_device_group
  * VK_EXT_full_screen_exclusive
The loader needs to know about these extensions for proper handling
of the vkGetDeviceGroupSurfacePresentModes2EXT terminator
- Update known-good file

Updated:
- `loader/loader.c`
- `loader/loader.h`
- `scripts/common_codegen.py`
- `scripts/dispatch_table_helper_generator.py`
- `scripts/helper_file_generator.py`
- `scripts/known_good.json`
- `scripts/loader_extension_generator.py`
- `scripts/loader_genvk.py`

Change-Id: I9f0828a8eee0e8e95b479e1b8feb31acaa10040d
2019-04-08 16:38:37 -06:00
Lenny Komow
2a680fb27c loader: Change override mechanics
Previously, the override's layer list was treated as an authoritative
list of layers. Now it uses a whilelist/blacklist so the override can
enabled, disable, or leave a layer alone.

Change-Id: I58db219deb2b6355c56aeb2d00187ac79ad531c2
2019-04-05 11:34:10 -06:00
Tony-LunarG
0366721b5b repo: Remove MIR specific code
Note that references in scripts/common_codegen.py and
scripts/loader_extension_generator.py will need to be
removed later

Change-Id: I7b17c80f7a06a339d7df0c199ff556212a7c6534
2018-10-25 09:39:32 -06:00
Lenny Komow
40761b0913 loader: Override layer support and settings
Add support for an override layer in the loader. This allows layers
to be set by an outside application.

Revamp the logic to detect manifest files in the various paths that
we allow them to be placed. This code significantly rewrites
loader_get_manifest_files.

Change-Id: I8abf558864b66eb71ee026ca559b0126cf2fa4e9
2018-10-22 16:33:51 -06:00
Lenny Komow
700483f5d9 loader: Rework include dependencies
This change removes the assumption that vk_layer.h will include
vk_layer_dispatch_table.h, since it will be removed from vk_layer.h
in the near future.

Change-Id: I3fed5efbc35781c96aa9d0977d046c8555e04a7c
2018-07-05 16:02:37 -06:00
Lenny Komow
6113978aa3 loader: Add support for get display properties2
Change-Id: I14260b231dd097c85a99ab99c62876b868918869
2018-06-06 11:04:16 -06:00