From 2d84525eaa5e82578f0b700449fd9611fbea290e Mon Sep 17 00:00:00 2001 From: GloriousEggroll Date: Sun, 7 Apr 2019 23:51:56 -0600 Subject: [PATCH] update this (a 3rd time) incase i missed something. this patch is tested and working. --- README.md | 339 +-- .../valve-winevulkan-patchset.patch | 2275 ++++++++++++++++- 2 files changed, 2245 insertions(+), 369 deletions(-) diff --git a/README.md b/README.md index b614745fc3..49ad6e43e9 100644 --- a/README.md +++ b/README.md @@ -1,269 +1,74 @@ ---- -Introduction ---- -Proton is a tool for use with the Steam client which allows games which are -exclusive to Windows to run on the Linux operating system. It uses Wine to -facilitate this. +This is my build of Proton which the most recent release of vanilla wine, has ffmpeg enabled for faudio by default, and all of Proton's patches ported over to be applied to vanilla wine. + +All patches: +-Warframe launcher loop patch +-DXVK Async patch applied and enabled specifically for warframe +-Mech Warrior online patch +-Resident Evil 4 patch +-World of Final Fantasy patch +-Skyrim SE/Fallout 4 script extender patch +-kde plasma systemtray fix patch +-FAudio with FFMpeg enabled (fixes audio/voices in multiple games) +-All of Valve's wine proton patches. Yes. All of them. I got quite a few of them from TKG, and parsed the remaining patches myself from their git commits. + +Building Proton in a nutshell: + +1. Install virtualbox and its kernel modules, make sure they are enabled at boot +2. Install vagrant +3. Clone this repo: +`git clone http://github.com/gloriouseggroll/proton-ge-custom` +4. Initiate the submodules in the cloned repo: +``` +cd proton-ge-custom +git submodule update --init +``` +5. Drop any custom patches into game-patches-testing/, then open game-patches-testing/proton-prep.sh and + add a patch line for them under #WINE CUSTOM PATCHES in the same way the others are done. + +6. Apply all of the patches in /game patches/testing by running: +``` +./game-patches-testing/proton-prep.sh &> patchlog.txt +``` +in the main proton-ge-custom directory. Open patchlog.txt and search "fail" to make sure no patch failures occured. + +7. in a terminal and type: + +`vagrant up` (this will take a while on the first run, as it prepares everything) +`vagrant ssh` (this will ssh you into the vagrant VM + +To leave the VM at any time just type `exit` + +NOTE ON MODIFICATIONS: +vagrant syncs the proton directory to any files in the cloned repo. So, if you want to make changes, close the VM with `vagrant halt`, make your changes, then launch vagrant again with `vagrant up` + +8. Edit the build name and build proton +``` +cd ~/build +nano Makefile +``` +Change the BUILD_NAME to whatever you want, then save & exit + +9. Build proton +``` +cd ~/build +make all dist +``` +10. Rename the dist folder to your BUILD_NAME, then tar it for easier distribution: +``` +mv dist Proton-Custom-Name +tar -cvzf Proton-Custom-Name.tar.gz Proton-Custom-Name/ +``` + +11. Move it to the /vagrant folder. This folder is accessible on your main system in the vagrant_share folder inside the cloned repository folder: + +`mv Proton-Custom-Name.tar.gz /vagrant/` + +12. Shut down the VM: +``` +exit +vagrant halt +``` + +13. Now open vagrant_share inside the cloned repo folder on your main system. Extract the tarball into `~/.steam/root/compatibilitytools.d/`, and restart steam. You will have to create the compatibilitytools.d folder. -Most users will prefer to use Proton provided by the Steam client itself. The -source code is provided to enable advanced users the ability to alter -Proton. For example, some users may wish to use a different version of Wine with -a particular title. ---- -Getting Started with Proton from Steam Play ---- -* As the new Steam Play is still in Beta, it is recommended that you opt into the [Steam Client Beta](https://steamcommunity.com/sharedfiles/filedetails/?id=182912431) for the latest features and fixes. -* Proton requires graphics drivers that are more recent than what is typically packaged in most distributions; please read the [list of requirements and quickstart for Ubuntu 18.04 users](https://github.com/ValveSoftware/Proton/wiki/Requirements) -* Install and play games! Please refer to [this post](https://steamcommunity.com/games/221410/announcements/detail/1696055855739350561) for more information. -* Visit the [changelog](https://github.com/ValveSoftware/Proton/wiki/Changelog) for information about recent updates. - ---- -Obtaining Proton from source ---- -**NOTE:** If you are not comfortable in a command line terminal, or if you find -any of the information presented in here strange and uncomfortable, then -this is probably not for you. The instructions are likely to be incomplete -and require some knowledge and skill on your part, and there is no warranty -or guarantee that anyone will help you with this process. - -We strongly recommend that most users use the production build of Proton. - -The most current source for Proton is here: - - -Which you can clone to your system with this command: - - git clone https://github.com/ValveSoftware/Proton.git proton - -After cloning the Proton git repository, the next step will be to -obtain the various submodules that go into building Proton: - - cd proton - git submodule update --init - -If you wish to change any subcomponent, now is the time to do so. -For example, if you wish make changes to Wine, you would apply those -changes to the wine/ directory. - ---- -Easy build path ---- - -Building Proton is quite complicated. We provide a top-level Makefile which -will execute most of the build commands for you. This section describes how to -use this Makefile for simple Proton builds. - -This Makefile uses a virtual machine to create a consistent build environment. -The VM is managed with [Vagrant](https://www.vagrantup.com/), which you will -need to install before invoking these commands. While Vagrant supports several -VM software backends, Proton's build system has been tested only with its -VirtualBox backend. You may run into problems with the shared folder -(`vagrant_share`) and/or CPU and memory usage with other backends. - -If your build VM gets cluttered, or falls out of date, you can use `vagrant -destroy` to wipe the VM clean, then invoke one of the below commands to start -over. - -After checking out Proton and updating its submodules, you can use these -targets to build Proton: - -`make install` - This will install Proton into your user's Steam directory. -You may need to restart the Steam client to see it. The tool's name in the -Steam client will be based on the currently checked out branch of Proton. You -can override this name using the `build_name` variable. - -`make deploy` - This will create a deployment tarball and set of files which -can be distributed as a Proton package. This is what we use to deploy Proton to -Steam users. The package will be dropped into a new directory in -`vagrant_share/`, named after the nearest Git tag (see `git describe`). - -`make clean` - This will completely erase the build tree. - -`make help` - View the Makefile documentation and examples. - -We also provide targets useful for simple Wine development: - -`make proton` - This will build Proton without copying its files out of the VM. - -`make module= module` - This will build both 32- and 64-bit versions of -the specified module, and copy the result into the `vagrant_share` directory. -This allows rapid iteration on one module. This target is only useful after -building Proton. - -If you are doing significant Wine development or want to control the build with -more fine detail, see the full documentation below. - ---- -Building ---- -At a high level, the build instructions are: - -1. Set up your build environment -1. Configure the build -1. Build Proton -1. Install Proton locally (optional) - -See below for more details on all of these steps. Please read all of the -instructions before proceeding. - ---- -Set up the build environment ---- -Proton has a lot of build-time dependencies. The following instructions -describe how we create the build environment for the production builds of -Proton. For reproducibility and security reasons, we will be setting up a -Debian 9 virtual machine. However, you should be able to follow these -instructions on other distributions as well. - -Proton provides a Vagrantfile, which will automatically set up the Debian 9 VM -for you. After installing [Vagrant](https://www.vagrantup.com/), initialize the -VM by running from within the Proton directory: - - vagrant up - -It will take a long time to download and install the Steam runtime containers -and so on. Eventually it will complete. You can SSH into the virtual machine -with: - - vagrant ssh - -At this point you will need to configure the build directory. See below. - -The Vagrantfile is set up to rsync the `proton` directory into the VM on boot. -On the host machine, you can use `vagrant rsync-auto` to have Vagrant -automatically sync changes on your host machine into the build machine. It is -recommended that you make changes on your host machine, and then perform the -build in the VM. Any changes you make in the `proton` directory on the VM may -be overwritten by later rsync updates from the host machine. - -The Vagrantfile also creates a directory called `vagrant_share` in the `proton` -directory of your host machine, which is mounted at `/vagrant` within the VM. -You can use this shared folder to move your Proton build out of the VM, or as -one way to copy files into the VM. - -When you are done with the VM, you can shut it down from the host machine: - - vagrant halt - -Please read the Vagrant documentation for more information about how to use -Vagrant VMs. - -If you do not wish to use Vagrant, you can read through both Vagrantfile and -`vagrant-user-setup.sh` for the list of dependencies and instructions on how to -set up your own machine or another VM of your choosing. It is aimed at Debian -9, but you should be able to adapt them for other distributions. - ---- -Alternative: Building without the Steam Runtime ---- -The Steam Runtime provides a clean and consistent set of libraries. Software -distributed through Steam should depend only on libraries available through the -runtime, and so we build in that environment for production Proton builds. The -Vagrantfile described above will set this up for you. However, if you are -simply making a build for yourself, you may want to skip setting up the Steam -runtime, as it takes a very long time to set up. To do this, edit the -`vagrant-user-setup.sh` script appropriately before running `vagrant up`. - ---- -Configure the build ---- -After setting up the build system, it is time to run the configure script which -will generate the Makefile to build your project. Run these steps. You may of -course use whatever paths you like. - - mkdir build/ - cd build - ../proton/configure.sh --steam-runtime64=docker:steam-proton-dev --steam-runtime32=docker:steam-proton-dev32 --steam-runtime=$HOME/steam-runtime/runtime/ - -If you are building without the Steam runtime, then instead use: - - ../proton/configure.sh --no-steam-runtime - -**Tip**: If you are building without the Steam runtime, you should now run -`make obj-wine64/Makefile obj-wine32/Makefile` and check the files -`obj-wine64/config.log` and `obj-wine32/config.log` for missing packages. -Search for `won't be supported`. A couple of missing packages are normal: -`opencv`, `gstreamer`, `vkd3d`, `oss`. More than that may indicate a problem. -Please see your distro's documentation to acquire the considerable build -dependencies for Wine. - ---- -Build Proton ---- -A couple of Makefile targets are provided. - -`make dist` will create a Proton installation in `dist/` that you can install -manually (see below), or automatically with `make install`. - -`make deploy` will package Proton up for distribution via Steamworks. - ---- -Install Proton locally ---- -Steam ships with several versions of Proton, which games will use by default or -that you can select in Steam Settings's SteamPlay page. Steam also supports -running games with local builds of Proton, which you can install on your -machine. The `install` target will perform the below steps for you. - -To install a local build of Proton into Steam, make a new directory in -`~/.steam/root/compatibilitytools.d/` with a tool name of your choosing and -place the contents of `dist` into that folder. The `make install` target will -perform this task for you, installing the Proton build into the Steam folder -for the current user. You will have to restart the Steam client for it to pick -up on a new tool. - -A correct local tool installation should look like this: - - compatibilitytools.d/my_proton/ - ├── compatibilitytool.vdf - ├── filelock.py - ├── LICENSE - ├── proton - ├── proton_dist.tar.gz - ├── toolmanifest.vdf - ├── user_settings.sample.py - └── version - -To enable your local build in Steam, go to the Steam Play section of the -Settings window. If the build was correctly installed, you should see -"proton-localbuild" in the drop-down list of compatibility tools. - -Each component of this software is used under the terms of their licenses. See -the LICENSE files here, as well as the LICENSE, -COPYING, etc files in each submodule and directory for details. If you -distribute a built version of Proton to other users, you must adhere to the -terms of these licenses. - ----- -Runtime Config Options ----- -Proton can be tuned at runtime to help certain games run. The Steam client sets -some options for known games using the STEAM_COMPAT_CONFIG variable. -You can override these options using the environment variables described below. -The best way to set these environment overrides for all games is by renaming -`user_settings.sample.py` to `user_settings.py` and modifying it appropriately. -If you want to change the runtime configuration for a specific game, you can -use the `Set Launch Options` setting in the game's `Properties` dialog in the Steam client. You can launch the -game as you would with "`PROTON_VARIABLE=1 %command%`" [(source)](https://superuser.com/questions/954041/how-to-set-an-environment-variable-for-an-specific-game-on-steam-for-linux#980437). - -To enable an option, set the variable to a non-0 value. To disable an -option, set the variable to 0. To use Steam's default configuration, do -not specify the variable at all. - -All of the below are runtime options. They do not effect permanent changes to -the Wine prefix. Removing the option will revert to the previous behavior. - -| Compat config string | Environment Variable | Description | -| :-------------------- | :----------------------------- | :----------- | -| | PROTON_LOG | Convenience method for dumping a useful debug log to `$HOME/steam-$APPID.log`. For more thorough logging, use `user_settings.py`. | -| | PROTON_DUMP_DEBUG_COMMANDS | When running a game, Proton will write some useful debug scripts for that game into `$PROTON_DEBUG_DIR/proton_$USER/`. | -| | PROTON_DEBUG_DIR | Root directory for the Proton debug scripts, `/tmp` by default. | -| wined3d | PROTON_USE_WINED3D | Use OpenGL-based wined3d instead of Vulkan-based DXVK for d3d11 and d3d10. This used to be called `PROTON_USE_WINED3D11`, which is now an alias for this same option. | -| nod3d11 | PROTON_NO_D3D11 | Disable d3d11.dll, for d3d11 games which can fall back to and run better with d3d9. | -| nod3d10 | PROTON_NO_D3D10 | Disable d3d10.dll and dxgi.dll, for d3d10 games which can fall back to and run better with d3d9. | -| noesync | PROTON_NO_ESYNC | Do not use eventfd-based in-process synchronization primitives. | -| forcelgadd | PROTON_FORCE_LARGE_ADDRESS_AWARE | Force Wine to enable the LARGE_ADDRESS_AWARE flag for all executables. | -| oldglstr | PROTON_OLD_GL_STRING | Set some driver overrides to limit the length of the GL extension string, for old games that crash on very long extension strings. | - - diff --git a/game-patches-testing/valve-winevulkan-patchset.patch b/game-patches-testing/valve-winevulkan-patchset.patch index 520d7dd7e8..f6da4ac090 100644 --- a/game-patches-testing/valve-winevulkan-patchset.patch +++ b/game-patches-testing/valve-winevulkan-patchset.patch @@ -861,16 +861,16 @@ index c714664de0e..c2a5641ef32 100644 VkResult WINAPI wine_vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName, uint32_t *pPropertyCount, VkExtensionProperties *pProperties); VkResult WINAPI wine_vkEnumeratePhysicalDeviceGroups(VkInstance instance, uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties); VkResult WINAPI wine_vkEnumeratePhysicalDeviceGroupsKHR(VkInstance instance, uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties) DECLSPEC_HIDDEN; -@@ -56,6 +60,9 @@ void WINAPI wine_vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool - PFN_vkVoidFunction WINAPI wine_vkGetDeviceProcAddr(VkDevice device, const char *pName); - void WINAPI wine_vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue *pQueue); - void WINAPI wine_vkGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue); +@@ -64,6 +68,9 @@ void WINAPI wine_vkGetPhysicalDeviceExternalSemaphoreProperties(VkPhysicalDevice + void WINAPI wine_vkGetPhysicalDeviceExternalSemaphorePropertiesKHR(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalSemaphoreInfo *pExternalSemaphoreInfo, VkExternalSemaphoreProperties *pExternalSemaphoreProperties) DECLSPEC_HIDDEN; + VkResult WINAPI wine_vkGetPhysicalDeviceImageFormatProperties2(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceImageFormatInfo2 *pImageFormatInfo, VkImageFormatProperties2 *pImageFormatProperties); + VkResult WINAPI wine_vkGetPhysicalDeviceImageFormatProperties2KHR(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceImageFormatInfo2 *pImageFormatInfo, VkImageFormatProperties2 *pImageFormatProperties) DECLSPEC_HIDDEN; +VkResult WINAPI wine_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, VkSurfaceCapabilitiesKHR *pSurfaceCapabilities); +VkResult WINAPI wine_vkGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages); +VkResult WINAPI wine_vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo); - void WINAPI wine_vkGetPhysicalDeviceExternalBufferProperties(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalBufferInfo *pExternalBufferInfo, VkExternalBufferProperties *pExternalBufferProperties); - void WINAPI wine_vkGetPhysicalDeviceExternalBufferPropertiesKHR(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalBufferInfo *pExternalBufferInfo, VkExternalBufferProperties *pExternalBufferProperties) DECLSPEC_HIDDEN; - void WINAPI wine_vkGetPhysicalDeviceExternalFenceProperties(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalFenceInfo *pExternalFenceInfo, VkExternalFenceProperties *pExternalFenceProperties); + VkResult WINAPI wine_vkQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits, VkFence fence); + + /* Private thunks */ @@ -746,6 +753,13 @@ typedef struct VkCopyDescriptorSet_host } VkCopyDescriptorSet_host; @@ -3185,113 +3185,2184 @@ index c06774a27fa..145635eea24 100644 VkRect2D blit_dst; VkCommandPool *cmd_pools; /* VkCommandPool[device->max_queue_families] */ VkDeviceMemory user_image_memory, blit_image_memory; -From 61fb2be6fa62f3b4b40f27f6a46343ddc2471e60 Mon Sep 17 00:00:00 2001 +From 0474bf7356a96915579e089cf16b6c3811ce6b45 Mon Sep 17 00:00:00 2001 From: Andrew Eikum -Date: Tue, 25 Sep 2018 14:53:00 -0500 -Subject: [PATCH] Revert "winevulkan: Check if instance extensions are - supported." - -This reverts commit e84999bd7ab859746e893ed2d49b1d42b0323c3a. +Date: Thu, 12 Apr 2018 14:07:26 -0500 +Subject: [PATCH] winevulkan: Implement fs hack -Vulkan VR games will try to load some extensions that winevulkan doesn't -support. --- - dlls/winevulkan/vulkan.c | 21 ++++----------------- - 1 file changed, 4 insertions(+), 17 deletions(-) + dlls/winevulkan/make_vulkan | 17 +- + dlls/winevulkan/vulkan.c | 1228 +++++++++++++++++++++++++++++- + dlls/winevulkan/vulkan_private.h | 28 + + dlls/winevulkan/vulkan_thunks.c | 126 +-- + dlls/winevulkan/vulkan_thunks.h | 3 - + dlls/winex11.drv/vulkan.c | 34 + + include/wine/vulkan_driver.h | 7 + + 7 files changed, 1365 insertions(+), 78 deletions(-) +diff --git a/dlls/winevulkan/make_vulkan b/dlls/winevulkan/make_vulkan +index b1ab1bf0dbc..076b50f58f0 100755 +--- a/dlls/winevulkan/make_vulkan ++++ b/dlls/winevulkan/make_vulkan +@@ -2017,9 +2017,14 @@ class VkGenerator(object): + # Generate any conversion helper functions. + f.write("#if defined(USE_STRUCT_CONVERSION)\n") + for conv in self.conversions: +- f.write(conv.definition()) ++ if not conv.shared: ++ f.write(conv.definition()) + f.write("#endif /* USE_STRUCT_CONVERSION */\n\n") + ++ for conv in self.conversions: ++ if conv.shared: ++ f.write(conv.definition()) ++ + # Create thunks for instance and device functions. + # Global functions don't go through the thunks. + for vk_func in self.registry.funcs.values(): +@@ -2145,11 +2150,9 @@ class VkGenerator(object): + f.write(struct.definition(align=False, conv=True, postfix="_host")) + f.write("\n") + +- f.write("#if defined(USE_STRUCT_CONVERSION)\n") + for conv in self.conversions: + if conv.shared: + f.write(conv.prototype()) +- f.write("#endif /* USE_STRUCT_CONVERSION */\n\n") + + f.write("/* For use by vkDevice and children */\n") + f.write("struct vulkan_device_funcs\n{\n") +@@ -2344,6 +2347,14 @@ class VkGenerator(object): + # stuff in there. For simplicity substitute with "void *". + pfn = pfn.replace("PFN_vkVoidFunction", "void *") + f.write(" {0};\n".format(pfn)) ++ ++ f.write("\n /* Optional. Returns TRUE if FS hack is active, otherwise returns FALSE. If\n") ++ f.write(" * it returns TRUE, then real_sz will contain the actual display\n") ++ f.write(" * resolution; user_sz will contain the app's requested mode; and dst_blit\n") ++ f.write(" * will contain the area to blit the user image to in real coordinates.\n") ++ f.write(" * All parameters are optional. */\n") ++ f.write(" VkBool32 (*query_fs_hack)(VkExtent2D *real_sz, VkExtent2D *user_sz, VkRect2D *dst_blit);\n") ++ + f.write("};\n\n") + + f.write("extern const struct vulkan_funcs * CDECL __wine_get_vulkan_driver(HDC hdc, UINT version);\n\n") diff --git a/dlls/winevulkan/vulkan.c b/dlls/winevulkan/vulkan.c -index 398fbac93eb..73a3023a522 100644 +index d433f090471..313bf8f78dc 100644 --- a/dlls/winevulkan/vulkan.c +++ b/dlls/winevulkan/vulkan.c -@@ -360,7 +360,7 @@ static BOOL wine_vk_init(void) - * This function takes care of extensions handled at winevulkan layer, a Wine graphics - * driver is responsible for handling e.g. surface extensions. +@@ -18,6 +18,7 @@ */ --static VkResult wine_vk_instance_convert_create_info(const VkInstanceCreateInfo *src, -+static void wine_vk_instance_convert_create_info(const VkInstanceCreateInfo *src, - VkInstanceCreateInfo *dst) - { - unsigned int i; -@@ -401,19 +401,11 @@ static VkResult wine_vk_instance_convert_create_info(const VkInstanceCreateInfo - dst->enabledLayerCount = 0; - dst->ppEnabledLayerNames = NULL; -- TRACE("Enabled %u instance extensions.\n", dst->enabledExtensionCount); -+ TRACE("Enabled extensions: %u\n", dst->enabledExtensionCount); - for (i = 0; i < dst->enabledExtensionCount; i++) - { -- const char *extension_name = dst->ppEnabledExtensionNames[i]; -- TRACE("Extension %u: %s.\n", i, debugstr_a(extension_name)); -- if (!wine_vk_instance_extension_supported(extension_name)) -- { -- WARN("Extension %s is not supported.\n", debugstr_a(extension_name)); -- return VK_ERROR_EXTENSION_NOT_PRESENT; -- } -+ TRACE("Extension %u: %s\n", i, debugstr_a(dst->ppEnabledExtensionNames[i])); - } -- -- return VK_SUCCESS; - } + #include ++#include - /* Helper function which stores wrapped physical devices in the instance object. */ -@@ -724,12 +716,7 @@ VkResult WINAPI wine_vkCreateInstance(const VkInstanceCreateInfo *create_info, + #include "windef.h" + #include "winbase.h" +@@ -330,6 +331,7 @@ static void wine_vk_device_free(struct VkDevice_T *device) + device->funcs.p_vkDestroyDevice(device->device, NULL /* pAllocator */); } - object->base.loader_magic = VULKAN_ICD_MAGIC_VALUE; -- res = wine_vk_instance_convert_create_info(create_info, &create_info_host); -- if (res != VK_SUCCESS) -- { -- wine_vk_instance_free(object); -- return res; -- } -+ wine_vk_instance_convert_create_info(create_info, &create_info_host); ++ heap_free(device->queue_props); + heap_free(device->swapchains); + DeleteCriticalSection(&device->swapchain_lock); - res = vk_funcs->p_vkCreateInstance(&create_info_host, NULL /* allocator */, &object->instance); - if (res != VK_SUCCESS) -From cdded00e22815367a63af811a577c06651277cf9 Mon Sep 17 00:00:00 2001 -From: Andrew Eikum -Date: Tue, 25 Sep 2018 14:53:05 -0500 -Subject: [PATCH] Revert "winevulkan: Check if device extensions are - supported." - -This reverts commit 4907ffdf2a15ab3a1e3749def37f4be67b758a35. - -Vulkan VR games will try to load some extensions that winevulkan doesn't -support. ---- - dlls/winevulkan/vulkan.c | 13 +++---------- - 1 file changed, 3 insertions(+), 10 deletions(-) - -diff --git a/dlls/winevulkan/vulkan.c b/dlls/winevulkan/vulkan.c -index 73a3023a522..cc2d9146282 100644 ---- a/dlls/winevulkan/vulkan.c -+++ b/dlls/winevulkan/vulkan.c -@@ -279,16 +279,10 @@ static VkResult wine_vk_device_convert_create_info(const VkDeviceCreateInfo *src - dst->enabledLayerCount = 0; - dst->ppEnabledLayerNames = NULL; +@@ -1284,8 +1286,23 @@ void *native_vkGetInstanceProcAddrWINE(VkInstance instance, const char *name) -- TRACE("Enabled %u extensions.\n", dst->enabledExtensionCount); -+ TRACE("Enabled extensions: %u.\n", dst->enabledExtensionCount); - for (i = 0; i < dst->enabledExtensionCount; i++) - { -- const char *extension_name = dst->ppEnabledExtensionNames[i]; -- TRACE("Extension %u: %s.\n", i, debugstr_a(extension_name)); -- if (!wine_vk_device_extension_supported(extension_name)) -- { -- WARN("Extension %s is not supported.\n", debugstr_a(extension_name)); -- return VK_ERROR_EXTENSION_NOT_PRESENT; -- } -+ TRACE("Extension %u: %s.\n", i, debugstr_a(dst->ppEnabledExtensionNames[i])); - } + VkResult WINAPI wine_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) + { ++ VkResult res; ++ VkExtent2D user_res; ++ + TRACE("%p, 0x%s, %p\n", physicalDevice, wine_dbgstr_longlong(surface), pSurfaceCapabilities); +- return physicalDevice->instance->funcs.p_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice->phys_dev, surface, pSurfaceCapabilities); ++ ++ res = physicalDevice->instance->funcs.p_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice->phys_dev, surface, pSurfaceCapabilities); ++ if(res != VK_SUCCESS) ++ return res; ++ ++ if(vk_funcs->query_fs_hack && ++ vk_funcs->query_fs_hack(NULL, &user_res, NULL)){ ++ pSurfaceCapabilities->currentExtent = user_res; ++ pSurfaceCapabilities->minImageExtent = user_res; ++ pSurfaceCapabilities->maxImageExtent = user_res; ++ } ++ ++ return VK_SUCCESS; + } - return VK_SUCCESS; -@@ -625,8 +619,7 @@ VkResult WINAPI wine_vkCreateDevice(VkPhysicalDevice phys_dev, - res = wine_vk_device_convert_create_info(create_info, &create_info_host); - if (res != VK_SUCCESS) - { -- if (res != VK_ERROR_EXTENSION_NOT_PRESENT) -- ERR("Failed to convert VkDeviceCreateInfo, res=%d.\n", res); -+ ERR("Failed to convert VkDeviceCreateInfo, res=%d.\n", res); - wine_vk_device_free(object); - return res; - } + VkResult WINAPI wine_vkAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) +@@ -1323,6 +1340,336 @@ static inline void convert_VkSwapchainCreateInfoKHR_win_to_host(const VkSwapchai + out->oldSwapchain = in->oldSwapchain; + } + ++/* ++#version 450 ++ ++layout(binding = 0) uniform sampler2D texSampler; ++layout(binding = 1, rgba8) uniform writeonly image2D outImage; ++layout(push_constant) uniform pushConstants { ++ //both in real image coords ++ vec2 offset; ++ vec2 extents; ++} constants; ++ ++layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; ++ ++void main() ++{ ++ vec2 texcoord = (vec2(gl_GlobalInvocationID.xy) - constants.offset) / constants.extents; ++ vec4 c = texture(texSampler, texcoord); ++ imageStore(outImage, ivec2(gl_GlobalInvocationID.xy), c.bgra); ++} ++*/ ++const uint32_t blit_comp_spv[] = { ++ 0x07230203,0x00010000,0x00080006,0x00000037,0x00000000,0x00020011,0x00000001,0x0006000b, ++ 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, ++ 0x0006000f,0x00000005,0x00000004,0x6e69616d,0x00000000,0x0000000d,0x00060010,0x00000004, ++ 0x00000011,0x00000008,0x00000008,0x00000001,0x00030003,0x00000002,0x000001c2,0x00040005, ++ 0x00000004,0x6e69616d,0x00000000,0x00050005,0x00000009,0x63786574,0x64726f6f,0x00000000, ++ 0x00080005,0x0000000d,0x475f6c67,0x61626f6c,0x766e496c,0x7461636f,0x496e6f69,0x00000044, ++ 0x00060005,0x00000012,0x68737570,0x736e6f43,0x746e6174,0x00000073,0x00050006,0x00000012, ++ 0x00000000,0x7366666f,0x00007465,0x00050006,0x00000012,0x00000001,0x65747865,0x0073746e, ++ 0x00050005,0x00000014,0x736e6f63,0x746e6174,0x00000073,0x00030005,0x00000021,0x00000063, ++ 0x00050005,0x00000025,0x53786574,0x6c706d61,0x00007265,0x00050005,0x0000002c,0x4974756f, ++ 0x6567616d,0x00000000,0x00040047,0x0000000d,0x0000000b,0x0000001c,0x00050048,0x00000012, ++ 0x00000000,0x00000023,0x00000000,0x00050048,0x00000012,0x00000001,0x00000023,0x00000008, ++ 0x00030047,0x00000012,0x00000002,0x00040047,0x00000025,0x00000022,0x00000000,0x00040047, ++ 0x00000025,0x00000021,0x00000000,0x00040047,0x0000002c,0x00000022,0x00000000,0x00040047, ++ 0x0000002c,0x00000021,0x00000001,0x00030047,0x0000002c,0x00000019,0x00040047,0x00000036, ++ 0x0000000b,0x00000019,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00030016, ++ 0x00000006,0x00000020,0x00040017,0x00000007,0x00000006,0x00000002,0x00040020,0x00000008, ++ 0x00000007,0x00000007,0x00040015,0x0000000a,0x00000020,0x00000000,0x00040017,0x0000000b, ++ 0x0000000a,0x00000003,0x00040020,0x0000000c,0x00000001,0x0000000b,0x0004003b,0x0000000c, ++ 0x0000000d,0x00000001,0x00040017,0x0000000e,0x0000000a,0x00000002,0x0004001e,0x00000012, ++ 0x00000007,0x00000007,0x00040020,0x00000013,0x00000009,0x00000012,0x0004003b,0x00000013, ++ 0x00000014,0x00000009,0x00040015,0x00000015,0x00000020,0x00000001,0x0004002b,0x00000015, ++ 0x00000016,0x00000000,0x00040020,0x00000017,0x00000009,0x00000007,0x0004002b,0x00000015, ++ 0x0000001b,0x00000001,0x00040017,0x0000001f,0x00000006,0x00000004,0x00040020,0x00000020, ++ 0x00000007,0x0000001f,0x00090019,0x00000022,0x00000006,0x00000001,0x00000000,0x00000000, ++ 0x00000000,0x00000001,0x00000000,0x0003001b,0x00000023,0x00000022,0x00040020,0x00000024, ++ 0x00000000,0x00000023,0x0004003b,0x00000024,0x00000025,0x00000000,0x0004002b,0x00000006, ++ 0x00000028,0x00000000,0x00090019,0x0000002a,0x00000006,0x00000001,0x00000000,0x00000000, ++ 0x00000000,0x00000002,0x00000004,0x00040020,0x0000002b,0x00000000,0x0000002a,0x0004003b, ++ 0x0000002b,0x0000002c,0x00000000,0x00040017,0x00000030,0x00000015,0x00000002,0x0004002b, ++ 0x0000000a,0x00000034,0x00000008,0x0004002b,0x0000000a,0x00000035,0x00000001,0x0006002c, ++ 0x0000000b,0x00000036,0x00000034,0x00000034,0x00000035,0x00050036,0x00000002,0x00000004, ++ 0x00000000,0x00000003,0x000200f8,0x00000005,0x0004003b,0x00000008,0x00000009,0x00000007, ++ 0x0004003b,0x00000020,0x00000021,0x00000007,0x0004003d,0x0000000b,0x0000000f,0x0000000d, ++ 0x0007004f,0x0000000e,0x00000010,0x0000000f,0x0000000f,0x00000000,0x00000001,0x00040070, ++ 0x00000007,0x00000011,0x00000010,0x00050041,0x00000017,0x00000018,0x00000014,0x00000016, ++ 0x0004003d,0x00000007,0x00000019,0x00000018,0x00050083,0x00000007,0x0000001a,0x00000011, ++ 0x00000019,0x00050041,0x00000017,0x0000001c,0x00000014,0x0000001b,0x0004003d,0x00000007, ++ 0x0000001d,0x0000001c,0x00050088,0x00000007,0x0000001e,0x0000001a,0x0000001d,0x0003003e, ++ 0x00000009,0x0000001e,0x0004003d,0x00000023,0x00000026,0x00000025,0x0004003d,0x00000007, ++ 0x00000027,0x00000009,0x00070058,0x0000001f,0x00000029,0x00000026,0x00000027,0x00000002, ++ 0x00000028,0x0003003e,0x00000021,0x00000029,0x0004003d,0x0000002a,0x0000002d,0x0000002c, ++ 0x0004003d,0x0000000b,0x0000002e,0x0000000d,0x0007004f,0x0000000e,0x0000002f,0x0000002e, ++ 0x0000002e,0x00000000,0x00000001,0x0004007c,0x00000030,0x00000031,0x0000002f,0x0004003d, ++ 0x0000001f,0x00000032,0x00000021,0x0009004f,0x0000001f,0x00000033,0x00000032,0x00000032, ++ 0x00000002,0x00000001,0x00000000,0x00000003,0x00040063,0x0000002d,0x00000031,0x00000033, ++ 0x000100fd,0x00010038 ++}; ++ ++static VkResult create_pipeline(VkDevice device, struct VkSwapchainKHR_T *swapchain, struct fs_hack_image *hack, VkShaderModule shaderModule) ++{ ++ VkResult res; ++#if defined(USE_STRUCT_CONVERSION) ++ VkComputePipelineCreateInfo_host pipelineInfo = {0}; ++#else ++ VkComputePipelineCreateInfo pipelineInfo = {0}; ++#endif ++ ++ pipelineInfo.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO; ++ pipelineInfo.stage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; ++ pipelineInfo.stage.stage = VK_SHADER_STAGE_COMPUTE_BIT; ++ pipelineInfo.stage.module = shaderModule; ++ pipelineInfo.stage.pName = "main"; ++ pipelineInfo.layout = swapchain->pipeline_layout; ++ pipelineInfo.basePipelineHandle = VK_NULL_HANDLE; ++ pipelineInfo.basePipelineIndex = -1; ++ ++ res = device->funcs.p_vkCreateComputePipelines(device->device, VK_NULL_HANDLE, 1, &pipelineInfo, NULL, &hack->pipeline); ++ if(res != VK_SUCCESS){ ++ ERR("vkCreateComputePipelines: %d\n", res); ++ return res; ++ } ++ ++ return VK_SUCCESS; ++} ++ ++static VkResult create_descriptor_set(VkDevice device, struct VkSwapchainKHR_T *swapchain, struct fs_hack_image *hack) ++{ ++ VkResult res; ++#if defined(USE_STRUCT_CONVERSION) ++ VkDescriptorSetAllocateInfo_host descriptorAllocInfo = {0}; ++ VkWriteDescriptorSet_host descriptorWrites[2] = {{0}, {0}}; ++ VkDescriptorImageInfo_host userDescriptorImageInfo = {0}, realDescriptorImageInfo = {0}; ++#else ++ VkDescriptorSetAllocateInfo descriptorAllocInfo = {0}; ++ VkWriteDescriptorSet descriptorWrites[2] = {{0}, {0}}; ++ VkDescriptorImageInfo userDescriptorImageInfo = {0}, realDescriptorImageInfo = {0}; ++#endif ++ ++ descriptorAllocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; ++ descriptorAllocInfo.descriptorPool = swapchain->descriptor_pool; ++ descriptorAllocInfo.descriptorSetCount = 1; ++ descriptorAllocInfo.pSetLayouts = &swapchain->descriptor_set_layout; ++ ++ res = device->funcs.p_vkAllocateDescriptorSets(device->device, &descriptorAllocInfo, &hack->descriptor_set); ++ if(res != VK_SUCCESS){ ++ ERR("vkAllocateDescriptorSets: %d\n", res); ++ return res; ++ } ++ ++ userDescriptorImageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; ++ userDescriptorImageInfo.imageView = hack->user_view; ++ userDescriptorImageInfo.sampler = swapchain->sampler; ++ ++ realDescriptorImageInfo.imageLayout = VK_IMAGE_LAYOUT_GENERAL; ++ realDescriptorImageInfo.imageView = hack->blit_view; ++ ++ descriptorWrites[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; ++ descriptorWrites[0].dstSet = hack->descriptor_set; ++ descriptorWrites[0].dstBinding = 0; ++ descriptorWrites[0].dstArrayElement = 0; ++ descriptorWrites[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; ++ descriptorWrites[0].descriptorCount = 1; ++ descriptorWrites[0].pImageInfo = &userDescriptorImageInfo; ++ ++ descriptorWrites[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; ++ descriptorWrites[1].dstSet = hack->descriptor_set; ++ descriptorWrites[1].dstBinding = 1; ++ descriptorWrites[1].dstArrayElement = 0; ++ descriptorWrites[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; ++ descriptorWrites[1].descriptorCount = 1; ++ descriptorWrites[1].pImageInfo = &realDescriptorImageInfo; ++ ++ device->funcs.p_vkUpdateDescriptorSets(device->device, 2, descriptorWrites, 0, NULL); ++ ++ return VK_SUCCESS; ++} ++ ++static void destroy_fs_hack_image(VkDevice device, struct VkSwapchainKHR_T *swapchain, struct fs_hack_image *hack) ++{ ++ device->funcs.p_vkDestroyPipeline(device->device, hack->pipeline, NULL); ++ device->funcs.p_vkFreeDescriptorSets(device->device, swapchain->descriptor_pool, 1, &hack->descriptor_set); ++ device->funcs.p_vkDestroyImageView(device->device, hack->user_view, NULL); ++ device->funcs.p_vkDestroyImageView(device->device, hack->blit_view, NULL); ++ device->funcs.p_vkDestroyImage(device->device, hack->user_image, NULL); ++ device->funcs.p_vkDestroyImage(device->device, hack->blit_image, NULL); ++ if(hack->cmd) ++ device->funcs.p_vkFreeCommandBuffers(device->device, ++ swapchain->cmd_pools[hack->cmd_queue_idx], ++ 1, &hack->cmd); ++ device->funcs.p_vkDestroySemaphore(device->device, hack->blit_finished, NULL); ++} ++ ++#if defined(USE_STRUCT_CONVERSION) ++static VkResult init_fs_hack_images(VkDevice device, struct VkSwapchainKHR_T *swapchain, VkSwapchainCreateInfoKHR_host *createinfo) ++#else ++static VkResult init_fs_hack_images(VkDevice device, struct VkSwapchainKHR_T *swapchain, VkSwapchainCreateInfoKHR *createinfo) ++#endif ++{ ++ VkResult res; ++ VkImage *real_images = NULL; ++ VkDeviceSize userMemTotal = 0, offs; ++ VkImageCreateInfo imageInfo = {0}; ++ VkSemaphoreCreateInfo semaphoreInfo = {0}; ++#if defined(USE_STRUCT_CONVERSION) ++ VkMemoryRequirements_host userMemReq; ++ VkMemoryAllocateInfo_host allocInfo = {0}; ++ VkPhysicalDeviceMemoryProperties_host memProperties; ++ VkImageViewCreateInfo_host viewInfo = {0}; ++#else ++ VkMemoryRequirements userMemReq; ++ VkMemoryAllocateInfo allocInfo = {0}; ++ VkPhysicalDeviceMemoryProperties memProperties; ++ VkImageViewCreateInfo viewInfo = {0}; ++#endif ++ uint32_t count, i = 0, user_memory_type = -1; ++ ++ res = device->funcs.p_vkGetSwapchainImagesKHR(device->device, swapchain->swapchain, &count, NULL); ++ if(res != VK_SUCCESS) ++ { ++ WARN("vkGetSwapchainImagesKHR failed, res=%d\n", res); ++ return res; ++ } ++ ++ real_images = heap_alloc(count * sizeof(VkImage)); ++ swapchain->cmd_pools = heap_alloc_zero(sizeof(VkCommandPool) * device->max_queue_families); ++ swapchain->fs_hack_images = heap_alloc_zero(sizeof(struct fs_hack_image) * count); ++ if(!real_images || !swapchain->cmd_pools || !swapchain->fs_hack_images) ++ goto fail; ++ ++ res = device->funcs.p_vkGetSwapchainImagesKHR(device->device, swapchain->swapchain, &count, real_images); ++ if(res != VK_SUCCESS) ++ { ++ WARN("vkGetSwapchainImagesKHR failed, res=%d\n", res); ++ goto fail; ++ } ++ ++ /* create user images */ ++ for(i = 0; i < count; ++i){ ++ struct fs_hack_image *hack = &swapchain->fs_hack_images[i]; ++ ++ hack->swapchain_image = real_images[i]; ++ ++ semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; ++ res = device->funcs.p_vkCreateSemaphore(device->device, &semaphoreInfo, NULL, &hack->blit_finished); ++ if(res != VK_SUCCESS) ++ { ++ WARN("vkCreateSemaphore failed, res=%d\n", res); ++ goto fail; ++ } ++ ++ imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; ++ imageInfo.imageType = VK_IMAGE_TYPE_2D; ++ imageInfo.extent.width = swapchain->user_extent.width; ++ imageInfo.extent.height = swapchain->user_extent.height; ++ imageInfo.extent.depth = 1; ++ imageInfo.mipLevels = 1; ++ imageInfo.arrayLayers = createinfo->imageArrayLayers; ++ imageInfo.format = createinfo->imageFormat; ++ imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL; ++ imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; ++ imageInfo.usage = createinfo->imageUsage | VK_IMAGE_USAGE_SAMPLED_BIT; ++ imageInfo.sharingMode = createinfo->imageSharingMode; ++ imageInfo.samples = VK_SAMPLE_COUNT_1_BIT; ++ imageInfo.queueFamilyIndexCount = createinfo->queueFamilyIndexCount; ++ imageInfo.pQueueFamilyIndices = createinfo->pQueueFamilyIndices; ++ res = device->funcs.p_vkCreateImage(device->device, &imageInfo, NULL, &hack->user_image); ++ if(res != VK_SUCCESS){ ++ ERR("vkCreateImage failed: %d\n", res); ++ goto fail; ++ } ++ ++ device->funcs.p_vkGetImageMemoryRequirements(device->device, hack->user_image, &userMemReq); ++ ++ offs = userMemTotal % userMemReq.alignment; ++ if(offs) ++ userMemTotal += userMemReq.alignment - offs; ++ ++ userMemTotal += userMemReq.size; ++ ++ swapchain->n_images++; ++ } ++ ++ /* allocate backing memory */ ++ device->phys_dev->instance->funcs.p_vkGetPhysicalDeviceMemoryProperties(device->phys_dev->phys_dev, &memProperties); ++ ++ for (i = 0; i < memProperties.memoryTypeCount; i++){ ++ if((memProperties.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT){ ++ if(userMemReq.memoryTypeBits & (1 << i)){ ++ user_memory_type = i; ++ break; ++ } ++ } ++ } ++ ++ if(user_memory_type == -1){ ++ ERR("unable to find suitable memory type\n"); ++ res = VK_ERROR_OUT_OF_HOST_MEMORY; ++ goto fail; ++ } ++ ++ allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; ++ allocInfo.allocationSize = userMemTotal; ++ allocInfo.memoryTypeIndex = user_memory_type; ++ ++ res = device->funcs.p_vkAllocateMemory(device->device, &allocInfo, NULL, &swapchain->user_image_memory); ++ if(res != VK_SUCCESS){ ++ ERR("vkAllocateMemory: %d\n", res); ++ goto fail; ++ } ++ ++ /* bind backing memory and create imageviews */ ++ userMemTotal = 0; ++ for(i = 0; i < count; ++i){ ++ device->funcs.p_vkGetImageMemoryRequirements(device->device, swapchain->fs_hack_images[i].user_image, &userMemReq); ++ ++ offs = userMemTotal % userMemReq.alignment; ++ if(offs) ++ userMemTotal += userMemReq.alignment - offs; ++ ++ res = device->funcs.p_vkBindImageMemory(device->device, swapchain->fs_hack_images[i].user_image, swapchain->user_image_memory, userMemTotal); ++ if(res != VK_SUCCESS){ ++ ERR("vkBindImageMemory: %d\n", res); ++ goto fail; ++ } ++ ++ userMemTotal += userMemReq.size; ++ ++ viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; ++ viewInfo.image = swapchain->fs_hack_images[i].user_image; ++ viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; ++ viewInfo.format = createinfo->imageFormat; ++ viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; ++ viewInfo.subresourceRange.baseMipLevel = 0; ++ viewInfo.subresourceRange.levelCount = 1; ++ viewInfo.subresourceRange.baseArrayLayer = 0; ++ viewInfo.subresourceRange.layerCount = 1; ++ ++ res = device->funcs.p_vkCreateImageView(device->device, &viewInfo, NULL, &swapchain->fs_hack_images[i].user_view); ++ if(res != VK_SUCCESS){ ++ ERR("vkCreateImageView(user): %d\n", res); ++ goto fail; ++ } ++ } ++ ++ heap_free(real_images); ++ ++ return VK_SUCCESS; ++ ++fail: ++ for(i = 0; i < swapchain->n_images; ++i) ++ destroy_fs_hack_image(device, swapchain, &swapchain->fs_hack_images[i]); ++ heap_free(real_images); ++ heap_free(swapchain->cmd_pools); ++ heap_free(swapchain->fs_hack_images); ++ return res; ++} ++ ++static VkResult init_blit_images(VkDevice device, struct VkSwapchainKHR_T *swapchain); + VkResult WINAPI wine_vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain) + { + VkResult result; +@@ -1331,6 +1678,7 @@ VkResult WINAPI wine_vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCrea + #else + VkSwapchainCreateInfoKHR our_createinfo; + #endif ++ VkExtent2D user_sz; + struct VkSwapchainKHR_T *object; + uint32_t i; + +@@ -1348,7 +1696,58 @@ VkResult WINAPI wine_vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCrea + if(our_createinfo.oldSwapchain) + our_createinfo.oldSwapchain = ((struct VkSwapchainKHR_T *)(UINT_PTR)our_createinfo.oldSwapchain)->swapchain; + ++ if(vk_funcs->query_fs_hack && ++ vk_funcs->query_fs_hack(&object->real_extent, &user_sz, &object->blit_dst) && ++ our_createinfo.imageExtent.width == user_sz.width && ++ our_createinfo.imageExtent.height == user_sz.height) ++ { ++ uint32_t count; ++ ++ device->phys_dev->instance->funcs.p_vkGetPhysicalDeviceQueueFamilyProperties(device->phys_dev->phys_dev, &count, NULL); ++ ++ device->queue_props = heap_alloc(sizeof(VkQueueFamilyProperties) * count); ++ ++ device->phys_dev->instance->funcs.p_vkGetPhysicalDeviceQueueFamilyProperties(device->phys_dev->phys_dev, &count, device->queue_props); ++ ++ our_createinfo.imageExtent = object->real_extent; ++ our_createinfo.imageUsage |= VK_IMAGE_USAGE_TRANSFER_DST_BIT; /* XXX: check if supported by surface */ ++ ++ if(our_createinfo.imageFormat != VK_FORMAT_B8G8R8A8_UNORM && ++ our_createinfo.imageFormat != VK_FORMAT_B8G8R8A8_SRGB){ ++ FIXME("swapchain image format is not BGRA8 UNORM/SRGB. Things may go badly. %d\n", our_createinfo.imageFormat); ++ } ++ ++ object->fs_hack_enabled = TRUE; ++ } ++ + result = device->funcs.p_vkCreateSwapchainKHR(device->device, &our_createinfo, NULL, &object->swapchain); ++ if(result != VK_SUCCESS) ++ { ++ TRACE("vkCreateSwapchainKHR failed, res=%d\n", result); ++ heap_free(object); ++ return result; ++ } ++ ++ if(object->fs_hack_enabled){ ++ object->user_extent = pCreateInfo->imageExtent; ++ ++ result = init_fs_hack_images(device, object, &our_createinfo); ++ if(result != VK_SUCCESS){ ++ ERR("creating fs hack images failed: %d\n", result); ++ device->funcs.p_vkDestroySwapchainKHR(device->device, object->swapchain, NULL); ++ heap_free(object); ++ return result; ++ } ++ ++ /* FIXME: would be nice to do this on-demand, but games can use up all ++ * memory so we fail to allocate later */ ++ result = init_blit_images(device, object); ++ if(result != VK_SUCCESS){ ++ ERR("creating blit images failed: %d\n", result); ++ wine_vkDestroySwapchainKHR(device, (VkSwapchainKHR)object, NULL); ++ return result; ++ } ++ } + + if(result != VK_SUCCESS){ + heap_free(object); +@@ -1400,28 +1799,787 @@ void WINAPI wine_vkDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain + } + LeaveCriticalSection(&device->swapchain_lock); + ++ if(object->fs_hack_enabled){ ++ for(i = 0; i < object->n_images; ++i) ++ destroy_fs_hack_image(device, object, &object->fs_hack_images[i]); ++ ++ for(i = 0; i < device->max_queue_families; ++i) ++ if(object->cmd_pools[i]) ++ device->funcs.p_vkDestroyCommandPool(device->device, object->cmd_pools[i], NULL); ++ ++ device->funcs.p_vkDestroyPipelineLayout(device->device, object->pipeline_layout, NULL); ++ device->funcs.p_vkDestroyDescriptorSetLayout(device->device, object->descriptor_set_layout, NULL); ++ device->funcs.p_vkDestroyDescriptorPool(device->device, object->descriptor_pool, NULL); ++ device->funcs.p_vkDestroySampler(device->device, object->sampler, NULL); ++ device->funcs.p_vkFreeMemory(device->device, object->user_image_memory, NULL); ++ device->funcs.p_vkFreeMemory(device->device, object->blit_image_memory, NULL); ++ heap_free(object->cmd_pools); ++ heap_free(object->fs_hack_images); ++ } ++ + device->funcs.p_vkDestroySwapchainKHR(device->device, object->swapchain, NULL); ++ + heap_free(object); + } + + VkResult WINAPI wine_vkGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages) + { + struct VkSwapchainKHR_T *object = (struct VkSwapchainKHR_T *)(UINT_PTR)swapchain; ++ uint32_t i; ++ + TRACE("%p, 0x%s, %p, %p\n", device, wine_dbgstr_longlong(swapchain), pSwapchainImageCount, pSwapchainImages); ++ ++ if(pSwapchainImages && object->fs_hack_enabled){ ++ if(*pSwapchainImageCount > object->n_images) ++ *pSwapchainImageCount = object->n_images; ++ for(i = 0; i < *pSwapchainImageCount ; ++i) ++ pSwapchainImages[i] = object->fs_hack_images[i].user_image; ++ return *pSwapchainImageCount == object->n_images ? VK_SUCCESS : VK_INCOMPLETE; ++ } ++ + return device->funcs.p_vkGetSwapchainImagesKHR(device->device, object->swapchain, pSwapchainImageCount, pSwapchainImages); + } + ++static uint32_t get_queue_index(VkQueue queue) ++{ ++ uint32_t i; ++ for(i = 0; i < queue->device->max_queue_families; ++i){ ++ if(queue->device->queues[i] == queue) ++ return i; ++ } ++ WARN("couldn't find queue\n"); ++ return -1; ++} ++ ++static VkCommandBuffer create_hack_cmd(VkQueue queue, struct VkSwapchainKHR_T *swapchain, uint32_t queue_idx) ++{ ++#if defined(USE_STRUCT_CONVERSION) ++ VkCommandBufferAllocateInfo_host allocInfo = {0}; ++#else ++ VkCommandBufferAllocateInfo allocInfo = {0}; ++#endif ++ VkCommandBuffer cmd; ++ VkResult result; ++ ++ if(!swapchain->cmd_pools[queue_idx]){ ++ VkCommandPoolCreateInfo poolInfo = {0}; ++ ++ poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; ++ poolInfo.queueFamilyIndex = queue_idx; ++ ++ result = queue->device->funcs.p_vkCreateCommandPool(queue->device->device, &poolInfo, NULL, &swapchain->cmd_pools[queue_idx]); ++ if(result != VK_SUCCESS){ ++ ERR("vkCreateCommandPool failed, res=%d\n", result); ++ return NULL; ++ } ++ } ++ ++ allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; ++ allocInfo.commandPool = swapchain->cmd_pools[queue_idx]; ++ allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; ++ allocInfo.commandBufferCount = 1; ++ ++ result = queue->device->funcs.p_vkAllocateCommandBuffers(queue->device->device, &allocInfo, &cmd); ++ if(result != VK_SUCCESS){ ++ ERR("vkAllocateCommandBuffers failed, res=%d\n", result); ++ return NULL; ++ } ++ ++ return cmd; ++} ++ ++static VkResult init_blit_images(VkDevice device, struct VkSwapchainKHR_T *swapchain) ++{ ++ VkResult res; ++ VkSamplerCreateInfo samplerInfo = {0}; ++ VkDescriptorPoolSize poolSizes[2] = {{0}, {0}}; ++ VkDescriptorPoolCreateInfo poolInfo = {0}; ++ VkDescriptorSetLayoutBinding layoutBindings[2] = {{0}, {0}}; ++ VkDescriptorSetLayoutCreateInfo descriptorLayoutInfo = {0}; ++ VkPipelineLayoutCreateInfo pipelineLayoutInfo = {0}; ++ VkPushConstantRange pushConstants; ++ VkShaderModuleCreateInfo shaderInfo = {0}; ++ VkShaderModule shaderModule = 0; ++ VkDeviceSize blitMemTotal = 0, offs; ++ VkImageCreateInfo imageInfo = {0}; ++#if defined(USE_STRUCT_CONVERSION) ++ VkMemoryRequirements_host blitMemReq; ++ VkMemoryAllocateInfo_host allocInfo = {0}; ++ VkPhysicalDeviceMemoryProperties_host memProperties; ++ VkImageViewCreateInfo_host viewInfo = {0}; ++#else ++ VkMemoryRequirements blitMemReq; ++ VkMemoryAllocateInfo allocInfo = {0}; ++ VkPhysicalDeviceMemoryProperties memProperties; ++ VkImageViewCreateInfo viewInfo = {0}; ++#endif ++ uint32_t blit_memory_type = -1, i; ++ ++ samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; ++ samplerInfo.magFilter = VK_FILTER_LINEAR; ++ samplerInfo.minFilter = VK_FILTER_LINEAR; ++ samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; ++ samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; ++ samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; ++ samplerInfo.anisotropyEnable = VK_FALSE; ++ samplerInfo.maxAnisotropy = 1; ++ samplerInfo.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; ++ samplerInfo.unnormalizedCoordinates = VK_FALSE; ++ samplerInfo.compareEnable = VK_FALSE; ++ samplerInfo.compareOp = VK_COMPARE_OP_ALWAYS; ++ samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; ++ samplerInfo.mipLodBias = 0.0f; ++ samplerInfo.minLod = 0.0f; ++ samplerInfo.maxLod = 0.0f; ++ ++ res = device->funcs.p_vkCreateSampler(device->device, &samplerInfo, NULL, &swapchain->sampler); ++ if(res != VK_SUCCESS) ++ { ++ WARN("vkCreateSampler failed, res=%d\n", res); ++ return res; ++ } ++ ++ poolSizes[0].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; ++ poolSizes[0].descriptorCount = swapchain->n_images; ++ poolSizes[1].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; ++ poolSizes[1].descriptorCount = swapchain->n_images; ++ ++ poolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; ++ poolInfo.poolSizeCount = 2; ++ poolInfo.pPoolSizes = poolSizes; ++ poolInfo.maxSets = swapchain->n_images; ++ ++ res = device->funcs.p_vkCreateDescriptorPool(device->device, &poolInfo, NULL, &swapchain->descriptor_pool); ++ if(res != VK_SUCCESS){ ++ ERR("vkCreateDescriptorPool: %d\n", res); ++ goto fail; ++ } ++ ++ layoutBindings[0].binding = 0; ++ layoutBindings[0].descriptorCount = 1; ++ layoutBindings[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; ++ layoutBindings[0].pImmutableSamplers = NULL; ++ layoutBindings[0].stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; ++ ++ layoutBindings[1].binding = 1; ++ layoutBindings[1].descriptorCount = 1; ++ layoutBindings[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; ++ layoutBindings[1].pImmutableSamplers = NULL; ++ layoutBindings[1].stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; ++ ++ descriptorLayoutInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; ++ descriptorLayoutInfo.bindingCount = 2; ++ descriptorLayoutInfo.pBindings = layoutBindings; ++ ++ res = device->funcs.p_vkCreateDescriptorSetLayout(device->device, &descriptorLayoutInfo, NULL, &swapchain->descriptor_set_layout); ++ if(res != VK_SUCCESS){ ++ ERR("vkCreateDescriptorSetLayout: %d\n", res); ++ goto fail; ++ } ++ ++ pushConstants.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; ++ pushConstants.offset = 0; ++ pushConstants.size = 4 * sizeof(float); /* 2 * vec2 */ ++ ++ pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; ++ pipelineLayoutInfo.setLayoutCount = 1; ++ pipelineLayoutInfo.pSetLayouts = &swapchain->descriptor_set_layout; ++ pipelineLayoutInfo.pushConstantRangeCount = 1; ++ pipelineLayoutInfo.pPushConstantRanges = &pushConstants; ++ ++ res = device->funcs.p_vkCreatePipelineLayout(device->device, &pipelineLayoutInfo, NULL, &swapchain->pipeline_layout); ++ if(res != VK_SUCCESS){ ++ ERR("vkCreatePipelineLayout: %d\n", res); ++ goto fail; ++ } ++ ++ /* create intermediate blit images */ ++ for(i = 0; i < swapchain->n_images; ++i){ ++ struct fs_hack_image *hack = &swapchain->fs_hack_images[i]; ++ ++ imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; ++ imageInfo.imageType = VK_IMAGE_TYPE_2D; ++ imageInfo.extent.width = swapchain->real_extent.width; ++ imageInfo.extent.height = swapchain->real_extent.height; ++ imageInfo.extent.depth = 1; ++ imageInfo.mipLevels = 1; ++ imageInfo.arrayLayers = 1; ++ imageInfo.format = VK_FORMAT_R8G8B8A8_UNORM; ++ imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL; ++ imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; ++ imageInfo.usage = VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT; ++ imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; ++ imageInfo.samples = VK_SAMPLE_COUNT_1_BIT; ++ res = device->funcs.p_vkCreateImage(device->device, &imageInfo, NULL, &hack->blit_image); ++ if(res != VK_SUCCESS){ ++ ERR("vkCreateImage failed: %d\n", res); ++ goto fail; ++ } ++ ++ device->funcs.p_vkGetImageMemoryRequirements(device->device, hack->blit_image, &blitMemReq); ++ ++ offs = blitMemTotal % blitMemReq.alignment; ++ if(offs) ++ blitMemTotal += blitMemReq.alignment - offs; ++ ++ blitMemTotal += blitMemReq.size; ++ } ++ ++ /* allocate backing memory */ ++ device->phys_dev->instance->funcs.p_vkGetPhysicalDeviceMemoryProperties(device->phys_dev->phys_dev, &memProperties); ++ ++ for(i = 0; i < memProperties.memoryTypeCount; i++){ ++ if((memProperties.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT){ ++ if(blitMemReq.memoryTypeBits & (1 << i)){ ++ blit_memory_type = i; ++ break; ++ } ++ } ++ } ++ ++ if(blit_memory_type == -1){ ++ ERR("unable to find suitable memory type\n"); ++ res = VK_ERROR_OUT_OF_HOST_MEMORY; ++ goto fail; ++ } ++ ++ allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; ++ allocInfo.allocationSize = blitMemTotal; ++ allocInfo.memoryTypeIndex = blit_memory_type; ++ ++ res = device->funcs.p_vkAllocateMemory(device->device, &allocInfo, NULL, &swapchain->blit_image_memory); ++ if(res != VK_SUCCESS){ ++ ERR("vkAllocateMemory: %d\n", res); ++ goto fail; ++ } ++ ++ shaderInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; ++ shaderInfo.codeSize = sizeof(blit_comp_spv); ++ shaderInfo.pCode = blit_comp_spv; ++ ++ res = device->funcs.p_vkCreateShaderModule(device->device, &shaderInfo, NULL, &shaderModule); ++ if(res != VK_SUCCESS){ ++ ERR("vkCreateShaderModule: %d\n", res); ++ goto fail; ++ } ++ ++ /* bind backing memory and create imageviews */ ++ blitMemTotal = 0; ++ for(i = 0; i < swapchain->n_images; ++i){ ++ struct fs_hack_image *hack = &swapchain->fs_hack_images[i]; ++ ++ device->funcs.p_vkGetImageMemoryRequirements(device->device, hack->blit_image, &blitMemReq); ++ ++ offs = blitMemTotal % blitMemReq.alignment; ++ if(offs) ++ blitMemTotal += blitMemReq.alignment - offs; ++ ++ res = device->funcs.p_vkBindImageMemory(device->device, hack->blit_image, swapchain->blit_image_memory, blitMemTotal); ++ if(res != VK_SUCCESS){ ++ ERR("vkBindImageMemory: %d\n", res); ++ goto fail; ++ } ++ ++ blitMemTotal += blitMemReq.size; ++ ++ viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; ++ viewInfo.image = hack->blit_image; ++ viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; ++ viewInfo.format = VK_FORMAT_R8G8B8A8_UNORM; ++ viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; ++ viewInfo.subresourceRange.baseMipLevel = 0; ++ viewInfo.subresourceRange.levelCount = 1; ++ viewInfo.subresourceRange.baseArrayLayer = 0; ++ viewInfo.subresourceRange.layerCount = 1; ++ ++ res = device->funcs.p_vkCreateImageView(device->device, &viewInfo, NULL, &hack->blit_view); ++ if(res != VK_SUCCESS){ ++ ERR("vkCreateImageView(blit): %d\n", res); ++ goto fail; ++ } ++ ++ res = create_descriptor_set(device, swapchain, hack); ++ if(res != VK_SUCCESS) ++ goto fail; ++ ++ res = create_pipeline(device, swapchain, hack, shaderModule); ++ if(res != VK_SUCCESS) ++ goto fail; ++ } ++ ++ device->funcs.p_vkDestroyShaderModule(device->device, shaderModule, NULL); ++ ++ return VK_SUCCESS; ++ ++fail: ++ for(i = 0; i < swapchain->n_images; ++i){ ++ struct fs_hack_image *hack = &swapchain->fs_hack_images[i]; ++ ++ device->funcs.p_vkDestroyPipeline(device->device, hack->pipeline, NULL); ++ hack->pipeline = VK_NULL_HANDLE; ++ ++ device->funcs.p_vkFreeDescriptorSets(device->device, swapchain->descriptor_pool, 1, &hack->descriptor_set); ++ hack->descriptor_set = VK_NULL_HANDLE; ++ ++ device->funcs.p_vkDestroyImageView(device->device, hack->blit_view, NULL); ++ hack->blit_view = VK_NULL_HANDLE; ++ ++ device->funcs.p_vkDestroyImage(device->device, hack->blit_image, NULL); ++ hack->blit_image = VK_NULL_HANDLE; ++ } ++ ++ device->funcs.p_vkDestroyShaderModule(device->device, shaderModule, NULL); ++ ++ device->funcs.p_vkDestroyPipelineLayout(device->device, swapchain->pipeline_layout, NULL); ++ swapchain->pipeline_layout = VK_NULL_HANDLE; ++ ++ device->funcs.p_vkDestroyDescriptorSetLayout(device->device, swapchain->descriptor_set_layout, NULL); ++ swapchain->descriptor_set_layout = VK_NULL_HANDLE; ++ ++ device->funcs.p_vkDestroyDescriptorPool(device->device, swapchain->descriptor_pool, NULL); ++ swapchain->descriptor_pool = VK_NULL_HANDLE; ++ ++ device->funcs.p_vkFreeMemory(device->device, swapchain->blit_image_memory, NULL); ++ swapchain->blit_image_memory = VK_NULL_HANDLE; ++ ++ device->funcs.p_vkDestroySampler(device->device, swapchain->sampler, NULL); ++ swapchain->sampler = VK_NULL_HANDLE; ++ ++ return res; ++} ++ ++static VkResult record_compute_cmd(VkDevice device, struct VkSwapchainKHR_T *swapchain, struct fs_hack_image *hack) ++{ ++ VkResult result; ++ VkImageCopy region = {0}; ++#if defined(USE_STRUCT_CONVERSION) ++ VkImageMemoryBarrier_host barriers[3] = {{0}}; ++ VkCommandBufferBeginInfo_host beginInfo = {0}; ++#else ++ VkImageMemoryBarrier barriers[3] = {{0}}; ++ VkCommandBufferBeginInfo beginInfo = {0}; ++#endif ++ float constants[4]; ++ ++ TRACE("recording compute command\n"); ++ ++#if 0 ++ /* DOOM runs out of memory when allocating blit images after loading. */ ++ if(!swapchain->blit_image_memory){ ++ result = init_blit_images(device, swapchain); ++ if(result != VK_SUCCESS) ++ return result; ++ } ++#endif ++ ++ beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; ++ beginInfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT; ++ ++ device->funcs.p_vkBeginCommandBuffer(hack->cmd, &beginInfo); ++ ++ /* transition user image from GENERAL to SHADER_READ */ ++ barriers[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; ++ barriers[0].oldLayout = VK_IMAGE_LAYOUT_GENERAL; ++ barriers[0].newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; ++ barriers[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; ++ barriers[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; ++ barriers[0].image = hack->user_image; ++ barriers[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; ++ barriers[0].subresourceRange.baseMipLevel = 0; ++ barriers[0].subresourceRange.levelCount = 1; ++ barriers[0].subresourceRange.baseArrayLayer = 0; ++ barriers[0].subresourceRange.layerCount = 1; ++ barriers[0].srcAccessMask = 0; ++ barriers[0].dstAccessMask = VK_ACCESS_SHADER_READ_BIT; ++ ++ /* transition blit image from whatever to GENERAL */ ++ barriers[1].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; ++ barriers[1].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; ++ barriers[1].newLayout = VK_IMAGE_LAYOUT_GENERAL; ++ barriers[1].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; ++ barriers[1].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; ++ barriers[1].image = hack->blit_image; ++ barriers[1].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; ++ barriers[1].subresourceRange.baseMipLevel = 0; ++ barriers[1].subresourceRange.levelCount = 1; ++ barriers[1].subresourceRange.baseArrayLayer = 0; ++ barriers[1].subresourceRange.layerCount = 1; ++ barriers[1].srcAccessMask = 0; ++ barriers[1].dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT; ++ ++ device->funcs.p_vkCmdPipelineBarrier( ++ hack->cmd, ++ VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, ++ VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, ++ 0, ++ 0, NULL, ++ 0, NULL, ++ 2, barriers ++ ); ++ ++ /* perform blit shader */ ++ device->funcs.p_vkCmdBindPipeline(hack->cmd, ++ VK_PIPELINE_BIND_POINT_COMPUTE, hack->pipeline); ++ ++ device->funcs.p_vkCmdBindDescriptorSets(hack->cmd, ++ VK_PIPELINE_BIND_POINT_COMPUTE, swapchain->pipeline_layout, ++ 0, 1, &hack->descriptor_set, 0, NULL); ++ ++ /* vec2: blit dst offset in real coords */ ++ constants[0] = swapchain->blit_dst.offset.x; ++ constants[1] = swapchain->blit_dst.offset.y; ++ /* vec2: blit dst extents in real coords */ ++ constants[2] = swapchain->blit_dst.extent.width; ++ constants[3] = swapchain->blit_dst.extent.height; ++ device->funcs.p_vkCmdPushConstants(hack->cmd, ++ swapchain->pipeline_layout, VK_SHADER_STAGE_COMPUTE_BIT, ++ 0, sizeof(constants), constants); ++ ++ /* local sizes in shader are 8 */ ++ device->funcs.p_vkCmdDispatch(hack->cmd, ceil(swapchain->real_extent.width / 8.), ++ ceil(swapchain->real_extent.height / 8.), 1); ++ ++ /* transition user image from SHADER_READ to GENERAL */ ++ barriers[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; ++ barriers[0].oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; ++ barriers[0].newLayout = VK_IMAGE_LAYOUT_GENERAL; ++ barriers[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; ++ barriers[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; ++ barriers[0].image = hack->user_image; ++ barriers[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; ++ barriers[0].subresourceRange.baseMipLevel = 0; ++ barriers[0].subresourceRange.levelCount = 1; ++ barriers[0].subresourceRange.baseArrayLayer = 0; ++ barriers[0].subresourceRange.layerCount = 1; ++ barriers[0].srcAccessMask = VK_ACCESS_SHADER_READ_BIT; ++ barriers[0].dstAccessMask = 0; ++ ++ device->funcs.p_vkCmdPipelineBarrier( ++ hack->cmd, ++ VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, ++ VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, ++ 0, ++ 0, NULL, ++ 0, NULL, ++ 1, barriers ++ ); ++ ++ /* transition blit image layout from GENERAL to TRANSFER_SRC ++ * and access from SHADER_WRITE_BIT to TRANSFER_READ_BIT */ ++ barriers[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; ++ barriers[0].oldLayout = VK_IMAGE_LAYOUT_GENERAL; ++ barriers[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; ++ barriers[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; ++ barriers[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; ++ barriers[0].image = hack->blit_image; ++ barriers[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; ++ barriers[0].subresourceRange.baseMipLevel = 0; ++ barriers[0].subresourceRange.levelCount = 1; ++ barriers[0].subresourceRange.baseArrayLayer = 0; ++ barriers[0].subresourceRange.layerCount = 1; ++ barriers[0].srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT; ++ barriers[0].dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; ++ ++ /* transition swapchain image from whatever to PRESENT_SRC */ ++ barriers[1].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; ++ barriers[1].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; ++ barriers[1].newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; ++ barriers[1].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; ++ barriers[1].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; ++ barriers[1].image = hack->swapchain_image; ++ barriers[1].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; ++ barriers[1].subresourceRange.baseMipLevel = 0; ++ barriers[1].subresourceRange.levelCount = 1; ++ barriers[1].subresourceRange.baseArrayLayer = 0; ++ barriers[1].subresourceRange.layerCount = 1; ++ barriers[1].srcAccessMask = 0; ++ barriers[1].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; ++ ++ device->funcs.p_vkCmdPipelineBarrier( ++ hack->cmd, ++ VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, ++ VK_PIPELINE_STAGE_TRANSFER_BIT, ++ 0, ++ 0, NULL, ++ 0, NULL, ++ 2, barriers ++ ); ++ ++ /* copy from blit image to swapchain image */ ++ region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; ++ region.srcSubresource.layerCount = 1; ++ region.srcOffset.x = 0; ++ region.srcOffset.y = 0; ++ region.srcOffset.z = 0; ++ region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; ++ region.dstSubresource.layerCount = 1; ++ region.dstOffset.x = 0; ++ region.dstOffset.y = 0; ++ region.dstOffset.z = 0; ++ region.extent.width = swapchain->real_extent.width; ++ region.extent.height = swapchain->real_extent.height; ++ region.extent.depth = 1; ++ ++ device->funcs.p_vkCmdCopyImage(hack->cmd, ++ hack->blit_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, ++ hack->swapchain_image, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, ++ 1, ®ion); ++ ++ result = device->funcs.p_vkEndCommandBuffer(hack->cmd); ++ if(result != VK_SUCCESS){ ++ ERR("vkEndCommandBuffer: %d\n", result); ++ return result; ++ } ++ ++ return VK_SUCCESS; ++} ++ ++static VkResult record_graphics_cmd(VkDevice device, struct VkSwapchainKHR_T *swapchain, struct fs_hack_image *hack) ++{ ++ VkResult result; ++ VkImageBlit blitregion = {0}; ++ VkImageSubresourceRange range = {0}; ++ VkClearColorValue black = {{0.f, 0.f, 0.f}}; ++#if defined(USE_STRUCT_CONVERSION) ++ VkImageMemoryBarrier_host barriers[2] = {{0}}; ++ VkCommandBufferBeginInfo_host beginInfo = {0}; ++#else ++ VkImageMemoryBarrier barriers[2] = {{0}}; ++ VkCommandBufferBeginInfo beginInfo = {0}; ++#endif ++ ++ TRACE("recording graphics command\n"); ++ ++ beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; ++ beginInfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT; ++ ++ device->funcs.p_vkBeginCommandBuffer(hack->cmd, &beginInfo); ++ ++ /* transition user image from GENERAL to TRANSFER_SRC_OPTIMAL */ ++ barriers[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; ++ barriers[0].oldLayout = VK_IMAGE_LAYOUT_GENERAL; ++ barriers[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; ++ barriers[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; ++ barriers[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; ++ barriers[0].image = hack->user_image; ++ barriers[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; ++ barriers[0].subresourceRange.baseMipLevel = 0; ++ barriers[0].subresourceRange.levelCount = 1; ++ barriers[0].subresourceRange.baseArrayLayer = 0; ++ barriers[0].subresourceRange.layerCount = 1; ++ barriers[0].srcAccessMask = 0; ++ barriers[0].dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; ++ ++ /* transition real image from whatever to TRANSFER_DST_OPTIMAL */ ++ barriers[1].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; ++ barriers[1].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; ++ barriers[1].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; ++ barriers[1].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; ++ barriers[1].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; ++ barriers[1].image = hack->swapchain_image; ++ barriers[1].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; ++ barriers[1].subresourceRange.baseMipLevel = 0; ++ barriers[1].subresourceRange.levelCount = 1; ++ barriers[1].subresourceRange.baseArrayLayer = 0; ++ barriers[1].subresourceRange.layerCount = 1; ++ barriers[1].srcAccessMask = 0; ++ barriers[1].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; ++ ++ device->funcs.p_vkCmdPipelineBarrier( ++ hack->cmd, ++ VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, ++ VK_PIPELINE_STAGE_TRANSFER_BIT, ++ 0, ++ 0, NULL, ++ 0, NULL, ++ 2, barriers ++ ); ++ ++ /* clear the image */ ++ range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; ++ range.baseMipLevel = 0; ++ range.levelCount = 1; ++ range.baseArrayLayer = 0; ++ range.layerCount = 1; ++ ++ device->funcs.p_vkCmdClearColorImage( ++ hack->cmd, hack->swapchain_image, ++ VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, ++ &black, 1, &range); ++ ++ /* perform blit */ ++ blitregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; ++ blitregion.srcSubresource.layerCount = 1; ++ blitregion.srcOffsets[0].x = 0; ++ blitregion.srcOffsets[0].y = 0; ++ blitregion.srcOffsets[0].z = 0; ++ blitregion.srcOffsets[1].x = swapchain->user_extent.width; ++ blitregion.srcOffsets[1].y = swapchain->user_extent.height; ++ blitregion.srcOffsets[1].z = 1; ++ blitregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; ++ blitregion.dstSubresource.layerCount = 1; ++ blitregion.dstOffsets[0].x = swapchain->blit_dst.offset.x; ++ blitregion.dstOffsets[0].y = swapchain->blit_dst.offset.y; ++ blitregion.dstOffsets[0].z = 0; ++ blitregion.dstOffsets[1].x = swapchain->blit_dst.offset.x + swapchain->blit_dst.extent.width; ++ blitregion.dstOffsets[1].y = swapchain->blit_dst.offset.y + swapchain->blit_dst.extent.height; ++ blitregion.dstOffsets[1].z = 1; ++ ++ device->funcs.p_vkCmdBlitImage(hack->cmd, ++ hack->user_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, ++ hack->swapchain_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, ++ 1, &blitregion, VK_FILTER_LINEAR /* CUBIC_IMG? */); ++ ++ /* transition user image from TRANSFER_SRC_OPTIMAL to GENERAL */ ++ barriers[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; ++ barriers[0].oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; ++ barriers[0].newLayout = VK_IMAGE_LAYOUT_GENERAL; ++ barriers[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; ++ barriers[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; ++ barriers[0].image = hack->user_image; ++ barriers[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; ++ barriers[0].subresourceRange.baseMipLevel = 0; ++ barriers[0].subresourceRange.levelCount = 1; ++ barriers[0].subresourceRange.baseArrayLayer = 0; ++ barriers[0].subresourceRange.layerCount = 1; ++ barriers[0].srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT; ++ barriers[0].dstAccessMask = 0; ++ ++ /* transition real image from TRANSFER_DST to PRESENT_SRC */ ++ barriers[1].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; ++ barriers[1].oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; ++ barriers[1].newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; ++ barriers[1].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; ++ barriers[1].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; ++ barriers[1].image = hack->swapchain_image; ++ barriers[1].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; ++ barriers[1].subresourceRange.baseMipLevel = 0; ++ barriers[1].subresourceRange.levelCount = 1; ++ barriers[1].subresourceRange.baseArrayLayer = 0; ++ barriers[1].subresourceRange.layerCount = 1; ++ barriers[1].srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; ++ barriers[1].dstAccessMask = 0; ++ ++ device->funcs.p_vkCmdPipelineBarrier( ++ hack->cmd, ++ VK_PIPELINE_STAGE_TRANSFER_BIT, ++ VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, ++ 0, ++ 0, NULL, ++ 0, NULL, ++ 2, barriers ++ ); ++ ++ result = device->funcs.p_vkEndCommandBuffer(hack->cmd); ++ if(result != VK_SUCCESS){ ++ ERR("vkEndCommandBuffer: %d\n", result); ++ return result; ++ } ++ ++ return VK_SUCCESS; ++} ++ + VkResult WINAPI wine_vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) + { ++ VkResult res; + VkPresentInfoKHR our_presentInfo; + VkSwapchainKHR *arr; +- uint32_t i; +- VkResult res; ++ VkCommandBuffer *blit_cmds = NULL; ++ VkSubmitInfo submitInfo = {0}; ++ VkSemaphore blit_sema; ++ struct VkSwapchainKHR_T *swapchain; ++ uint32_t i, n_hacks = 0; ++ uint32_t queue_idx; + + TRACE("%p, %p\n", queue, pPresentInfo); + + our_presentInfo = *pPresentInfo; + ++ for(i = 0; i < our_presentInfo.swapchainCount; ++i){ ++ swapchain = (struct VkSwapchainKHR_T *)(UINT_PTR)our_presentInfo.pSwapchains[i]; ++ ++ if(swapchain->fs_hack_enabled){ ++ struct fs_hack_image *hack = &swapchain->fs_hack_images[our_presentInfo.pImageIndices[i]]; ++ ++ if(!blit_cmds){ ++ queue_idx = get_queue_index(queue); ++ blit_cmds = heap_alloc(our_presentInfo.swapchainCount * sizeof(VkCommandBuffer)); ++ blit_sema = hack->blit_finished; ++ } ++ ++ if(!hack->cmd || hack->cmd_queue_idx != queue_idx){ ++ if(hack->cmd) ++ queue->device->funcs.p_vkFreeCommandBuffers(queue->device->device, ++ swapchain->cmd_pools[hack->cmd_queue_idx], ++ 1, &hack->cmd); ++ ++ hack->cmd_queue_idx = queue_idx; ++ hack->cmd = create_hack_cmd(queue, swapchain, queue_idx); ++ ++ if(!hack->cmd){ ++ heap_free(blit_cmds); ++ return VK_ERROR_DEVICE_LOST; ++ } ++ ++ if(queue->device->queue_props[queue_idx].queueFlags & VK_QUEUE_GRAPHICS_BIT) ++ res = record_graphics_cmd(queue->device, swapchain, hack); ++ else if(queue->device->queue_props[queue_idx].queueFlags & VK_QUEUE_COMPUTE_BIT) ++ res = record_compute_cmd(queue->device, swapchain, hack); ++ else{ ++ ERR("Present queue is neither graphics nor compute queue!\n"); ++ res = VK_ERROR_DEVICE_LOST; ++ } ++ ++ if(res != VK_SUCCESS){ ++ queue->device->funcs.p_vkFreeCommandBuffers(queue->device->device, ++ swapchain->cmd_pools[hack->cmd_queue_idx], ++ 1, &hack->cmd); ++ hack->cmd = NULL; ++ heap_free(blit_cmds); ++ return res; ++ } ++ } ++ ++ blit_cmds[n_hacks] = hack->cmd; ++ ++ ++n_hacks; ++ } ++ } ++ ++ if(n_hacks > 0){ ++ VkPipelineStageFlags waitStage, *waitStages, *waitStages_arr = NULL; ++ ++ if(pPresentInfo->waitSemaphoreCount > 1){ ++ waitStages_arr = heap_alloc(sizeof(VkPipelineStageFlags) * pPresentInfo->waitSemaphoreCount); ++ for(i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) ++ waitStages_arr[i] = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; ++ waitStages = waitStages_arr; ++ }else{ ++ waitStage = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; ++ waitStages = &waitStage; ++ } ++ ++ /* blit user image to real image */ ++ submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; ++ submitInfo.waitSemaphoreCount = pPresentInfo->waitSemaphoreCount; ++ submitInfo.pWaitSemaphores = pPresentInfo->pWaitSemaphores; ++ submitInfo.pWaitDstStageMask = waitStages; ++ submitInfo.commandBufferCount = n_hacks; ++ submitInfo.pCommandBuffers = blit_cmds; ++ submitInfo.signalSemaphoreCount = 1; ++ submitInfo.pSignalSemaphores = &blit_sema; ++ ++ res = queue->device->funcs.p_vkQueueSubmit(queue->queue, 1, &submitInfo, VK_NULL_HANDLE); ++ if(res != VK_SUCCESS) ++ ERR("vkQueueSubmit: %d\n", res); ++ ++ heap_free(waitStages_arr); ++ heap_free(blit_cmds); ++ ++ our_presentInfo.waitSemaphoreCount = 1; ++ our_presentInfo.pWaitSemaphores = &blit_sema; ++ } ++ + arr = heap_alloc(our_presentInfo.swapchainCount * sizeof(VkSwapchainKHR)); + if(!arr){ + ERR("Failed to allocate memory for swapchain array\n"); +@@ -1441,23 +2599,75 @@ VkResult WINAPI wine_vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pP + + } + +-void WINAPI wine_vkCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier *pImageMemoryBarriers) ++void WINAPI wine_vkCmdPipelineBarrier(VkCommandBuffer commandBuffer, ++ VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, ++ VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, ++ const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, ++ const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, ++ const VkImageMemoryBarrier *pImageMemoryBarriers) + { + #if defined(USE_STRUCT_CONVERSION) + VkBufferMemoryBarrier_host *pBufferMemoryBarriers_host; +- VkImageMemoryBarrier_host *pImageMemoryBarriers_host; ++#endif ++ VkImageMemoryBarrier_host *pImageMemoryBarriers_host = NULL; ++ uint32_t i, j, k; ++ int old, new; ++ + TRACE("%p, %#x, %#x, %#x, %u, %p, %u, %p, %u, %p\n", commandBuffer, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers); + ++#if defined(USE_STRUCT_CONVERSION) + pBufferMemoryBarriers_host = convert_VkBufferMemoryBarrier_array_win_to_host(pBufferMemoryBarriers, bufferMemoryBarrierCount); + pImageMemoryBarriers_host = convert_VkImageMemoryBarrier_array_win_to_host(pImageMemoryBarriers, imageMemoryBarrierCount); +- commandBuffer->device->funcs.p_vkCmdPipelineBarrier(commandBuffer->command_buffer, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers_host, imageMemoryBarrierCount, pImageMemoryBarriers_host); ++#endif + ++ /* if the client is trying to transition a user image to PRESENT_SRC, ++ * transition it to GENERAL instead. */ ++ EnterCriticalSection(&commandBuffer->device->swapchain_lock); ++ for(i = 0; i < imageMemoryBarrierCount; ++i){ ++ old = pImageMemoryBarriers[i].oldLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; ++ new = pImageMemoryBarriers[i].newLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; ++ if(old || new){ ++ for(j = 0; j < commandBuffer->device->num_swapchains; ++j){ ++ struct VkSwapchainKHR_T *swapchain = commandBuffer->device->swapchains[j]; ++ if(swapchain->fs_hack_enabled){ ++ for(k = 0; k < swapchain->n_images; ++k){ ++ struct fs_hack_image *hack = &swapchain->fs_hack_images[k]; ++ if(pImageMemoryBarriers[i].image == hack->user_image){ ++#if !defined(USE_STRUCT_CONVERSION) ++ if(!pImageMemoryBarriers_host) ++ pImageMemoryBarriers_host = convert_VkImageMemoryBarrier_array_win_to_host(pImageMemoryBarriers, imageMemoryBarrierCount); ++#endif ++ if(old) ++ pImageMemoryBarriers_host[i].oldLayout = VK_IMAGE_LAYOUT_GENERAL; ++ if(new) ++ pImageMemoryBarriers_host[i].newLayout = VK_IMAGE_LAYOUT_GENERAL; ++ goto next; ++ } ++ } ++ } ++ } ++ } ++next: ; ++ } ++ LeaveCriticalSection(&commandBuffer->device->swapchain_lock); ++ ++ commandBuffer->device->funcs.p_vkCmdPipelineBarrier(commandBuffer->command_buffer, ++ srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, ++ pMemoryBarriers, bufferMemoryBarrierCount, ++#if defined(USE_STRUCT_CONVERSION) ++ pBufferMemoryBarriers_host, imageMemoryBarrierCount, pImageMemoryBarriers_host ++#else ++ pBufferMemoryBarriers, imageMemoryBarrierCount, ++ pImageMemoryBarriers_host ? (VkImageMemoryBarrier*)pImageMemoryBarriers_host : pImageMemoryBarriers ++#endif ++ ); ++ ++#if defined(USE_STRUCT_CONVERSION) + free_VkBufferMemoryBarrier_array(pBufferMemoryBarriers_host, bufferMemoryBarrierCount); +- free_VkImageMemoryBarrier_array(pImageMemoryBarriers_host, imageMemoryBarrierCount); + #else +- TRACE("%p, %#x, %#x, %#x, %u, %p, %u, %p, %u, %p\n", commandBuffer, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers); +- commandBuffer->device->funcs.p_vkCmdPipelineBarrier(commandBuffer->command_buffer, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers); ++ if(pImageMemoryBarriers_host) + #endif ++ free_VkImageMemoryBarrier_array(pImageMemoryBarriers_host, imageMemoryBarrierCount); + } + + VkDevice WINAPI __wine_get_native_VkDevice(VkDevice device) +diff --git a/dlls/winevulkan/vulkan_private.h b/dlls/winevulkan/vulkan_private.h +index b74a850bf37..c06774a27fa 100644 +--- a/dlls/winevulkan/vulkan_private.h ++++ b/dlls/winevulkan/vulkan_private.h +@@ -81,6 +81,7 @@ struct VkDevice_T + + uint32_t num_swapchains; + struct VkSwapchainKHR_T **swapchains; ++ VkQueueFamilyProperties *queue_props; + + CRITICAL_SECTION swapchain_lock; + }; +@@ -136,10 +137,37 @@ static inline VkCommandPool wine_cmd_pool_to_handle(struct wine_cmd_pool *cmd_po + return (VkCommandPool)(uintptr_t)cmd_pool; + } + ++struct fs_hack_image ++{ ++ uint32_t cmd_queue_idx; ++ VkCommandBuffer cmd; ++ VkImage swapchain_image; ++ VkImage blit_image; ++ VkImage user_image; ++ VkSemaphore blit_finished; ++ VkImageView user_view, blit_view; ++ VkDescriptorSet descriptor_set; ++ VkPipeline pipeline; ++}; ++ + struct VkSwapchainKHR_T + { + struct wine_vk_base base; + VkSwapchainKHR swapchain; /* native swapchain */ ++ ++ /* fs hack data below */ ++ BOOL fs_hack_enabled; ++ VkExtent2D user_extent; ++ VkExtent2D real_extent; ++ VkRect2D blit_dst; ++ VkCommandPool *cmd_pools; /* VkCommandPool[device->max_queue_families] */ ++ VkDeviceMemory user_image_memory, blit_image_memory; ++ uint32_t n_images; ++ struct fs_hack_image *fs_hack_images; /* struct fs_hack_image[n_images] */ ++ VkSampler sampler; ++ VkDescriptorPool descriptor_pool; ++ VkDescriptorSetLayout descriptor_set_layout; ++ VkPipelineLayout pipeline_layout; + }; + + void *wine_vk_get_device_proc_addr(const char *name) DECLSPEC_HIDDEN; +diff --git a/dlls/winevulkan/vulkan_thunks.c b/dlls/winevulkan/vulkan_thunks.c +index 8ea6129336b..eb4e1b9bfae 100644 +--- a/dlls/winevulkan/vulkan_thunks.c ++++ b/dlls/winevulkan/vulkan_thunks.c +@@ -455,69 +455,6 @@ static inline void free_VkWriteDescriptorSet_array(VkWriteDescriptorSet_host *in + heap_free(in); + } + +-VkBufferMemoryBarrier_host *convert_VkBufferMemoryBarrier_array_win_to_host(const VkBufferMemoryBarrier *in, uint32_t count) +-{ +- VkBufferMemoryBarrier_host *out; +- unsigned int i; +- +- if (!in) return NULL; +- +- out = heap_alloc(count * sizeof(*out)); +- for (i = 0; i < count; i++) +- { +- out[i].sType = in[i].sType; +- out[i].pNext = in[i].pNext; +- out[i].srcAccessMask = in[i].srcAccessMask; +- out[i].dstAccessMask = in[i].dstAccessMask; +- out[i].srcQueueFamilyIndex = in[i].srcQueueFamilyIndex; +- out[i].dstQueueFamilyIndex = in[i].dstQueueFamilyIndex; +- out[i].buffer = in[i].buffer; +- out[i].offset = in[i].offset; +- out[i].size = in[i].size; +- } +- +- return out; +-} +- +-void free_VkBufferMemoryBarrier_array(VkBufferMemoryBarrier_host *in, uint32_t count) +-{ +- if (!in) return; +- +- heap_free(in); +-} +- +-VkImageMemoryBarrier_host *convert_VkImageMemoryBarrier_array_win_to_host(const VkImageMemoryBarrier *in, uint32_t count) +-{ +- VkImageMemoryBarrier_host *out; +- unsigned int i; +- +- if (!in) return NULL; +- +- out = heap_alloc(count * sizeof(*out)); +- for (i = 0; i < count; i++) +- { +- out[i].sType = in[i].sType; +- out[i].pNext = in[i].pNext; +- out[i].srcAccessMask = in[i].srcAccessMask; +- out[i].dstAccessMask = in[i].dstAccessMask; +- out[i].oldLayout = in[i].oldLayout; +- out[i].newLayout = in[i].newLayout; +- out[i].srcQueueFamilyIndex = in[i].srcQueueFamilyIndex; +- out[i].dstQueueFamilyIndex = in[i].dstQueueFamilyIndex; +- out[i].image = in[i].image; +- out[i].subresourceRange = in[i].subresourceRange; +- } +- +- return out; +-} +- +-void free_VkImageMemoryBarrier_array(VkImageMemoryBarrier_host *in, uint32_t count) +-{ +- if (!in) return; +- +- heap_free(in); +-} +- + static inline void convert_VkAccelerationStructureCreateInfoNV_win_to_host(const VkAccelerationStructureCreateInfoNV *in, VkAccelerationStructureCreateInfoNV_host *out) + { + if (!in) return; +@@ -1310,6 +1247,69 @@ static inline void free_VkCopyDescriptorSet_array(VkCopyDescriptorSet_host *in, + + #endif /* USE_STRUCT_CONVERSION */ + ++VkBufferMemoryBarrier_host *convert_VkBufferMemoryBarrier_array_win_to_host(const VkBufferMemoryBarrier *in, uint32_t count) ++{ ++ VkBufferMemoryBarrier_host *out; ++ unsigned int i; ++ ++ if (!in) return NULL; ++ ++ out = heap_alloc(count * sizeof(*out)); ++ for (i = 0; i < count; i++) ++ { ++ out[i].sType = in[i].sType; ++ out[i].pNext = in[i].pNext; ++ out[i].srcAccessMask = in[i].srcAccessMask; ++ out[i].dstAccessMask = in[i].dstAccessMask; ++ out[i].srcQueueFamilyIndex = in[i].srcQueueFamilyIndex; ++ out[i].dstQueueFamilyIndex = in[i].dstQueueFamilyIndex; ++ out[i].buffer = in[i].buffer; ++ out[i].offset = in[i].offset; ++ out[i].size = in[i].size; ++ } ++ ++ return out; ++} ++ ++void free_VkBufferMemoryBarrier_array(VkBufferMemoryBarrier_host *in, uint32_t count) ++{ ++ if (!in) return; ++ ++ heap_free(in); ++} ++ ++VkImageMemoryBarrier_host *convert_VkImageMemoryBarrier_array_win_to_host(const VkImageMemoryBarrier *in, uint32_t count) ++{ ++ VkImageMemoryBarrier_host *out; ++ unsigned int i; ++ ++ if (!in) return NULL; ++ ++ out = heap_alloc(count * sizeof(*out)); ++ for (i = 0; i < count; i++) ++ { ++ out[i].sType = in[i].sType; ++ out[i].pNext = in[i].pNext; ++ out[i].srcAccessMask = in[i].srcAccessMask; ++ out[i].dstAccessMask = in[i].dstAccessMask; ++ out[i].oldLayout = in[i].oldLayout; ++ out[i].newLayout = in[i].newLayout; ++ out[i].srcQueueFamilyIndex = in[i].srcQueueFamilyIndex; ++ out[i].dstQueueFamilyIndex = in[i].dstQueueFamilyIndex; ++ out[i].image = in[i].image; ++ out[i].subresourceRange = in[i].subresourceRange; ++ } ++ ++ return out; ++} ++ ++void free_VkImageMemoryBarrier_array(VkImageMemoryBarrier_host *in, uint32_t count) ++{ ++ if (!in) return; ++ ++ heap_free(in); ++} ++ + VkResult WINAPI wine_vkAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo, uint32_t *pImageIndex) + { + #if defined(USE_STRUCT_CONVERSION) +diff --git a/dlls/winevulkan/vulkan_thunks.h b/dlls/winevulkan/vulkan_thunks.h +index c2a5641ef32..c741e305efc 100644 +--- a/dlls/winevulkan/vulkan_thunks.h ++++ b/dlls/winevulkan/vulkan_thunks.h +@@ -753,13 +753,10 @@ typedef struct VkCopyDescriptorSet_host + } VkCopyDescriptorSet_host; + + +-#if defined(USE_STRUCT_CONVERSION) + VkBufferMemoryBarrier_host *convert_VkBufferMemoryBarrier_array_win_to_host(const VkBufferMemoryBarrier *in, uint32_t count); + void free_VkBufferMemoryBarrier_array(VkBufferMemoryBarrier_host *in, uint32_t count); + VkImageMemoryBarrier_host *convert_VkImageMemoryBarrier_array_win_to_host(const VkImageMemoryBarrier *in, uint32_t count); + void free_VkImageMemoryBarrier_array(VkImageMemoryBarrier_host *in, uint32_t count); +-#endif /* USE_STRUCT_CONVERSION */ +- + /* For use by vkDevice and children */ + struct vulkan_device_funcs + { +diff --git a/dlls/winex11.drv/vulkan.c b/dlls/winex11.drv/vulkan.c +index 28ae1a9e0e8..2e2ac8f0b40 100644 +--- a/dlls/winex11.drv/vulkan.c ++++ b/dlls/winex11.drv/vulkan.c +@@ -544,6 +544,39 @@ static VkResult X11DRV_vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR * + return res; + } + ++static VkBool32 X11DRV_query_fs_hack(VkExtent2D *real_sz, VkExtent2D *user_sz, ++ VkRect2D *dst_blit) ++{ ++ if(fs_hack_enabled()){ ++ POINT real_res = fs_hack_real_mode(); ++ POINT user_res = fs_hack_current_mode(); ++ POINT scaled = fs_hack_get_scaled_screen_size(); ++ POINT scaled_origin = {0, 0}; ++ ++ fs_hack_user_to_real(&scaled_origin); ++ ++ if(real_sz){ ++ real_sz->width = real_res.x; ++ real_sz->height = real_res.y; ++ } ++ ++ if(user_sz){ ++ user_sz->width = user_res.x; ++ user_sz->height = user_res.y; ++ } ++ ++ if(dst_blit){ ++ dst_blit->offset.x = scaled_origin.x; ++ dst_blit->offset.y = scaled_origin.y; ++ dst_blit->extent.width = scaled.x; ++ dst_blit->extent.height = scaled.y; ++ } ++ ++ return VK_TRUE; ++ } ++ return VK_FALSE; ++} ++ + static const struct vulkan_funcs vulkan_funcs = + { + X11DRV_vkCreateInstance, +@@ -564,6 +597,7 @@ static const struct vulkan_funcs vulkan_funcs = + X11DRV_vkGetPhysicalDeviceWin32PresentationSupportKHR, + X11DRV_vkGetSwapchainImagesKHR, + X11DRV_vkQueuePresentKHR, ++ X11DRV_query_fs_hack, + }; + + static void *X11DRV_get_vk_device_proc_addr(const char *name) +diff --git a/include/wine/vulkan_driver.h b/include/wine/vulkan_driver.h +index a5bc50325c7..bd27a1b0f19 100644 +--- a/include/wine/vulkan_driver.h ++++ b/include/wine/vulkan_driver.h +@@ -65,6 +65,13 @@ struct vulkan_funcs + VkBool32 (*p_vkGetPhysicalDeviceWin32PresentationSupportKHR)(VkPhysicalDevice, uint32_t); + VkResult (*p_vkGetSwapchainImagesKHR)(VkDevice, VkSwapchainKHR, uint32_t *, VkImage *); + VkResult (*p_vkQueuePresentKHR)(VkQueue, const VkPresentInfoKHR *); ++ ++ /* Optional. Returns TRUE if FS hack is active, otherwise returns FALSE. If ++ * it returns TRUE, then real_sz will contain the actual display ++ * resolution; user_sz will contain the app's requested mode; and dst_blit ++ * will contain the area to blit the user image to in real coordinates. ++ * All parameters are optional. */ ++ VkBool32 (*query_fs_hack)(VkExtent2D *real_sz, VkExtent2D *user_sz, VkRect2D *dst_blit); + }; + + extern const struct vulkan_funcs * CDECL __wine_get_vulkan_driver(HDC hdc, UINT version); +From e09840b7e114774b2a7995ea88c9c50d161cb33c Mon Sep 17 00:00:00 2001 +From: Andrew Eikum +Date: Wed, 9 May 2018 15:24:38 -0500 +Subject: [PATCH] winevulkan: Blit directly to swapchain images if possible + +--- + dlls/winevulkan/vulkan.c | 300 ++++++++++++++++++------------- + dlls/winevulkan/vulkan_private.h | 1 + + 2 files changed, 175 insertions(+), 126 deletions(-) + +diff --git a/dlls/winevulkan/vulkan.c b/dlls/winevulkan/vulkan.c +index 313bf8f78dc..398fbac93eb 100644 +--- a/dlls/winevulkan/vulkan.c ++++ b/dlls/winevulkan/vulkan.c +@@ -1702,6 +1702,7 @@ VkResult WINAPI wine_vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCrea + our_createinfo.imageExtent.height == user_sz.height) + { + uint32_t count; ++ VkSurfaceCapabilitiesKHR caps = {0}; + + device->phys_dev->instance->funcs.p_vkGetPhysicalDeviceQueueFamilyProperties(device->phys_dev->phys_dev, &count, NULL); + +@@ -1709,6 +1710,17 @@ VkResult WINAPI wine_vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCrea + + device->phys_dev->instance->funcs.p_vkGetPhysicalDeviceQueueFamilyProperties(device->phys_dev->phys_dev, &count, device->queue_props); + ++ result = device->phys_dev->instance->funcs.p_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device->phys_dev->phys_dev, pCreateInfo->surface, &caps); ++ if(result != VK_SUCCESS) ++ { ++ TRACE("vkGetPhysicalDeviceSurfaceCapabilities failed, res=%d\n", result); ++ heap_free(object); ++ return result; ++ } ++ ++ object->surface_usage = caps.supportedUsageFlags; ++ TRACE("surface usage flags: 0x%x\n", object->surface_usage); ++ + our_createinfo.imageExtent = object->real_extent; + our_createinfo.imageUsage |= VK_IMAGE_USAGE_TRANSFER_DST_BIT; /* XXX: check if supported by surface */ + +@@ -1993,65 +2005,89 @@ static VkResult init_blit_images(VkDevice device, struct VkSwapchainKHR_T *swapc + goto fail; + } + +- /* create intermediate blit images */ +- for(i = 0; i < swapchain->n_images; ++i){ +- struct fs_hack_image *hack = &swapchain->fs_hack_images[i]; ++ if(!(swapchain->surface_usage & VK_IMAGE_USAGE_STORAGE_BIT)){ ++ TRACE("using intermediate blit images\n"); ++ /* create intermediate blit images */ ++ for(i = 0; i < swapchain->n_images; ++i){ ++ struct fs_hack_image *hack = &swapchain->fs_hack_images[i]; ++ ++ imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; ++ imageInfo.imageType = VK_IMAGE_TYPE_2D; ++ imageInfo.extent.width = swapchain->real_extent.width; ++ imageInfo.extent.height = swapchain->real_extent.height; ++ imageInfo.extent.depth = 1; ++ imageInfo.mipLevels = 1; ++ imageInfo.arrayLayers = 1; ++ imageInfo.format = VK_FORMAT_R8G8B8A8_UNORM; ++ imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL; ++ imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; ++ imageInfo.usage = VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT; ++ imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; ++ imageInfo.samples = VK_SAMPLE_COUNT_1_BIT; ++ res = device->funcs.p_vkCreateImage(device->device, &imageInfo, NULL, &hack->blit_image); ++ if(res != VK_SUCCESS){ ++ ERR("vkCreateImage failed: %d\n", res); ++ goto fail; ++ } + +- imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; +- imageInfo.imageType = VK_IMAGE_TYPE_2D; +- imageInfo.extent.width = swapchain->real_extent.width; +- imageInfo.extent.height = swapchain->real_extent.height; +- imageInfo.extent.depth = 1; +- imageInfo.mipLevels = 1; +- imageInfo.arrayLayers = 1; +- imageInfo.format = VK_FORMAT_R8G8B8A8_UNORM; +- imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL; +- imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; +- imageInfo.usage = VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT; +- imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; +- imageInfo.samples = VK_SAMPLE_COUNT_1_BIT; +- res = device->funcs.p_vkCreateImage(device->device, &imageInfo, NULL, &hack->blit_image); +- if(res != VK_SUCCESS){ +- ERR("vkCreateImage failed: %d\n", res); +- goto fail; ++ device->funcs.p_vkGetImageMemoryRequirements(device->device, hack->blit_image, &blitMemReq); ++ ++ offs = blitMemTotal % blitMemReq.alignment; ++ if(offs) ++ blitMemTotal += blitMemReq.alignment - offs; ++ ++ blitMemTotal += blitMemReq.size; + } + +- device->funcs.p_vkGetImageMemoryRequirements(device->device, hack->blit_image, &blitMemReq); ++ /* allocate backing memory */ ++ device->phys_dev->instance->funcs.p_vkGetPhysicalDeviceMemoryProperties(device->phys_dev->phys_dev, &memProperties); + +- offs = blitMemTotal % blitMemReq.alignment; +- if(offs) +- blitMemTotal += blitMemReq.alignment - offs; ++ for(i = 0; i < memProperties.memoryTypeCount; i++){ ++ if((memProperties.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT){ ++ if(blitMemReq.memoryTypeBits & (1 << i)){ ++ blit_memory_type = i; ++ break; ++ } ++ } ++ } + +- blitMemTotal += blitMemReq.size; +- } ++ if(blit_memory_type == -1){ ++ ERR("unable to find suitable memory type\n"); ++ res = VK_ERROR_OUT_OF_HOST_MEMORY; ++ goto fail; ++ } + +- /* allocate backing memory */ +- device->phys_dev->instance->funcs.p_vkGetPhysicalDeviceMemoryProperties(device->phys_dev->phys_dev, &memProperties); ++ allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; ++ allocInfo.allocationSize = blitMemTotal; ++ allocInfo.memoryTypeIndex = blit_memory_type; + +- for(i = 0; i < memProperties.memoryTypeCount; i++){ +- if((memProperties.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT){ +- if(blitMemReq.memoryTypeBits & (1 << i)){ +- blit_memory_type = i; +- break; +- } ++ res = device->funcs.p_vkAllocateMemory(device->device, &allocInfo, NULL, &swapchain->blit_image_memory); ++ if(res != VK_SUCCESS){ ++ ERR("vkAllocateMemory: %d\n", res); ++ goto fail; + } +- } + +- if(blit_memory_type == -1){ +- ERR("unable to find suitable memory type\n"); +- res = VK_ERROR_OUT_OF_HOST_MEMORY; +- goto fail; +- } ++ /* bind backing memory and create imageviews */ ++ blitMemTotal = 0; ++ for(i = 0; i < swapchain->n_images; ++i){ ++ struct fs_hack_image *hack = &swapchain->fs_hack_images[i]; + +- allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; +- allocInfo.allocationSize = blitMemTotal; +- allocInfo.memoryTypeIndex = blit_memory_type; ++ device->funcs.p_vkGetImageMemoryRequirements(device->device, hack->blit_image, &blitMemReq); + +- res = device->funcs.p_vkAllocateMemory(device->device, &allocInfo, NULL, &swapchain->blit_image_memory); +- if(res != VK_SUCCESS){ +- ERR("vkAllocateMemory: %d\n", res); +- goto fail; +- } ++ offs = blitMemTotal % blitMemReq.alignment; ++ if(offs) ++ blitMemTotal += blitMemReq.alignment - offs; ++ ++ res = device->funcs.p_vkBindImageMemory(device->device, hack->blit_image, swapchain->blit_image_memory, blitMemTotal); ++ if(res != VK_SUCCESS){ ++ ERR("vkBindImageMemory: %d\n", res); ++ goto fail; ++ } ++ ++ blitMemTotal += blitMemReq.size; ++ } ++ }else ++ TRACE("blitting directly to swapchain images\n"); + + shaderInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + shaderInfo.codeSize = sizeof(blit_comp_spv); +@@ -2063,27 +2099,12 @@ static VkResult init_blit_images(VkDevice device, struct VkSwapchainKHR_T *swapc + goto fail; + } + +- /* bind backing memory and create imageviews */ +- blitMemTotal = 0; ++ /* create imageviews */ + for(i = 0; i < swapchain->n_images; ++i){ + struct fs_hack_image *hack = &swapchain->fs_hack_images[i]; + +- device->funcs.p_vkGetImageMemoryRequirements(device->device, hack->blit_image, &blitMemReq); +- +- offs = blitMemTotal % blitMemReq.alignment; +- if(offs) +- blitMemTotal += blitMemReq.alignment - offs; +- +- res = device->funcs.p_vkBindImageMemory(device->device, hack->blit_image, swapchain->blit_image_memory, blitMemTotal); +- if(res != VK_SUCCESS){ +- ERR("vkBindImageMemory: %d\n", res); +- goto fail; +- } +- +- blitMemTotal += blitMemReq.size; +- + viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; +- viewInfo.image = hack->blit_image; ++ viewInfo.image = hack->blit_image ? hack->blit_image : hack->swapchain_image; + viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; + viewInfo.format = VK_FORMAT_R8G8B8A8_UNORM; + viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; +@@ -2198,7 +2219,7 @@ static VkResult record_compute_cmd(VkDevice device, struct VkSwapchainKHR_T *swa + barriers[1].newLayout = VK_IMAGE_LAYOUT_GENERAL; + barriers[1].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barriers[1].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; +- barriers[1].image = hack->blit_image; ++ barriers[1].image = hack->blit_image ? hack->blit_image : hack->swapchain_image; + barriers[1].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + barriers[1].subresourceRange.baseMipLevel = 0; + barriers[1].subresourceRange.levelCount = 1; +@@ -2264,66 +2285,93 @@ static VkResult record_compute_cmd(VkDevice device, struct VkSwapchainKHR_T *swa + 1, barriers + ); + +- /* transition blit image layout from GENERAL to TRANSFER_SRC +- * and access from SHADER_WRITE_BIT to TRANSFER_READ_BIT */ +- barriers[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; +- barriers[0].oldLayout = VK_IMAGE_LAYOUT_GENERAL; +- barriers[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; +- barriers[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; +- barriers[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; +- barriers[0].image = hack->blit_image; +- barriers[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; +- barriers[0].subresourceRange.baseMipLevel = 0; +- barriers[0].subresourceRange.levelCount = 1; +- barriers[0].subresourceRange.baseArrayLayer = 0; +- barriers[0].subresourceRange.layerCount = 1; +- barriers[0].srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT; +- barriers[0].dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; +- +- /* transition swapchain image from whatever to PRESENT_SRC */ +- barriers[1].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; +- barriers[1].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; +- barriers[1].newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; +- barriers[1].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; +- barriers[1].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; +- barriers[1].image = hack->swapchain_image; +- barriers[1].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; +- barriers[1].subresourceRange.baseMipLevel = 0; +- barriers[1].subresourceRange.levelCount = 1; +- barriers[1].subresourceRange.baseArrayLayer = 0; +- barriers[1].subresourceRange.layerCount = 1; +- barriers[1].srcAccessMask = 0; +- barriers[1].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; +- +- device->funcs.p_vkCmdPipelineBarrier( +- hack->cmd, +- VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, +- VK_PIPELINE_STAGE_TRANSFER_BIT, +- 0, +- 0, NULL, +- 0, NULL, +- 2, barriers +- ); +- +- /* copy from blit image to swapchain image */ +- region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; +- region.srcSubresource.layerCount = 1; +- region.srcOffset.x = 0; +- region.srcOffset.y = 0; +- region.srcOffset.z = 0; +- region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; +- region.dstSubresource.layerCount = 1; +- region.dstOffset.x = 0; +- region.dstOffset.y = 0; +- region.dstOffset.z = 0; +- region.extent.width = swapchain->real_extent.width; +- region.extent.height = swapchain->real_extent.height; +- region.extent.depth = 1; +- +- device->funcs.p_vkCmdCopyImage(hack->cmd, +- hack->blit_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, +- hack->swapchain_image, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, +- 1, ®ion); ++ if(hack->blit_image){ ++ /* transition blit image layout from GENERAL to TRANSFER_SRC ++ * and access from SHADER_WRITE_BIT to TRANSFER_READ_BIT */ ++ barriers[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; ++ barriers[0].oldLayout = VK_IMAGE_LAYOUT_GENERAL; ++ barriers[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; ++ barriers[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; ++ barriers[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; ++ barriers[0].image = hack->blit_image; ++ barriers[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; ++ barriers[0].subresourceRange.baseMipLevel = 0; ++ barriers[0].subresourceRange.levelCount = 1; ++ barriers[0].subresourceRange.baseArrayLayer = 0; ++ barriers[0].subresourceRange.layerCount = 1; ++ barriers[0].srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT; ++ barriers[0].dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; ++ ++ /* transition swapchain image from whatever to PRESENT_SRC */ ++ barriers[1].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; ++ barriers[1].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; ++ barriers[1].newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; ++ barriers[1].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; ++ barriers[1].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; ++ barriers[1].image = hack->swapchain_image; ++ barriers[1].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; ++ barriers[1].subresourceRange.baseMipLevel = 0; ++ barriers[1].subresourceRange.levelCount = 1; ++ barriers[1].subresourceRange.baseArrayLayer = 0; ++ barriers[1].subresourceRange.layerCount = 1; ++ barriers[1].srcAccessMask = 0; ++ barriers[1].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; ++ ++ device->funcs.p_vkCmdPipelineBarrier( ++ hack->cmd, ++ VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, ++ VK_PIPELINE_STAGE_TRANSFER_BIT, ++ 0, ++ 0, NULL, ++ 0, NULL, ++ 2, barriers ++ ); ++ ++ /* copy from blit image to swapchain image */ ++ region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; ++ region.srcSubresource.layerCount = 1; ++ region.srcOffset.x = 0; ++ region.srcOffset.y = 0; ++ region.srcOffset.z = 0; ++ region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; ++ region.dstSubresource.layerCount = 1; ++ region.dstOffset.x = 0; ++ region.dstOffset.y = 0; ++ region.dstOffset.z = 0; ++ region.extent.width = swapchain->real_extent.width; ++ region.extent.height = swapchain->real_extent.height; ++ region.extent.depth = 1; ++ ++ device->funcs.p_vkCmdCopyImage(hack->cmd, ++ hack->blit_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, ++ hack->swapchain_image, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, ++ 1, ®ion); ++ }else{ ++ /* transition swapchain image from GENERAL to PRESENT_SRC */ ++ barriers[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; ++ barriers[0].oldLayout = VK_IMAGE_LAYOUT_GENERAL; ++ barriers[0].newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; ++ barriers[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; ++ barriers[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; ++ barriers[0].image = hack->swapchain_image; ++ barriers[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; ++ barriers[0].subresourceRange.baseMipLevel = 0; ++ barriers[0].subresourceRange.levelCount = 1; ++ barriers[0].subresourceRange.baseArrayLayer = 0; ++ barriers[0].subresourceRange.layerCount = 1; ++ barriers[0].srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT; ++ barriers[0].dstAccessMask = 0; ++ ++ device->funcs.p_vkCmdPipelineBarrier( ++ hack->cmd, ++ VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, ++ VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, ++ 0, ++ 0, NULL, ++ 0, NULL, ++ 1, barriers ++ ); ++ } + + result = device->funcs.p_vkEndCommandBuffer(hack->cmd); + if(result != VK_SUCCESS){ +diff --git a/dlls/winevulkan/vulkan_private.h b/dlls/winevulkan/vulkan_private.h +index c06774a27fa..145635eea24 100644 +--- a/dlls/winevulkan/vulkan_private.h ++++ b/dlls/winevulkan/vulkan_private.h +@@ -159,6 +159,7 @@ struct VkSwapchainKHR_T + BOOL fs_hack_enabled; + VkExtent2D user_extent; + VkExtent2D real_extent; ++ VkImageUsageFlags surface_usage; + VkRect2D blit_dst; + VkCommandPool *cmd_pools; /* VkCommandPool[device->max_queue_families] */ + VkDeviceMemory user_image_memory, blit_image_memory; +From 61fb2be6fa62f3b4b40f27f6a46343ddc2471e60 Mon Sep 17 00:00:00 2001 +From: Andrew Eikum +Date: Tue, 25 Sep 2018 14:53:00 -0500 +Subject: [PATCH] Revert "winevulkan: Check if instance extensions are + supported." + +This reverts commit e84999bd7ab859746e893ed2d49b1d42b0323c3a. + +Vulkan VR games will try to load some extensions that winevulkan doesn't +support. +--- + dlls/winevulkan/vulkan.c | 21 ++++----------------- + 1 file changed, 4 insertions(+), 17 deletions(-) + +diff --git a/dlls/winevulkan/vulkan.c b/dlls/winevulkan/vulkan.c +index 398fbac93eb..73a3023a522 100644 +--- a/dlls/winevulkan/vulkan.c ++++ b/dlls/winevulkan/vulkan.c +@@ -360,7 +360,7 @@ static BOOL wine_vk_init(void) + * This function takes care of extensions handled at winevulkan layer, a Wine graphics + * driver is responsible for handling e.g. surface extensions. + */ +-static VkResult wine_vk_instance_convert_create_info(const VkInstanceCreateInfo *src, ++static void wine_vk_instance_convert_create_info(const VkInstanceCreateInfo *src, + VkInstanceCreateInfo *dst) + { + unsigned int i; +@@ -401,19 +401,11 @@ static VkResult wine_vk_instance_convert_create_info(const VkInstanceCreateInfo + dst->enabledLayerCount = 0; + dst->ppEnabledLayerNames = NULL; + +- TRACE("Enabled %u instance extensions.\n", dst->enabledExtensionCount); ++ TRACE("Enabled extensions: %u\n", dst->enabledExtensionCount); + for (i = 0; i < dst->enabledExtensionCount; i++) + { +- const char *extension_name = dst->ppEnabledExtensionNames[i]; +- TRACE("Extension %u: %s.\n", i, debugstr_a(extension_name)); +- if (!wine_vk_instance_extension_supported(extension_name)) +- { +- WARN("Extension %s is not supported.\n", debugstr_a(extension_name)); +- return VK_ERROR_EXTENSION_NOT_PRESENT; +- } ++ TRACE("Extension %u: %s\n", i, debugstr_a(dst->ppEnabledExtensionNames[i])); + } +- +- return VK_SUCCESS; + } + + /* Helper function which stores wrapped physical devices in the instance object. */ +@@ -724,12 +716,7 @@ VkResult WINAPI wine_vkCreateInstance(const VkInstanceCreateInfo *create_info, + } + object->base.loader_magic = VULKAN_ICD_MAGIC_VALUE; + +- res = wine_vk_instance_convert_create_info(create_info, &create_info_host); +- if (res != VK_SUCCESS) +- { +- wine_vk_instance_free(object); +- return res; +- } ++ wine_vk_instance_convert_create_info(create_info, &create_info_host); + + res = vk_funcs->p_vkCreateInstance(&create_info_host, NULL /* allocator */, &object->instance); + if (res != VK_SUCCESS) +From cdded00e22815367a63af811a577c06651277cf9 Mon Sep 17 00:00:00 2001 +From: Andrew Eikum +Date: Tue, 25 Sep 2018 14:53:05 -0500 +Subject: [PATCH] Revert "winevulkan: Check if device extensions are + supported." + +This reverts commit 4907ffdf2a15ab3a1e3749def37f4be67b758a35. + +Vulkan VR games will try to load some extensions that winevulkan doesn't +support. +--- + dlls/winevulkan/vulkan.c | 13 +++---------- + 1 file changed, 3 insertions(+), 10 deletions(-) + +diff --git a/dlls/winevulkan/vulkan.c b/dlls/winevulkan/vulkan.c +index 73a3023a522..cc2d9146282 100644 +--- a/dlls/winevulkan/vulkan.c ++++ b/dlls/winevulkan/vulkan.c +@@ -279,16 +279,10 @@ static VkResult wine_vk_device_convert_create_info(const VkDeviceCreateInfo *src + dst->enabledLayerCount = 0; + dst->ppEnabledLayerNames = NULL; + +- TRACE("Enabled %u extensions.\n", dst->enabledExtensionCount); ++ TRACE("Enabled extensions: %u.\n", dst->enabledExtensionCount); + for (i = 0; i < dst->enabledExtensionCount; i++) + { +- const char *extension_name = dst->ppEnabledExtensionNames[i]; +- TRACE("Extension %u: %s.\n", i, debugstr_a(extension_name)); +- if (!wine_vk_device_extension_supported(extension_name)) +- { +- WARN("Extension %s is not supported.\n", debugstr_a(extension_name)); +- return VK_ERROR_EXTENSION_NOT_PRESENT; +- } ++ TRACE("Extension %u: %s.\n", i, debugstr_a(dst->ppEnabledExtensionNames[i])); + } + + return VK_SUCCESS; +@@ -625,8 +619,7 @@ VkResult WINAPI wine_vkCreateDevice(VkPhysicalDevice phys_dev, + res = wine_vk_device_convert_create_info(create_info, &create_info_host); + if (res != VK_SUCCESS) + { +- if (res != VK_ERROR_EXTENSION_NOT_PRESENT) +- ERR("Failed to convert VkDeviceCreateInfo, res=%d.\n", res); ++ ERR("Failed to convert VkDeviceCreateInfo, res=%d.\n", res); + wine_vk_device_free(object); + return res; + } +diff --git a/dlls/winevulkan/make_vulkan b/dlls/winevulkan/make_vulkan +index e915026f24..cdaa3a0498 100755 +--- a/dlls/winevulkan/make_vulkan ++++ b/dlls/winevulkan/make_vulkan +@@ -95,6 +95,7 @@ BLACKLISTED_EXTENSIONS = [ + "VK_EXT_validation_features", + "VK_EXT_validation_flags", + "VK_KHR_display", # Needs WSI work. ++ "VK_EXT_host_query_reset", + "VK_KHR_get_surface_capabilities2", + "VK_KHR_surface_protected_capabilities", + +@@ -2757,6 +2758,10 @@ class VkRegistry(object): + if required_extension and not self._is_extension_supported(required_extension): + continue + ++ required_extension = require.attrib.get("extension") ++ if required_extension and required_extension in BLACKLISTED_EXTENSIONS: ++ continue ++ + # Pull in any commands we need. We infer types to pull in from the command + # as well. + for command in require.findall("command"):