Commit Graph

796 Commits

Author SHA1 Message Date
shegangbin
4603b3a932 standardize OH extension api
Signed-off-by: shegangbin <shegangbin1@huawei.com>
Change-Id: I854a1a67f1337482279c300dcc37f6637c638f7e
2023-06-19 11:42:13 +08:00
Charles Giessen
a88144de30 Correctly handle layers not being loaded in vkCreateDevice
This reverts the previous commit which reverted bad behavior.
2022-10-12 18:58:46 -06:00
Charles Giessen
a53232449e Revert "Don't load layer libraries in vkCreateDevice"
This reverts commit cd9b4afed4.
2022-10-12 16:22:24 -06:00
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
cd9b4afed4 Don't load layer libraries in vkCreateDevice
These libraries will always be loaded in vkCreateInstance, so we don't
need to load them again in vkCreateDevice. This has the added benefit
of not printing 'unloading library X' twice in the log.
2022-10-04 13:28:00 -06:00
Charles Giessen
55b1b3d07a Make old layer with new app API version warning clearer
The previous message incorrectly labled all layes as Explicit layers
and didn't indicate what the 'warning' was about very well.
2022-09-15 10:03:20 -06:00
Charles Giessen
2f87e2b3a5 Allow implicit layers for all API versions
This change makes the loader conform to the latests specification
update, 1.3.227, which removes the requirement that implicit layers
API version is at least as high as the application provided API
version.

This change reduces friction for layer developers and API users.
2022-09-08 13:48:46 -06:00
Charles Giessen
1bede3d1a0 Refactor loader_icd_scan()
Put all of the parsing for ICD Manifest data into a separate function.
This cleans it up by not requiring manual tracking of allocated resources
while parsing, and allow much saner 'skipping' of incorrect ICD's.

This commit also addresses an issue where OOM during ICD parsing wasn't
immediately ending parsing and returning.
2022-09-01 13:13:14 -06:00
Charles Giessen
ad5c8f5305 Remove redundant checks for NULL
Calling free() doesn't require checking for NULL, but many places were
checking for NULL before calling the appropriate freeing function.
2022-09-01 13:13:14 -06:00
Charles Giessen
1f2f222f60 Enable layer interception of unknown functions
Re-add previously reverted behavior that allows layers to setup dispatch chains for unknown physical
device and device functions during vkCreateInstance. Previously, functions not known to the loader could not
be queried by a layer during vkCreateInstance (when dispatch tables should be setup). The change adds support
for unknown functions in the trampolines of vkGetInstanceProcAddr and vkGetPhysicalDeviceProcAddr.

Unknown Device functions not listed in a layers manifest will now be found through vkGetInstanceProcAddr,
which was previously not used.
2022-09-01 12:23:17 -06:00
Charles Giessen
e19518e31f Rename GIPA, GPDPA, & GDPA terminators
Use more correct terminology for the various terminators of the
get proc addr functions. This makes it more obvious when each function
is being called, as well as removing the unecessary
loader_gpdpa_instance_internal.
2022-09-01 12:23:17 -06:00
Charles Giessen
192efa48a7 Dont pass portability bit to ICDs that dont expect it
There was a small issue with the initial version of the portability
enumeration extension where the portability enumeration flag bit would
be passed down to ICDs which did not expect flags to contain anything
other than zero.

While an argument could be made for those drivers to ignore flags they
do not recognize, just like extensions and other 'unknown' things, it
is best to play nice as this is the first instance creation flag bit
added.
2022-08-31 11:49:56 -06:00
Charles Giessen
16d5d8f254 Separate Major.minor version checks from Full version checks
loader_make_Version previously would decode the major, minor, and patch info out of version data. This results in
erroneous version checks that took into account patch version when they shouldn't of. The loader_make_full_version
function is introduced for code that wishes to get the full major.minor.patch version and uses of
loader_make_version that need the full version have been replaced.
2022-08-15 09:27:43 -06:00
Charles Giessen
d4801c93c5 Use memmove for copying pApplicationInfo
Replace memcpy with memmove in terminator_CreateInstance to prevent possible issues
with the same memory being the source of the copy and the dest, as there is a for
loop which makes it possible for that to happen.
2022-07-29 16:09:29 -06:00
Mike Schuchardt
4de4f256ab loader: Dynamically load Win8+ functions
Allow loader to run on Windows 7 by dynamically loading function
pointers for Windows 8 and above APIs.
2022-07-11 13:38:35 -06:00
Charles Giessen
9a45e5a4ab Disable VulkanOn12/Dozen in Windows 7
Chromium still supports building for Win7, as such the newly added support for
VulkanOn12/Dozen needs to be excluded from said build. This is achieved by using
the SDK version macros defined in <sdkddkver>
2022-07-08 13:32:14 -06:00
Charles Giessen
57d5dd568b Fix corrupted pNext chain in vkCreateDevice
When creating a device, the loader looks for the VkDeviceGroupCreateInfo
structure and replaces it with its own. This allows the loader to edit the
struct. However, to do this required editing the pNext chain. Because the
edited chain contained pointers to structures whose lifetimes end when the
vkCreateDevice function returns, the pNext chain is now corrupted.

This commit fixes that by storing a pointer to the user's
VkDeviceGroupCreateInfo and fixing up the pNext chain to use that instead.
2022-07-07 18:17:34 -06:00
Charles Giessen
d8af0ae227 Refactor vk_loader_platform.h
Move includes of vulkan headers into loader_common.h, delete dead code
and unnecessary macro defines, and generally clean up the header.
2022-07-07 14:41:01 -06:00
Jesse Natalie
26921924d6 Enable the Vulkan loader to load VulkanOn12/Dozen out of the D3DMappingLayers app package 2022-07-05 14:34:53 -06:00
Marcin Kańtoch
e91cfe1cf9 loader: device array dealloc fix 2022-06-24 14:08:04 -06:00
Andrew Naumov
5249c8f869 loader: Add unicode support 2022-06-24 13:14:10 -06:00
Charles Giessen
865626abba Add 32 & 64 bit field to json manifests
Allows drivers and layers to specify if they are 32 bit or 64 bit in the
manifest file. This makes the loader able to prune manifests without
loading the library and finding that it failed to load.
2022-06-22 10:28:18 -06:00
Charles Giessen
8d3d6d4e16 Fix use-after-free in loader_add_layer_properties
Occurs after file_vers is freed and when the layer manifest has a layers field
but has a version of 1.0.0.
2022-06-22 10:18:15 -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
e52b98e356 Keep allocated debug callbacks until destroy instance
Previously the loader would destroy any debug callbacks created during instance creation
to later create new ones during instance destruction. This required a memory allocation
to occur inside vkDestroyInstance, which can cause leaks if an OOM occurs during
instance destruction.

This commit simplifies the logic by keeping around the allocations made during instance
creation by moving them into their own debug node chain. Then during instance destruction
moves them back.

Also renames several functions to better describe their intended purpose.
2022-05-27 17:14:25 -06:00
Charles Giessen
b1478c3e73 Use calloc to allocate memory for the search path
This prevents bugs where uninitialized memory is treated as a real path. It
should fix an issue where sometimes CI would fail due to what appears to be a
spurious path with junk characters.
2022-05-27 11:12:46 -06:00
Charles Giessen
c2897084d2 Fix a NULL inst crashing during loader_icd_scan
When checking for the portability driver field of driver manifests,
the loader did not check if inst was NULL first. Since this function
is called in pre-instance functions, this crashes the loader.
2022-05-25 13:14:04 -06:00
Charles Giessen
2d15653773 Use calloc instead of alloc+memset
Replace naked uses of malloc & free with loader_alloc & loader_free.
2022-05-24 14:18:26 -06:00
Charles Giessen
9b355f1948 Use VkAllocationCallback in cJSON
Make cJSON pass the VkAllocationCallbacks instead of the loader_instance.
This removes and unecessary dependency between cJSON and the loader headers.
It also somewhat simplifies the interface by not requiring the inst parameter
everywhere, just in the creation of cJSON pointers and freeing.
2022-05-24 14:18:26 -06:00
Charles Giessen
0a2395df92 Use VkAllocationCallbacks in windows dirent
Pass the allocation callbacks directly to dirent_on_windows.
This removes a unecessary dependency between the loader headers and
dirent_on_windows.
2022-05-24 14:18:26 -06:00
Charles Giessen
e65a8bcaeb Refactor loader allocation functionality
Created wrapper functions loader_alloc, loader_calloc, loader_free,
and loader_realloc. Made the existing loader allocation functions use
them. Replaced manual usage of VkAllocatorCallbacks with the new
wrapper functions.
2022-05-24 14:18:26 -06:00
Charles Giessen
8dc9ab5ce8 Revert "Implement unknown function intercept in layers"
This reverts commit 0fd2ff8384.
2022-05-11 08:57:30 -06:00
Mark Young
08cad0c015 Output message if override app_keys mismatch on app name
Output a layer message if the override layer is present and the
app name is not in the app_keys list.
Fixes issue #917.
2022-05-05 16:46:41 -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
461f53cdb5 Fix CMake code for getting Git Version information
The ${CMAKE_SOURCE_DIR} uses the wrong directory when the loader is included as a
subproject. By using ${CMAKE_CURRENT_LIST_DIR}, the CMake code to find the git
commit and branch name will use the correct directory.

Additionally, the logic was ammended to curtail this issue in the future. Quotes are
included in the string to allow it to be used as a string literal, instead of
needing a const char[] variable and macros. Also, the CMake code was restructured
to always define GIT_BRANCH_NAME and GIT_TAG_INFO.
2022-05-04 14:46:53 -06:00
Charles Giessen
0fd2ff8384 Implement unknown function intercept in layers
Make it possible for layers to declare that they support unknown functions
and set up the layer dispatch table appropriately. A very niche use case
but helpful when developing validation for functions not yet out in the
public headers.
2022-05-03 17:38:09 -06:00
Charles Giessen
859fb722c2 Document VK_KHR_portability_enumeration support 2022-04-07 11:49:53 -06:00
Charles Giessen
717697987e Warn if portability_enumeration extension should be enabled
Log an error if an application creates a VkDevice from a physical device which
was enumerated from a driver that is a portability driver but the application
didn't correctly enable the portability enumeration flag & extension.
2022-04-06 18:25:09 -06:00
Charles Giessen
469aead205 Allow meta layers to have newer component layers
Relax the requirement that all component layers in a meta layer must equal the version of the meta layer.
This allows enabling layers that do not have the same API version as the meta layer.
2022-04-04 19:17:07 -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
d24a1045fd Fix missed Physical Devices in Windows
The previous logic would cause any non-sorted physical devices to be missed
when aggregating the final list. This caused crashes due to the phys_dev
value not being initialized. The fix is to make sure both sorted and non
sorted physical devices are included in the final output of
setup_loader_term_phys_devs().
2022-04-04 16:38:17 -06:00
Charles Giessen
f8c97eea2f Dont emit warnings on unknown manifest file versions
Since the loader is meant to be forward compatible, it makes little sense to emit
a warning when an ICD or Layer manifest is found with a version that it doesn't
understand. Thus they now are INFO level.
2022-03-31 11:54:03 -06:00
unknown
ca66d5aa8b Fixup several small issues found by Visual Studio
The VS Analyzer went through the codebase and pointed out a dozen warnings and
one possible crash.
2022-03-30 10:06:23 -06:00
Charles Giessen
336508b06b Enable /W4 errors and support clang-cl
Enable /W4 errors on MSVC and fix all corresponding errors.

Refactor the CMakeLists.txt to allow for compiling with clang-cl. This required
figuring out that -Wall -Wextra mangle the set of warnings used. The solution
is to use /W4 instead when compiling with clang-cl on Windows.
2022-03-29 16:10:30 -06:00
Mark Young
d72909ee28 Fix #888 crash in Lutris with Linux sorting
The sorting algorithm needed to take into account both the application
API version as well as the driver API version.

This required additional changes to the sorting algorithm for the fallback
since even if the instance supports the extension or Vulkan 1.1, the individual
drivers may not.

Also, add supporting tests which would catch these cases in the future.
In the process, I realized we assumed that the presence of an extension in the
test_icd indicated "enablement" which was incorrect.  So I separated out
that into a set of "enabled instance extensions"
2022-03-25 15:29:40 -06:00
Charles Giessen
8354f108f5 Remove LDP_DRIVER_6
The cause for this policy was due to dynamic linker behavior which could have
resulted in the wrong symbols being used. However, this didn't occur in
practical usage of the dynamic linker. Also drivers exporting Vulkan
entrypoints was a useful behavior to enable testing and more flexible usage
that this policy actively interfered with.
2022-03-25 11:52:46 -06:00
Mark Young
2d1860d238 Fix non-sorted surface indexing
The physical device terminator was missing the ICD index in the
non-sorted path.  This caused crashes in Angle before it was realized
that the sorting code was unintentionally disabled in that build
path.

Also, add tests to catch this case in the future in the WSI code, but
this required converting all the TEST_F tests to TEST since Gtest
didn't like mixing the 2 on my system.

Finally, fix a few WSI error messages in the loader which were
missing spaces.

Fixes #863 for non-sorting paths
2022-03-24 15:22:04 -06:00
Mark Young
d3ae7ffe1c Add device log info on vkCreateDevice
To make things clearer on output, log the device information for
the physical device being used on vkCreateDevice if either the
layer or the driver log bits are set.
2022-03-21 14:04:39 -06:00
Charles Giessen
38e9dc8faf Test framework now shims registry functions
Previously the way the test framework worked was to fake the registry using a
special windows API call. However this led to brittle tests and was incompatible
with googletest's death test capabilities.

These death tests highlighted that the current set of them didn't use the built in
matcher to verify a correct crash/abort. This commit also amends all uses of
ASSERT_DEATH to provide the relevant death message.

If a driver reports an interface version greater than 0 but doesn't export
vk_icdGetInstanceProcAddr, the loader will now skip the driver.
2022-03-14 23:31:26 -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