mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 13:55:58 +00:00
feat: non-Adreno graphics stack (Venus, open driver pairs, gamescope patches) (#2029)
* Retain compositor resources when GPU completion is unconfirmed * Stop quarantined GPU callers before retries and mapped writes * Support Android hardware-buffer presentation over Wayland * Support PowerVR swapchains and linear image imports in Gamescope * Bundle verified PowerVR graphics components through existing build preparation * Detect and select the system Vulkan backend on PowerVR * Apply PowerVR Steam and game compatibility during normal launches * Show PowerVR support through existing driver and component controls * Update existing hardware guidance for system Vulkan support * Import the shared system Vulkan readiness check * Discover and propagate the actual PowerVR render node * Prune obsolete PowerVR runtimes after guest processes exit * Retain external DMA-BUF ownership after GPU quarantine * Name the PowerVR HAL selection explicitly * Isolate component UI tests from application startup * Cover the inherited FEX preset in PowerVR profile tests * Log test worker failures for CI diagnosis * Remove temporary test logging after diagnostic CI * Prefer system dependencies for the Android Vulkan loader * Capture raw stderr before test worker termination * Remove the temporary test worker crash probe * Import pinned DXVK recipe prerequisite from PowerVR PR570 Copy only the standalone build recipe, source pin, BC-format prerequisite and presentation-sync patch/check from wallentx/DroidDeck atd0f7264ea8. Source: https://github.com/Droid-Deck/DroidDeck/pull/570 Preserve that proposal attribution; no Android app, compositor, managed pack, private data or fork development history is imported. * Add opt-in low32 GPU mapping adapter and integrity probes * Add opt-in D3D9 single-sample workaround and fix HUD texel format * Document verified production game workaround and publication scope * Restrict reset diagnostics and create private output atomically * Target official runtime review and document PR570 prerequisite provenance * Fix runtime tool output isolation, mmap64 chaining and DST ambiguity * Normalize swapchain backbuffers for the opt-in D3D9 single-sample path * Experimental Samsung Xclipse support on the system Vulkan path Detect Samsung's Vulkan HAL (vulkan.samsung.so) and its sgpu render node alongside PowerVR, and run Xclipse through the same libhybris bridge: - VK_LAYER_DROIDDECK_xclipse (tools/linuxfs/xclipse-layer), built with the glibc preloads and enabled only on Xclipse: sets bionic's environ for the driver's shader compiler, avoids immutable YCbCr samplers in compute layouts, forwards the KHR calibrated-timestamp entry points to the EXT ones, and reports textureCompressionBC and BC4/BC5 filtering over the compat layer's BC emulation. - Upstream DXVK 2.6.2, pinned as a tar.gz component and selected on Xclipse: the driver has 128 bytes of push constants, DXVK 3 needs 256. - android_wlegl accepts a zero stride and passes it through unchanged: Samsung's gralloc records none for GPU-only buffers. Tested on a Galaxy A56 (Xclipse 540, driver 24.0.560): Steam Big Picture and PICO PARK (D3D9). * Xclipse layer: copy the device chain and track samplers per device - Clear textureCompressionBC in a copy of the device-create chain (every structure up to the VkPhysicalDeviceFeatures2 that enables it) instead of writing the caller's structure; a chain led by a structure of unknown size is passed on unchanged. - Track YCbCr samplers per device in a growable list, drop them on vkDestroySampler and device teardown, and fail sampler creation rather than leave one untracked when the list cannot grow. - Fail descriptor set layout creation with VK_ERROR_OUT_OF_HOST_MEMORY when a replacement sampler array cannot be allocated, instead of passing the original YCbCr samplers to the driver. * Xclipse layer: copy any device-chain structure the headers define The chain copy that clears the emulated textureCompressionBC only knew a handful of structure sizes, so a valid chain such as VkPhysicalDeviceTimelineSemaphoreFeatures -> VkPhysicalDeviceFeatures2 was passed on unchanged and the compat layer refused the bit. Size every structure that may extend VkDeviceCreateInfo from a table generated from the Vulkan registry (gen_device_chain.py, Vulkan-Headers 1.3.275, the headers the build compiles with), and copy onto the heap instead of a fixed buffer. Only a structure newer than those headers still passes the chain unchanged. Add a regression test that runs the layer between a simulated loader and a mock driver: the timeline-semaphore chain, pEnabledFeatures, an unknown structure, the caller's structures left untouched, per-device YCbCr sampler tracking with handle reuse, and the KHR calibrated-timestamp forwarding. CI installs libvulkan-dev for it. * Mali bridge (#517, by ASEbrahim) on the non-Adreno test branch Squash of Droid-Deck/DroidDeck#517 (ASEbrahim/DroidDeck mali-bridge @6b823341): the Vulkan bridge (tools/vkbridge) that runs the guest's Vulkan on the phone's own driver, with BC1-BC7, clip/cull distance, vertex-divisor and depth-clip emulation and dma-heap memory sharing for Mali. All of the bridge is ASEbrahim's work; squashed only to carry it on this test branch. Combined with #570 on this branch, a device draws through exactly one path: - Adreno: Turnip, unchanged (checked first; the bridge setting is ignored there). - PowerVR / Xclipse with the system HAL and a render node: the system-Vulkan path (#570). - Anything else with the Setup toggle on (Mali): the bridge. * Test branch: keep #570's DXVK build recipe so its pinned PowerVR components verify #602 adds output checks to tools/dxvk/build.sh; tools/powervr/fetch.py pins the exact recipe the published PowerVR DXVK was built from, so the branch carries #570's copy. * Test branch: make #570, #602 and #560/#561 pass each other's tests - tools/dxvk/build.sh: #602's copy (its output checks) and the PowerVR pin in tools/powervr/release.json moved to that file's hash; the recipe's outputs are unchanged. - droiddeck-session: the presentation block sets _bl_cef for #570's PowerVR path, and the UI block keeps main's order, defaulting to -cef-use-angle=vulkan when the block has not run. - Compositor test harnesses: AHardwareBuffer stubs for #570's AHB import, and a stub for vkp_effects_forget_image (main #597) that #561's caller harness predates. * Auto drivers for Mali and Xclipse on the non-Adreno test branch Auto now picks an open driver pair for the GPU, the way it does for Adreno: - Mali (no KGSL, /dev/mali0): the GPU's name ("Mali-G720-Immortalis MC12", from the vendor Vulkan driver or kbase's gpuinfo) picks the PanVK build: G52-G78 (Job Manager), G610/G710, G615 or G720. A Mali none of them covers (G925...), or one whose pair is not published yet, draws through the Mali bridge, switched on by Auto. - Xclipse keeps the system-driver path as Auto; the RADV pair is offered as a manual choice. - The pairs come from The412Banner/droiddeck-nonadreno-drivers (one pre-release per driver, each a DriverBundle zip). Only a device without an Adreno reads that repo. - The importers accept PanVK and RADV libraries (libvulkan_panfrost / libvulkan_radeon). - An open driver pair and the Mali bridge are alternatives: a selected pair turns the bridge off. - TU_DEBUG is only set for Turnip, on an Adreno. Every new branch is reached only when the device has no Adreno; an Adreno's detection, release sources, Auto choice and session environment are unchanged. * Auto: the one-binary PanVK kbase build for Mali v9-v13 on Android 15+ The412Banner/droiddeck-nonadreno-drivers adds panvk-mali-kbase: one PanVK build for G57/G68/G77/G78, G610/G710, G615/G715, G720/G725 and G925, whose display half needs Android 15. On Android 15+ Auto prefers it for every Mali it covers; below 15, and whenever its release is not listed, Auto falls back to the GPU generation's own pair. G52/G76 keep the Job Manager build; a G715/G725/G925 below Android 15, or any Mali no pair covers, draws through the bridge. Every pair stays selectable by hand. * Test: the G925 is in the kbase build's family now * Offer faux123's device PanVK builds (RP4 Pro, Ace, RG556) as manual pairs for their Mali * Detailed graphics logs for non-Adreno test reports - graphics-report.txt in every session folder: the graphics path the session draws with and why (Turnip, system Vulkan #570, Mali bridge #517, or an open driver pair with its release), the driver mode and choices, what Auto would pick, the GPU (family, Vulkan device name, kbase gpuinfo, Android, SoC, kernel), the GPU nodes the app can see (access, device numbers, SELinux label; nothing is opened) and the guest's graphics environment. At the end it adds the compositor's driver lines from app.log and the game launches that were logged. - vulkan-summary.txt: the session's own vulkaninfo --summary with the driver as exported, in the background with a 10 s timeout. - Per-game logs under games/<time>-<appid>/: Proton's log, DXVK's and vkd3d-proton's, Mesa's and PanVK's startup messages and the launch environment, from droiddeck-game-env. Each file is cut to 20 MB and the folder to 120 MB at the session's end. - The per-game logs and the Vulkan summary are on for a GPU that is not an Adreno, and on an Adreno only with Setup's new "Detailed graphics logs" switch. Share logs already takes the whole session folder, so all of it is in the zip, scrubbed as before. * Mali pairs: a stand-in render node, the driver's real library name, and a Mali known by its chip - Auto on Jim's Dimensity 9300+ chose the bridge: the GPU had no name (the app had not asked Vulkan yet and kbase's gpuinfo is unreadable under SELinux), so a Mali-G720 counted as a Mali no build covers. The name now falls back to the GPU the chip is known to carry (Dimensity, Helio, Kompanio, Tensor); and when nothing names it, Auto asks the vendor Vulkan driver off the main thread before it settles for the bridge. Auto logs what it decided and why. - An open Mali driver pair gets /dev/mali0 as the guest's render node, as the bridge does (bindGpuNode, BL_DRM_STANDIN): gamescope needs the node the driver reports. The session shim only answers libdrm's PRIME and GEM-close calls on it, which PanVK on kbase never makes. - A PanVK or RADV runtime half is installed as libvulkan_panfrost.so / libvulkan_radeon.so rather than under Turnip's name; Turnip keeps libvulkan_freedreno.so. - graphics-report.txt names the render node the guest got, adds the session script's driver lines and flags a failed Mali-bridge self-test at the top. * Auto takes the RADV pair on a Samsung Xclipse, with the system route as its fallback A tester's Galaxy S24 FE (Xclipse 940) boots to Steam with the RADV-Xclipse pair, where the system-driver route fails at Steam's OpenGL (glamor and GLX cannot load a driver). Auto now downloads and selects RADV on an Xclipse like the Mali pairs, and falls back to the system route only when RADV is not published. #570's reset of both drivers at each start no longer undoes an open driver pair. PowerVR (vulkan.powervr.so) keeps the system driver as before. * An Exynos with a Mali is a Mali, not an Xclipse The system route took vulkan.samsung.so as Samsung's Xclipse, but an Exynos 1280/1380 (Galaxy Tab S9 FE: Mali-G68) may name its HAL the same; with /dev/mali0 present that HAL is not the system route's, and the device is detected as the Mali it is. The chip table adds the Exynos 1380 and 1280 (s5e8835, s5e8825: Mali-G68). * Auto fetches the open drivers itself; Xclipse named as such; sound and frame-gen in the logs - Auto looks online again when its saved release list predates this device's open drivers, so a Samsung or Mali phone gets its pair without pressing refresh first. - A Samsung Xclipse is labelled "Samsung Xclipse" (not PowerVR), with its own support line. - Per-game logs add audio-streams.txt: PulseAudio's sink inputs 20 s and 60 s into the launch, so a silent game shows whether its stream reached Pulse. - graphics-report.txt states the frame-generation setting and keeps the LSFG gate, FrameGen and audio lines from app.log. * Client sound retries a briefly disconnected AAudio; kbase ioctl refusals explained in the report A Galaxy S24 FE's session had no sound at all: the DirectAudio sink's AAudio stream opened with AAUDIO_ERROR_DISCONNECTED while the output route was still changing at session start, and the plain AAudio fallback failed the same moment. The sink guard now retries DirectAudio, then the plain sink, five times over ten seconds and says which one it got. graphics-report.txt keeps the client-sink and kbase lines, and explains a KBASE_IOCTL_MEM_EXEC_INIT EPERM as the kbase driver's own answer rather than the session's sandbox. * Mali pairs draw the display on the phone's own Mali driver; Xwayland falls back without glamor - Testers' Mali pairs got the guest drawing (gamescope on the stand-in node, Zink on PanVK) but the compositor's PanVK Android half failed on Mali gralloc: it probes AHB formats 0x38/0x3b that mali_gralloc does not have, and "vkCreateImage w/ native buffer failed". Under Auto a Mali pair now leaves the display on the phone's own Vulkan driver (dma-buf, modifiers and AHB all pass the testers' checks) and runs the pair's PanVK in the guest; the Android half stays installed for a manual pick. "Pair in use" now follows the runtime half. - A session after one whose Xwayland crashed (segfault, then gamescope's X11 I/O error) starts Xwayland with XWAYLAND_NO_GLAMOR=1 on a non-Adreno device, and says so in app.log. - graphics-report.txt names the display driver the compositor used, and keeps gralloc, dma-buf, modifier and import lines from app.log and Xwayland's own lines from the session log. * Non-Adreno sound: the daemon falls back on its own; the build's commit in device.txt and the report The S24 FE's session still had no sound: its AAudio refuses DirectAudio's low-latency stream with AAUDIO_ERROR_DISCONNECTED, and the sink guard never got to retry because pactl did not reach the daemon in time ("the daemon did not answer in 15 s"). On a GPU that is not an Adreno the daemon's own start-up script now asks DirectAudio again without low latency and loads the plain AAudio sink underneath it, so a default sink exists whatever pactl does. device.txt and graphics-report.txt name the build label and source commit, so a log says which build it came from. * Non-Adreno sound: no second DirectAudio load (it hung the daemon); the plain AAudio sink underneath On the S24 FE the daemon stopped after DirectAudio's failed low-latency load: the second DirectAudio load in the same daemon never returned, so nothing after it ran and pactl never connected. The daemon now loads only the plain AAudio sink (no low latency) after DirectAudio, inside .nofail, and sets whichever exists as the default. * gamescope: explicit sync off where the kernel or the stand-in node cannot signal its timelines Adds tools/gamescope/patches/0126 (GAMESCOPE_DISABLE_EXPLICIT_SYNC=1 for the nested backends) and sets it on a GPU that is not an Adreno when the kernel is older than 6.6 (no DRM_IOCTL_SYNCOBJ_EVENTFD) or the guest's render node is Mali's stand-in. The graphics report lists it with the rest of the guest's graphics environment. * Test branch: gamescope with the explicit-sync switch (0126), pinned by sha Built by build-gamescope.yml run 38335744351 from0136fb61and published as a component release of The412Banner/droiddeck-nonadreno-drivers; the apk build fetches it by tag and checks the sha. * Sound: nothing that can block in the daemon's start-up; Steam's web compositing in software on open pairs - The S24 FE (US) daemon hung loading the plain AAudio sink from default.pa (its AAudio open blocks rather than fails), so it never finished starting. default.pa is back to DirectAudio alone inside .nofail; the fallbacks are loaded from the app once the daemon answers, each pactl bounded by its timeout (DirectAudio, then the plain sink with and without low latency). The guard waits 30 s and logs, with timestamps, how long the daemon took, whether its socket and pactl exist, and what it finally got. - With an open driver pair on a GPU that is not an Adreno, Steam's CEF composites in software (-cef-disable-gpu-compositing) with GPU raster kept: RADV on Xclipse showed stale, half-written tiles, as #570 saw on PowerVR. The session log says so. * Mali under Auto: the display always on Android's own Vulkan loader; a reboot hint for refused audio Axel's Tab S9 FE still drew its display with the PanVK Android half, set by an earlier build, and stalled at "Waiting for Steam's first frame" on Mali gralloc's format probes. Under Auto a Mali's display now goes to Android's own loader whatever was set before (DriverMenus resets it, and the compositor's driver choice ignores a pair's Android half), with no HAL path to find first. A pair counts as in use when its runtime half is. A manual pick of the PanVK display is kept. When audio.log shows AAUDIO_ERROR_DISCONNECTED, the report and the client-sink line say Android refused the output and that rebooting the phone usually fixes it. * Fix: call SessionPrefs.gpuDriverMode through its instance from Java * Compositor: log each new dma-buf format/modifier/size it imports (for colour and swizzle reports) Steam's software web compositing already covers every open driver pair, Mali included. * Open driver pairs: vkd3d-proton reports the driver's caps; buffer attach/release tracing; Mesa log - With a PanVK or RADV pair (BL_OPEN_DRIVER=1), droiddeck-game-env drops the app-wide VKD3D_FEATURE_LEVEL=12_2 and VKD3D_SHADER_MODEL=6_9 so vkd3d-proton reports what the driver has (an Unreal DX12 game crashed at start on PanVK with the overrides); a game's own setting still wins, and launch.txt records DROIDDECK_VKD3D_CAPS=driver. - The compositor traces, on a GPU that is not an Adreno, the first 400 dma-buf attaches and buffer releases by wl_buffer id and sending line, and logs any release of a buffer already released and not attached again (gamescope's "Compositor released us but we were not acquired" on G925). - Per-game logs no longer set MESA_DEBUG=silent, which kept mesa.log empty. * Tests: the dma-buf quarantine harness follows send_buffer_release's tracing macro * Mali (Venus): David Cimo's Venus route sources and recipes From DavidCimo/droiddeck-mali, branch mali-venus @ 4f838891 (prototype 13; his 12 commits on top of DroidDeck 0.3.1, GPL-3.0), by David Cimo: - tools/venus: Mesa Venus vtest patch (incl. the per-queue submit_mutex fix and the cached-memory frame readback), virglrenderer Android patch, the Mali compatibility layer (the six features DXVK needs: fill modes, multi-viewport, robustness2, clip/cull distance, BC1-BC7) and his tools. - tools/linuxfs/preload/venus.c: keeps Zink's kopper under Venus. - tools/gamescope/patches/0127 (his 0114): shm buffers uploaded on every commit. - docs/development/mali-venus.md: his design notes. - tools/venus/ci-build.sh and build-venus.yml: his build recipes as one CI job that packs the component (vtest server, ICD, layer) as venus.tzst for the apk. Co-authored-by: Dersim Abbas <derabb0620@gmail.com> * Mali (Venus) as a selectable route, by David Cimo Ports David Cimo's Venus route (DavidCimo/droiddeck-mali, mali-venus @ 4f838891) onto this branch as "Mali (Venus)", one tap in Setup next to the Mali bridge: - VenusComponent (his): stages the Venus ICD and runs virglrenderer's vtest server over the phone's own Vulkan driver; the guest gets VK_ICD_FILENAMES, VN_DEBUG=vtest, VTEST_SOCKET_NAME and MESA_VK_WSI_DEBUG=sw. - Selection rule: Venus when Setup's "Mali (Venus)" is on, on a GPU that is neither an Adreno nor a system-driver one (PowerVR, Xclipse), and the apk carries it. It then replaces the Mali bridge and any open driver pair for the session, and the display stays on the phone's own driver. Auto is unchanged (the PanVK pair). Adreno never takes any of it. - The compositor enables only the dma-buf extensions the driver has, logs a vendor driver's extension list, and gives a zero row pitch a packed row (his vk_present.c changes). - The Mali compatibility layer is staged into the runtime on non-Adreno devices only. - The component (vtest server, ICD, layer) comes from build-venus.yml as venus.tzst, published on The412Banner/droiddeck-nonadreno-drivers and pinned by sha in tools/venus/release.env. - gamescope 3.16.29-p15 adds his shm upload patch (0127) next to 0126; pinned by sha. - device.txt and graphics-report.txt name the route. Co-authored-by: Dersim Abbas <derabb0620@gmail.com> * Mali: Venus gamescope without robustness2, the bridge switch honoured and kept, clean driver switches - gamescope 0128: VK_EXT_robustness2 is optional. A Mali driver through Venus has none, and gamescope stopped at "Missing required extension: VK_EXT_robustness2" (the wayland_surface error after it was only the knock-on). Without it, unused descriptor slots point at a 1x1 texture instead of VK_NULL_HANDLE. (David Cimo's Pixel 9 driver has robustness2, so his build never needed this.) gamescope component rebuilt and pinned by sha. - Open-files limit: on a GPU that is not an Adreno the session script raises the soft limit to the hard limit for the whole session tree (a PanVK-kbase session froze on "Too many open files" after ten minutes) and graphics-report.txt shows before and after. A stopgap; the driver leak is fixed separately. - The Mali bridge switch is honoured: when on and usable it wins over a PanVK pair for the session (Venus still wins over it). Selecting a pair no longer switches the bridge off, which is why the switch did not survive an app restart (Auto re-selected the pair at start). Setup says when this phone cannot use the bridge at all. - Driver switching: picking a Mali pair by hand keeps the display on the phone's own driver, as Auto does (a PanVK Android display stalls on Mali gralloc at "Waiting for Steam's first frame", and stayed set after switching back); installing a bundle again replaces it instead of adding a "-2" copy beside the old one. - graphics-report.txt names the runtime driver's folder and libraries, and the previous session's drivers, flagged when they changed. * gamescope p16 (0128 robustness2 optional), pinned by sha; graphics-report says who chose the display driver * Bundle replace only for open non-Adreno pairs; Adreno bundles keep their numbered copies * Rebuilt open drivers reach phones: re-downloaded when their digest changes, release list hourly on non-Adreno The non-Adreno driver releases replace their assets in place (the PanVK kbase sync-file fd leak fix). A download is now remembered with its GitHub sha256, and an asset whose digest changed counts as not installed, so Auto fetches it again and the bundle replaces the old one; the release list is re-read after an hour instead of a day on a GPU that is not an Adreno. * Mali compatibility layer: multiDrawIndirect, depthClipEnable and robustness2 for DXVK on Venus A Galaxy A15 (Mali-G57) on Venus got gamescope and Steam up, but DXVK refused the GPU: "Device does not support required feature 'multiDrawIndirect'". DXVK 3.1 stops at the first missing feature, so the rest of its required list (dxvk_device_info.cpp) was checked against what the testers' Mali drivers cannot have, and covered in the same pass, on top of David Cimo's six: - multiDrawIndirect: reported, taken off the device, and an indirect draw with drawCount > 1 is recorded as single draws at offset + i * stride; maxDrawIndirectCount reported as 2^30. (drawIndirectCount is optional for DXVK and stays as the driver says.) - VK_EXT_depth_clip_enable (required): offered when the driver lacks it; depthClipEnable off in a pipeline becomes depthClampEnable, and the extension's structures never reach the driver. - VK_EXT_robustness2 missing entirely (gamescope saw the same on these phones): offered with robustBufferAccess2 (as robustBufferAccess, as before) and nullDescriptor, emulated by small stand-ins (a zeroed buffer, a 1x1 image) for VK_NULL_HANDLE buffers, image views and vertex buffers in plain, template and push descriptor writes and vertex-buffer binds. A null texel-buffer view stays null (its format is not known). The layer logs every feature it emulates per device. * Venus component22694a38(layer: multiDrawIndirect, depthClipEnable, robustness2), pinned by sha * Non-Adreno round 3: bridge images, Venus GL, shared buffers, Steam GPU drawing - vkbridge: the memory model skips lazily allocated types. Mali-G615 lists DEVICE_LOCAL|LAZILY_ALLOCATED first; taken as the device-local type it left images with no memory type (self-test "image clear/draw: setup" FAIL, gamescope "No compatible image memory type"). - Session: a bridge self-test that fails images or draws falls back to the runtime's driver pair for that session (BL_VKBRIDGE_FALLBACK_ICD); Setup and the graphics report say so. - Venus: the Mali compatibility layer runs in every process but gamescope (DROIDDECK_MALI_COMPAT=1), so Zink in Steam and Xwayland gets nullDescriptor; null texel-buffer views get stand-ins too. Without nullDescriptor the session's GL goes to llvmpipe. - gamescope 0129: a refused compute pipeline is named with its SPIR-V capabilities. - Compositor: a buffer on two surfaces at once (gamescope's planes while a notification is up) is released only when the last one lets go. - Open driver pairs: processes.txt timeline for the first three minutes; Setup "Steam interface: GPU drawing" turns off software web compositing. * Pin gamescope p17 (0129) and Venus55b30fbf* Non-Adreno round 4: Mali GPU-drawing block, gamescope YCbCr retry, GL probe, bridge draw sync - Setup's "Steam interface: GPU drawing" is hidden on Mali and a saved "on" is cleared: with PanVK it rebooted an Edge 60 (G615) as steamwebhelper started. Kept for Xclipse. - gamescope 0130: a composite pipeline refused at start-up is retried with a layout without immutable YCbCr samplers (G615 through Venus refused every composite shader; their SPIR-V has no Float16, so fp16 was not the cause). - Venus: droiddeck-glprobe opens GL through GLX the way the Steam client does, with the loader's reasons logged; when it fails the client's GL goes to llvmpipe. - vkbridge self-test: the draw check waits for the render pass's stores before copying out (a tiler read zeros without the dependency). * Pin gamescope p18 (0130) * Non-Adreno round 5: gamescope memory fallback, Venus destroy guard, OpenAL depot - gamescope 0131: DEVICE_LOCAL|HOST_VISIBLE requests fall back to host-visible memory (the bridge's unified-memory model lists none with both), with the request, type bits and memory types logged on failure; 0130's probe pipeline is kept and skipped when forced. - Venus: GAMESCOPE_NO_YCBCR_SAMPLERS=1 from the start; virglrenderer ignores the destroy of a pipeline it never created instead of marking the context fatal (vtest server exit 137 on a Mali-G615). - Steam's OpenAL depot (229020) maps to oalinst_dll, so games that list it (Hotline Miami) get OpenAL in their prefix. * Pin gamescope p19 (0131) and Venus6199a93f* Non-Adreno round 6: PowerVR PRIME on old kernels, thermal, hang-up names, bridge flippable images, Venus Zink variants - drm.c: PR #570's current PRIME ownership check (F_DUPFD_QUERY, then kcmp, then the F_SETOWN_EX owner marker): on a kernel before 6.10 with kcmp blocked, drmPrimeFDToHandle answered EOPNOTSUPP for every PowerVR import (Pixel 10, Android 17: Zink "failed drmPrimeFDToHandle", Xwayland error 7, gamescope X11 I/O error). The Mali stand-in node is kept. - A /sys/class/thermal the kernel will not list gets an empty directory, so mangoapp no longer aborts on it. - gamescope 0132: a hung-up waitable is named before the abort; 0133: the bridge's flippable images use supported-but-unexportable modifiers instead of asserting. - Venus: when Zink does not start, the loader's view is logged and Zink is retried without ZINK_DEBUG=compact, with ZINK_DESCRIPTORS=auto and without kopper before falling back to llvmpipe. * Pin gamescope p20 (0132, 0133) * Non-Adreno round 7: bridge command-buffer guard, Venus Zink trace, PowerVR mangoapp, Xclipse label - vkbridge server: every command buffer a device hands out is tracked; Begin, End (stream replay) and QueueSubmit refuse one it never allocated or has freed (VK_ERROR_DEVICE_LOST, logged) instead of passing it to the driver, where Mali's vkBeginCommandBuffer crashed the app (SIGSEGV 0x10, Steam's Zink on an Edge 60 and a Tab S11). - vkbridge server: a fault inside the driver while serving a request cuts that client off (SIGSEGV/SIGBUS guard per request) and leaves its objects alone; the app and the other clients carry on. Other faults go to the previous handler. - vkbridge server: the pipeline cache directory is copied; the JNI string it pointed at was freed (garbage in the cache path). - Venus: DROIDDECK_MALI_COMPAT_TRACE=1 makes the Mali compatibility layer log what an application queries before vkCreateDevice; a failed glprobe adds a traced run and vulkaninfo --summary under the same environment. - PowerVR: mangoapp draws with llvmpipe (Zink could not make it a swapchain and it crashed at every start). - Setup: an Xclipse GPU reads "Experimental: RADV or the system Xclipse driver", not the PowerVR line. * Pin Venuse40cd361(layer trace) * Non-Adreno round 8: bridge sharing fallback and crash detail, Venus diagnostics and 1.2 gate, compositor disconnect reasons, RADV upstream - Mali bridge: the self-test fails "memory sharing" when the server offers no host-visible memory type (no sharing method passed, RP4 Pro G77); the session then falls back to the PanVK pair like a failed draw, and Setup says the bridge cannot share memory with that driver. Without a pair to fall back on, the log says so. - Mali bridge: a guarded driver crash now logs the sub-command it was in, the fault address and pc (library + offset via dladdr), the command buffer's level, begin flags, pool flags and state, and the last 32 replayed commands. Begin on an executable buffer from a pool without RESET_COMMAND_BUFFER_BIT is logged once (implicit reset). - Venus: vulkan-summary.txt gets the device extension list and key features (full vulkaninfo in vulkan-full.txt); a failed GL probe runs once with VN_DEBUG=init,result, ZINK_DEBUG=mem, MESA_LOG_LEVEL=debug and the layer trace into glprobe-trace.txt. The Mali compatibility layer's trace covers every pre-device query (devices, memory, queue families, formats, image formats, external handles) and names the extensions. - Venus: off when the phone's driver reports Vulkan below 1.2 (gamescope skips such a device); Setup and the graphics report say why and the session uses the PanVK pair. - Compositor: libwayland's own disconnect reasons go to wayland.log, and a client's buffer may grow to 1 MB before a slow reader is dropped. A session that ended without teardown records Android's exit reasons. - Drivers: RADV-Xclipse upstream (radv-xclipse-upstream) is a manual choice for Xclipse; Auto keeps radv-xclipse. * Tests: the terminal-callers harness stubs the Quest layer and Cardboard modules and Android's system properties * Pin gamescope p21 (main's patches + 0120-0133) and Venusa4d47cf3(layer trace) * Display driver Auto: Quest's patched Turnip first; the system driver only for a Mali, other GPUs keep the generic fallback * Open driver pairs: the installed build's version, its upload date, and an Update when the release is rebuilt in place - The release check records each asset's GitHub id and updated_at; a download records them (with the digest) for an open non-Adreno pair. - Components > GPU drivers: an installed open pair shows its manifest version ("android <tag> + linux <commit>"), one not yet installed shows "built YYYY-MM-DD". A different digest, asset id or upload time on the same tag marks the installed pair "Update available" with an Update action: the pair is downloaded again and replaced in place, and stays selected only if it was. Adreno and DD-Turnip pairs are unchanged. - graphics-report.txt: the pair release line gives the installed and the listed upload dates and flags a newer build; an exact bundle id match is preferred (RADV-Xclipse-upstream is not RADV-Xclipse). * Session preload: drop oom_score_adj raises so lmkd does not treat games as cached apps steam-launch-wrapper starts every game with --oom-score-adjust 900; on Android 900 is CACHED_APP_MIN_ADJ, so lmkd kills the running game first when memory runs short (and on Linux 6.1 the raise becomes the process's permanent minimum). A process in the app cannot go below the score it inherits, so the writes that succeed from inside are raises: every write-open of /proc/<pid|self|thread-self>[/task/<tid>]/oom_score_adj (or oom_adj), through open/openat or fopen, goes to /dev/null, logged once. Based on the oom_score_adj redirect in the preload's opens.c by jdmg28 (https://github.com/jdmg28/DroidDeck-Mali/commit/6be00e00) * Display: why presenting failed on the session-ended screen, and the display driver that really loaded - The compositor records why it cannot present (no Vulkan driver loaded, vkCreateInstance/vkCreateDevice failed, no GPU or graphics queue, no swapchain on the screen with the driver's reason, device lost, GPU work unconfirmed). Each is a DD_PRESENT_FAULT line in wayland.log, read back over JNI or from wayland.log; the session-ended screen shows it instead of a black screen, and graphics-report.txt gets "!! DISPLAY FAILED". A first frame or a working swapchain clears it. - After the display device is created, the driver that answered is logged from VkPhysicalDeviceDriverProperties (device, driverName, driverInfo, driver id, Vulkan version) and reported in graphics-report.txt. When a driver pair's display half was requested but a vendor driver answered (adrenotools falls back to the system driver when the requested one does not load), it says so. Based on DD_PRESENT_FAULT in vk_present.c / waylandcomp_jni.c / SessionActivity by jdmg28 (https://github.com/jdmg28/DroidDeck-Mali/blob/arena/cd8ab18a-droiddeck-mali/app/src/main/cpp/waylandcomp/src/vk_present.c) Based on the adrenotools silent-fallback finding by ryanistr (https://github.com/ryanistr/DroidDeck-Mali/blob/main/docs/development/panvk-mali-g77-bringup.md) * tests: steam presentation test sets 0.5.0's steam_client * Non-Adreno: find every driver pair, Venus before the bridge, fix the bridge's begin info From the logs testers sent sincec9ebb247: - The app read the drivers repo's newest 15 releases only; the component releases (gamescope, Venus) pushed every PanVK pair and RADV-Xclipse past them, so Auto found no pair on any Mali and switched the Mali bridge on. The non-Adreno repo is now read in one page of 100. - Auto's stand-in for a missing pair: Mali (Venus) where the apk carries it (Steam runs on it from the G57 to the G1-Ultra), the bridge otherwise, nothing on a driver below Vulkan 1.2. It no longer clears the Linux driver, does nothing when the list could not be read, records that it chose the route, and turns it off again once a pair is installed. A bridge that earlier builds left on under Auto is taken as Auto's. - Mali bridge: vkBeginCommandBuffer sent its begin info without the count the server decodes, so Mali got a zeroed begin info with stale flags and crashed at 0x10 (Pixel 8 Pro G715, Lenovo G615, Xiaomi G925, Tab S11). - Mali-G1 series (MT6993, arch v14) known by its chip; its label says Venus, not the bridge. - A session Android killed for memory is said so on the next start (the S24 FE "crashes" were low-memory kills, not driver faults). - The in-app updater never installs an official (Adreno-only) build over this test build. * Venus: destroy the device's object mutex after the objects that lock it Bionic aborts on locking a destroyed mutex ("pthread_mutex_lock called on a destroyed mutex", Tab S9 FE G68, Pixel 9a), so a client that exited holding objects took the render worker down. From BattleTempest's DroidDeck-Pixel (kevinbryant551-ux/DroidDeck-Pixel, GPL-3.0). * release check: a session helper may be extracted to another runtime path droiddeck-steam-taskset (#570) goes to usr/local/libexec/droiddeck-steam/taskset, where PATH puts it in front of Steam's own taskset for the client only; 0.5.0's check wanted every droiddeck-* helper at its own path. * Venus component93038b7d(destroyed-mutex fix) * Update MaliBridge to v0.5.1 (#1135) * Mali Auto: never leave a session on the runtime's Turnip Logs from a Retroid Pocket 4 Pro (G77), Galaxy S21 Ultra (G78), Tab S11 Ultra (G925) and Xiaomi G610 showed Auto ending on the runtime's Turnip, where gamescope finds no GPU ("failed to find physical device"): after a pair's trial rolled back, when the pair is on the bad list, and when the driver list could not be read. In each case Auto now switches on its stand-in (Venus, or the bridge) when no open driver, Venus or bridge is set. Under Auto the Mali display also leaves any imported driver, not only a pair's PanVK half (a lone PanVK_G720 import gave a black screen). * Mali bridge: MaliBridge 224b6e36 (v0.5.3 source, by ASEbrahim) From c65062b6 (v0.5.1). v0.5.2/v0.5.3: Steam mode on older Mali drivers (G77/G710/G610/G57) gets past "starting display and audio", OpenGL 4.6 on most Malis through dynamic-rendering and vertex-format emulation, Dimensity 9500 texture fixes, async pipeline compile, RE2 flicker on G925, DirectX on the Pixel 8 family. JNI entry and session env names are unchanged. * gamescope 0134: linear when the backend offers no modifier; Venus on Mesa 26.2.5 0134: CVulkanTexture::BInit asserted !modifiers.empty() when the nested Wayland backend offered no modifier for a flippable image's format (NieR Replicant on a Pixel 9a under Venus, session exit 134). It now tries linear and logs it. Venus ICD: mesa-26.2.5 (venus TLS teardown from an unloaded driver, virtio-gpu devices without 3D skipped); virglrenderer stays on 1.3.0. * gamescope p22-nonadreno (0134 + main's 0116 cursor fix; build run 40159674290) * CI: build the non-Adreno additions before the preload check * build.gradle: drop verifyHandModel (main moved the hand models into the tracking pack) * Venus component venus-proto13-e24ed8ab (Mesa 26.2.5; build run 40161447324) * CI: fetch the Mali (Venus) component again (lost when build.yml took main's jobs) Builda7a1ebf1(run 40161734101) had no assets/venus or libvirgl_test_server.so, so VenusComponent.available() was false and Auto's stand-in would have been the bridge. * Auto: the Mali bridge stands in on a Vulkan 1.1 Mali driver Auto refused both Venus and the bridge when the phone's driver reports Vulkan below 1.2, so on the G77, G78 and G610 (r32p1/r38, Vulkan 1.1) a rolled-back or missing pair left the runtime's Turnip: "failed to find physical device" (Retroid Pocket 4 Pro after the JM pair's trial, Xiaomi 13T). Only Venus needs 1.2; the bridge raises the driver for gamescope and runs on these phones. A Venus switch that cannot start on such a driver no longer counts as a route. * Tests: stub main's g_release_unpaced in the DMA-BUF quarantine probe The probe copies release_buffer out of compositor.c; since the merge it reads g_release_unpaced, which the harness did not declare (setUpClass failed to compile). * Update MaliBridge to v0.5.4 (ASEbrahim) 48477fe6 (tag v0.5.4): Dimensity 9500 green squares and red-tinted textures, Balatro and other OpenGL text, fewer crashes when memory runs low, one screen update per game frame, picture kept after a long background pause (SIGHUP no longer stops the server), wrong colours after changing graphics settings on the G720, more in the session report. The app-side changes of his DroidDeck Mali app (Steam menus setting, per-game setup, Send logs, updates) are not part of the MaliBridge repository and are not in this build. * gamescope 0135: linear when the driver rejects every offered modifier An r32p1 Mali-G610 (Vulkan 1.1) behind the Mali bridge answered both of the backend's modifiers for AR24 with VK_ERROR_FORMAT_NOT_SUPPORTED, so the first flippable image failed and gamescope asserted in vulkan_create_flat_texture (Xiaomi 13T). Linear, when offered, is tried anyway; the bridge makes such images without the handle type and exports them through a dma-heap. If the image cannot be made, BInit fails as before. * gamescope: pin the non-Adreno p23 build (0135) * Tests: the terminal-callers harness stubs take_shm's game-frame detection Main's take_shm now reads surface damage, parent/role/mapped and the HUD state to spot game frames; the harness declares them so the copied function compiles (setUpClass failed in Build APK run 40505286127). No damage, so it stays off. * gamescope: number the test branch's patches 0920-0935 Main now has its own 0121-0125 (window override walk, host-event wake, commit fences, done at import, HUD frame times), which sorted in between this branch's 0120-0135. The branch's sixteen patches move to 0920-0935 with the same last two digits, so they apply after main's set and stay clear of its next numbers. Applying all 38 to gamescope 3.16.29 in the old order and the new one gives the same tree (checked with patch -p1, as build-in-arch.sh does). PATCHES.md and the one code comment that named 0130 follow the new numbers. * check_session_assets: helpers count in usr/local/bin or the Steam taskset folder only The merge kept this branch's pattern (any usr/ target), which main's new test rejects: a helper extracted into a subfolder of usr/local/bin must not count. The pattern now takes usr/local/bin under any name, as on main, plus usr/local/libexec/droiddeck-steam for droiddeck-steam-taskset. Every helper in the overlay is still found extracted in SessionFiles.kt. * gamescope: pin 3.16.29 p24 (non-Adreno) Built from this branch @d13b9d88 (run 41119284267): main a5b035b2's patches plus this branch's, now 0920-0935. All 38 applied, gamescope's tests 2/2. sha256 1d1088d4. * Update MaliBridge to v0.5.4.2 (ASEbrahim) 95a1e600 (tag v0.5.4.2), was v0.5.4 (48477fe6). For the bridge: memory sharing without the handle type where that is all the self-test passed (unflagged buffers, client/memory.c, server_memory.c), the older-Mali (G52-G77) game-mode start fixes, the r38p1 beta geometry-shader erratum (gs_hide), present timeouts and an API cap per process. Client, server and the in-app library all build from the submodule with MaliBridge's own scripts, which did not change; the protocol only gained fields an older server sends as 0. * Session end: the compositor fault query no longer fails the hint when the native library is absent presentationFault() (6778a224) called WaylandCompositor.compositorFault() directly. Main's new SessionEndHintTest runs sessionEndHint() in Robolectric, where libdroiddeckwayland cannot load, so all six cases ended in UnsatisfiedLinkError (Build APK run 41125749537). The call is now wrapped like runtimeDamageHint()'s, and without an answer the hint reads wayland.log as before. * test: stub the GPU busy reader in the caller harness * fix: release build is not debuggable, Mali uses the system display driver, staging failure ends its own session * fix: address non-Adreno review findings * fix: preserve current gamescope and GPU warning behavior * fix: retain graphics failure hints and launch diagnostics * fix: identify non-Adreno GPUs in driver failure hints * test: harnesses follow the external client barrier and effects upscaling changes * fix: client sources return to foreign ownership after the overlay draws --------- Co-authored-by: Leask Wong <i@leaskh.com> Co-authored-by: wallentx <william.allentx@gmail.com> Co-authored-by: Stefan Zijlstra <6730062+stefanz92@users.noreply.github.com> Co-authored-by: William Allen <wallentx@users.noreply.github.com> Co-authored-by: The412Banner <the412banner@users.noreply.github.com> Co-authored-by: Dersim Abbas <derabb0620@gmail.com> Co-authored-by: root <root@localhost.localdomain> Co-authored-by: ASEbrahim <ahmadsmain@gmail.com> Co-authored-by: The412Banner <the412banner@gmail.com> Co-authored-by: The412Banner <205237651+The412Banner@users.noreply.github.com>
This commit is contained in:
215 files changed
+19024
-428
No files matched your search
@@ -139,8 +139,15 @@ docker run --rm --platform "${docker_platform}" \
|
||||
aarch64-linux-gnu-gcc -shared -fPIC -O2 -Wall -pthread \
|
||||
-o "$d/libssbs.so" tools/linuxfs/ssbs/ssbs_adapter.c -ldl
|
||||
aarch64-linux-gnu-strip --strip-unneeded "$d/libssbs.so"
|
||||
mkdir -p "$d/usr/local/lib/droiddeck-xclipse"
|
||||
aarch64-linux-gnu-gcc -shared -fPIC -O2 -Wall -Wextra -Wno-unused-parameter -fvisibility=hidden -pthread \
|
||||
-o "$d/usr/local/lib/droiddeck-xclipse/libVkLayer_droiddeck_xclipse.so" tools/linuxfs/xclipse-layer/xclipse_layer.c -ldl
|
||||
aarch64-linux-gnu-strip --strip-unneeded "$d/usr/local/lib/droiddeck-xclipse/libVkLayer_droiddeck_xclipse.so"
|
||||
install -m644 tools/linuxfs/xclipse-layer/VkLayer_droiddeck_xclipse.json "$d/usr/local/lib/droiddeck-xclipse/"
|
||||
mkdir -p "$d/usr/local/bin"
|
||||
external/MaliBridge/scripts/build-client-linux.sh "$d" aarch64-linux-gnu-gcc
|
||||
aarch64-linux-gnu-gcc -O2 -Wall -o "$d/usr/local/bin/droiddeck-glprobe" tools/venus/glprobe.c -ldl
|
||||
aarch64-linux-gnu-strip --strip-unneeded "$d/usr/local/bin/droiddeck-glprobe"
|
||||
aarch64-linux-gnu-gcc -O2 -Wall -Wextra -o "$d/usr/local/bin/droiddeck-clipboard" tools/linuxfs/clipboard/clipboard.c -ldl
|
||||
aarch64-linux-gnu-strip --strip-unneeded "$d/usr/local/bin/droiddeck-clipboard"
|
||||
for script in tools/linuxfs/overlay/usr/local/bin/droiddeck-* tools/linuxfs/overlay/usr/local/bin/steam-compatibility; do
|
||||
@@ -417,6 +424,7 @@ if ! restore_step comet "${comet_key}" "${comet_out}"; then
|
||||
DROIDDECK_BUILD_IMAGE="${image_name}" bash tools/comet/build-local.sh
|
||||
save_step comet "${comet_key}" "${comet_out}"
|
||||
fi
|
||||
python3 tools/powervr/fetch.py
|
||||
bash tools/packs/build.sh app/build/packs
|
||||
python3 tools/release/runtime_inputs.py record
|
||||
./gradlew "${gradle_task}" --console=plain -PndkVersion="${ndk_version}" ${gradle_rust_arg}
|
||||
|
||||
@@ -4,7 +4,7 @@ if [[ -z "${docker_platform}" ]]; then
|
||||
fi
|
||||
case "${docker_platform}" in linux/arm64|linux/arm64/*) docker_platform=linux/arm64 ;; esac
|
||||
if [[ -z "${DROIDDECK_BUILD_IMAGE:-}" ]]; then
|
||||
DROIDDECK_BUILD_IMAGE=droiddeck-local-cross:24.04-v3
|
||||
DROIDDECK_BUILD_IMAGE=droiddeck-local-cross:24.04-v4
|
||||
[[ "${docker_platform}" == linux/arm64 ]] && DROIDDECK_BUILD_IMAGE+=-arm64
|
||||
fi
|
||||
export DROIDDECK_DOCKER_PLATFORM=${docker_platform} DROIDDECK_BUILD_IMAGE
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env bash
|
||||
# CI component build; this does not change the APK or an installed Proton depot.
|
||||
set -euo pipefail
|
||||
root=$(cd "$(dirname "$0")/../.." && pwd)
|
||||
. "$root/tools/dxvk/source.env"
|
||||
mkdir -p "${1:?output directory required}"
|
||||
out=$(cd "$1" && pwd)
|
||||
# Refuse to mix a pinned build with prior DLLs or an incomplete previous build.
|
||||
# Include dotfiles in the check and leave all existing contents untouched.
|
||||
shopt -s nullglob dotglob
|
||||
existing=("$out"/*)
|
||||
if ((${#existing[@]})); then
|
||||
printf '%s\n' 'output directory must be empty; use a fresh build directory' >&2
|
||||
exit 1
|
||||
fi
|
||||
shopt -u nullglob dotglob
|
||||
work=$(mktemp -d)
|
||||
trap 'rm -rf "$work"' EXIT
|
||||
git init -q "$work/source"
|
||||
git -C "$work/source" fetch --depth=1 https://github.com/doitsujin/dxvk.git "$DXVK_REVISION"
|
||||
git -C "$work/source" checkout -q --detach FETCH_HEAD
|
||||
test "$(git -C "$work/source" rev-parse HEAD)" = "$DXVK_REVISION"
|
||||
git -C "$work/source" submodule update --init --recursive --depth=1
|
||||
for patch in "$root"/tools/dxvk/patches/*.patch; do
|
||||
git -C "$work/source" apply --check "$patch"
|
||||
git -C "$work/source" apply "$patch"
|
||||
done
|
||||
python3 "$root/tools/dxvk/check_present_sync.py" "$work/source/src/dxvk/dxvk_presenter.cpp"
|
||||
python3 "$root/tools/dxvk/check_hud_storage_format.py" "$work/source/src/dxvk/hud/shaders/hud_frame_time_eval.comp"
|
||||
python3 "$root/tools/dxvk/check_d3d9_single_sample.py" "$work/source"
|
||||
for arch in 32 64; do
|
||||
meson setup "$work/build$arch" "$work/source" --cross-file "$work/source/build-win$arch.txt" \
|
||||
--buildtype release --prefix "$out" --bindir "x$arch" --libdir "x$arch" -Db_ndebug=if-release --strip
|
||||
meson compile -C "$work/build$arch" -j 4
|
||||
meson install -C "$work/build$arch"
|
||||
done
|
||||
cp "$work/source/LICENSE" "$out/LICENSE"
|
||||
printf '%s\n' "$DXVK_REVISION" > "$out/source-commit"
|
||||
git -C "$work/source" submodule status --recursive > "$out/submodules.txt"
|
||||
git -C "$work/source" diff > "$out/downstream.patch"
|
||||
tar --exclude-vcs --zstd -cf "$out/source.tar.zst" -C "$work/source" .
|
||||
(cd "$out" && find x32 x64 -name '*.dll' -type f -print0 | sort -z | xargs -0 sha256sum > SHA256SUMS)
|
||||
@@ -0,0 +1,112 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compile pinned DXVK's actual descriptor paths against a controlled backend.
|
||||
|
||||
This checks CPU control flow, not GPU rendering. No Wine/game/device is started.
|
||||
"""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
CASES = ('forced_msaa_depth', 'default_msaa_depth', 'forced_nonmaskable',
|
||||
'default_nonmaskable', 'forced_already_single', 'forced_no_depth',
|
||||
'forced_unsupported', 'forced_invalid_type', 'forced_lockable_msaa',
|
||||
'forced_lockable_single', 'forced_allocation_failure',
|
||||
'default_allocation_failure', 'forced_recreate', 'ordinary_surface',
|
||||
'ordinary_invalid_lockable')
|
||||
|
||||
|
||||
def function(text, signature):
|
||||
start = text.index(signature)
|
||||
opening = text.index('{', start)
|
||||
# Ignore braces in comments and strings while preserving source positions.
|
||||
stripped = re.sub(r'//[^\n]*|/\*.*?\*/|"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\'',
|
||||
lambda m: ' ' * len(m.group()), text, flags=re.S)
|
||||
depth = 0
|
||||
for index in range(opening, len(stripped)):
|
||||
depth += (stripped[index] == '{') - (stripped[index] == '}')
|
||||
if depth == 0:
|
||||
return text[start:index + 1]
|
||||
raise ValueError('Unterminated source function: ' + signature)
|
||||
|
||||
|
||||
def production(source):
|
||||
base = source / 'src/d3d9'
|
||||
common = (base / 'd3d9_common_texture.cpp').read_text()
|
||||
header = (base / 'd3d9_common_texture.h').read_text()
|
||||
swap = (base / 'd3d9_swapchain.cpp').read_text()
|
||||
device = (base / 'd3d9_device.cpp').read_text()
|
||||
util = (base / 'd3d9_util.cpp').read_text()
|
||||
pieces = {
|
||||
'decode': function(util, 'HRESULT DecodeMultiSampleType('),
|
||||
'normalize': function(common, 'HRESULT D3D9CommonTexture::NormalizeTextureProperties('),
|
||||
'backbuffers': function(swap, 'HRESULT D3D9SwapChainEx::CreateBackBuffers('),
|
||||
'uses_image': function(header, 'static bool TextureUsesImage('),
|
||||
}
|
||||
reset = function(device, 'HRESULT D3D9DeviceEx::ResetSwapChain(')
|
||||
begin = reset.index('D3D9_COMMON_TEXTURE_DESC desc;', reset.index('if (pPresentationParameters->EnableAutoDepthStencil)'))
|
||||
end = reset.index('m_autoDepthStencil =', begin)
|
||||
pieces['auto_depth'] = reset[begin:end].rstrip()
|
||||
framebuffer = function(device, 'void D3D9DeviceEx::BindFramebuffer(')
|
||||
begin = framebuffer.index('const bool mismatch =')
|
||||
end = framebuffer.index(';', framebuffer.index('const bool bindDS =', begin)) + 1
|
||||
pieces['depth_binding'] = framebuffer[begin:end]
|
||||
return pieces
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('source', type=Path, help='Pinned DXVK tree with downstream patches applied')
|
||||
parser.add_argument('--cxx', default=os.environ.get('CXX', 'c++'))
|
||||
parser.add_argument('--sanitize', action='store_true', help='Enable ASan/UBSan on the CPU harness')
|
||||
args = parser.parse_args()
|
||||
pieces = production(args.source)
|
||||
harness = (Path(__file__).parent / 'tests/d3d9_single_sample.cpp').read_text()
|
||||
harness = harness.replace('/* PRODUCTION_USES_IMAGE */', pieces['uses_image'])
|
||||
with tempfile.TemporaryDirectory(prefix='dxvk-d3d9-') as directory:
|
||||
out = Path(directory)
|
||||
(out / 'harness.cpp').write_text(harness)
|
||||
include = '\n\n'.join(pieces[key] for key in ('decode', 'normalize', 'backbuffers'))
|
||||
include += '\nHRESULT auto_depth(D3D9DeviceEx* device, D3DPRESENT_PARAMETERS* pPresentationParameters, D3D9_COMMON_TEXTURE_DESC* output) {\n'
|
||||
include += 'auto* self = device;\n' + pieces['auto_depth'].replace('(this,', '(self,')
|
||||
include += '\n*output = desc; return D3D_OK;\n}\n'
|
||||
include += '\nbool depth_binds(const ImageInfo& color, const ImageInfo& dsInfo) {\n'
|
||||
include += 'auto sampleCount = color.sampleCount; auto renderArea = color.extent;\n'
|
||||
include += 'const bool noRT0Bound = false, ignoreRT0 = false;\n'
|
||||
include += pieces['depth_binding'] + '\nreturn bindDS;\n}\n'
|
||||
(out / 'd3d9_production.inc').write_text(include)
|
||||
command = [args.cxx, '-std=c++17', '-Wall', '-Wextra', '-Werror',
|
||||
'-Wno-unused-parameter', str(out / 'harness.cpp'), '-o', str(out / 'check')]
|
||||
# The original CreateBackBuffers does not use Flags; that known baseline
|
||||
# warning must not turn a negative control into a compiler-fixture error.
|
||||
if args.sanitize:
|
||||
command[1:1] = ['-fsanitize=address,undefined', '-fno-omit-frame-pointer']
|
||||
compilation = subprocess.run(command, capture_output=True, text=True)
|
||||
if compilation.returncode:
|
||||
raise SystemExit(compilation.stderr)
|
||||
results = []
|
||||
for case in CASES:
|
||||
process = subprocess.run([str(out / 'check'), case], capture_output=True,
|
||||
text=True, timeout=10, cwd=out,
|
||||
env={'ASAN_OPTIONS': 'detect_leaks=' +
|
||||
('0' if sys.platform == 'darwin' else '1')})
|
||||
results.append({'case': case, 'passed': process.returncode == 0,
|
||||
'exit': process.returncode, 'detail': process.stderr.strip()[-800:]})
|
||||
result = {'cases': results, 'passed': sum(row['passed'] for row in results),
|
||||
'failed': sum(not row['passed'] for row in results),
|
||||
'production_sha256': {key: hashlib.sha256(value.encode()).hexdigest()
|
||||
for key, value in pieces.items()},
|
||||
'backend_and_adapter_mocked': True, 'GPU_test': False,
|
||||
'sanitizers': args.sanitize,
|
||||
'leak_detection': args.sanitize and sys.platform != 'darwin'}
|
||||
print(json.dumps(result, indent=2))
|
||||
return bool(result['failed'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compile the actual HUD shader and verify its binding-3 R8_UINT contract.
|
||||
|
||||
The frame-time HUD binds an R8_UINT texel-buffer view. An Unknown SPIR-V image
|
||||
format requires STORAGE_WRITE_WITHOUT_FORMAT, which PowerVR does not report
|
||||
for that buffer format. Static spirv-val alone accepts both declarations;
|
||||
this check validates the shader against the known host-side binding contract.
|
||||
"""
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import struct
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
|
||||
def check(shader):
|
||||
compiler = shutil.which('glslangValidator')
|
||||
validator = shutil.which('spirv-val')
|
||||
if not compiler or not validator:
|
||||
raise RuntimeError('glslangValidator and spirv-val required')
|
||||
with tempfile.TemporaryDirectory(prefix='dxvk-hud-contract-') as directory:
|
||||
output = Path(directory) / 'hud.spv'
|
||||
for command in ([compiler, '-V', '--target-env', 'vulkan1.3', str(shader), '-o', str(output)],
|
||||
[validator, '--target-env', 'vulkan1.3', str(output)]):
|
||||
process = subprocess.run(command, capture_output=True, text=True, timeout=30)
|
||||
if process.returncode:
|
||||
raise RuntimeError('HUD shader compilation/SPIR-V validation failed')
|
||||
raw = output.read_bytes()
|
||||
if len(raw) < 20 or len(raw) % 4:
|
||||
raise RuntimeError('Malformed SPIR-V')
|
||||
words = struct.unpack('<' + str(len(raw) // 4) + 'I', raw)
|
||||
if words[0] != 0x07230203:
|
||||
raise RuntimeError('Unexpected SPIR-V magic')
|
||||
bindings, sets, variables, pointers, images = {}, {}, {}, {}, {}
|
||||
offset = 5
|
||||
while offset < len(words):
|
||||
size, opcode = words[offset] >> 16, words[offset] & 0xffff
|
||||
if not size or size > len(words) - offset:
|
||||
raise RuntimeError('Malformed SPIR-V instruction')
|
||||
instruction = words[offset:offset + size]
|
||||
if opcode == 71 and size == 4: # OpDecorate
|
||||
if instruction[2] == 33:
|
||||
bindings[instruction[1]] = instruction[3]
|
||||
elif instruction[2] == 34:
|
||||
sets[instruction[1]] = instruction[3]
|
||||
elif opcode == 59 and size >= 4: # OpVariable
|
||||
variables[instruction[2]] = instruction[1]
|
||||
elif opcode == 32 and size == 4: # OpTypePointer
|
||||
pointers[instruction[1]] = instruction[3]
|
||||
elif opcode == 25 and size >= 9: # OpTypeImage
|
||||
images[instruction[1]] = (instruction[3], instruction[7], instruction[8])
|
||||
offset += size
|
||||
targets = [images.get(pointers.get(variables.get(identifier)))
|
||||
for identifier, binding in bindings.items()
|
||||
if binding == 3 and sets.get(identifier) == 0]
|
||||
if targets != [(5, 2, 39)]: # DimBuffer, storage image, ImageFormatR8ui
|
||||
raise RuntimeError('HUD binding 3 must compile to a storage texel buffer with ImageFormatR8ui')
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('shader', type=Path)
|
||||
args = parser.parse_args()
|
||||
try:
|
||||
check(args.shader)
|
||||
except RuntimeError as error:
|
||||
parser.exit(1, str(error) + '\n')
|
||||
print('HUD binding 3: SPIR-V valid, explicit R8ui storage texel-buffer format')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,116 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Replay asynchronous WSI ownership using the pinned presenter's actual selections.
|
||||
|
||||
This checks semaphore selection, not the full Vulkan presenter. Real Vulkan
|
||||
validation and device testing remain separate gates. Requires a native C++ compiler.
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
|
||||
def selection_code(source):
|
||||
match = re.search(
|
||||
r"// Return relevant Vulkan objects for the acquired image\s*"
|
||||
r"(?P<acquire>.*?)\s*m_presentPending = true;", source, re.S)
|
||||
wait = re.search(r"info\.pWaitSemaphores\s*=.*?;", source, re.S)
|
||||
if not match or not wait:
|
||||
raise ValueError("unsupported pinned presenter layout")
|
||||
return match["acquire"], wait[0]
|
||||
|
||||
|
||||
HARNESS = r'''
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
using VkSemaphore = uint64_t;
|
||||
struct Sync { VkSemaphore acquire, present; };
|
||||
struct Info { const VkSemaphore* pWaitSemaphores; };
|
||||
|
||||
struct Presenter {
|
||||
std::vector<Sync> m_semaphores;
|
||||
std::vector<unsigned> m_images = {0, 1, 2, 3};
|
||||
unsigned m_frameIndex = 0, m_imageIndex = 0;
|
||||
bool m_hasSwapchainMaintenance1;
|
||||
explicit Presenter(bool maintenance): m_hasSwapchainMaintenance1(maintenance) {
|
||||
for (unsigned i = 0; i < (maintenance ? 4u : 8u); ++i)
|
||||
m_semaphores.push_back({100 + i, 1 + i});
|
||||
}
|
||||
Sync acquire() {
|
||||
Sync sync{}; unsigned image;
|
||||
ACQUIRE_SELECTION
|
||||
(void)image;
|
||||
return sync;
|
||||
}
|
||||
VkSemaphore present() {
|
||||
auto& currSync = m_semaphores.at(m_frameIndex);
|
||||
Info info{};
|
||||
PRESENT_SELECTION
|
||||
return *info.pWaitSemaphores;
|
||||
}
|
||||
};
|
||||
|
||||
int replay(bool maintenance) {
|
||||
Presenter p(maintenance);
|
||||
std::array<VkSemaphore, 4> outstandingByImage{};
|
||||
std::array<VkSemaphore, 4> outstandingByFence{};
|
||||
// Deliberately delay reacquisition of image 2 beyond a full frame-ring cycle.
|
||||
const std::array<unsigned, 21> imageOrder = {
|
||||
2,0,3,0,1,3,0,1,1,2,3,1,0,3,2,2,0,1,3,0,2
|
||||
};
|
||||
for (unsigned iteration = 0; iteration < 200; ++iteration) {
|
||||
p.m_imageIndex = imageOrder[iteration % imageOrder.size()];
|
||||
if (maintenance) {
|
||||
// The existing fence path waits this frame's previous present fence.
|
||||
const auto completed = outstandingByFence.at(p.m_frameIndex);
|
||||
for (auto& pending : outstandingByImage)
|
||||
if (pending == completed) pending = 0;
|
||||
}
|
||||
// Acquisition and its GPU wait complete the last present of THIS image.
|
||||
outstandingByImage.at(p.m_imageIndex) = 0;
|
||||
const auto signal = p.acquire().present;
|
||||
const auto wait = p.present();
|
||||
if (signal != wait) {
|
||||
std::fprintf(stderr, "FAIL: render signal differs from present wait\n");
|
||||
return 2;
|
||||
}
|
||||
for (auto pending : outstandingByImage) {
|
||||
if (pending == signal) {
|
||||
std::fprintf(stderr, "FAIL: semaphore reused before presentation completion at frame %u\n", iteration);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
outstandingByImage.at(p.m_imageIndex) = signal;
|
||||
if (maintenance) outstandingByFence.at(p.m_frameIndex) = signal;
|
||||
p.m_frameIndex = (p.m_frameIndex + 1) % p.m_semaphores.size();
|
||||
}
|
||||
std::printf("PASS: %s, 200 out-of-order acquisitions\n", maintenance ? "present-fence path" : "no-present-fence path");
|
||||
return 0;
|
||||
}
|
||||
int main() {
|
||||
if (int status = replay(false)) return status;
|
||||
return replay(true);
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("source", type=Path, help="pinned dxvk_presenter.cpp, after patching")
|
||||
args = parser.parse_args()
|
||||
acquire, present = selection_code(args.source.read_text())
|
||||
code = HARNESS.replace("ACQUIRE_SELECTION", acquire).replace("PRESENT_SELECTION", present)
|
||||
with tempfile.TemporaryDirectory(prefix="dxvk-present-sync-") as directory:
|
||||
cpp = Path(directory) / "replay.cpp"
|
||||
exe = Path(directory) / "replay"
|
||||
cpp.write_text(code)
|
||||
subprocess.run([os.environ.get("HOST_CXX", "c++"), "-std=c++17", "-Wall", "-Wextra", str(cpp), "-o", str(exe)], check=True)
|
||||
return subprocess.run([str(exe)]).returncode
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,53 @@
|
||||
diff --git a/src/dxvk/dxvk_device_info.cpp b/src/dxvk/dxvk_device_info.cpp
|
||||
index db09fba..8e9a76e 100644
|
||||
--- a/src/dxvk/dxvk_device_info.cpp
|
||||
+++ b/src/dxvk/dxvk_device_info.cpp
|
||||
@@ -118,6 +118,17 @@ namespace dxvk {
|
||||
initQueueProperties(instance, adapter, deviceInfo);
|
||||
initMemoryProperties(instance, adapter);
|
||||
|
||||
+ m_hasBcFormats = true;
|
||||
+ for (uint32_t value = VK_FORMAT_BC1_RGBA_UNORM_BLOCK; value <= VK_FORMAT_BC7_SRGB_BLOCK; value++) {
|
||||
+ VkFormatProperties properties = { };
|
||||
+ vk->vkGetPhysicalDeviceFormatProperties(adapter, VkFormat(value), &properties);
|
||||
+ constexpr VkFormatFeatureFlags required = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
|
||||
+ | VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT
|
||||
+ | VK_FORMAT_FEATURE_TRANSFER_SRC_BIT | VK_FORMAT_FEATURE_TRANSFER_DST_BIT;
|
||||
+ if ((properties.optimalTilingFeatures & required) != required)
|
||||
+ m_hasBcFormats = false;
|
||||
+ }
|
||||
+
|
||||
disableUnusedFeatures(instance, safeMode);
|
||||
|
||||
enableFeaturesAndExtensions();
|
||||
@@ -785,6 +796,9 @@ namespace dxvk {
|
||||
}
|
||||
}
|
||||
|
||||
+ if (!m_hasBcFormats)
|
||||
+ return std::string("Device does not support the BC formats required by Direct3D");
|
||||
+
|
||||
if (!m_featuresEnabled.extDescriptorHeap.descriptorHeap && m_properties.core.properties.limits.maxPushConstantsSize < MaxTotalPushDataSize)
|
||||
return str::format("Device does not support ", MaxTotalPushDataSize, " of push data");
|
||||
|
||||
@@ -886,7 +900,7 @@ namespace dxvk {
|
||||
ENABLE_FEATURE(core.features, shaderResourceResidency, false),
|
||||
ENABLE_FEATURE(core.features, shaderResourceMinLod, false),
|
||||
ENABLE_FEATURE(core.features, tessellationShader, false),
|
||||
- ENABLE_FEATURE(core.features, textureCompressionBC, true),
|
||||
+ ENABLE_FEATURE(core.features, textureCompressionBC, false),
|
||||
ENABLE_FEATURE(core.features, variableMultisampleRate, false),
|
||||
ENABLE_FEATURE(core.features, vertexPipelineStoresAndAtomics, false),
|
||||
ENABLE_FEATURE(core.features, wideLines, false),
|
||||
diff --git a/src/dxvk/dxvk_device_info.h b/src/dxvk/dxvk_device_info.h
|
||||
index 0a55f90..8bbc770 100644
|
||||
--- a/src/dxvk/dxvk_device_info.h
|
||||
+++ b/src/dxvk/dxvk_device_info.h
|
||||
@@ -394,6 +394,7 @@ namespace dxvk {
|
||||
|
||||
DxvkDeviceQueueMapping m_queueMapping = { };
|
||||
|
||||
+ bool m_hasBcFormats = false;
|
||||
bool m_hasMeshShader = false;
|
||||
bool m_hasFmask = false;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
diff --git a/src/dxvk/dxvk_presenter.cpp b/src/dxvk/dxvk_presenter.cpp
|
||||
index 643f7c5..4dc8c4d 100644
|
||||
--- a/src/dxvk/dxvk_presenter.cpp
|
||||
+++ b/src/dxvk/dxvk_presenter.cpp
|
||||
@@ -161,6 +161,10 @@ namespace dxvk {
|
||||
|
||||
// Return relevant Vulkan objects for the acquired image
|
||||
sync = m_semaphores.at(m_frameIndex);
|
||||
+ // Without a present fence, reacquiring this image is the only guarantee
|
||||
+ // that its previous presentation has consumed the wait semaphore.
|
||||
+ if (!m_hasSwapchainMaintenance1)
|
||||
+ sync.present = m_semaphores.at(m_imageIndex).present;
|
||||
image = m_images.at(m_imageIndex);
|
||||
|
||||
m_presentPending = true;
|
||||
@@ -239,7 +243,9 @@ namespace dxvk {
|
||||
|
||||
VkPresentInfoKHR info = { VK_STRUCTURE_TYPE_PRESENT_INFO_KHR };
|
||||
info.waitSemaphoreCount = 1;
|
||||
- info.pWaitSemaphores = &currSync.present;
|
||||
+ info.pWaitSemaphores = m_hasSwapchainMaintenance1
|
||||
+ ? &currSync.present
|
||||
+ : &m_semaphores.at(m_imageIndex).present;
|
||||
info.swapchainCount = 1;
|
||||
info.pSwapchains = &m_swapchain;
|
||||
info.pImageIndices = &m_imageIndex;
|
||||
@@ -0,0 +1,12 @@
|
||||
--- a/src/dxvk/hud/shaders/hud_frame_time_eval.comp
|
||||
+++ b/src/dxvk/hud/shaders/hud_frame_time_eval.comp
|
||||
@@ -41,7 +41,8 @@
|
||||
draw_info_t draw_infos[];
|
||||
};
|
||||
|
||||
-layout(binding = 3)
|
||||
+// The bound text view is VK_FORMAT_R8_UINT; do not require formatless writes.
|
||||
+layout(binding = 3, r8ui)
|
||||
uniform writeonly uimageBuffer text_buffer;
|
||||
|
||||
layout(push_constant)
|
||||
@@ -0,0 +1,86 @@
|
||||
diff --git a/dxvk.conf b/dxvk.conf
|
||||
index ba4bc20..26d3127 100644
|
||||
--- a/dxvk.conf
|
||||
+++ b/dxvk.conf
|
||||
@@ -336,6 +336,15 @@
|
||||
|
||||
# d3d11.disableMsaa = False
|
||||
|
||||
+# Forces D3D9 surfaces to single-sample after validating the original request.
|
||||
+# The effective surface description reports D3DMULTISAMPLE_NONE; MSAA quality,
|
||||
+# alpha-to-coverage and per-sample masks are consequently disabled. This is an
|
||||
+# opt-in compatibility override for games with broken MSAA rendering.
|
||||
+#
|
||||
+# Supported values: True, False
|
||||
+
|
||||
+# d3d9.forceSingleSample = False
|
||||
+
|
||||
|
||||
# Forces insertion of memory and control barriers after writes to group-shared
|
||||
# memory in compute shaders. This is only intended to be used as a workaround
|
||||
diff --git a/src/d3d9/d3d9_common_texture.cpp b/src/d3d9/d3d9_common_texture.cpp
|
||||
index 9d5fe38..629fea3 100644
|
||||
--- a/src/d3d9/d3d9_common_texture.cpp
|
||||
+++ b/src/d3d9/d3d9_common_texture.cpp
|
||||
@@ -212,6 +212,15 @@ namespace dxvk {
|
||||
return D3DERR_INVALIDCALL;
|
||||
}
|
||||
|
||||
+ // Keep original request validation above. This opt-in override changes
|
||||
+ // the effective surface description as well as the backing image.
|
||||
+ // All surface descriptors and resolves then see the actual sample count.
|
||||
+ if (ResourceType == D3DRTYPE_SURFACE && options->forceSingleSample
|
||||
+ && sampleCount != VK_SAMPLE_COUNT_1_BIT) {
|
||||
+ pDesc->MultiSample = D3DMULTISAMPLE_NONE;
|
||||
+ pDesc->MultisampleQuality = 0;
|
||||
+ }
|
||||
+
|
||||
// Using MANAGED pool with DYNAMIC usage is illegal
|
||||
if (IsPoolManaged(pDesc->Pool) && (pDesc->Usage & D3DUSAGE_DYNAMIC))
|
||||
return D3DERR_INVALIDCALL;
|
||||
diff --git a/src/d3d9/d3d9_options.cpp b/src/d3d9/d3d9_options.cpp
|
||||
index e46864e..0cab7dc 100644
|
||||
--- a/src/d3d9/d3d9_options.cpp
|
||||
+++ b/src/d3d9/d3d9_options.cpp
|
||||
@@ -59,6 +59,7 @@ namespace dxvk {
|
||||
this->memoryTrackTest = config.getOption<bool> ("d3d9.memoryTrackTest", false);
|
||||
this->forceSamplerTypeSpecConstants = config.getOption<bool> ("d3d9.forceSamplerTypeSpecConstants", false);
|
||||
this->forceSampleRateShading = config.getOption<bool> ("d3d9.forceSampleRateShading", false);
|
||||
+ this->forceSingleSample = config.getOption<bool> ("d3d9.forceSingleSample", false);
|
||||
this->forceAspectRatio = config.getOption<std::string> ("d3d9.forceAspectRatio", "");
|
||||
this->forceRefreshRate = config.getOption<int32_t> ("d3d9.forceRefreshRate", 0u);
|
||||
this->modeCountCompatibility = config.getOption<bool> ("d3d9.modeCountCompatibility", false);
|
||||
diff --git a/src/d3d9/d3d9_options.h b/src/d3d9/d3d9_options.h
|
||||
index e69a39a..4478420 100644
|
||||
--- a/src/d3d9/d3d9_options.h
|
||||
+++ b/src/d3d9/d3d9_options.h
|
||||
@@ -113,6 +113,9 @@ namespace dxvk {
|
||||
/// Forces sample rate shading
|
||||
bool forceSampleRateShading;
|
||||
|
||||
+ /// Optional compatibility override: report and render surfaces as single-sample.
|
||||
+ bool forceSingleSample;
|
||||
+
|
||||
/// Allow D3DLOCK_DISCARD
|
||||
bool allowDiscard;
|
||||
|
||||
diff --git a/src/d3d9/d3d9_swapchain.cpp b/src/d3d9/d3d9_swapchain.cpp
|
||||
--- a/src/d3d9/d3d9_swapchain.cpp
|
||||
+++ b/src/d3d9/d3d9_swapchain.cpp
|
||||
@@ -1055,1 +1055,16 @@ namespace dxvk {
|
||||
+ if (m_parent->GetOptions()->forceSingleSample) {
|
||||
+ // Backbuffers bypass the normal surface-creation entry points. Validate
|
||||
+ // the application's request, then apply the same effective sample count.
|
||||
+ // IsLockable above is an internal GDI fallback requirement, not the
|
||||
+ // application's lockability request used by MSAA validation.
|
||||
+ auto requestedDesc = desc;
|
||||
+ requestedDesc.IsLockable = (Flags & D3DPRESENTFLAG_LOCKABLE_BACKBUFFER) != 0;
|
||||
+ HRESULT hr = D3D9CommonTexture::NormalizeTextureProperties(
|
||||
+ m_parent, D3DRTYPE_SURFACE, &requestedDesc);
|
||||
+ if (FAILED(hr))
|
||||
+ return hr;
|
||||
+ desc.MultiSample = requestedDesc.MultiSample;
|
||||
+ desc.MultisampleQuality = requestedDesc.MultisampleQuality;
|
||||
+ }
|
||||
+
|
||||
const bool isExtended = m_parent->IsD3DCompatibile(D3DCompatibility::D3D9Ex);
|
||||
@@ -0,0 +1 @@
|
||||
DXVK_REVISION=25ca63f17f34bdc05a39873ee63907d3cbbfa030
|
||||
@@ -0,0 +1,214 @@
|
||||
// Backend/adapter fixture for the verbatim DXVK functions in d3d9_production.inc.
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using HRESULT = int32_t;
|
||||
using DWORD = uint32_t;
|
||||
using UINT = uint32_t;
|
||||
using VkSampleCountFlagBits = uint32_t;
|
||||
constexpr HRESULT D3D_OK = 0, D3DERR_INVALIDCALL = -1,
|
||||
D3DERR_NOTAVAILABLE = -2, D3DERR_OUTOFVIDEOMEMORY = -3;
|
||||
constexpr uint32_t VK_SAMPLE_COUNT_1_BIT = 1, VK_IMAGE_ASPECT_COLOR_BIT = 1;
|
||||
constexpr bool FALSE = false, TRUE = true;
|
||||
#define FAILED(x) ((x) < 0)
|
||||
#define unlikely(x) (x)
|
||||
enum D3DMULTISAMPLE_TYPE { D3DMULTISAMPLE_NONE, D3DMULTISAMPLE_NONMASKABLE,
|
||||
D3DMULTISAMPLE_16_SAMPLES = 16 };
|
||||
enum D3DRESOURCETYPE { D3DRTYPE_SURFACE, D3DRTYPE_CUBETEXTURE, D3DRTYPE_VOLUMETEXTURE };
|
||||
enum D3DPOOL { D3DPOOL_DEFAULT, D3DPOOL_MANAGED, D3DPOOL_SYSTEMMEM, D3DPOOL_SCRATCH };
|
||||
enum class D3DCompatibility { D3D9Ex };
|
||||
enum class D3D9Format { X8R8G8B8, D24S8, A8, NULL_FORMAT, ATI2,
|
||||
D32_LOCKABLE, D32F_LOCKABLE, D16_LOCKABLE, S8_LOCKABLE };
|
||||
constexpr DWORD D3DUSAGE_RENDERTARGET = 1, D3DUSAGE_DEPTHSTENCIL = 2,
|
||||
D3DUSAGE_DYNAMIC = 4, D3DUSAGE_WRITEONLY = 8, D3DUSAGE_AUTOGENMIPMAP = 16;
|
||||
constexpr DWORD D3DPRESENTFLAG_LOCKABLE_BACKBUFFER = 1, D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL = 2;
|
||||
constexpr int D3DDEVTYPE_HAL = 1, VK_IMAGE_LAYOUT_UNDEFINED = 0;
|
||||
struct Extent { uint32_t width, height, depth = 1; };
|
||||
namespace util {
|
||||
uint32_t computeMipLevelCount(Extent e) {
|
||||
uint32_t n = std::max({e.width, e.height, e.depth}), levels = 0;
|
||||
do { ++levels; n >>= 1; } while (n);
|
||||
return levels;
|
||||
}
|
||||
}
|
||||
bool IsPoolManaged(D3DPOOL pool) { return pool == D3DPOOL_MANAGED; }
|
||||
bool IsDXTFormat(D3D9Format) { return false; }
|
||||
bool IsDepthStencilFormat(D3D9Format format) { return format == D3D9Format::D24S8; }
|
||||
bool IsLockableDepthStencilFormat(D3D9Format) { return false; }
|
||||
struct D3D9_FORMAT_BLOCK_SIZE { uint32_t Width, Height; };
|
||||
D3D9_FORMAT_BLOCK_SIZE GetFormatAlignedBlockSize(D3D9Format) { return {1, 1}; }
|
||||
D3D9Format EnumerateFormat(D3D9Format format) { return format; }
|
||||
struct D3D9_COMMON_TEXTURE_DESC {
|
||||
uint32_t Width = 1280, Height = 720, Depth = 1, MipLevels = 1, ArraySize = 1;
|
||||
D3D9Format Format = D3D9Format::X8R8G8B8;
|
||||
D3DMULTISAMPLE_TYPE MultiSample = D3DMULTISAMPLE_NONE;
|
||||
DWORD MultisampleQuality = 0;
|
||||
D3DPOOL Pool = D3DPOOL_DEFAULT;
|
||||
DWORD Usage = D3DUSAGE_RENDERTARGET;
|
||||
bool Discard = false, IsBackBuffer = false, IsAttachmentOnly = false, IsLockable = false;
|
||||
};
|
||||
struct D3DPRESENT_PARAMETERS {
|
||||
uint32_t BackBufferWidth = 1280, BackBufferHeight = 720;
|
||||
D3D9Format BackBufferFormat = D3D9Format::X8R8G8B8;
|
||||
D3DMULTISAMPLE_TYPE MultiSampleType = D3DMULTISAMPLE_TYPE(4);
|
||||
DWORD MultiSampleQuality = 0, Flags = 0;
|
||||
D3D9Format AutoDepthStencilFormat = D3D9Format::D24S8;
|
||||
};
|
||||
struct Options {
|
||||
bool forceSingleSample = false, extraFrontbuffer = false,
|
||||
disableA8RT = false, supportCubeDepthFormats = false;
|
||||
};
|
||||
struct FormatMapping {
|
||||
uint32_t Aspect;
|
||||
bool IsValid() const { return true; }
|
||||
};
|
||||
struct Adapter {
|
||||
bool supported = true;
|
||||
std::vector<D3DMULTISAMPLE_TYPE> checked;
|
||||
HRESULT CheckDeviceMultiSampleType(int, D3D9Format, bool, D3DMULTISAMPLE_TYPE samples, void*) {
|
||||
checked.push_back(samples);
|
||||
return supported ? D3D_OK : D3DERR_NOTAVAILABLE;
|
||||
}
|
||||
};
|
||||
struct ImageInfo { Extent extent; VkSampleCountFlagBits sampleCount; };
|
||||
struct DxvkImage { ImageInfo info; };
|
||||
template<typename T> using Rc = std::shared_ptr<T>;
|
||||
template<typename T, unsigned N> using small_vector = std::vector<T>;
|
||||
struct DxvkContext {
|
||||
unsigned initialized = 0;
|
||||
void initImage(const Rc<DxvkImage>&, int) { ++initialized; }
|
||||
};
|
||||
struct D3D9DeviceEx {
|
||||
Options options;
|
||||
Adapter adapter;
|
||||
DxvkContext context;
|
||||
unsigned attempts = 0, failAt = 0, losable = 0, live = 0, injected = 0;
|
||||
std::vector<D3D9_COMMON_TEXTURE_DESC> created;
|
||||
Options* GetOptions() { return &options; }
|
||||
Adapter* GetAdapter() { return &adapter; }
|
||||
FormatMapping LookupFormat(D3D9Format format) { return {IsDepthStencilFormat(format) ? 2u : 1u}; }
|
||||
struct Unsupported { unsigned elementSize = 0; };
|
||||
Unsupported unsupported;
|
||||
const Unsupported* UnsupportedFormatInfo(D3D9Format) { return &unsupported; }
|
||||
bool IsD3DCompatibile(D3DCompatibility) { return false; }
|
||||
void IncrementLosableCounter() { ++losable; }
|
||||
template<typename F> void InjectCs(F function) { ++injected; function(&context); }
|
||||
};
|
||||
HRESULT DecodeMultiSampleType(D3DMULTISAMPLE_TYPE, DWORD, VkSampleCountFlagBits*);
|
||||
struct D3D9CommonTexture {
|
||||
Rc<DxvkImage> image;
|
||||
const Rc<DxvkImage>& GetImage() const { return image; }
|
||||
static HRESULT NormalizeTextureProperties(D3D9DeviceEx*, D3DRESOURCETYPE, D3D9_COMMON_TEXTURE_DESC*);
|
||||
/* PRODUCTION_USES_IMAGE */
|
||||
};
|
||||
class DxvkError : public std::runtime_error {
|
||||
public:
|
||||
using std::runtime_error::runtime_error;
|
||||
std::string message() const { return what(); }
|
||||
};
|
||||
struct Logger { static void err(const std::string&) {} };
|
||||
struct D3D9SwapChainEx;
|
||||
struct D3D9Surface {
|
||||
D3D9CommonTexture texture;
|
||||
D3D9DeviceEx* device;
|
||||
D3D9Surface(D3D9DeviceEx* d, D3D9_COMMON_TEXTURE_DESC* desc, bool, D3D9SwapChainEx*, void*) : device(d) {
|
||||
if (++d->attempts == d->failAt) throw DxvkError("controlled allocation failure");
|
||||
VkSampleCountFlagBits samples;
|
||||
if (FAILED(DecodeMultiSampleType(desc->MultiSample, desc->MultisampleQuality, &samples)))
|
||||
throw DxvkError("invalid backend sample count");
|
||||
texture.image = std::make_shared<DxvkImage>(DxvkImage{{{desc->Width, desc->Height}, samples}});
|
||||
d->created.push_back(*desc); ++d->live;
|
||||
}
|
||||
~D3D9Surface() { --device->live; }
|
||||
D3D9CommonTexture* GetCommonTexture() { return &texture; }
|
||||
};
|
||||
struct D3D9SwapChainEx {
|
||||
D3D9DeviceEx* m_parent;
|
||||
D3DPRESENT_PARAMETERS m_presentParams;
|
||||
std::vector<std::unique_ptr<D3D9Surface>> m_backBuffers;
|
||||
bool flip = false;
|
||||
unsigned destroys = 0;
|
||||
bool SwapWithFrontBuffer() { return flip; }
|
||||
void DestroyBackBuffers() { ++destroys; m_backBuffers.clear(); }
|
||||
HRESULT CreateBackBuffers(uint32_t, DWORD);
|
||||
};
|
||||
#include "d3d9_production.inc"
|
||||
|
||||
void paired(bool enabled, D3DMULTISAMPLE_TYPE type, DWORD quality) {
|
||||
D3D9DeviceEx device; device.options.forceSingleSample = enabled;
|
||||
device.options.extraFrontbuffer = true;
|
||||
D3D9SwapChainEx chain{&device, {}, {}};
|
||||
chain.m_presentParams.MultiSampleType = type; chain.m_presentParams.MultiSampleQuality = quality;
|
||||
assert(chain.CreateBackBuffers(2, 0) == D3D_OK);
|
||||
D3D9_COMMON_TEXTURE_DESC depth;
|
||||
assert(auto_depth(&device, &chain.m_presentParams, &depth) == D3D_OK);
|
||||
VkSampleCountFlagBits requested, dsSamples;
|
||||
assert(DecodeMultiSampleType(type, quality, &requested) == D3D_OK);
|
||||
assert(DecodeMultiSampleType(depth.MultiSample, depth.MultisampleQuality, &dsSamples) == D3D_OK);
|
||||
assert(chain.m_backBuffers.size() == 3 && device.context.initialized == 3);
|
||||
for (const auto& surface : chain.m_backBuffers) {
|
||||
const auto& image = surface->GetCommonTexture()->GetImage()->info;
|
||||
assert(image.sampleCount == (enabled ? 1u : requested));
|
||||
assert(depth_binds(image, {{depth.Width, depth.Height}, dsSamples}));
|
||||
}
|
||||
for (const auto& desc : device.created) {
|
||||
assert(desc.IsLockable && desc.IsBackBuffer && !desc.IsAttachmentOnly);
|
||||
assert(desc.MultiSample == (enabled ? D3DMULTISAMPLE_NONE : type));
|
||||
assert(desc.MultisampleQuality == (enabled ? 0u : quality));
|
||||
}
|
||||
// Original presentation parameters remain available for reset/auto-depth validation.
|
||||
assert(chain.m_presentParams.MultiSampleType == type && chain.m_presentParams.MultiSampleQuality == quality);
|
||||
if (enabled && requested > 1) assert(device.adapter.checked.front() == D3DMULTISAMPLE_TYPE(requested));
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
assert(argc == 2); std::string name = argv[1];
|
||||
if (name == "forced_msaa_depth") paired(true, D3DMULTISAMPLE_TYPE(4), 0);
|
||||
else if (name == "default_msaa_depth") paired(false, D3DMULTISAMPLE_TYPE(4), 0);
|
||||
else if (name == "forced_nonmaskable") paired(true, D3DMULTISAMPLE_NONMASKABLE, 2);
|
||||
else if (name == "default_nonmaskable") paired(false, D3DMULTISAMPLE_NONMASKABLE, 2);
|
||||
else if (name == "forced_already_single") paired(true, D3DMULTISAMPLE_NONE, 0);
|
||||
else if (name == "forced_no_depth" || name == "forced_lockable_single") {
|
||||
D3D9DeviceEx d; d.options.forceSingleSample = true;
|
||||
D3D9SwapChainEx c{&d, {}, {}};
|
||||
if (name == "forced_lockable_single") c.m_presentParams.MultiSampleType = D3DMULTISAMPLE_NONE;
|
||||
assert(c.CreateBackBuffers(1, name == "forced_lockable_single" ? D3DPRESENTFLAG_LOCKABLE_BACKBUFFER : 0) == D3D_OK);
|
||||
assert(c.m_backBuffers.size() == 1 && d.created[0].MultiSample == D3DMULTISAMPLE_NONE);
|
||||
assert(d.created[0].IsLockable && d.context.initialized == 1);
|
||||
} else if (name == "forced_unsupported" || name == "forced_invalid_type" || name == "forced_lockable_msaa") {
|
||||
D3D9DeviceEx d; d.options.forceSingleSample = true;
|
||||
D3D9SwapChainEx c{&d, {}, {}};
|
||||
if (name == "forced_unsupported") d.adapter.supported = false;
|
||||
if (name == "forced_invalid_type") c.m_presentParams.MultiSampleType = D3DMULTISAMPLE_TYPE(17);
|
||||
HRESULT expected = name == "forced_unsupported" ? D3DERR_NOTAVAILABLE : D3DERR_INVALIDCALL;
|
||||
assert(c.CreateBackBuffers(2, name == "forced_lockable_msaa" ? D3DPRESENTFLAG_LOCKABLE_BACKBUFFER : 0) == expected);
|
||||
assert(d.attempts == 0 && d.losable == 0 && d.injected == 0 && c.m_backBuffers.empty());
|
||||
} else if (name == "forced_allocation_failure" || name == "default_allocation_failure") {
|
||||
D3D9DeviceEx d; d.options.forceSingleSample = name == "forced_allocation_failure"; d.failAt = 2;
|
||||
D3D9SwapChainEx c{&d, {}, {}};
|
||||
assert(c.CreateBackBuffers(3, 0) == D3DERR_OUTOFVIDEOMEMORY);
|
||||
assert(d.attempts == 2 && d.losable == 1 && d.live == 0 && d.injected == 0 && c.m_backBuffers.empty());
|
||||
} else if (name == "forced_recreate") {
|
||||
D3D9DeviceEx d; d.options.forceSingleSample = true;
|
||||
D3D9SwapChainEx c{&d, {}, {}};
|
||||
assert(c.CreateBackBuffers(3, 0) == D3D_OK);
|
||||
c.m_presentParams.MultiSampleType = D3DMULTISAMPLE_TYPE(8);
|
||||
assert(c.CreateBackBuffers(1, 0) == D3D_OK);
|
||||
assert(d.live == 1 && c.m_backBuffers.size() == 1 && c.destroys == 2);
|
||||
assert(d.adapter.checked.size() == 2 && d.adapter.checked.back() == D3DMULTISAMPLE_TYPE(8));
|
||||
assert(c.m_backBuffers[0]->GetCommonTexture()->GetImage()->info.sampleCount == 1);
|
||||
} else if (name == "ordinary_surface" || name == "ordinary_invalid_lockable") {
|
||||
D3D9DeviceEx d; d.options.forceSingleSample = true;
|
||||
D3D9_COMMON_TEXTURE_DESC desc; desc.MultiSample = D3DMULTISAMPLE_TYPE(4);
|
||||
desc.IsLockable = name == "ordinary_invalid_lockable";
|
||||
assert(D3D9CommonTexture::NormalizeTextureProperties(&d, D3DRTYPE_SURFACE, &desc)
|
||||
== (desc.IsLockable ? D3DERR_INVALIDCALL : D3D_OK));
|
||||
if (!desc.IsLockable) assert(desc.MultiSample == D3DMULTISAMPLE_NONE && desc.MultisampleQuality == 0);
|
||||
} else assert(false);
|
||||
return 0;
|
||||
}
|
||||
@@ -64,14 +64,79 @@ library list, before anything is published.
|
||||
refresh output they now wait for it too, for at most `external_overlay_hold_cycles` refreshes (4,
|
||||
so 30 fps at 120 Hz still merges), and are painted on their own after that.
|
||||
|
||||
The non-Adreno test branch's own patches are numbered 0920-0935 (0120-0135 until main took
|
||||
0121-0125), so they apply after DroidDeck's. Applied in either order the tree is the same.
|
||||
|
||||
The system PowerVR driver uses the existing SDL/Wayland swapchain backend. Its additional patches are:
|
||||
|
||||
- `0920-nested-swapchain-capability-fallback.patch`: negotiate the surface's usages, mutable-format
|
||||
support, image count, alpha and extent; use offscreen composition and GPU copies when required.
|
||||
- `0921-powervr-single-pixel-rcas.patch`: use the existing single-pixel RCAS shader on PowerVR,
|
||||
where the quad variant fails compilation.
|
||||
- `0922-powervr-linear-dmabuf-import.patch`: retain the explicit linear layout when PowerVR
|
||||
rejects the mutable-format query, and intersect imported-image and FD memory-type masks.
|
||||
- `0923-powervr-rgba-copy-surface.patch`: require an advertised RGBA SDR copy surface matching
|
||||
the shader's `rgba8` storage view. The tested workaround leaves other vendors, HDR and direct
|
||||
composition unchanged; it does not restrict game-facing BGRA formats.
|
||||
- `0924-sdl-preserve-explicit-refresh.patch` and `0925-sdl-wait-before-present.patch`: preserve
|
||||
configured refresh across SDL events and finish composition before presenting without a
|
||||
render-finished semaphore. The build runs the focused capability, format and refresh tests.
|
||||
|
||||
Sixteen more of Armada's patches are DRM/lease/HDR-on-KMS work for a native display, which this
|
||||
app's Wayland-hosted gamescope never reaches, or need a newer gamescope than the runtime has.
|
||||
- `0926-explicit-sync-switch.patch`: `GAMESCOPE_DISABLE_EXPLICIT_SYNC=1` makes the nested
|
||||
(Wayland and SDL) backends report no explicit sync, so gamescope does not offer
|
||||
wp_linux_drm_syncobj_manager_v1 and clients use implicit sync. The app sets it on a GPU that is
|
||||
not an Adreno when the kernel is older than 6.6 (no DRM_IOCTL_SYNCOBJ_EVENTFD: an Exynos 2400e
|
||||
on 6.1 logged hundreds of "timeline: DRM_IOCTL_SYNCOBJ_EVENTFD failed" and a game hung at a
|
||||
black screen) or when the render node is Mali's stand-in (/dev/mali0 has no DRM syncobjs).
|
||||
- `0927-shm-buffers-upload-every-commit.patch` (David Cimo, for Mali through Venus; his `0114`): with
|
||||
no DRM node, Xwayland has no glamor and commits a few wl_shm buffers over and over with new pixels.
|
||||
gamescope memoizes one texture per `wlr_buffer`, and a shm buffer's texture is a copy taken at
|
||||
import, so the screen cycled through the first few frames forever while Steam ran on behind them.
|
||||
Only dma-buf textures are memoized now; a shm buffer is uploaded on every commit. Adreno never
|
||||
takes this path, since its Xwayland hands over dma-bufs. Also what XWAYLAND_NO_GLAMOR sessions need.
|
||||
- `0929-log-failing-compute-pipeline.patch`: when `vkCreateComputePipelines` fails, one extra line
|
||||
per shader type names the pipeline (shader type, layer count, ycbcr/colorspace masks, fp16) and the
|
||||
SPIR-V capabilities its shader declares. A Mali-G615 through Venus refused all 119 composite
|
||||
pipelines with VK_ERROR_INITIALIZATION_FAILED and nothing said which feature it objected to.
|
||||
- `0930-composite-without-immutable-ycbcr-samplers.patch`: one composite pipeline is compiled at
|
||||
start-up; when the driver refuses it, the descriptor layout is rebuilt without binding 4's immutable
|
||||
YCbCr samplers (that binding then takes the slot's ordinary sampler) and the probe tried again, with
|
||||
both outcomes in the log. `GAMESCOPE_NO_YCBCR_SAMPLERS=1` forces it. A Mali-G615 through Venus
|
||||
refused every composite shader (blit, blur, RCAS: SPIR-V capabilities Shader, Sampled1D,
|
||||
ImageQuery, no Float16) while EASU, NIS and the NV12 converter, which share the layout but never
|
||||
touch binding 4, compiled.
|
||||
- `0931-memory-type-fallback-keep-probe.patch`: `findMemoryType` asked for DEVICE_LOCAL|HOST_VISIBLE
|
||||
memory falls back to host-visible memory without DEVICE_LOCAL, and a failure logs the requested
|
||||
properties, the type bits and every memory type. The Mali bridge models a unified-memory GPU like a
|
||||
discrete one (host-visible types without DEVICE_LOCAL), so the upload buffer found nothing and the
|
||||
backend failed. Also: 0930's probe pipeline is kept instead of destroyed, and skipped when
|
||||
`GAMESCOPE_NO_YCBCR_SAMPLERS=1` (destroying a pipeline the Venus host had refused killed the
|
||||
render server).
|
||||
- `0932-name-hung-up-waitable.patch`: "IWaitable hung up. Aborting." now names the waitable's class,
|
||||
its fd and what the fd is (`/proc/self/fd`), and the Wayland backend's input thread says why the
|
||||
compositor connection ended (protocol error or errno) first. An S24 FE aborted there after 60/120 Hz
|
||||
flips and after a resume with nothing else in the log.
|
||||
- `0933-flippable-image-unexportable-modifiers.patch`: a flippable (dma-buf exported) image whose
|
||||
modifiers the driver supports but does not report EXPORTABLE uses them anyway, and an image with no
|
||||
usable modifier fails with a log line instead of asserting in `CVulkanTexture::BInit`. The Mali
|
||||
bridge forwards the phone driver's answer, which leaves EXPORTABLE out, though it exports dma-bufs.
|
||||
- `0934-flippable-image-no-backend-modifiers.patch`: when the nested backend offers no modifier at all
|
||||
for a flippable image's format, `CVulkanTexture::BInit` tries linear and logs it instead of asserting
|
||||
`!modifiers.empty()`. NieR Replicant ended the session there on a Pixel 9a under Venus.
|
||||
- `0935-flippable-image-linear-when-driver-rejects-all.patch`: when the driver answers every offered
|
||||
modifier with `VK_ERROR_FORMAT_NOT_SUPPORTED` and linear was among them, the flippable image tries
|
||||
linear anyway; if it cannot be made, `BInit` fails as before. An r32p1 Mali-G610 (Vulkan 1.1) behind
|
||||
the Mali bridge rejected both of the backend's modifiers for AR24, so the session ended at start
|
||||
(0933's "no usable modifier"); the bridge makes such images without the handle type and exports
|
||||
them through a dma-heap.
|
||||
|
||||
- `0116-release-cursor-shm-buffers.patch` - this app: pointer cursor surfaces have no
|
||||
X11/xdg window association, so routing their commits through `g_PendingCommits`
|
||||
retained every old SHM buffer until the surface was destroyed. Ignore cursor-role
|
||||
commits before taking the buffer lock; X11 cursor images still follow the existing
|
||||
MouseCursor path. Window commits awaiting association are unchanged.
|
||||
The shared DroidDeck patch also includes `0116-release-cursor-shm-buffers.patch`: pointer cursor
|
||||
surfaces have no X11/xdg window association, so routing their commits through `g_PendingCommits`
|
||||
retained every old SHM buffer until the surface was destroyed. It ignores cursor-role commits before
|
||||
taking the buffer lock; X11 cursor images still follow the existing MouseCursor path. Window commits
|
||||
awaiting association are unchanged.
|
||||
|
||||
The live regression probe is `tools/tests/test_gamescope_cursor_shm.py`. Run it
|
||||
inside an active Gamescope session with access to that process's `/proc` fd
|
||||
|
||||
@@ -43,9 +43,12 @@ meson test -C src/build --no-rebuild --print-errorlogs cursor_routing wayland_sc
|
||||
ls -l *.pkg.tar.*
|
||||
"
|
||||
cd "$WORK"
|
||||
g++ -std=c++17 -Wall -Wextra -Werror -UNDEBUG -I pkg/arch/src/gamescope/src \
|
||||
tools/gamescope/tests/nested-swapchain.cpp -o pkg/test-nested-swapchain
|
||||
pkg/test-nested-swapchain
|
||||
rm -rf out && mkdir -p out/usr/local/bin
|
||||
PKG=$(ls pkg/arch/gamescope-*.pkg.tar.* | grep -v -- '-debug-' | head -1)
|
||||
tar --use-compress-program=unzstd -xf "$PKG" -C out --strip-components=2 usr/bin/gamescope
|
||||
tar -xf "$PKG" -C out --strip-components=2 usr/bin/gamescope
|
||||
mv out/gamescope out/usr/local/bin/gamescope
|
||||
chmod 755 out/usr/local/bin/gamescope
|
||||
strip --strip-unneeded out/usr/local/bin/gamescope || true
|
||||
|
||||
@@ -0,0 +1,358 @@
|
||||
diff --git a/src/nested_swapchain.hpp b/src/nested_swapchain.hpp
|
||||
new file mode 100644
|
||||
index 0000000..06fc987
|
||||
--- /dev/null
|
||||
+++ b/src/nested_swapchain.hpp
|
||||
@@ -0,0 +1,53 @@
|
||||
+#pragma once
|
||||
+
|
||||
+#include <algorithm>
|
||||
+#include <vulkan/vulkan_core.h>
|
||||
+
|
||||
+namespace gamescope
|
||||
+{
|
||||
+struct NestedSwapchainConfig
|
||||
+{
|
||||
+ bool copy = false;
|
||||
+ uint32_t imageCount = 0;
|
||||
+ VkImageUsageFlags usage = 0;
|
||||
+ VkCompositeAlphaFlagBitsKHR alpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
|
||||
+ VkExtent2D extent = {};
|
||||
+};
|
||||
+
|
||||
+inline bool ChooseNestedSwapchainConfig( const VkSurfaceCapabilitiesKHR &caps,
|
||||
+ bool mutableFormat, uint32_t width, uint32_t height, NestedSwapchainConfig &config )
|
||||
+{
|
||||
+ constexpr VkImageUsageFlags direct = VK_IMAGE_USAGE_SAMPLED_BIT |
|
||||
+ VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
|
||||
+ config.copy = !mutableFormat || ( caps.supportedUsageFlags & direct ) != direct;
|
||||
+ config.usage = config.copy ? VkImageUsageFlags{VK_IMAGE_USAGE_TRANSFER_DST_BIT} : direct;
|
||||
+ if ( ( caps.supportedUsageFlags & config.usage ) != config.usage )
|
||||
+ return false;
|
||||
+
|
||||
+ bool foundAlpha = false;
|
||||
+ for ( auto alpha : { VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR, VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR,
|
||||
+ VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR, VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR } )
|
||||
+ {
|
||||
+ if ( caps.supportedCompositeAlpha & alpha )
|
||||
+ {
|
||||
+ config.alpha = alpha;
|
||||
+ foundAlpha = true;
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+ if ( !foundAlpha || caps.maxImageExtent.width < caps.minImageExtent.width ||
|
||||
+ caps.maxImageExtent.height < caps.minImageExtent.height )
|
||||
+ return false;
|
||||
+
|
||||
+ config.imageCount = caps.minImageCount + ( caps.minImageCount != UINT32_MAX );
|
||||
+ if ( caps.maxImageCount )
|
||||
+ config.imageCount = std::min( config.imageCount, caps.maxImageCount );
|
||||
+ if ( config.imageCount < caps.minImageCount )
|
||||
+ return false;
|
||||
+ config.extent = caps.currentExtent.width == UINT32_MAX
|
||||
+ ? VkExtent2D{ std::clamp( width, caps.minImageExtent.width, caps.maxImageExtent.width ),
|
||||
+ std::clamp( height, caps.minImageExtent.height, caps.maxImageExtent.height ) }
|
||||
+ : caps.currentExtent;
|
||||
+ return config.extent.width && config.extent.height;
|
||||
+}
|
||||
+}
|
||||
diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp
|
||||
index ffad695..ffc8e28 100644
|
||||
--- a/src/rendervulkan.cpp
|
||||
+++ b/src/rendervulkan.cpp
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <deque>
|
||||
#include <dlfcn.h>
|
||||
#include "vulkan_include.h"
|
||||
+#include "nested_swapchain.hpp"
|
||||
#include "Utils/Algorithm.h"
|
||||
|
||||
#if defined(__linux__)
|
||||
@@ -450,6 +451,8 @@ bool CVulkanDevice::createDevice()
|
||||
bool hasDrmProps = vulkan_has_drm_props();
|
||||
bool supportsForeignQueue = false;
|
||||
bool supportsHDRMetadata = false;
|
||||
+ bool presentIdExtension = false;
|
||||
+ bool presentWaitExtension = false;
|
||||
for (const auto& ext : m_supportedExts) {
|
||||
if ( strcmp(ext.extensionName, VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME) == 0 )
|
||||
m_bSupportsModifiers = true;
|
||||
@@ -457,6 +460,13 @@ bool CVulkanDevice::createDevice()
|
||||
if ( strcmp(ext.extensionName, VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME) == 0 )
|
||||
supportsForeignQueue = true;
|
||||
|
||||
+ if ( strcmp(ext.extensionName, VK_KHR_SWAPCHAIN_MUTABLE_FORMAT_EXTENSION_NAME) == 0 )
|
||||
+ m_bSupportsMutableSwapchain = true;
|
||||
+ if ( strcmp(ext.extensionName, VK_KHR_PRESENT_ID_EXTENSION_NAME) == 0 )
|
||||
+ presentIdExtension = true;
|
||||
+ if ( strcmp(ext.extensionName, VK_KHR_PRESENT_WAIT_EXTENSION_NAME) == 0 )
|
||||
+ presentWaitExtension = true;
|
||||
+
|
||||
if ( strcmp(ext.extensionName, VK_EXT_HDR_METADATA_EXTENSION_NAME) == 0 )
|
||||
supportsHDRMetadata = true;
|
||||
}
|
||||
@@ -576,10 +586,24 @@ bool CVulkanDevice::createDevice()
|
||||
if ( GetBackend()->UsesVulkanSwapchain() )
|
||||
{
|
||||
enabledExtensions.push_back( VK_KHR_SWAPCHAIN_EXTENSION_NAME );
|
||||
- enabledExtensions.push_back( VK_KHR_SWAPCHAIN_MUTABLE_FORMAT_EXTENSION_NAME );
|
||||
+ if ( m_bSupportsMutableSwapchain )
|
||||
+ enabledExtensions.push_back( VK_KHR_SWAPCHAIN_MUTABLE_FORMAT_EXTENSION_NAME );
|
||||
|
||||
- enabledExtensions.push_back( VK_KHR_PRESENT_ID_EXTENSION_NAME );
|
||||
- enabledExtensions.push_back( VK_KHR_PRESENT_WAIT_EXTENSION_NAME );
|
||||
+ if ( presentIdExtension && presentWaitExtension )
|
||||
+ {
|
||||
+ VkPhysicalDevicePresentWaitFeaturesKHR wait = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_WAIT_FEATURES_KHR };
|
||||
+ VkPhysicalDevicePresentIdFeaturesKHR id = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_ID_FEATURES_KHR, .pNext = &wait };
|
||||
+ VkPhysicalDeviceFeatures2 features = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, .pNext = &id };
|
||||
+ vk.GetPhysicalDeviceFeatures2( physDev(), &features );
|
||||
+ m_bSupportsPresentWait = id.presentId && wait.presentWait;
|
||||
+ }
|
||||
+ if ( m_bSupportsPresentWait )
|
||||
+ {
|
||||
+ enabledExtensions.push_back( VK_KHR_PRESENT_ID_EXTENSION_NAME );
|
||||
+ enabledExtensions.push_back( VK_KHR_PRESENT_WAIT_EXTENSION_NAME );
|
||||
+ }
|
||||
+ else
|
||||
+ vk_log.infof( "Using FIFO acquire pacing; presentation timestamps unavailable" );
|
||||
|
||||
if ( supportsHDRMetadata )
|
||||
enabledExtensions.push_back( VK_EXT_HDR_METADATA_EXTENSION_NAME );
|
||||
@@ -654,7 +678,7 @@ bool CVulkanDevice::createDevice()
|
||||
|
||||
VkPhysicalDeviceFeatures2 features2 = {
|
||||
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2,
|
||||
- .pNext = &presentIdFeatures,
|
||||
+ .pNext = m_bSupportsPresentWait ? static_cast<void *>( &presentIdFeatures ) : static_cast<void *>( &features13 ),
|
||||
.features = {
|
||||
.shaderInt16 = m_bSupportsFp16,
|
||||
},
|
||||
@@ -2660,7 +2684,7 @@ bool CVulkanTexture::BInit( uint32_t width, uint32_t height, uint32_t depth, uin
|
||||
return true;
|
||||
}
|
||||
|
||||
-bool CVulkanTexture::BInitFromSwapchain( VkImage image, uint32_t width, uint32_t height, VkFormat format )
|
||||
+bool CVulkanTexture::BInitFromSwapchain( VkImage image, uint32_t width, uint32_t height, VkFormat format, bool transferOnly )
|
||||
{
|
||||
m_drmFormat = VulkanFormatToDRM( format );
|
||||
m_vkImage = image;
|
||||
@@ -2672,6 +2696,12 @@ bool CVulkanTexture::BInitFromSwapchain( VkImage image, uint32_t width, uint32_t
|
||||
m_contentWidth = width;
|
||||
m_contentHeight = height;
|
||||
m_bOutputImage = true;
|
||||
+ if ( transferOnly )
|
||||
+ {
|
||||
+ // A copy destination needs no views (and the swapchain need not be mutable).
|
||||
+ m_bInitialized = true;
|
||||
+ return true;
|
||||
+ }
|
||||
|
||||
VkImageViewCreateInfo createInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
||||
@@ -3094,7 +3124,7 @@ void vulkan_present_to_window( void )
|
||||
|
||||
VkPresentInfoKHR presentInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
|
||||
- .pNext = &presentIdInfo,
|
||||
+ .pNext = g_device.supportsPresentWait() ? &presentIdInfo : nullptr,
|
||||
.swapchainCount = 1,
|
||||
.pSwapchains = &g_output.swapChain,
|
||||
.pImageIndices = &g_output.nOutImage,
|
||||
@@ -3102,14 +3132,22 @@ void vulkan_present_to_window( void )
|
||||
|
||||
if ( g_device.vk.QueuePresentKHR( g_device.queue(), &presentInfo ) == VK_SUCCESS )
|
||||
{
|
||||
- g_currentPresentWaitId = presentId;
|
||||
- g_currentPresentWaitId.notify_all();
|
||||
+ if ( g_device.supportsPresentWait() )
|
||||
+ {
|
||||
+ g_currentPresentWaitId = presentId;
|
||||
+ g_currentPresentWaitId.notify_all();
|
||||
+ }
|
||||
}
|
||||
else
|
||||
vulkan_remake_swapchain();
|
||||
|
||||
while ( !acquire_next_image() )
|
||||
vulkan_remake_swapchain();
|
||||
+ if ( !g_device.supportsPresentWait() )
|
||||
+ {
|
||||
+ // Estimated scheduling anchor after FIFO buffer acquisition, not presentation feedback.
|
||||
+ GetVBlankTimer().MarkVBlank( get_time_in_nanos(), true );
|
||||
+ }
|
||||
}
|
||||
|
||||
gamescope::Rc<CVulkanTexture> vulkan_create_1d_lut(uint32_t size)
|
||||
@@ -3219,7 +3257,19 @@ extern bool g_bOutputHDREnabled;
|
||||
|
||||
bool vulkan_make_swapchain( VulkanOutput_t *pOutput )
|
||||
{
|
||||
- uint32_t imageCount = pOutput->surfaceCaps.minImageCount + 1;
|
||||
+ // Re-query on resize as well as initial creation.
|
||||
+ if ( g_device.vk.GetPhysicalDeviceSurfaceCapabilitiesKHR( g_device.physDev(), pOutput->surface, &pOutput->surfaceCaps ) != VK_SUCCESS )
|
||||
+ return false;
|
||||
+ gamescope::NestedSwapchainConfig config;
|
||||
+ if ( !gamescope::ChooseNestedSwapchainConfig( pOutput->surfaceCaps, g_device.supportsMutableSwapchain(), g_nOutputWidth, g_nOutputHeight, config ) )
|
||||
+ {
|
||||
+ vk_log.errorf( "Surface supports neither direct composition nor transfer presentation" );
|
||||
+ return false;
|
||||
+ }
|
||||
+ pOutput->copyToSwapchain = config.copy;
|
||||
+ g_nOutputWidth = config.extent.width;
|
||||
+ g_nOutputHeight = config.extent.height;
|
||||
+ uint32_t imageCount = config.imageCount;
|
||||
uint32_t formatCount = pOutput->surfaceFormats.size();
|
||||
uint32_t surfaceFormat = formatCount;
|
||||
VkColorSpaceKHR preferredColorSpace = g_bOutputHDREnabled ? VK_COLOR_SPACE_HDR10_ST2084_EXT : VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
|
||||
@@ -3254,6 +3304,13 @@ bool vulkan_make_swapchain( VulkanOutput_t *pOutput )
|
||||
}
|
||||
}
|
||||
|
||||
+ if ( surfaceFormat == formatCount )
|
||||
+ {
|
||||
+ for ( surfaceFormat = 0; surfaceFormat < formatCount; ++surfaceFormat )
|
||||
+ if ( pOutput->surfaceFormats[surfaceFormat].format == VK_FORMAT_R8G8B8A8_UNORM &&
|
||||
+ pOutput->surfaceFormats[surfaceFormat].colorSpace == preferredColorSpace )
|
||||
+ break;
|
||||
+ }
|
||||
if ( surfaceFormat == formatCount )
|
||||
return false;
|
||||
|
||||
@@ -3276,8 +3333,8 @@ bool vulkan_make_swapchain( VulkanOutput_t *pOutput )
|
||||
|
||||
VkSwapchainCreateInfoKHR createInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
|
||||
- .pNext = formats[0] != formats[1] ? &usageListInfo : nullptr,
|
||||
- .flags = formats[0] != formats[1] ? VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR : (VkSwapchainCreateFlagBitsKHR )0,
|
||||
+ .pNext = !config.copy && formats[0] != formats[1] ? &usageListInfo : nullptr,
|
||||
+ .flags = !config.copy && formats[0] != formats[1] ? VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR : (VkSwapchainCreateFlagBitsKHR )0,
|
||||
.surface = pOutput->surface,
|
||||
.minImageCount = imageCount,
|
||||
.imageFormat = eVkFormat,
|
||||
@@ -3287,10 +3344,10 @@ bool vulkan_make_swapchain( VulkanOutput_t *pOutput )
|
||||
.height = g_nOutputHeight,
|
||||
},
|
||||
.imageArrayLayers = 1,
|
||||
- .imageUsage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
|
||||
+ .imageUsage = config.usage,
|
||||
.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
||||
.preTransform = pOutput->surfaceCaps.currentTransform,
|
||||
- .compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR,
|
||||
+ .compositeAlpha = config.alpha,
|
||||
.presentMode = VK_PRESENT_MODE_FIFO_KHR,
|
||||
.clipped = VK_TRUE,
|
||||
};
|
||||
@@ -3304,12 +3361,30 @@ bool vulkan_make_swapchain( VulkanOutput_t *pOutput )
|
||||
g_device.vk.GetSwapchainImagesKHR( g_device.device(), pOutput->swapChain, &imageCount, swapchainImages.data() );
|
||||
|
||||
pOutput->outputImages.resize(imageCount);
|
||||
+ pOutput->presentationImages.clear();
|
||||
+ if ( config.copy )
|
||||
+ {
|
||||
+ vk_log.infof( "Nested swapchain: composing offscreen and copying to FIFO presentation images" );
|
||||
+ pOutput->presentationImages.resize(imageCount);
|
||||
+ }
|
||||
|
||||
for ( uint32_t i = 0; i < pOutput->outputImages.size(); i++ )
|
||||
{
|
||||
pOutput->outputImages[i] = new CVulkanTexture();
|
||||
|
||||
- if ( !pOutput->outputImages[i]->BInitFromSwapchain(swapchainImages[i], g_nOutputWidth, g_nOutputHeight, eVkFormat))
|
||||
+ if ( config.copy )
|
||||
+ {
|
||||
+ CVulkanTexture::createFlags flags;
|
||||
+ flags.bStorage = true;
|
||||
+ flags.bSampled = true;
|
||||
+ flags.bTransferSrc = true;
|
||||
+ if ( !pOutput->outputImages[i]->BInit( g_nOutputWidth, g_nOutputHeight, 1, pOutput->uOutputFormat, flags ) )
|
||||
+ return false;
|
||||
+ pOutput->presentationImages[i] = new CVulkanTexture();
|
||||
+ if ( !pOutput->presentationImages[i]->BInitFromSwapchain( swapchainImages[i], g_nOutputWidth, g_nOutputHeight, eVkFormat, true ) )
|
||||
+ return false;
|
||||
+ }
|
||||
+ else if ( !pOutput->outputImages[i]->BInitFromSwapchain(swapchainImages[i], g_nOutputWidth, g_nOutputHeight, eVkFormat))
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -3335,6 +3410,10 @@ bool vulkan_remake_swapchain( void )
|
||||
g_device.vk.QueueWaitIdle( g_device.queue() );
|
||||
|
||||
pOutput->outputImages.clear();
|
||||
+ pOutput->presentationImages.clear();
|
||||
+ if ( pOutput->acquireFence )
|
||||
+ g_device.vk.DestroyFence( g_device.device(), pOutput->acquireFence, nullptr );
|
||||
+ pOutput->acquireFence = VK_NULL_HANDLE;
|
||||
|
||||
g_device.vk.DestroySwapchainKHR( g_device.device(), pOutput->swapChain, nullptr );
|
||||
|
||||
@@ -3670,7 +3749,7 @@ bool vulkan_init( VkInstance instance, VkSurfaceKHR surface )
|
||||
if (!init_nis_data())
|
||||
return false;
|
||||
|
||||
- if ( GetBackend()->UsesVulkanSwapchain() )
|
||||
+ if ( GetBackend()->UsesVulkanSwapchain() && g_device.supportsPresentWait() )
|
||||
{
|
||||
std::thread present_wait_thread( present_wait_thread_func );
|
||||
present_wait_thread.detach();
|
||||
@@ -4579,6 +4658,9 @@ std::optional<uint64_t> vulkan_composite( struct FrameInfo_t *frameInfo, gamesco
|
||||
CompositeTimingEnd( cmdBuffer.get(), *oTimingSlot, pszKey, pszKeyPre, pszKeyPost );
|
||||
}
|
||||
|
||||
+ if ( !pOutputOverride && g_output.copyToSwapchain )
|
||||
+ cmdBuffer->copyImage( compositeImage, g_output.presentationImages[g_output.nOutImage] );
|
||||
+
|
||||
uint64_t sequence = g_device.submit(std::move(cmdBuffer));
|
||||
if ( oTimingSlot )
|
||||
g_CompositeTiming.pending.back().ulSeqNo = sequence;
|
||||
diff --git a/src/rendervulkan.hpp b/src/rendervulkan.hpp
|
||||
index fa519db..674a3b4 100644
|
||||
--- a/src/rendervulkan.hpp
|
||||
+++ b/src/rendervulkan.hpp
|
||||
@@ -162,7 +162,7 @@ public:
|
||||
};
|
||||
|
||||
bool BInit( uint32_t width, uint32_t height, uint32_t depth, uint32_t drmFormat, createFlags flags, wlr_dmabuf_attributes *pDMA = nullptr, uint32_t contentWidth = 0, uint32_t contentHeight = 0, CVulkanTexture *pExistingImageToReuseMemory = nullptr, gamescope::OwningRc<gamescope::IBackendFb> pBackendFb = nullptr );
|
||||
- bool BInitFromSwapchain( VkImage image, uint32_t width, uint32_t height, VkFormat format );
|
||||
+ bool BInitFromSwapchain( VkImage image, uint32_t width, uint32_t height, VkFormat format, bool transferOnly = false );
|
||||
|
||||
uint32_t IncRef();
|
||||
uint32_t DecRef();
|
||||
@@ -586,7 +586,9 @@ struct VulkanOutput_t
|
||||
|
||||
std::shared_ptr<gamescope::BackendBlob> swapchainHDRMetadata;
|
||||
VkSwapchainKHR swapChain;
|
||||
- VkFence acquireFence;
|
||||
+ VkFence acquireFence = VK_NULL_HANDLE;
|
||||
+ bool copyToSwapchain = false;
|
||||
+ std::vector<gamescope::OwningRc<CVulkanTexture>> presentationImages;
|
||||
|
||||
uint32_t nOutImage; // swapchain index in nested mode, or ping/pong between two RTs
|
||||
std::vector<gamescope::OwningRc<CVulkanTexture>> outputImages;
|
||||
@@ -756,6 +758,7 @@ static inline uint32_t div_roundup(uint32_t x, uint32_t y)
|
||||
VK_FUNC(CreateDescriptorPool) \
|
||||
VK_FUNC(CreateDescriptorSetLayout) \
|
||||
VK_FUNC(CreateFence) \
|
||||
+ VK_FUNC(DestroyFence) \
|
||||
VK_FUNC(CreateGraphicsPipelines) \
|
||||
VK_FUNC(CreateImage) \
|
||||
VK_FUNC(CreateImageView) \
|
||||
@@ -862,6 +865,8 @@ public:
|
||||
inline VkPipelineLayout pipelineLayout() {return m_pipelineLayout;}
|
||||
inline int drmRenderFd() {return m_drmRendererFd;}
|
||||
inline bool supportsModifiers() {return m_bSupportsModifiers;}
|
||||
+ inline bool supportsMutableSwapchain() {return m_bSupportsMutableSwapchain;}
|
||||
+ inline bool supportsPresentWait() {return m_bSupportsPresentWait;}
|
||||
inline bool hasDrmPrimaryDevId() {return m_bHasDrmPrimaryDevId;}
|
||||
inline dev_t primaryDevId() {return m_drmPrimaryDevId;}
|
||||
inline bool supportsFp16() {return m_bSupportsFp16;}
|
||||
@@ -930,6 +935,8 @@ protected:
|
||||
uint32_t m_uVendorID = 0;
|
||||
bool m_bHasDrmPrimaryDevId = false;
|
||||
bool m_bSupportsModifiers = false;
|
||||
+ bool m_bSupportsMutableSwapchain = false;
|
||||
+ bool m_bSupportsPresentWait = false;
|
||||
bool m_bInitialized = false;
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp
|
||||
--- a/src/rendervulkan.cpp
|
||||
+++ b/src/rendervulkan.cpp
|
||||
@@ -996,8 +996,9 @@
|
||||
SHADER(BLUR, cs_composite_blur);
|
||||
SHADER(BLUR_COND, cs_composite_blur_cond);
|
||||
SHADER(BLUR_FIRST_PASS, cs_gaussian_blur_horizontal);
|
||||
- // The one pixel layout is only measured on Adreno, every other vendor keeps the quad swizzle.
|
||||
- if (m_uVendorID == 0x5143) /* Qualcomm */
|
||||
+ // PowerVR rejects the quad-swizzled RCAS for 3+ layers with YCbCr mask 2.
|
||||
+ // The existing one-pixel shader compiles those variants and covers the same 16x16 tile.
|
||||
+ if (m_uVendorID == 0x5143 || m_uVendorID == 0x1010) /* Qualcomm or Imagination */
|
||||
{
|
||||
SHADER(RCAS, cs_composite_rcas_1px);
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp
|
||||
--- a/src/rendervulkan.cpp
|
||||
+++ b/src/rendervulkan.cpp
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <dlfcn.h>
|
||||
#include "vulkan_include.h"
|
||||
#include "nested_swapchain.hpp"
|
||||
+#include "dmabuf_import.hpp"
|
||||
#include "Utils/Algorithm.h"
|
||||
|
||||
#if defined(__linux__)
|
||||
@@ -2229,8 +2230,27 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
- if ( res == VK_SUCCESS &&
|
||||
- ( externalImageProperties.externalMemoryProperties.externalMemoryFeatures & VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT ) )
|
||||
+ bool importable = res == VK_SUCCESS &&
|
||||
+ ( externalImageProperties.externalMemoryProperties.externalMemoryFeatures & VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT );
|
||||
+ if ( gamescope::RetryPowerVRLinearQuery( g_device.vendorID(), imageInfo.format,
|
||||
+ pDMA->modifier, pDMA->n_planes, imageInfo.flags, res ) )
|
||||
+ {
|
||||
+ // PowerVR's mutable-format query rejects this linear import even though
|
||||
+ // explicit-layout imports and UNORM/sRGB GPU sampling work. Query the base
|
||||
+ // format without changing the image we actually create or its supplied stride.
|
||||
+ VkImageCreateInfo baseFormat = imageInfo;
|
||||
+ baseFormat.flags &= ~VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
|
||||
+ baseFormat.pNext = nullptr;
|
||||
+ res = getModifierProps( &baseFormat, pDMA->modifier, &externalImageProperties );
|
||||
+ importable = res == VK_SUCCESS &&
|
||||
+ ( externalImageProperties.externalMemoryProperties.externalMemoryFeatures & VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT );
|
||||
+ }
|
||||
+ if ( !importable && g_device.vendorID() == 0x1010 )
|
||||
+ {
|
||||
+ vk_log.errorf( "PowerVR DMA-BUF modifier is not importable; refusing a different tiling" );
|
||||
+ return false;
|
||||
+ }
|
||||
+ if ( importable )
|
||||
{
|
||||
modifierInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_EXPLICIT_CREATE_INFO_EXT,
|
||||
@@ -2348,6 +2368,22 @@
|
||||
|
||||
m_format = imageInfo.format;
|
||||
|
||||
+ VkMemoryFdPropertiesKHR fdProperties = {
|
||||
+ .sType = VK_STRUCTURE_TYPE_MEMORY_FD_PROPERTIES_KHR,
|
||||
+ };
|
||||
+ if ( pDMA )
|
||||
+ {
|
||||
+ if ( !g_device.vk.GetMemoryFdPropertiesKHR )
|
||||
+ return false;
|
||||
+ res = g_device.vk.GetMemoryFdPropertiesKHR( g_device.device(),
|
||||
+ VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT, pDMA->fd[0], &fdProperties );
|
||||
+ if ( res != VK_SUCCESS )
|
||||
+ {
|
||||
+ vk_errorf( res, "vkGetMemoryFdPropertiesKHR failed" );
|
||||
+ return false;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
res = g_device.vk.CreateImage(g_device.device(), &imageInfo, nullptr, &m_vkImage);
|
||||
if (res != VK_SUCCESS) {
|
||||
vk_errorf( res, "vkCreateImage failed" );
|
||||
@@ -2357,10 +2393,22 @@
|
||||
VkMemoryRequirements memRequirements;
|
||||
g_device.vk.GetImageMemoryRequirements(g_device.device(), m_vkImage, &memRequirements);
|
||||
|
||||
+ uint32_t memoryType = pDMA
|
||||
+ ? gamescope::DmabufMemoryType( g_device.memoryProperties(), memRequirements.memoryTypeBits,
|
||||
+ fdProperties.memoryTypeBits, properties )
|
||||
+ : uint32_t( g_device.findMemoryType( properties, memRequirements.memoryTypeBits ) );
|
||||
+ if ( memoryType == UINT32_MAX )
|
||||
+ {
|
||||
+ vk_log.errorf( "No compatible image memory type (image=0x%x, fd=0x%x)",
|
||||
+ memRequirements.memoryTypeBits, fdProperties.memoryTypeBits );
|
||||
+ g_device.vk.DestroyImage( g_device.device(), m_vkImage, nullptr );
|
||||
+ m_vkImage = VK_NULL_HANDLE;
|
||||
+ return false;
|
||||
+ }
|
||||
VkMemoryAllocateInfo allocInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
|
||||
.allocationSize = memRequirements.size,
|
||||
- .memoryTypeIndex = uint32_t(g_device.findMemoryType(properties, memRequirements.memoryTypeBits)),
|
||||
+ .memoryTypeIndex = memoryType,
|
||||
};
|
||||
|
||||
m_size = allocInfo.allocationSize;
|
||||
@@ -2453,6 +2501,13 @@
|
||||
if ( res != VK_SUCCESS )
|
||||
{
|
||||
vk_errorf( res, "vkBindImageMemory failed" );
|
||||
+ if ( pDMA )
|
||||
+ vk_log.errorf( "DMA-BUF: %ux%u format=%u modifier=0x%" PRIx64
|
||||
+ " planes=%d stride=%u offset=%u tiling=%u allocation=%" PRIu64
|
||||
+ " memoryType=%u imageBits=0x%x fdBits=0x%x", width, height, imageInfo.format,
|
||||
+ pDMA->modifier, pDMA->n_planes, pDMA->stride[0], pDMA->offset[0], imageInfo.tiling,
|
||||
+ uint64_t( allocInfo.allocationSize ), allocInfo.memoryTypeIndex,
|
||||
+ memRequirements.memoryTypeBits, fdProperties.memoryTypeBits );
|
||||
return false;
|
||||
}
|
||||
|
||||
diff --git a/src/rendervulkan.hpp b/src/rendervulkan.hpp
|
||||
--- a/src/rendervulkan.hpp
|
||||
+++ b/src/rendervulkan.hpp
|
||||
@@ -791,6 +791,7 @@
|
||||
VK_FUNC(GetImageMemoryRequirements) \
|
||||
VK_FUNC(GetImageSubresourceLayout) \
|
||||
VK_FUNC(GetMemoryFdKHR) \
|
||||
+ VK_FUNC(GetMemoryFdPropertiesKHR) \
|
||||
VK_FUNC(GetQueryPoolResults) \
|
||||
VK_FUNC(GetSemaphoreCounterValue) \
|
||||
VK_FUNC(GetSwapchainImagesKHR) \
|
||||
@@ -865,6 +866,8 @@
|
||||
inline VkPipelineLayout pipelineLayout() {return m_pipelineLayout;}
|
||||
inline int drmRenderFd() {return m_drmRendererFd;}
|
||||
inline bool supportsModifiers() {return m_bSupportsModifiers;}
|
||||
+ inline uint32_t vendorID() const {return m_uVendorID;}
|
||||
+ inline const VkPhysicalDeviceMemoryProperties &memoryProperties() const {return m_memoryProperties;}
|
||||
inline bool supportsMutableSwapchain() {return m_bSupportsMutableSwapchain;}
|
||||
inline bool supportsPresentWait() {return m_bSupportsPresentWait;}
|
||||
inline bool hasDrmPrimaryDevId() {return m_bHasDrmPrimaryDevId;}
|
||||
diff --git a/src/dmabuf_import.hpp b/src/dmabuf_import.hpp
|
||||
new file mode 100644
|
||||
--- /dev/null
|
||||
+++ b/src/dmabuf_import.hpp
|
||||
@@ -0,0 +1,29 @@
|
||||
+#pragma once
|
||||
+#include <vulkan/vulkan_core.h>
|
||||
+
|
||||
+namespace gamescope
|
||||
+{
|
||||
+inline bool RetryPowerVRLinearQuery( uint32_t vendor, VkFormat format, uint64_t modifier,
|
||||
+ uint32_t planes, VkImageCreateFlags flags, VkResult result )
|
||||
+{
|
||||
+ return vendor == 0x1010 && modifier == 0 && planes == 1 &&
|
||||
+ flags == VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT && result == VK_ERROR_FORMAT_NOT_SUPPORTED &&
|
||||
+ ( format == VK_FORMAT_R8G8B8A8_UNORM || format == VK_FORMAT_B8G8R8A8_UNORM );
|
||||
+}
|
||||
+
|
||||
+inline uint32_t DmabufMemoryType( const VkPhysicalDeviceMemoryProperties &memory,
|
||||
+ uint32_t imageBits, uint32_t fdBits, VkMemoryPropertyFlags preferred )
|
||||
+{
|
||||
+ uint32_t fallback = UINT32_MAX;
|
||||
+ const uint32_t compatible = imageBits & fdBits;
|
||||
+ for ( uint32_t i = 0; i < memory.memoryTypeCount; ++i )
|
||||
+ {
|
||||
+ if ( !( compatible & ( 1u << i ) ) ) continue;
|
||||
+ if ( fallback == UINT32_MAX ) fallback = i;
|
||||
+ if ( ( memory.memoryTypes[i].propertyFlags & preferred ) == preferred ) return i;
|
||||
+ }
|
||||
+ // Device-local is a preference for an existing imported buffer. CPU mapping
|
||||
+ // properties are requirements and must never be silently relaxed.
|
||||
+ return preferred == VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT ? fallback : UINT32_MAX;
|
||||
+}
|
||||
+}
|
||||
@@ -0,0 +1,61 @@
|
||||
diff --git a/src/nested_surface_format.hpp b/src/nested_surface_format.hpp
|
||||
new file mode 100644
|
||||
--- /dev/null
|
||||
+++ b/src/nested_surface_format.hpp
|
||||
@@ -0,0 +1,31 @@
|
||||
+#pragma once
|
||||
+
|
||||
+#include <vulkan/vulkan_core.h>
|
||||
+
|
||||
+namespace gamescope
|
||||
+{
|
||||
+// The SDR composition shader declares rgba8, which requires an R8G8B8A8_UNORM
|
||||
+// storage view. Binding a BGRA view is a format mismatch; a same-format copy
|
||||
+// cannot correct it. Keep the workaround scoped to the PowerVR SDR copy path
|
||||
+// where the channel reversal was reproduced, not game-facing texture formats.
|
||||
+// On success, formatCount means the existing selector should choose the format.
|
||||
+// On failure, no matching RGBA SDR surface was advertised for this scoped path.
|
||||
+inline bool ChooseNestedSDRCopySurfaceFormat( uint32_t vendorId, bool copy, bool hdr,
|
||||
+ const VkSurfaceFormatKHR *formats, uint32_t formatCount, uint32_t &surfaceFormat )
|
||||
+{
|
||||
+ surfaceFormat = formatCount;
|
||||
+ if ( vendorId != 0x1010 || !copy || hdr )
|
||||
+ return true;
|
||||
+
|
||||
+ for ( uint32_t i = 0; i < formatCount; ++i )
|
||||
+ {
|
||||
+ if ( formats[i].format == VK_FORMAT_R8G8B8A8_UNORM &&
|
||||
+ formats[i].colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR )
|
||||
+ {
|
||||
+ surfaceFormat = i;
|
||||
+ return true;
|
||||
+ }
|
||||
+ }
|
||||
+ return false;
|
||||
+}
|
||||
+}
|
||||
diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp
|
||||
--- a/src/rendervulkan.cpp
|
||||
+++ b/src/rendervulkan.cpp
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "vulkan_include.h"
|
||||
#include "nested_swapchain.hpp"
|
||||
#include "dmabuf_import.hpp"
|
||||
+#include "nested_surface_format.hpp"
|
||||
#include "Utils/Algorithm.h"
|
||||
|
||||
#if defined(__linux__)
|
||||
@@ -3330,6 +3331,13 @@
|
||||
uint32_t surfaceFormat = formatCount;
|
||||
VkColorSpaceKHR preferredColorSpace = g_bOutputHDREnabled ? VK_COLOR_SPACE_HDR10_ST2084_EXT : VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
|
||||
|
||||
+ if ( !gamescope::ChooseNestedSDRCopySurfaceFormat( g_device.vendorID(), config.copy,
|
||||
+ g_bOutputHDREnabled, pOutput->surfaceFormats.data(), formatCount, surfaceFormat ) )
|
||||
+ {
|
||||
+ vk_log.errorf( "PowerVR copy composition requires an RGBA SDR surface" );
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
if ( surfaceFormat == formatCount )
|
||||
{
|
||||
for ( surfaceFormat = 0; surfaceFormat < formatCount; surfaceFormat++ )
|
||||
@@ -0,0 +1,78 @@
|
||||
diff --git a/src/sdl_refresh.hpp b/src/sdl_refresh.hpp
|
||||
new file mode 100644
|
||||
--- /dev/null
|
||||
+++ b/src/sdl_refresh.hpp
|
||||
@@ -0,0 +1,22 @@
|
||||
+#pragma once
|
||||
+
|
||||
+#include <cstdint>
|
||||
+
|
||||
+namespace gamescope
|
||||
+{
|
||||
+struct SDLRefreshChoice
|
||||
+{
|
||||
+ int32_t refresh = 0;
|
||||
+ bool configured = false;
|
||||
+};
|
||||
+
|
||||
+// SDL reports the desktop mode again when its window is shown, moved or resized. Keep an
|
||||
+// explicit -r as the rate exposed by nested Gamescope; discover the desktop rate only when the
|
||||
+// caller did not configure one.
|
||||
+inline constexpr SDLRefreshChoice ChooseSDLRefresh( int32_t configuredRefresh, int32_t desktopRefresh )
|
||||
+{
|
||||
+ return configuredRefresh > 0
|
||||
+ ? SDLRefreshChoice{ configuredRefresh, true }
|
||||
+ : SDLRefreshChoice{ desktopRefresh, false };
|
||||
+}
|
||||
+}
|
||||
diff --git a/src/Backends/SDLBackend.cpp b/src/Backends/SDLBackend.cpp
|
||||
--- a/src/Backends/SDLBackend.cpp
|
||||
+++ b/src/Backends/SDLBackend.cpp
|
||||
@@ -18,14 +18,20 @@
|
||||
#include "steamcompmgr.hpp"
|
||||
#include "Utils/Defer.h"
|
||||
#include "refresh_rate.h"
|
||||
+#include "log.hpp"
|
||||
+#include "sdl_refresh.hpp"
|
||||
|
||||
#include "sdlscancodetable.hpp"
|
||||
|
||||
static int g_nOldNestedRefresh = 0;
|
||||
static bool g_bWindowFocused = true;
|
||||
+static int g_nLastLoggedConfiguredRefresh = -1;
|
||||
+static int g_nLastLoggedDesktopRefresh = -1;
|
||||
+static int g_nLastLoggedEffectiveRefresh = -1;
|
||||
|
||||
static int g_nOutputWidthPts = 0;
|
||||
static int g_nOutputHeightPts = 0;
|
||||
+static LogScope sdl_log( "sdl_backend" );
|
||||
|
||||
extern bool g_bForceHDR10OutputDebug;
|
||||
extern bool steamMode;
|
||||
@@ -846,9 +851,25 @@ namespace gamescope
|
||||
SDL_DisplayMode mode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 };
|
||||
|
||||
display_index = SDL_GetWindowDisplayIndex( m_Connector.GetSDLWindow() );
|
||||
if ( SDL_GetDesktopDisplayMode( display_index, &mode ) == 0 )
|
||||
{
|
||||
- g_nOutputRefresh = ConvertHztomHz( mode.refresh_rate );
|
||||
+ const int nDesktopRefresh = ConvertHztomHz( mode.refresh_rate );
|
||||
+ const SDLRefreshChoice refresh = ChooseSDLRefresh( g_nOldNestedRefresh, nDesktopRefresh );
|
||||
+ g_nOutputRefresh = refresh.refresh;
|
||||
+
|
||||
+ if ( g_nLastLoggedConfiguredRefresh != g_nOldNestedRefresh ||
|
||||
+ g_nLastLoggedDesktopRefresh != nDesktopRefresh ||
|
||||
+ g_nLastLoggedEffectiveRefresh != refresh.refresh )
|
||||
+ {
|
||||
+ sdl_log.infof( "Refresh mode: configured=%.3fHz desktop=%.3fHz effective=%.3fHz source=%s",
|
||||
+ ConvertmHzToHz( float( g_nOldNestedRefresh ) ),
|
||||
+ ConvertmHzToHz( float( nDesktopRefresh ) ),
|
||||
+ ConvertmHzToHz( float( refresh.refresh ) ),
|
||||
+ refresh.configured ? "configured -r" : "SDL desktop" );
|
||||
+ g_nLastLoggedConfiguredRefresh = g_nOldNestedRefresh;
|
||||
+ g_nLastLoggedDesktopRefresh = nDesktopRefresh;
|
||||
+ g_nLastLoggedEffectiveRefresh = refresh.refresh;
|
||||
+ }
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -0,0 +1,23 @@
|
||||
diff --git a/src/Backends/SDLBackend.cpp b/src/Backends/SDLBackend.cpp
|
||||
--- a/src/Backends/SDLBackend.cpp
|
||||
+++ b/src/Backends/SDLBackend.cpp
|
||||
@@ -351,14 +351,15 @@ namespace gamescope
|
||||
std::optional oCompositeResult = vulkan_composite( (FrameInfo_t *)pFrameInfo, nullptr, false );
|
||||
if ( !oCompositeResult )
|
||||
return -EINVAL;
|
||||
|
||||
+ // Present has no render-finished semaphore, so wait before the native consumer can read
|
||||
+ // the old contents. This serializes composition and present; a future pipelined path must
|
||||
+ // signal a binary render-finished semaphore and make vkQueuePresentKHR wait on it.
|
||||
+ vulkan_wait( *oCompositeResult, true );
|
||||
+
|
||||
vulkan_present_to_window();
|
||||
|
||||
// TODO: Hook up PresentationFeedback.
|
||||
-
|
||||
- // Wait for the composite result on our side *after* we
|
||||
- // commit the buffer to the compositor to avoid a bubble.
|
||||
- vulkan_wait( *oCompositeResult, true );
|
||||
|
||||
GetVBlankTimer().UpdateWasCompositing( true );
|
||||
GetVBlankTimer().UpdateLastDrawTime( get_time_in_nanos() - g_SteamCompMgrVBlankTime.ulWakeupTime );
|
||||
@@ -0,0 +1,29 @@
|
||||
--- a/src/Backends/WaylandBackend.cpp
|
||||
+++ b/src/Backends/WaylandBackend.cpp
|
||||
@@ -2309,7 +2309,10 @@
|
||||
|
||||
bool CWaylandBackend::SupportsExplicitSync() const
|
||||
{
|
||||
- return true;
|
||||
+ // GAMESCOPE_DISABLE_EXPLICIT_SYNC=1: a kernel without DRM_IOCTL_SYNCOBJ_EVENTFD (before
|
||||
+ // Linux 6.6) cannot signal the timelines, so clients use implicit sync instead.
|
||||
+ const char *pszDisable = getenv( "GAMESCOPE_DISABLE_EXPLICIT_SYNC" );
|
||||
+ return !( pszDisable && *pszDisable == '1' );
|
||||
}
|
||||
|
||||
bool CWaylandBackend::IsPaused() const
|
||||
--- a/src/Backends/SDLBackend.cpp
|
||||
+++ b/src/Backends/SDLBackend.cpp
|
||||
@@ -506,8 +506,10 @@
|
||||
|
||||
bool CSDLBackend::SupportsExplicitSync() const
|
||||
{
|
||||
- // We use a Vulkan swapchain, so yes.
|
||||
- return true;
|
||||
+ // We use a Vulkan swapchain, so yes - unless the kernel cannot signal the timelines
|
||||
+ // (no DRM_IOCTL_SYNCOBJ_EVENTFD before Linux 6.6): GAMESCOPE_DISABLE_EXPLICIT_SYNC=1.
|
||||
+ const char *pszDisable = getenv( "GAMESCOPE_DISABLE_EXPLICIT_SYNC" );
|
||||
+ return !( pszDisable && *pszDisable == '1' );
|
||||
}
|
||||
|
||||
bool CSDLBackend::IsPaused() const
|
||||
@@ -0,0 +1,44 @@
|
||||
diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp
|
||||
index 18b799e..b803ee0 100644
|
||||
--- a/src/steamcompmgr.cpp
|
||||
+++ b/src/steamcompmgr.cpp
|
||||
@@ -1850,16 +1850,23 @@ import_commit (
|
||||
commit->fifo = false;
|
||||
}
|
||||
|
||||
- if ( gamescope::OwningRc<CVulkanTexture> pTexture = s_BufferMemos.LookupVulkanTexture( buf ) )
|
||||
+ struct wlr_dmabuf_attributes dmabuf = {0};
|
||||
+ const bool bDmabuf = wlr_buffer_get_dmabuf( buf, &dmabuf );
|
||||
+
|
||||
+ // Only a dma-buf's texture shows the buffer itself. A shm buffer's texture is a copy taken at
|
||||
+ // import, and Xwayland without glamor commits the same shm buffers again with new pixels.
|
||||
+ if ( bDmabuf )
|
||||
{
|
||||
- // Going from OwningRc -> Rc now.
|
||||
- commit->vulkanTex = pTexture;
|
||||
- return commit;
|
||||
+ if ( gamescope::OwningRc<CVulkanTexture> pTexture = s_BufferMemos.LookupVulkanTexture( buf ) )
|
||||
+ {
|
||||
+ // Going from OwningRc -> Rc now.
|
||||
+ commit->vulkanTex = pTexture;
|
||||
+ return commit;
|
||||
+ }
|
||||
}
|
||||
|
||||
- struct wlr_dmabuf_attributes dmabuf = {0};
|
||||
gamescope::OwningRc<gamescope::IBackendFb> pBackendFb;
|
||||
- if ( wlr_buffer_get_dmabuf( buf, &dmabuf ) )
|
||||
+ if ( bDmabuf )
|
||||
{
|
||||
pBackendFb = GetBackend()->ImportDmabufToBackend( &dmabuf );
|
||||
}
|
||||
@@ -1873,7 +1880,8 @@ import_commit (
|
||||
|
||||
commit->vulkanTex = pOwnedTexture;
|
||||
|
||||
- s_BufferMemos.MemoizeBuffer( buf, std::move( pOwnedTexture ) );
|
||||
+ if ( bDmabuf )
|
||||
+ s_BufferMemos.MemoizeBuffer( buf, std::move( pOwnedTexture ) );
|
||||
|
||||
return commit;
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp
|
||||
index 41294f7..42b2ec6 100644
|
||||
--- a/src/rendervulkan.cpp
|
||||
+++ b/src/rendervulkan.cpp
|
||||
@@ -435,6 +435,9 @@ bool CVulkanDevice::selectPhysDev(VkSurfaceKHR surface)
|
||||
return true;
|
||||
}
|
||||
|
||||
+// Stands in for VK_NULL_HANDLE in descriptor slots when the device has no nullDescriptor.
|
||||
+static gamescope::OwningRc<CVulkanTexture> s_nullDescriptorFallback;
|
||||
+
|
||||
bool CVulkanDevice::createDevice()
|
||||
{
|
||||
uint32_t supportedExtensionCount;
|
||||
@@ -459,6 +462,9 @@ bool CVulkanDevice::createDevice()
|
||||
if ( strcmp(ext.extensionName, VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME) == 0 )
|
||||
m_bSupportsModifiers = true;
|
||||
|
||||
+ if ( strcmp(ext.extensionName, VK_EXT_ROBUSTNESS_2_EXTENSION_NAME) == 0 )
|
||||
+ m_bSupportsNullDescriptor = true;
|
||||
+
|
||||
if ( strcmp(ext.extensionName, VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME) == 0 )
|
||||
supportsForeignQueue = true;
|
||||
|
||||
@@ -622,7 +628,10 @@ bool CVulkanDevice::createDevice()
|
||||
|
||||
enabledExtensions.push_back( VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME );
|
||||
|
||||
- enabledExtensions.push_back( VK_EXT_ROBUSTNESS_2_EXTENSION_NAME );
|
||||
+ if ( m_bSupportsNullDescriptor )
|
||||
+ enabledExtensions.push_back( VK_EXT_ROBUSTNESS_2_EXTENSION_NAME );
|
||||
+ else
|
||||
+ vk_log.infof( "no VK_EXT_robustness2: unused descriptor slots use a 1x1 texture" );
|
||||
#if 0
|
||||
enabledExtensions.push_back( VK_KHR_MAINTENANCE_5_EXTENSION_NAME );
|
||||
#endif
|
||||
@@ -711,9 +720,10 @@ bool CVulkanDevice::createDevice()
|
||||
|
||||
VkPhysicalDeviceRobustness2FeaturesEXT robustness2Features = {
|
||||
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT,
|
||||
- .pNext = std::exchange(features2.pNext, &robustness2Features),
|
||||
.nullDescriptor = VK_TRUE,
|
||||
};
|
||||
+ if ( m_bSupportsNullDescriptor )
|
||||
+ robustness2Features.pNext = std::exchange(features2.pNext, &robustness2Features);
|
||||
|
||||
VkResult res = vk.CreateDevice(physDev(), &deviceCreateInfo, nullptr, &m_device);
|
||||
if ( res == VK_ERROR_NOT_PERMITTED_KHR && useRealtimeVulkanQueue )
|
||||
@@ -1861,6 +1871,15 @@ void CVulkanCmdBuffer::dispatch(uint32_t x, uint32_t y, uint32_t z)
|
||||
lut3DDescriptor[i].imageView = m_lut3D[i] ? m_lut3D[i]->srgbView() : VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
+ if ( !m_device->supportsNullDescriptor() && s_nullDescriptorFallback != nullptr )
|
||||
+ {
|
||||
+ VkImageView fallback = s_nullDescriptorFallback->srgbView();
|
||||
+ for (auto &d : imageDescriptors) if (d.imageView == VK_NULL_HANDLE) d.imageView = fallback;
|
||||
+ for (auto &d : ycbcrImageDescriptors) if (d.imageView == VK_NULL_HANDLE) d.imageView = fallback;
|
||||
+ for (auto &d : shaperLutDescriptor) if (d.imageView == VK_NULL_HANDLE) d.imageView = fallback;
|
||||
+ for (auto &d : lut3DDescriptor) if (d.imageView == VK_NULL_HANDLE) d.imageView = fallback;
|
||||
+ }
|
||||
+
|
||||
if (!m_target->isYcbcr())
|
||||
{
|
||||
targetDescriptors[0].imageView = m_target->srgbView();
|
||||
@@ -3546,6 +3565,9 @@ static bool vulkan_make_output_images( VulkanOutput_t *pOutput )
|
||||
// Oh no.
|
||||
pOutput->temporaryHackyBlankImage = vulkan_create_debug_blank_texture();
|
||||
|
||||
+ if ( !g_device.supportsNullDescriptor() && s_nullDescriptorFallback == nullptr )
|
||||
+ s_nullDescriptorFallback = vulkan_create_flat_texture( 1, 1, 0, 0, 0, 0 );
|
||||
+
|
||||
if ( pOutput->uOutputFormatOverlay != VK_FORMAT_UNDEFINED && !kDisablePartialComposition )
|
||||
{
|
||||
uint32_t uPartialDRMFormat = pOutput->uOutputFormatOverlay;
|
||||
diff --git a/src/rendervulkan.hpp b/src/rendervulkan.hpp
|
||||
index 5ffec4a..901e6a6 100644
|
||||
--- a/src/rendervulkan.hpp
|
||||
+++ b/src/rendervulkan.hpp
|
||||
@@ -866,6 +866,9 @@ public:
|
||||
inline VkPipelineLayout pipelineLayout() {return m_pipelineLayout;}
|
||||
inline int drmRenderFd() {return m_drmRendererFd;}
|
||||
inline bool supportsModifiers() {return m_bSupportsModifiers;}
|
||||
+ // VK_EXT_robustness2's nullDescriptor. A Mali driver through Venus has no robustness2: unused
|
||||
+ // descriptor slots then point at a 1x1 texture instead of VK_NULL_HANDLE.
|
||||
+ inline bool supportsNullDescriptor() {return m_bSupportsNullDescriptor;}
|
||||
inline uint32_t vendorID() const {return m_uVendorID;}
|
||||
inline const VkPhysicalDeviceMemoryProperties &memoryProperties() const {return m_memoryProperties;}
|
||||
inline bool supportsMutableSwapchain() {return m_bSupportsMutableSwapchain;}
|
||||
@@ -938,6 +941,7 @@ protected:
|
||||
uint32_t m_uVendorID = 0;
|
||||
bool m_bHasDrmPrimaryDevId = false;
|
||||
bool m_bSupportsModifiers = false;
|
||||
+ bool m_bSupportsNullDescriptor = false;
|
||||
bool m_bSupportsMutableSwapchain = false;
|
||||
bool m_bSupportsPresentWait = false;
|
||||
bool m_bInitialized = false;
|
||||
@@ -0,0 +1,55 @@
|
||||
diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp
|
||||
index 42b2ec6..103baee 100644
|
||||
--- a/src/rendervulkan.cpp
|
||||
+++ b/src/rendervulkan.cpp
|
||||
@@ -994,6 +994,8 @@ bool CVulkanDevice::createPools()
|
||||
return true;
|
||||
}
|
||||
|
||||
+static std::string s_shaderCaps[SHADER_TYPE_COUNT];
|
||||
+
|
||||
bool CVulkanDevice::createShaders()
|
||||
{
|
||||
struct ShaderInfo_t
|
||||
@@ -1040,6 +1042,25 @@ bool CVulkanDevice::createShaders()
|
||||
.pCode = shaderInfos[i].spirv,
|
||||
};
|
||||
|
||||
+ // The SPIR-V capabilities each shader declares, for the log when its pipeline is refused.
|
||||
+ {
|
||||
+ const uint32_t *pWords = shaderInfos[i].spirv;
|
||||
+ size_t nWords = shaderInfos[i].size / sizeof(uint32_t);
|
||||
+ std::string &sCaps = s_shaderCaps[i];
|
||||
+ sCaps.clear();
|
||||
+ for ( size_t w = 5; w < nWords; )
|
||||
+ {
|
||||
+ uint32_t uLen = pWords[w] >> 16;
|
||||
+ if ( !uLen )
|
||||
+ break;
|
||||
+ if ( ( pWords[w] & 0xffffu ) == 17 /* OpCapability */ && w + 1 < nWords )
|
||||
+ sCaps += " " + std::to_string( pWords[w + 1] );
|
||||
+ else if ( ( pWords[w] & 0xffffu ) == 54 /* OpFunction: past the header */ )
|
||||
+ break;
|
||||
+ w += uLen;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
VkResult res = vk.CreateShaderModule(device(), &shaderCreateInfo, nullptr, &m_shaderModules[i]);
|
||||
if ( res != VK_SUCCESS )
|
||||
{
|
||||
@@ -1240,6 +1261,15 @@ VkPipeline CVulkanDevice::compilePipeline(uint32_t layerCount, uint32_t ycbcrMas
|
||||
VkResult res = vk.CreateComputePipelines(device(), VK_NULL_HANDLE, 1, &computePipelineCreateInfo, nullptr, &result);
|
||||
if (res != VK_SUCCESS) {
|
||||
vk_errorf( res, "vkCreateComputePipelines failed" );
|
||||
+ // Which pipeline, once per shader type: a vendor driver through Venus may refuse one variant only.
|
||||
+ static uint32_t s_uLoggedTypes = 0;
|
||||
+ if ( !( s_uLoggedTypes & ( 1u << ( (uint32_t)type & 31u ) ) ) )
|
||||
+ {
|
||||
+ s_uLoggedTypes |= 1u << ( (uint32_t)type & 31u );
|
||||
+ vk_log.errorf( " failing compute pipeline: shader type %u, layers %u, ycbcr mask 0x%x, blur layers %u, colorspace mask 0x%x, output eotf %u, itm %u, fp16 %d, SPIR-V capabilities:%s",
|
||||
+ (uint32_t)type, layerCount, ycbcrMask, blur_layer_count, colorspace_mask, (uint32_t)output_eotf, (uint32_t)itm_enable, m_bSupportsFp16 ? 1 : 0,
|
||||
+ (uint32_t)type < SHADER_TYPE_COUNT ? s_shaderCaps[type].c_str() : "" );
|
||||
+ }
|
||||
return VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp
|
||||
index 103baee..d344a99 100644
|
||||
--- a/src/rendervulkan.cpp
|
||||
+++ b/src/rendervulkan.cpp
|
||||
@@ -319,6 +319,33 @@ bool CVulkanDevice::BInit(VkInstance instance, VkSurfaceKHR surface)
|
||||
return false;
|
||||
if (!createShaders())
|
||||
return false;
|
||||
+ {
|
||||
+ // One composite pipeline up front: a driver that refuses it with the immutable YCbCr
|
||||
+ // samplers gets the layout without them (NV12 textures then sample without conversion).
|
||||
+ if ( getenv( "GAMESCOPE_NO_YCBCR_SAMPLERS" ) && *getenv( "GAMESCOPE_NO_YCBCR_SAMPLERS" ) == '1' )
|
||||
+ {
|
||||
+ vk_log.infof( "GAMESCOPE_NO_YCBCR_SAMPLERS=1: composite layout without immutable YCbCr samplers" );
|
||||
+ vk.DestroyPipelineLayout( device(), m_pipelineLayout, nullptr );
|
||||
+ vk.DestroyDescriptorSetLayout( device(), m_descriptorSetLayout, nullptr );
|
||||
+ m_bYcbcrImmutableSamplers = false;
|
||||
+ if ( !createLayouts() )
|
||||
+ return false;
|
||||
+ }
|
||||
+ VkPipeline probe = compilePipeline( 1, 0, SHADER_TYPE_BLIT, 1, 0, 0, 0, false );
|
||||
+ if ( probe == VK_NULL_HANDLE && m_bYcbcrImmutableSamplers )
|
||||
+ {
|
||||
+ vk_log.errorf( "composite pipeline refused; retrying without immutable YCbCr samplers" );
|
||||
+ vk.DestroyPipelineLayout( device(), m_pipelineLayout, nullptr );
|
||||
+ vk.DestroyDescriptorSetLayout( device(), m_descriptorSetLayout, nullptr );
|
||||
+ m_bYcbcrImmutableSamplers = false;
|
||||
+ if ( !createLayouts() )
|
||||
+ return false;
|
||||
+ probe = compilePipeline( 1, 0, SHADER_TYPE_BLIT, 1, 0, 0, 0, false );
|
||||
+ vk_log.infof( "composite pipeline without immutable YCbCr samplers: %s", probe ? "accepted" : "STILL refused" );
|
||||
+ }
|
||||
+ if ( probe != VK_NULL_HANDLE )
|
||||
+ vk.DestroyPipeline( device(), probe, nullptr );
|
||||
+ }
|
||||
if (!createScratchResources())
|
||||
return false;
|
||||
|
||||
@@ -869,7 +896,7 @@ bool CVulkanDevice::createLayouts()
|
||||
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||
.descriptorCount = VKR_SAMPLER_SLOTS,
|
||||
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
- .pImmutableSamplers = ycbcrSamplers.data(),
|
||||
+ .pImmutableSamplers = m_bYcbcrImmutableSamplers ? ycbcrSamplers.data() : nullptr,
|
||||
},
|
||||
VkDescriptorSetLayoutBinding {
|
||||
.binding = 5,
|
||||
@@ -1870,6 +1897,8 @@ void CVulkanCmdBuffer::dispatch(uint32_t x, uint32_t y, uint32_t z)
|
||||
imageDescriptors[i].sampler = m_device->sampler(m_samplerState[i]);
|
||||
imageDescriptors[i].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
|
||||
ycbcrImageDescriptors[i].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
|
||||
+ if ( !m_device->ycbcrImmutableSamplers() )
|
||||
+ ycbcrImageDescriptors[i].sampler = imageDescriptors[i].sampler;
|
||||
if (m_boundTextures[i] == nullptr)
|
||||
continue;
|
||||
|
||||
diff --git a/src/rendervulkan.hpp b/src/rendervulkan.hpp
|
||||
index 901e6a6..e0ede11 100644
|
||||
--- a/src/rendervulkan.hpp
|
||||
+++ b/src/rendervulkan.hpp
|
||||
@@ -876,6 +876,7 @@ public:
|
||||
inline bool hasDrmPrimaryDevId() {return m_bHasDrmPrimaryDevId;}
|
||||
inline dev_t primaryDevId() {return m_drmPrimaryDevId;}
|
||||
inline bool supportsFp16() {return m_bSupportsFp16;}
|
||||
+ inline bool ycbcrImmutableSamplers() {return m_bYcbcrImmutableSamplers;}
|
||||
inline std::vector<VkExtensionProperties>& supportedExtensions() {return m_supportedExts;}
|
||||
|
||||
inline std::pair<void *, uint32_t> uploadBufferData(uint32_t size)
|
||||
@@ -925,6 +926,9 @@ protected:
|
||||
VkQueue m_generalQueue = nullptr;
|
||||
VkSamplerYcbcrConversion m_ycbcrConversion = VK_NULL_HANDLE;
|
||||
VkSampler m_ycbcrSampler = VK_NULL_HANDLE;
|
||||
+ // Binding 4 carries immutable YCbCr samplers; off when the driver refuses every composite
|
||||
+ // pipeline with them (Mali-G615 through Venus: VK_ERROR_INITIALIZATION_FAILED).
|
||||
+ bool m_bYcbcrImmutableSamplers = true;
|
||||
VkDescriptorSetLayout m_descriptorSetLayout = VK_NULL_HANDLE;
|
||||
VkPipelineLayout m_pipelineLayout = VK_NULL_HANDLE;
|
||||
VkDescriptorPool m_descriptorPool = VK_NULL_HANDLE;
|
||||
@@ -0,0 +1,55 @@
|
||||
diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp
|
||||
index d344a99..e699c85 100644
|
||||
--- a/src/rendervulkan.cpp
|
||||
+++ b/src/rendervulkan.cpp
|
||||
@@ -331,7 +331,10 @@ bool CVulkanDevice::BInit(VkInstance instance, VkSurfaceKHR surface)
|
||||
if ( !createLayouts() )
|
||||
return false;
|
||||
}
|
||||
- VkPipeline probe = compilePipeline( 1, 0, SHADER_TYPE_BLIT, 1, 0, 0, 0, false );
|
||||
+ // Forced off: no probe. Through Venus a pipeline the host refused can still come back as a
|
||||
+ // handle, and destroying it later is a command the render server rejects - it killed the
|
||||
+ // whole vtest context (Mali-G615: "vkDestroyPipeline resulted in CS error", exit 137).
|
||||
+ VkPipeline probe = m_bYcbcrImmutableSamplers ? compilePipeline( 1, 0, SHADER_TYPE_BLIT, 1, 0, 0, 0, false ) : VK_NULL_HANDLE;
|
||||
if ( probe == VK_NULL_HANDLE && m_bYcbcrImmutableSamplers )
|
||||
{
|
||||
vk_log.errorf( "composite pipeline refused; retrying without immutable YCbCr samplers" );
|
||||
@@ -343,8 +346,8 @@ bool CVulkanDevice::BInit(VkInstance instance, VkSurfaceKHR surface)
|
||||
probe = compilePipeline( 1, 0, SHADER_TYPE_BLIT, 1, 0, 0, 0, false );
|
||||
vk_log.infof( "composite pipeline without immutable YCbCr samplers: %s", probe ? "accepted" : "STILL refused" );
|
||||
}
|
||||
- if ( probe != VK_NULL_HANDLE )
|
||||
- vk.DestroyPipeline( device(), probe, nullptr );
|
||||
+ // The probe is kept, never destroyed (see above): one pipeline.
|
||||
+ (void)probe;
|
||||
}
|
||||
if (!createScratchResources())
|
||||
return false;
|
||||
@@ -1380,7 +1383,26 @@ int32_t CVulkanDevice::findMemoryType( VkMemoryPropertyFlags properties, uint32_
|
||||
|
||||
return i;
|
||||
}
|
||||
-
|
||||
+
|
||||
+ // A device that lists its host-visible memory without DEVICE_LOCAL (the Mali bridge models a
|
||||
+ // unified-memory GPU that way, as a discrete one would) still has it all on the GPU: settle for
|
||||
+ // host-visible memory rather than fail ("findMemoryType failed", then no backend).
|
||||
+ if ( properties & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT && properties & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT )
|
||||
+ {
|
||||
+ int32_t nFallback = findMemoryType( properties & ~VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, requiredTypeBits );
|
||||
+ static bool s_bLogged = false;
|
||||
+ if ( !s_bLogged )
|
||||
+ {
|
||||
+ s_bLogged = true;
|
||||
+ vk_log.infof( "no memory type with properties 0x%x in type bits 0x%x; without DEVICE_LOCAL: %d", properties, requiredTypeBits, nFallback );
|
||||
+ }
|
||||
+ if ( nFallback >= 0 )
|
||||
+ return nFallback;
|
||||
+ }
|
||||
+
|
||||
+ vk_log.errorf( "findMemoryType: no memory type with properties 0x%x in type bits 0x%x (%u types)", properties, requiredTypeBits, m_memoryProperties.memoryTypeCount );
|
||||
+ for ( uint32_t i = 0; i < m_memoryProperties.memoryTypeCount; i++ )
|
||||
+ vk_log.errorf( " memory type %u: flags 0x%x heap %u", i, m_memoryProperties.memoryTypes[ i ].propertyFlags, m_memoryProperties.memoryTypes[ i ].heapIndex );
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp
|
||||
index a927f69..2c9bd73 100644
|
||||
--- a/src/Backends/WaylandBackend.cpp
|
||||
+++ b/src/Backends/WaylandBackend.cpp
|
||||
@@ -2882,7 +2882,22 @@ namespace gamescope
|
||||
abort();
|
||||
}
|
||||
|
||||
- CFunctionWaitable waitable( nFD );
|
||||
+ // The compositor's connection: a hang-up says why (the protocol error, if one was posted).
|
||||
+ class CDisplayWaitable final : public IWaitable
|
||||
+ {
|
||||
+ public:
|
||||
+ CDisplayWaitable( int nFD, wl_display *pDisplay ) : m_nFD{ nFD }, m_pDisplay{ pDisplay } {}
|
||||
+ int GetFD() final { return m_nFD; }
|
||||
+ void OnPollHangUp() final
|
||||
+ {
|
||||
+ LogDisplayError( "The Wayland compositor closed gamescope's connection (input thread)", m_pDisplay );
|
||||
+ IWaitable::OnPollHangUp();
|
||||
+ }
|
||||
+ private:
|
||||
+ int m_nFD;
|
||||
+ wl_display *m_pDisplay;
|
||||
+ };
|
||||
+ CDisplayWaitable waitable( nFD, m_pBackend->GetDisplay() );
|
||||
m_Waiter.AddWaitable( &waitable );
|
||||
|
||||
int nRet = 0;
|
||||
diff --git a/src/waitable.h b/src/waitable.h
|
||||
index be54d46..b9116fe 100644
|
||||
--- a/src/waitable.h
|
||||
+++ b/src/waitable.h
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
+#include <typeinfo>
|
||||
+#include <stdio.h>
|
||||
|
||||
#include "log.hpp"
|
||||
|
||||
@@ -30,7 +32,14 @@ namespace gamescope
|
||||
virtual void OnPollPri() {}
|
||||
virtual void OnPollHangUp()
|
||||
{
|
||||
- g_WaitableLog.errorf( "IWaitable hung up. Aborting." );
|
||||
+ // Which one: its class and what its descriptor is (a socket, a pipe, an eventfd...).
|
||||
+ int nFD = GetFD();
|
||||
+ char szPath[64], szTarget[256] = "?";
|
||||
+ snprintf( szPath, sizeof( szPath ), "/proc/self/fd/%d", nFD );
|
||||
+ ssize_t nLen = nFD >= 0 ? readlink( szPath, szTarget, sizeof( szTarget ) - 1 ) : -1;
|
||||
+ if ( nLen >= 0 )
|
||||
+ szTarget[nLen] = '\0';
|
||||
+ g_WaitableLog.errorf( "IWaitable hung up: %s, fd %d -> %s. Aborting.", typeid( *this ).name(), nFD, szTarget );
|
||||
abort();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp
|
||||
index e699c85..0ddd249 100644
|
||||
--- a/src/rendervulkan.cpp
|
||||
+++ b/src/rendervulkan.cpp
|
||||
@@ -2372,6 +2372,7 @@ bool CVulkanTexture::BInit( uint32_t width, uint32_t height, uint32_t depth, uin
|
||||
}
|
||||
|
||||
std::vector<uint64_t> modifiers = {};
|
||||
+ std::vector<uint64_t> unexportable = {};
|
||||
// TODO(JoshA): Move this code to backend for making flippable image.
|
||||
if ( GetBackend()->UsesModifiers() && flags.bFlippable && g_device.supportsModifiers() && !pDMA )
|
||||
{
|
||||
@@ -2410,12 +2411,30 @@ bool CVulkanTexture::BInit( uint32_t width, uint32_t height, uint32_t depth, uin
|
||||
}
|
||||
|
||||
if ( !( externalFormatProps.externalMemoryProperties.externalMemoryFeatures & VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT ) )
|
||||
+ {
|
||||
+ vk_log.infof( "flippable image: modifier 0x%" PRIx64 " for DRM format 0x%x supported but not reported exportable (features 0x%x)",
|
||||
+ modifier, drmFormat, externalFormatProps.externalMemoryProperties.externalMemoryFeatures );
|
||||
+ unexportable.push_back( modifier );
|
||||
continue;
|
||||
+ }
|
||||
|
||||
modifiers.push_back( modifier );
|
||||
}
|
||||
|
||||
- assert( modifiers.size() > 0 );
|
||||
+ // A driver that supports the modifier but leaves EXPORTABLE out (the Mali bridge forwards the
|
||||
+ // phone's own driver's answer) can still export the memory as a dma-buf: the bridge's
|
||||
+ // swapchains do exactly that. Try those rather than assert (rendervulkan.cpp, CVulkanTexture::BInit).
|
||||
+ if ( modifiers.empty() && !unexportable.empty() )
|
||||
+ {
|
||||
+ vk_log.errorf( "flippable image: no modifier reported exportable for DRM format 0x%x; trying %zu supported one(s) anyway",
|
||||
+ drmFormat, unexportable.size() );
|
||||
+ modifiers = unexportable;
|
||||
+ }
|
||||
+ if ( modifiers.empty() )
|
||||
+ {
|
||||
+ vk_log.errorf( "flippable image: no usable modifier for DRM format 0x%x (%zu offered by the backend)", drmFormat, numPossibleModifiers );
|
||||
+ return false;
|
||||
+ }
|
||||
|
||||
modifierListInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_LIST_CREATE_INFO_EXT,
|
||||
@@ -0,0 +1,26 @@
|
||||
diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp
|
||||
--- a/src/rendervulkan.cpp
|
||||
+++ b/src/rendervulkan.cpp
|
||||
@@ -2235,9 +2235,19 @@
|
||||
else
|
||||
{
|
||||
std::span<const uint64_t> modifiers = GetBackend()->GetSupportedModifiers( drmFormat );
|
||||
- assert( !modifiers.empty() );
|
||||
- possibleModifiers = modifiers.data();
|
||||
- numPossibleModifiers = modifiers.size();
|
||||
+ if ( modifiers.empty() )
|
||||
+ {
|
||||
+ // The nested backend offered no modifier for this format (a game's buffer on Venus,
|
||||
+ // NieR Replicant on a Pixel 9a): linear instead of the assert that ended the session.
|
||||
+ vk_log.errorf( "flippable image: the backend offers no modifier for DRM format 0x%x; trying linear", drmFormat );
|
||||
+ possibleModifiers = &linear;
|
||||
+ numPossibleModifiers = 1;
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ possibleModifiers = modifiers.data();
|
||||
+ numPossibleModifiers = modifiers.size();
|
||||
+ }
|
||||
}
|
||||
|
||||
for ( size_t i = 0; i < numPossibleModifiers; i++ )
|
||||
@@ -0,0 +1,38 @@
|
||||
--- a/src/rendervulkan.cpp
|
||||
+++ b/src/rendervulkan.cpp
|
||||
@@ -2373,6 +2373,7 @@
|
||||
|
||||
std::vector<uint64_t> modifiers = {};
|
||||
std::vector<uint64_t> unexportable = {};
|
||||
+ bool linearRejected = false;
|
||||
// TODO(JoshA): Move this code to backend for making flippable image.
|
||||
if ( GetBackend()->UsesModifiers() && flags.bFlippable && g_device.supportsModifiers() && !pDMA )
|
||||
{
|
||||
@@ -2414,7 +2415,10 @@
|
||||
};
|
||||
res = getModifierProps( &imageInfo, modifier, &externalFormatProps );
|
||||
if ( res == VK_ERROR_FORMAT_NOT_SUPPORTED )
|
||||
+ {
|
||||
+ linearRejected |= modifier == DRM_FORMAT_MOD_LINEAR;
|
||||
continue;
|
||||
+ }
|
||||
else if ( res != VK_SUCCESS ) {
|
||||
vk_errorf( res, "getModifierProps failed" );
|
||||
return false;
|
||||
@@ -2440,6 +2444,16 @@
|
||||
drmFormat, unexportable.size() );
|
||||
modifiers = unexportable;
|
||||
}
|
||||
+ // An r32p1 Mali driver (G610, Vulkan 1.1) behind the Mali bridge answers every modifier query
|
||||
+ // with VK_ERROR_FORMAT_NOT_SUPPORTED, yet the bridge makes such an image without the handle type
|
||||
+ // and exports it through a dma-heap. Linear, when the backend offered it, is tried rather than
|
||||
+ // giving up; if the image cannot be made, BInit fails as before (Xiaomi 13T, AR24).
|
||||
+ if ( modifiers.empty() && linearRejected )
|
||||
+ {
|
||||
+ vk_log.errorf( "flippable image: the driver supports none of the %zu modifier(s) offered for DRM format 0x%x; trying linear anyway",
|
||||
+ numPossibleModifiers, drmFormat );
|
||||
+ modifiers.push_back( DRM_FORMAT_MOD_LINEAR );
|
||||
+ }
|
||||
if ( modifiers.empty() )
|
||||
{
|
||||
vk_log.errorf( "flippable image: no usable modifier for DRM format 0x%x (%zu offered by the backend)", drmFormat, numPossibleModifiers );
|
||||
@@ -1,3 +1,3 @@
|
||||
GAMESCOPE_REPO=Droid-Deck/DroidDeck-Components
|
||||
GAMESCOPE_TAG=gamescope-3.16.29-p21
|
||||
GAMESCOPE_SHA256=c34d2728eb31a5ded35e5cb874e68dd4932a7fba4bcce5f99edf654108f97018
|
||||
GAMESCOPE_REPO=Droid-Deck/DroidDeck
|
||||
GAMESCOPE_TAG=gamescope-3.16.29-pr2029-22b50d182
|
||||
GAMESCOPE_SHA256=d6bf0fe2ebb98e1fc7c9a09fccce7d7916c9cc6a10016018040cda01a940b781
|
||||
@@ -0,0 +1,156 @@
|
||||
#include "nested_swapchain.hpp"
|
||||
#include "nested_surface_format.hpp"
|
||||
#include "dmabuf_import.hpp"
|
||||
#include "sdl_refresh.hpp"
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
|
||||
int main()
|
||||
{
|
||||
using gamescope::ChooseSDLRefresh;
|
||||
constexpr int configured60 = 60'000;
|
||||
constexpr int desktop120 = 120'000;
|
||||
auto capped = ChooseSDLRefresh(configured60, desktop120);
|
||||
assert(capped.configured && capped.refresh == configured60);
|
||||
|
||||
auto discovered = ChooseSDLRefresh(0, desktop120);
|
||||
assert(!discovered.configured && discovered.refresh == desktop120);
|
||||
|
||||
auto configured120 = ChooseSDLRefresh(120'000, 60'000);
|
||||
assert(configured120.configured && configured120.refresh == 120'000);
|
||||
|
||||
VkSurfaceCapabilitiesKHR caps = {};
|
||||
caps.minImageCount = 2;
|
||||
caps.maxImageCount = 3;
|
||||
caps.currentExtent = {UINT32_MAX, UINT32_MAX};
|
||||
caps.minImageExtent = {16, 16};
|
||||
caps.maxImageExtent = {4096, 4096};
|
||||
caps.supportedCompositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
|
||||
caps.supportedUsageFlags = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT |
|
||||
VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||
gamescope::NestedSwapchainConfig config;
|
||||
|
||||
// Existing desktop drivers retain direct composition into mutable swapchains.
|
||||
assert(gamescope::ChooseNestedSwapchainConfig(caps, true, 1280, 720, config));
|
||||
assert(!config.copy && config.imageCount == 3 && config.extent.width == 1280);
|
||||
|
||||
// No mutable formats: compose offscreen and request only a copy destination.
|
||||
assert(gamescope::ChooseNestedSwapchainConfig(caps, false, 1280, 720, config));
|
||||
assert(config.copy && config.usage == VK_IMAGE_USAGE_TRANSFER_DST_BIT);
|
||||
|
||||
// The Android bridge exposes transfer usage and inherited alpha, but no storage.
|
||||
caps.supportedUsageFlags &= ~VK_IMAGE_USAGE_STORAGE_BIT;
|
||||
caps.supportedCompositeAlpha = VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR;
|
||||
caps.maxImageCount = 2;
|
||||
caps.currentExtent = {1602, 720};
|
||||
assert(gamescope::ChooseNestedSwapchainConfig(caps, true, 1920, 1080, config));
|
||||
assert(config.copy && config.alpha == VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR);
|
||||
assert(config.imageCount == 2 && config.extent.width == 1602);
|
||||
|
||||
// Fail rather than submitting unsupported image usage or alpha.
|
||||
caps.supportedUsageFlags &= ~VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||
assert(!gamescope::ChooseNestedSwapchainConfig(caps, true, 1280, 720, config));
|
||||
caps.supportedUsageFlags |= VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||
caps.supportedCompositeAlpha = 0;
|
||||
assert(!gamescope::ChooseNestedSwapchainConfig(caps, false, 1280, 720, config));
|
||||
caps.supportedCompositeAlpha = VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR;
|
||||
|
||||
caps.currentExtent = {0, 0};
|
||||
assert(!gamescope::ChooseNestedSwapchainConfig(caps, false, 1280, 720, config));
|
||||
caps.currentExtent = {UINT32_MAX, UINT32_MAX};
|
||||
assert(gamescope::ChooseNestedSwapchainConfig(caps, false, 1, 9000, config));
|
||||
assert(config.extent.width == 16 && config.extent.height == 4096);
|
||||
caps.maxImageCount = 1;
|
||||
assert(!gamescope::ChooseNestedSwapchainConfig(caps, false, 1280, 720, config));
|
||||
|
||||
using gamescope::ChooseNestedSDRCopySurfaceFormat;
|
||||
const VkSurfaceFormatKHR rgba = {
|
||||
VK_FORMAT_R8G8B8A8_UNORM, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR};
|
||||
const VkSurfaceFormatKHR bgra = {
|
||||
VK_FORMAT_B8G8R8A8_UNORM, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR};
|
||||
uint32_t surfaceFormat = UINT32_MAX;
|
||||
|
||||
// PowerVR SDR copy output needs the RGBA view matching the rgba8 shader.
|
||||
const VkSurfaceFormatKHR bgraFirst[] = {bgra, rgba, rgba};
|
||||
assert(ChooseNestedSDRCopySurfaceFormat(0x1010, true, false,
|
||||
bgraFirst, 3, surfaceFormat));
|
||||
assert(surfaceFormat == 1);
|
||||
const VkSurfaceFormatKHR rgbaFirst[] = {rgba, bgra};
|
||||
assert(ChooseNestedSDRCopySurfaceFormat(0x1010, true, false,
|
||||
rgbaFirst, 2, surfaceFormat));
|
||||
assert(surfaceFormat == 0);
|
||||
assert(ChooseNestedSDRCopySurfaceFormat(0x1010, true, false,
|
||||
&rgba, 1, surfaceFormat));
|
||||
assert(surfaceFormat == 0);
|
||||
|
||||
// Reusing a successful index must not hide a missing compatible format.
|
||||
assert(!ChooseNestedSDRCopySurfaceFormat(0x1010, true, false,
|
||||
&bgra, 1, surfaceFormat));
|
||||
assert(surfaceFormat == 1);
|
||||
const VkSurfaceFormatKHR wrongColorSpace = {
|
||||
VK_FORMAT_R8G8B8A8_UNORM, VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT};
|
||||
assert(!ChooseNestedSDRCopySurfaceFormat(0x1010, true, false,
|
||||
&wrongColorSpace, 1, surfaceFormat));
|
||||
assert(surfaceFormat == 1);
|
||||
const VkSurfaceFormatKHR srgbFormat = {
|
||||
VK_FORMAT_R8G8B8A8_SRGB, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR};
|
||||
assert(!ChooseNestedSDRCopySurfaceFormat(0x1010, true, false,
|
||||
&srgbFormat, 1, surfaceFormat));
|
||||
assert(surfaceFormat == 1);
|
||||
const VkSurfaceFormatKHR compatibleLast[] = {wrongColorSpace, srgbFormat, rgba};
|
||||
assert(ChooseNestedSDRCopySurfaceFormat(0x1010, true, false,
|
||||
compatibleLast, 3, surfaceFormat));
|
||||
assert(surfaceFormat == 2);
|
||||
assert(!ChooseNestedSDRCopySurfaceFormat(0x1010, true, false,
|
||||
nullptr, 0, surfaceFormat));
|
||||
assert(surfaceFormat == 0);
|
||||
|
||||
// The existing selector still owns HDR, direct output, and other vendors.
|
||||
// Each call clears a stale index even when BGRA is the only advertised format.
|
||||
surfaceFormat = 0;
|
||||
assert(ChooseNestedSDRCopySurfaceFormat(0x1010, true, true,
|
||||
&bgra, 1, surfaceFormat));
|
||||
assert(surfaceFormat == 1);
|
||||
surfaceFormat = 0;
|
||||
assert(ChooseNestedSDRCopySurfaceFormat(0x1010, false, false,
|
||||
&bgra, 1, surfaceFormat));
|
||||
assert(surfaceFormat == 1);
|
||||
surfaceFormat = 0;
|
||||
assert(ChooseNestedSDRCopySurfaceFormat(0x5143, true, false,
|
||||
&bgra, 1, surfaceFormat));
|
||||
assert(surfaceFormat == 1);
|
||||
|
||||
// Retry only the device/format/layout/flag combination reproduced on PowerVR.
|
||||
using gamescope::RetryPowerVRLinearQuery;
|
||||
assert(RetryPowerVRLinearQuery(0x1010, VK_FORMAT_B8G8R8A8_UNORM, 0, 1,
|
||||
VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT, VK_ERROR_FORMAT_NOT_SUPPORTED));
|
||||
assert(RetryPowerVRLinearQuery(0x1010, VK_FORMAT_R8G8B8A8_UNORM, 0, 1,
|
||||
VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT, VK_ERROR_FORMAT_NOT_SUPPORTED));
|
||||
assert(!RetryPowerVRLinearQuery(0x5143, VK_FORMAT_B8G8R8A8_UNORM, 0, 1,
|
||||
VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT, VK_ERROR_FORMAT_NOT_SUPPORTED));
|
||||
assert(!RetryPowerVRLinearQuery(0x1010, VK_FORMAT_B8G8R8A8_UNORM, 1, 1,
|
||||
VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT, VK_ERROR_FORMAT_NOT_SUPPORTED));
|
||||
assert(!RetryPowerVRLinearQuery(0x1010, VK_FORMAT_B8G8R8A8_UNORM, 0, 2,
|
||||
VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT, VK_ERROR_FORMAT_NOT_SUPPORTED));
|
||||
assert(!RetryPowerVRLinearQuery(0x1010, VK_FORMAT_R16G16B16A16_SFLOAT, 0, 1,
|
||||
VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT, VK_ERROR_FORMAT_NOT_SUPPORTED));
|
||||
assert(!RetryPowerVRLinearQuery(0x1010, VK_FORMAT_B8G8R8A8_UNORM, 0, 1,
|
||||
0, VK_ERROR_FORMAT_NOT_SUPPORTED));
|
||||
assert(!RetryPowerVRLinearQuery(0x1010, VK_FORMAT_B8G8R8A8_UNORM, 0, 1,
|
||||
VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT, VK_ERROR_DEVICE_LOST));
|
||||
|
||||
VkPhysicalDeviceMemoryProperties memory = {};
|
||||
memory.memoryTypeCount = 3;
|
||||
memory.memoryTypes[0].propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
||||
memory.memoryTypes[1].propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
||||
memory.memoryTypes[2].propertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
|
||||
using gamescope::DmabufMemoryType;
|
||||
assert(DmabufMemoryType(memory, 7, 6, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == 1);
|
||||
assert(DmabufMemoryType(memory, 7, 4, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == 2);
|
||||
assert(DmabufMemoryType(memory, 1, 6, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == UINT32_MAX);
|
||||
assert(DmabufMemoryType(memory, 7, 0, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == UINT32_MAX);
|
||||
assert(DmabufMemoryType(memory, 7, 4, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
|
||||
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) == UINT32_MAX);
|
||||
std::puts("Gamescope presentation and DMA-BUF import tests passed");
|
||||
}
|
||||
Executable
+51
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env bash
|
||||
# CI-only full libhybris build, using the upstream pinned cross-toolchain recipe.
|
||||
set -euo pipefail
|
||||
root=$(cd "$(dirname "$0")/../.." && pwd)
|
||||
out=${1:?output directory required}
|
||||
mkdir -p "$out"
|
||||
out=$(cd "$out" && pwd)
|
||||
. "$root/tools/hybris/source.env"
|
||||
work=$(mktemp -d "${TMPDIR:-/tmp}/droiddeck-hybris.XXXXXX")
|
||||
trap 'rm -rf "$work"' EXIT
|
||||
fetch() {
|
||||
git init -q "$3"
|
||||
git -C "$3" fetch --depth=1 "$1" "$2"
|
||||
git -C "$3" checkout -q --detach FETCH_HEAD
|
||||
test "$(git -C "$3" rev-parse HEAD)" = "$2"
|
||||
}
|
||||
fetch https://github.com/taowen/libhybris.git "$HYBRIS_REVISION" "$work/libhybris"
|
||||
fetch https://github.com/taowen/arlinux-rootfs.git "$PROTOCOL_REVISION" "$work/rootfs"
|
||||
git -C "$work/libhybris" apply --check "$root/tools/hybris/powervr-hal-version.patch"
|
||||
git -C "$work/libhybris" apply "$root/tools/hybris/powervr-hal-version.patch"
|
||||
for patch in "$root"/tools/hybris/patches/*.patch; do
|
||||
git -C "$work/libhybris" apply --check "$patch"
|
||||
git -C "$work/libhybris" apply "$patch"
|
||||
done
|
||||
export ARLINUX_WSI_PROTOCOL_DIR="$work/rootfs/graphics-protocols"
|
||||
export CONTAINER_ENGINE=podman
|
||||
"$work/libhybris/tools/build-aarch64.sh" --out "$work/build"
|
||||
|
||||
mkdir -p "$work/package/lib" "$work/package/licenses"
|
||||
cp -a "$work/build/install/usr/lib/hybris/." "$work/package/lib/"
|
||||
find "$work/package/lib" -name '*.la' -delete
|
||||
rm -rf "$work/package/lib/include" "$work/package/lib/pkgconfig" "$work/package/lib/bin"
|
||||
# Resolve the wrapper's private dependencies without putting its EGL/Vulkan frontends
|
||||
# on the session's LD_LIBRARY_PATH. The Linux runtime keeps owning its Mesa loader.
|
||||
while IFS= read -r -d '' library; do
|
||||
patchelf --set-rpath '$ORIGIN:$ORIGIN/../..' "$library"
|
||||
done < <(find "$work/package/lib" -type f -name '*.so*' -print0)
|
||||
for library in libhybris-vulkan-icd.so.0 libhybris-common.so.1 libVkLayer_hybris_compat.so libhybris/linker/q.so; do
|
||||
test -s "$work/package/lib/$library"
|
||||
done
|
||||
cp "$work/libhybris"/LICENSE.* "$work/package/licenses/"
|
||||
cp "$work/build/manifest.json" "$work/package/build-manifest.json"
|
||||
printf '%s\n' "$HYBRIS_REVISION" > "$work/package/source-commit"
|
||||
# Ship the exact patched source and protocol license with the runtime.
|
||||
git -C "$work/libhybris" diff > "$work/package/licenses/powervr.patch"
|
||||
git -C "$work/libhybris" archive HEAD | zstd -T0 -q -o "$work/package/licenses/libhybris-source.tar.zst"
|
||||
cp "$ARLINUX_WSI_PROTOCOL_DIR/wayland-android.xml" "$work/package/licenses/"
|
||||
(cd "$work/package" && find lib -type f -print0 | sort -z | xargs -0 sha256sum > SHA256SUMS)
|
||||
tar --zstd -cf "$out/runtime.tzst" -C "$work/package" .
|
||||
sha256sum "$out/runtime.tzst" | cut -d' ' -f1 > "$out/version.txt"
|
||||
printf 'Built libhybris %s for Android HAL access from AArch64 Linux\n' "$HYBRIS_REVISION"
|
||||
@@ -0,0 +1,99 @@
|
||||
# Opt-in device-backed low mappings for Wine WoW64
|
||||
|
||||
On the tested Pixel PowerVR stack, Vulkan maps host-visible GPU allocations
|
||||
above 4 GiB. Wine's 32-bit WoW64 Vulkan bridge rejects those pointers. This
|
||||
caused American Nightmare (202750) to stop at D3D9 vertex-buffer creation even
|
||||
after the separate PowerVR BC texture profile passed device initialization.
|
||||
|
||||
`low32.c` is an experimental native Linux/glibc preload adapter. It is off by
|
||||
default. It applies only to anonymous-address, non-executable `MAP_SHARED`
|
||||
mappings of one explicitly selected character device. It retains the original
|
||||
device FD, offset, protection, flags, and actual GPU backing, and searches low
|
||||
address space with `MAP_FIXED_NOREPLACE`. It never truncates a pointer, copies
|
||||
into shadow storage, replaces existing mappings, or disables Wine's guard.
|
||||
Caller-specified/fixed mappings, regular files, private/anonymous memory and
|
||||
other devices retain their original behavior. Failure to find a suitable low
|
||||
hole fails with ENOMEM. The mmap and mmap64 preload chains are independently
|
||||
resolved and called through their respective RTLD_NEXT symbols;
|
||||
only resolver bootstrap uses the raw syscall. A compact atomic cursor avoids
|
||||
wasting large address slots on thousands of small driver control allocations.
|
||||
If the compact probe collides, a bounded address-range walk of
|
||||
/proc/self/maps finds page-sized holes and uses NOREPLACE again to handle races.
|
||||
The walk runs before coarse fallback, so small allocations do not fragment
|
||||
large available ranges. A game load had 2.3 GB free below 4 GiB but no hole as large as 4 MiB; the
|
||||
coarse-only version falsely failed even 4 KiB mappings. Mapping failures are
|
||||
reported even after the ordinary 256-event trace limit.
|
||||
|
||||
## Build and verify
|
||||
|
||||
Use a native 64-bit Linux/glibc compiler, not the Android NDK or macOS compiler:
|
||||
|
||||
```sh
|
||||
tools/hybris/low32/build.sh /absolute/build-dir /path/to/Vulkan-Headers/include
|
||||
```
|
||||
|
||||
The native library and unit test are always built. GPU probes are optional when
|
||||
headers are provided; `gpu-copy-native` uses the selected native host compiler
|
||||
and has the host's architecture, while the Windows x86 probe also needs
|
||||
i686-w64-mingw32-gcc. Copy a native probe to a device only when their architectures match.
|
||||
The unit test uses /dev/zero and proves CPU data integrity, collision handling,
|
||||
concurrency, 2000 simultaneous small mappings, invalid offsets, forwarding and
|
||||
opt-out. A fragmented-address-space regression reserves the low region, opens
|
||||
64 off-grid page holes, and verifies all 64 mappings and their data. The old
|
||||
coarse adapter fails that regression; the address-range fallback passes. An
|
||||
additional density regression fills 64 existing page holes while preserving a
|
||||
separate contiguous 16 MiB interval for a later complete data-readback map; the
|
||||
prior gap-after-coarse implementation fails and the gap-first strategy passes. These
|
||||
CPU tests do not by themselves prove GPU correctness.
|
||||
The build also tests both preload orders with a second library that hooks mmap
|
||||
and mmap64 independently. Opt-out, tracing and adaptation must each preserve
|
||||
the selected symbol's chain, invalid-offset errno and file offsets above 4 GiB.
|
||||
|
||||
`gpu-copy.c` tests actual Vulkan transfer operations on vendor 0x1010. It maps
|
||||
two 32 MiB device allocations, runs four copies of full deterministic patterns,
|
||||
including offset/unmap/remap, uses flush/invalidate and barriers/fences, and
|
||||
compares every word. It can require each full CPU range to fit below 4 GiB:
|
||||
|
||||
```sh
|
||||
./gpu-copy-native 32 --require-low32
|
||||
# Through a separate Proton ARM64/WoW64 test prefix:
|
||||
proton run gpu-copy-x86.exe 32 --require-low32 'Z:\path\probe-output.txt'
|
||||
```
|
||||
|
||||
The Windows output file avoids Wine's detached console hiding probe results.
|
||||
Run with Khronos synchronization validation. Keep raw Steam/account logs local;
|
||||
export only controlled PROBE results, validation IDs and counts. The tested
|
||||
memory type was device-local, host-visible and coherent; noncoherent physical
|
||||
memory is not covered by that run.
|
||||
|
||||
## Activation scope
|
||||
|
||||
Set only the target game's overrides, after identifying the render device's
|
||||
`st_rdev` and validating the installed library's hash:
|
||||
|
||||
```text
|
||||
LD_PRELOAD=/absolute/guest/path/libdroiddeck-low32.so
|
||||
DROIDDECK_LOW32_MODE=low32
|
||||
DROIDDECK_LOW32_RDEV=<verified decimal st_rdev>
|
||||
```
|
||||
|
||||
Preserve any existing target-game preload rather than replacing it. The tested
|
||||
Pixel's /dev/dri/renderD128 was character device major 226/minor 128, st_rdev 57984.
|
||||
Do not hardcode that value for other machines. BC emulation and the repaired
|
||||
DXVK presentation component remain separate prerequisites; this adapter does
|
||||
not implement them. No global Steam profile, managed graphics pack, Android
|
||||
security setting or unrelated game's overrides should change.
|
||||
|
||||
Before activating, back up the exact game-environment bytes and only the target
|
||||
prefix's graphics DLLs, preserving symlinks. Rollback must check for concurrent
|
||||
edits. Keep original backups in the app; do not copy account files or an entire
|
||||
Steam prefix to a report. Removing these three overrides disables the adapter.
|
||||
|
||||
## Compatibility limits
|
||||
|
||||
This initial binary was built on Ubuntu 24.04 ARM64 and needs glibc 2.38. The
|
||||
tested guest supports it. This is not yet a universal runtime component; other
|
||||
glibc versions, page sizes, drivers, GPU families, native 32-bit processes and
|
||||
general game stability require their own tests. Bounded native and Windows GPU
|
||||
copies prove data integrity for those workloads, not unrestricted gameplay.
|
||||
Never enable globally based on successful testing of one game.
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
# Run on native 64-bit Linux/glibc. This is not an Android/Bionic library.
|
||||
base=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
output=${1:?usage: build.sh /absolute/build-directory [Vulkan-header-directory]}
|
||||
mkdir -p "$output"
|
||||
cc=${CC:-cc}
|
||||
"$cc" -std=gnu11 -Wall -Wextra -Werror -O2 -fPIC -shared -s \
|
||||
"$base/low32.c" -ldl -o "$output/libdroiddeck-low32.so"
|
||||
"$cc" -std=gnu11 -Wall -Wextra -Werror -O2 "$base/test-low32.c" -pthread -o "$output/test-low32"
|
||||
LD_PRELOAD="$output/libdroiddeck-low32.so" "$output/test-low32"
|
||||
"$cc" -std=gnu11 -Wall -Wextra -Werror -O2 -fPIC -shared \
|
||||
"$base/test-chain-hook.c" -ldl -o "$output/test-chain-hook.so"
|
||||
"$cc" -std=gnu11 -Wall -Wextra -Werror -O2 "$base/test-preload-chain.c" -ldl -o "$output/test-preload-chain"
|
||||
for preloads in "$output/libdroiddeck-low32.so:$output/test-chain-hook.so" \
|
||||
"$output/test-chain-hook.so:$output/libdroiddeck-low32.so"; do
|
||||
for mode in off trace low32; do
|
||||
LD_PRELOAD="$preloads" "$output/test-preload-chain" "$mode"
|
||||
done
|
||||
done
|
||||
if [ "$#" -ge 2 ]; then
|
||||
"$cc" -std=gnu11 -Wall -Wextra -Werror -O2 -s -I"$2" "$base/gpu-copy.c" -ldl -o "$output/gpu-copy-native"
|
||||
if command -v i686-w64-mingw32-gcc >/dev/null 2>&1; then
|
||||
i686-w64-mingw32-gcc -std=gnu11 -Wall -Wextra -Werror -O2 -s -I"$2" \
|
||||
"$base/gpu-copy.c" -o "$output/gpu-copy-x86.exe"
|
||||
fi
|
||||
fi
|
||||
@@ -0,0 +1,166 @@
|
||||
/* Same standalone GPU-copy probe built as Linux AArch64 and Windows x86.
|
||||
* Tests actual Vulkan buffers, complete data comparison, noncoherent cache
|
||||
* operations, remapping with an offset and queue completion. No Steam API.
|
||||
*/
|
||||
#define VK_NO_PROTOTYPES
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
#define IFNS(X) X(DestroyInstance) X(EnumeratePhysicalDevices) X(GetPhysicalDeviceProperties) \
|
||||
X(GetPhysicalDeviceMemoryProperties) X(GetPhysicalDeviceQueueFamilyProperties) X(CreateDevice) X(GetDeviceProcAddr)
|
||||
#define DFNS(X) X(DestroyDevice) X(GetDeviceQueue) X(CreateBuffer) X(DestroyBuffer) \
|
||||
X(GetBufferMemoryRequirements) X(AllocateMemory) X(FreeMemory) X(BindBufferMemory) \
|
||||
X(MapMemory) X(UnmapMemory) X(FlushMappedMemoryRanges) X(InvalidateMappedMemoryRanges) \
|
||||
X(CreateCommandPool) X(DestroyCommandPool) X(AllocateCommandBuffers) X(ResetCommandBuffer) \
|
||||
X(BeginCommandBuffer) X(EndCommandBuffer) X(CmdCopyBuffer) X(CmdPipelineBarrier) \
|
||||
X(CreateFence) X(DestroyFence) X(ResetFences) X(QueueSubmit) X(WaitForFences)
|
||||
#define DECL(n) static PFN_vk##n p##n;
|
||||
IFNS(DECL)
|
||||
DFNS(DECL)
|
||||
#undef DECL
|
||||
#define CHECK(x) do { VkResult rc=(x); if(rc!=VK_SUCCESS){printf("PROBE_FAIL stage=%s vk_result=%d\n",#x,rc);goto cleanup;} }while(0)
|
||||
#define REQUIRE(x,msg) do {if(!(x)){puts("PROBE_FAIL " msg);goto cleanup;}}while(0)
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
/* Wine/Proton can detach the Windows console from the Linux pipe. */
|
||||
if(argc>3 && !freopen(argv[3],"w",stdout)) return 4;
|
||||
#endif
|
||||
setvbuf(stdout,NULL,_IONBF,0);
|
||||
puts("PROBE_STAGE main");
|
||||
unsigned mib=argc>1?(unsigned)strtoul(argv[1],NULL,10):32;
|
||||
int require_low=argc>2&&!strcmp(argv[2],"--require-low32");
|
||||
if(mib<1||mib>256)return 2;
|
||||
const VkDeviceSize bytes=(VkDeviceSize)mib*1024*1024;
|
||||
VkInstance instance=VK_NULL_HANDLE;VkDevice device=VK_NULL_HANDLE;
|
||||
VkBuffer buffers[2]={0};VkDeviceMemory memories[2]={0};
|
||||
VkDeviceSize allocated[2]={0};void *mapped[2]={0};
|
||||
VkCommandPool pool=VK_NULL_HANDLE;VkFence fence=VK_NULL_HANDLE;
|
||||
int success=0,pending=0;uint64_t mismatches=0;unsigned iterations=0;
|
||||
int low_all=1;uint32_t memory_flags[2]={0};
|
||||
PFN_vkGetInstanceProcAddr gipa;
|
||||
#ifdef _WIN32
|
||||
HMODULE loader=LoadLibraryA("vulkan-1.dll");
|
||||
REQUIRE(loader,"load_vulkan_failed");
|
||||
gipa=(PFN_vkGetInstanceProcAddr)(void *)GetProcAddress(loader,"vkGetInstanceProcAddr");
|
||||
#else
|
||||
void *loader=dlopen("libvulkan.so.1",RTLD_NOW|RTLD_LOCAL);
|
||||
REQUIRE(loader,"load_vulkan_failed");
|
||||
gipa=(PFN_vkGetInstanceProcAddr)dlsym(loader,"vkGetInstanceProcAddr");
|
||||
#endif
|
||||
REQUIRE(gipa,"missing_gipa");
|
||||
puts("PROBE_STAGE vulkan_loader");
|
||||
PFN_vkCreateInstance create=(PFN_vkCreateInstance)gipa(NULL,"vkCreateInstance");
|
||||
REQUIRE(create,"missing_create_instance");
|
||||
VkApplicationInfo app={.sType=VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
||||
.pApplicationName="DroidDeck low32 buffer integrity probe",.apiVersion=VK_API_VERSION_1_1};
|
||||
VkInstanceCreateInfo ici={.sType=VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,.pApplicationInfo=&app};
|
||||
CHECK(create(&ici,NULL,&instance));
|
||||
puts("PROBE_STAGE instance_created");
|
||||
#define LOADI(n) p##n=(PFN_vk##n)gipa(instance,"vk" #n);REQUIRE(p##n,"missing_" #n);
|
||||
IFNS(LOADI)
|
||||
#undef LOADI
|
||||
uint32_t count=0;CHECK(pEnumeratePhysicalDevices(instance,&count,NULL));
|
||||
puts("PROBE_STAGE physical_device_enumeration");
|
||||
REQUIRE(count&&count<=16,"physical_device_count");
|
||||
VkPhysicalDevice physicals[16],physical=VK_NULL_HANDLE;
|
||||
CHECK(pEnumeratePhysicalDevices(instance,&count,physicals));
|
||||
VkPhysicalDeviceProperties properties;
|
||||
for(uint32_t i=0;i<count;i++){
|
||||
pGetPhysicalDeviceProperties(physicals[i],&properties);
|
||||
if(properties.vendorID==0x1010&&properties.deviceType!=VK_PHYSICAL_DEVICE_TYPE_CPU){physical=physicals[i];break;}
|
||||
}
|
||||
REQUIRE(physical,"no_real_powervr");
|
||||
printf("PROBE_DEVICE vendor=%x device=%x api=%x pointer_bits=%zu\n",
|
||||
properties.vendorID,properties.deviceID,properties.apiVersion,sizeof(void *)*8);
|
||||
uint32_t qcount=0;pGetPhysicalDeviceQueueFamilyProperties(physical,&qcount,NULL);
|
||||
REQUIRE(qcount&&qcount<=64,"queue_count");
|
||||
VkQueueFamilyProperties qp[64];pGetPhysicalDeviceQueueFamilyProperties(physical,&qcount,qp);
|
||||
uint32_t family=UINT32_MAX;
|
||||
for(uint32_t i=0;i<qcount;i++)if(qp[i].queueCount&&(qp[i].queueFlags&VK_QUEUE_GRAPHICS_BIT)){family=i;break;}
|
||||
REQUIRE(family!=UINT32_MAX,"no_graphics_queue");float priority=1.0f;
|
||||
VkDeviceQueueCreateInfo qci={.sType=VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,.queueFamilyIndex=family,.queueCount=1,.pQueuePriorities=&priority};
|
||||
VkDeviceCreateInfo dci={.sType=VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,.queueCreateInfoCount=1,.pQueueCreateInfos=&qci};
|
||||
CHECK(pCreateDevice(physical,&dci,NULL,&device));
|
||||
#define LOADD(n) p##n=(PFN_vk##n)pGetDeviceProcAddr(device,"vk" #n);REQUIRE(p##n,"missing_" #n);
|
||||
DFNS(LOADD)
|
||||
#undef LOADD
|
||||
VkPhysicalDeviceMemoryProperties mp;pGetPhysicalDeviceMemoryProperties(physical,&mp);
|
||||
for(unsigned j=0;j<2;j++){
|
||||
VkBufferCreateInfo bci={.sType=VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,.size=bytes,
|
||||
.usage=VK_BUFFER_USAGE_TRANSFER_SRC_BIT|VK_BUFFER_USAGE_TRANSFER_DST_BIT,.sharingMode=VK_SHARING_MODE_EXCLUSIVE};
|
||||
CHECK(pCreateBuffer(device,&bci,NULL,&buffers[j]));VkMemoryRequirements mr;
|
||||
pGetBufferMemoryRequirements(device,buffers[j],&mr);
|
||||
uint32_t type=UINT32_MAX;
|
||||
for(uint32_t i=0;i<mp.memoryTypeCount;i++)if((mr.memoryTypeBits&(1u<<i))&&(mp.memoryTypes[i].propertyFlags&VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)){type=i;break;}
|
||||
REQUIRE(type!=UINT32_MAX,"no_host_visible_memory");memory_flags[j]=mp.memoryTypes[type].propertyFlags;
|
||||
VkMemoryAllocateInfo mai={.sType=VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,.allocationSize=mr.size,.memoryTypeIndex=type};
|
||||
allocated[j]=mr.size;CHECK(pAllocateMemory(device,&mai,NULL,&memories[j]));
|
||||
CHECK(pBindBufferMemory(device,buffers[j],memories[j],0));
|
||||
}
|
||||
VkCommandPoolCreateInfo pci={.sType=VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
|
||||
.flags=VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,.queueFamilyIndex=family};
|
||||
CHECK(pCreateCommandPool(device,&pci,NULL,&pool));VkCommandBuffer command;
|
||||
VkCommandBufferAllocateInfo cai={.sType=VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
|
||||
.commandPool=pool,.level=VK_COMMAND_BUFFER_LEVEL_PRIMARY,.commandBufferCount=1};
|
||||
CHECK(pAllocateCommandBuffers(device,&cai,&command));
|
||||
VkFenceCreateInfo fci={.sType=VK_STRUCTURE_TYPE_FENCE_CREATE_INFO};
|
||||
CHECK(pCreateFence(device,&fci,NULL,&fence));VkQueue queue;pGetDeviceQueue(device,family,0,&queue);
|
||||
for(unsigned k=0;k<4;k++){
|
||||
/* Alternate full mapping and a 64KiB aligned offset, preserving every word. */
|
||||
VkDeviceSize offset=(k&1)?65536:0,span=bytes-offset;
|
||||
for(unsigned j=0;j<2;j++){
|
||||
CHECK(pMapMemory(device,memories[j],offset,VK_WHOLE_SIZE,0,&mapped[j]));
|
||||
int low=(uint64_t)(uintptr_t)mapped[j]+(allocated[j]-offset)<=UINT64_C(0x100000000);
|
||||
low_all&=low;
|
||||
printf("PROBE_MAP iteration=%u buffer=%u offset=%" PRIu64 " bytes=%" PRIu64 " ptr=%p low32=%d flags=%x\n",
|
||||
k,j,(uint64_t)offset,(uint64_t)(allocated[j]-offset),mapped[j],low,memory_flags[j]);
|
||||
REQUIRE(!require_low||low,"mapping_not_low32");
|
||||
}
|
||||
uint32_t *src=mapped[0],*dst=mapped[1];size_t words=(size_t)(span/4);
|
||||
for(size_t i=0;i<words;i++){src[i]=((uint32_t)i*2654435761u)^(0xa5a50000u+k);dst[i]=0;}
|
||||
VkMappedMemoryRange ranges[2];memset(ranges,0,sizeof(ranges));
|
||||
for(unsigned j=0;j<2;j++)ranges[j]=(VkMappedMemoryRange){.sType=VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,.memory=memories[j],.offset=offset,.size=VK_WHOLE_SIZE};
|
||||
CHECK(pFlushMappedMemoryRanges(device,2,ranges));
|
||||
if(k){CHECK(pResetFences(device,1,&fence));CHECK(pResetCommandBuffer(command,0));}
|
||||
VkCommandBufferBeginInfo cbi={.sType=VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,.flags=VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT};
|
||||
CHECK(pBeginCommandBuffer(command,&cbi));
|
||||
VkMemoryBarrier before={.sType=VK_STRUCTURE_TYPE_MEMORY_BARRIER,.srcAccessMask=VK_ACCESS_HOST_WRITE_BIT,.dstAccessMask=VK_ACCESS_TRANSFER_READ_BIT|VK_ACCESS_TRANSFER_WRITE_BIT};
|
||||
pCmdPipelineBarrier(command,VK_PIPELINE_STAGE_HOST_BIT,VK_PIPELINE_STAGE_TRANSFER_BIT,0,1,&before,0,NULL,0,NULL);
|
||||
VkBufferCopy copy={.srcOffset=offset,.dstOffset=offset,.size=span};pCmdCopyBuffer(command,buffers[0],buffers[1],1,©);
|
||||
VkMemoryBarrier after={.sType=VK_STRUCTURE_TYPE_MEMORY_BARRIER,.srcAccessMask=VK_ACCESS_TRANSFER_WRITE_BIT,.dstAccessMask=VK_ACCESS_HOST_READ_BIT};
|
||||
pCmdPipelineBarrier(command,VK_PIPELINE_STAGE_TRANSFER_BIT,VK_PIPELINE_STAGE_HOST_BIT,0,1,&after,0,NULL,0,NULL);
|
||||
CHECK(pEndCommandBuffer(command));VkSubmitInfo si={.sType=VK_STRUCTURE_TYPE_SUBMIT_INFO,.commandBufferCount=1,.pCommandBuffers=&command};
|
||||
CHECK(pQueueSubmit(queue,1,&si,fence));pending=1;
|
||||
VkResult waited=pWaitForFences(device,1,&fence,VK_TRUE,UINT64_C(10000000000));
|
||||
if(waited!=VK_SUCCESS){printf("PROBE_FAIL GPU_COMPLETION_UNCONFIRMED result=%d\n",waited);goto cleanup;}
|
||||
pending=0;CHECK(pInvalidateMappedMemoryRanges(device,1,&ranges[1]));
|
||||
for(size_t i=0;i<words;i++)if(dst[i]!=(((uint32_t)i*2654435761u)^(0xa5a50000u+k)))mismatches++;
|
||||
for(unsigned j=0;j<2;j++){pUnmapMemory(device,memories[j]);mapped[j]=NULL;}
|
||||
iterations++;REQUIRE(!mismatches,"data_mismatch");
|
||||
}
|
||||
success=1;
|
||||
cleanup:
|
||||
printf("PROBE_RESULT success=%d mib=%u iterations=%u mismatches=%" PRIu64 " all_mappings_low32=%d\n",success,mib,iterations,mismatches,low_all);
|
||||
if(pending)return 3; /* Do not explicitly destroy objects with unknown GPU completion. */
|
||||
if(device){
|
||||
if(pUnmapMemory)for(unsigned j=0;j<2;j++)if(mapped[j])pUnmapMemory(device,memories[j]);
|
||||
if(fence&&pDestroyFence)pDestroyFence(device,fence,NULL);
|
||||
if(pool&&pDestroyCommandPool)pDestroyCommandPool(device,pool,NULL);
|
||||
for(unsigned j=0;j<2;j++)if(buffers[j]&&pDestroyBuffer)pDestroyBuffer(device,buffers[j],NULL);
|
||||
for(unsigned j=0;j<2;j++)if(memories[j]&&pFreeMemory)pFreeMemory(device,memories[j],NULL);
|
||||
if(pDestroyDevice)pDestroyDevice(device,NULL);
|
||||
}
|
||||
if(instance&&pDestroyInstance)pDestroyInstance(instance,NULL);
|
||||
return success?0:1;
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
/* Experimental per-process PowerVR device-backed low-address mmap adapter.
|
||||
* No copied/shadow memory, changed device offset or MAP_FIXED replacement.
|
||||
* Default is off. Enable only for the identified render-device rdev and the
|
||||
* target x86/WoW64 game. Native 64-bit Linux/glibc preload, not an Android ABI DLL.
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#define _LARGEFILE64_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef MAP_FIXED_NOREPLACE
|
||||
#define MAP_FIXED_NOREPLACE 0x100000
|
||||
#endif
|
||||
|
||||
static _Atomic uint64_t cursor;
|
||||
static _Atomic unsigned logged;
|
||||
typedef void *(*map_function)(void *,size_t,int,int,int,off_t);
|
||||
typedef void *(*map64_function)(void *,size_t,int,int,int,off64_t);
|
||||
static _Atomic(map_function) next_map;
|
||||
static _Atomic(map64_function) next_map64;
|
||||
_Static_assert(sizeof(off_t) == sizeof(off64_t) && sizeof(off_t) == 8,
|
||||
"64-bit host required");
|
||||
static __thread int resolving __attribute__((tls_model("initial-exec")));
|
||||
static __thread int active __attribute__((tls_model("initial-exec")));
|
||||
static void *native_map(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
|
||||
{
|
||||
map_function next=atomic_load(&next_map);
|
||||
if (!next && !resolving) {
|
||||
resolving=1;
|
||||
next=(map_function)dlsym(RTLD_NEXT,"mmap");
|
||||
atomic_store(&next_map,next);
|
||||
resolving=0;
|
||||
}
|
||||
/* Bootstrap only while resolving; otherwise preserve existing preload hooks. */
|
||||
if (next) return next(addr,length,prot,flags,fd,offset);
|
||||
return (void *)syscall(SYS_mmap, addr, length, prot, flags, fd, offset);
|
||||
}
|
||||
|
||||
static void *native_map64(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
|
||||
{
|
||||
map64_function next=atomic_load(&next_map64);
|
||||
if (!next && !resolving) {
|
||||
resolving=1;
|
||||
next=(map64_function)dlsym(RTLD_NEXT,"mmap64");
|
||||
atomic_store(&next_map64,next);
|
||||
resolving=0;
|
||||
}
|
||||
if (next) return next(addr,length,prot,flags,fd,(off64_t)offset);
|
||||
return (void *)syscall(SYS_mmap, addr, length, prot, flags, fd, offset);
|
||||
}
|
||||
|
||||
static void trace_map(const char *kind, size_t n, int prot, int flags, int fd,
|
||||
off_t off, const struct stat *st, void *p, int error)
|
||||
{
|
||||
int saved = errno;
|
||||
unsigned count = atomic_fetch_add(&logged, 1);
|
||||
if (count < 256 || error != 0) {
|
||||
char text[320];
|
||||
int nbytes = snprintf(text, sizeof(text),
|
||||
"DD_LOW32 %s pid=%ld len=%zu prot=%x flags=%x fd=%d off=%jd mode=%o rdev=%ju ptr=%p errno=%d\n",
|
||||
kind, (long)getpid(), n, prot, flags, fd, (intmax_t)off, st ? st->st_mode : 0,
|
||||
st ? (uintmax_t)st->st_rdev : 0, p, error);
|
||||
if (nbytes > 0) {
|
||||
ssize_t written = write(STDERR_FILENO, text,
|
||||
(size_t)nbytes < sizeof(text) ? (size_t)nbytes : sizeof(text)-1);
|
||||
(void)written;
|
||||
}
|
||||
}
|
||||
errno = saved;
|
||||
}
|
||||
|
||||
static int target_device(int fd, struct stat *st)
|
||||
{
|
||||
const char *value = getenv("DROIDDECK_LOW32_RDEV");
|
||||
char *end = NULL;
|
||||
if (!value || !*value || fd < 0) return 0;
|
||||
int saved = errno;
|
||||
errno = 0;
|
||||
uintmax_t expected = strtoumax(value, &end, 10);
|
||||
int valid = !errno && end && !*end && expected > 0 &&
|
||||
fstat(fd, st) == 0 && S_ISCHR(st->st_mode) &&
|
||||
(uintmax_t)st->st_rdev == expected;
|
||||
errno = saved;
|
||||
return valid;
|
||||
}
|
||||
|
||||
static void *adapted_map(map_function forward, void *addr, size_t length, int prot,
|
||||
int flags, int fd, off_t offset)
|
||||
{
|
||||
const char *mode = getenv("DROIDDECK_LOW32_MODE");
|
||||
struct stat st = {0};
|
||||
if (mode && !strcmp(mode, "trace")) {
|
||||
void *p = forward(addr, length, prot, flags, fd, offset);
|
||||
if (fd >= 0 && (prot & PROT_WRITE) && !(prot & PROT_EXEC) &&
|
||||
(flags & MAP_TYPE) == MAP_SHARED) {
|
||||
int saved=errno;
|
||||
(void)fstat(fd,&st);
|
||||
errno=saved;
|
||||
trace_map("trace", length, prot, flags, fd, offset, &st, p,
|
||||
p == MAP_FAILED ? errno : 0);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
if (!mode || strcmp(mode, "low32") || addr || !length ||
|
||||
(flags & (MAP_ANONYMOUS | MAP_FIXED | MAP_FIXED_NOREPLACE)) ||
|
||||
(prot & PROT_EXEC) || (flags & MAP_TYPE) != MAP_SHARED ||
|
||||
!target_device(fd, &st))
|
||||
return forward(addr, length, prot, flags, fd, offset);
|
||||
|
||||
const uintptr_t lower = 0x10000000u, upper = 0xffff0000u;
|
||||
const uintptr_t step = 0x00400000u;
|
||||
if (length > upper-lower) {
|
||||
errno = ENOMEM;
|
||||
trace_map("too_large", length, prot, flags, fd, offset, &st, MAP_FAILED, errno);
|
||||
return MAP_FAILED;
|
||||
}
|
||||
long page_value=sysconf(_SC_PAGESIZE);
|
||||
uintptr_t page=page_value>0?(uintptr_t)page_value:4096;
|
||||
uintptr_t rounded=(length+page-1)&~(page-1);
|
||||
uintptr_t span=upper-lower;
|
||||
uintptr_t compact=(uintptr_t)(atomic_fetch_add(&cursor,rounded)%span);
|
||||
if (rounded>span-compact) compact=0;
|
||||
unsigned slots = (unsigned)((span-length)/step)+1;
|
||||
unsigned start = (unsigned)(compact/step)%slots;
|
||||
int original_errno = errno;
|
||||
for (unsigned i = 0; i < 1; i++) {
|
||||
/* Compact first: hundreds of small driver mappings must not waste a
|
||||
* 4MiB address slot each. Coarse search is only for existing Wine holes. */
|
||||
uintptr_t hint = lower + (i==0?compact:(uintptr_t)((start+i-1)%slots)*step);
|
||||
void *p = forward((void *)hint, length, prot,
|
||||
flags|MAP_FIXED_NOREPLACE, fd, offset);
|
||||
if (p != MAP_FAILED) {
|
||||
uintptr_t first = (uintptr_t)p;
|
||||
if (first >= lower && first < upper && length <= upper-first) {
|
||||
errno = original_errno;
|
||||
trace_map("mapped", length, prot, flags, fd, offset, &st, p, 0);
|
||||
return p;
|
||||
}
|
||||
/* Older kernels can ignore NOREPLACE; never return a high mapping. */
|
||||
int saved = errno;
|
||||
(void)syscall(SYS_munmap, p, length);
|
||||
errno = saved;
|
||||
} else if (errno != EEXIST && errno != ENOMEM && errno != EAGAIN) {
|
||||
trace_map("rejected", length, prot, flags, fd, offset, &st, p, errno);
|
||||
return p;
|
||||
}
|
||||
}
|
||||
/* Pack small allocations into address holes before coarse probing can
|
||||
* fragment large holes. Walk
|
||||
* this process's current mappings, then use NOREPLACE to tolerate races.
|
||||
* No pointer paths or contents are read; only address ranges are used. */
|
||||
for (unsigned pass = 0; pass < 2; ++pass) {
|
||||
FILE *maps = fopen("/proc/self/maps", "r");
|
||||
if (!maps) break;
|
||||
char line[512];
|
||||
uintptr_t gap_start = lower;
|
||||
unsigned lines = 0;
|
||||
while (fgets(line, sizeof(line), maps) && ++lines < 65536) {
|
||||
uintptr_t first, last;
|
||||
if (sscanf(line, "%" SCNxPTR "-%" SCNxPTR, &first, &last) != 2) continue;
|
||||
if (last <= gap_start) continue;
|
||||
uintptr_t gap_end = first < upper ? first : upper;
|
||||
if (gap_end > gap_start && rounded <= gap_end - gap_start) {
|
||||
void *p = forward((void *)gap_start, length, prot,
|
||||
flags | MAP_FIXED_NOREPLACE, fd, offset);
|
||||
if (p != MAP_FAILED) {
|
||||
uintptr_t address = (uintptr_t)p;
|
||||
if (address >= lower && address < upper && length <= upper - address) {
|
||||
fclose(maps);
|
||||
errno = original_errno;
|
||||
trace_map("mapped_gap", length, prot, flags, fd, offset, &st, p, 0);
|
||||
return p;
|
||||
}
|
||||
(void)syscall(SYS_munmap, p, length);
|
||||
} else if (errno != EEXIST && errno != ENOMEM && errno != EAGAIN) {
|
||||
int saved = errno;
|
||||
fclose(maps);
|
||||
errno = saved;
|
||||
trace_map("rejected", length, prot, flags, fd, offset, &st, MAP_FAILED, errno);
|
||||
return MAP_FAILED;
|
||||
}
|
||||
}
|
||||
if (last > gap_start) gap_start = last;
|
||||
if (gap_start >= upper) break;
|
||||
}
|
||||
if (gap_start < upper && rounded <= upper - gap_start) {
|
||||
void *p = forward((void *)gap_start, length, prot,
|
||||
flags | MAP_FIXED_NOREPLACE, fd, offset);
|
||||
if (p != MAP_FAILED) {
|
||||
uintptr_t address = (uintptr_t)p;
|
||||
if (address >= lower && address < upper && length <= upper - address) {
|
||||
fclose(maps);
|
||||
errno = original_errno;
|
||||
trace_map("mapped_gap", length, prot, flags, fd, offset, &st, p, 0);
|
||||
return p;
|
||||
}
|
||||
(void)syscall(SYS_munmap, p, length);
|
||||
}
|
||||
}
|
||||
fclose(maps);
|
||||
}
|
||||
for (unsigned i = 1; i <= slots; i++) {
|
||||
/* Last resort if address walking was unavailable or raced. */
|
||||
uintptr_t hint = lower + (i==0?compact:(uintptr_t)((start+i-1)%slots)*step);
|
||||
void *p = forward((void *)hint, length, prot,
|
||||
flags|MAP_FIXED_NOREPLACE, fd, offset);
|
||||
if (p != MAP_FAILED) {
|
||||
uintptr_t first = (uintptr_t)p;
|
||||
if (first >= lower && first < upper && length <= upper-first) {
|
||||
errno = original_errno;
|
||||
trace_map("mapped", length, prot, flags, fd, offset, &st, p, 0);
|
||||
return p;
|
||||
}
|
||||
/* Older kernels can ignore NOREPLACE; never return a high mapping. */
|
||||
int saved = errno;
|
||||
(void)syscall(SYS_munmap, p, length);
|
||||
errno = saved;
|
||||
} else if (errno != EEXIST && errno != ENOMEM && errno != EAGAIN) {
|
||||
trace_map("rejected", length, prot, flags, fd, offset, &st, p, errno);
|
||||
return p;
|
||||
}
|
||||
}
|
||||
errno = ENOMEM;
|
||||
trace_map("no_low_hole", length, prot, flags, fd, offset, &st, MAP_FAILED, errno);
|
||||
return MAP_FAILED;
|
||||
}
|
||||
|
||||
static void *intercept_map(map_function forward, void *addr, size_t length,
|
||||
int prot, int flags, int fd, off_t offset)
|
||||
{
|
||||
if (active) return forward(addr,length,prot,flags,fd,offset);
|
||||
active=1;
|
||||
void *p=adapted_map(forward,addr,length,prot,flags,fd,offset);
|
||||
active=0;
|
||||
return p;
|
||||
}
|
||||
|
||||
void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
|
||||
{
|
||||
return intercept_map(native_map,addr,length,prot,flags,fd,offset);
|
||||
}
|
||||
|
||||
void *mmap64(void *addr, size_t length, int prot, int flags, int fd, off64_t offset)
|
||||
{
|
||||
return intercept_map(native_map64,addr,length,prot,flags,fd,(off_t)offset);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/* Controlled second preload: distinct mmap/mmap64 counters and 64-bit offsets. */
|
||||
#define _GNU_SOURCE
|
||||
#define _LARGEFILE64_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
static int selected_fd = -2;
|
||||
static unsigned calls[2];
|
||||
static int64_t offsets[2];
|
||||
|
||||
void chain_clear(int fd)
|
||||
{
|
||||
selected_fd = fd;
|
||||
calls[0] = calls[1] = 0;
|
||||
offsets[0] = offsets[1] = -1;
|
||||
}
|
||||
|
||||
unsigned chain_calls(unsigned channel) { return calls[channel]; }
|
||||
int64_t chain_offset(unsigned channel) { return offsets[channel]; }
|
||||
|
||||
void *mmap(void *addr, size_t len, int prot, int flags, int fd, off_t off)
|
||||
{
|
||||
static void *(*next)(void *, size_t, int, int, int, off_t);
|
||||
if (!next) next = dlsym(RTLD_NEXT, "mmap");
|
||||
if (fd == selected_fd) { ++calls[0]; offsets[0] = off; }
|
||||
return next(addr, len, prot, flags, fd, off);
|
||||
}
|
||||
|
||||
void *mmap64(void *addr, size_t len, int prot, int flags, int fd, off64_t off)
|
||||
{
|
||||
static void *(*next)(void *, size_t, int, int, int, off64_t);
|
||||
if (!next) next = dlsym(RTLD_NEXT, "mmap64");
|
||||
if (fd == selected_fd) { ++calls[1]; offsets[1] = off; }
|
||||
return next(addr, len, prot, flags, fd, off);
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define N (32u*1024u*1024u)
|
||||
static int zero_fd;
|
||||
static void *thread_test(void *arg)
|
||||
{
|
||||
unsigned seed = (unsigned)(uintptr_t)arg;
|
||||
uint32_t *p = mmap(NULL,N,PROT_READ|PROT_WRITE,MAP_SHARED,zero_fd,0);
|
||||
assert(p != MAP_FAILED && (uintptr_t)p+N <= 0x100000000ull);
|
||||
for (size_t i=0;i<N/4;i++) p[i]=(uint32_t)i^seed;
|
||||
for (size_t i=0;i<N/4;i++) assert(p[i]==((uint32_t)i^seed));
|
||||
assert(!munmap(p,N));
|
||||
return NULL;
|
||||
}
|
||||
int main(void)
|
||||
{
|
||||
zero_fd=open("/dev/zero",O_RDWR|O_CLOEXEC); assert(zero_fd>=0);
|
||||
struct stat st; assert(!fstat(zero_fd,&st)); char value[48];
|
||||
snprintf(value,sizeof(value),"%ju",(uintmax_t)st.st_rdev);
|
||||
assert(!setenv("DROIDDECK_LOW32_RDEV",value,1));
|
||||
assert(!setenv("DROIDDECK_LOW32_MODE","low32",1));
|
||||
/* Existing low-address memory must survive device mappings. */
|
||||
uint32_t *guard=mmap((void *)0x10000000,128u*1024u*1024u,PROT_READ|PROT_WRITE,
|
||||
MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED_NOREPLACE,-1,0);
|
||||
assert(guard==(void *)0x10000000);guard[0]=0xdeadbeef;guard[32767]=0xcafef00d;
|
||||
pthread_t threads[8];
|
||||
for (uintptr_t i=0;i<8;i++) assert(!pthread_create(&threads[i],NULL,thread_test,(void *)i));
|
||||
for (unsigned i=0;i<8;i++) assert(!pthread_join(threads[i],NULL));
|
||||
assert(guard[0]==0xdeadbeef && guard[32767]==0xcafef00d);
|
||||
puts("PASS concurrent 32MiB mappings, full pattern readback and occupied-memory preservation");
|
||||
assert(!munmap(guard,128u*1024u*1024u));
|
||||
/* Caller-specified address and MAP_FIXED semantics are preserved. */
|
||||
void *explicit=mmap((void *)0x30000000,4096,PROT_READ|PROT_WRITE,
|
||||
MAP_SHARED|MAP_FIXED_NOREPLACE,zero_fd,0);
|
||||
assert(explicit==(void *)0x30000000); assert(!munmap(explicit,4096));
|
||||
int mem=memfd_create("low32-nontarget",0);assert(mem>=0);assert(!ftruncate(mem,N));
|
||||
uint32_t *q=mmap((void *)0x500000000ull,N,PROT_READ|PROT_WRITE,MAP_SHARED,mem,0);
|
||||
assert(q==(void *)0x500000000ull);q[0]=123;assert(q[0]==123);assert(!munmap(q,N));close(mem);
|
||||
puts("PASS unrelated regular-file mapping and explicit-address forwarding");
|
||||
errno=0;
|
||||
void *bad=mmap(NULL,4096,PROT_READ|PROT_WRITE,MAP_SHARED,zero_fd,1);
|
||||
assert(bad==MAP_FAILED && errno==EINVAL);
|
||||
puts("PASS invalid device offset retains EINVAL");
|
||||
/* Real game initialization creates many small control/buffer mappings. */
|
||||
void *small[2000];
|
||||
for(unsigned i=0;i<2000;i++) {
|
||||
small[i]=mmap(NULL,4096,PROT_READ|PROT_WRITE,MAP_SHARED,zero_fd,0);
|
||||
assert(small[i]!=MAP_FAILED && (uintptr_t)small[i]+4096<=0x100000000ull);
|
||||
*(uint32_t *)small[i]=i;
|
||||
}
|
||||
for(unsigned i=0;i<2000;i++){
|
||||
assert(*(uint32_t *)small[i]==i);assert(!munmap(small[i],4096));
|
||||
}
|
||||
puts("PASS 2000 simultaneous small mappings without address-slot exhaustion");
|
||||
/* A fragmented Wine address space has usable holes away from every
|
||||
* 4MiB probe location. The mapping walk must find them without clobbering. */
|
||||
const uintptr_t lo=0x10000000u, hi=0xffff0000u;
|
||||
void *reservation=mmap((void *)lo,hi-lo,PROT_NONE,
|
||||
MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE|MAP_FIXED_NOREPLACE,-1,0);
|
||||
assert(reservation==(void *)lo);
|
||||
void *holes[64], *fragmented[64];
|
||||
for (unsigned i=0;i<64;i++) {
|
||||
holes[i]=(void *)(lo+0x12345000u+(uintptr_t)i*0x10000u);
|
||||
assert(!munmap(holes[i],4096));
|
||||
}
|
||||
for (unsigned i=0;i<64;i++) {
|
||||
fragmented[i]=mmap(NULL,4096,PROT_READ|PROT_WRITE,MAP_SHARED,zero_fd,0);
|
||||
assert(fragmented[i]!=MAP_FAILED);
|
||||
int found=0;for(unsigned j=0;j<64;j++)found|=fragmented[i]==holes[j];assert(found);
|
||||
*(uint32_t *)fragmented[i]=i+77;
|
||||
}
|
||||
for (unsigned i=0;i<64;i++) assert(*(uint32_t *)fragmented[i]==i+77);
|
||||
for (unsigned i=0;i<64;i++) assert(!munmap(fragmented[i],4096));
|
||||
assert(!munmap(reservation,hi-lo));
|
||||
puts("PASS fragmented low32 mappings find 64 page holes beyond coarse probes");
|
||||
/* Small allocations must consume existing page holes rather than punch
|
||||
* coarse-grid holes into the only large interval needed by a later map. */
|
||||
reservation=mmap((void *)lo,hi-lo,PROT_NONE,
|
||||
MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE|MAP_FIXED_NOREPLACE,-1,0);
|
||||
assert(reservation==(void *)lo);
|
||||
for (unsigned i=0;i<64;i++) assert(!munmap(holes[i],4096));
|
||||
const uintptr_t large_address=0x70000000u;
|
||||
const size_t large_size=16u*1024u*1024u;
|
||||
assert(!munmap((void *)large_address,large_size));
|
||||
for (unsigned i=0;i<64;i++) {
|
||||
fragmented[i]=mmap(NULL,4096,PROT_READ|PROT_WRITE,MAP_SHARED,zero_fd,0);
|
||||
assert(fragmented[i]!=MAP_FAILED);
|
||||
int found=0;for(unsigned j=0;j<64;j++)found|=fragmented[i]==holes[j];assert(found);
|
||||
*(uint32_t *)fragmented[i]=i+99;
|
||||
}
|
||||
uint32_t *large=mmap(NULL,large_size,PROT_READ|PROT_WRITE,MAP_SHARED,zero_fd,0);
|
||||
assert(large==(void *)large_address);
|
||||
for(size_t i=0;i<large_size/4;i++)large[i]=(uint32_t)i^0xa5a5a5a5u;
|
||||
for(size_t i=0;i<large_size/4;i++)assert(large[i]==((uint32_t)i^0xa5a5a5a5u));
|
||||
for(unsigned i=0;i<64;i++){
|
||||
assert(*(uint32_t *)fragmented[i]==i+99);assert(!munmap(fragmented[i],4096));
|
||||
}
|
||||
assert(!munmap(large,large_size));assert(!munmap(reservation,hi-lo));
|
||||
puts("PASS page-sized mapping density preserves subsequent contiguous 16MiB allocation");
|
||||
assert(!setenv("DROIDDECK_LOW32_RDEV","999999999",1));
|
||||
q=mmap((void *)0x510000000ull,4096,PROT_READ|PROT_WRITE,MAP_SHARED,zero_fd,0);
|
||||
assert(q==(void *)0x510000000ull);assert(!munmap(q,4096));
|
||||
puts("PASS mismatched device remains untouched");
|
||||
assert(!unsetenv("DROIDDECK_LOW32_MODE"));
|
||||
q=mmap((void *)0x520000000ull,4096,PROT_READ|PROT_WRITE,MAP_SHARED,zero_fd,0);
|
||||
assert(q==(void *)0x520000000ull);assert(!munmap(q,4096));
|
||||
puts("PASS opt-in disabled by default");
|
||||
close(zero_fd);return 0;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
#define _GNU_SOURCE
|
||||
#define _LARGEFILE64_SOURCE
|
||||
#include <assert.h>
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
assert(argc == 2);
|
||||
void (*clear)(int) = dlsym(RTLD_DEFAULT, "chain_clear");
|
||||
unsigned (*calls)(unsigned) = dlsym(RTLD_DEFAULT, "chain_calls");
|
||||
int64_t (*offset)(unsigned) = dlsym(RTLD_DEFAULT, "chain_offset");
|
||||
assert(clear && calls && offset);
|
||||
if (strcmp(argv[1], "off")) assert(!setenv("DROIDDECK_LOW32_MODE", argv[1], 1));
|
||||
else assert(!unsetenv("DROIDDECK_LOW32_MODE"));
|
||||
int fd = open("/dev/zero", O_RDWR | O_CLOEXEC);
|
||||
assert(fd >= 0);
|
||||
struct stat st;
|
||||
assert(!fstat(fd, &st));
|
||||
char rdev[48];
|
||||
snprintf(rdev, sizeof(rdev), "%ju", (uintmax_t)st.st_rdev);
|
||||
assert(!setenv("DROIDDECK_LOW32_RDEV", rdev, 1));
|
||||
for (unsigned channel = 0; channel < 2; ++channel) {
|
||||
clear(fd);
|
||||
void *p = channel ? mmap64(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)
|
||||
: mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
assert(p != MAP_FAILED);
|
||||
assert(calls(channel) == 1 && calls(1 - channel) == 0 && offset(channel) == 0);
|
||||
if (!strcmp(argv[1], "low32")) assert((uintptr_t)p + 4096 <= UINT64_C(0x100000000));
|
||||
*(unsigned *)p = 0xcafef00d;
|
||||
assert(*(unsigned *)p == 0xcafef00d && !munmap(p, 4096));
|
||||
clear(fd);
|
||||
errno = 0;
|
||||
p = channel ? mmap64(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 1)
|
||||
: mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 1);
|
||||
assert(p == MAP_FAILED && errno == EINVAL);
|
||||
assert(calls(channel) == 1 && calls(1 - channel) == 0 && offset(channel) == 1);
|
||||
}
|
||||
close(fd);
|
||||
/* Regular-file forwarding must preserve an mmap64 offset above 4 GiB. */
|
||||
fd = memfd_create("preload-chain-test", 0);
|
||||
const off64_t large_offset = INT64_C(0x200001000);
|
||||
assert(fd >= 0 && !ftruncate64(fd, large_offset + 4096));
|
||||
unsigned value = 0x1234abcd;
|
||||
assert(pwrite64(fd, &value, sizeof(value), large_offset) == (ssize_t)sizeof(value));
|
||||
clear(fd);
|
||||
unsigned *p = mmap64(NULL, 4096, PROT_READ, MAP_SHARED, fd, large_offset);
|
||||
assert(p != MAP_FAILED && *p == value);
|
||||
assert(calls(1) == 1 && calls(0) == 0 && offset(1) == large_offset);
|
||||
assert(!munmap(p, 4096));
|
||||
close(fd);
|
||||
printf("PASS separate mmap/mmap64 chains (%s), EINVAL and >4GiB offset readback\n", argv[1]);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,505 @@
|
||||
diff --git a/hybris/vulkan/compat/bc_commands.c b/hybris/vulkan/compat/bc_commands.c
|
||||
index 90dac59..cf62d7d 100644
|
||||
--- a/hybris/vulkan/compat/bc_commands.c
|
||||
+++ b/hybris/vulkan/compat/bc_commands.c
|
||||
@@ -2,6 +2,7 @@
|
||||
#define VK_NO_PROTOTYPES
|
||||
#include "bc_context.h"
|
||||
#include <string.h>
|
||||
+#include <stdio.h>
|
||||
|
||||
#define PROC(name) PFN_vk##name name = (PFN_vk##name)device->resolver(device->handle, "vk" #name)
|
||||
static VkResult VKAPI_CALL allocate_commands(VkDevice handle, const VkCommandBufferAllocateInfo *info,
|
||||
@@ -76,6 +77,7 @@ static VkResult VKAPI_CALL end_command(VkCommandBuffer handle)
|
||||
PROC(EndCommandBuffer);
|
||||
VkResult result = EndCommandBuffer(handle);
|
||||
VkResult recorded = command->state.error;
|
||||
+ if (result != VK_SUCCESS || recorded != VK_SUCCESS) fprintf(stderr, "HYBRIS_BC end: native=%d recorded=%d\n", result, recorded);
|
||||
if (recorded == VK_SUCCESS) return result;
|
||||
if (recorded == VK_ERROR_OUT_OF_HOST_MEMORY || recorded == VK_ERROR_OUT_OF_DEVICE_MEMORY ||
|
||||
recorded == VK_ERROR_DEVICE_LOST) return recorded;
|
||||
@@ -198,6 +200,37 @@ static void VKAPI_CALL push_constants(VkCommandBuffer handle, VkPipelineLayout l
|
||||
CmdPushConstants(handle, layout, stages, offset, size, values);
|
||||
if (device->format_mask) hybris_bc_save_push(&command->state, layout, stages, offset, size, values);
|
||||
}
|
||||
+static void bind_descriptors2(VkCommandBuffer handle, const VkBindDescriptorSetsInfo *info, const char *name)
|
||||
+{
|
||||
+ struct hybris_bc_device *device;
|
||||
+ struct hybris_bc_command *command = hybris_bc_command_find(handle, &device);
|
||||
+ if (!command) return;
|
||||
+ PFN_vkCmdBindDescriptorSets2 call = (void *)device->resolver(device->handle, name);
|
||||
+ call(handle, info);
|
||||
+ if (device->format_mask && (info->stageFlags & VK_SHADER_STAGE_COMPUTE_BIT))
|
||||
+ hybris_bc_save_descriptors(&command->state, VK_PIPELINE_BIND_POINT_COMPUTE,
|
||||
+ info->layout, info->firstSet, info->descriptorSetCount, info->pDescriptorSets,
|
||||
+ info->dynamicOffsetCount, info->pDynamicOffsets);
|
||||
+}
|
||||
+static void VKAPI_CALL bind_descriptors2_core(VkCommandBuffer handle, const VkBindDescriptorSetsInfo *info)
|
||||
+{ bind_descriptors2(handle, info, "vkCmdBindDescriptorSets2"); }
|
||||
+static void VKAPI_CALL bind_descriptors2_khr(VkCommandBuffer handle, const VkBindDescriptorSetsInfo *info)
|
||||
+{ bind_descriptors2(handle, info, "vkCmdBindDescriptorSets2KHR"); }
|
||||
+static void push_constants2(VkCommandBuffer handle, const VkPushConstantsInfo *info, const char *name)
|
||||
+{
|
||||
+ struct hybris_bc_device *device;
|
||||
+ struct hybris_bc_command *command = hybris_bc_command_find(handle, &device);
|
||||
+ if (!command) return;
|
||||
+ PFN_vkCmdPushConstants2 call = (void *)device->resolver(device->handle, name);
|
||||
+ call(handle, info);
|
||||
+ if (device->format_mask)
|
||||
+ hybris_bc_save_push(&command->state, info->layout, info->stageFlags,
|
||||
+ info->offset, info->size, info->pValues);
|
||||
+}
|
||||
+static void VKAPI_CALL push_constants2_core(VkCommandBuffer handle, const VkPushConstantsInfo *info)
|
||||
+{ push_constants2(handle, info, "vkCmdPushConstants2"); }
|
||||
+static void VKAPI_CALL push_constants2_khr(VkCommandBuffer handle, const VkPushConstantsInfo *info)
|
||||
+{ push_constants2(handle, info, "vkCmdPushConstants2KHR"); }
|
||||
PFN_vkVoidFunction hybris_bc_commands_proc(const char *name)
|
||||
{
|
||||
static const struct { const char *name; PFN_vkVoidFunction function; } commands[] = {
|
||||
@@ -207,7 +240,9 @@ PFN_vkVoidFunction hybris_bc_commands_proc(const char *name)
|
||||
ENTRY(ResetCommandBuffer, reset_command), ENTRY(ResetCommandPool, reset_pool),
|
||||
ENTRY(DestroyCommandPool, destroy_pool), ENTRY(CreatePipelineLayout, create_layout),
|
||||
ENTRY(DestroyPipelineLayout, destroy_layout), ENTRY(CmdBindPipeline, bind_pipeline),
|
||||
- ENTRY(CmdBindDescriptorSets, bind_descriptors), ENTRY(CmdPushConstants, push_constants)
|
||||
+ ENTRY(CmdBindDescriptorSets, bind_descriptors), ENTRY(CmdPushConstants, push_constants),
|
||||
+ ENTRY(CmdBindDescriptorSets2, bind_descriptors2_core), ENTRY(CmdBindDescriptorSets2KHR, bind_descriptors2_khr),
|
||||
+ ENTRY(CmdPushConstants2, push_constants2_core), ENTRY(CmdPushConstants2KHR, push_constants2_khr)
|
||||
#undef ENTRY
|
||||
};
|
||||
for (size_t i = 0; i < sizeof(commands) / sizeof(commands[0]); ++i)
|
||||
diff --git a/hybris/vulkan/compat/bc_image.c b/hybris/vulkan/compat/bc_image.c
|
||||
index fe25344..44faaf6 100644
|
||||
--- a/hybris/vulkan/compat/bc_image.c
|
||||
+++ b/hybris/vulkan/compat/bc_image.c
|
||||
@@ -5,6 +5,19 @@
|
||||
|
||||
#define PROC(name) PFN_vk##name name = (PFN_vk##name)image->resolver(image->device, "vk" #name)
|
||||
|
||||
+int hybris_bc_srgb_family(VkFormat format)
|
||||
+{
|
||||
+ return (format >= VK_FORMAT_BC1_RGB_UNORM_BLOCK && format <= VK_FORMAT_BC3_SRGB_BLOCK) ||
|
||||
+ format == VK_FORMAT_BC7_UNORM_BLOCK || format == VK_FORMAT_BC7_SRGB_BLOCK;
|
||||
+}
|
||||
+int hybris_bc_view_compatible(VkFormat image, VkFormat view)
|
||||
+{
|
||||
+ if (image == view) return 1;
|
||||
+ return hybris_bc_srgb_family(image) &&
|
||||
+ ((image - VK_FORMAT_BC1_RGB_UNORM_BLOCK) / 2 ==
|
||||
+ (view - VK_FORMAT_BC1_RGB_UNORM_BLOCK) / 2) && hybris_bc_srgb_family(view);
|
||||
+}
|
||||
+
|
||||
VkFormat hybris_bc_image_format(VkFormat format, unsigned rgb_mask)
|
||||
{
|
||||
switch (format) {
|
||||
@@ -71,19 +84,28 @@ VkResult hybris_bc_image_describe(const VkImageCreateInfo *info, struct hybris_b
|
||||
info->imageType != VK_IMAGE_TYPE_2D || info->tiling != VK_IMAGE_TILING_OPTIMAL ||
|
||||
info->samples != VK_SAMPLE_COUNT_1_BIT ||
|
||||
(info->initialLayout != VK_IMAGE_LAYOUT_UNDEFINED && info->initialLayout != VK_IMAGE_LAYOUT_PREINITIALIZED) ||
|
||||
- (info->flags & ~VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) ||
|
||||
+ (info->flags & ~(VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT | VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT)) ||
|
||||
+ ((info->flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) && !hybris_bc_srgb_family(info->format)) ||
|
||||
!info->usage ||
|
||||
(info->usage & ~(VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT)) ||
|
||||
!info->extent.width || !info->extent.height || info->extent.depth != 1 ||
|
||||
!info->mipLevels || info->mipLevels > 32 || !info->arrayLayers)
|
||||
return VK_ERROR_FORMAT_NOT_SUPPORTED;
|
||||
+ image->flags = info->flags;
|
||||
+ image->view_mask = (info->flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) ? 3 : 1;
|
||||
/* These chains only constrain views or request no external/swapchain
|
||||
* binding. The decoded image has the same view restriction in our wrapper. */
|
||||
for (const VkBaseInStructure *next = info->pNext; next; next = next->pNext) {
|
||||
if (next->sType == VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO) {
|
||||
const VkImageFormatListCreateInfo *list = (const void *)next;
|
||||
- for (uint32_t i = 0; i < list->viewFormatCount; ++i)
|
||||
- if (list->pViewFormats[i] != info->format) return VK_ERROR_FORMAT_NOT_SUPPORTED;
|
||||
+ if (list->viewFormatCount) image->view_mask = 0;
|
||||
+ for (uint32_t i = 0; i < list->viewFormatCount; ++i) {
|
||||
+ VkFormat view = list->pViewFormats[i];
|
||||
+ if (!hybris_bc_view_compatible(info->format, view) ||
|
||||
+ (view != info->format && !(info->flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT)))
|
||||
+ return VK_ERROR_FORMAT_NOT_SUPPORTED;
|
||||
+ image->view_mask |= view == info->format ? 1u : 2u;
|
||||
+ }
|
||||
} else if (next->sType == VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO) {
|
||||
if (((const VkExternalMemoryImageCreateInfo *)next)->handleTypes)
|
||||
return VK_ERROR_FORMAT_NOT_SUPPORTED;
|
||||
diff --git a/hybris/vulkan/compat/bc_image.h b/hybris/vulkan/compat/bc_image.h
|
||||
index 9e62eb3..c950cc2 100644
|
||||
--- a/hybris/vulkan/compat/bc_image.h
|
||||
+++ b/hybris/vulkan/compat/bc_image.h
|
||||
@@ -12,10 +12,14 @@ struct hybris_bc_image {
|
||||
VkMemoryRequirements requirements;
|
||||
VkBool32 requires_dedicated, prefers_dedicated;
|
||||
VkFormat format, decoded_format;
|
||||
+ VkImageCreateFlags flags;
|
||||
+ unsigned view_mask;
|
||||
VkExtent3D extent;
|
||||
uint32_t mip_levels, layers, block_bytes;
|
||||
VkDeviceSize mip_offset[32], block_size;
|
||||
};
|
||||
+int hybris_bc_srgb_family(VkFormat format);
|
||||
+int hybris_bc_view_compatible(VkFormat image, VkFormat view);
|
||||
VkFormat hybris_bc_image_format(VkFormat format, unsigned rgb_mask);
|
||||
VkResult hybris_bc_image_describe(const VkImageCreateInfo *info, struct hybris_bc_image *image);
|
||||
void hybris_bc_image_backing_info(const struct hybris_bc_image *image,
|
||||
diff --git a/hybris/vulkan/compat/bc_policy.c b/hybris/vulkan/compat/bc_policy.c
|
||||
index c5856f6..3124a25 100644
|
||||
--- a/hybris/vulkan/compat/bc_policy.c
|
||||
+++ b/hybris/vulkan/compat/bc_policy.c
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "bc_context.h"
|
||||
#include "../layer/layer.h"
|
||||
#include <stdlib.h>
|
||||
+#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <sys/auxv.h>
|
||||
|
||||
@@ -16,12 +17,18 @@ static void initialize_policy(void)
|
||||
const char *value = getenv("HYBRIS_BC_TEXTURES");
|
||||
if (!value || !strcmp(value, "missing") || !strcmp(value, "1")) policy = 1;
|
||||
else if (value && !strcmp(value, "force")) policy = 2;
|
||||
+ else if (value && !strcmp(value, "dxvk")) policy = 3;
|
||||
}
|
||||
int hybris_bc_enabled(void)
|
||||
{
|
||||
pthread_once(&policy_once, initialize_policy);
|
||||
return policy != 0;
|
||||
}
|
||||
+static int dxvk_profile(void)
|
||||
+{
|
||||
+ pthread_once(&policy_once, initialize_policy);
|
||||
+ return policy == 3;
|
||||
+}
|
||||
#define PHYSICAL_PROC(name) PFN_vk##name name = (PFN_vk##name)context.resolver(context.instance, "vk" #name)
|
||||
/* Preserve three-channel border replacement when the native image format
|
||||
* supports the full sampled/transfer domain. Selection is per physical device;
|
||||
@@ -52,7 +59,7 @@ unsigned hybris_bc_physical_mask(VkPhysicalDevice physical)
|
||||
VkPhysicalDeviceProperties properties;
|
||||
GetPhysicalDeviceProperties(physical, &properties);
|
||||
/* Core 1.4 includes descriptor-state commands that are not intercepted yet. */
|
||||
- if (properties.apiVersion < VK_API_VERSION_1_1 || properties.apiVersion >= VK_MAKE_API_VERSION(0, 1, 4, 0) ||
|
||||
+ if (properties.apiVersion < VK_API_VERSION_1_1 || (!dxvk_profile() && properties.apiVersion >= VK_MAKE_API_VERSION(0, 1, 4, 0)) ||
|
||||
properties.limits.maxStorageBufferRange < 256 ||
|
||||
properties.limits.minStorageBufferOffsetAlignment >= properties.limits.maxStorageBufferRange) return 0;
|
||||
uint32_t count = 0;
|
||||
@@ -72,6 +79,9 @@ unsigned hybris_bc_physical_mask(VkPhysicalDevice physical)
|
||||
unsigned mask = 0;
|
||||
for (unsigned i = 0; i < 16; ++i) {
|
||||
VkFormat format = VK_FORMAT_BC1_RGB_UNORM_BLOCK + i;
|
||||
+ /* D3D uses BC1 RGBA. Keep RGB-only BC1 unadvertised until absent-alpha
|
||||
+ * border semantics are implemented on devices without RGB8 images. */
|
||||
+ if (dxvk_profile() && i < 2) continue;
|
||||
VkFormat backing = hybris_bc_image_format(format, physical_rgb_mask(physical));
|
||||
if (backing == VK_FORMAT_UNDEFINED) continue;
|
||||
VkFormatProperties native, decoded;
|
||||
@@ -84,6 +94,33 @@ unsigned hybris_bc_physical_mask(VkPhysicalDevice physical)
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
+/* The emulation profile implements Vulkan 1.3 plus maintenance6. Do not expose
|
||||
+ * 1.4 core host-copy/push-descriptor operations that bypass our state tracking. */
|
||||
+static void cap_properties(VkPhysicalDevice physical, VkPhysicalDeviceProperties *out)
|
||||
+{
|
||||
+ if (dxvk_profile() && hybris_bc_physical_mask(physical) && out->apiVersion > VK_API_VERSION_1_3)
|
||||
+ out->apiVersion = VK_API_VERSION_1_3;
|
||||
+}
|
||||
+static void VKAPI_CALL properties(VkPhysicalDevice physical, VkPhysicalDeviceProperties *out)
|
||||
+{
|
||||
+ struct hybris_layer_physical context;
|
||||
+ if (!hybris_layer_lookup_physical(physical, &context)) return;
|
||||
+ PHYSICAL_PROC(GetPhysicalDeviceProperties);
|
||||
+ GetPhysicalDeviceProperties(physical, out);
|
||||
+ cap_properties(physical, out);
|
||||
+}
|
||||
+static void properties2(VkPhysicalDevice physical, VkPhysicalDeviceProperties2 *out, const char *name)
|
||||
+{
|
||||
+ struct hybris_layer_physical context;
|
||||
+ if (!hybris_layer_lookup_physical(physical, &context)) return;
|
||||
+ PFN_vkGetPhysicalDeviceProperties2 query = (void *)context.resolver(context.instance, name);
|
||||
+ query(physical, out);
|
||||
+ cap_properties(physical, &out->properties);
|
||||
+}
|
||||
+static void VKAPI_CALL properties2_core(VkPhysicalDevice physical, VkPhysicalDeviceProperties2 *out)
|
||||
+{ properties2(physical, out, "vkGetPhysicalDeviceProperties2"); }
|
||||
+static void VKAPI_CALL properties2_khr(VkPhysicalDevice physical, VkPhysicalDeviceProperties2 *out)
|
||||
+{ properties2(physical, out, "vkGetPhysicalDeviceProperties2KHR"); }
|
||||
static int emulates(VkPhysicalDevice physical, VkFormat format)
|
||||
{
|
||||
return format >= VK_FORMAT_BC1_RGB_UNORM_BLOCK && format <= VK_FORMAT_BC7_SRGB_BLOCK &&
|
||||
@@ -109,10 +146,13 @@ int hybris_bc_extension_allowed(const char *name)
|
||||
"VK_KHR_maintenance6", "VK_KHR_maintenance8", "VK_EXT_host_image_copy",
|
||||
"VK_QCOM_rotated_copy_commands", "VK_EXT_device_generated_commands",
|
||||
"VK_NV_device_generated_commands", "VK_NV_device_generated_commands_compute",
|
||||
- "VK_NV_dedicated_allocation", "VK_NV_copy_memory_indirect"
|
||||
+ "VK_NV_dedicated_allocation", "VK_NV_copy_memory_indirect", "VK_NV_per_stage_descriptor_set"
|
||||
};
|
||||
for (size_t i = 0; i < sizeof(unsupported) / sizeof(unsupported[0]); ++i)
|
||||
- if (!strcmp(name, unsupported[i])) return 0;
|
||||
+ if (!strcmp(name, unsupported[i])) {
|
||||
+ if (dxvk_profile() && !strcmp(name, "VK_KHR_maintenance6")) continue;
|
||||
+ return 0;
|
||||
+ }
|
||||
return 1;
|
||||
}
|
||||
/* Extension feature queries must agree with the filtered extension list. Each
|
||||
@@ -121,8 +161,12 @@ static unsigned unsupported_feature_count(VkStructureType type)
|
||||
{
|
||||
switch (type) {
|
||||
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_BUFFER_FEATURES_EXT: return 4;
|
||||
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_4_FEATURES:
|
||||
+ return dxvk_profile() ? (offsetof(VkPhysicalDeviceVulkan14Features, pushDescriptor) -
|
||||
+ offsetof(VkPhysicalDeviceVulkan14Features, globalPriorityQuery)) / sizeof(VkBool32) + 1 : 0;
|
||||
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_6_FEATURES_KHR: return dxvk_profile() ? 0 : 1;
|
||||
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PER_STAGE_DESCRIPTOR_SET_FEATURES_NV: return 2;
|
||||
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_OBJECT_FEATURES_EXT:
|
||||
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_6_FEATURES_KHR:
|
||||
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_IMAGE_COPY_FEATURES_EXT:
|
||||
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COPY_MEMORY_INDIRECT_FEATURES_NV:
|
||||
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEVICE_GENERATED_COMMANDS_FEATURES_NV: return 1;
|
||||
@@ -252,11 +296,12 @@ static void VKAPI_CALL sparse_properties2_core(VkPhysicalDevice physical, const
|
||||
static void VKAPI_CALL sparse_properties2_khr(VkPhysicalDevice physical, const VkPhysicalDeviceSparseImageFormatInfo2 *info,
|
||||
uint32_t *count, VkSparseImageFormatProperties2 *out)
|
||||
{ sparse_properties2(physical, info, count, out, "vkGetPhysicalDeviceSparseImageFormatProperties2KHR"); }
|
||||
-static int image_supported(VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags)
|
||||
+static int image_supported(VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags)
|
||||
{
|
||||
return type == VK_IMAGE_TYPE_2D && tiling == VK_IMAGE_TILING_OPTIMAL && usage &&
|
||||
!(usage & ~(VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT)) &&
|
||||
- !(flags & ~VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT);
|
||||
+ !(flags & ~(VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT | VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT)) &&
|
||||
+ (!(flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) || hybris_bc_srgb_family(format));
|
||||
}
|
||||
static VkResult VKAPI_CALL image_properties(VkPhysicalDevice physical, VkFormat format, VkImageType type,
|
||||
VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties *out)
|
||||
@@ -265,7 +310,7 @@ static VkResult VKAPI_CALL image_properties(VkPhysicalDevice physical, VkFormat
|
||||
if (!hybris_layer_lookup_physical(physical, &context)) return VK_ERROR_INITIALIZATION_FAILED;
|
||||
PHYSICAL_PROC(GetPhysicalDeviceImageFormatProperties);
|
||||
if (emulates(physical, format)) {
|
||||
- if (!image_supported(type, tiling, usage, flags)) { *out = (VkImageFormatProperties){0}; return VK_ERROR_FORMAT_NOT_SUPPORTED; }
|
||||
+ if (!image_supported(format, type, tiling, usage, flags)) { *out = (VkImageFormatProperties){0}; return VK_ERROR_FORMAT_NOT_SUPPORTED; }
|
||||
VkResult result = GetPhysicalDeviceImageFormatProperties(physical, hybris_bc_image_format(format, physical_rgb_mask(physical)), type,
|
||||
tiling, usage | VK_IMAGE_USAGE_TRANSFER_DST_BIT, flags, out);
|
||||
if (result == VK_SUCCESS) out->sampleCounts &= VK_SAMPLE_COUNT_1_BIT;
|
||||
@@ -282,14 +327,16 @@ static VkResult image_properties2(VkPhysicalDevice physical, const VkPhysicalDev
|
||||
(PFN_vkGetPhysicalDeviceImageFormatProperties2)context.resolver(context.instance, name);
|
||||
if (!emulates(physical, info->format)) return query(physical, info, out);
|
||||
out->imageFormatProperties = (VkImageFormatProperties){0};
|
||||
- if (!image_supported(info->type, info->tiling, info->usage, info->flags)) return VK_ERROR_FORMAT_NOT_SUPPORTED;
|
||||
+ if (!image_supported(info->format, info->type, info->tiling, info->usage, info->flags)) return VK_ERROR_FORMAT_NOT_SUPPORTED;
|
||||
for (const VkBaseInStructure *node = info->pNext; node; node = node->pNext) {
|
||||
if (node->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO) {
|
||||
if (((const VkPhysicalDeviceExternalImageFormatInfo *)node)->handleType) return VK_ERROR_FORMAT_NOT_SUPPORTED;
|
||||
} else if (node->sType == VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO) {
|
||||
const VkImageFormatListCreateInfo *list = (const void *)node;
|
||||
for (uint32_t i = 0; i < list->viewFormatCount; ++i)
|
||||
- if (list->pViewFormats[i] != info->format) return VK_ERROR_FORMAT_NOT_SUPPORTED;
|
||||
+ if (!hybris_bc_view_compatible(info->format, list->pViewFormats[i]) ||
|
||||
+ (list->pViewFormats[i] != info->format && !(info->flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT)))
|
||||
+ return VK_ERROR_FORMAT_NOT_SUPPORTED;
|
||||
} else if (node->sType != VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_VIEW_IMAGE_FORMAT_INFO_EXT) {
|
||||
return VK_ERROR_FORMAT_NOT_SUPPORTED;
|
||||
}
|
||||
@@ -322,6 +369,9 @@ PFN_vkVoidFunction hybris_bc_policy_proc(const char *name)
|
||||
if (!hybris_bc_enabled()) return NULL;
|
||||
static const struct { const char *name; PFN_vkVoidFunction function; } commands[] = {
|
||||
#define ENTRY(name, function) {"vk" #name, (PFN_vkVoidFunction)function}
|
||||
+ ENTRY(GetPhysicalDeviceProperties, properties),
|
||||
+ ENTRY(GetPhysicalDeviceProperties2, properties2_core),
|
||||
+ ENTRY(GetPhysicalDeviceProperties2KHR, properties2_khr),
|
||||
ENTRY(GetPhysicalDeviceQueueFamilyProperties, queue_properties),
|
||||
ENTRY(GetPhysicalDeviceQueueFamilyProperties2, queue_properties2_core),
|
||||
ENTRY(GetPhysicalDeviceQueueFamilyProperties2KHR, queue_properties2_khr),
|
||||
diff --git a/hybris/vulkan/compat/bc_resources.c b/hybris/vulkan/compat/bc_resources.c
|
||||
index 526c3f1..74cc0c9 100644
|
||||
--- a/hybris/vulkan/compat/bc_resources.c
|
||||
+++ b/hybris/vulkan/compat/bc_resources.c
|
||||
@@ -210,8 +210,10 @@ static VkResult VKAPI_CALL create_view(VkDevice handle, const VkImageViewCreateI
|
||||
struct hybris_bc_resource *resource = hybris_bc_resource_find(device, info->image);
|
||||
VkImageViewCreateInfo translated = *info;
|
||||
if (resource && resource->emulated.image) {
|
||||
- if (info->format != resource->format) return VK_ERROR_FORMAT_NOT_SUPPORTED;
|
||||
- translated.format = resource->emulated.decoded_format;
|
||||
+ unsigned bit = info->format == resource->format ? 1u : 2u;
|
||||
+ if (!hybris_bc_view_compatible(resource->format, info->format) ||
|
||||
+ !(resource->emulated.view_mask & bit)) return VK_ERROR_FORMAT_NOT_SUPPORTED;
|
||||
+ translated.format = hybris_bc_image_format(info->format, device->rgb_mask);
|
||||
}
|
||||
PROC(CreateImageView);
|
||||
return CreateImageView(handle, &translated, allocator, view);
|
||||
diff --git a/hybris/vulkan/compat/bc_transfer.c b/hybris/vulkan/compat/bc_transfer.c
|
||||
index 6edb652..799fb62 100644
|
||||
--- a/hybris/vulkan/compat/bc_transfer.c
|
||||
+++ b/hybris/vulkan/compat/bc_transfer.c
|
||||
@@ -2,6 +2,7 @@
|
||||
#define VK_NO_PROTOTYPES
|
||||
#include "bc_transfer.h"
|
||||
#include <stdlib.h>
|
||||
+#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define PROC(name) PFN_vk##name name = (PFN_vk##name)t->decoder->resolver(t->decoder->device, "vk" #name)
|
||||
@@ -59,16 +60,29 @@ static VkResult scratch(struct hybris_bc_transfer *t)
|
||||
if (type == t->memory->memoryTypeCount) type = i;
|
||||
if (t->memory->memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) { type = i; break; }
|
||||
}
|
||||
- if (type == t->memory->memoryTypeCount) { result = VK_ERROR_OUT_OF_DEVICE_MEMORY; goto fail; }
|
||||
+ if (type == t->memory->memoryTypeCount) {
|
||||
+ fprintf(stderr, "HYBRIS_BC scratch: no memory type (bits=0x%x count=%u size=%llu)\n",
|
||||
+ requirements.memoryRequirements.memoryTypeBits, t->memory->memoryTypeCount,
|
||||
+ (unsigned long long)requirements.memoryRequirements.size);
|
||||
+ result = VK_ERROR_OUT_OF_DEVICE_MEMORY; goto fail;
|
||||
+ }
|
||||
VkMemoryDedicatedAllocateInfo owner = {
|
||||
.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO, .buffer = buffer};
|
||||
VkMemoryAllocateInfo allocation = {.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
|
||||
.pNext = dedicated.requiresDedicatedAllocation || dedicated.prefersDedicatedAllocation ? &owner : NULL,
|
||||
.allocationSize = requirements.memoryRequirements.size, .memoryTypeIndex = type};
|
||||
result = AllocateMemory(device, &allocation, NULL, &memory);
|
||||
- if (result != VK_SUCCESS) goto fail;
|
||||
+ if (result != VK_SUCCESS) {
|
||||
+ fprintf(stderr, "HYBRIS_BC scratch allocation: result=%d size=%llu type=%u bits=0x%x\n",
|
||||
+ result, (unsigned long long)allocation.allocationSize, type, requirements.memoryRequirements.memoryTypeBits);
|
||||
+ goto fail;
|
||||
+ }
|
||||
result = BindBufferMemory(device, buffer, memory, 0);
|
||||
- if (result != VK_SUCCESS) goto fail;
|
||||
+ if (result != VK_SUCCESS) {
|
||||
+ fprintf(stderr, "HYBRIS_BC scratch bind: result=%d size=%llu type=%u\n",
|
||||
+ result, (unsigned long long)allocation.allocationSize, type);
|
||||
+ goto fail;
|
||||
+ }
|
||||
t->scratch = buffer;
|
||||
t->scratch_memory = memory;
|
||||
t->scratch_size = size;
|
||||
@@ -193,7 +207,7 @@ VkResult hybris_bc_decode_image(struct hybris_bc_transfer *t,
|
||||
buffer_barrier(t, command, image->blocks, VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT);
|
||||
VkResult result = decode(t, command, image, layout, region);
|
||||
- if (result != VK_SUCCESS) { state->error = result; return result; }
|
||||
+ if (result != VK_SUCCESS) { fprintf(stderr, "HYBRIS_BC transfer failed: %d\n", result); state->error = result; return result; }
|
||||
buffer_barrier(t, command, image->blocks, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||
VK_ACCESS_SHADER_READ_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT);
|
||||
diff --git a/hybris/vulkan/compat/shader_policy.c b/hybris/vulkan/compat/shader_policy.c
|
||||
index a1dcf6d..21a4cc7 100644
|
||||
--- a/hybris/vulkan/compat/shader_policy.c
|
||||
+++ b/hybris/vulkan/compat/shader_policy.c
|
||||
@@ -92,7 +92,8 @@ static void properties2(VkPhysicalDevice physical, VkPhysicalDeviceProperties2 *
|
||||
{
|
||||
struct hybris_layer_physical context;
|
||||
if (!hybris_layer_lookup_physical(physical, &context)) return;
|
||||
- PFN_vkGetPhysicalDeviceProperties2 query = (PFN_vkGetPhysicalDeviceProperties2)context.resolver(context.instance, name);
|
||||
+ PFN_vkGetPhysicalDeviceProperties2 query = (void *)hybris_bc_policy_proc(name);
|
||||
+ if (!query) query = (void *)context.resolver(context.instance, name);
|
||||
query(physical, out);
|
||||
VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT *legacy = NULL;
|
||||
for (VkBaseOutStructure *node = out->pNext; node; node = node->pNext)
|
||||
diff --git a/tests/baseline/probe_bc_images.c b/tests/baseline/probe_bc_images.c
|
||||
index 85ba6e6..55e069c 100644
|
||||
--- a/tests/baseline/probe_bc_images.c
|
||||
+++ b/tests/baseline/probe_bc_images.c
|
||||
@@ -95,9 +95,10 @@ int bc_images_probe(int validate, int route)
|
||||
}
|
||||
free(queues);
|
||||
if (family == UINT32_MAX) return 3;
|
||||
+ unsigned first_format = getenv("BC_D3D_FORMATS") ? 2 : 0;
|
||||
VkBool32 linear_filter[BC_IMAGE_FORMAT_COUNT] = {0};
|
||||
unsigned unsupported_formats = 0;
|
||||
- for (unsigned f = 0; f < BC_IMAGE_FORMAT_COUNT; ++f) {
|
||||
+ for (unsigned f = first_format; f < BC_IMAGE_FORMAT_COUNT; ++f) {
|
||||
VkFormatProperties format;
|
||||
p_vkGetPhysicalDeviceFormatProperties(physical, bc_formats[f], &format);
|
||||
VkFormatProperties2 format2 = {.sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2};
|
||||
@@ -164,19 +165,28 @@ int bc_images_probe(int validate, int route)
|
||||
p_vkGetPhysicalDeviceFeatures2(physical, &queried);
|
||||
maintenance4 = maintenance.maintenance4;
|
||||
}
|
||||
- synchronization.pNext = maintenance4 ? &maintenance : NULL;
|
||||
- const char *device_extensions[4];
|
||||
+ int maintenance6 = getenv("BC_MAINTENANCE6") != NULL;
|
||||
+ VkPhysicalDeviceMaintenance6FeaturesKHR maintenance_six = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_6_FEATURES_KHR};
|
||||
+ if (maintenance6) {
|
||||
+ VkPhysicalDeviceFeatures2 q = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, .pNext = &maintenance_six};
|
||||
+ p_vkGetPhysicalDeviceFeatures2(physical, &q);
|
||||
+ if (!maintenance_six.maintenance6) { puts("MISSING maintenance6"); return 3; }
|
||||
+ }
|
||||
+ maintenance.pNext = maintenance6 ? &maintenance_six : NULL;
|
||||
+ synchronization.pNext = maintenance4 ? (void *)&maintenance : maintenance6 ? (void *)&maintenance_six : NULL;
|
||||
+ const char *device_extensions[5];
|
||||
uint32_t device_extension_count = 0;
|
||||
if (copies2) device_extensions[device_extension_count++] = VK_KHR_COPY_COMMANDS_2_EXTENSION_NAME;
|
||||
if (sync2) device_extensions[device_extension_count++] = VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME;
|
||||
if (maintenance4) device_extensions[device_extension_count++] = VK_KHR_MAINTENANCE_4_EXTENSION_NAME;
|
||||
if (format_list) device_extensions[device_extension_count++] = VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME;
|
||||
+ if (maintenance6) device_extensions[device_extension_count++] = VK_KHR_MAINTENANCE_6_EXTENSION_NAME;
|
||||
float priority = 1;
|
||||
VkDeviceQueueCreateInfo qc = {.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
|
||||
.queueFamilyIndex = family, .queueCount = 1, .pQueuePriorities = &priority};
|
||||
VkDeviceCreateInfo dc = {.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
|
||||
.queueCreateInfoCount = 1, .pQueueCreateInfos = &qc,
|
||||
- .pNext = sync2 ? (void *)&synchronization : maintenance4 ? (void *)&maintenance : NULL,
|
||||
+ .pNext = sync2 ? (void *)&synchronization : maintenance4 ? (void *)&maintenance : maintenance6 ? (void *)&maintenance_six : NULL,
|
||||
.enabledExtensionCount = device_extension_count, .ppEnabledExtensionNames = device_extensions};
|
||||
VkDebugUtilsMessengerEXT messenger = VK_NULL_HANDLE;
|
||||
PFN_vkDestroyDebugUtilsMessengerEXT destroy_messenger = NULL;
|
||||
@@ -307,8 +317,12 @@ int bc_images_probe(int validate, int route)
|
||||
VkFenceCreateInfo fence_info = {.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO};
|
||||
VkFence fence;
|
||||
CHECK(p_vkCreateFence(device, &fence_info, NULL, &fence));
|
||||
+ PFN_vkCmdBindDescriptorSets2KHR bind2 = (PFN_vkCmdBindDescriptorSets2KHR)p_vkGetDeviceProcAddr(device, "vkCmdBindDescriptorSets2KHR");
|
||||
+ PFN_vkCmdPushConstants2KHR push2 = (PFN_vkCmdPushConstants2KHR)p_vkGetDeviceProcAddr(device, "vkCmdPushConstants2KHR");
|
||||
+ if (maintenance6 && (!bind2 || !push2)) return 2;
|
||||
+ printf("BC_EXTENDED maintenance6=%d mutable=%d\n", maintenance6, getenv("BC_MUTABLE") != NULL);
|
||||
unsigned failures = 0, readbacks = 0, copies2_cases = 0, sync2_cases = 0;
|
||||
- for (unsigned f = 0; f < BC_IMAGE_FORMAT_COUNT; ++f) {
|
||||
+ for (unsigned f = first_format; f < BC_IMAGE_FORMAT_COUNT; ++f) {
|
||||
for (unsigned shape_index = 0; shape_index < 2; ++shape_index) {
|
||||
uint32_t base_width = shape_index ? 32 : 9, base_height = shape_index ? 32 : 7;
|
||||
for (uint32_t mip = 0; mip < 4; ++mip) {
|
||||
@@ -337,6 +351,13 @@ int bc_images_probe(int validate, int route)
|
||||
(i != 2 ? VK_IMAGE_USAGE_SAMPLED_BIT : 0), .sharingMode = VK_SHARING_MODE_EXCLUSIVE};
|
||||
VkImageFormatListCreateInfo formats = {.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO,
|
||||
.viewFormatCount = 1, .pViewFormats = &image_info.format};
|
||||
+ VkFormat paired[2] = {bc_formats[f], bc_formats[f ^ 1]};
|
||||
+ if (getenv("BC_MUTABLE") && (f < 8 || (f >= 12 && f < 14)) && i < 2) {
|
||||
+ image_info.flags |= VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
|
||||
+ image_info.format = paired[1];
|
||||
+ formats.viewFormatCount = 2;
|
||||
+ formats.pViewFormats = paired;
|
||||
+ }
|
||||
if (format_list) image_info.pNext = &formats;
|
||||
VkMemoryRequirements2 described = {.sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2};
|
||||
if (maintenance4) {
|
||||
@@ -414,9 +435,19 @@ int bc_images_probe(int validate, int route)
|
||||
VkCommandBufferBeginInfo begin = {.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO};
|
||||
CHECK(p_vkBeginCommandBuffer(command, &begin));
|
||||
p_vkCmdBindPipeline(command, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline);
|
||||
- p_vkCmdBindDescriptorSets(command, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_layout, 0, 1, &descriptors, 1, &dynamic_offset);
|
||||
+ if (maintenance6) {
|
||||
+ VkBindDescriptorSetsInfoKHR bind = {.sType = VK_STRUCTURE_TYPE_BIND_DESCRIPTOR_SETS_INFO_KHR,
|
||||
+ .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, .layout = pipeline_layout,
|
||||
+ .descriptorSetCount = 1, .pDescriptorSets = &descriptors,
|
||||
+ .dynamicOffsetCount = 1, .pDynamicOffsets = &dynamic_offset};
|
||||
+ bind2(command, &bind);
|
||||
+ } else p_vkCmdBindDescriptorSets(command, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_layout, 0, 1, &descriptors, 1, &dynamic_offset);
|
||||
uint32_t shape[] = {width, height, LAYERS, f >= 14 ? 3 : f >= 8 && f < 12 ? 1 + (f & 1) : 0, linear_filter[f] != 0};
|
||||
- p_vkCmdPushConstants(command, pipeline_layout, VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(shape), shape);
|
||||
+ if (maintenance6) {
|
||||
+ VkPushConstantsInfoKHR push = {.sType = VK_STRUCTURE_TYPE_PUSH_CONSTANTS_INFO_KHR,
|
||||
+ .layout = pipeline_layout, .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, .size = sizeof(shape), .pValues = shape};
|
||||
+ push2(command, &push);
|
||||
+ } else p_vkCmdPushConstants(command, pipeline_layout, VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(shape), shape);
|
||||
VkMemoryBarrier before = {.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER,
|
||||
.srcAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT,
|
||||
.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT};
|
||||
@@ -614,7 +645,7 @@ int bc_images_probe(int validate, int route)
|
||||
p_vkDestroyDevice(device, NULL);
|
||||
if (destroy_messenger) destroy_messenger(instance, messenger, NULL);
|
||||
p_vkDestroyInstance(instance, NULL); dlclose(h);
|
||||
- printf("BC_IMAGES_SUMMARY formats=16 shapes=2 readbacks=%u copy2_cases=%u sync2_cases=%u maintenance4=%u format_list=%u failures=%u validation_errors=%u route=%d\n",
|
||||
- readbacks, copies2_cases, sync2_cases, maintenance4, format_list, failures, validation.errors, route);
|
||||
- return failures || validation.errors || readbacks != BC_IMAGE_FORMAT_COUNT * 2 * 4 * 3 ? 2 : 0;
|
||||
+ printf("BC_IMAGES_SUMMARY formats=%u shapes=2 readbacks=%u copy2_cases=%u sync2_cases=%u maintenance4=%u format_list=%u failures=%u validation_errors=%u route=%d\n",
|
||||
+ (unsigned)BC_IMAGE_FORMAT_COUNT - first_format, readbacks, copies2_cases, sync2_cases, maintenance4, format_list, failures, validation.errors, route);
|
||||
+ return failures || validation.errors || readbacks != (BC_IMAGE_FORMAT_COUNT - first_format) * 2 * 4 * 3 ? 2 : 0;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
--- a/hybris/vulkan/icd/icd.c
|
||||
+++ b/hybris/vulkan/icd/icd.c
|
||||
@@ -71,7 +71,8 @@
|
||||
int result = module->methods->open(module, HWVULKAN_DEVICE_0,
|
||||
(hw_device_t **)&candidate);
|
||||
if (result || !candidate || candidate->common.tag != HARDWARE_DEVICE_TAG ||
|
||||
- candidate->common.version != HWVULKAN_DEVICE_API_VERSION_0_1 ||
|
||||
+ (candidate->common.version != HWVULKAN_DEVICE_API_VERSION_0_1 &&
|
||||
+ candidate->common.version != HARDWARE_DEVICE_API_VERSION(0, 1)) ||
|
||||
!candidate->CreateInstance || !candidate->GetInstanceProcAddr ||
|
||||
!candidate->EnumerateInstanceExtensionProperties) {
|
||||
fprintf(stderr, "hybris ICD: incompatible Vulkan HAL device (open=%d)\n", result);
|
||||
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/python3
|
||||
"""Select a staged DXVK payload for one DroidDeck Proton game launch.
|
||||
|
||||
Place this script beside dxvk/x32/ and dxvk/x64/, then select its absolute
|
||||
path with DROIDDECK_PROTON_WRAPPER in the game's environment settings.
|
||||
Run `python3 run-proton.py --check /path/to/proton` to check the payload and
|
||||
Proton source layout without starting Proton or changing a game prefix.
|
||||
|
||||
This wrapper does not install the graphics runtime, select Vulkan layers,
|
||||
change synchronization settings, or provide game-specific workarounds.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
|
||||
DLL_NAMES = ("d3d8.dll", "d3d9.dll", "d3d10core.dll", "d3d11.dll", "dxgi.dll")
|
||||
PREFIX_MARKER = "droiddeck-dxvk-profile-v1"
|
||||
|
||||
|
||||
def prepare(proton, dxvk):
|
||||
"""Validate all inputs and compile an in-memory copy of the Proton script."""
|
||||
for architecture in ("x32", "x64"):
|
||||
for name in DLL_NAMES:
|
||||
dll = dxvk / architecture / name
|
||||
if not dll.is_file():
|
||||
raise ValueError(f"missing DXVK file: {dll}")
|
||||
with dll.open("rb") as stream:
|
||||
if not stream.read(1):
|
||||
raise ValueError(f"empty DXVK file: {dll}")
|
||||
|
||||
source = proton.read_text(encoding="utf-8")
|
||||
for is32, architecture in (("False", "x64"), ("True", "x32")):
|
||||
needle = f'g_proton.arch_pe_dir("wine/dxvk", {is32}) + f + ".dll"'
|
||||
if source.count(needle) != 1:
|
||||
raise ValueError(f"unsupported Proton layout: expected one {architecture} DXVK copy expression")
|
||||
directory = str(dxvk / architecture) + "/"
|
||||
source = source.replace(needle, repr(directory) + ' + f + ".dll"', 1)
|
||||
|
||||
needle = " # check whether any prefix config has changed"
|
||||
if source.count(needle) != 1:
|
||||
raise ValueError("unsupported Proton layout: expected one prefix configuration marker")
|
||||
# The supported Proton copies DXVK DLLs on every launch. This marker records
|
||||
# profile activation; it does not need changing whenever the payload changes.
|
||||
marker = repr("\n" + PREFIX_MARKER)
|
||||
source = source.replace(needle, f" prefix_info += {marker}\n" + needle, 1)
|
||||
return compile(source, str(proton), "exec")
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--check", action="store_true", help="validate inputs without running Proton")
|
||||
parser.add_argument("proton", help="selected Proton Python script")
|
||||
parser.add_argument("proton_args", nargs=argparse.REMAINDER)
|
||||
args = parser.parse_args()
|
||||
if not args.check and (len(args.proton_args) < 2 or args.proton_args[0] != "waitforexitandrun"):
|
||||
parser.error("expected: PROTON waitforexitandrun GAME [ARGUMENTS...]")
|
||||
|
||||
proton = Path(args.proton)
|
||||
# A sibling payload directory by name (dxvk-2.6.2 for Xclipse); never a path.
|
||||
name = os.environ.get("DROIDDECK_HYBRIS_DXVK") or "dxvk"
|
||||
if not name.startswith("dxvk") or "/" in name or name.startswith("."):
|
||||
print(f"DroidDeck DXVK profile: invalid payload name {name!r}", file=sys.stderr)
|
||||
return 1
|
||||
dxvk = Path(__file__).resolve().parent / name
|
||||
try:
|
||||
code = prepare(proton, dxvk)
|
||||
except (OSError, ValueError, SyntaxError) as error:
|
||||
print(f"DroidDeck DXVK profile: {error}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
if args.check:
|
||||
print(f"DroidDeck DXVK profile: payload present and Proton layout supported ({dxvk})")
|
||||
return 0
|
||||
|
||||
print(f"DROIDDECK_GRAPHICS profile={PREFIX_MARKER} dxvk={dxvk}", flush=True)
|
||||
# Preserve the selected Proton path, including symlinks, and its arguments.
|
||||
# Proton uses argv[0] and sibling Python imports to locate its own depot.
|
||||
sys.argv = [args.proton, *args.proton_args]
|
||||
sys.path.insert(0, str(proton.absolute().parent))
|
||||
exec(code, {"__name__": "__main__", "__file__": args.proton,
|
||||
"__package__": None, "__spec__": None})
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,2 @@
|
||||
HYBRIS_REVISION=bc8cb3586b79d208fd21b925fa0209b3e432e008
|
||||
PROTOCOL_REVISION=c6ae3c22a804da3cda017f4c8eaa6c6a3da55457
|
||||
@@ -26,5 +26,10 @@ SSBS=$(syms "$D/libssbs.so")
|
||||
for sym in sigaction signal bsd_signal sysv_signal; do
|
||||
grep -qx "$sym" <<<"$SSBS" || { echo "::error::libssbs.so does not export $sym"; exit 1; }
|
||||
done
|
||||
XCLIPSE=$(syms "$D/usr/local/lib/droiddeck-xclipse/libVkLayer_droiddeck_xclipse.so")
|
||||
for sym in vkNegotiateLoaderLayerInterfaceVersion vkGetInstanceProcAddr vkGetDeviceProcAddr; do
|
||||
grep -qx "$sym" <<<"$XCLIPSE" || { echo "::error::the Xclipse layer does not export $sym"; exit 1; }
|
||||
done
|
||||
test -f "$D/usr/local/lib/droiddeck-xclipse/VkLayer_droiddeck_xclipse.json"
|
||||
test -f "$D/usr/local/bin/droiddeck-session"
|
||||
test -f "$D/usr/local/bin/droiddeck-proton-extra"
|
||||
@@ -6,13 +6,18 @@ if [ -n "${BL_DEBUG_DIR:-}" ]; then
|
||||
fi
|
||||
width=${BL_WIDTH:-1280}
|
||||
height=${BL_HEIGHT:-720}
|
||||
backend=${BL_GAMESCOPE_BACKEND:-wayland}
|
||||
case "$backend" in
|
||||
wayland|sdl) ;;
|
||||
*) echo "== unsupported gamescope backend: $backend" >&2; exit 64 ;;
|
||||
esac
|
||||
window=0
|
||||
if [ "${BL_DESKTOP_GPU_WINDOW:-1}" != 0 ] && [ -n "${WAYLAND_DISPLAY:-}" ] && [ "$WAYLAND_DISPLAY" != wayland-0 ]; then
|
||||
if [ "$backend" = wayland ] && [ "${BL_DESKTOP_GPU_WINDOW:-1}" != 0 ] && [ -n "${WAYLAND_DISPLAY:-}" ] && [ "$WAYLAND_DISPLAY" != wayland-0 ]; then
|
||||
window=1
|
||||
parent=$WAYLAND_DISPLAY
|
||||
args=(--backend sdl --expose-wayland --follow-game-window-mode -W "$width" -H "$height" -w "$width" -h "$height")
|
||||
else
|
||||
args=(--backend wayland --expose-wayland -f -W "$width" -H "$height" -w "$width" -h "$height")
|
||||
args=(--backend "$backend" --expose-wayland -f -W "$width" -H "$height" -w "$width" -h "$height")
|
||||
fi
|
||||
if [ "${BL_FPS:-0}" -gt 0 ]; then
|
||||
args+=(-r "$BL_FPS")
|
||||
@@ -27,6 +32,7 @@ else
|
||||
export WAYLAND_DISPLAY=wayland-0
|
||||
fi
|
||||
export GDK_BACKEND=x11 QT_QPA_PLATFORM=xcb SDL_VIDEODRIVER=x11
|
||||
[ "$backend" = sdl ] && export SDL_VIDEODRIVER=wayland
|
||||
unset LIBGL_ALWAYS_SOFTWARE QT_QUICK_BACKEND KWIN_COMPOSE
|
||||
wsi=",${MESA_VK_WSI_DEBUG:-},"
|
||||
while [[ $wsi == *,sw,* ]]; do wsi=${wsi//,sw,/,}; done
|
||||
@@ -40,7 +46,7 @@ if [ "$window" = 1 ]; then
|
||||
export BL_GPU_CHILD_WSI=${MESA_VK_WSI_DEBUG:-}
|
||||
SDL_VIDEODRIVER=wayland MESA_VK_WSI_DEBUG=sw gamescope "${args[@]}" -- /usr/local/bin/droiddeck-gpu-window "$@"
|
||||
else
|
||||
gamescope "${args[@]}" -- /usr/local/bin/droiddeck-gpu-window "$@"
|
||||
gamescope "${args[@]}" -- env SDL_VIDEODRIVER=x11 /usr/local/bin/droiddeck-gpu-window "$@"
|
||||
fi
|
||||
rc=$?
|
||||
echo "== droiddeck-gpu $(date -u +%H:%M:%S): exited $rc"
|
||||
|
||||
@@ -524,6 +524,15 @@ def apply_config(env, config, app_id, fixes=None):
|
||||
if dxvk:
|
||||
own = result.get("DXVK_CONFIG", "").strip().rstrip(";").strip()
|
||||
result["DXVK_CONFIG"] = own + "; " + dxvk if own else dxvk
|
||||
# An open driver pair (PanVK, RADV) on a GPU that is not an Adreno: vkd3d-proton reports the
|
||||
# driver's own feature level and shader model. The app-wide 12_2 / 6_9 over-promised what PanVK
|
||||
# has, and an Unreal DX12 game took paths that crashed. A game's own setting still wins.
|
||||
if env.get("BL_OPEN_DRIVER") == "1":
|
||||
game = config.get("games", {}).get(app_id, {}) or {}
|
||||
for name in ("VKD3D_FEATURE_LEVEL", "VKD3D_SHADER_MODEL"):
|
||||
if name not in game and name in result:
|
||||
result.pop(name)
|
||||
result["DROIDDECK_VKD3D_CAPS"] = "driver"
|
||||
return result
|
||||
|
||||
|
||||
@@ -995,6 +1004,7 @@ def diagnostic_game_exit(app_id, raw_code, source=None, wrapper_status=None):
|
||||
def start(launch, launch_env, digest, after=None, diagnostic_app_id=None):
|
||||
if len(launch) > 1 and launch[1] == "waitforexitandrun":
|
||||
ubisoft_composition_off(launch[0], launch_env)
|
||||
launch, launch_env = system_graphics_launch(launch, launch_env)
|
||||
if after or diagnostic_app_id is not None:
|
||||
process = subprocess.Popen(launch, env=launch_env)
|
||||
if diagnostic_app_id is not None:
|
||||
@@ -1022,6 +1032,110 @@ def start(launch, launch_env, digest, after=None, diagnostic_app_id=None):
|
||||
return os.execvpe(launch[0], launch, launch_env)
|
||||
|
||||
|
||||
class SystemGraphicsError(ValueError):
|
||||
pass
|
||||
|
||||
|
||||
def system_graphics_launch(command, env):
|
||||
"""Use the APK's PowerVR compatibility files only for actual Proton game launches."""
|
||||
runtime = env.get("DROIDDECK_POWERVR_RUNTIME")
|
||||
if not runtime or not game_id(env) or len(command) < 3 or command[1] != "waitforexitandrun":
|
||||
return command, env
|
||||
directory = Path(runtime)
|
||||
if not directory.is_absolute():
|
||||
raise SystemGraphicsError("system Vulkan runtime path is not absolute")
|
||||
# run-proton.py picks the same payload by name; Xclipse needs a DXVK within 128 bytes of push data.
|
||||
payload = env.get("DROIDDECK_HYBRIS_DXVK") or "dxvk"
|
||||
if not payload.startswith("dxvk") or "/" in payload:
|
||||
raise SystemGraphicsError("invalid DXVK payload name: %s" % payload)
|
||||
required = (
|
||||
"run-proton.py", "wsi/libVkLayer_window_system_integration.so",
|
||||
"wsi/VkLayer_window_system_integration.json", "lib/libVkLayer_hybris_compat.so",
|
||||
*("%s/%s/%s.dll" % (payload, arch, name) for arch in ("x32", "x64")
|
||||
for name in ("d3d8", "d3d9", "d3d10core", "d3d11", "dxgi")),
|
||||
)
|
||||
try:
|
||||
for name in required:
|
||||
path = directory / name
|
||||
if not path.is_file() or not path.stat().st_size:
|
||||
raise SystemGraphicsError("missing system Vulkan component: %s" % name)
|
||||
wrapper = directory / "run-proton.py"
|
||||
if not os.access(wrapper, os.X_OK):
|
||||
raise SystemGraphicsError("system Vulkan Proton wrapper is not executable")
|
||||
except OSError as error:
|
||||
raise SystemGraphicsError("system Vulkan component is unreadable: %s" % error) from error
|
||||
result = dict(env)
|
||||
layers = "VK_LAYER_window_system_integration:" + env.get("DROIDDECK_HYBRIS_LAYERS", "VK_LAYER_HYBRIS_compat")
|
||||
result.update({
|
||||
"HYBRIS_BC_TEXTURES": "dxvk",
|
||||
"VK_LAYER_PATH": ":".join(filter(None, (str(directory / "wsi"), str(directory / "lib"),
|
||||
env.get("DROIDDECK_HYBRIS_LAYER_PATH")))),
|
||||
"VK_INSTANCE_LAYERS": layers,
|
||||
"ENABLE_GAMESCOPE_WSI": "0",
|
||||
"VK_LOADER_LAYERS_DISABLE": "*gamescope*",
|
||||
"DISABLE_VK_LAYER_VALVE_steam_fossilize_1": "1",
|
||||
})
|
||||
for name in ("DISABLE_WSI_LAYER", "PROTON_USE_WINED3D", "ENABLE_VK_LAYER_VALVE_steam_fossilize_1"):
|
||||
result.pop(name, None)
|
||||
return [str(wrapper), *command], result
|
||||
|
||||
|
||||
def game_logs(command, env, app_id, now=None):
|
||||
"""Detailed graphics logs for one game launch, in the session's log folder: Proton's own log,
|
||||
DXVK's and vkd3d-proton's, and the Vulkan driver's startup messages. The app turns this on
|
||||
(BL_GAME_LOGS=1) on a GPU that is not an Adreno, or with Setup's "Detailed graphics logs"."""
|
||||
if env.get("BL_GAME_LOGS") != "1" or not env.get("BL_DEBUG_DIR") or len(command) < 3 \
|
||||
or command[1] != "waitforexitandrun":
|
||||
return env
|
||||
import time
|
||||
stamp = time.strftime("%Y%m%d-%H%M%S", time.localtime(now))
|
||||
name = app_id or re.sub(r"[^A-Za-z0-9._-]+", "_", Path(command[2]).stem)[:40] or "game"
|
||||
parent = Path(env["BL_DEBUG_DIR"]) / "games"
|
||||
try:
|
||||
parent.mkdir(parents=True, exist_ok=True)
|
||||
folder = Path(tempfile.mkdtemp(prefix=stamp + "-", suffix="-" + name, dir=parent))
|
||||
except OSError as error:
|
||||
print("droiddeck-game-env: no game log folder (%s)" % error, file=sys.stderr)
|
||||
return env
|
||||
result = dict(env)
|
||||
result.update({
|
||||
"PROTON_LOG": "1",
|
||||
"PROTON_LOG_DIR": str(folder),
|
||||
"DXVK_LOG_PATH": str(folder),
|
||||
"DXVK_LOG_LEVEL": env.get("DXVK_LOG_LEVEL", "info"),
|
||||
"VKD3D_LOG_FILE": str(folder / "vkd3d.log"),
|
||||
"VKD3D_DEBUG": env.get("VKD3D_DEBUG", "warn"),
|
||||
"VKD3D_SHADER_DEBUG": env.get("VKD3D_SHADER_DEBUG", "none"),
|
||||
"MESA_LOG_FILE": str(folder / "mesa.log"),
|
||||
"PANVK_DEBUG": env.get("PANVK_DEBUG", "startup"),
|
||||
})
|
||||
try:
|
||||
(folder / "launch.txt").write_text("\n".join([
|
||||
"app: %s" % (app_id or "-"),
|
||||
"exe: %s" % command[2],
|
||||
"proton: %s" % command[0],
|
||||
"started: %s" % time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(now)),
|
||||
] + ["%s=%s" % (key, env[key]) for key in sorted(env)
|
||||
if key.startswith(("VK_", "BL_VK", "BL_DRM", "BL_OPEN", "MESA_", "PANVK", "DXVK_", "VKD3D", "ZINK", "TU_", "DROIDDECK_VKD3D"))]) + "\n")
|
||||
except OSError:
|
||||
pass
|
||||
# Whether the game's sound reaches PulseAudio: the streams 20 s and 60 s in, without waiting.
|
||||
try:
|
||||
subprocess.Popen(["sh", "-c", 'for t in 20 40; do sleep $t; { echo "== $(date +%T)"; '
|
||||
'pactl list sink-inputs 2>&1 | head -80; } >> "$1/audio-streams.txt"; done', "audio", str(folder)],
|
||||
stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||
start_new_session=True)
|
||||
except OSError:
|
||||
pass
|
||||
return result
|
||||
|
||||
|
||||
def exec_proton(command, env):
|
||||
# Synchronization selection has already picked the actual Proton executable.
|
||||
command, env = system_graphics_launch(command, env)
|
||||
os.execvpe(command[0], command, env)
|
||||
|
||||
|
||||
def main():
|
||||
command = sys.argv[1:]
|
||||
if not command:
|
||||
@@ -1089,6 +1203,7 @@ def main():
|
||||
print("droiddeck-game-env: OpenGL does not wait for the screen refresh (vblank_mode=0)", file=sys.stderr)
|
||||
if app_id and len(command) > 1 and command[1] == "waitforexitandrun":
|
||||
command = offline_without_anticheat(command, env)
|
||||
env = game_logs(command, env, app_id)
|
||||
if mic_enabled == "0":
|
||||
env["AUDIO_DIRECT_MIC"] = "0"
|
||||
env = directaudio_settings(env)
|
||||
@@ -1165,4 +1280,8 @@ def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
try:
|
||||
sys.exit(main())
|
||||
except SystemGraphicsError as error:
|
||||
print("droiddeck-game-env: PowerVR graphics runtime unavailable (%s)" % error, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
@@ -1,5 +1,15 @@
|
||||
#!/bin/bash
|
||||
set -u
|
||||
# A GPU that is not an Adreno (BL_RAISE_NOFILE=1): the open-files limit goes up to the hard limit
|
||||
# for the whole session tree (gamescope, Steam, games). A Mali PanVK session ran out after ten
|
||||
# minutes ("Too many open files" importing sync files and dma-bufs) and froze.
|
||||
if [ "${BL_RAISE_NOFILE:-0}" = 1 ] && [ -z "${BL_INSIDE:-}" ]; then
|
||||
bl_nofile_was="$(ulimit -Sn)/$(ulimit -Hn)"
|
||||
ulimit -Sn "$(ulimit -Hn)" 2>/dev/null || true
|
||||
echo "== open files: soft/hard $bl_nofile_was -> soft $(ulimit -Sn)"
|
||||
[ -n "${BL_DEBUG_DIR:-}" ] && echo "soft/hard $bl_nofile_was -> soft $(ulimit -Sn) (session tree)" > "$BL_DEBUG_DIR/limits.txt" 2>/dev/null
|
||||
unset bl_nofile_was
|
||||
fi
|
||||
export HOME=${HOME:-/root}
|
||||
mode=${1:-desktop}
|
||||
shift || true
|
||||
@@ -260,18 +270,78 @@ if [ "${BL_VKBRIDGE:-0}" = 1 ]; then
|
||||
unset TU_DEBUG
|
||||
if [ -z "${BL_INSIDE:-}" ]; then
|
||||
step "vkbridge self-test"
|
||||
timeout 60 /usr/local/bin/droiddeck-vkbridge-smoke 2>&1 | sed 's/^/== vkbridge: /'
|
||||
bl_vkb_smoke=$(timeout 60 /usr/local/bin/droiddeck-vkbridge-smoke 2>&1)
|
||||
printf '%s\n' "$bl_vkb_smoke" | sed 's/^/== vkbridge: /'
|
||||
bl_vkb_why=
|
||||
if printf '%s\n' "$bl_vkb_smoke" | grep -qE '^FAIL memory sharing'; then
|
||||
bl_vkb_why=memory
|
||||
elif printf '%s\n' "$bl_vkb_smoke" | grep -qE '^FAIL (image clear|draw)'; then
|
||||
bl_vkb_why=draw
|
||||
fi
|
||||
if [ -n "$bl_vkb_why" ] && [ -r "${BL_VKBRIDGE_FALLBACK_ICD:-}" ]; then
|
||||
export VK_DRIVER_FILES=$BL_VKBRIDGE_FALLBACK_ICD VK_ICD_FILENAMES=$BL_VKBRIDGE_FALLBACK_ICD BL_VKBRIDGE=0
|
||||
export BL_OPEN_DRIVER=1 BL_DRM_STANDIN=/dev/mali0
|
||||
[ "${BL_STEAM_GPU_COMPOSITING:-0}" = 1 ] || export BL_STEAM_SOFT_COMPOSITING=1
|
||||
if [ "$bl_vkb_why" = memory ]; then
|
||||
echo "== vkbridge: memory sharing = none (no method passed the server's self-test); this session uses the PanVK pair instead ($BL_VKBRIDGE_FALLBACK_ICD)"
|
||||
else
|
||||
echo "== vkbridge: self-test failed images or draws; this session uses the PanVK pair instead ($BL_VKBRIDGE_FALLBACK_ICD)"
|
||||
fi
|
||||
[ -n "${BL_DEBUG_DIR:-}" ] && printf '%s\n%s\n' "$BL_VKBRIDGE_FALLBACK_ICD" "$bl_vkb_why" > "$BL_DEBUG_DIR/vkbridge-fallback" 2>/dev/null
|
||||
elif [ -n "$bl_vkb_why" ]; then
|
||||
echo "== vkbridge: self-test failed ($bl_vkb_why) and no PanVK pair is installed to fall back on; expect a black screen or a lost device - set a Mali driver pair in Setup"
|
||||
fi
|
||||
unset bl_vkb_why
|
||||
unset bl_vkb_smoke
|
||||
if command -v vulkaninfo >/dev/null 2>&1; then
|
||||
timeout 30 vulkaninfo --summary 2>&1 | sed -n '/^Devices:/,$p' | head -40 | sed 's/^/== vulkaninfo: /'
|
||||
fi
|
||||
fi
|
||||
echo "== vulkan driver: Mali bridge ($bl_vkb_icd, server at $VKBRIDGE_SOCKET)"
|
||||
[ "${BL_VKBRIDGE:-0}" = 1 ] && echo "== vulkan driver: Mali bridge ($bl_vkb_icd, server at $VKBRIDGE_SOCKET)"
|
||||
else
|
||||
echo "== vulkan driver: Mali bridge requested but NOT usable (icd $bl_vkb_icd, socket ${VKBRIDGE_SOCKET:-unset}; missing:$bl_vkb_missing)"
|
||||
[ -n "${BL_INSIDE:-}" ] || exit 69
|
||||
fi
|
||||
unset bl_vkb_icd bl_vkb_missing
|
||||
fi
|
||||
if [ "${BL_VENUS:-0}" = 1 ] && [ -z "${BL_INSIDE:-}" ] && command -v vulkaninfo >/dev/null 2>&1; then
|
||||
if bl_vn_info=$(timeout 30 vulkaninfo 2>/dev/null); then
|
||||
case $(printf '%s\n' "$bl_vn_info" | grep -m1 'nullDescriptor') in
|
||||
*true*) echo "== venus: nullDescriptor present (Zink keeps the GPU)" ;;
|
||||
*)
|
||||
export GALLIUM_DRIVER=llvmpipe LIBGL_ALWAYS_SOFTWARE=1
|
||||
unset MESA_LOADER_DRIVER_OVERRIDE LIBGL_KOPPER_DRI2
|
||||
echo "== venus: no nullDescriptor on this device even with the Mali compatibility layer; Steam's GL and Xwayland use llvmpipe (software)"
|
||||
;;
|
||||
esac
|
||||
else
|
||||
echo "== venus: vulkaninfo failed or timed out; GL left on Zink"
|
||||
fi
|
||||
unset bl_vn_info
|
||||
fi
|
||||
if [ "${BL_GAME_LOGS:-0}" = 1 ] && [ -z "${BL_INSIDE:-}" ] && [ -n "${BL_DEBUG_DIR:-}" ]; then
|
||||
(
|
||||
{
|
||||
echo "== VK_DRIVER_FILES=${VK_DRIVER_FILES:-} VK_ICD_FILENAMES=${VK_ICD_FILENAMES:-} BL_DRM_STANDIN=${BL_DRM_STANDIN:-}"
|
||||
if command -v vulkaninfo >/dev/null 2>&1; then
|
||||
timeout 10 vulkaninfo --summary
|
||||
echo "== vulkaninfo exit: $?"
|
||||
if timeout 20 vulkaninfo > "$BL_DEBUG_DIR/vulkan-full.txt" 2>&1; then
|
||||
echo "== device extensions (full list in vulkan-full.txt):"
|
||||
sed -n '/^Device Extensions:/,/^$/p' "$BL_DEBUG_DIR/vulkan-full.txt" | grep -o 'VK_[A-Za-z0-9_]*' | sort -u | tr '\n' ' ' | fold -s -w 200
|
||||
echo
|
||||
echo "== key features:"
|
||||
grep -E '^[[:space:]]+(robustBufferAccess2?|robustImageAccess2?|nullDescriptor|logicOp|fillModeNonSolid|shaderClipDistance|shaderCullDistance|dualSrcBlend|geometryShader|scalarBlockLayout|timelineSemaphore|dynamicRendering|synchronization2|maintenance4|maintenance5|maintenance6|shaderDrawParameters|descriptorIndexing|bufferDeviceAddress|vulkanMemoryModel|hostQueryReset|imagelessFramebuffer|samplerYcbcrConversion|shaderInt64|shaderFloat64|shaderInt16|shaderFloat16|storageBuffer16BitAccess|extendedDynamicState[23]?|vertexInputDynamicState|customBorderColors|customBorderColorWithoutFormat|depthClipEnable|multiViewport|textureCompressionBC|indexTypeUint8|rectangularLines|bresenhamLines|transformFeedback|geometryStreams|graphicsPipelineLibrary|pushDescriptor|primitiveTopologyListRestart|dynamicRenderingLocalRead|shaderDemoteToHelperInvocation|subgroupSizeControl|computeFullSubgroups|inlineUniformBlock|pipelineCreationCacheControl) = ' "$BL_DEBUG_DIR/vulkan-full.txt" | sed 's/^[[:space:]]*/ /' | sort -u
|
||||
else
|
||||
echo "== full vulkaninfo failed or timed out (exit $?)"
|
||||
fi
|
||||
else
|
||||
echo "== vulkaninfo is not in this runtime; GPU nodes:"
|
||||
ls -l /dev/kgsl-3d0 /dev/mali0 /dev/dri 2>&1
|
||||
fi
|
||||
} > "$BL_DEBUG_DIR/vulkan-summary.txt" 2>&1
|
||||
) &
|
||||
fi
|
||||
export GAMESCOPE_FORCE_VULKAN_REALTIME=${BL_GAMESCOPE_REALTIME:-0}
|
||||
|
||||
start_agent() {
|
||||
@@ -283,6 +353,38 @@ nap() {
|
||||
[ -n "${bl_nap_fd:-}" ] || exec {bl_nap_fd}<> <(:)
|
||||
read -r -t "$1" -u "$bl_nap_fd" _ 2>/dev/null || :
|
||||
}
|
||||
# Which program a driver error came from: Mesa's lines ("radv/amdgpu: The CS has been rejected",
|
||||
# "ZINK: vkQueueWaitIdle failed") carry no process name. For the first three minutes of an open
|
||||
# driver pair's session, every process that appears goes into processes.txt with the session log's
|
||||
# line count at that moment, so an error's line number in session.log points at what had just
|
||||
# started. Pure bash over /proc (no execs: see nap).
|
||||
watch_processes() {
|
||||
local out=$BL_DEBUG_DIR/processes.txt log=$BL_DEBUG_DIR/session.log i p pid comm lines
|
||||
local -a argv new
|
||||
local -A seen=()
|
||||
echo "# seconds session.log-lines pid name command line" > "$out" 2>/dev/null || return 0
|
||||
for ((i = 0; i < 360; i++)); do
|
||||
new=()
|
||||
for p in /proc/[0-9]*; do
|
||||
pid=${p#/proc/}
|
||||
[ -n "${seen[$pid]:-}" ] && continue
|
||||
seen[$pid]=1
|
||||
read -r comm < "$p/comm" 2>/dev/null || continue
|
||||
argv=()
|
||||
mapfile -d '' -t argv < "$p/cmdline" 2>/dev/null
|
||||
new+=("$pid"$'\t'"$comm"$'\t'"${argv[*]:0:8}")
|
||||
done
|
||||
if [ ${#new[@]} -gt 0 ]; then
|
||||
lines=0
|
||||
[ -r "$log" ] && { mapfile -t argv < "$log"; lines=${#argv[@]}; argv=(); }
|
||||
for p in "${new[@]}"; do printf '%s\t%s\t%.200s\n' "$SECONDS" "$lines" "$p"; done >> "$out"
|
||||
fi
|
||||
nap 0.5
|
||||
done
|
||||
}
|
||||
if [ "${BL_OPEN_DRIVER:-0}" = 1 ] && [ -z "${BL_INSIDE:-}" ] && [ -n "${BL_DEBUG_DIR:-}" ]; then
|
||||
watch_processes &
|
||||
fi
|
||||
export XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}
|
||||
export XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
|
||||
export XDG_CACHE_HOME=${XDG_CACHE_HOME:-$HOME/.cache}
|
||||
@@ -400,6 +502,12 @@ if [ -z "${BL_INSIDE:-}" ]; then
|
||||
echo "== gamescope: games at ${nested}x${nested_h} stretched to the ${width}x${height} output"
|
||||
fi
|
||||
fi
|
||||
backend=${BL_GAMESCOPE_BACKEND:-wayland}
|
||||
case "$backend" in
|
||||
wayland) ;;
|
||||
sdl) export SDL_VIDEODRIVER=wayland ;;
|
||||
*) echo "== unsupported gamescope backend: $backend"; exit 64 ;;
|
||||
esac
|
||||
if [ "$mode" = steam ] && [ "${BL_CURSOR_COMPOSITE:-0}" = 1 ]; then
|
||||
export gamescope_cursor_composite=2
|
||||
fi
|
||||
@@ -410,7 +518,7 @@ if [ -z "${BL_INSIDE:-}" ]; then
|
||||
export gamescope_composite_force=1
|
||||
echo "== gamescope: composites every frame (Mali bridge: the Steam UI flickers on separate planes)"
|
||||
fi
|
||||
args=(--backend wayland --expose-wayland -f -W "$width" -H "$height" -w "$nested" -h "$nested_h")
|
||||
args=(--backend "$backend" --expose-wayland -f -W "$width" -H "$height" -w "$nested" -h "$nested_h")
|
||||
if [ "$nested" != "$width" ] || [ "$nested_h" != "$height" ]; then
|
||||
args+=(-S stretch)
|
||||
export BL_STRETCHED=1
|
||||
@@ -1145,6 +1253,20 @@ case $mode in
|
||||
export STEAM_STEAMRT_RECURSION_GUARD=1
|
||||
export LD_LIBRARY_PATH=$steam_root/steamrtarm64:$steam_root/steamrtarm64/panorama${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
|
||||
export SDL_VIDEO_X11_DGAMOUSE=0
|
||||
bl_steam_path=$PATH
|
||||
bl_steam_angle=vulkan
|
||||
bl_steam_presentation=()
|
||||
if [ "${BL_STEAM_GL_PRESENT:-}" = 1 ]; then
|
||||
bl_steam_path="/usr/local/libexec/droiddeck-steam:$PATH"
|
||||
export DISABLE_GAMESCOPE_WSI=1 LIBGL_KOPPER_DISABLE=true
|
||||
bl_steam_angle=gl
|
||||
bl_steam_presentation=(-cef-disable-gpu-compositing)
|
||||
echo "== steam: system PowerVR uses OpenGL/DRI3 through Zink with software CEF compositing"
|
||||
elif [ "${BL_STEAM_SOFT_COMPOSITING:-}" = 1 ]; then
|
||||
bl_steam_presentation=(-cef-disable-gpu-compositing)
|
||||
echo "== steam: open driver pair - software CEF compositing, GPU raster"
|
||||
fi
|
||||
_bl_cef=(-cef-force-gpu "${bl_steam_presentation[@]}" -cef-use-gl=angle "-cef-use-angle=$bl_steam_angle")
|
||||
decky_loader=$HOME/homebrew/services/PluginLoader
|
||||
if [ -f "$HOME/.droiddeck-decky-enabled" ] && [ -x "$decky_loader" ]; then
|
||||
decky_arch=$(cat "$HOME/homebrew/services/.droiddeck-decky-arch" 2>/dev/null || echo unknown)
|
||||
@@ -1194,7 +1316,9 @@ case $mode in
|
||||
fi
|
||||
_bl_ui=(-gamepadui)
|
||||
[ "${BL_STEAM_UI:-}" = desktop ] && _bl_ui=()
|
||||
_bl_cef=(-cef-force-gpu -cef-use-gl=angle -cef-use-angle=vulkan)
|
||||
# bl_steam_angle / bl_steam_presentation (set above) default to the Adreno values (vulkan,
|
||||
# none); only the system-PowerVR path (BL_STEAM_GL_PRESENT=1) changes them.
|
||||
_bl_cef=(-cef-force-gpu "${bl_steam_presentation[@]}" -cef-use-gl=angle "-cef-use-angle=${bl_steam_angle:-vulkan}")
|
||||
[ "${steam_cef_gpu:-1}" = 1 ] || _bl_cef=(-cef-disable-gpu)
|
||||
if [ "${BL_DESKTOP:-}" = 1 ] && [ "${BL_STEAM_UI:-}" = desktop ]; then
|
||||
_bl_cef=(-cef-disable-gpu)
|
||||
@@ -1547,6 +1671,36 @@ case $mode in
|
||||
done
|
||||
) &
|
||||
stop_watcher=$!
|
||||
if [ "${BL_VENUS:-0}" = 1 ] && [ -x /usr/local/bin/droiddeck-glprobe ] && [ "${GALLIUM_DRIVER:-}" = zink ]; then
|
||||
LIBGL_DEBUG=verbose MESA_LOG_LEVEL=debug timeout 20 /usr/local/bin/droiddeck-glprobe 2>&1 | grep -v drirc | head -60 | sed 's/^/== glprobe: /'
|
||||
if [ "${PIPESTATUS[0]}" = 1 ]; then
|
||||
VK_LOADER_DEBUG=error,warn timeout 20 /usr/local/bin/droiddeck-glprobe 2>&1 | grep -v drirc | head -40 | sed 's/^/== glprobe (loader): /'
|
||||
DROIDDECK_MALI_COMPAT_TRACE=1 MESA_DEBUG=1 MESA_LOG_LEVEL=debug LIBGL_DEBUG=verbose ZINK_DEBUG=mem VN_DEBUG=init,result,log_ctx_info \
|
||||
timeout 30 /usr/local/bin/droiddeck-glprobe > "${BL_DEBUG_DIR:-/tmp}/glprobe-trace.txt" 2>&1
|
||||
grep -v drirc "${BL_DEBUG_DIR:-/tmp}/glprobe-trace.txt" | head -120 | sed 's/^/== glprobe (trace): /'
|
||||
echo "== glprobe (trace): last pre-device query before Zink gave up: $(grep 'droiddeck-mali-compat: trace:' "${BL_DEBUG_DIR:-/tmp}/glprobe-trace.txt" | grep -v 'trace: extensions:' | tail -1)"
|
||||
command -v vulkaninfo >/dev/null 2>&1 && DROIDDECK_MALI_COMPAT_TRACE=1 timeout 20 vulkaninfo --summary 2>&1 | head -40 | sed 's/^/== glprobe (vulkaninfo): /'
|
||||
bl_gl_ok=
|
||||
for bl_variant in "ZINK_DEBUG=" "ZINK_DEBUG= ZINK_DESCRIPTORS=auto" "ZINK_DEBUG= LIBGL_KOPPER_DISABLE=true" "ZINK_DEBUG= DROIDDECK_MALI_COMPAT=0"; do
|
||||
if env $bl_variant timeout 20 /usr/local/bin/droiddeck-glprobe 2>&1 | grep -v drirc | head -20 | sed "s/^/== glprobe ($bl_variant): /"; [ "${PIPESTATUS[0]}" = 0 ]; then
|
||||
bl_gl_ok=$bl_variant
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ -n "$bl_gl_ok" ] && [ "$bl_gl_ok" != "ZINK_DEBUG= DROIDDECK_MALI_COMPAT=0" ]; then
|
||||
for bl_kv in $bl_gl_ok; do
|
||||
case $bl_kv in *=) unset "${bl_kv%=}" ;; *) export "$bl_kv" ;; esac
|
||||
done
|
||||
echo "== venus: GL through Zink starts with: $bl_gl_ok (the Steam client gets that)"
|
||||
else
|
||||
[ -n "$bl_gl_ok" ] && echo "== venus: Zink starts only without the Mali compatibility layer (then without nullDescriptor); not used"
|
||||
export GALLIUM_DRIVER=llvmpipe LIBGL_ALWAYS_SOFTWARE=1
|
||||
unset MESA_LOADER_DRIVER_OVERRIDE LIBGL_KOPPER_DRI2
|
||||
echo "== venus: GL through Zink did not start (see glprobe above); the Steam client's GL uses llvmpipe (software)"
|
||||
fi
|
||||
unset bl_gl_ok bl_variant bl_kv
|
||||
fi
|
||||
fi
|
||||
rm -f "$HOME/.bl-restart-game" "$HOME/.bl-restarted-for"
|
||||
while :; do
|
||||
rm -f "$HOME/.bl-restart-once" "$HOME/.bl-restart-lost"
|
||||
@@ -1572,6 +1726,8 @@ case $mode in
|
||||
desktop_ui_pid=$!
|
||||
fi
|
||||
steam_started=$SECONDS
|
||||
PATH="$bl_steam_path" \
|
||||
BL_STEAM_WEBHELPER="$steam_root/steamrtarm64/steamwebhelper" \
|
||||
"${steam_client[@]}" "${_bl_ui[@]}" "${_bl_cdp[@]}" "${_bl_lang[@]}" -clientbeta "$steam_channel" \
|
||||
-no-cef-sandbox -cef-ozone-platform=x11 "${_bl_cef[@]}" "$@"
|
||||
rc=$?
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
# Staged as taskset in a PATH directory used only by the Steam client.
|
||||
# Valve's ARM64 helper uses `taskset 0x7c /path/to/steamwebhelper ...` and exits
|
||||
# before starting the browser when Android denies sched_setaffinity.
|
||||
set -u
|
||||
if [ "$#" -ge 2 ] && [[ "$1" =~ ^(0[xX])?[0-9a-fA-F]+$ ]] &&
|
||||
[ -n "${BL_STEAM_WEBHELPER:-}" ] && [ "$2" -ef "$BL_STEAM_WEBHELPER" ]; then
|
||||
mask=$1
|
||||
shift
|
||||
# Pin this wrapper before exec; never retry a helper that has already run.
|
||||
if ! /usr/bin/taskset -p "$mask" "$$" >/dev/null 2>&1; then
|
||||
echo "droiddeck: Steam helper CPU pinning unavailable; using the allowed CPUs" >&2
|
||||
fi
|
||||
exec -- "$@"
|
||||
fi
|
||||
# Queries, existing-process changes, and other programs retain taskset's behavior.
|
||||
exec /usr/bin/taskset "$@"
|
||||
@@ -174,6 +174,9 @@ bl_components() {
|
||||
local -A cm_sums=()
|
||||
while IFS=$'\\t' read -r scope t want comp rel sum src; do
|
||||
[ -n "$scope" ] || continue
|
||||
# The selected system PowerVR runtime supplies DXVK at launch. Keep saved selections
|
||||
# for a later manual-driver session without rewriting this Proton's bundled files now.
|
||||
[ "$comp" = dxvk ] && [ -n "${DROIDDECK_POWERVR_RUNTIME:-}" ] && continue
|
||||
cm_rows+=("$comp"$'\\t'"$rel"$'\\t'"$sum"$'\\t'"$src")
|
||||
[ "$src" != "-" ] && [ -f "$base/$rel" ] && cm_files+=("$base/$rel")
|
||||
done <<< "$cm_selected"
|
||||
|
||||
+159
-24
@@ -4,6 +4,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
@@ -12,6 +13,10 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#define MAX_HANDLES 4096
|
||||
#ifndef F_DUPFD_QUERY
|
||||
#define F_DUPFD_QUERY 1027
|
||||
#endif
|
||||
#define PVR_HANDLE_BIT UINT32_C(0x80000000)
|
||||
|
||||
struct gem_close {
|
||||
uint32_t handle;
|
||||
@@ -23,11 +28,14 @@ struct handle_entry {
|
||||
uint32_t handle;
|
||||
int dma_fd;
|
||||
int drm_fd;
|
||||
int owned_drm_fd; /* PowerVR: pin the open file description, not its reusable fd number. */
|
||||
int powervr;
|
||||
};
|
||||
|
||||
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static struct handle_entry handle_entries[MAX_HANDLES];
|
||||
static uint32_t next_handle = 1;
|
||||
static uint32_t next_pvr_handle = PVR_HANDLE_BIT;
|
||||
static dev_t kgsl_dev;
|
||||
static int kgsl_state;
|
||||
|
||||
@@ -37,12 +45,40 @@ static int is_kgsl(int fd) {
|
||||
if (kgsl_state == 0) {
|
||||
const char *standin = getenv("BL_DRM_STANDIN");
|
||||
kgsl_state = stat("/dev/kgsl-3d0", &st) == 0 || (standin && *standin && stat(standin, &st) == 0) ? 1 : -1;
|
||||
kgsl_dev = st.st_rdev;
|
||||
if (kgsl_state > 0) kgsl_dev = st.st_rdev;
|
||||
}
|
||||
pthread_mutex_unlock(&lock);
|
||||
return kgsl_state > 0 && fstat(fd, &st) == 0 && S_ISCHR(st.st_mode) && st.st_rdev == kgsl_dev;
|
||||
}
|
||||
|
||||
/* Keep the opt-in separate from GPU detection: manual ICDs must retain native DRM behavior. */
|
||||
struct bl_drm_version {
|
||||
int major, minor, patch;
|
||||
size_t name_len;
|
||||
char *name;
|
||||
size_t date_len;
|
||||
char *date;
|
||||
size_t desc_len;
|
||||
char *desc;
|
||||
};
|
||||
#define BL_DRM_VERSION _IOWR('d', 0x00, struct bl_drm_version)
|
||||
|
||||
static int is_powervr(int fd) {
|
||||
const char *enabled = getenv("BL_POWERVR_DRM_HANDLES");
|
||||
if (!enabled || strcmp(enabled, "1")) return 0;
|
||||
const char *path = getenv("BL_POWERVR_RENDER_NODE");
|
||||
if (!path || !*path) return 0;
|
||||
struct stat node, candidate;
|
||||
if (stat(path, &node) || fstat(fd, &candidate) ||
|
||||
!S_ISCHR(candidate.st_mode) || !S_ISCHR(node.st_mode) ||
|
||||
candidate.st_rdev != node.st_rdev) return 0;
|
||||
char name[16] = {0};
|
||||
struct bl_drm_version version = {.name_len = sizeof(name) - 1, .name = name};
|
||||
/* Bypass the preload's ioctl dispatcher to avoid recursively entering this hook. */
|
||||
return syscall(SYS_ioctl, fd, BL_DRM_VERSION, &version) == 0 &&
|
||||
version.name_len == 3 && !memcmp(name, "pvr", 3);
|
||||
}
|
||||
|
||||
static void *real(const char *name) {
|
||||
void *fn = dlsym(RTLD_NEXT, name);
|
||||
if (!fn) {
|
||||
@@ -89,21 +125,86 @@ static int same_file_description(int a, int b) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Android kernels before 6.10 have no F_DUPFD_QUERY, while the app seccomp policy blocks kcmp.
|
||||
* F_SETOWN_EX updates the open file description, so a duplicate observes a temporary owner marker
|
||||
* and an independent open of the same render node does not. Restore the original owner before
|
||||
* returning; no signal is armed because these DRM descriptors do not have O_ASYNC set.
|
||||
*/
|
||||
static int same_owner_description(int owned, int fd) {
|
||||
struct f_owner_ex original_owned, original_fd, observed;
|
||||
if (fcntl(owned, F_GETOWN_EX, &original_owned) < 0 ||
|
||||
fcntl(fd, F_GETOWN_EX, &original_fd) < 0) {
|
||||
return -1;
|
||||
}
|
||||
const struct f_owner_ex candidates[] = {
|
||||
{.type = F_OWNER_TID, .pid = getpid()},
|
||||
{.type = F_OWNER_PID, .pid = getpid()},
|
||||
{.type = F_OWNER_PGRP, .pid = getpgrp()},
|
||||
};
|
||||
const struct f_owner_ex *marker = NULL;
|
||||
for (size_t i = 0; i < sizeof(candidates) / sizeof(candidates[0]); i++) {
|
||||
if (candidates[i].type != original_fd.type || candidates[i].pid != original_fd.pid) {
|
||||
marker = &candidates[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!marker || fcntl(owned, F_SETOWN_EX, marker) < 0) return -1;
|
||||
int observed_result = fcntl(fd, F_GETOWN_EX, &observed);
|
||||
int observed_errno = errno;
|
||||
int restore_result = fcntl(owned, F_SETOWN_EX, &original_owned);
|
||||
int restore_errno = errno;
|
||||
if (restore_result < 0) {
|
||||
errno = restore_errno;
|
||||
return -1;
|
||||
}
|
||||
if (observed_result < 0) {
|
||||
errno = observed_errno;
|
||||
return -1;
|
||||
}
|
||||
return observed.type == marker->type && observed.pid == marker->pid;
|
||||
}
|
||||
|
||||
static int same_owned_description(int owned, int fd) {
|
||||
int saved_errno = errno;
|
||||
int result = fcntl(owned, F_DUPFD_QUERY, fd);
|
||||
if (result >= 0) {
|
||||
errno = saved_errno;
|
||||
return result == 1;
|
||||
}
|
||||
#ifdef SYS_kcmp
|
||||
long compared = syscall(SYS_kcmp, getpid(), getpid(), 0 /* KCMP_FILE */, owned, fd);
|
||||
if (compared >= 0) {
|
||||
errno = saved_errno;
|
||||
return compared == 0;
|
||||
}
|
||||
#endif
|
||||
int owner_match = same_owner_description(owned, fd);
|
||||
errno = saved_errno;
|
||||
return owner_match == 1;
|
||||
}
|
||||
|
||||
static int find_handle_locked(int fd, uint32_t handle) {
|
||||
for (int i = 0; i < MAX_HANDLES; i++) {
|
||||
if (handle_entries[i].handle == handle &&
|
||||
same_file_description(handle_entries[i].drm_fd, fd)) {
|
||||
(handle_entries[i].powervr
|
||||
? same_owned_description(handle_entries[i].owned_drm_fd, fd)
|
||||
: same_file_description(handle_entries[i].drm_fd, fd))) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static uint32_t alloc_handle_locked(void) {
|
||||
static uint32_t alloc_handle_locked(int powervr) {
|
||||
for (int tries = 0; tries <= MAX_HANDLES; tries++) {
|
||||
uint32_t candidate = next_handle++;
|
||||
if (next_handle == 0) {
|
||||
next_handle = 1;
|
||||
uint32_t candidate;
|
||||
if (powervr) {
|
||||
candidate = next_pvr_handle++;
|
||||
if (!(next_pvr_handle & PVR_HANDLE_BIT)) next_pvr_handle = PVR_HANDLE_BIT;
|
||||
} else {
|
||||
candidate = next_handle++;
|
||||
if (next_handle == PVR_HANDLE_BIT) next_handle = 1;
|
||||
}
|
||||
if (candidate == 0) {
|
||||
continue;
|
||||
@@ -123,25 +224,49 @@ static uint32_t alloc_handle_locked(void) {
|
||||
}
|
||||
|
||||
int drmPrimeFDToHandle(int fd, int prime_fd, uint32_t *handle) {
|
||||
if (!is_kgsl(fd)) {
|
||||
int kgsl = is_kgsl(fd);
|
||||
int powervr = !kgsl && is_powervr(fd);
|
||||
if (!kgsl) {
|
||||
int (*fn)(int, int, uint32_t *) = (int (*)(int, int, uint32_t *)) real("drmPrimeFDToHandle");
|
||||
return fn ? fn(fd, prime_fd, handle) : -ENOSYS;
|
||||
if (!fn) return -ENOSYS;
|
||||
int result = fn(fd, prime_fd, handle);
|
||||
if (!result || !powervr || errno != EINVAL) return result;
|
||||
}
|
||||
if (!handle) { errno = EINVAL; return -EINVAL; }
|
||||
int owner = -1;
|
||||
if (powervr) {
|
||||
owner = fcntl(fd, F_DUPFD_CLOEXEC, 0);
|
||||
if (owner < 0) return -errno;
|
||||
/* The old-kernel owner probe mutates shared OFD state briefly; serialize it with lookups. */
|
||||
pthread_mutex_lock(&lock);
|
||||
int owner_matches = same_owned_description(owner, fd);
|
||||
pthread_mutex_unlock(&lock);
|
||||
if (!owner_matches) {
|
||||
close(owner);
|
||||
errno = EOPNOTSUPP;
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
}
|
||||
int dup_fd = fcntl(prime_fd, F_DUPFD_CLOEXEC, 0);
|
||||
if (dup_fd < 0) {
|
||||
return -errno;
|
||||
int error = errno;
|
||||
if (owner >= 0) close(owner);
|
||||
errno = error;
|
||||
return -error;
|
||||
}
|
||||
int ret = -ENOMEM;
|
||||
pthread_mutex_lock(&lock);
|
||||
for (int i = 0; i < MAX_HANDLES; i++) {
|
||||
if (handle_entries[i].handle == 0) {
|
||||
uint32_t token = alloc_handle_locked();
|
||||
uint32_t token = alloc_handle_locked(powervr);
|
||||
if (!token) {
|
||||
break;
|
||||
}
|
||||
handle_entries[i].handle = token;
|
||||
handle_entries[i].dma_fd = dup_fd;
|
||||
handle_entries[i].drm_fd = fd;
|
||||
handle_entries[i].owned_drm_fd = owner;
|
||||
handle_entries[i].powervr = powervr;
|
||||
*handle = token;
|
||||
ret = 0;
|
||||
break;
|
||||
@@ -150,24 +275,32 @@ int drmPrimeFDToHandle(int fd, int prime_fd, uint32_t *handle) {
|
||||
pthread_mutex_unlock(&lock);
|
||||
if (ret) {
|
||||
close(dup_fd);
|
||||
if (owner >= 0) close(owner);
|
||||
errno = -ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags, int *prime_fd) {
|
||||
if (!is_kgsl(fd)) {
|
||||
int (*fn)(int, uint32_t, uint32_t, int *) = (int (*)(int, uint32_t, uint32_t, int *)) real("drmPrimeHandleToFD");
|
||||
return fn ? fn(fd, handle, flags, prime_fd) : -ENOSYS;
|
||||
}
|
||||
int kgsl = is_kgsl(fd);
|
||||
int ret = -EINVAL;
|
||||
pthread_mutex_lock(&lock);
|
||||
int index = find_handle_locked(fd, handle);
|
||||
if (index >= 0) {
|
||||
*prime_fd = fcntl(handle_entries[index].dma_fd, F_DUPFD_CLOEXEC, 0);
|
||||
ret = *prime_fd < 0 ? -errno : 0;
|
||||
if (!prime_fd || (handle_entries[index].powervr && (flags & ~(O_CLOEXEC | O_RDWR)))) {
|
||||
errno = EINVAL;
|
||||
} else {
|
||||
int command = handle_entries[index].powervr && !(flags & O_CLOEXEC) ? F_DUPFD : F_DUPFD_CLOEXEC;
|
||||
*prime_fd = fcntl(handle_entries[index].dma_fd, command, 0);
|
||||
ret = *prime_fd < 0 ? -errno : 0;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&lock);
|
||||
return ret;
|
||||
if (index >= 0 || kgsl) return ret;
|
||||
/* Unknown handles (including real PowerVR GEM handles) retain kernel semantics. */
|
||||
int (*fn)(int, uint32_t, uint32_t, int *) =
|
||||
(int (*)(int, uint32_t, uint32_t, int *)) real("drmPrimeHandleToFD");
|
||||
return fn ? fn(fd, handle, flags, prime_fd) : -ENOSYS;
|
||||
}
|
||||
|
||||
static int release_handle(int fd, uint32_t handle) {
|
||||
@@ -176,6 +309,7 @@ static int release_handle(int fd, uint32_t handle) {
|
||||
int index = find_handle_locked(fd, handle);
|
||||
if (index >= 0) {
|
||||
close(handle_entries[index].dma_fd);
|
||||
if (handle_entries[index].powervr) close(handle_entries[index].owned_drm_fd);
|
||||
handle_entries[index] = (struct handle_entry){0};
|
||||
found = 1;
|
||||
}
|
||||
@@ -184,22 +318,23 @@ static int release_handle(int fd, uint32_t handle) {
|
||||
}
|
||||
|
||||
int drmCloseBufferHandle(int fd, uint32_t handle) {
|
||||
if (!is_kgsl(fd)) {
|
||||
int (*fn)(int, uint32_t) = (int (*)(int, uint32_t)) real("drmCloseBufferHandle");
|
||||
return fn ? fn(fd, handle) : -ENOSYS;
|
||||
}
|
||||
return release_handle(fd, handle) ? 0 : -EINVAL;
|
||||
if (release_handle(fd, handle)) return 0;
|
||||
if (is_kgsl(fd)) { errno = EINVAL; return -EINVAL; }
|
||||
int (*fn)(int, uint32_t) = (int (*)(int, uint32_t)) real("drmCloseBufferHandle");
|
||||
return fn ? fn(fd, handle) : -ENOSYS;
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden"))) int bl_drm_gem_close(int fd, unsigned long request, void *arg, int *rc) {
|
||||
if (request != GEM_CLOSE || !arg || !is_kgsl(fd)) {
|
||||
if (request != GEM_CLOSE || !arg) {
|
||||
return 0;
|
||||
}
|
||||
if (release_handle(fd, ((struct gem_close *) arg)->handle)) {
|
||||
*rc = 0;
|
||||
} else {
|
||||
} else if (is_kgsl(fd)) {
|
||||
errno = EINVAL;
|
||||
*rc = -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -596,6 +596,8 @@ static FILE *synthesize(const char *table) {
|
||||
|
||||
int bl_status_without_tracer(const char *path, int flags, const void *caller) __attribute__((visibility("hidden")));
|
||||
|
||||
const char *bl_oom_adj_redirect(const char *path, int writing) __attribute__((visibility("hidden")));
|
||||
|
||||
static FILE *open_stream(fopen_fn real, const char *path, const char *mode, const void *caller) {
|
||||
int status = mode && mode[0] == 'r' && !strchr(mode, '+')
|
||||
? bl_status_without_tracer(path, O_RDONLY | O_CLOEXEC, caller) : -1;
|
||||
@@ -604,6 +606,7 @@ static FILE *open_stream(fopen_fn real, const char *path, const char *mode, cons
|
||||
if (copy == NULL) close(status);
|
||||
return copy;
|
||||
}
|
||||
path = bl_oom_adj_redirect(path, mode && (mode[0] == 'w' || mode[0] == 'a' || strchr(mode, '+')));
|
||||
int table = path && mode && mode[0] == 'r' ? denied_table(path) : -1;
|
||||
FILE *f;
|
||||
if (table >= 0 && denied_recently(table, path) && (f = synthesize(net_tables[table])) != NULL) return f;
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Based on jdmg28's DroidDeck-Mali fork (commit 6be00e00, GPL-3.0): steam-launch-wrapper runs every
|
||||
* game with --oom-score-adjust 900. Android's lmkd reads 900 as CACHED_APP_MIN_ADJ and kills the
|
||||
* foreground game first when memory runs short; on Linux 6.1 the raise also becomes the process's
|
||||
* permanent minimum. An app's processes cannot go below the score they inherit, so the only writes
|
||||
* that succeed from in here are raises: every write-open of an oom_score_adj file goes to /dev/null.
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static int is_oom_score_adj(const char *path) {
|
||||
if (path == NULL || strncmp(path, "/proc/", 6) != 0) return 0;
|
||||
const char *p = path + 6;
|
||||
if (strncmp(p, "self/", 5) == 0) {
|
||||
p += 5;
|
||||
} else if (strncmp(p, "thread-self/", 12) == 0) {
|
||||
p += 12;
|
||||
} else {
|
||||
const char *digits = p;
|
||||
while (*p >= '0' && *p <= '9') p++;
|
||||
if (p == digits || *p != '/') return 0;
|
||||
p++;
|
||||
if (strncmp(p, "task/", 5) == 0) {
|
||||
p += 5;
|
||||
digits = p;
|
||||
while (*p >= '0' && *p <= '9') p++;
|
||||
if (p == digits || *p != '/') return 0;
|
||||
p++;
|
||||
}
|
||||
}
|
||||
return strcmp(p, "oom_score_adj") == 0 || strcmp(p, "oom_adj") == 0;
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden"))) const char *bl_oom_adj_redirect(const char *path, int writing) {
|
||||
static int logged;
|
||||
if (!writing || !is_oom_score_adj(path)) return path;
|
||||
if (!__atomic_exchange_n(&logged, 1, __ATOMIC_RELAXED)) {
|
||||
static const char msg[] = "droiddeck: an oom_score_adj raise was dropped (Android would treat this program as a cached app)\n";
|
||||
int saved = errno;
|
||||
ssize_t ignored = write(STDERR_FILENO, msg, sizeof(msg) - 1);
|
||||
(void)ignored;
|
||||
errno = saved;
|
||||
}
|
||||
return "/dev/null";
|
||||
}
|
||||
@@ -14,6 +14,7 @@
|
||||
int bl_status_without_tracer(const char *path, int flags, const void *caller) __attribute__((visibility("hidden")));
|
||||
int bl_writable_retry(int dirfd, const char *path, int flags) __attribute__((visibility("hidden")));
|
||||
int bl_ntsync_open(const char *path, int flags) __attribute__((visibility("hidden")));
|
||||
const char *bl_oom_adj_redirect(const char *path, int writing) __attribute__((visibility("hidden")));
|
||||
int bl_venc_open(const char *path, int flags) __attribute__((visibility("hidden")));
|
||||
int bl_vdec_open(const char *path, int flags) __attribute__((visibility("hidden")));
|
||||
int bl_dircache_create(int dirfd, const char *path, int flags, mode_t mode,
|
||||
@@ -53,6 +54,7 @@ int open(const char *path, int flags, ...) {
|
||||
errno = EACCES;
|
||||
return -1;
|
||||
}
|
||||
path = bl_oom_adj_redirect(path, (flags & O_ACCMODE) != O_RDONLY);
|
||||
if ((fd = bl_status_without_tracer(path, flags, __builtin_return_address(0))) >= 0) return fd;
|
||||
if ((fd = bl_ntsync_open(path, flags)) != -2) return fd;
|
||||
if ((fd = bl_venc_open(path, flags)) != -2) return fd;
|
||||
@@ -80,6 +82,7 @@ int openat(int dirfd, const char *path, int flags, ...) {
|
||||
errno = EACCES;
|
||||
return -1;
|
||||
}
|
||||
path = bl_oom_adj_redirect(path, (flags & O_ACCMODE) != O_RDONLY);
|
||||
if ((fd = bl_status_without_tracer(path, flags, __builtin_return_address(0))) >= 0) return fd;
|
||||
if ((fd = bl_ntsync_open(path, flags)) != -2) return fd;
|
||||
if ((fd = bl_venc_open(path, flags)) != -2) return fd;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Zink keeps kopper when the session draws through Venus.
|
||||
*
|
||||
* On Mali the session reaches the GPU through Venus over vtest, and Xwayland has no DRM node to
|
||||
* build glamor on, so it offers no DRI3. Without DRI3, Zink can only present through kopper (its
|
||||
* Vulkan WSI path). Steam's steamwebhelper.sh exports LIBGL_KOPPER_DISABLE=true for the client
|
||||
* interface unconditionally, so on Mali every GL context the interface asked for failed and the
|
||||
* webhelper restarted until Steam gave up on GPU acceleration. Steam restores that script when
|
||||
* it verifies its install, so the variable is dropped here instead, before Mesa reads it.
|
||||
*/
|
||||
#define _GNU_SOURCE 1
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
__attribute__((constructor)) static void bl_venus_keep_kopper(void) {
|
||||
const char *debug = getenv("VN_DEBUG");
|
||||
if (debug && strstr(debug, "vtest")) unsetenv("LIBGL_KOPPER_DISABLE");
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"file_format_version": "1.2.0",
|
||||
"layer": {
|
||||
"name": "VK_LAYER_DROIDDECK_xclipse",
|
||||
"type": "GLOBAL",
|
||||
"library_path": "./libVkLayer_droiddeck_xclipse.so",
|
||||
"api_version": "1.3.0",
|
||||
"implementation_version": "1",
|
||||
"description": "Workarounds for Samsung Xclipse drivers loaded through libhybris"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
/* Generated by gen_device_chain.py from Vulkan-Headers 1.3.275; do not edit. */
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_DEVICE_DEVICE_MEMORY_REPORT_CREATE_INFO_EXT, VkDeviceDeviceMemoryReportCreateInfoEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_DEVICE_DIAGNOSTICS_CONFIG_CREATE_INFO_NV, VkDeviceDiagnosticsConfigCreateInfoNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_DEVICE_GROUP_DEVICE_CREATE_INFO, VkDeviceGroupDeviceCreateInfo)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_DEVICE_MEMORY_OVERALLOCATION_CREATE_INFO_AMD, VkDeviceMemoryOverallocationCreateInfoAMD)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_DEVICE_PRIVATE_DATA_CREATE_INFO, VkDevicePrivateDataCreateInfo)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_DEVICE_QUEUE_SHADER_CORE_CONTROL_CREATE_INFO_ARM, VkDeviceQueueShaderCoreControlCreateInfoARM)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES, VkPhysicalDevice16BitStorageFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_4444_FORMATS_FEATURES_EXT, VkPhysicalDevice4444FormatsFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES, VkPhysicalDevice8BitStorageFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_FEATURES_KHR, VkPhysicalDeviceAccelerationStructureFeaturesKHR)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ADDRESS_BINDING_REPORT_FEATURES_EXT, VkPhysicalDeviceAddressBindingReportFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_AMIGO_PROFILING_FEATURES_SEC, VkPhysicalDeviceAmigoProfilingFeaturesSEC)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ASTC_DECODE_FEATURES_EXT, VkPhysicalDeviceASTCDecodeFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ATTACHMENT_FEEDBACK_LOOP_DYNAMIC_STATE_FEATURES_EXT, VkPhysicalDeviceAttachmentFeedbackLoopDynamicStateFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ATTACHMENT_FEEDBACK_LOOP_LAYOUT_FEATURES_EXT, VkPhysicalDeviceAttachmentFeedbackLoopLayoutFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT, VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BORDER_COLOR_SWIZZLE_FEATURES_EXT, VkPhysicalDeviceBorderColorSwizzleFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES, VkPhysicalDeviceBufferDeviceAddressFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT, VkPhysicalDeviceBufferDeviceAddressFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CLUSTER_CULLING_SHADER_FEATURES_HUAWEI, VkPhysicalDeviceClusterCullingShaderFeaturesHUAWEI)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COHERENT_MEMORY_FEATURES_AMD, VkPhysicalDeviceCoherentMemoryFeaturesAMD)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COLOR_WRITE_ENABLE_FEATURES_EXT, VkPhysicalDeviceColorWriteEnableFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV, VkPhysicalDeviceComputeShaderDerivativesFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT, VkPhysicalDeviceConditionalRenderingFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COOPERATIVE_MATRIX_FEATURES_KHR, VkPhysicalDeviceCooperativeMatrixFeaturesKHR)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COOPERATIVE_MATRIX_FEATURES_NV, VkPhysicalDeviceCooperativeMatrixFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COPY_MEMORY_INDIRECT_FEATURES_NV, VkPhysicalDeviceCopyMemoryIndirectFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CORNER_SAMPLED_IMAGE_FEATURES_NV, VkPhysicalDeviceCornerSampledImageFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COVERAGE_REDUCTION_MODE_FEATURES_NV, VkPhysicalDeviceCoverageReductionModeFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUBIC_CLAMP_FEATURES_QCOM, VkPhysicalDeviceCubicClampFeaturesQCOM)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUBIC_WEIGHTS_FEATURES_QCOM, VkPhysicalDeviceCubicWeightsFeaturesQCOM)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUDA_KERNEL_LAUNCH_FEATURES_NV, VkPhysicalDeviceCudaKernelLaunchFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT, VkPhysicalDeviceCustomBorderColorFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEDICATED_ALLOCATION_IMAGE_ALIASING_FEATURES_NV, VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_BIAS_CONTROL_FEATURES_EXT, VkPhysicalDeviceDepthBiasControlFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLAMP_ZERO_ONE_FEATURES_EXT, VkPhysicalDeviceDepthClampZeroOneFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_CONTROL_FEATURES_EXT, VkPhysicalDeviceDepthClipControlFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT, VkPhysicalDeviceDepthClipEnableFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_BUFFER_FEATURES_EXT, VkPhysicalDeviceDescriptorBufferFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES, VkPhysicalDeviceDescriptorIndexingFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_POOL_OVERALLOCATION_FEATURES_NV, VkPhysicalDeviceDescriptorPoolOverallocationFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_SET_HOST_MAPPING_FEATURES_VALVE, VkPhysicalDeviceDescriptorSetHostMappingFeaturesVALVE)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEVICE_GENERATED_COMMANDS_COMPUTE_FEATURES_NV, VkPhysicalDeviceDeviceGeneratedCommandsComputeFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEVICE_GENERATED_COMMANDS_FEATURES_NV, VkPhysicalDeviceDeviceGeneratedCommandsFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEVICE_MEMORY_REPORT_FEATURES_EXT, VkPhysicalDeviceDeviceMemoryReportFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DIAGNOSTICS_CONFIG_FEATURES_NV, VkPhysicalDeviceDiagnosticsConfigFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_FEATURES, VkPhysicalDeviceDynamicRenderingFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_UNUSED_ATTACHMENTS_FEATURES_EXT, VkPhysicalDeviceDynamicRenderingUnusedAttachmentsFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXCLUSIVE_SCISSOR_FEATURES_NV, VkPhysicalDeviceExclusiveScissorFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_2_FEATURES_EXT, VkPhysicalDeviceExtendedDynamicState2FeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_3_FEATURES_EXT, VkPhysicalDeviceExtendedDynamicState3FeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT, VkPhysicalDeviceExtendedDynamicStateFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_SPARSE_ADDRESS_SPACE_FEATURES_NV, VkPhysicalDeviceExtendedSparseAddressSpaceFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_RDMA_FEATURES_NV, VkPhysicalDeviceExternalMemoryRDMAFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FAULT_FEATURES_EXT, VkPhysicalDeviceFaultFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, VkPhysicalDeviceFeatures2)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_DENSITY_MAP_2_FEATURES_EXT, VkPhysicalDeviceFragmentDensityMap2FeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_DENSITY_MAP_FEATURES_EXT, VkPhysicalDeviceFragmentDensityMapFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_DENSITY_MAP_OFFSET_FEATURES_QCOM, VkPhysicalDeviceFragmentDensityMapOffsetFeaturesQCOM)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADER_BARYCENTRIC_FEATURES_KHR, VkPhysicalDeviceFragmentShaderBarycentricFeaturesKHR)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADER_INTERLOCK_FEATURES_EXT, VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADING_RATE_ENUMS_FEATURES_NV, VkPhysicalDeviceFragmentShadingRateEnumsFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADING_RATE_FEATURES_KHR, VkPhysicalDeviceFragmentShadingRateFeaturesKHR)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAME_BOUNDARY_FEATURES_EXT, VkPhysicalDeviceFrameBoundaryFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GLOBAL_PRIORITY_QUERY_FEATURES_KHR, VkPhysicalDeviceGlobalPriorityQueryFeaturesKHR)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GRAPHICS_PIPELINE_LIBRARY_FEATURES_EXT, VkPhysicalDeviceGraphicsPipelineLibraryFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_IMAGE_COPY_FEATURES_EXT, VkPhysicalDeviceHostImageCopyFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES, VkPhysicalDeviceHostQueryResetFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES, VkPhysicalDeviceImagelessFramebufferFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_2D_VIEW_OF_3D_FEATURES_EXT, VkPhysicalDeviceImage2DViewOf3DFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_COMPRESSION_CONTROL_FEATURES_EXT, VkPhysicalDeviceImageCompressionControlFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN_FEATURES_EXT, VkPhysicalDeviceImageCompressionControlSwapchainFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_PROCESSING_2_FEATURES_QCOM, VkPhysicalDeviceImageProcessing2FeaturesQCOM)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_PROCESSING_FEATURES_QCOM, VkPhysicalDeviceImageProcessingFeaturesQCOM)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_ROBUSTNESS_FEATURES, VkPhysicalDeviceImageRobustnessFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_SLICED_VIEW_OF_3D_FEATURES_EXT, VkPhysicalDeviceImageSlicedViewOf3DFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_VIEW_MIN_LOD_FEATURES_EXT, VkPhysicalDeviceImageViewMinLodFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT, VkPhysicalDeviceIndexTypeUint8FeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INHERITED_VIEWPORT_SCISSOR_FEATURES_NV, VkPhysicalDeviceInheritedViewportScissorFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES, VkPhysicalDeviceInlineUniformBlockFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INVOCATION_MASK_FEATURES_HUAWEI, VkPhysicalDeviceInvocationMaskFeaturesHUAWEI)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LEGACY_DITHERING_FEATURES_EXT, VkPhysicalDeviceLegacyDitheringFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINEAR_COLOR_ATTACHMENT_FEATURES_NV, VkPhysicalDeviceLinearColorAttachmentFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT, VkPhysicalDeviceLineRasterizationFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_4_FEATURES, VkPhysicalDeviceMaintenance4Features)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_5_FEATURES_KHR, VkPhysicalDeviceMaintenance5FeaturesKHR)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_6_FEATURES_KHR, VkPhysicalDeviceMaintenance6FeaturesKHR)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_DECOMPRESSION_FEATURES_NV, VkPhysicalDeviceMemoryDecompressionFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PRIORITY_FEATURES_EXT, VkPhysicalDeviceMemoryPriorityFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MESH_SHADER_FEATURES_EXT, VkPhysicalDeviceMeshShaderFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MESH_SHADER_FEATURES_NV, VkPhysicalDeviceMeshShaderFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTISAMPLED_RENDER_TO_SINGLE_SAMPLED_FEATURES_EXT, VkPhysicalDeviceMultisampledRenderToSingleSampledFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES, VkPhysicalDeviceMultiviewFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PER_VIEW_RENDER_AREAS_FEATURES_QCOM, VkPhysicalDeviceMultiviewPerViewRenderAreasFeaturesQCOM)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PER_VIEW_VIEWPORTS_FEATURES_QCOM, VkPhysicalDeviceMultiviewPerViewViewportsFeaturesQCOM)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTI_DRAW_FEATURES_EXT, VkPhysicalDeviceMultiDrawFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MUTABLE_DESCRIPTOR_TYPE_FEATURES_EXT, VkPhysicalDeviceMutableDescriptorTypeFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_NESTED_COMMAND_BUFFER_FEATURES_EXT, VkPhysicalDeviceNestedCommandBufferFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_NON_SEAMLESS_CUBE_MAP_FEATURES_EXT, VkPhysicalDeviceNonSeamlessCubeMapFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_OPACITY_MICROMAP_FEATURES_EXT, VkPhysicalDeviceOpacityMicromapFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_OPTICAL_FLOW_FEATURES_NV, VkPhysicalDeviceOpticalFlowFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PAGEABLE_DEVICE_LOCAL_MEMORY_FEATURES_EXT, VkPhysicalDevicePageableDeviceLocalMemoryFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PERFORMANCE_QUERY_FEATURES_KHR, VkPhysicalDevicePerformanceQueryFeaturesKHR)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PER_STAGE_DESCRIPTOR_SET_FEATURES_NV, VkPhysicalDevicePerStageDescriptorSetFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_CREATION_CACHE_CONTROL_FEATURES, VkPhysicalDevicePipelineCreationCacheControlFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_EXECUTABLE_PROPERTIES_FEATURES_KHR, VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_LIBRARY_GROUP_HANDLES_FEATURES_EXT, VkPhysicalDevicePipelineLibraryGroupHandlesFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_PROPERTIES_FEATURES_EXT, VkPhysicalDevicePipelinePropertiesFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_PROTECTED_ACCESS_FEATURES_EXT, VkPhysicalDevicePipelineProtectedAccessFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_ROBUSTNESS_FEATURES_EXT, VkPhysicalDevicePipelineRobustnessFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_BARRIER_FEATURES_NV, VkPhysicalDevicePresentBarrierFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_ID_FEATURES_KHR, VkPhysicalDevicePresentIdFeaturesKHR)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_WAIT_FEATURES_KHR, VkPhysicalDevicePresentWaitFeaturesKHR)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIMITIVES_GENERATED_QUERY_FEATURES_EXT, VkPhysicalDevicePrimitivesGeneratedQueryFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIMITIVE_TOPOLOGY_LIST_RESTART_FEATURES_EXT, VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIVATE_DATA_FEATURES, VkPhysicalDevicePrivateDataFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES, VkPhysicalDeviceProtectedMemoryFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROVOKING_VERTEX_FEATURES_EXT, VkPhysicalDeviceProvokingVertexFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_FEATURES_EXT, VkPhysicalDeviceRasterizationOrderAttachmentAccessFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_QUERY_FEATURES_KHR, VkPhysicalDeviceRayQueryFeaturesKHR)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_INVOCATION_REORDER_FEATURES_NV, VkPhysicalDeviceRayTracingInvocationReorderFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_MAINTENANCE_1_FEATURES_KHR, VkPhysicalDeviceRayTracingMaintenance1FeaturesKHR)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_MOTION_BLUR_FEATURES_NV, VkPhysicalDeviceRayTracingMotionBlurFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_FEATURES_KHR, VkPhysicalDeviceRayTracingPipelineFeaturesKHR)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_POSITION_FETCH_FEATURES_KHR, VkPhysicalDeviceRayTracingPositionFetchFeaturesKHR)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RELAXED_LINE_RASTERIZATION_FEATURES_IMG, VkPhysicalDeviceRelaxedLineRasterizationFeaturesIMG)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RENDER_PASS_STRIPED_FEATURES_ARM, VkPhysicalDeviceRenderPassStripedFeaturesARM)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_REPRESENTATIVE_FRAGMENT_TEST_FEATURES_NV, VkPhysicalDeviceRepresentativeFragmentTestFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RGBA10X6_FORMATS_FEATURES_EXT, VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT, VkPhysicalDeviceRobustness2FeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES, VkPhysicalDeviceSamplerYcbcrConversionFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES, VkPhysicalDeviceScalarBlockLayoutFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCHEDULING_CONTROLS_FEATURES_ARM, VkPhysicalDeviceSchedulingControlsFeaturesARM)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SEPARATE_DEPTH_STENCIL_LAYOUTS_FEATURES, VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_FLOAT_2_FEATURES_EXT, VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_FLOAT_FEATURES_EXT, VkPhysicalDeviceShaderAtomicFloatFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES, VkPhysicalDeviceShaderAtomicInt64Features)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CLOCK_FEATURES_KHR, VkPhysicalDeviceShaderClockFeaturesKHR)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_BUILTINS_FEATURES_ARM, VkPhysicalDeviceShaderCoreBuiltinsFeaturesARM)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DEMOTE_TO_HELPER_INVOCATION_FEATURES, VkPhysicalDeviceShaderDemoteToHelperInvocationFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES, VkPhysicalDeviceShaderDrawParametersFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_EARLY_AND_LATE_FRAGMENT_TESTS_FEATURES_AMD, VkPhysicalDeviceShaderEarlyAndLateFragmentTestsFeaturesAMD)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES, VkPhysicalDeviceShaderFloat16Int8Features)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_IMAGE_ATOMIC_INT64_FEATURES_EXT, VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_IMAGE_FOOTPRINT_FEATURES_NV, VkPhysicalDeviceShaderImageFootprintFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_INTEGER_DOT_PRODUCT_FEATURES, VkPhysicalDeviceShaderIntegerDotProductFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_INTEGER_FUNCTIONS_2_FEATURES_INTEL, VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_MODULE_IDENTIFIER_FEATURES_EXT, VkPhysicalDeviceShaderModuleIdentifierFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_OBJECT_FEATURES_EXT, VkPhysicalDeviceShaderObjectFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_SM_BUILTINS_FEATURES_NV, VkPhysicalDeviceShaderSMBuiltinsFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_SUBGROUP_EXTENDED_TYPES_FEATURES, VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_SUBGROUP_UNIFORM_CONTROL_FLOW_FEATURES_KHR, VkPhysicalDeviceShaderSubgroupUniformControlFlowFeaturesKHR)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_TERMINATE_INVOCATION_FEATURES, VkPhysicalDeviceShaderTerminateInvocationFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_TILE_IMAGE_FEATURES_EXT, VkPhysicalDeviceShaderTileImageFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADING_RATE_IMAGE_FEATURES_NV, VkPhysicalDeviceShadingRateImageFeaturesNV)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_FEATURES, VkPhysicalDeviceSubgroupSizeControlFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBPASS_MERGE_FEEDBACK_FEATURES_EXT, VkPhysicalDeviceSubpassMergeFeedbackFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBPASS_SHADING_FEATURES_HUAWEI, VkPhysicalDeviceSubpassShadingFeaturesHUAWEI)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SWAPCHAIN_MAINTENANCE_1_FEATURES_EXT, VkPhysicalDeviceSwapchainMaintenance1FeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SYNCHRONIZATION_2_FEATURES, VkPhysicalDeviceSynchronization2Features)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_FEATURES_EXT, VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXTURE_COMPRESSION_ASTC_HDR_FEATURES, VkPhysicalDeviceTextureCompressionASTCHDRFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TILE_PROPERTIES_FEATURES_QCOM, VkPhysicalDeviceTilePropertiesFeaturesQCOM)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES, VkPhysicalDeviceTimelineSemaphoreFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT, VkPhysicalDeviceTransformFeedbackFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES, VkPhysicalDeviceUniformBufferStandardLayoutFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES, VkPhysicalDeviceVariablePointersFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_KHR, VkPhysicalDeviceVertexAttributeDivisorFeaturesKHR)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_INPUT_DYNAMIC_STATE_FEATURES_EXT, VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VIDEO_MAINTENANCE_1_FEATURES_KHR, VkPhysicalDeviceVideoMaintenance1FeaturesKHR)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES, VkPhysicalDeviceVulkan11Features)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES, VkPhysicalDeviceVulkan12Features)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES, VkPhysicalDeviceVulkan13Features)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_MEMORY_MODEL_FEATURES, VkPhysicalDeviceVulkanMemoryModelFeatures)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_WORKGROUP_MEMORY_EXPLICIT_LAYOUT_FEATURES_KHR, VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_2_PLANE_444_FORMATS_FEATURES_EXT, VkPhysicalDeviceYcbcr2Plane444FormatsFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_DEGAMMA_FEATURES_QCOM, VkPhysicalDeviceYcbcrDegammaFeaturesQCOM)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_IMAGE_ARRAYS_FEATURES_EXT, VkPhysicalDeviceYcbcrImageArraysFeaturesEXT)
|
||||
DEVICE_CHAIN(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ZERO_INITIALIZE_WORKGROUP_MEMORY_FEATURES, VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures)
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Generate device_chain.inc: the structures a VkDeviceCreateInfo chain may hold, with their sizes.
|
||||
|
||||
The Xclipse layer copies the chain ahead of the VkPhysicalDeviceFeatures2 it edits, and copying a
|
||||
structure needs its size. Run against the Vulkan-Headers release the build compiles with (Ubuntu
|
||||
24.04's libvulkan-dev is 1.3.275):
|
||||
|
||||
gen_device_chain.py Vulkan-Headers/registry/vk.xml Vulkan-Headers/include/vulkan/vulkan_core.h
|
||||
"""
|
||||
import re
|
||||
import sys
|
||||
import xml.etree.ElementTree as ElementTree
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def main(registry, core_header, output):
|
||||
core = Path(core_header).read_text()
|
||||
root = ElementTree.parse(registry).getroot()
|
||||
entries = []
|
||||
for struct in root.iter("type"):
|
||||
if struct.get("category") != "struct" or struct.get("alias"):
|
||||
continue
|
||||
if "VkDeviceCreateInfo" not in (struct.get("structextends") or "").split(","):
|
||||
continue
|
||||
name = struct.get("name")
|
||||
stype = next((member.get("values") for member in struct.findall("member")
|
||||
if member.findtext("name") == "sType"), None)
|
||||
# Platform and provisional structures live outside vulkan_core.h; the layer never builds them.
|
||||
if not stype or not re.search(r"\}\s*" + re.escape(name) + r"\s*;", core):
|
||||
continue
|
||||
entries.append((stype, name))
|
||||
version = re.search(r"#define VK_HEADER_VERSION (\d+)", core).group(1)
|
||||
lines = ["/* Generated by gen_device_chain.py from Vulkan-Headers 1.3.%s; do not edit. */" % version]
|
||||
lines += ["DEVICE_CHAIN(%s, %s)" % entry for entry in sorted(entries)]
|
||||
Path(output).write_text("\n".join(lines) + "\n")
|
||||
print("%d structures" % len(entries))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) not in (3, 4):
|
||||
sys.exit(__doc__)
|
||||
main(sys.argv[1], sys.argv[2], sys.argv[3] if len(sys.argv) == 4 else
|
||||
Path(__file__).with_name("device_chain.inc"))
|
||||
@@ -0,0 +1,493 @@
|
||||
/*
|
||||
* VK_LAYER_DROIDDECK_xclipse: workarounds for Samsung's Xclipse driver loaded through libhybris.
|
||||
*
|
||||
* 1. bionic environ. A glibc process never initializes bionic's `environ`; the driver's
|
||||
* AMD-derived shader compiler walks it for AMD_SC_* settings and crashed on the NULL.
|
||||
* Once instance creation has loaded the driver, point it at a snapshot of ours.
|
||||
* 2. YCbCr immutable samplers in compute. Compute pipelines whose layout binds an array of
|
||||
* immutable YCbCr-conversion samplers fail to compile (VK_ERROR_UNKNOWN); gamescope's
|
||||
* composite shaders all bind one. Such bindings get a plain linear sampler instead, so only
|
||||
* multi-planar (NV12) layers sample incorrectly.
|
||||
* 3. Calibrated timestamps. The driver has only VK_EXT_calibrated_timestamps, but the bridge
|
||||
* lists the KHR names too, and Wine calls those; the loader then aborts (it took down Wine's
|
||||
* explorer.exe and with it every game window). The KHR entry points forward to the EXT ones.
|
||||
* 4. BC4/BC5 filtering. The libhybris compat layer emulates BC textures; BC4/BC5 decode into
|
||||
* R16/R16G16 images, for which this driver advertises no linear filtering, so DXVK would
|
||||
* treat them as unfilterable. The layer reports linear filtering for BC4/BC5 where they are
|
||||
* sampled at all (RDNA filters 16-bit normalized formats; at worst they sample unfiltered).
|
||||
* 5. textureCompressionBC. The compat layer emulates BC formats but keeps the feature bit off;
|
||||
* DXVK before 3.0 (the last that fits this driver's 128 bytes of push constants) requires
|
||||
* it. The layer reports it while BC formats are sampleable and clears it at device creation.
|
||||
* Everything else passes straight through.
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include <vulkan/vk_layer.h>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <dlfcn.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define EXPORT __attribute__((visibility("default")))
|
||||
#define MAX_OBJECTS 64
|
||||
|
||||
extern char **environ;
|
||||
|
||||
/* The loader's dispatch table pointer heads every dispatchable object: an instance shares it
|
||||
* with its physical devices, a device with its queues and command buffers. */
|
||||
typedef void *dispatch_key;
|
||||
static dispatch_key key_of(const void *object) { return *(dispatch_key *)object; }
|
||||
|
||||
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static int debug;
|
||||
|
||||
struct instance_data {
|
||||
dispatch_key key;
|
||||
VkInstance handle;
|
||||
PFN_vkGetInstanceProcAddr next;
|
||||
PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT time_domains;
|
||||
PFN_vkGetPhysicalDeviceFeatures features;
|
||||
PFN_vkGetPhysicalDeviceFeatures2 features2;
|
||||
PFN_vkGetPhysicalDeviceFormatProperties format_properties;
|
||||
PFN_vkGetPhysicalDeviceFormatProperties2 format_properties2;
|
||||
};
|
||||
struct device_data {
|
||||
dispatch_key key;
|
||||
VkDevice handle;
|
||||
PFN_vkGetDeviceProcAddr next;
|
||||
PFN_vkCreateSampler create_sampler;
|
||||
PFN_vkDestroySampler destroy_sampler;
|
||||
PFN_vkCreateDescriptorSetLayout create_set_layout;
|
||||
PFN_vkDestroyDevice destroy_device;
|
||||
PFN_vkGetCalibratedTimestampsEXT timestamps;
|
||||
VkSampler fallback;
|
||||
};
|
||||
static struct instance_data instances[MAX_OBJECTS];
|
||||
static struct device_data devices[MAX_OBJECTS];
|
||||
/* The live YCbCr samplers each device created, so set layouts can recognise them. Guarded by lock. */
|
||||
static struct ycbcr_sampler { VkDevice device; VkSampler sampler; } *ycbcr_samplers;
|
||||
static size_t ycbcr_count, ycbcr_capacity;
|
||||
|
||||
static struct instance_data *instance_by_key(dispatch_key key) {
|
||||
for (int i = 0; i < MAX_OBJECTS; i++)
|
||||
if (instances[i].handle && instances[i].key == key) return &instances[i];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct device_data *device_by_key(dispatch_key key) {
|
||||
for (int i = 0; i < MAX_OBJECTS; i++)
|
||||
if (devices[i].handle && devices[i].key == key) return &devices[i];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Entries are never freed while their object lives, so a looked-up copy of the pointers is safe. */
|
||||
static struct instance_data instance_of(const void *object) {
|
||||
struct instance_data copy = {0};
|
||||
pthread_mutex_lock(&lock);
|
||||
struct instance_data *data = instance_by_key(key_of(object));
|
||||
if (data) copy = *data;
|
||||
pthread_mutex_unlock(&lock);
|
||||
return copy;
|
||||
}
|
||||
|
||||
static struct device_data device_of(const void *object) {
|
||||
struct device_data copy = {0};
|
||||
pthread_mutex_lock(&lock);
|
||||
struct device_data *data = device_by_key(key_of(object));
|
||||
if (data) copy = *data;
|
||||
pthread_mutex_unlock(&lock);
|
||||
return copy;
|
||||
}
|
||||
|
||||
static void fix_bionic_environ(void) {
|
||||
void *common = dlopen("libhybris-common.so.1", RTLD_NOW | RTLD_NOLOAD);
|
||||
if (!common) return; /* not a libhybris driver */
|
||||
void *(*h_dlopen)(const char *, int) = (void *(*)(const char *, int))dlsym(common, "hybris_dlopen");
|
||||
void *(*h_dlsym)(void *, const char *) = (void *(*)(void *, const char *))dlsym(common, "hybris_dlsym");
|
||||
if (!h_dlopen || !h_dlsym) return;
|
||||
void *libc = h_dlopen("libc.so", RTLD_NOW);
|
||||
char ***bionic_environ = libc ? (char ***)h_dlsym(libc, "environ") : NULL;
|
||||
if (!bionic_environ || *bionic_environ) return;
|
||||
size_t count = 0;
|
||||
while (environ && environ[count]) count++;
|
||||
char **snapshot = calloc(count + 1, sizeof(*snapshot));
|
||||
if (!snapshot) return;
|
||||
for (size_t i = 0; i < count; i++) snapshot[i] = strdup(environ[i]);
|
||||
*bionic_environ = snapshot;
|
||||
if (debug) fprintf(stderr, "xclipse layer: bionic environ set (%zu entries)\n", count);
|
||||
}
|
||||
|
||||
/* ---- instance ---- */
|
||||
|
||||
static VkResult VKAPI_CALL create_instance(const VkInstanceCreateInfo *info, const VkAllocationCallbacks *allocator,
|
||||
VkInstance *instance) {
|
||||
VkLayerInstanceCreateInfo *chain = (VkLayerInstanceCreateInfo *)info->pNext;
|
||||
while (chain && !(chain->sType == VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO && chain->function == VK_LAYER_LINK_INFO))
|
||||
chain = (VkLayerInstanceCreateInfo *)chain->pNext;
|
||||
if (!chain || !chain->u.pLayerInfo) return VK_ERROR_INITIALIZATION_FAILED;
|
||||
PFN_vkGetInstanceProcAddr next = chain->u.pLayerInfo->pfnNextGetInstanceProcAddr;
|
||||
chain->u.pLayerInfo = chain->u.pLayerInfo->pNext;
|
||||
PFN_vkCreateInstance next_create = (PFN_vkCreateInstance)next(NULL, "vkCreateInstance");
|
||||
if (!next_create) return VK_ERROR_INITIALIZATION_FAILED;
|
||||
VkResult result = next_create(info, allocator, instance);
|
||||
if (result != VK_SUCCESS) return result;
|
||||
fix_bionic_environ();
|
||||
struct instance_data data = {
|
||||
.key = key_of(*instance),
|
||||
.handle = *instance,
|
||||
.next = next,
|
||||
.time_domains = (PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT)
|
||||
next(*instance, "vkGetPhysicalDeviceCalibrateableTimeDomainsEXT"),
|
||||
.features = (PFN_vkGetPhysicalDeviceFeatures)next(*instance, "vkGetPhysicalDeviceFeatures"),
|
||||
.features2 = (PFN_vkGetPhysicalDeviceFeatures2)next(*instance, "vkGetPhysicalDeviceFeatures2"),
|
||||
.format_properties = (PFN_vkGetPhysicalDeviceFormatProperties)next(*instance, "vkGetPhysicalDeviceFormatProperties"),
|
||||
.format_properties2 = (PFN_vkGetPhysicalDeviceFormatProperties2)next(*instance, "vkGetPhysicalDeviceFormatProperties2"),
|
||||
};
|
||||
pthread_mutex_lock(&lock);
|
||||
for (int i = 0; i < MAX_OBJECTS; i++)
|
||||
if (!instances[i].handle) { instances[i] = data; break; }
|
||||
pthread_mutex_unlock(&lock);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void VKAPI_CALL destroy_instance(VkInstance instance, const VkAllocationCallbacks *allocator) {
|
||||
PFN_vkGetInstanceProcAddr next = instance_of(instance).next;
|
||||
pthread_mutex_lock(&lock);
|
||||
struct instance_data *data = instance_by_key(key_of(instance));
|
||||
if (data) memset(data, 0, sizeof(*data));
|
||||
pthread_mutex_unlock(&lock);
|
||||
PFN_vkDestroyInstance next_destroy = next ? (PFN_vkDestroyInstance)next(instance, "vkDestroyInstance") : NULL;
|
||||
if (next_destroy) next_destroy(instance, allocator);
|
||||
}
|
||||
|
||||
static VkResult VKAPI_CALL time_domains_khr(VkPhysicalDevice physical, uint32_t *count, VkTimeDomainEXT *domains) {
|
||||
PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT ext = instance_of(physical).time_domains;
|
||||
if (!ext) { *count = 0; return VK_SUCCESS; }
|
||||
return ext(physical, count, domains);
|
||||
}
|
||||
|
||||
/* BC formats sampleable below us although the driver's feature bit is off: the compat layer emulates them. */
|
||||
static int bc_emulated(VkPhysicalDevice physical) {
|
||||
struct instance_data data = instance_of(physical);
|
||||
if (!data.features || !data.format_properties) return 0;
|
||||
VkPhysicalDeviceFeatures native;
|
||||
data.features(physical, &native);
|
||||
if (native.textureCompressionBC) return 0;
|
||||
VkFormatProperties bc1, bc7;
|
||||
data.format_properties(physical, VK_FORMAT_BC1_RGBA_UNORM_BLOCK, &bc1);
|
||||
data.format_properties(physical, VK_FORMAT_BC7_UNORM_BLOCK, &bc7);
|
||||
return (bc1.optimalTilingFeatures & bc7.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) != 0;
|
||||
}
|
||||
|
||||
static void VKAPI_CALL get_features(VkPhysicalDevice physical, VkPhysicalDeviceFeatures *features) {
|
||||
PFN_vkGetPhysicalDeviceFeatures next = instance_of(physical).features;
|
||||
if (next) next(physical, features);
|
||||
if (bc_emulated(physical)) features->textureCompressionBC = VK_TRUE;
|
||||
}
|
||||
|
||||
static void VKAPI_CALL get_features2(VkPhysicalDevice physical, VkPhysicalDeviceFeatures2 *features) {
|
||||
PFN_vkGetPhysicalDeviceFeatures2 next = instance_of(physical).features2;
|
||||
if (next) next(physical, features);
|
||||
if (bc_emulated(physical)) features->features.textureCompressionBC = VK_TRUE;
|
||||
}
|
||||
|
||||
static int bc45(VkFormat format) {
|
||||
return format >= VK_FORMAT_BC4_UNORM_BLOCK && format <= VK_FORMAT_BC5_SNORM_BLOCK;
|
||||
}
|
||||
|
||||
static void VKAPI_CALL get_format_properties(VkPhysicalDevice physical, VkFormat format, VkFormatProperties *out) {
|
||||
PFN_vkGetPhysicalDeviceFormatProperties next = instance_of(physical).format_properties;
|
||||
if (next) next(physical, format, out);
|
||||
if (bc45(format) && (out->optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT))
|
||||
out->optimalTilingFeatures |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
|
||||
}
|
||||
|
||||
static void VKAPI_CALL get_format_properties2(VkPhysicalDevice physical, VkFormat format, VkFormatProperties2 *out) {
|
||||
PFN_vkGetPhysicalDeviceFormatProperties2 next = instance_of(physical).format_properties2;
|
||||
if (next) next(physical, format, out);
|
||||
if (!bc45(format)) return;
|
||||
if (out->formatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
|
||||
out->formatProperties.optimalTilingFeatures |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
|
||||
for (VkBaseOutStructure *p = (VkBaseOutStructure *)out->pNext; p; p = p->pNext) {
|
||||
if (p->sType != VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_3) continue;
|
||||
VkFormatProperties3 *f3 = (VkFormatProperties3 *)p;
|
||||
if (f3->optimalTilingFeatures & VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_BIT)
|
||||
f3->optimalTilingFeatures |= VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- device ---- */
|
||||
|
||||
/* The size of each structure a VkDeviceCreateInfo chain may hold (device_chain.inc, generated from the
|
||||
* Vulkan registry), plus the loader's own; 0 for anything else. */
|
||||
static size_t chain_size(VkStructureType type) {
|
||||
switch (type) {
|
||||
#define DEVICE_CHAIN(stype, name) case stype: return sizeof(name);
|
||||
#include "device_chain.inc"
|
||||
#undef DEVICE_CHAIN
|
||||
case VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO: return sizeof(VkLayerDeviceCreateInfo);
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
struct chain_copy { void **nodes; size_t count; };
|
||||
|
||||
static void free_chain_copy(struct chain_copy *copy) {
|
||||
for (size_t i = 0; i < copy->count; i++) free(copy->nodes[i]);
|
||||
free(copy->nodes);
|
||||
copy->nodes = NULL;
|
||||
copy->count = 0;
|
||||
}
|
||||
|
||||
/* The chain with textureCompressionBC cleared in a copy of the VkPhysicalDeviceFeatures2 that enables
|
||||
* it: every structure up to it is copied into [copy], the rest is shared. The caller's structures are
|
||||
* never written. *head_out stays [head] when nothing needs clearing, or when a structure ahead of it
|
||||
* is unknown to this build (newer than its Vulkan headers); the compat layer then refuses the bit. */
|
||||
static VkResult chain_without_bc(const void *head, struct chain_copy *copy, const void **head_out) {
|
||||
*head_out = head;
|
||||
const VkBaseInStructure *target = NULL;
|
||||
size_t count = 0;
|
||||
for (const VkBaseInStructure *p = head; p && !target; p = p->pNext) {
|
||||
if (!chain_size(p->sType)) return VK_SUCCESS;
|
||||
count++;
|
||||
if (p->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2 &&
|
||||
((const VkPhysicalDeviceFeatures2 *)p)->features.textureCompressionBC) target = p;
|
||||
}
|
||||
if (!target) return VK_SUCCESS;
|
||||
if (!(copy->nodes = calloc(count, sizeof(*copy->nodes)))) return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
VkBaseOutStructure *first = NULL, *last = NULL;
|
||||
for (const VkBaseInStructure *p = head; ; p = p->pNext) {
|
||||
size_t size = chain_size(p->sType);
|
||||
VkBaseOutStructure *node = malloc(size);
|
||||
if (!node) { free_chain_copy(copy); return VK_ERROR_OUT_OF_HOST_MEMORY; }
|
||||
copy->nodes[copy->count++] = node;
|
||||
memcpy(node, p, size);
|
||||
if (last) last->pNext = node; else first = node;
|
||||
last = node;
|
||||
if (p == target) {
|
||||
((VkPhysicalDeviceFeatures2 *)node)->features.textureCompressionBC = VK_FALSE;
|
||||
*head_out = first; /* its pNext still leads to the caller's remaining structures */
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static VkResult VKAPI_CALL create_device(VkPhysicalDevice physical, const VkDeviceCreateInfo *info,
|
||||
const VkAllocationCallbacks *allocator, VkDevice *device) {
|
||||
VkLayerDeviceCreateInfo *chain = (VkLayerDeviceCreateInfo *)info->pNext;
|
||||
while (chain && !(chain->sType == VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO && chain->function == VK_LAYER_LINK_INFO))
|
||||
chain = (VkLayerDeviceCreateInfo *)chain->pNext;
|
||||
if (!chain || !chain->u.pLayerInfo) return VK_ERROR_INITIALIZATION_FAILED;
|
||||
PFN_vkGetInstanceProcAddr next_gipa = chain->u.pLayerInfo->pfnNextGetInstanceProcAddr;
|
||||
PFN_vkGetDeviceProcAddr next_gdpa = chain->u.pLayerInfo->pfnNextGetDeviceProcAddr;
|
||||
chain->u.pLayerInfo = chain->u.pLayerInfo->pNext;
|
||||
PFN_vkCreateDevice next_create = (PFN_vkCreateDevice)next_gipa(NULL, "vkCreateDevice");
|
||||
if (!next_create) return VK_ERROR_INITIALIZATION_FAILED;
|
||||
|
||||
VkDeviceCreateInfo patched = *info;
|
||||
/* An emulated textureCompressionBC never reaches the compat layer, which refuses the bit. */
|
||||
int strip_bc = bc_emulated(physical);
|
||||
VkPhysicalDeviceFeatures plain_features;
|
||||
if (strip_bc && info->pEnabledFeatures && info->pEnabledFeatures->textureCompressionBC) {
|
||||
plain_features = *info->pEnabledFeatures;
|
||||
plain_features.textureCompressionBC = VK_FALSE;
|
||||
patched.pEnabledFeatures = &plain_features;
|
||||
}
|
||||
struct chain_copy copy = {0};
|
||||
if (strip_bc) {
|
||||
VkResult copied = chain_without_bc(info->pNext, ©, &patched.pNext);
|
||||
if (copied != VK_SUCCESS) return copied;
|
||||
}
|
||||
VkResult result = next_create(physical, &patched, allocator, device);
|
||||
free_chain_copy(©);
|
||||
if (result != VK_SUCCESS) return result;
|
||||
|
||||
PFN_vkCreateSampler create_sampler = (PFN_vkCreateSampler)next_gdpa(*device, "vkCreateSampler");
|
||||
VkSamplerCreateInfo plain = {
|
||||
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
|
||||
.magFilter = VK_FILTER_LINEAR, .minFilter = VK_FILTER_LINEAR,
|
||||
.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
||||
.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
||||
.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
||||
.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK,
|
||||
};
|
||||
VkSampler fallback = VK_NULL_HANDLE;
|
||||
if (create_sampler) create_sampler(*device, &plain, NULL, &fallback);
|
||||
struct device_data data = {
|
||||
.key = key_of(*device),
|
||||
.handle = *device,
|
||||
.next = next_gdpa,
|
||||
.create_sampler = create_sampler,
|
||||
.destroy_sampler = (PFN_vkDestroySampler)next_gdpa(*device, "vkDestroySampler"),
|
||||
.create_set_layout = (PFN_vkCreateDescriptorSetLayout)next_gdpa(*device, "vkCreateDescriptorSetLayout"),
|
||||
.destroy_device = (PFN_vkDestroyDevice)next_gdpa(*device, "vkDestroyDevice"),
|
||||
.timestamps = (PFN_vkGetCalibratedTimestampsEXT)next_gdpa(*device, "vkGetCalibratedTimestampsEXT"),
|
||||
.fallback = fallback,
|
||||
};
|
||||
pthread_mutex_lock(&lock);
|
||||
for (int i = 0; i < MAX_OBJECTS; i++)
|
||||
if (!devices[i].handle) { devices[i] = data; break; }
|
||||
pthread_mutex_unlock(&lock);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void VKAPI_CALL destroy_device(VkDevice device, const VkAllocationCallbacks *allocator) {
|
||||
struct device_data data = device_of(device);
|
||||
pthread_mutex_lock(&lock);
|
||||
struct device_data *entry = device_by_key(key_of(device));
|
||||
if (entry) memset(entry, 0, sizeof(*entry));
|
||||
for (size_t k = 0; k < ycbcr_count;)
|
||||
if (ycbcr_samplers[k].device == device) ycbcr_samplers[k] = ycbcr_samplers[--ycbcr_count];
|
||||
else k++;
|
||||
pthread_mutex_unlock(&lock);
|
||||
if (data.fallback && data.destroy_sampler) data.destroy_sampler(device, data.fallback, NULL);
|
||||
if (data.destroy_device) data.destroy_device(device, allocator);
|
||||
}
|
||||
|
||||
static VkResult VKAPI_CALL timestamps_khr(VkDevice device, uint32_t count, const VkCalibratedTimestampInfoEXT *infos,
|
||||
uint64_t *timestamps, uint64_t *deviation) {
|
||||
PFN_vkGetCalibratedTimestampsEXT ext = device_of(device).timestamps;
|
||||
return ext ? ext(device, count, infos, timestamps, deviation) : VK_ERROR_FEATURE_NOT_PRESENT;
|
||||
}
|
||||
|
||||
static VkResult VKAPI_CALL create_sampler(VkDevice device, const VkSamplerCreateInfo *info,
|
||||
const VkAllocationCallbacks *allocator, VkSampler *sampler) {
|
||||
PFN_vkCreateSampler next = device_of(device).create_sampler;
|
||||
if (!next) return VK_ERROR_INITIALIZATION_FAILED;
|
||||
VkResult result = next(device, info, allocator, sampler);
|
||||
if (result != VK_SUCCESS) return result;
|
||||
int ycbcr = 0;
|
||||
for (const VkBaseInStructure *p = info->pNext; p && !ycbcr; p = p->pNext)
|
||||
ycbcr = p->sType == VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO;
|
||||
if (!ycbcr) return result;
|
||||
pthread_mutex_lock(&lock);
|
||||
if (ycbcr_count == ycbcr_capacity) {
|
||||
size_t capacity = ycbcr_capacity ? ycbcr_capacity * 2 : 16;
|
||||
struct ycbcr_sampler *grown = realloc(ycbcr_samplers, capacity * sizeof(*grown));
|
||||
if (!grown) {
|
||||
pthread_mutex_unlock(&lock);
|
||||
/* An untracked YCbCr sampler would reach a compute layout unreplaced: fail instead. */
|
||||
PFN_vkDestroySampler destroy = device_of(device).destroy_sampler;
|
||||
if (destroy) destroy(device, *sampler, allocator);
|
||||
*sampler = VK_NULL_HANDLE;
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
ycbcr_samplers = grown;
|
||||
ycbcr_capacity = capacity;
|
||||
}
|
||||
ycbcr_samplers[ycbcr_count++] = (struct ycbcr_sampler){device, *sampler};
|
||||
pthread_mutex_unlock(&lock);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void VKAPI_CALL destroy_sampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks *allocator) {
|
||||
pthread_mutex_lock(&lock);
|
||||
for (size_t k = 0; k < ycbcr_count; k++)
|
||||
if (ycbcr_samplers[k].device == device && ycbcr_samplers[k].sampler == sampler) {
|
||||
ycbcr_samplers[k] = ycbcr_samplers[--ycbcr_count];
|
||||
break;
|
||||
}
|
||||
pthread_mutex_unlock(&lock);
|
||||
PFN_vkDestroySampler next = device_of(device).destroy_sampler;
|
||||
if (next) next(device, sampler, allocator);
|
||||
}
|
||||
|
||||
/* Called with lock held. */
|
||||
static int is_ycbcr(VkDevice device, VkSampler sampler) {
|
||||
for (size_t k = 0; sampler && k < ycbcr_count; k++)
|
||||
if (ycbcr_samplers[k].device == device && ycbcr_samplers[k].sampler == sampler) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static VkResult VKAPI_CALL create_set_layout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *info,
|
||||
const VkAllocationCallbacks *allocator, VkDescriptorSetLayout *layout) {
|
||||
struct device_data data = device_of(device);
|
||||
if (!data.create_set_layout) return VK_ERROR_INITIALIZATION_FAILED;
|
||||
int replace = 0;
|
||||
pthread_mutex_lock(&lock);
|
||||
for (uint32_t b = 0; data.fallback && b < info->bindingCount && !replace; b++) {
|
||||
const VkDescriptorSetLayoutBinding *binding = &info->pBindings[b];
|
||||
if (!(binding->stageFlags & VK_SHADER_STAGE_COMPUTE_BIT) || !binding->pImmutableSamplers) continue;
|
||||
for (uint32_t s = 0; s < binding->descriptorCount; s++)
|
||||
if (is_ycbcr(device, binding->pImmutableSamplers[s])) { replace = 1; break; }
|
||||
}
|
||||
pthread_mutex_unlock(&lock);
|
||||
if (!replace) return data.create_set_layout(device, info, allocator, layout);
|
||||
|
||||
VkResult result = VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
VkDescriptorSetLayoutBinding *bindings = calloc(info->bindingCount, sizeof(*bindings));
|
||||
VkSampler **arrays = calloc(info->bindingCount, sizeof(*arrays));
|
||||
if (!bindings || !arrays) goto done;
|
||||
for (uint32_t b = 0; b < info->bindingCount; b++) {
|
||||
bindings[b] = info->pBindings[b];
|
||||
if (!(bindings[b].stageFlags & VK_SHADER_STAGE_COMPUTE_BIT) || !bindings[b].pImmutableSamplers) continue;
|
||||
/* Without the replacement the driver would see the samplers it cannot compile: fail instead. */
|
||||
if (!(arrays[b] = malloc(bindings[b].descriptorCount * sizeof(VkSampler)))) goto done;
|
||||
pthread_mutex_lock(&lock);
|
||||
for (uint32_t s = 0; s < bindings[b].descriptorCount; s++) {
|
||||
VkSampler original = bindings[b].pImmutableSamplers[s];
|
||||
arrays[b][s] = is_ycbcr(device, original) ? data.fallback : original;
|
||||
}
|
||||
pthread_mutex_unlock(&lock);
|
||||
bindings[b].pImmutableSamplers = arrays[b];
|
||||
}
|
||||
VkDescriptorSetLayoutCreateInfo patched = *info;
|
||||
patched.pBindings = bindings;
|
||||
result = data.create_set_layout(device, &patched, allocator, layout);
|
||||
if (debug) fprintf(stderr, "xclipse layer: compute YCbCr immutable samplers replaced (%d)\n", result);
|
||||
done:
|
||||
for (uint32_t b = 0; arrays && b < info->bindingCount; b++) free(arrays[b]);
|
||||
free(arrays);
|
||||
free(bindings);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* ---- dispatch ---- */
|
||||
|
||||
static PFN_vkVoidFunction device_hook(const char *name) {
|
||||
if (!strcmp(name, "vkGetDeviceProcAddr")) return NULL; /* handled by the caller */
|
||||
if (!strcmp(name, "vkDestroyDevice")) return (PFN_vkVoidFunction)destroy_device;
|
||||
if (!strcmp(name, "vkCreateSampler")) return (PFN_vkVoidFunction)create_sampler;
|
||||
if (!strcmp(name, "vkDestroySampler")) return (PFN_vkVoidFunction)destroy_sampler;
|
||||
if (!strcmp(name, "vkCreateDescriptorSetLayout")) return (PFN_vkVoidFunction)create_set_layout;
|
||||
if (!strcmp(name, "vkGetCalibratedTimestampsKHR")) return (PFN_vkVoidFunction)timestamps_khr;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char *name) {
|
||||
if (!strcmp(name, "vkGetDeviceProcAddr")) return (PFN_vkVoidFunction)vkGetDeviceProcAddr;
|
||||
PFN_vkVoidFunction hook = device_hook(name);
|
||||
if (hook) return hook;
|
||||
struct device_data data = device ? device_of(device) : (struct device_data){0};
|
||||
return data.next ? data.next(device, name) : NULL;
|
||||
}
|
||||
|
||||
EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *name) {
|
||||
if (!strcmp(name, "vkGetInstanceProcAddr")) return (PFN_vkVoidFunction)vkGetInstanceProcAddr;
|
||||
if (!strcmp(name, "vkCreateInstance")) return (PFN_vkVoidFunction)create_instance;
|
||||
if (!strcmp(name, "vkDestroyInstance")) return (PFN_vkVoidFunction)destroy_instance;
|
||||
if (!strcmp(name, "vkCreateDevice")) return (PFN_vkVoidFunction)create_device;
|
||||
if (!strcmp(name, "vkGetDeviceProcAddr")) return (PFN_vkVoidFunction)vkGetDeviceProcAddr;
|
||||
if (!strcmp(name, "vkGetPhysicalDeviceFeatures")) return (PFN_vkVoidFunction)get_features;
|
||||
if (!strcmp(name, "vkGetPhysicalDeviceFeatures2") || !strcmp(name, "vkGetPhysicalDeviceFeatures2KHR"))
|
||||
return (PFN_vkVoidFunction)get_features2;
|
||||
if (!strcmp(name, "vkGetPhysicalDeviceCalibrateableTimeDomainsKHR")) return (PFN_vkVoidFunction)time_domains_khr;
|
||||
if (!strcmp(name, "vkGetPhysicalDeviceFormatProperties")) return (PFN_vkVoidFunction)get_format_properties;
|
||||
if (!strcmp(name, "vkGetPhysicalDeviceFormatProperties2") || !strcmp(name, "vkGetPhysicalDeviceFormatProperties2KHR"))
|
||||
return (PFN_vkVoidFunction)get_format_properties2;
|
||||
PFN_vkVoidFunction hook = device_hook(name);
|
||||
if (hook) return hook;
|
||||
PFN_vkGetInstanceProcAddr next = instance ? instance_of(instance).next : NULL;
|
||||
return next ? next(instance, name) : NULL;
|
||||
}
|
||||
|
||||
EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *negotiate) {
|
||||
if (!negotiate || negotiate->loaderLayerInterfaceVersion < 2) return VK_ERROR_INITIALIZATION_FAILED;
|
||||
debug = getenv("DROIDDECK_XCLIPSE_LAYER_DEBUG") != NULL;
|
||||
negotiate->loaderLayerInterfaceVersion = 2;
|
||||
negotiate->pfnGetInstanceProcAddr = vkGetInstanceProcAddr;
|
||||
negotiate->pfnGetDeviceProcAddr = vkGetDeviceProcAddr;
|
||||
negotiate->pfnGetPhysicalDeviceProcAddr = NULL;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
@@ -3,7 +3,7 @@ FROM ubuntu:24.04
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y binutils gcc g++ python3 zstd unzip \
|
||||
&& apt-get install -y binutils gcc g++ libvulkan-dev python3 zstd unzip \
|
||||
&& if [ "$(uname -m)" = aarch64 ]; then \
|
||||
for tool in gcc g++ strip readelf objdump ar; do ln -s "$(command -v $tool)" /usr/local/bin/aarch64-linux-gnu-$tool; done; \
|
||||
else \
|
||||
|
||||
@@ -8,4 +8,11 @@ if [ "$(wc -l < "$starts")" -gt 5 ]; then
|
||||
echo "mangoapp: started $(wc -l < "$starts") times in 60 s; the performance overlay stays off for this session" >&2
|
||||
exec sleep infinity
|
||||
fi
|
||||
# The system PowerVR route (BL_POWERVR_RENDER_NODE): Zink could not make mangoapp a swapchain there
|
||||
# ("zink: could not create swapchain", then GLXBadCurrentWindow) and it crashed at every start. The
|
||||
# overlay is a few text lines: llvmpipe draws it.
|
||||
if [ -n "${BL_POWERVR_RENDER_NODE:-}" ]; then
|
||||
export GALLIUM_DRIVER=llvmpipe LIBGL_ALWAYS_SOFTWARE=1
|
||||
unset MESA_LOADER_DRIVER_OVERRIDE LIBGL_KOPPER_DRI2
|
||||
fi
|
||||
LD_LIBRARY_PATH=/usr/local/lib/mangoapp${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} exec /usr/local/lib/mangoapp/mangoapp "$@"
|
||||
@@ -0,0 +1,152 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Read-only reboot projection. Never writes raw Android logs or account data.
|
||||
|
||||
This is evidence collection, not a GPU fault injector or a root-cause oracle.
|
||||
The optional kernel projection reads only SYSTEM_LAST_KMSG after user unlock.
|
||||
It emits fixed categories and numeric hardware fields, never arbitrary log lines.
|
||||
"""
|
||||
import argparse
|
||||
from datetime import datetime, timezone
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
|
||||
|
||||
ENTRY = re.compile(r'^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\s+(SYSTEM_LAST_KMSG)\b', re.M)
|
||||
CATEGORIES = ('GNOC', 'PVRSRV', 'watchdog', 'IOMMU', 'S2MPU', 'access control', 'Kernel panic', 'HWR', 'GPU fault')
|
||||
PRIMARY_USER_STATES = frozenset(('RUNNING_LOCKED', 'RUNNING_UNLOCKING', 'RUNNING_UNLOCKED'))
|
||||
# Exact canonical reasons plus the vendor reason observed in the bounded Pixel
|
||||
# tests. Unrecognized/custom suffixes are not diagnostic output categories.
|
||||
BOOT_REASONS = frozenset(('cold', 'hard', 'warm', 'reboot', 'shutdown',
|
||||
'recovery', 'bootloader', 'kernel_panic', 'watchdog',
|
||||
'reset,warm,gnoc_error'))
|
||||
|
||||
|
||||
def primary_state(text):
|
||||
match = re.search(r'Started users state: \[0=([A-Z_]+)(?=[,\]])', text)
|
||||
return match.group(1) if match and match.group(1) in PRIMARY_USER_STATES else 'unknown'
|
||||
|
||||
|
||||
def safe_reason(text):
|
||||
value = text.strip()
|
||||
return value if value in BOOT_REASONS else 'unknown'
|
||||
|
||||
|
||||
def kernel_projection(text, device_timezone, after=None):
|
||||
entries = list(ENTRY.finditer(text))
|
||||
result = {'metadata_dates': [m.group(1) for m in entries], 'raw_body_saved': False,
|
||||
'root_cause_proven': False}
|
||||
if not entries:
|
||||
result['status'] = 'no_accessible_entry'
|
||||
return result
|
||||
latest = max(enumerate(entries), key=lambda row: row[1].group(1))
|
||||
index, match = latest
|
||||
body = text[match.end():entries[index + 1].start() if index + 1 < len(entries) else len(text)]
|
||||
result['entry_date_device_local'] = match.group(1)
|
||||
try:
|
||||
naive = datetime.strptime(match.group(1), '%Y-%m-%d %H:%M:%S')
|
||||
zone = ZoneInfo(device_timezone)
|
||||
except (ValueError, ZoneInfoNotFoundError):
|
||||
result['status'] = 'unknown_device_timezone'
|
||||
return result
|
||||
# Dropbox supplies a local wall clock without an offset. Round-trip both
|
||||
# folds: a repeated hour has two possible instants; a skipped hour has none.
|
||||
instants = {local.astimezone(timezone.utc)
|
||||
for fold in (0, 1)
|
||||
for local in (naive.replace(tzinfo=zone, fold=fold),)
|
||||
if local.astimezone(timezone.utc).astimezone(zone).replace(tzinfo=None) == naive}
|
||||
if len(instants) != 1:
|
||||
result['status'] = ('ambiguous_device_local_time' if instants
|
||||
else 'nonexistent_device_local_time')
|
||||
return result
|
||||
local = instants.pop()
|
||||
result['entry_date_utc'] = local.isoformat()
|
||||
if after is not None and local < after:
|
||||
result['status'] = 'stale_entry_not_attributed_to_current_trial'
|
||||
return result
|
||||
result['status'] = 'projected_entry_not_a_root_cause'
|
||||
result['categories'] = {key: len(re.findall(re.escape(key), body, re.I)) for key in CATEGORIES}
|
||||
patterns = {
|
||||
'gnoc_addresses': r'Error from GNOC at addr (0x[0-9a-fA-F]+)',
|
||||
'gnoc_error_types': r'GNOC error type (0x[0-9a-fA-F]+)',
|
||||
'firmware_reboot_codes': r'Reboot reason:\s+(0x[0-9a-fA-F]+)',
|
||||
'access_control_addresses': r'Access Control Error \((0x[0-9a-fA-F]+)',
|
||||
}
|
||||
result['hardware_fields'] = {key: sorted(set(re.findall(pattern, body))) for key, pattern in patterns.items()}
|
||||
# Read the complete value, not just a recognized-looking prefix. Apply the
|
||||
# same fixed projection as getprop; no arbitrary kernel reason text escapes.
|
||||
reasons = re.findall(r'Last boot reason:[ \t]*([^\r\n]*)', body)
|
||||
result['last_boot_reasons'] = sorted({safe_reason(reason) for reason in reasons})
|
||||
return result
|
||||
|
||||
|
||||
def collect(adb, serial, include_kernel=False, after=None):
|
||||
def shell(*args):
|
||||
try:
|
||||
process = subprocess.run([adb, '-s', serial, 'shell', *args], capture_output=True,
|
||||
text=True, timeout=20)
|
||||
except (OSError, subprocess.TimeoutExpired):
|
||||
return None, ''
|
||||
# No command stderr is copied to output: it may contain unrelated data.
|
||||
return process.returncode, process.stdout if process.returncode == 0 else ''
|
||||
|
||||
result = {'at': datetime.now(timezone.utc).isoformat(), 'read_only': True,
|
||||
'raw_logs_saved': False, 'credentials_collected': False}
|
||||
code, value = shell('settings', 'get', 'global', 'boot_count')
|
||||
result['boot_count'] = int(value.strip()) if code == 0 and value.strip().isdigit() else None
|
||||
code, value = shell('getprop', 'ro.boot.bootreason')
|
||||
result['bootloader_reason'] = safe_reason(value)
|
||||
code, value = shell('getprop', 'sys.boot.reason')
|
||||
result['system_boot_reason'] = safe_reason(value)
|
||||
code, value = shell('dumpsys', 'user')
|
||||
result['primary_user_state'] = primary_state(value)
|
||||
code, value = shell('getprop', 'persist.sys.timezone')
|
||||
device_timezone = value.strip()
|
||||
try:
|
||||
ZoneInfo(device_timezone)
|
||||
result['device_timezone'] = device_timezone
|
||||
except (ValueError, ZoneInfoNotFoundError):
|
||||
result['device_timezone'] = 'unknown'
|
||||
code, value = shell('dumpsys', 'dropbox', 'SYSTEM_LAST_KMSG')
|
||||
result['kernel_metadata_dates'] = [m.group(1) for m in ENTRY.finditer(value)]
|
||||
if include_kernel:
|
||||
if result['primary_user_state'] != 'RUNNING_UNLOCKED':
|
||||
result['kernel'] = {'status': 'requires_user_unlock', 'raw_body_saved': False}
|
||||
else:
|
||||
code, value = shell('dumpsys', 'dropbox', '--print', 'SYSTEM_LAST_KMSG')
|
||||
result['kernel'] = kernel_projection(value, result['device_timezone'], after)
|
||||
result['kernel']['read_exit_code'] = code
|
||||
return result
|
||||
|
||||
|
||||
def write_private_output(path, output):
|
||||
# Exclusive creation also rejects existing symlinks. Set the private mode
|
||||
# before any bytes are written, rather than chmod after exposing the data.
|
||||
flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL | getattr(os, 'O_NOFOLLOW', 0)
|
||||
descriptor = os.open(path, flags, 0o600)
|
||||
with os.fdopen(descriptor, 'w', encoding='utf-8') as stream:
|
||||
stream.write(output)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--adb', default='adb')
|
||||
parser.add_argument('--serial', required=True)
|
||||
parser.add_argument('--kernel', action='store_true')
|
||||
parser.add_argument('--after', help='Earliest relevant UTC ISO timestamp; excludes stale kernel entries')
|
||||
parser.add_argument('--output', type=Path, help='New JSON file; refuses to overwrite')
|
||||
args = parser.parse_args()
|
||||
after = datetime.fromisoformat(args.after.replace('Z', '+00:00')) if args.after else None
|
||||
if after is not None and after.tzinfo is None:
|
||||
parser.error('--after must include a timezone')
|
||||
result = collect(args.adb, args.serial, args.kernel, after)
|
||||
output = json.dumps(result, indent=2) + '\n'
|
||||
if args.output:
|
||||
write_private_output(args.output, output)
|
||||
print(output, end='')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,366 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Assemble the pinned PowerVR components into the APK's isolated Linux runtime.
|
||||
|
||||
Like DirectAudio, APK builds download published components rather than compile
|
||||
them. Their source, licenses and patches travel with the payload. Build recipes
|
||||
remain in tools/{hybris,dxvk,vulkan-wsi}; release.json pins their reviewed inputs.
|
||||
"""
|
||||
import argparse
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path, PurePosixPath
|
||||
import posixpath
|
||||
import re
|
||||
import stat
|
||||
import subprocess
|
||||
import tarfile
|
||||
import tempfile
|
||||
from urllib.parse import urlparse
|
||||
from urllib.request import urlopen
|
||||
from zipfile import ZipFile
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
ASSETS = Path("app/src/main/assets/hybris")
|
||||
REQUIRED_LIBRARIES = (
|
||||
"lib/libhybris-vulkan-icd.so.0", "lib/libhybris-common.so.1",
|
||||
"lib/libhybris/linker/q.so", "lib/libVkLayer_hybris_compat.so",
|
||||
"wsi/libVkLayer_window_system_integration.so",
|
||||
)
|
||||
MAX_UNPACKED = 256 * 1024 * 1024
|
||||
BUNDLED_LICENSES = {
|
||||
'tools/vulkan-wsi/licenses/Vulkan-Headers/' + name: 'licenses/Vulkan-Headers/' + name
|
||||
for name in ('LICENSE.md', 'MIT.txt')
|
||||
}
|
||||
|
||||
|
||||
def sha256(data):
|
||||
return hashlib.sha256(data).hexdigest()
|
||||
|
||||
|
||||
def json_bytes(value):
|
||||
return (json.dumps(value, sort_keys=True, indent=2) + "\n").encode()
|
||||
|
||||
|
||||
def safe_name(name):
|
||||
path = PurePosixPath(name)
|
||||
if not name or path.is_absolute() or ".." in path.parts or "\\" in name:
|
||||
raise ValueError("unsafe archive path: " + name)
|
||||
return str(path)
|
||||
|
||||
|
||||
def check_tree(entries):
|
||||
# Never extract through a symlink, even one pointing inside the tree.
|
||||
for name, entry in entries.items():
|
||||
for parent in PurePosixPath(name).parents:
|
||||
if str(parent) in entries:
|
||||
raise ValueError("archive member below a file or symlink: " + name)
|
||||
if entry[0] == "symlink":
|
||||
read(entries, name)
|
||||
|
||||
|
||||
def read(entries, name, seen=()):
|
||||
if name in seen or len(seen) > 16:
|
||||
raise ValueError("runtime symlink cycle: " + name)
|
||||
if name not in entries:
|
||||
raise ValueError("missing runtime file: " + name)
|
||||
kind, mode, data = entries[name]
|
||||
if kind == "symlink":
|
||||
if PurePosixPath(data).is_absolute() or "\\" in data:
|
||||
raise ValueError("unsafe runtime symlink: " + name)
|
||||
target = safe_name(posixpath.normpath(posixpath.join(posixpath.dirname(name), data)))
|
||||
return read(entries, target, (*seen, name))
|
||||
return data
|
||||
|
||||
|
||||
def read_tar(data):
|
||||
unpacked = subprocess.run(["zstd", "-q", "-dc"], input=data,
|
||||
capture_output=True, check=True).stdout
|
||||
if len(unpacked) > MAX_UNPACKED:
|
||||
raise ValueError("runtime archive exceeds size limit")
|
||||
entries, seen = {}, set()
|
||||
with tarfile.open(fileobj=io.BytesIO(unpacked)) as package:
|
||||
for member in package:
|
||||
name = safe_name(member.name)
|
||||
if name in seen:
|
||||
raise ValueError("duplicate archive path: " + name)
|
||||
seen.add(name)
|
||||
if member.isdir():
|
||||
continue
|
||||
if name == ".":
|
||||
raise ValueError("archive root must be a directory")
|
||||
if member.issym():
|
||||
entries[name] = ("symlink", 0o777, member.linkname)
|
||||
elif member.isfile():
|
||||
entries[name] = ("file", 0o755 if member.mode & 0o111 else 0o644,
|
||||
package.extractfile(member).read())
|
||||
else:
|
||||
raise ValueError("unsupported archive entry type: " + name)
|
||||
check_tree(entries)
|
||||
return entries
|
||||
|
||||
|
||||
def tree_digest(entries):
|
||||
return sha256(json_bytes({name: [kind, mode, sha256(data) if kind == "file" else data]
|
||||
for name, (kind, mode, data) in sorted(entries.items())}))
|
||||
|
||||
|
||||
def load_release(root):
|
||||
release = json.loads((root / "tools/powervr/release.json").read_bytes())
|
||||
if release.get("format") != 1:
|
||||
raise ValueError("unsupported PowerVR release pins")
|
||||
# These identify the reviewed recipe, not a new attestation from the old
|
||||
# producer. The original build metadata is preserved inside the runtime.
|
||||
for component in [release["hybris"], *release["archives"]]:
|
||||
for name, expected in component["recipe_inputs"].items():
|
||||
if sha256((root / name).read_bytes()) != expected:
|
||||
raise ValueError("PowerVR component recipe changed; update its release pin: " + name)
|
||||
return release
|
||||
|
||||
|
||||
def assembly_inputs(root):
|
||||
return {"format": 1, "inputs": {
|
||||
name: sha256((root / name).read_bytes()) for name in
|
||||
("tools/powervr/release.json", "tools/powervr/fetch.py", "tools/hybris/run-proton.py", *BUNDLED_LICENSES)}}
|
||||
|
||||
|
||||
def fetch(component, cache):
|
||||
url = component["url"]
|
||||
if urlparse(url).scheme != "https":
|
||||
raise ValueError("component URL must use HTTPS")
|
||||
cache.mkdir(parents=True, exist_ok=True)
|
||||
target = cache / (component["sha256"] + "-" + PurePosixPath(urlparse(url).path).name)
|
||||
|
||||
def valid(path):
|
||||
return (path.is_file() and path.stat().st_size == component["size"]
|
||||
and sha256(path.read_bytes()) == component["sha256"])
|
||||
|
||||
if valid(target):
|
||||
return target.read_bytes()
|
||||
# No unverified response is ever parsed or promoted into the cache.
|
||||
with tempfile.NamedTemporaryFile(dir=cache, prefix=".download-", delete=False) as output:
|
||||
temporary = Path(output.name)
|
||||
try:
|
||||
with urlopen(url, timeout=60) as response:
|
||||
remaining = component["size"]
|
||||
while block := response.read(min(1024 * 1024, remaining + 1)):
|
||||
remaining -= len(block)
|
||||
if remaining < 0:
|
||||
raise ValueError("component download exceeds pinned size")
|
||||
output.write(block)
|
||||
output.flush()
|
||||
if not valid(temporary):
|
||||
raise ValueError("component download checksum mismatch: " + url)
|
||||
os.replace(temporary, target)
|
||||
finally:
|
||||
temporary.unlink(missing_ok=True)
|
||||
return target.read_bytes()
|
||||
|
||||
|
||||
def read_zip(data, component):
|
||||
entries, seen = {}, set()
|
||||
expected = {item["name"]: item for item in component["files"]}
|
||||
allowed = set(expected) | set(component["ignored"])
|
||||
total = 0
|
||||
with ZipFile(io.BytesIO(data)) as archive:
|
||||
for member in archive.infolist():
|
||||
name = safe_name(member.filename)
|
||||
if name in seen:
|
||||
raise ValueError("duplicate archive path: " + name)
|
||||
seen.add(name)
|
||||
mode = member.external_attr >> 16
|
||||
kind = stat.S_IFMT(mode)
|
||||
if member.is_dir() and kind in (0, stat.S_IFDIR):
|
||||
continue
|
||||
if kind not in (0, stat.S_IFREG) or name not in allowed:
|
||||
raise ValueError("unexpected component archive entry: " + name)
|
||||
total += member.file_size
|
||||
if total > MAX_UNPACKED:
|
||||
raise ValueError("component archive exceeds size limit")
|
||||
if name not in expected:
|
||||
continue
|
||||
pin = expected[name]
|
||||
content = archive.read(member)
|
||||
if len(content) != pin["size"] or sha256(content) != pin["sha256"]:
|
||||
raise ValueError("component member checksum mismatch: " + name)
|
||||
path = safe_name(pin["path"])
|
||||
if path in entries:
|
||||
raise ValueError("duplicate component destination: " + path)
|
||||
entries[path] = ("file", pin["mode"], content)
|
||||
if set(expected) - seen:
|
||||
raise ValueError("component archive missing files: " + ", ".join(sorted(set(expected) - seen)))
|
||||
check_tree(entries)
|
||||
return entries
|
||||
|
||||
|
||||
def read_tar_gz(data, component):
|
||||
"""An upstream release tarball, held to the same per-file pins as a CI archive."""
|
||||
entries, seen = {}, set()
|
||||
expected = {item["name"]: item for item in component["files"]}
|
||||
allowed = set(expected) | set(component["ignored"])
|
||||
total = 0
|
||||
with tarfile.open(fileobj=io.BytesIO(data), mode="r:gz") as archive:
|
||||
for member in archive:
|
||||
name = safe_name(member.name)
|
||||
if name in seen:
|
||||
raise ValueError("duplicate archive path: " + name)
|
||||
seen.add(name)
|
||||
if member.isdir():
|
||||
continue
|
||||
if not member.isfile() or name not in allowed:
|
||||
raise ValueError("unexpected component archive entry: " + name)
|
||||
total += member.size
|
||||
if total > MAX_UNPACKED:
|
||||
raise ValueError("component archive exceeds size limit")
|
||||
if name not in expected:
|
||||
continue
|
||||
pin = expected[name]
|
||||
content = archive.extractfile(member).read()
|
||||
if len(content) != pin["size"] or sha256(content) != pin["sha256"]:
|
||||
raise ValueError("component member checksum mismatch: " + name)
|
||||
path = safe_name(pin["path"])
|
||||
if path in entries:
|
||||
raise ValueError("duplicate component destination: " + path)
|
||||
entries[path] = ("file", pin["mode"], content)
|
||||
if set(expected) - seen:
|
||||
raise ValueError("component archive missing files: " + ", ".join(sorted(set(expected) - seen)))
|
||||
check_tree(entries)
|
||||
return entries
|
||||
|
||||
|
||||
def read_component(data, component):
|
||||
kind = component.get("format", "zip")
|
||||
if kind == "zip":
|
||||
return read_zip(data, component)
|
||||
if kind == "tar.gz":
|
||||
return read_tar_gz(data, component)
|
||||
raise ValueError("unsupported component archive format: " + kind)
|
||||
|
||||
|
||||
def check_bundle(entries, release, root):
|
||||
check_tree(entries)
|
||||
if read(entries, "assembly-inputs.json") != json_bytes(assembly_inputs(root)):
|
||||
raise ValueError("PowerVR assembly inputs changed; run tools/powervr/fetch.py")
|
||||
if entries["run-proton.py"] != ("file", 0o755, (root / "tools/hybris/run-proton.py").read_bytes()):
|
||||
raise ValueError("PowerVR Proton wrapper is stale or not executable")
|
||||
compile(read(entries, "run-proton.py"), "run-proton.py", "exec")
|
||||
bridge = dict(entries)
|
||||
del bridge["assembly-inputs.json"], bridge["run-proton.py"]
|
||||
for source, target in BUNDLED_LICENSES.items():
|
||||
if entries.get(target) != ("file", 0o644, (root / source).read_bytes()):
|
||||
raise ValueError("Vulkan-Headers license missing or stale: " + target)
|
||||
for component in release["archives"]:
|
||||
for pin in component["files"]:
|
||||
content = read(entries, pin["path"])
|
||||
if (entries[pin["path"]][:2] != ("file", pin["mode"])
|
||||
or len(content) != pin["size"] or sha256(content) != pin["sha256"]):
|
||||
raise ValueError("PowerVR component mismatch: " + pin["path"])
|
||||
del bridge[pin["path"]]
|
||||
for target in BUNDLED_LICENSES.values():
|
||||
bridge.pop(target, None)
|
||||
if tree_digest(bridge) != release["hybris"]["tree_sha256"]:
|
||||
raise ValueError("PowerVR bridge differs from the pinned archive")
|
||||
for name in REQUIRED_LIBRARIES:
|
||||
content = read(entries, name)
|
||||
if content[:6] != b"\x7fELF\x02\x01" or content[18:20] != b"\xb7\x00":
|
||||
raise ValueError("runtime library is not ELF64 AArch64: " + name)
|
||||
# dxvk/ is the default payload; run-proton.py can select another dxvk-* sibling by name.
|
||||
payloads = sorted({name.split("/")[0] for name in entries if re.fullmatch(r"dxvk[^/]*/x(32|64)/[^/]+\.dll", name)})
|
||||
if "dxvk" not in payloads:
|
||||
raise ValueError("default DXVK payload missing")
|
||||
for payload in payloads:
|
||||
for architecture, machine, magic in (("x32", b"\x4c\x01", b"\x0b\x01"),
|
||||
("x64", b"\x64\x86", b"\x0b\x02")):
|
||||
for name in ("d3d8.dll", "d3d9.dll", "d3d10core.dll", "d3d11.dll", "dxgi.dll"):
|
||||
path = payload + "/" + architecture + "/" + name
|
||||
content = read(entries, path)
|
||||
pe = int.from_bytes(content[60:64], "little")
|
||||
if (content[:2] != b"MZ" or pe < 64 or content[pe:pe + 4] != b"PE\0\0"
|
||||
or content[pe + 4:pe + 6] != machine or content[pe + 24:pe + 26] != magic):
|
||||
raise ValueError("DXVK library has wrong PE architecture: " + path)
|
||||
|
||||
|
||||
def pack(entries):
|
||||
stream = io.BytesIO()
|
||||
directories = {str(parent) for name in entries for parent in PurePosixPath(name).parents
|
||||
if str(parent) != "."}
|
||||
with tarfile.open(fileobj=stream, mode="w", format=tarfile.USTAR_FORMAT) as archive:
|
||||
for name in sorted(directories | set(entries)):
|
||||
info = tarfile.TarInfo(name)
|
||||
info.mtime = info.uid = info.gid = 0
|
||||
if name in directories:
|
||||
info.type, info.mode = tarfile.DIRTYPE, 0o755
|
||||
archive.addfile(info)
|
||||
continue
|
||||
kind, info.mode, data = entries[name]
|
||||
if kind == "symlink":
|
||||
info.type, info.linkname = tarfile.SYMTYPE, data
|
||||
archive.addfile(info)
|
||||
else:
|
||||
info.size = len(data)
|
||||
archive.addfile(info, io.BytesIO(data))
|
||||
return subprocess.run(["zstd", "-q", "-10", "-T1", "-c"], input=stream.getvalue(),
|
||||
capture_output=True, check=True).stdout
|
||||
|
||||
|
||||
def verify_archive(archive, version, root=ROOT):
|
||||
release = load_release(root)
|
||||
if sha256(archive) != version.strip():
|
||||
raise ValueError("PowerVR runtime archive checksum mismatch")
|
||||
check_bundle(read_tar(archive), release, root)
|
||||
|
||||
|
||||
def verify(root=ROOT):
|
||||
verify_archive((root / ASSETS / "runtime.tzst").read_bytes(),
|
||||
(root / ASSETS / "version.txt").read_text(), root)
|
||||
|
||||
|
||||
def assemble(root, cache):
|
||||
release = load_release(root)
|
||||
entries = read_tar(fetch(release["hybris"], cache))
|
||||
if tree_digest(entries) != release["hybris"]["tree_sha256"]:
|
||||
raise ValueError("PowerVR bridge tree checksum mismatch")
|
||||
for component in release["archives"]:
|
||||
additions = read_component(fetch(component, cache), component)
|
||||
if set(entries) & set(additions):
|
||||
raise ValueError("component overwrites existing runtime files")
|
||||
entries.update(additions)
|
||||
for source, target in BUNDLED_LICENSES.items():
|
||||
license_entry = ("file", 0o644, (root / source).read_bytes())
|
||||
if target in entries and entries[target] != license_entry:
|
||||
raise ValueError("bundled license overwrites component file: " + target)
|
||||
entries[target] = license_entry
|
||||
entries["run-proton.py"] = ("file", 0o755, (root / "tools/hybris/run-proton.py").read_bytes())
|
||||
entries["assembly-inputs.json"] = ("file", 0o644, json_bytes(assembly_inputs(root)))
|
||||
check_bundle(entries, release, root)
|
||||
archive = pack(entries)
|
||||
assets = root / ASSETS
|
||||
assets.mkdir(parents=True, exist_ok=True)
|
||||
with tempfile.TemporaryDirectory(dir=assets.parent, prefix=".hybris-") as directory:
|
||||
stage = Path(directory)
|
||||
(stage / "runtime.tzst").write_bytes(archive)
|
||||
(stage / "version.txt").write_text(sha256(archive) + "\n")
|
||||
# version.txt is the readiness marker; an interrupted replacement fails
|
||||
# closed instead of presenting a partially updated payload as ready.
|
||||
(assets / "version.txt").unlink(missing_ok=True)
|
||||
os.replace(stage / "runtime.tzst", assets / "runtime.tzst")
|
||||
os.replace(stage / "version.txt", assets / "version.txt")
|
||||
print("PowerVR runtime prepared: " + sha256(archive))
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--verify", action="store_true")
|
||||
parser.add_argument("--cache-dir", type=Path, default=Path(os.environ.get(
|
||||
"DROIDDECK_BUILD_CACHE", str(Path.home() / ".cache/droiddeck-build"))))
|
||||
args = parser.parse_args()
|
||||
if args.verify:
|
||||
verify()
|
||||
else:
|
||||
assemble(ROOT, args.cache_dir)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,335 @@
|
||||
{
|
||||
"archives": [
|
||||
{
|
||||
"files": [
|
||||
{
|
||||
"mode": 493,
|
||||
"name": "x32/d3d8.dll",
|
||||
"path": "dxvk/x32/d3d8.dll",
|
||||
"sha256": "c9612be6aac99390156cdcd3b22054fba62cf68bfc948d753cc39282d37f67ab",
|
||||
"size": 1658894
|
||||
},
|
||||
{
|
||||
"mode": 493,
|
||||
"name": "x32/d3d9.dll",
|
||||
"path": "dxvk/x32/d3d9.dll",
|
||||
"sha256": "fbd0e7d7aae39d5d623757ead228930c4be78cb3b16db6f352796577831ce36e",
|
||||
"size": 7598094
|
||||
},
|
||||
{
|
||||
"mode": 493,
|
||||
"name": "x32/d3d10core.dll",
|
||||
"path": "dxvk/x32/d3d10core.dll",
|
||||
"sha256": "cd6052b1f6a02ab94fea5bfa3519e556fb353f585da4b64e3c810ef4cc37c808",
|
||||
"size": 192526
|
||||
},
|
||||
{
|
||||
"mode": 493,
|
||||
"name": "x32/d3d11.dll",
|
||||
"path": "dxvk/x32/d3d11.dll",
|
||||
"sha256": "9bf51b5ab913e1bd84513b2b1608586bc0a651788df9e664b8135840b8c8c54d",
|
||||
"size": 7942158
|
||||
},
|
||||
{
|
||||
"mode": 493,
|
||||
"name": "x32/dxgi.dll",
|
||||
"path": "dxvk/x32/dxgi.dll",
|
||||
"sha256": "d3772dc86267fe94eee7afc30c993f44297fd43b50210f1691f3d03ebf4d4402",
|
||||
"size": 5738510
|
||||
},
|
||||
{
|
||||
"mode": 493,
|
||||
"name": "x64/d3d8.dll",
|
||||
"path": "dxvk/x64/d3d8.dll",
|
||||
"sha256": "cd870a8f5cdbfef33e7ccf7884d6f1c442e2c8ec22d6adea60fea3dbe83c32e2",
|
||||
"size": 1499136
|
||||
},
|
||||
{
|
||||
"mode": 493,
|
||||
"name": "x64/d3d9.dll",
|
||||
"path": "dxvk/x64/d3d9.dll",
|
||||
"sha256": "4f80af96991073bb3dc25f3b93ec2c07ba25fcabb8a6e30ffd5eaae38c8465c7",
|
||||
"size": 6934528
|
||||
},
|
||||
{
|
||||
"mode": 493,
|
||||
"name": "x64/d3d10core.dll",
|
||||
"path": "dxvk/x64/d3d10core.dll",
|
||||
"sha256": "4950e952ca291b13c0645322f1831414e77df87183ed2f81d5dde02c1fd43ff9",
|
||||
"size": 978944
|
||||
},
|
||||
{
|
||||
"mode": 493,
|
||||
"name": "x64/d3d11.dll",
|
||||
"path": "dxvk/x64/d3d11.dll",
|
||||
"sha256": "3497d5f7dc78fa7affdba6777d3ab4aac7ec744d7e2c795fbf07dbff54058e6c",
|
||||
"size": 7143424
|
||||
},
|
||||
{
|
||||
"mode": 493,
|
||||
"name": "x64/dxgi.dll",
|
||||
"path": "dxvk/x64/dxgi.dll",
|
||||
"sha256": "d6e0ca242dba6cb8606106a7fcb65268225520f03c68e36a365f44d65f863e74",
|
||||
"size": 5230592
|
||||
},
|
||||
{
|
||||
"mode": 420,
|
||||
"name": "LICENSE",
|
||||
"path": "licenses/dxvk-LICENSE",
|
||||
"sha256": "a5cb1a6ded7d2d7e92d550ba28edd21be2d1d4044662b399887351023e30ce64",
|
||||
"size": 1074
|
||||
},
|
||||
{
|
||||
"mode": 420,
|
||||
"name": "source-commit",
|
||||
"path": "provenance/dxvk-source-commit",
|
||||
"sha256": "cb748e54f2fcdca516189435647ea001dbd14f97e2df5b36fd2f13fc185a5dbf",
|
||||
"size": 41
|
||||
},
|
||||
{
|
||||
"mode": 420,
|
||||
"name": "SHA256SUMS",
|
||||
"path": "provenance/dxvk-SHA256SUMS",
|
||||
"sha256": "8a106cb90288052cc91768b569980ed7381c89591fb7cea3bc6d0312c6f30a47",
|
||||
"size": 802
|
||||
},
|
||||
{
|
||||
"mode": 420,
|
||||
"name": "downstream.patch",
|
||||
"path": "licenses/dxvk-downstream.patch",
|
||||
"sha256": "e44b8d656a37c3b1059bbf3dcbcf11922a00634301f2509024fb263a45e9f50e",
|
||||
"size": 3604
|
||||
},
|
||||
{
|
||||
"mode": 420,
|
||||
"name": "source.tar.zst",
|
||||
"path": "licenses/dxvk-source.tar.zst",
|
||||
"sha256": "dfdebe8aa71b85af638f2565c1d5abe31417c6db643a827bcf0988e29ded55e7",
|
||||
"size": 6043001
|
||||
},
|
||||
{
|
||||
"mode": 420,
|
||||
"name": "submodules.txt",
|
||||
"path": "provenance/dxvk-submodules.txt",
|
||||
"sha256": "01e74c750ca473590e17f1ca33f204b8272f84898ee6e8a8509be9740919092c",
|
||||
"size": 472
|
||||
}
|
||||
],
|
||||
"id": "dxvk",
|
||||
"ignored": [
|
||||
"x32/d3d10core.dll.a",
|
||||
"x32/d3d11.dll.a",
|
||||
"x32/d3d8.dll.a",
|
||||
"x32/d3d9.dll.a",
|
||||
"x32/dxgi.dll.a",
|
||||
"x64/d3d10core.dll.a",
|
||||
"x64/d3d11.dll.a",
|
||||
"x64/d3d8.dll.a",
|
||||
"x64/d3d9.dll.a",
|
||||
"x64/dxgi.dll.a"
|
||||
],
|
||||
"provenance": {
|
||||
"ci_run": "https://github.com/wallentx/DroidDeck/actions/runs/38119192562",
|
||||
"repository_commit": "aee0ebd43557ef9964ba7f6a11d7d30efaf983ac"
|
||||
},
|
||||
"recipe_inputs": {
|
||||
"tools/dxvk/build.sh": "88b656292a6a8c92974f1c014dd685e104818ef45af5fa4e62b729452c969d6e",
|
||||
"tools/dxvk/check_present_sync.py": "42e2a590e17c1f53e5cd4100ef3d19a5bdcce31a6d7a18fbf9961f4ef27d5063",
|
||||
"tools/dxvk/patches/0001-check-direct3d-bc-formats.patch": "d38fc4d773b7974498dcb377dbaa883c9bba36aefa3235b39bca69d6dd220c77",
|
||||
"tools/dxvk/patches/0002-present-semaphore-per-swapchain-image.patch": "c802789a33099d3efc3413a297e2b752f8eb84c18cbfbdfc04e188f4090410d0",
|
||||
"tools/dxvk/source.env": "e49b0757f203f88783360c06118f60945242fde8738419e0b27cf2531bf3a365"
|
||||
},
|
||||
"sha256": "d08dd962ced3482883ad9e9eb4903a4d27a3756b4f989a97ecdfcccb53fbee66",
|
||||
"size": 24063241,
|
||||
"url": "https://github.com/wallentx/DroidDeck/releases/download/v0.3.2-progress.20261011.3/dxvk-aee0ebd.zip"
|
||||
},
|
||||
{
|
||||
"files": [
|
||||
{
|
||||
"mode": 420,
|
||||
"name": "libVkLayer_window_system_integration.so",
|
||||
"path": "wsi/libVkLayer_window_system_integration.so",
|
||||
"sha256": "d07b961181b9547fd48ad9f05cc6d3b808b824676eb5a186fe3feb8caa013f19",
|
||||
"size": 436888
|
||||
},
|
||||
{
|
||||
"mode": 420,
|
||||
"name": "VkLayer_window_system_integration.json",
|
||||
"path": "wsi/VkLayer_window_system_integration.json",
|
||||
"sha256": "a1df8b1cee7315015d8fe82534451e373ae4d9cb2adfc232c68346ecbf2818ee",
|
||||
"size": 3683
|
||||
},
|
||||
{
|
||||
"mode": 420,
|
||||
"name": "LICENSE",
|
||||
"path": "licenses/wsi-LICENSE",
|
||||
"sha256": "5eb8d2da52230d2d66ce078a89ae0173aac63e2e73bed5f907a34736d114ea30",
|
||||
"size": 1086
|
||||
},
|
||||
{
|
||||
"mode": 420,
|
||||
"name": "source-commit",
|
||||
"path": "provenance/wsi-source-commit",
|
||||
"sha256": "8367150b20502af36c472651850694a15a3e2a1fd6b6beb1f6e12a85a97824f5",
|
||||
"size": 41
|
||||
},
|
||||
{
|
||||
"mode": 420,
|
||||
"name": "SHA256SUMS",
|
||||
"path": "provenance/wsi-SHA256SUMS",
|
||||
"sha256": "fda6f61028659648801de0e3a6fe1676efd99e1551881a5db8630970eae86158",
|
||||
"size": 108
|
||||
},
|
||||
{
|
||||
"mode": 420,
|
||||
"name": "downstream.patch",
|
||||
"path": "licenses/wsi-downstream.patch",
|
||||
"sha256": "e2ed113d22f05563248ef606c774c22658b184fbc05912229007cd5281027e78",
|
||||
"size": 769
|
||||
},
|
||||
{
|
||||
"mode": 420,
|
||||
"name": "source.tar.zst",
|
||||
"path": "licenses/wsi-source.tar.zst",
|
||||
"sha256": "22ae7c2d8aa3dfffdda601c3442d1966ab53ad225acdfadee69ba38974d0c4c5",
|
||||
"size": 209468
|
||||
},
|
||||
{
|
||||
"mode": 420,
|
||||
"name": "vulkan-headers-commit",
|
||||
"path": "provenance/wsi-vulkan-headers-commit",
|
||||
"sha256": "16706d6cdbeb788426a90d66574dfd71068c4d993d39e76ec5c281b1f30dc7a6",
|
||||
"size": 41
|
||||
}
|
||||
],
|
||||
"id": "wsi",
|
||||
"ignored": [],
|
||||
"provenance": {
|
||||
"ci_run": "https://github.com/wallentx/DroidDeck/actions/runs/38047627963",
|
||||
"repository_commit": "abe58618a5194f1f15499cbd5f9ec75503782556",
|
||||
"vulkan_headers_licenses": {
|
||||
"note": "Added from tracked assembly inputs; the original WSI archive and compiled library are unchanged.",
|
||||
"revision": "8d6039a455a7ecc7d2a592ff97f62db4e59b70bf",
|
||||
"source_urls": [
|
||||
"https://raw.githubusercontent.com/KhronosGroup/Vulkan-Headers/8d6039a455a7ecc7d2a592ff97f62db4e59b70bf/LICENSE.md",
|
||||
"https://raw.githubusercontent.com/KhronosGroup/Vulkan-Headers/8d6039a455a7ecc7d2a592ff97f62db4e59b70bf/LICENSES/MIT.txt"
|
||||
]
|
||||
}
|
||||
},
|
||||
"recipe_inputs": {
|
||||
"tools/vulkan-wsi/build.sh": "9e403151c58e6b2ee15241f525c4bacb2495f072191da6a63065e7fcc25b3b3c",
|
||||
"tools/vulkan-wsi/licenses/Vulkan-Headers/LICENSE.md": "95ad366d23fadf701d355bc45fb8b82ae2d700239471d35d41286ac3b08ff903",
|
||||
"tools/vulkan-wsi/licenses/Vulkan-Headers/MIT.txt": "1ca3502222d967f3be5751c55f6b7ee735b5383909c3b501495f54b216dbf227",
|
||||
"tools/vulkan-wsi/patches/0001-link-x11-external-memory.patch": "e2ed113d22f05563248ef606c774c22658b184fbc05912229007cd5281027e78",
|
||||
"tools/vulkan-wsi/source.env": "71a88087265a09b4ce06e7c9b98ef6799c6a7657cc6ef9084de663e96f5cfe63"
|
||||
},
|
||||
"sha256": "348f9ec42159c1ee6e2baba4312a5e845d26687238f29e3f4a1b0c3c97e13b3c",
|
||||
"size": 362717,
|
||||
"url": "https://github.com/wallentx/DroidDeck/releases/download/v0.3.2-progress.20261010.4/wsi-abe5861.zip"
|
||||
},
|
||||
{
|
||||
"files": [
|
||||
{
|
||||
"mode": 493,
|
||||
"name": "dxvk-2.6.2/x32/d3d10core.dll",
|
||||
"path": "dxvk-2.6.2/x32/d3d10core.dll",
|
||||
"sha256": "b34b479fa0bce29eba6dcff5b1f8584c2ae699d53a123668590f8a2b84e84094",
|
||||
"size": 176142
|
||||
},
|
||||
{
|
||||
"mode": 493,
|
||||
"name": "dxvk-2.6.2/x32/d3d11.dll",
|
||||
"path": "dxvk-2.6.2/x32/d3d11.dll",
|
||||
"sha256": "858d1a848dd5023191cb16cd986e0f00008faf5df8a87b5c835b56cf4b646910",
|
||||
"size": 4845582
|
||||
},
|
||||
{
|
||||
"mode": 493,
|
||||
"name": "dxvk-2.6.2/x32/d3d8.dll",
|
||||
"path": "dxvk-2.6.2/x32/d3d8.dll",
|
||||
"sha256": "617459c8d1239f98687f8157bdaec85738ee4699885ed7d1ff13deb32609c759",
|
||||
"size": 1658894
|
||||
},
|
||||
{
|
||||
"mode": 493,
|
||||
"name": "dxvk-2.6.2/x32/d3d9.dll",
|
||||
"path": "dxvk-2.6.2/x32/d3d9.dll",
|
||||
"sha256": "00bc142e98ddad1e334a4d88fa630038e092b0758b3d79e295172b181a4c772d",
|
||||
"size": 4460558
|
||||
},
|
||||
{
|
||||
"mode": 493,
|
||||
"name": "dxvk-2.6.2/x32/dxgi.dll",
|
||||
"path": "dxvk-2.6.2/x32/dxgi.dll",
|
||||
"sha256": "67d7ca4a4f8f66baabd381c73b52a8e85870083e868ed474a4bc58b7da486883",
|
||||
"size": 3137550
|
||||
},
|
||||
{
|
||||
"mode": 493,
|
||||
"name": "dxvk-2.6.2/x64/d3d10core.dll",
|
||||
"path": "dxvk-2.6.2/x64/d3d10core.dll",
|
||||
"sha256": "565154a0763c6460843fe47e5aaec62e609163d9995a922d5e19e85027fe2f88",
|
||||
"size": 155662
|
||||
},
|
||||
{
|
||||
"mode": 493,
|
||||
"name": "dxvk-2.6.2/x64/d3d11.dll",
|
||||
"path": "dxvk-2.6.2/x64/d3d11.dll",
|
||||
"sha256": "5b63515a432d19302f7dc81dd2ee5bf40043683b5064a2bce03a2b6d27dcce5d",
|
||||
"size": 4399118
|
||||
},
|
||||
{
|
||||
"mode": 493,
|
||||
"name": "dxvk-2.6.2/x64/d3d8.dll",
|
||||
"path": "dxvk-2.6.2/x64/d3d8.dll",
|
||||
"sha256": "dfd837c3467eeb15f69a773e18bbc0550cb69c9e33d5d57b4ea42c5f63bfdc4b",
|
||||
"size": 1544206
|
||||
},
|
||||
{
|
||||
"mode": 493,
|
||||
"name": "dxvk-2.6.2/x64/d3d9.dll",
|
||||
"path": "dxvk-2.6.2/x64/d3d9.dll",
|
||||
"sha256": "01e7ae2b0544b6031fe695fd16fbc76786ded57fdbe3f6bd11eee7c98d2c370d",
|
||||
"size": 4108302
|
||||
},
|
||||
{
|
||||
"mode": 493,
|
||||
"name": "dxvk-2.6.2/x64/dxgi.dll",
|
||||
"path": "dxvk-2.6.2/x64/dxgi.dll",
|
||||
"sha256": "074616e1af172edf175f3fc6ed7ca30f6c685a70875eed3af10797a10840ed39",
|
||||
"size": 2891790
|
||||
}
|
||||
],
|
||||
"format": "tar.gz",
|
||||
"id": "dxvk-xclipse",
|
||||
"ignored": [],
|
||||
"provenance": {
|
||||
"note": "Unmodified upstream release, selected on Samsung Xclipse: its 128 bytes of push constants predate DXVK 3's 256-byte requirement. Covered by the zlib license already shipped as licenses/dxvk-LICENSE.",
|
||||
"upstream_release": "https://github.com/doitsujin/dxvk/releases/tag/v2.6.2"
|
||||
},
|
||||
"recipe_inputs": {},
|
||||
"sha256": "17761876556afd55736cb895d184f5a1c55d43350f1b1e3b129f8d28706d7992",
|
||||
"size": 10107492,
|
||||
"url": "https://github.com/doitsujin/dxvk/releases/download/v2.6.2/dxvk-2.6.2.tar.gz"
|
||||
}
|
||||
],
|
||||
"format": 1,
|
||||
"hybris": {
|
||||
"provenance": {
|
||||
"apk_ci_run": "https://github.com/wallentx/DroidDeck/actions/runs/38123715308",
|
||||
"extracted_from_apk": "https://github.com/wallentx/DroidDeck/releases/download/v0.3.2-progress.20261011.3/DroidDeck-0.3.2-1b6185b.apk",
|
||||
"note": "APK build reused a cached bridge. Original source and compiler metadata are preserved in build-manifest.json; no APK commit is claimed as the bridge producer.",
|
||||
"upstream_source_commit": "bc8cb3586b79d208fd21b925fa0209b3e432e008"
|
||||
},
|
||||
"recipe_inputs": {
|
||||
"tools/hybris/build_runtime.sh": "bc83472ecfd886841c8c2c436080cdee0a27ce0d860ffbffe45a75fbc6b2b21d",
|
||||
"tools/hybris/patches/0001-dxvk-bc-profile.patch": "b90605e51256595de4453352865aa198e59bd2d392ac6b7c2a60f38c57727c9d",
|
||||
"tools/hybris/powervr-hal-version.patch": "d3ed8ca03e5a874b9dc46651983117760c7490b96127335625d0480a2b85e66f",
|
||||
"tools/hybris/source.env": "9ae7985f2052dbcc8b9666494bc8a711ec85013f6a27d6d72d9729c32b919dd8"
|
||||
},
|
||||
"sha256": "f4f12c26ed21003c2c98a7cececd76c8a3b332d79ece9d1f963cf3b9e8943978",
|
||||
"size": 5552486,
|
||||
"tree_sha256": "de9cc2c4107bf396e4f963d7e91f936a966593fb1df680a0b5d43db0f9fef4e1",
|
||||
"url": "https://github.com/wallentx/DroidDeck/releases/download/v0.3.2-progress.20261011.3/hybris-runtime-f4f12c26.tzst"
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
from pathlib import Path
|
||||
import importlib.util
|
||||
import re
|
||||
import sys
|
||||
from zipfile import ZipFile
|
||||
@@ -9,7 +10,10 @@ SESSION_FILES = OVERLAY.parents[2] / 'app/src/main/java/com/droiddeck/launcher/s
|
||||
|
||||
|
||||
def check_extraction(overlay, source):
|
||||
deployed = set(re.findall(r'"(usr/local/bin/droiddeck-[^"]+)"\s+to\s+"usr/local/bin/[^"/]+"', source))
|
||||
# Extracted into usr/local/bin under any name, or (droiddeck-steam-taskset, which PATH puts in
|
||||
# front of Steam's own taskset only for the client) into usr/local/libexec/droiddeck-steam.
|
||||
deployed = set(re.findall(
|
||||
r'"(usr/local/bin/droiddeck-[^"]+)"\s+to\s+"usr/local/(?:bin|libexec/droiddeck-steam)/[^"/]+"', source))
|
||||
return ['not extracted at session start: ' + path.relative_to(overlay).as_posix()
|
||||
for path in sorted((overlay / 'usr/local/bin').glob('droiddeck-*'))
|
||||
if path.relative_to(overlay).as_posix() not in deployed]
|
||||
@@ -41,6 +45,16 @@ def check(apk, overlay=OVERLAY):
|
||||
continue
|
||||
if content != source.read_bytes():
|
||||
errors.append('stale ' + asset)
|
||||
if overlay == OVERLAY:
|
||||
spec = importlib.util.spec_from_file_location('powervr_fetch',
|
||||
OVERLAY.parents[1] / 'powervr/fetch.py')
|
||||
runtime = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(runtime)
|
||||
try:
|
||||
runtime.verify_archive(package.read('assets/hybris/runtime.tzst'),
|
||||
package.read('assets/hybris/version.txt').decode('ascii'))
|
||||
except (KeyError, ValueError, OSError) as error:
|
||||
errors.append('invalid PowerVR runtime: ' + str(error))
|
||||
return errors
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import hashlib
|
||||
import gzip
|
||||
import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
@@ -22,6 +23,7 @@ SOURCE_PATHS = ['app/build.gradle', 'app/src/main/cpp/fakeinput_steam.cpp', 'app
|
||||
'tools/linuxfs', 'tools/proot', 'tools/aaudio-sink', 'tools/directaudio', 'tools/packs',
|
||||
'tools/gamescope/release.env', 'tools/droiddeck-esync/release.env',
|
||||
'tools/mangoapp', 'tools/msitools', 'tools/pipewire', 'tools/comet', 'tools/xbox', 'tools/dirt-ws2', 'tools/components', 'tools/ci', 'tools/build_local.sh',
|
||||
'tools/powervr', 'tools/hybris', 'tools/dxvk', 'tools/vulkan-wsi',
|
||||
'tools/release/runtime_inputs.py', 'app/src/main/assets/desktop-removal',
|
||||
'tools/quest', 'tools/vr/src', 'tools/vr/driver_droiddeck', 'tools/vr/layer', 'tools/vr/build.sh',
|
||||
'tools/gpuload',
|
||||
@@ -53,7 +55,7 @@ def sources(root):
|
||||
|
||||
def outputs(root):
|
||||
result = {}
|
||||
for tree in ['linuxfs', 'directaudio', 'droiddeck-esync', 'desktop-removal']:
|
||||
for tree in ['linuxfs', 'directaudio', 'droiddeck-esync', 'desktop-removal', 'hybris']:
|
||||
base = root / 'app/src/main/assets' / tree
|
||||
for path in base.rglob('*'):
|
||||
if path.is_file() and not any(part.startswith('.') for part in path.relative_to(base).parts):
|
||||
@@ -85,6 +87,8 @@ def required():
|
||||
paths += ['assets/linuxfs/i386/libfaultreport.so']
|
||||
paths += ['assets/linuxfs/usr/local/lib/droiddeck-msitools/' + name for name in
|
||||
['msiinfo', 'cabextract', '7z', '7z.so', 'libmsi-1.0.so.0', 'libgsf-1.so.114', 'libgcab-1.0.so.0']]
|
||||
paths += ['assets/linuxfs/usr/local/lib/droiddeck-xclipse/' + name for name in
|
||||
['libVkLayer_droiddeck_xclipse.so', 'VkLayer_droiddeck_xclipse.json']]
|
||||
paths += ['assets/linuxfs/usr/local/lib/droiddeck-vr/' + name for name in
|
||||
['droiddeck/bin/linuxarm64/driver_droiddeck.so', 'droiddeck/bin/linuxarm64/xr-display-mode',
|
||||
'droiddeck/driver.vrdrivermanifest',
|
||||
@@ -115,9 +119,17 @@ def required():
|
||||
paths += ['assets/desktop-removal/' + name for name in
|
||||
['lxqt-r1.tsv.gzip', 'kde-remove.tsv.gzip', 'kde-keep.txt.gzip',
|
||||
'emulators-keep.txt.gzip', 'versions.txt', 'sources.json']]
|
||||
paths += ['assets/hybris/runtime.tzst', 'assets/hybris/version.txt']
|
||||
return paths
|
||||
|
||||
|
||||
def verify_powervr(root):
|
||||
spec = importlib.util.spec_from_file_location('powervr_fetch', ROOT / 'tools/powervr/fetch.py')
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
module.verify(root)
|
||||
|
||||
|
||||
def record(root=ROOT):
|
||||
if root == ROOT:
|
||||
from check_session_assets import source_assets
|
||||
@@ -129,6 +141,7 @@ def record(root=ROOT):
|
||||
missing = [name for name in required() if name not in paths or not (root / paths[name]).is_file()]
|
||||
if missing:
|
||||
raise ValueError('Missing runtime inputs:\n' + '\n'.join(missing))
|
||||
verify_powervr(root)
|
||||
for name, path in paths.items():
|
||||
if name.startswith('assets/desktop-removal/') and name.endswith('.gzip'):
|
||||
try:
|
||||
|
||||
@@ -0,0 +1,343 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <assert.h>
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Only the device/driver boundary is simulated. Descriptors and their lifetimes are real.
|
||||
* F_DUPFD_QUERY is modelled so this test also runs on older CI kernels; the device probe
|
||||
* separately exercises the actual query on Android. */
|
||||
#define TEST_FD_LIMIT 65536
|
||||
static _Atomic unsigned identities[TEST_FD_LIMIT];
|
||||
static struct f_owner_ex owners[TEST_FD_LIMIT];
|
||||
static unsigned identity_serial = 1;
|
||||
static int identity_denied, owner_denied, owner_probe_delay, kgsl_present;
|
||||
static int kernel_error = EINVAL;
|
||||
static int native_imports, native_exports, native_closes;
|
||||
static const char *driver_name = "pvr";
|
||||
static const char *pvr_node = "/dev/dri/renderD129";
|
||||
static int fixture_stat(const char *path, struct stat *st);
|
||||
static long fixture_syscall(long number, ...);
|
||||
static int fixture_fcntl(int fd, int op, ...);
|
||||
static void *fixture_dlsym(void *object, const char *name);
|
||||
static int fixture_close(int fd);
|
||||
|
||||
#define stat(path, st) fixture_stat(path, st)
|
||||
#define syscall fixture_syscall
|
||||
#define fcntl fixture_fcntl
|
||||
#define dlsym fixture_dlsym
|
||||
#define close fixture_close
|
||||
#include "../linuxfs/preload/drm.c"
|
||||
#undef stat
|
||||
#undef syscall
|
||||
#undef fcntl
|
||||
#undef dlsym
|
||||
#undef close
|
||||
|
||||
static int test_open(const char *path) {
|
||||
int fd = open(path, O_RDWR | O_CLOEXEC);
|
||||
assert(fd >= 0 && fd < TEST_FD_LIMIT);
|
||||
identities[fd] = identity_serial++;
|
||||
return fd;
|
||||
}
|
||||
|
||||
static int fixture_close(int fd) {
|
||||
if (fd >= 0 && fd < TEST_FD_LIMIT) identities[fd] = 0;
|
||||
return close(fd);
|
||||
}
|
||||
|
||||
static int fixture_stat(const char *path, struct stat *st) {
|
||||
if (!strcmp(path, "/dev/kgsl-3d0")) {
|
||||
if (kgsl_present) return stat("/dev/zero", st);
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
if (!strcmp(path, pvr_node)) return stat("/dev/null", st);
|
||||
if (!strcmp(path, "/dev/dri/renderD128")) return stat("/dev/zero", st);
|
||||
if (!strncmp(path, "/dev/dri/", 9)) { errno = ENOENT; return -1; }
|
||||
return stat(path, st);
|
||||
}
|
||||
|
||||
static int fixture_fcntl(int fd, int op, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, op);
|
||||
if (op == F_GETOWN_EX || op == F_SETOWN_EX) {
|
||||
struct f_owner_ex *owner = va_arg(ap, struct f_owner_ex *);
|
||||
va_end(ap);
|
||||
if (owner_denied) { errno = EINVAL; return -1; }
|
||||
if (fd < 0 || fd >= TEST_FD_LIMIT || !identities[fd] || !owner) {
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
if (op == F_GETOWN_EX) {
|
||||
*owner = owners[identities[fd]];
|
||||
} else {
|
||||
owners[identities[fd]] = *owner;
|
||||
if (owner_probe_delay && owner->pid) usleep(1000);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int arg = va_arg(ap, int);
|
||||
va_end(ap);
|
||||
if (op == F_DUPFD_QUERY) {
|
||||
if (identity_denied) { errno = EINVAL; return -1; }
|
||||
if (fd < 0 || arg < 0 || fd >= TEST_FD_LIMIT || arg >= TEST_FD_LIMIT ||
|
||||
!identities[fd] || !identities[arg]) { errno = EBADF; return -1; }
|
||||
return identities[fd] == identities[arg];
|
||||
}
|
||||
int ret = fcntl(fd, op, arg);
|
||||
if (ret >= 0 && (op == F_DUPFD || op == F_DUPFD_CLOEXEC)) {
|
||||
assert(ret < TEST_FD_LIMIT);
|
||||
identities[ret] = identities[fd];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static long fixture_syscall(long number, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, number);
|
||||
if (number == SYS_ioctl) {
|
||||
(void)va_arg(ap, int);
|
||||
unsigned long request = va_arg(ap, unsigned long);
|
||||
struct bl_drm_version *v = va_arg(ap, void *);
|
||||
assert(request == BL_DRM_VERSION);
|
||||
snprintf(v->name, v->name_len, "%s", driver_name);
|
||||
v->name_len = strlen(driver_name);
|
||||
va_end(ap);
|
||||
return 0;
|
||||
}
|
||||
va_end(ap);
|
||||
assert(number == SYS_kcmp);
|
||||
errno = EPERM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int native_import(int fd, int dma, uint32_t *handle) {
|
||||
(void)fd;
|
||||
native_imports++;
|
||||
if (fcntl(dma, F_GETFD) < 0) return -1;
|
||||
if (!handle) { errno = EFAULT; return -1; }
|
||||
if (kernel_error) { errno = kernel_error; return -1; }
|
||||
*handle = 42;
|
||||
return 0;
|
||||
}
|
||||
static int native_export(int fd, uint32_t handle, uint32_t flags, int *out) {
|
||||
(void)flags;
|
||||
native_exports++;
|
||||
if (handle != 42 || !out) { errno = EINVAL; return -1; }
|
||||
*out = fixture_fcntl(fd, F_DUPFD_CLOEXEC, 0);
|
||||
return *out < 0 ? -1 : 0;
|
||||
}
|
||||
static int native_close(int fd, uint32_t handle) {
|
||||
(void)fd;
|
||||
native_closes++;
|
||||
if (handle == 42) return 0;
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
static void *fixture_dlsym(void *object, const char *name) {
|
||||
assert(object == RTLD_NEXT);
|
||||
if (!strcmp(name, "drmPrimeFDToHandle")) return native_import;
|
||||
if (!strcmp(name, "drmPrimeHandleToFD")) return native_export;
|
||||
if (!strcmp(name, "drmCloseBufferHandle")) return native_close;
|
||||
abort();
|
||||
}
|
||||
|
||||
static int count_fds(void) {
|
||||
int count = 0;
|
||||
for (int fd = 0; fd < TEST_FD_LIMIT; ++fd) count += identities[fd] != 0;
|
||||
return count;
|
||||
}
|
||||
static void empty_table(void) {
|
||||
for (int i = 0; i < MAX_HANDLES; ++i) assert(!handle_entries[i].handle);
|
||||
}
|
||||
|
||||
struct fallback_stress {
|
||||
int drm;
|
||||
int dma;
|
||||
int failures;
|
||||
};
|
||||
|
||||
static void *stress_fallback_imports(void *opaque) {
|
||||
struct fallback_stress *stress = opaque;
|
||||
for (int i = 0; i < 20; i++) {
|
||||
uint32_t handle = 0;
|
||||
if (drmPrimeFDToHandle(stress->drm, stress->dma, &handle) != 0 ||
|
||||
drmCloseBufferHandle(stress->drm, handle) != 0) {
|
||||
stress->failures++;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int drm = test_open("/dev/null"), dma = test_open("/dev/zero");
|
||||
uint32_t handle = 0;
|
||||
unsetenv("BL_POWERVR_DRM_HANDLES");
|
||||
setenv("BL_POWERVR_RENDER_NODE", pvr_node, 1);
|
||||
assert(drmPrimeFDToHandle(drm, dma, &handle) != 0);
|
||||
setenv("BL_POWERVR_DRM_HANDLES", "yes", 1);
|
||||
assert(drmPrimeFDToHandle(drm, dma, &handle) != 0);
|
||||
setenv("BL_POWERVR_DRM_HANDLES", "1", 1);
|
||||
unsetenv("BL_POWERVR_RENDER_NODE");
|
||||
assert(drmPrimeFDToHandle(drm, dma, &handle) != 0); /* no selected node */
|
||||
setenv("BL_POWERVR_RENDER_NODE", "", 1);
|
||||
assert(drmPrimeFDToHandle(drm, dma, &handle) != 0);
|
||||
setenv("BL_POWERVR_RENDER_NODE", "/dev/dri/renderD128", 1);
|
||||
assert(drmPrimeFDToHandle(drm, dma, &handle) != 0); /* another GPU owns 128 */
|
||||
setenv("BL_POWERVR_RENDER_NODE", "/dev/dri/renderD130", 1);
|
||||
assert(drmPrimeFDToHandle(drm, dma, &handle) != 0); /* selected node is absent */
|
||||
setenv("BL_POWERVR_RENDER_NODE", __FILE__, 1);
|
||||
assert(drmPrimeFDToHandle(drm, dma, &handle) != 0); /* regular files are not DRM nodes */
|
||||
setenv("BL_POWERVR_RENDER_NODE", pvr_node, 1);
|
||||
driver_name = "other";
|
||||
assert(drmPrimeFDToHandle(drm, dma, &handle) != 0);
|
||||
driver_name = "pvr";
|
||||
assert(drmPrimeFDToHandle(dma, dma, &handle) != 0); /* wrong character device */
|
||||
kernel_error = EACCES;
|
||||
assert(drmPrimeFDToHandle(drm, dma, &handle) != 0 && errno == EACCES);
|
||||
kernel_error = EINVAL;
|
||||
assert(drmPrimeFDToHandle(drm, -1, &handle) != 0 && errno == EBADF);
|
||||
empty_table();
|
||||
|
||||
int baseline = count_fds();
|
||||
identity_denied = 1;
|
||||
assert(drmPrimeFDToHandle(drm, dma, &handle) == 0 && (handle & PVR_HANDLE_BIT));
|
||||
int denied_alias = fixture_fcntl(drm, F_DUPFD_CLOEXEC, 0), denied_out = -1;
|
||||
int denied_separate = test_open("/dev/null");
|
||||
assert(drmPrimeHandleToFD(denied_separate, handle, O_CLOEXEC, &denied_out) != 0);
|
||||
assert(drmPrimeHandleToFD(denied_alias, handle, O_CLOEXEC, &denied_out) == 0);
|
||||
fixture_close(denied_out);
|
||||
assert(drmCloseBufferHandle(denied_alias, handle) == 0);
|
||||
fixture_close(denied_alias);
|
||||
fixture_close(denied_separate);
|
||||
assert(count_fds() == baseline);
|
||||
owner_denied = 1;
|
||||
assert(drmPrimeFDToHandle(drm, dma, &handle) == -EOPNOTSUPP);
|
||||
assert(count_fds() == baseline);
|
||||
owner_denied = 0;
|
||||
|
||||
/* Marker changes and restoration must be atomic across concurrent imports of one DRM OFD. */
|
||||
owner_probe_delay = 1;
|
||||
struct fallback_stress stress[8];
|
||||
pthread_t workers[8];
|
||||
for (int i = 0; i < 8; i++) {
|
||||
stress[i] = (struct fallback_stress){.drm = drm, .dma = dma};
|
||||
assert(pthread_create(&workers[i], NULL, stress_fallback_imports, &stress[i]) == 0);
|
||||
}
|
||||
for (int i = 0; i < 8; i++) {
|
||||
assert(pthread_join(workers[i], NULL) == 0);
|
||||
assert(stress[i].failures == 0);
|
||||
}
|
||||
owner_probe_delay = 0;
|
||||
assert(owners[identities[drm]].pid == 0);
|
||||
assert(count_fds() == baseline);
|
||||
empty_table();
|
||||
identity_denied = 0;
|
||||
|
||||
assert(drmPrimeFDToHandle(drm, dma, &handle) == 0 && (handle & PVR_HANDLE_BIT));
|
||||
assert(count_fds() == baseline + 2);
|
||||
int alias = fixture_fcntl(drm, F_DUPFD_CLOEXEC, 0), out = -1;
|
||||
int separate = test_open("/dev/null");
|
||||
assert(drmPrimeHandleToFD(separate, handle, O_CLOEXEC | O_RDWR, &out) != 0);
|
||||
struct gem_close close_request = {.handle = handle};
|
||||
int rc = 123;
|
||||
assert(bl_drm_gem_close(separate, GEM_CLOSE, &close_request, &rc) == 0 && rc == 123);
|
||||
assert(drmPrimeHandleToFD(alias, handle, O_CLOEXEC | O_RDWR, &out) == 0);
|
||||
assert(fcntl(out, F_GETFD) & FD_CLOEXEC);
|
||||
struct stat src, dst;
|
||||
assert(fstat(dma, &src) == 0 && fstat(out, &dst) == 0);
|
||||
assert(src.st_dev == dst.st_dev && src.st_ino == dst.st_ino);
|
||||
fixture_close(out);
|
||||
assert(drmPrimeHandleToFD(alias, handle, 0, &out) == 0);
|
||||
assert(!(fcntl(out, F_GETFD) & FD_CLOEXEC));
|
||||
fixture_close(out);
|
||||
assert(drmPrimeHandleToFD(alias, handle, 0x40, &out) == -EINVAL);
|
||||
|
||||
/* A closed-and-reused descriptor must not inherit the old open file's handles. */
|
||||
int old_number = drm;
|
||||
fixture_close(drm);
|
||||
drm = test_open("/dev/null");
|
||||
assert(drm == old_number);
|
||||
assert(drmPrimeHandleToFD(drm, handle, O_CLOEXEC, &out) != 0);
|
||||
assert(drmCloseBufferHandle(drm, handle) != 0);
|
||||
assert(drmPrimeHandleToFD(alias, handle, O_CLOEXEC, &out) == 0);
|
||||
fixture_close(out);
|
||||
assert(bl_drm_gem_close(alias, GEM_CLOSE, &close_request, &rc) == 1 && rc == 0);
|
||||
assert(drmPrimeHandleToFD(alias, handle, O_CLOEXEC, &out) != 0);
|
||||
fixture_close(alias);
|
||||
fixture_close(separate);
|
||||
assert(count_fds() == baseline);
|
||||
empty_table();
|
||||
|
||||
/* Real kernel handles and their direct GEM_CLOSE ioctls are never swallowed. */
|
||||
kernel_error = 0;
|
||||
assert(drmPrimeFDToHandle(drm, dma, &handle) == 0 && handle == 42);
|
||||
empty_table();
|
||||
assert(drmPrimeHandleToFD(drm, handle, O_CLOEXEC, &out) == 0);
|
||||
fixture_close(out);
|
||||
close_request.handle = handle;
|
||||
assert(bl_drm_gem_close(drm, GEM_CLOSE, &close_request, &rc) == 0);
|
||||
assert(drmCloseBufferHandle(drm, handle) == 0);
|
||||
assert(native_imports && native_exports && native_closes);
|
||||
kernel_error = EINVAL;
|
||||
|
||||
/* Slot reuse must not reuse public tokens or leak either owned descriptor. */
|
||||
uint32_t previous = 0;
|
||||
for (int n = 0; n < 1000; ++n) {
|
||||
assert(drmPrimeFDToHandle(drm, dma, &handle) == 0 && handle != previous);
|
||||
assert(drmCloseBufferHandle(drm, handle) == 0);
|
||||
if (previous) assert(drmPrimeHandleToFD(drm, previous, O_CLOEXEC, &out) != 0);
|
||||
previous = handle;
|
||||
}
|
||||
assert(count_fds() == baseline);
|
||||
empty_table();
|
||||
|
||||
assert(drmPrimeFDToHandle(drm, dma, &handle) == 0);
|
||||
pid_t child = fork();
|
||||
assert(child >= 0);
|
||||
if (child == 0) {
|
||||
assert(drmPrimeHandleToFD(drm, handle, O_CLOEXEC, &out) == 0);
|
||||
fixture_close(out);
|
||||
assert(drmCloseBufferHandle(drm, handle) == 0);
|
||||
_exit(0);
|
||||
}
|
||||
int status;
|
||||
assert(waitpid(child, &status, 0) == child && WIFEXITED(status) && WEXITSTATUS(status) == 0);
|
||||
assert(drmPrimeHandleToFD(drm, handle, O_CLOEXEC, &out) == 0);
|
||||
fixture_close(out);
|
||||
assert(drmCloseBufferHandle(drm, handle) == 0);
|
||||
|
||||
/* Preserve the original device layout when PowerVR owns renderD128. */
|
||||
pvr_node = "/dev/dri/renderD128";
|
||||
setenv("BL_POWERVR_RENDER_NODE", pvr_node, 1);
|
||||
assert(drmPrimeFDToHandle(drm, dma, &handle) == 0 && (handle & PVR_HANDLE_BIT));
|
||||
assert(drmCloseBufferHandle(drm, handle) == 0);
|
||||
|
||||
/* Retain the old KGSL path with the PowerVR opt-in unset. */
|
||||
unsetenv("BL_POWERVR_DRM_HANDLES");
|
||||
kgsl_present = 1;
|
||||
kgsl_state = 0;
|
||||
assert(drmPrimeFDToHandle(dma, drm, &handle) == 0 && !(handle & PVR_HANDLE_BIT));
|
||||
assert(drmPrimeHandleToFD(dma, handle, O_CLOEXEC | O_RDWR, &out) == 0);
|
||||
fixture_close(out);
|
||||
close_request.handle = handle;
|
||||
assert(bl_drm_gem_close(dma, GEM_CLOSE, &close_request, &rc) == 1 && rc == 0);
|
||||
assert(drmCloseBufferHandle(dma, handle) == -EINVAL);
|
||||
empty_table();
|
||||
assert(count_fds() == baseline);
|
||||
fixture_close(drm);
|
||||
fixture_close(dma);
|
||||
puts("DRM adapter scoping, ownership, reuse, fork and kernel-passthrough tests passed");
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
class DrmHandleTest(unittest.TestCase):
|
||||
def test_handle_lifetime_and_device_scope(self):
|
||||
compiler = shutil.which(os.environ.get("CC", "cc"))
|
||||
if not compiler:
|
||||
self.fail("A C compiler is required for the DRM adapter regression test")
|
||||
source = Path(__file__).with_name("drm_handles_test.c")
|
||||
with tempfile.TemporaryDirectory(prefix="droiddeck-drm-") as tmp:
|
||||
program = Path(tmp) / "drm-handles"
|
||||
built = subprocess.run([compiler, "-std=gnu11", "-Wall", "-Wextra", "-Werror",
|
||||
"-UNDEBUG", "-pthread", str(source), "-ldl", "-o", str(program)],
|
||||
capture_output=True, text=True)
|
||||
self.assertEqual(built.returncode, 0, built.stdout + built.stderr)
|
||||
ran = subprocess.run([str(program)], capture_output=True, text=True, timeout=30)
|
||||
self.assertEqual(ran.returncode, 0, ran.stdout + ran.stderr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,121 @@
|
||||
"""Exercise output isolation with a synthetic toolchain; no network/DLL build."""
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
|
||||
# Substitute only external source/compiler/archive commands. The real build.sh
|
||||
# owns output checks, architecture iteration and manifest inputs.
|
||||
FAKE_TOOL = r'''
|
||||
import hashlib, json, os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
name = Path(sys.argv[0]).name
|
||||
args = sys.argv[1:]
|
||||
with open(os.environ['TOOL_CALLS'], 'a') as stream:
|
||||
stream.write(name + '\n')
|
||||
if name == 'git':
|
||||
if args[0] == 'init':
|
||||
Path(args[-1]).mkdir()
|
||||
(Path(args[-1]) / 'LICENSE').write_text('synthetic public license')
|
||||
elif 'rev-parse' in args:
|
||||
print(os.environ['TEST_REVISION'])
|
||||
elif name == 'meson':
|
||||
if args[0] == 'setup':
|
||||
p = Path(args[1]); p.mkdir()
|
||||
p.joinpath('config.json').write_text(json.dumps({
|
||||
'out': args[args.index('--prefix') + 1],
|
||||
'arch': args[args.index('--bindir') + 1]}))
|
||||
elif args[0] == 'install':
|
||||
config = json.loads(Path(args[2], 'config.json').read_text())
|
||||
out = Path(config['out'], config['arch']); out.mkdir(exist_ok=True)
|
||||
out.joinpath('current.dll').write_bytes(b'synthetic current pinned DLL')
|
||||
if config['arch'] == os.environ.get('FAIL_INSTALL_ARCH'):
|
||||
sys.exit(5)
|
||||
elif name == 'tar':
|
||||
Path(args[args.index('-cf') + 1]).write_bytes(b'synthetic source archive')
|
||||
elif name == 'sha256sum':
|
||||
for arg in args:
|
||||
print(hashlib.sha256(Path(arg).read_bytes()).hexdigest() + ' ' + arg)
|
||||
elif name != 'python3':
|
||||
raise AssertionError(name)
|
||||
'''
|
||||
|
||||
|
||||
class DxvkBuildTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.temporary = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self.temporary.cleanup)
|
||||
self.base = Path(self.temporary.name)
|
||||
self.bin = self.base / 'bin'; self.bin.mkdir()
|
||||
executable = self.bin / 'fake-tool'
|
||||
executable.write_text('#!' + sys.executable + '\n' + FAKE_TOOL)
|
||||
executable.chmod(0o755)
|
||||
for name in ('git', 'meson', 'tar', 'sha256sum', 'python3'):
|
||||
(self.bin / name).symlink_to(executable)
|
||||
self.calls = self.base / 'calls'
|
||||
self.env = dict(os.environ, PATH=str(self.bin) + os.pathsep + os.environ['PATH'],
|
||||
TOOL_CALLS=str(self.calls))
|
||||
source_env = ROOT / 'tools/dxvk/source.env'
|
||||
self.env['TEST_REVISION'] = next(line.split('=', 1)[1].strip('"\'')
|
||||
for line in source_env.read_text().splitlines()
|
||||
if line.startswith('DXVK_REVISION='))
|
||||
self.output = self.base / 'component'
|
||||
|
||||
def build(self):
|
||||
return subprocess.run(['bash', str(ROOT / 'tools/dxvk/build.sh'), str(self.output)],
|
||||
env=self.env, capture_output=True, text=True, timeout=10)
|
||||
|
||||
def test_stale_dll_is_rejected_untouched_before_fetch(self):
|
||||
stale = self.output / 'x32/stale.dll'; stale.parent.mkdir(parents=True)
|
||||
stale.write_bytes(b'prior pinned build')
|
||||
result = self.build()
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertIn('output directory must be empty', result.stderr)
|
||||
self.assertEqual(stale.read_bytes(), b'prior pinned build')
|
||||
self.assertFalse(self.calls.exists())
|
||||
self.assertFalse((self.output / 'SHA256SUMS').exists())
|
||||
|
||||
def test_hidden_contents_are_also_rejected(self):
|
||||
self.output.mkdir(); (self.output / '.previous').write_text('retained')
|
||||
self.assertNotEqual(self.build().returncode, 0)
|
||||
self.assertFalse(self.calls.exists())
|
||||
self.assertEqual((self.output / '.previous').read_text(), 'retained')
|
||||
|
||||
def test_empty_or_new_output_contains_only_current_dlls(self):
|
||||
for existing in (False, True):
|
||||
with self.subTest(existing=existing):
|
||||
self.output = self.base / ('existing' if existing else 'new')
|
||||
if existing: self.output.mkdir()
|
||||
result = self.build()
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
rows = (self.output / 'SHA256SUMS').read_text().splitlines()
|
||||
self.assertEqual([row.split(' ')[1] for row in rows],
|
||||
['x32/current.dll', 'x64/current.dll'])
|
||||
for row in rows:
|
||||
digest, path = row.split(' ')
|
||||
self.assertEqual(digest, hashlib.sha256((self.output / path).read_bytes()).hexdigest())
|
||||
|
||||
def test_partial_build_is_not_reused_or_deleted(self):
|
||||
self.env['FAIL_INSTALL_ARCH'] = 'x64'
|
||||
result = self.build()
|
||||
self.assertEqual(result.returncode, 5, result.stderr)
|
||||
before = {str(p.relative_to(self.output)): p.read_bytes()
|
||||
for p in self.output.rglob('*') if p.is_file()}
|
||||
self.calls.unlink(); del self.env['FAIL_INSTALL_ARCH']
|
||||
result = self.build()
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertFalse(self.calls.exists())
|
||||
after = {str(p.relative_to(self.output)): p.read_bytes()
|
||||
for p in self.output.rglob('*') if p.is_file()}
|
||||
self.assertEqual(after, before)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -26,6 +26,7 @@ class EffectsSourceResolutionTest(unittest.TestCase):
|
||||
header = (REPO / 'app/src/main/cpp/waylandcomp/src/vk_present.h').read_text()
|
||||
effects = (REPO / 'app/src/main/cpp/waylandcomp/src/effects_chain.c').read_text()
|
||||
functions = '\n'.join(function(source, signature) for signature in (
|
||||
'static void release_external_client_image(', 'static void release_external_client_draws(',
|
||||
'static int map_draw(', 'static int draw_to_blit(',
|
||||
'static int draw_to_scene_blit(', 'static int effects_source_draw(',
|
||||
'static void effects_source_note(',
|
||||
@@ -37,11 +38,13 @@ class EffectsSourceResolutionTest(unittest.TestCase):
|
||||
image = source[source.index('struct vkp_image {'):source.index('\n};', source.index('struct vkp_image {')) + 3]
|
||||
draw = header[header.index('struct vkp_draw {'):header.index('\n};', header.index('struct vkp_draw {')) + 3]
|
||||
hdr = header[header.index('struct vkp_hdr_frame {'):header.index('\n};', header.index('struct vkp_hdr_frame {')) + 3]
|
||||
constants = sorted(set(re.findall(r'\bVK_[A-Z0-9_]+\b', functions + image)) -
|
||||
sync = (REPO / 'app/src/main/cpp/waylandcomp/src/vk_external_image_sync.h').read_text()
|
||||
sync = re.sub(r'^#(include|ifndef|define|endif).*$', '', sync, flags=re.M)
|
||||
constants = sorted(set(re.findall(r'\bVK_[A-Z0-9_]+\b', functions + image + sync)) -
|
||||
{'VK_FORMAT_R8G8B8A8_UNORM'})
|
||||
definitions = '\n'.join(f'#define {name} {0 if name in ("VK_SUCCESS", "VK_NULL_HANDLE") else i + 1}'
|
||||
for i, name in enumerate(constants))
|
||||
code = TYPES + definitions + '\n' + image + '\n' + draw + '\n' + hdr + STUBS + functions + CASES
|
||||
code = TYPES + definitions + '\n' + sync + '\n' + image + '\n' + draw + '\n' + hdr + STUBS + functions + CASES
|
||||
cls.temp = tempfile.TemporaryDirectory(prefix='droiddeck-effects-resolution-')
|
||||
cls.addClassCleanup(cls.temp.cleanup)
|
||||
folder = Path(cls.temp.name)
|
||||
@@ -148,10 +151,12 @@ typedef struct {
|
||||
#define droiddeck_log(...) ((void)0)
|
||||
#define LOGE(...) ((void)0)
|
||||
struct droiddeck_color { uint32_t identity; };
|
||||
typedef struct AHardwareBuffer AHardwareBuffer;
|
||||
'''
|
||||
|
||||
|
||||
STUBS = r'''
|
||||
static void quarantine_pending_work(VkResult result, const char *where) { (void)result; (void)where; }
|
||||
static int noop(int handle, ...) { return VK_SUCCESS; }
|
||||
static VkImageMemoryBarrier recorded_barriers[64];
|
||||
static int barrier_count;
|
||||
@@ -173,7 +178,7 @@ static struct {
|
||||
int (*EndCommandBuffer)(int, ...), (*ResetFences)(int, ...);
|
||||
int (*QueueSubmit)(int, ...), (*QueuePresentKHR)(int, ...);
|
||||
} g_vk = {noop, noop, note_barriers, noop, noop, noop, noop, noop};
|
||||
static int g_dev_state, g_window = 1, g_swapchain, g_swap_extra;
|
||||
static int g_dev_state = 1, g_window = 1, g_swapchain, g_swap_extra;
|
||||
static int g_colorspace_ext, g_swap_hdr_unavailable, g_swap_is_hdr, g_swap_hdr_want;
|
||||
static int g_plain_frame, g_first_frame_done, g_base_black;
|
||||
static int g_qfam, g_queue, g_dev, g_fence, g_swap_fmt = SCENE_FMT;
|
||||
@@ -195,7 +200,7 @@ static VkImageBlit copied;
|
||||
static struct vkp_draw recorded_draws[16];
|
||||
static VkImageBlit recorded_blits[16];
|
||||
static VkImage recorded_targets[16];
|
||||
static int recorded_after_effects[16];
|
||||
static int recorded_after_effects[16], recorded_barrier_marks[16];
|
||||
static void vkp_apply_window_request(void) {}
|
||||
static void sc_layer_hide_base(void) {}
|
||||
static void check_surface_changed(void) {}
|
||||
@@ -238,6 +243,7 @@ static void record_draw(int cmd, const struct vkp_draw *draw, const VkImageBlit
|
||||
assert(copy_count < 16);
|
||||
recorded_draws[copy_count] = *draw; recorded_blits[copy_count] = *blit;
|
||||
recorded_targets[copy_count] = target; recorded_after_effects[copy_count] = effects_count > 0;
|
||||
recorded_barrier_marks[copy_count] = barrier_count;
|
||||
copy_count++; copied = *blit;
|
||||
copied_w = draw->dw; copied_h = draw->dh; target_w = w; target_h = h;
|
||||
}
|
||||
@@ -509,11 +515,16 @@ static void check_overlay_barriers(void) {
|
||||
reset();
|
||||
struct vkp_draw layers[] = {background_draw(), fullscreen(), cursor_draw()};
|
||||
run_path(offscreen, layers, 3, NULL); check_input(1280, 720);
|
||||
int acquired = find_barrier(cursor.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
||||
int acquired = find_barrier(cursor.image, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
||||
assert(acquired >= 0 && recorded_barriers[acquired].srcQueueFamilyIndex == VK_QUEUE_FAMILY_FOREIGN_EXT);
|
||||
int writable = find_barrier(4, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
int readable = find_barrier(4, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
||||
assert(writable > acquired && readable > writable);
|
||||
int released = find_barrier(cursor.image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL);
|
||||
assert(released > acquired && recorded_barriers[released].dstQueueFamilyIndex == VK_QUEUE_FAMILY_FOREIGN_EXT);
|
||||
int last_cursor_draw = -1;
|
||||
for (int i = 0; i < copy_count; i++) if (recorded_draws[i].img == &cursor) last_cursor_draw = i;
|
||||
assert(last_cursor_draw >= 0 && released >= recorded_barrier_marks[last_cursor_draw]);
|
||||
}
|
||||
}
|
||||
static void check_postprocessing(void) {
|
||||
|
||||
@@ -11,6 +11,7 @@ import sys
|
||||
import tempfile
|
||||
from unittest import mock
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
BIN = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin"
|
||||
MODULE = runpy.run_path(str(BIN / "droiddeck-game-env"))
|
||||
@@ -410,6 +411,154 @@ class EgoCorePlanTest(unittest.TestCase):
|
||||
self.assertIn("added a copy of its 4-core plan", result.stderr)
|
||||
|
||||
|
||||
class SystemGraphicsLaunchTest(unittest.TestCase):
|
||||
def test_start_configures_ubisoft_with_proton_before_wrapping_the_game(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
runtime, _ = self.runtime(root)
|
||||
prefix = root / "42" / "pfx"
|
||||
(prefix / MODULE["UBISOFT_LAUNCHER"]).mkdir(parents=True)
|
||||
(prefix / "user.reg").write_text("WINE REGISTRY Version 2\n")
|
||||
env = {"DROIDDECK_POWERVR_RUNTIME": str(runtime), "STEAM_COMPAT_DATA_PATH": str(prefix.parent)}
|
||||
command = ["/selected/proton", "waitforexitandrun", "game.exe"]
|
||||
with mock.patch("subprocess.run") as run, mock.patch("os.execvpe") as execute:
|
||||
MODULE["start"](command, env, None)
|
||||
self.assertEqual(run.call_count, 2)
|
||||
for call in run.call_args_list:
|
||||
self.assertEqual(call.args[0][:3], ["/selected/proton", "runinprefix", "reg.exe"])
|
||||
self.assertEqual(execute.call_args.args[:2], (str(runtime / "run-proton.py"),
|
||||
[str(runtime / "run-proton.py"), *command]))
|
||||
|
||||
def runtime(self, root):
|
||||
runtime = root / "system_vulkan" / ("a" * 64)
|
||||
files = ["run-proton.py", "lib/libVkLayer_hybris_compat.so",
|
||||
"wsi/libVkLayer_window_system_integration.so",
|
||||
"wsi/VkLayer_window_system_integration.json"]
|
||||
files += ["dxvk/%s/%s.dll" % (arch, name) for arch in ("x32", "x64")
|
||||
for name in ("d3d8", "d3d9", "d3d10core", "d3d11", "dxgi")]
|
||||
for name in files:
|
||||
target = runtime / name
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_bytes(b"component")
|
||||
(runtime / "run-proton.py").chmod(0o755)
|
||||
return runtime, files
|
||||
|
||||
def test_other_gpus_and_non_game_calls_keep_the_original_launch(self):
|
||||
command = ["/proton", "waitforexitandrun", "game.exe"]
|
||||
base = {"STEAM_COMPAT_DATA_PATH": "/compatdata/42", "VK_LAYER_PATH": "original"}
|
||||
selected = dict(base, DROIDDECK_POWERVR_RUNTIME="/not-installed")
|
||||
cases = [(command, base), (command, dict(selected, STEAM_COMPAT_DATA_PATH="/compatdata/0")),
|
||||
(command, dict(selected, STEAM_COMPAT_DATA_PATH="/compatdata/invalid")),
|
||||
(["/proton", "run", "iscriptevaluator.exe"], selected),
|
||||
(["/proton", "getcompatpath", "x"], selected), (command[:2], selected)]
|
||||
for args, env in cases:
|
||||
with self.subTest(args=args, env=env):
|
||||
actual, inherited = MODULE["system_graphics_launch"](args, env)
|
||||
self.assertIs(actual, args)
|
||||
self.assertIs(inherited, env)
|
||||
|
||||
def test_system_graphics_follow_game_configuration_and_preserve_other_keys(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
runtime, _ = self.runtime(Path(tmp))
|
||||
base = {"DROIDDECK_POWERVR_RUNTIME": str(runtime), "STEAM_COMPAT_DATA_PATH": "/compatdata/42"}
|
||||
config = {"version": 1, "games": {"42": {
|
||||
"PROTON_USE_WINED3D": "1", "DISABLE_WSI_LAYER": "1",
|
||||
"ENABLE_VK_LAYER_VALVE_steam_fossilize_1": "1", "HYBRIS_BC_TEXTURES": "0",
|
||||
"VK_LAYER_PATH": "old", "VK_INSTANCE_LAYERS": "old", "ENABLE_GAMESCOPE_WSI": "1",
|
||||
"FEX_TSOENABLED": "1", "WINESERVER": "/selected/wineserver", "CUSTOM": "literal $value",
|
||||
}}}
|
||||
env = MODULE["apply_config"](base, config, "42")
|
||||
command = ["/selected/proton", "waitforexitandrun", "game with spaces.exe"]
|
||||
launch, result = MODULE["system_graphics_launch"](command, env)
|
||||
self.assertEqual(launch, [str(runtime / "run-proton.py"), *command])
|
||||
self.assertEqual(result["HYBRIS_BC_TEXTURES"], "dxvk")
|
||||
self.assertEqual(result["VK_LAYER_PATH"], f"{runtime}/wsi:{runtime}/lib")
|
||||
self.assertEqual(result["VK_INSTANCE_LAYERS"], "VK_LAYER_window_system_integration:VK_LAYER_HYBRIS_compat")
|
||||
self.assertEqual(result["VK_LOADER_LAYERS_DISABLE"], "*gamescope*")
|
||||
self.assertEqual(result["ENABLE_GAMESCOPE_WSI"], "0")
|
||||
self.assertEqual(result["DISABLE_VK_LAYER_VALVE_steam_fossilize_1"], "1")
|
||||
for key in ("PROTON_USE_WINED3D", "DISABLE_WSI_LAYER", "ENABLE_VK_LAYER_VALVE_steam_fossilize_1"):
|
||||
self.assertNotIn(key, result)
|
||||
self.assertIn(key, env)
|
||||
for key in ("FEX_TSOENABLED", "WINESERVER", "CUSTOM"):
|
||||
self.assertEqual(result[key], env[key])
|
||||
|
||||
def test_xclipse_selection_adds_its_layers_layer_path_and_dxvk_payload(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
runtime, _ = self.runtime(Path(tmp))
|
||||
env = {"DROIDDECK_POWERVR_RUNTIME": str(runtime), "STEAM_COMPAT_DATA_PATH": "/compatdata/42",
|
||||
"DROIDDECK_HYBRIS_LAYERS": "VK_LAYER_DROIDDECK_xclipse:VK_LAYER_HYBRIS_compat",
|
||||
"DROIDDECK_HYBRIS_LAYER_PATH": "/usr/local/lib/droiddeck-xclipse",
|
||||
"DROIDDECK_HYBRIS_DXVK": "dxvk-2.6.2"}
|
||||
command = ["/proton", "waitforexitandrun", "game.exe"]
|
||||
# The selected payload is required like the default one.
|
||||
with self.assertRaises(MODULE["SystemGraphicsError"]):
|
||||
MODULE["system_graphics_launch"](command, env)
|
||||
for arch in ("x32", "x64"):
|
||||
for name in ("d3d8", "d3d9", "d3d10core", "d3d11", "dxgi"):
|
||||
target = runtime / "dxvk-2.6.2" / arch / (name + ".dll")
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_bytes(b"component")
|
||||
launch, result = MODULE["system_graphics_launch"](command, env)
|
||||
self.assertEqual(launch, [str(runtime / "run-proton.py"), *command])
|
||||
self.assertEqual(result["VK_INSTANCE_LAYERS"],
|
||||
"VK_LAYER_window_system_integration:VK_LAYER_DROIDDECK_xclipse:VK_LAYER_HYBRIS_compat")
|
||||
self.assertEqual(result["VK_LAYER_PATH"], f"{runtime}/wsi:{runtime}/lib:/usr/local/lib/droiddeck-xclipse")
|
||||
self.assertEqual(result["DROIDDECK_HYBRIS_DXVK"], "dxvk-2.6.2")
|
||||
for name in ("../dxvk", "other", "dxvk/x"):
|
||||
with self.subTest(name=name), self.assertRaises(MODULE["SystemGraphicsError"]):
|
||||
MODULE["system_graphics_launch"](command, dict(env, DROIDDECK_HYBRIS_DXVK=name))
|
||||
|
||||
def test_incomplete_runtime_fails_before_any_proton_exec(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
runtime, files = self.runtime(Path(tmp))
|
||||
env = {"DROIDDECK_POWERVR_RUNTIME": str(runtime), "STEAM_COMPAT_DATA_PATH": "/compatdata/42"}
|
||||
command = ["/proton", "waitforexitandrun", "game.exe"]
|
||||
for name in files:
|
||||
target = runtime / name
|
||||
original = target.read_bytes()
|
||||
for missing in (False, True):
|
||||
with self.subTest(name=name, missing=missing):
|
||||
target.unlink() if missing else target.write_bytes(b"")
|
||||
with patch.object(os, "execvpe") as execute:
|
||||
with self.assertRaises(MODULE["SystemGraphicsError"]):
|
||||
MODULE["exec_proton"](command, env)
|
||||
execute.assert_not_called()
|
||||
target.write_bytes(original)
|
||||
if name == "run-proton.py":
|
||||
target.chmod(0o755)
|
||||
(runtime / "run-proton.py").chmod(0o644)
|
||||
with self.assertRaises(MODULE["SystemGraphicsError"]):
|
||||
MODULE["system_graphics_launch"](command, env)
|
||||
with self.assertRaises(MODULE["SystemGraphicsError"]):
|
||||
MODULE["system_graphics_launch"](command, dict(env, DROIDDECK_POWERVR_RUNTIME="relative"))
|
||||
|
||||
def test_wrapper_receives_the_sync_selected_proton(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
runtime, _ = self.runtime(root)
|
||||
env = {"HOME": tmp, "DROIDDECK_POWERVR_RUNTIME": str(runtime),
|
||||
"STEAM_COMPAT_DATA_PATH": "/compatdata/42"}
|
||||
command = ["/stock/proton", "waitforexitandrun", "game.exe"]
|
||||
selected = ["/sync-pack/proton", *command[1:]]
|
||||
selected_env = dict(env, WINESERVER="/sync-pack/wineserver", BL_SYNC_PACK="selected")
|
||||
main = MODULE["main"]
|
||||
with patch.dict(os.environ, env, clear=True), patch.object(sys, "argv", ["game-env", *command]), \
|
||||
patch.dict(main.__globals__, {"load_sync": lambda: {},
|
||||
"select_sync": lambda *args: (selected, selected_env),
|
||||
"win_components": lambda *args: ""}), \
|
||||
patch.object(os, "execvpe", side_effect=SystemExit(23)) as execute:
|
||||
with self.assertRaises(SystemExit) as stopped:
|
||||
main()
|
||||
self.assertEqual(stopped.exception.code, 23)
|
||||
execute.assert_called_once()
|
||||
path, args, actual_env = execute.call_args.args
|
||||
self.assertEqual(path, str(runtime / "run-proton.py"))
|
||||
self.assertEqual(args, [path, *selected])
|
||||
self.assertEqual(actual_env["WINESERVER"], "/sync-pack/wineserver")
|
||||
self.assertEqual(actual_env["BL_SYNC_PACK"], "selected")
|
||||
|
||||
|
||||
class GameDebugLoggingTest(unittest.TestCase):
|
||||
def test_maintenance_precision_survives_run_with_performance_game_settings(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
@@ -807,6 +956,55 @@ class GameEnvironmentTest(unittest.TestCase):
|
||||
subprocess.run(["bash", "-c", script, "test", str(base)], env=env, check=True)
|
||||
self.assertEqual(target.read_text(), "general")
|
||||
|
||||
def test_system_powervr_preserves_dxvk_profiles_without_applying_them(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
home = root / "home"
|
||||
component_dir = home / ".local/share/droiddeck-components"
|
||||
component_dir.mkdir(parents=True)
|
||||
base = root / "proton"
|
||||
paths = {
|
||||
"dxvk": "files/lib/wine/dxvk/aarch64-windows/d3d11.dll",
|
||||
"fex": "files/lib/wine/aarch64-windows/libarm64ecfex.dll",
|
||||
"vkd3d": "files/lib/wine/vkd3d-proton/aarch64-windows/d3d12.dll",
|
||||
}
|
||||
rows = []
|
||||
for comp, rel in paths.items():
|
||||
target = base / rel
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_text("bundled " + comp)
|
||||
for scope in ("*", "42"):
|
||||
source = root / (comp + ("-general" if scope == "*" else "-game"))
|
||||
source.write_text(source.name)
|
||||
rows.append("%s\tproton\tbuild-1\t%s\t%s\t%s\t%s\n" % (
|
||||
scope, comp, rel, hashlib.sha256(source.read_bytes()).hexdigest(), source,
|
||||
))
|
||||
leftover = (base / paths["dxvk"]).with_name("d3d8.dll")
|
||||
leftover.write_text("bundled d3d8")
|
||||
rows.append("42\tproton\tbuild-1\tdxvk\t%s\t-\t-\n" % leftover.relative_to(base))
|
||||
(base / "version").write_text("1 build-1\n")
|
||||
selection = component_dir / "desired.tsv"
|
||||
selection.write_text("".join(rows))
|
||||
saved = selection.read_bytes()
|
||||
script = COMPAT["BL_COMPONENTS_SETUP"] + '\nverb=waitforexitandrun; bl_components "$1"\n'
|
||||
env = dict(os.environ, HOME=str(home), STEAM_COMPAT_DATA_PATH="/steam/compatdata/42",
|
||||
DROIDDECK_POWERVR_RUNTIME="/system_vulkan/runtime")
|
||||
|
||||
subprocess.run(["bash", "-c", script, "test", str(base)], env=env, check=True)
|
||||
|
||||
self.assertEqual((base / paths["dxvk"]).read_text(), "bundled dxvk")
|
||||
self.assertEqual(leftover.read_text(), "bundled d3d8")
|
||||
for comp in ("fex", "vkd3d"):
|
||||
self.assertEqual((base / paths[comp]).read_text(), comp + "-game")
|
||||
self.assertEqual(selection.read_bytes(), saved)
|
||||
|
||||
# A subsequent manual-driver session still applies the saved per-game DXVK choice.
|
||||
env.pop("DROIDDECK_POWERVR_RUNTIME")
|
||||
subprocess.run(["bash", "-c", script, "test", str(base)], env=env, check=True)
|
||||
self.assertEqual((base / paths["dxvk"]).read_text(), "dxvk-game")
|
||||
self.assertFalse(leftover.exists())
|
||||
self.assertEqual(selection.read_bytes(), saved)
|
||||
|
||||
def test_component_scope_matches_environment_scope_for_shortcut_ids(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
@@ -1294,6 +1492,49 @@ class GameEnvironmentTest(unittest.TestCase):
|
||||
with self.assertRaises(ValueError):
|
||||
MODULE["apply_config"]({}, {**config, "dxvkConfigGames": []}, "42")
|
||||
|
||||
def test_game_logs_only_when_asked_and_only_for_game_launches(self):
|
||||
game_logs = MODULE["game_logs"]
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
command = ["/proton", "waitforexitandrun", "/games/Hades/Hades.exe"]
|
||||
env = {"BL_DEBUG_DIR": tmp, "VK_DRIVER_FILES": "/icd.json"}
|
||||
self.assertEqual(game_logs(command, env, "1145360", now=0), env)
|
||||
on = dict(env, BL_GAME_LOGS="1")
|
||||
self.assertEqual(game_logs(["/proton", "run", "x.exe"], on, "1145360", now=0), on)
|
||||
result = game_logs(command, on, "1145360", now=0)
|
||||
folder = Path(result["PROTON_LOG_DIR"])
|
||||
self.assertEqual(folder.parent, Path(tmp) / "games")
|
||||
self.assertTrue(folder.name.endswith("-1145360"))
|
||||
self.assertEqual(result["DXVK_LOG_PATH"], str(folder))
|
||||
self.assertEqual(result["PROTON_LOG"], "1")
|
||||
launch = (folder / "launch.txt").read_text()
|
||||
self.assertIn("VK_DRIVER_FILES=/icd.json", launch)
|
||||
self.assertNotIn("PROTON_LOG", env)
|
||||
named = game_logs(command, on, None, now=0)
|
||||
self.assertTrue(Path(named["PROTON_LOG_DIR"]).name.endswith("-Hades"))
|
||||
|
||||
def test_rapid_game_launches_keep_separate_diagnostics(self):
|
||||
with tempfile.TemporaryDirectory() as tmp, mock.patch("subprocess.Popen"):
|
||||
env = {"BL_GAME_LOGS": "1", "BL_DEBUG_DIR": tmp}
|
||||
first = MODULE["game_logs"](["/proton", "waitforexitandrun", "first.exe"], env, "42", now=0)
|
||||
second = MODULE["game_logs"](["/proton", "waitforexitandrun", "second.exe"], env, "42", now=0)
|
||||
self.assertNotEqual(first["PROTON_LOG_DIR"], second["PROTON_LOG_DIR"])
|
||||
self.assertIn("exe: first.exe", (Path(first["PROTON_LOG_DIR"]) / "launch.txt").read_text())
|
||||
self.assertIn("exe: second.exe", (Path(second["PROTON_LOG_DIR"]) / "launch.txt").read_text())
|
||||
|
||||
def test_open_driver_pairs_report_the_drivers_own_vkd3d_caps(self):
|
||||
apply = MODULE["apply_config"]
|
||||
config = {"version": 1, "shared": {"VKD3D_FEATURE_LEVEL": "12_2", "VKD3D_SHADER_MODEL": "6_9"},
|
||||
"games": {"42": {"VKD3D_SHADER_MODEL": "6_6"}}}
|
||||
adreno = apply({}, config, "1")
|
||||
self.assertEqual(adreno["VKD3D_FEATURE_LEVEL"], "12_2")
|
||||
pair = apply({"BL_OPEN_DRIVER": "1"}, config, "1")
|
||||
self.assertNotIn("VKD3D_FEATURE_LEVEL", pair)
|
||||
self.assertNotIn("VKD3D_SHADER_MODEL", pair)
|
||||
self.assertEqual(pair["DROIDDECK_VKD3D_CAPS"], "driver")
|
||||
own = apply({"BL_OPEN_DRIVER": "1"}, config, "42")
|
||||
self.assertEqual(own["VKD3D_SHADER_MODEL"], "6_6")
|
||||
self.assertNotIn("VKD3D_FEATURE_LEVEL", own)
|
||||
|
||||
def test_game_ids_and_probes(self):
|
||||
for prefix in ("", "/compatdata/0", "/compatdata/0-123", "/compatdata/nope", "/compatdata/4294967296"):
|
||||
self.assertIsNone(MODULE["game_id"]({"STEAM_COMPAT_DATA_PATH": prefix}))
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
SESSION = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-session"
|
||||
DESKTOP_GPU = Path(__file__).resolve().parents[1] / "linuxfs/desktop/droiddeck-gpu"
|
||||
|
||||
|
||||
class GamescopeBackendTest(unittest.TestCase):
|
||||
def select(self, backend=None):
|
||||
source = SESSION.read_text()
|
||||
start = source.index(' backend=${BL_GAMESCOPE_BACKEND:-wayland}')
|
||||
end = source.index('\n', source.index(' args=(--backend ', start))
|
||||
script = 'width=1280; height=720; nested=1280\n' + source[start:end]
|
||||
script += '\nprintf "%s\\n" "${args[0]}" "${args[1]}" "${SDL_VIDEODRIVER:-unset}"\n'
|
||||
env = dict(os.environ)
|
||||
env.pop("BL_GAMESCOPE_BACKEND", None)
|
||||
env.pop("SDL_VIDEODRIVER", None)
|
||||
if backend is not None:
|
||||
env["BL_GAMESCOPE_BACKEND"] = backend
|
||||
return subprocess.run(["bash", "-c", script], env=env, text=True,
|
||||
capture_output=True, timeout=5)
|
||||
|
||||
def test_default_retains_the_wayland_backend(self):
|
||||
result = self.select()
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
self.assertEqual(["--backend", "wayland", "unset"], result.stdout.splitlines())
|
||||
|
||||
def test_sdl_uses_the_host_wayland_vulkan_swapchain(self):
|
||||
result = self.select("sdl")
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
self.assertEqual(["--backend", "sdl", "wayland"], result.stdout.splitlines())
|
||||
|
||||
def test_unknown_backend_fails_before_gamescope(self):
|
||||
result = self.select("drm")
|
||||
self.assertEqual(64, result.returncode)
|
||||
self.assertIn("unsupported gamescope backend: drm", result.stdout)
|
||||
|
||||
|
||||
class DesktopGamescopeBackendTest(unittest.TestCase):
|
||||
def launch(self, backend=None):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
capture = root / "gamescope.json"
|
||||
gamescope = root / "gamescope"
|
||||
gamescope.write_text(
|
||||
f"#!{sys.executable}\n"
|
||||
"import json, os, sys\n"
|
||||
"from pathlib import Path\n"
|
||||
"Path(os.environ['GAMESCOPE_CAPTURE']).write_text(json.dumps({\n"
|
||||
" 'args': sys.argv[1:],\n"
|
||||
" 'sdl': os.environ.get('SDL_VIDEODRIVER'),\n"
|
||||
" 'gdk': os.environ.get('GDK_BACKEND'),\n"
|
||||
" 'qt': os.environ.get('QT_QPA_PLATFORM'),\n"
|
||||
" 'wayland': os.environ.get('WAYLAND_DISPLAY'),\n"
|
||||
"}))\n"
|
||||
)
|
||||
gamescope.chmod(0o755)
|
||||
env = dict(os.environ)
|
||||
for name in ("BL_GAMESCOPE_BACKEND", "BL_DEBUG_DIR", "BL_FPS", "BL_REFRESH", "BL_HDR"):
|
||||
env.pop(name, None)
|
||||
env.update(PATH=f"{root}{os.pathsep}{env.get('PATH', '')}",
|
||||
GAMESCOPE_CAPTURE=str(capture), WAYLAND_DISPLAY="desktop-0", BL_DESKTOP_GPU_WINDOW="0",
|
||||
SDL_VIDEODRIVER="dummy", GDK_BACKEND="wayland", QT_QPA_PLATFORM="wayland")
|
||||
if backend is not None:
|
||||
env["BL_GAMESCOPE_BACKEND"] = backend
|
||||
result = subprocess.run(["bash", str(DESKTOP_GPU), "demo", "one argument"],
|
||||
env=env, text=True, capture_output=True, timeout=5)
|
||||
return result, json.loads(capture.read_text()) if capture.exists() else None
|
||||
|
||||
def assert_xwayland_application(self, capture):
|
||||
args = capture["args"]
|
||||
self.assertEqual(["env", "SDL_VIDEODRIVER=x11", "/usr/local/bin/droiddeck-gpu-window",
|
||||
"demo", "one argument"], args[args.index("--") + 1:])
|
||||
self.assertEqual("x11", capture["gdk"])
|
||||
self.assertEqual("xcb", capture["qt"])
|
||||
self.assertEqual("wayland-0", capture["wayland"])
|
||||
|
||||
def test_default_keeps_wayland_and_xwayland_application(self):
|
||||
result, capture = self.launch()
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
self.assertEqual(["--backend", "wayland"], capture["args"][:2])
|
||||
self.assertEqual("x11", capture["sdl"])
|
||||
self.assert_xwayland_application(capture)
|
||||
|
||||
def test_sdl_uses_wayland_without_leaking_to_the_application(self):
|
||||
result, capture = self.launch("sdl")
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
self.assertEqual(["--backend", "sdl"], capture["args"][:2])
|
||||
self.assertEqual("wayland", capture["sdl"])
|
||||
self.assert_xwayland_application(capture)
|
||||
|
||||
def test_unknown_backend_fails_before_gamescope(self):
|
||||
result, capture = self.launch("drm")
|
||||
self.assertEqual(64, result.returncode)
|
||||
self.assertIn("unsupported gamescope backend: drm", result.stderr)
|
||||
self.assertIsNone(capture)
|
||||
@@ -0,0 +1,47 @@
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
SOURCE = Path(__file__).resolve().parents[1] / "linuxfs/preload/oomadj.c"
|
||||
|
||||
PROGRAM = r"""
|
||||
#include <stdio.h>
|
||||
const char *bl_oom_adj_redirect(const char *path, int writing);
|
||||
int main(int argc, char **argv) {
|
||||
for (int i = 1; i + 1 < argc; i += 2) printf("%s\n", bl_oom_adj_redirect(argv[i + 1], argv[i][0] == 'w'));
|
||||
return 0;
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
@unittest.skipUnless(shutil.which("cc"), "needs cc")
|
||||
class OomAdjPreloadTest(unittest.TestCase):
|
||||
def test_only_writes_to_oom_files_go_to_dev_null(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
main = Path(tmp) / "main.c"
|
||||
main.write_text(PROGRAM)
|
||||
binary = Path(tmp) / "probe"
|
||||
subprocess.run(["cc", "-o", str(binary), str(main), str(SOURCE)], check=True)
|
||||
cases = [
|
||||
("w", "/proc/self/oom_score_adj", "/dev/null"),
|
||||
("w", "/proc/123/oom_score_adj", "/dev/null"),
|
||||
("w", "/proc/thread-self/oom_score_adj", "/dev/null"),
|
||||
("w", "/proc/12/task/34/oom_score_adj", "/dev/null"),
|
||||
("w", "/proc/self/oom_adj", "/dev/null"),
|
||||
("r", "/proc/self/oom_score_adj", "/proc/self/oom_score_adj"),
|
||||
("w", "/proc/self/oom_score", "/proc/self/oom_score"),
|
||||
("w", "/proc/abc/oom_score_adj", "/proc/abc/oom_score_adj"),
|
||||
("w", "/tmp/oom_score_adj", "/tmp/oom_score_adj"),
|
||||
]
|
||||
args = [str(binary)]
|
||||
for mode, path, _ in cases:
|
||||
args += [mode, path]
|
||||
out = subprocess.run(args, capture_output=True, text=True, check=True)
|
||||
self.assertEqual(out.stdout.split(), [want for _, _, want in cases])
|
||||
self.assertIn("oom_score_adj raise was dropped", out.stderr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,215 @@
|
||||
"""Test freshness, narrow output, and lock handling without accessing a device."""
|
||||
from datetime import datetime, timezone
|
||||
import importlib.util
|
||||
import json
|
||||
import io
|
||||
import os
|
||||
from pathlib import Path
|
||||
import stat
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
spec = importlib.util.spec_from_file_location('reset_projection', Path(__file__).resolve().parents[1] / 'pixel_reset_diagnostics.py')
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
|
||||
|
||||
class ResetProjectionTest(unittest.TestCase):
|
||||
def test_only_primary_state(self):
|
||||
self.assertEqual(module.primary_state('Private space secret\nStarted users state: [0=RUNNING_UNLOCKED, 10=STOPPED]'), 'RUNNING_UNLOCKED')
|
||||
self.assertEqual(module.primary_state('State: RUNNING_UNLOCKED'), 'unknown')
|
||||
|
||||
def test_stale_body_not_used(self):
|
||||
raw = '2026-10-10 20:10:09 SYSTEM_LAST_KMSG (text, 1024 bytes)\nGNOC error type 0x2000'
|
||||
result = module.kernel_projection(raw, 'America/Toronto', datetime(2026, 10, 11, 21, tzinfo=timezone.utc))
|
||||
self.assertEqual(result['status'], 'stale_entry_not_attributed_to_current_trial')
|
||||
self.assertNotIn('categories', result)
|
||||
|
||||
def test_repeated_dst_hour_is_ambiguous_before_freshness(self):
|
||||
raw = '2026-11-01 01:30:00 SYSTEM_LAST_KMSG\nGNOC error type 0x2000'
|
||||
for after in (None, datetime(2026, 11, 1, 6, tzinfo=timezone.utc)):
|
||||
with self.subTest(after=after):
|
||||
result = module.kernel_projection(raw, 'America/Toronto', after)
|
||||
self.assertEqual(result['status'], 'ambiguous_device_local_time')
|
||||
self.assertNotIn('entry_date_utc', result)
|
||||
self.assertNotIn('categories', result)
|
||||
self.assertNotIn('hardware_fields', result)
|
||||
|
||||
def test_skipped_dst_hour_is_not_a_real_instant(self):
|
||||
raw = '2026-03-08 02:30:00 SYSTEM_LAST_KMSG\nGNOC error type 0x2000'
|
||||
result = module.kernel_projection(raw, 'America/Toronto')
|
||||
self.assertEqual(result['status'], 'nonexistent_device_local_time')
|
||||
self.assertNotIn('entry_date_utc', result)
|
||||
self.assertNotIn('categories', result)
|
||||
|
||||
def test_unambiguous_times_keep_correct_offsets_and_cutoff(self):
|
||||
for stamp, expected in (('2026-11-01 00:30:00', '2026-11-01T04:30:00+00:00'),
|
||||
('2026-11-01 02:30:00', '2026-11-01T07:30:00+00:00'),
|
||||
('2026-03-08 03:30:00', '2026-03-08T07:30:00+00:00')):
|
||||
with self.subTest(stamp=stamp):
|
||||
raw = stamp + ' SYSTEM_LAST_KMSG\nGNOC'
|
||||
result = module.kernel_projection(raw, 'America/Toronto')
|
||||
self.assertEqual(result['entry_date_utc'], expected)
|
||||
self.assertEqual(result['status'], 'projected_entry_not_a_root_cause')
|
||||
cutoff = datetime.fromisoformat(expected)
|
||||
self.assertEqual(module.kernel_projection(raw, 'America/Toronto', cutoff)['status'],
|
||||
'projected_entry_not_a_root_cause')
|
||||
|
||||
def test_latest_entry_and_no_arbitrary_body(self):
|
||||
raw = ('2026-10-10 20:10:09 SYSTEM_LAST_KMSG (text)\nGNOC error type 0x1111\n'
|
||||
'2026-10-11 17:35:01 SYSTEM_LAST_KMSG (text)\n'
|
||||
'PRIVATE_TEST_VALUE=a_secret_that_must_not_be_emitted\n'
|
||||
'Error from GNOC at addr 0x28220000\nGNOC error type 0x2000\n'
|
||||
'Reboot reason: 0xc005 - Secret arbitrary description\nLast boot reason: reset,warm,gnoc_error\n')
|
||||
result = module.kernel_projection(raw, 'America/Toronto', datetime(2026, 10, 11, 21, tzinfo=timezone.utc))
|
||||
self.assertEqual(result['entry_date_utc'], '2026-10-11T21:35:01+00:00')
|
||||
self.assertEqual(result['hardware_fields']['gnoc_error_types'], ['0x2000'])
|
||||
self.assertNotIn('0x1111', json.dumps(result))
|
||||
self.assertNotIn('a_secret', json.dumps(result))
|
||||
self.assertNotIn('arbitrary description', json.dumps(result))
|
||||
self.assertFalse(result['root_cause_proven'])
|
||||
|
||||
def test_missing_entry_and_timezone(self):
|
||||
self.assertEqual(module.kernel_projection('Permission denied', 'America/Toronto')['status'], 'no_accessible_entry')
|
||||
self.assertEqual(module.kernel_projection('2026-10-11 17:00:00 SYSTEM_LAST_KMSG\nGNOC', 'Unknown/Region')['status'], 'unknown_device_timezone')
|
||||
|
||||
def test_reason_rejects_paths_and_urls(self):
|
||||
self.assertEqual(module.safe_reason('reset,warm,gnoc_error\n'), 'reset,warm,gnoc_error')
|
||||
self.assertEqual(module.safe_reason('https://private.invalid/login?secret=abc'), 'unknown')
|
||||
self.assertEqual(module.safe_reason('/data/private'), 'unknown')
|
||||
|
||||
def test_reason_only_recognized_exact_values(self):
|
||||
for reason in ('cold', 'hard', 'warm', 'reboot', 'shutdown', 'recovery',
|
||||
'bootloader', 'kernel_panic', 'watchdog', 'reset,warm,gnoc_error'):
|
||||
with self.subTest(reason=reason):
|
||||
self.assertEqual(module.safe_reason(reason + '\n'), reason)
|
||||
for reason in ('PRIVATE TEST VALUE', 'private_test_value', '123456',
|
||||
'reboot,private_test_value', 'reset,warm,gnoc_error,private_test_value',
|
||||
'reset,warm,gnoc_error trailing_private_test_value', ''):
|
||||
with self.subTest(reason=reason):
|
||||
self.assertEqual(module.safe_reason(reason), 'unknown')
|
||||
|
||||
def test_kernel_reason_uses_same_fixed_projection(self):
|
||||
raw = ('2026-10-11 17:35:01 SYSTEM_LAST_KMSG (text)\n'
|
||||
'Last boot reason: private_test_value\n'
|
||||
'Last boot reason: reset,warm,gnoc_error trailing_private_test_value\n'
|
||||
'Last boot reason: reset,warm,gnoc_error\n'
|
||||
'Last boot reason:\nPRIVATE TEST VALUE\n')
|
||||
result = module.kernel_projection(raw, 'America/Toronto')
|
||||
self.assertEqual(result['last_boot_reasons'], ['reset,warm,gnoc_error', 'unknown'])
|
||||
self.assertNotIn('private_test_value', json.dumps(result))
|
||||
self.assertNotIn('PRIVATE TEST VALUE', json.dumps(result))
|
||||
|
||||
def test_primary_state_uses_fixed_categories(self):
|
||||
for state in ('RUNNING_LOCKED', 'RUNNING_UNLOCKING', 'RUNNING_UNLOCKED'):
|
||||
self.assertEqual(module.primary_state('Started users state: [0=' + state + ']'), state)
|
||||
for state in ('RUNNING_PRIVATE_TEST_VALUE', 'RUNNING_UNLOCKED_PRIVATE',
|
||||
'RUNNING_UNLOCKED=private_test_value'):
|
||||
self.assertEqual(module.primary_state('Started users state: [0=' + state + ']'), 'unknown')
|
||||
|
||||
def test_property_reason_never_exports_custom_text(self):
|
||||
def run(argv, **kwargs):
|
||||
if argv[-2:] == ['getprop', 'ro.boot.bootreason']:
|
||||
text = 'PRIVATE TEST VALUE'
|
||||
elif argv[-2:] == ['getprop', 'sys.boot.reason']:
|
||||
text = 'reset,warm,gnoc_error,private_test_value'
|
||||
elif argv[-1] == 'persist.sys.timezone':
|
||||
text = 'America/Toronto'
|
||||
else:
|
||||
text = ''
|
||||
return subprocess.CompletedProcess(argv, 0, text, '')
|
||||
with patch.object(module.subprocess, 'run', side_effect=run):
|
||||
result = module.collect('adb', 'test-device')
|
||||
self.assertEqual(result['bootloader_reason'], 'unknown')
|
||||
self.assertEqual(result['system_boot_reason'], 'unknown')
|
||||
self.assertNotIn('PRIVATE TEST VALUE', json.dumps(result))
|
||||
self.assertNotIn('private_test_value', json.dumps(result))
|
||||
|
||||
@unittest.skipUnless(os.name == 'posix', 'POSIX private file modes')
|
||||
def test_cli_output_is_private_before_writing(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
output = Path(directory) / 'diagnostics.json'
|
||||
saved_umask = os.umask(0)
|
||||
original_fdopen = os.fdopen
|
||||
original_path_open = Path.open
|
||||
creation_modes = []
|
||||
def inspect_stream(stream):
|
||||
try:
|
||||
creation_modes.append(stat.S_IMODE(os.fstat(stream.fileno()).st_mode))
|
||||
self.assertEqual(os.fstat(stream.fileno()).st_size, 0)
|
||||
self.assertEqual(creation_modes[-1], 0o600)
|
||||
except BaseException:
|
||||
stream.close()
|
||||
raise
|
||||
return stream
|
||||
def inspect_fd(fd, *args, **kwargs):
|
||||
return inspect_stream(original_fdopen(fd, *args, **kwargs))
|
||||
def inspect_path(path, *args, **kwargs):
|
||||
stream = original_path_open(path, *args, **kwargs)
|
||||
return inspect_stream(stream) if path == output else stream
|
||||
try:
|
||||
with patch.object(sys, 'argv', ['diagnostics', '--serial', 'test-device',
|
||||
'--output', str(output)]), \
|
||||
patch.object(module, 'collect', return_value={'boot_count': 12}), \
|
||||
patch.object(os, 'fdopen', side_effect=inspect_fd), \
|
||||
patch.object(Path, 'open', new=inspect_path), \
|
||||
patch('sys.stdout', new_callable=io.StringIO):
|
||||
module.main()
|
||||
finally:
|
||||
os.umask(saved_umask)
|
||||
self.assertEqual(creation_modes, [0o600])
|
||||
self.assertEqual(stat.S_IMODE(output.stat().st_mode), 0o600)
|
||||
self.assertEqual(json.loads(output.read_text()), {'boot_count': 12})
|
||||
|
||||
def test_output_refuses_existing_file(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
output = Path(directory) / 'diagnostics.json'
|
||||
output.write_text('existing controlled test data')
|
||||
with self.assertRaises(FileExistsError):
|
||||
module.write_private_output(output, '{"replacement":true}\n')
|
||||
self.assertEqual(output.read_text(), 'existing controlled test data')
|
||||
|
||||
@unittest.skipUnless(os.name == 'posix', 'POSIX symlink behavior')
|
||||
def test_output_refuses_symlink_without_touching_target(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
target = Path(directory) / 'target.json'
|
||||
target.write_text('existing controlled test data')
|
||||
output = Path(directory) / 'diagnostics.json'
|
||||
output.symlink_to(target)
|
||||
with self.assertRaises(FileExistsError):
|
||||
module.write_private_output(output, '{"replacement":true}\n')
|
||||
self.assertTrue(output.is_symlink())
|
||||
self.assertEqual(target.read_text(), 'existing controlled test data')
|
||||
|
||||
def test_locked_skips_kernel_body(self):
|
||||
commands = []
|
||||
def run(argv, **kwargs):
|
||||
commands.append(argv)
|
||||
if argv[-2:] == ['dumpsys', 'user']:
|
||||
text = 'Started users state: [0=RUNNING_LOCKED]'
|
||||
elif argv[-1] == 'persist.sys.timezone':
|
||||
text = 'America/Toronto'
|
||||
elif argv[-3:] == ['get', 'global', 'boot_count']:
|
||||
text = '12'
|
||||
else:
|
||||
text = ''
|
||||
return subprocess.CompletedProcess(argv, 0, text, 'PRIVATE_STDERR')
|
||||
with patch.object(module.subprocess, 'run', side_effect=run):
|
||||
result = module.collect('adb', 'test-device', True)
|
||||
self.assertEqual(result['kernel']['status'], 'requires_user_unlock')
|
||||
self.assertFalse(any('--print' in command for command in commands))
|
||||
self.assertNotIn('PRIVATE_STDERR', json.dumps(result))
|
||||
|
||||
def test_command_failure_does_not_export_stderr(self):
|
||||
with patch.object(module.subprocess, 'run', return_value=subprocess.CompletedProcess([], 1, 'UNRELATED_DATA', 'PRIVATE_STDERR')):
|
||||
result = module.collect('adb', 'test-device', True)
|
||||
self.assertIsNone(result['boot_count'])
|
||||
self.assertNotIn('UNRELATED_DATA', json.dumps(result))
|
||||
self.assertNotIn('PRIVATE_STDERR', json.dumps(result))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,291 @@
|
||||
import importlib.util
|
||||
import io
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tarfile
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
from zipfile import ZipFile, ZipInfo
|
||||
|
||||
|
||||
spec = importlib.util.spec_from_file_location('powervr_fetch',
|
||||
Path(__file__).resolve().parents[1] / 'powervr/fetch.py')
|
||||
runtime = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(runtime)
|
||||
|
||||
|
||||
def elf():
|
||||
content = bytearray(64)
|
||||
content[:6], content[18:20] = b'\x7fELF\x02\x01', b'\xb7\x00'
|
||||
return bytes(content)
|
||||
|
||||
|
||||
def pe(architecture):
|
||||
content = bytearray(128)
|
||||
content[:2], content[60:64], content[64:68] = b'MZ', (64).to_bytes(4, 'little'), b'PE\0\0'
|
||||
content[68:70] = b'\x4c\x01' if architecture == 'x32' else b'\x64\x86'
|
||||
content[88:90] = b'\x0b\x01' if architecture == 'x32' else b'\x0b\x02'
|
||||
return bytes(content)
|
||||
|
||||
|
||||
def tar(entries):
|
||||
stream = io.BytesIO()
|
||||
with tarfile.open(fileobj=stream, mode='w') as archive:
|
||||
for name, kind, content in entries:
|
||||
info = tarfile.TarInfo(name)
|
||||
info.type = kind
|
||||
if kind in (tarfile.SYMTYPE, tarfile.LNKTYPE):
|
||||
info.linkname = content
|
||||
archive.addfile(info)
|
||||
elif kind == tarfile.REGTYPE:
|
||||
info.size = len(content)
|
||||
archive.addfile(info, io.BytesIO(content))
|
||||
else:
|
||||
archive.addfile(info)
|
||||
return subprocess.run(['zstd', '-q', '-c'], input=stream.getvalue(),
|
||||
capture_output=True, check=True).stdout
|
||||
|
||||
|
||||
def tar_gz(entries):
|
||||
stream = io.BytesIO()
|
||||
with tarfile.open(fileobj=stream, mode='w:gz') as archive:
|
||||
for name, kind, content in entries:
|
||||
info = tarfile.TarInfo(name)
|
||||
info.type = kind
|
||||
if kind == tarfile.SYMTYPE:
|
||||
info.linkname = content
|
||||
archive.addfile(info)
|
||||
elif kind == tarfile.REGTYPE:
|
||||
info.size = len(content)
|
||||
archive.addfile(info, io.BytesIO(content))
|
||||
else:
|
||||
archive.addfile(info)
|
||||
return stream.getvalue()
|
||||
|
||||
|
||||
def upstream_dxvk(version, architecture_of=lambda arch: arch):
|
||||
return {'dxvk-%s/%s/%s' % (version, arch, name): pe(architecture_of(arch))
|
||||
for arch in ('x32', 'x64')
|
||||
for name in ('d3d8.dll', 'd3d9.dll', 'd3d10core.dll', 'd3d11.dll', 'dxgi.dll')}
|
||||
|
||||
|
||||
class PowerVRRuntimeTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.temporary = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self.temporary.cleanup)
|
||||
self.root = Path(self.temporary.name)
|
||||
self.cache = self.root / 'cache'
|
||||
self.cache.mkdir()
|
||||
for name, content in {
|
||||
'tools/powervr/fetch.py': b'fixture assembler',
|
||||
'tools/hybris/run-proton.py': b'print("fixture Proton wrapper")\n',
|
||||
'tools/hybris/source.env': b'HYBRIS_REVISION=fixture\n',
|
||||
'tools/vulkan-wsi/licenses/Vulkan-Headers/LICENSE.md': b'Khronos headers attribution\n',
|
||||
'tools/vulkan-wsi/licenses/Vulkan-Headers/MIT.txt': b'MIT license fixture\n',
|
||||
}.items():
|
||||
path = self.root / name
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_bytes(content)
|
||||
bridge = {name: ('file', 0o755, elf()) for name in runtime.REQUIRED_LIBRARIES if name.startswith('lib/')}
|
||||
bridge['lib/libhybris-common.so.1.0.0'] = bridge.pop('lib/libhybris-common.so.1')
|
||||
bridge['lib/libhybris-common.so.1'] = ('symlink', 0o777, 'libhybris-common.so.1.0.0')
|
||||
data = runtime.pack(bridge)
|
||||
self.release = {'format': 1, 'hybris': self.component('bridge.tzst', data), 'archives': []}
|
||||
self.release['hybris'].update({
|
||||
'tree_sha256': runtime.tree_digest(bridge),
|
||||
'recipe_inputs': {'tools/hybris/source.env': runtime.sha256((self.root / 'tools/hybris/source.env').read_bytes())}})
|
||||
files = {'dxvk/' + arch + '/' + name: pe(arch)
|
||||
for arch in ('x32', 'x64')
|
||||
for name in ('d3d8.dll', 'd3d9.dll', 'd3d10core.dll', 'd3d11.dll', 'dxgi.dll')}
|
||||
files['wsi/libVkLayer_window_system_integration.so'] = elf()
|
||||
stream = io.BytesIO()
|
||||
with ZipFile(stream, 'w') as archive:
|
||||
for name, content in files.items():
|
||||
archive.writestr(name, content)
|
||||
component = self.component('graphics.zip', stream.getvalue())
|
||||
component.update({'ignored': [], 'files': [
|
||||
{'name': name, 'path': name, 'size': len(content), 'sha256': runtime.sha256(content), 'mode': 0o644}
|
||||
for name, content in files.items()]})
|
||||
self.release['archives'].append(component)
|
||||
self.pins = self.root / 'tools/powervr/release.json'
|
||||
self.pins.write_bytes(runtime.json_bytes(self.release))
|
||||
|
||||
def component(self, name, data):
|
||||
component = {'url': 'https://example.invalid/' + name, 'size': len(data),
|
||||
'sha256': runtime.sha256(data), 'recipe_inputs': {}}
|
||||
(self.cache / (component['sha256'] + '-' + name)).write_bytes(data)
|
||||
return component
|
||||
|
||||
def add_upstream_dxvk(self, files):
|
||||
top = next(iter(files)).split('/')[0]
|
||||
data = tar_gz([(top, tarfile.DIRTYPE, None)] +
|
||||
[(name, tarfile.REGTYPE, content) for name, content in files.items()])
|
||||
component = self.component('dxvk-upstream.tar.gz', data)
|
||||
component.update({'format': 'tar.gz', 'ignored': [], 'files': [
|
||||
{'name': name, 'path': name, 'size': len(content), 'sha256': runtime.sha256(content), 'mode': 0o755}
|
||||
for name, content in files.items()]})
|
||||
self.release['archives'].append(component)
|
||||
self.pins.write_bytes(runtime.json_bytes(self.release))
|
||||
return component
|
||||
|
||||
def assembled(self):
|
||||
runtime.assemble(self.root, self.cache)
|
||||
return runtime.read_tar((self.root / runtime.ASSETS / 'runtime.tzst').read_bytes())
|
||||
|
||||
def test_complete_payload_preserves_symlinks_and_is_reproducible(self):
|
||||
self.assembled()
|
||||
first = (self.root / runtime.ASSETS / 'runtime.tzst').read_bytes()
|
||||
runtime.verify(self.root)
|
||||
self.assembled()
|
||||
self.assertEqual(first, (self.root / runtime.ASSETS / 'runtime.tzst').read_bytes())
|
||||
self.assertEqual(runtime.read_tar(first)['lib/libhybris-common.so.1'][0], 'symlink')
|
||||
|
||||
def test_upstream_tarball_adds_a_second_dxvk_payload(self):
|
||||
files = upstream_dxvk('2.6.2')
|
||||
self.add_upstream_dxvk(files)
|
||||
entries = self.assembled()
|
||||
runtime.verify(self.root)
|
||||
for name, content in files.items():
|
||||
self.assertEqual(entries[name], ('file', 0o755, content))
|
||||
self.assertIn('dxvk/x64/d3d9.dll', entries)
|
||||
|
||||
def test_second_dxvk_payload_with_wrong_pe_architecture_is_rejected(self):
|
||||
self.add_upstream_dxvk(upstream_dxvk('2.6.2', lambda arch: 'x64' if arch == 'x32' else 'x32'))
|
||||
with self.assertRaisesRegex(ValueError, 'wrong PE architecture: dxvk-2.6.2/'):
|
||||
self.assembled()
|
||||
|
||||
def test_tar_gz_rejects_symlinks_unknown_members_and_changed_files(self):
|
||||
pin = {'name': 'dxvk-1/x64/d3d9.dll', 'path': 'dxvk-1/x64/d3d9.dll', 'size': 4,
|
||||
'sha256': runtime.sha256(b'good'), 'mode': 0o755}
|
||||
component = {'files': [pin], 'ignored': []}
|
||||
cases = [
|
||||
[('dxvk-1/x64/d3d9.dll', tarfile.SYMTYPE, '../../outside')],
|
||||
[('dxvk-1/x64/d3d9.dll', tarfile.REGTYPE, b'good'), ('dxvk-1/extra.dll', tarfile.REGTYPE, b'x')],
|
||||
[('dxvk-1/x64/d3d9.dll', tarfile.REGTYPE, b'evil')],
|
||||
[],
|
||||
]
|
||||
for entries in cases:
|
||||
with self.subTest(entries=[name for name, _, _ in entries]), self.assertRaises(ValueError):
|
||||
runtime.read_tar_gz(tar_gz(entries), component)
|
||||
self.assertEqual(runtime.read_tar_gz(tar_gz([('dxvk-1/x64/d3d9.dll', tarfile.REGTYPE, b'good')]), component),
|
||||
{'dxvk-1/x64/d3d9.dll': ('file', 0o755, b'good')})
|
||||
with self.assertRaisesRegex(ValueError, 'unsupported component archive format'):
|
||||
runtime.read_component(b'', {'format': 'rar'})
|
||||
|
||||
def test_stale_wrapper_cannot_pass_with_an_updated_archive_checksum(self):
|
||||
self.assembled()
|
||||
(self.root / 'tools/hybris/run-proton.py').write_text('print("new wrapper")\n')
|
||||
with self.assertRaisesRegex(ValueError, 'assembly inputs changed'):
|
||||
runtime.verify(self.root)
|
||||
|
||||
def test_header_licenses_are_bundled_verbatim(self):
|
||||
entries = self.assembled()
|
||||
for source, target in runtime.BUNDLED_LICENSES.items():
|
||||
self.assertEqual(runtime.read(entries, target), (self.root / source).read_bytes())
|
||||
|
||||
def test_missing_or_modified_header_license_is_rejected(self):
|
||||
original = self.assembled()
|
||||
target = 'licenses/Vulkan-Headers/MIT.txt'
|
||||
for replacement in (None, ('file', 0o644, b'stale license')):
|
||||
with self.subTest(replacement=replacement):
|
||||
entries = dict(original)
|
||||
if replacement is None:
|
||||
del entries[target]
|
||||
else:
|
||||
entries[target] = replacement
|
||||
with self.assertRaisesRegex(ValueError, 'license missing or stale'):
|
||||
runtime.check_bundle(entries, self.release, self.root)
|
||||
|
||||
def test_changed_tracked_header_license_rejects_old_bundle(self):
|
||||
self.assembled()
|
||||
source = next(iter(runtime.BUNDLED_LICENSES))
|
||||
(self.root / source).write_bytes(b'changed license text')
|
||||
with self.assertRaisesRegex(ValueError, 'assembly inputs changed'):
|
||||
runtime.verify(self.root)
|
||||
|
||||
def test_changed_component_recipe_requires_new_release_pin(self):
|
||||
self.assembled()
|
||||
(self.root / 'tools/hybris/source.env').write_text('HYBRIS_REVISION=new-source\n')
|
||||
with self.assertRaisesRegex(ValueError, 'recipe changed'):
|
||||
runtime.verify(self.root)
|
||||
|
||||
def test_old_dxvk_cannot_pass_by_updating_only_the_bundle_checksum(self):
|
||||
entries = self.assembled()
|
||||
entries['dxvk/x64/d3d11.dll'] = ('file', 0o644, pe('x64') + b'old DLL')
|
||||
archive = runtime.pack(entries)
|
||||
with self.assertRaisesRegex(ValueError, 'component mismatch'):
|
||||
runtime.verify_archive(archive, runtime.sha256(archive), self.root)
|
||||
|
||||
def test_wrong_pe_architecture_rejected_even_with_matching_member_pin(self):
|
||||
entries = self.assembled()
|
||||
name = 'dxvk/x32/d3d11.dll'
|
||||
entries[name] = ('file', 0o644, pe('x64'))
|
||||
pin = next(item for item in self.release['archives'][0]['files'] if item['path'] == name)
|
||||
pin['sha256'] = runtime.sha256(pe('x64'))
|
||||
with self.assertRaisesRegex(ValueError, 'wrong PE architecture'):
|
||||
runtime.check_bundle(entries, self.release, self.root)
|
||||
|
||||
def test_unpinned_bridge_file_is_rejected(self):
|
||||
entries = self.assembled()
|
||||
entries['lib/extra-loader.so'] = ('file', 0o755, elf())
|
||||
with self.assertRaisesRegex(ValueError, 'bridge differs'):
|
||||
runtime.check_bundle(entries, self.release, self.root)
|
||||
|
||||
def test_failed_download_leaves_the_previous_payload_ready(self):
|
||||
self.assembled()
|
||||
before = (self.root / runtime.ASSETS / 'version.txt').read_bytes()
|
||||
component = self.release['archives'][0]
|
||||
(self.cache / (component['sha256'] + '-graphics.zip')).write_bytes(b'bad cache')
|
||||
with patch.object(runtime, 'urlopen', return_value=io.BytesIO(b'corrupt response')):
|
||||
with self.assertRaisesRegex(ValueError, 'checksum mismatch'):
|
||||
runtime.assemble(self.root, self.cache)
|
||||
self.assertEqual(before, (self.root / runtime.ASSETS / 'version.txt').read_bytes())
|
||||
runtime.verify(self.root)
|
||||
|
||||
def test_tar_rejects_traversal_duplicate_special_files_and_symlink_escape(self):
|
||||
cases = [
|
||||
[('../escape', tarfile.REGTYPE, b'x')],
|
||||
[('file', tarfile.REGTYPE, b'x'), ('./file', tarfile.REGTYPE, b'y')],
|
||||
[('device', tarfile.CHRTYPE, b'')],
|
||||
[('file', tarfile.LNKTYPE, 'other')],
|
||||
[('lib/link', tarfile.SYMTYPE, '../../outside')],
|
||||
[('lib/link', tarfile.SYMTYPE, '/absolute')],
|
||||
[('lib/a', tarfile.SYMTYPE, 'b'), ('lib/b', tarfile.SYMTYPE, 'a')],
|
||||
[('lib', tarfile.SYMTYPE, 'target'), ('target', tarfile.REGTYPE, b'x'),
|
||||
('lib/child', tarfile.REGTYPE, b'x')],
|
||||
]
|
||||
for members in cases:
|
||||
with self.subTest(members=members):
|
||||
with self.assertRaises(ValueError):
|
||||
runtime.read_tar(tar(members))
|
||||
|
||||
def test_relative_symlink_that_stays_inside_runtime_is_preserved(self):
|
||||
entries = runtime.read_tar(tar([
|
||||
('lib/a', tarfile.REGTYPE, b'library'), ('lib/child/link', tarfile.SYMTYPE, '../a')]))
|
||||
self.assertEqual(runtime.read(entries, 'lib/child/link'), b'library')
|
||||
|
||||
def test_zip_rejects_symlink_even_if_name_is_allowed(self):
|
||||
stream = io.BytesIO()
|
||||
with ZipFile(stream, 'w') as archive:
|
||||
info = ZipInfo('allowed')
|
||||
info.create_system = 3
|
||||
info.external_attr = 0o120777 << 16
|
||||
archive.writestr(info, '../outside')
|
||||
with self.assertRaisesRegex(ValueError, 'unexpected component archive entry'):
|
||||
runtime.read_zip(stream.getvalue(), {'files': [], 'ignored': ['allowed']})
|
||||
|
||||
def test_zip_rejects_unknown_and_duplicate_members(self):
|
||||
for names in (['unexpected'], ['allowed', 'allowed'], ['../escape']):
|
||||
with self.subTest(names=names):
|
||||
stream = io.BytesIO()
|
||||
with ZipFile(stream, 'w') as archive:
|
||||
for name in names:
|
||||
archive.writestr(name, b'file')
|
||||
with self.assertRaises(ValueError):
|
||||
runtime.read_zip(stream.getvalue(), {'files': [], 'ignored': ['allowed']})
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,228 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
TOOLS = Path(__file__).resolve().parents[1]
|
||||
WRAPPER_SOURCE = TOOLS / "hybris/run-proton.py"
|
||||
DLL_NAMES = ("d3d8.dll", "d3d9.dll", "d3d10core.dll", "d3d11.dll", "dxgi.dll")
|
||||
DXVK_X64_ANCHOR = 'g_proton.arch_pe_dir("wine/dxvk", False) + f + ".dll"'
|
||||
DXVK_X32_ANCHOR = 'g_proton.arch_pe_dir("wine/dxvk", True) + f + ".dll"'
|
||||
PREFIX_ANCHOR = " # check whether any prefix config has changed"
|
||||
|
||||
|
||||
PROTON_SOURCE = '''import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
from neighbor import NEIGHBOR
|
||||
|
||||
|
||||
class Proton:
|
||||
def arch_pe_dir(self, directory, is32):
|
||||
return str(Path(__file__).parent / "stock" / ("x32" if is32 else "x64")) + "/"
|
||||
|
||||
|
||||
g_proton = Proton()
|
||||
|
||||
|
||||
def prefix_marker():
|
||||
if True:
|
||||
prefix_info = "stock"
|
||||
# check whether any prefix config has changed
|
||||
return prefix_info
|
||||
|
||||
|
||||
def payloads():
|
||||
result = {"x64": {}, "x32": {}}
|
||||
for f in ("d3d8", "d3d9", "d3d10core", "d3d11", "dxgi"):
|
||||
x64 = g_proton.arch_pe_dir("wine/dxvk", False) + f + ".dll"
|
||||
x32 = g_proton.arch_pe_dir("wine/dxvk", True) + f + ".dll"
|
||||
result["x64"][f + ".dll"] = Path(x64).read_text()
|
||||
result["x32"][f + ".dll"] = Path(x32).read_text()
|
||||
return result
|
||||
|
||||
|
||||
def main():
|
||||
record = {
|
||||
"argv0": sys.argv[0],
|
||||
"argv": sys.argv[1:],
|
||||
"file": __file__,
|
||||
"neighbor": NEIGHBOR,
|
||||
"prefix": prefix_marker(),
|
||||
"payloads": payloads(),
|
||||
"openvr": g_proton.arch_pe_dir("wine/dxvk", False) + "openvr_api_dxvk.dll",
|
||||
}
|
||||
Path(os.environ["PROBE"]).write_text(json.dumps(record))
|
||||
raise SystemExit(int(os.environ.get("PROTON_EXIT", "0")))
|
||||
|
||||
|
||||
main()
|
||||
'''
|
||||
|
||||
|
||||
class ProtonWrapperTest(unittest.TestCase):
|
||||
def fixture(self, root):
|
||||
wrapper_dir = root / 'DXVK profile "quotes" $dollar `backticks`'
|
||||
wrapper_dir.mkdir(parents=True)
|
||||
wrapper = wrapper_dir / "run-proton.py"
|
||||
shutil.copy2(WRAPPER_SOURCE, wrapper)
|
||||
|
||||
dxvk = wrapper_dir / "dxvk"
|
||||
for architecture in ("x32", "x64"):
|
||||
payload = dxvk / architecture
|
||||
payload.mkdir(parents=True)
|
||||
for name in DLL_NAMES:
|
||||
(payload / name).write_text(f"{architecture}:{name}")
|
||||
|
||||
depot = root / "Proton depot with spaces"
|
||||
depot.mkdir()
|
||||
proton = depot / "selected proton.py"
|
||||
proton.write_text(PROTON_SOURCE)
|
||||
(depot / "neighbor.py").write_text('NEIGHBOR = "imported from selected depot"\n')
|
||||
return {"wrapper": wrapper, "dxvk": dxvk, "depot": depot, "proton": proton,
|
||||
"probe": root / "proton-ran.json"}
|
||||
|
||||
def run_wrapper(self, fixture, *proton_args, check=False, exit_status=0, env=None):
|
||||
command = [sys.executable, str(fixture["wrapper"])]
|
||||
if check:
|
||||
command.append("--check")
|
||||
command.extend((str(fixture["proton"]), *proton_args))
|
||||
return subprocess.run(
|
||||
command,
|
||||
cwd=fixture["wrapper"].parent,
|
||||
env={"PATH": os.defpath, "PROBE": str(fixture["probe"]),
|
||||
"PROTON_EXIT": str(exit_status), **(env or {})},
|
||||
text=True,
|
||||
capture_output=True,
|
||||
)
|
||||
|
||||
def test_launch_uses_both_staged_payloads_and_selected_proton_context(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
fixture = self.fixture(Path(tmp))
|
||||
original_source = fixture["proton"].read_bytes()
|
||||
arguments = ("waitforexitandrun", "game with spaces.exe", 'quoted "value"',
|
||||
"$literal-dollar", "`literal-backticks`")
|
||||
result = self.run_wrapper(fixture, *arguments)
|
||||
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(fixture["proton"].read_bytes(), original_source)
|
||||
record = json.loads(fixture["probe"].read_text())
|
||||
self.assertEqual(record["argv0"], str(fixture["proton"]))
|
||||
self.assertEqual(record["argv"], list(arguments))
|
||||
self.assertEqual(record["file"], str(fixture["proton"]))
|
||||
self.assertEqual(record["neighbor"], "imported from selected depot")
|
||||
self.assertEqual(record["prefix"], "stock\ndroiddeck-dxvk-profile-v1")
|
||||
self.assertEqual(record["openvr"], str(fixture["depot"] / "stock/x64/openvr_api_dxvk.dll"))
|
||||
for architecture in ("x32", "x64"):
|
||||
self.assertEqual(
|
||||
record["payloads"][architecture],
|
||||
{name: f"{architecture}:{name}" for name in DLL_NAMES},
|
||||
)
|
||||
|
||||
def test_named_sibling_payload_replaces_the_default(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
fixture = self.fixture(Path(tmp))
|
||||
for architecture in ("x32", "x64"):
|
||||
payload = fixture["wrapper"].parent / "dxvk-2.6.2" / architecture
|
||||
payload.mkdir(parents=True)
|
||||
for name in DLL_NAMES:
|
||||
(payload / name).write_text(f"2.6.2 {architecture}:{name}")
|
||||
result = self.run_wrapper(fixture, "waitforexitandrun", "game.exe",
|
||||
env={"DROIDDECK_HYBRIS_DXVK": "dxvk-2.6.2"})
|
||||
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
record = json.loads(fixture["probe"].read_text())
|
||||
for architecture in ("x32", "x64"):
|
||||
self.assertEqual(
|
||||
record["payloads"][architecture],
|
||||
{name: f"2.6.2 {architecture}:{name}" for name in DLL_NAMES},
|
||||
)
|
||||
|
||||
def test_payload_names_outside_the_wrapper_directory_are_refused(self):
|
||||
for name in ("../dxvk", "dxvk/../../x", "/tmp/dxvk", "other", ".dxvk"):
|
||||
with self.subTest(name=name), tempfile.TemporaryDirectory() as tmp:
|
||||
fixture = self.fixture(Path(tmp))
|
||||
result = self.run_wrapper(fixture, "waitforexitandrun", "game.exe",
|
||||
env={"DROIDDECK_HYBRIS_DXVK": name})
|
||||
|
||||
self.assertEqual(result.returncode, 1)
|
||||
self.assertIn("invalid payload name", result.stderr)
|
||||
self.assertFalse(fixture["probe"].exists())
|
||||
|
||||
def test_check_validates_without_executing_proton(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
fixture = self.fixture(Path(tmp))
|
||||
result = self.run_wrapper(fixture, check=True)
|
||||
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertIn("payload present and Proton layout supported", result.stdout)
|
||||
self.assertFalse(fixture["probe"].exists())
|
||||
|
||||
def test_check_rejects_malformed_source_before_its_top_level_code_runs(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
fixture = self.fixture(Path(tmp))
|
||||
source = fixture["proton"].read_text()
|
||||
source = source.replace(
|
||||
"import sys\n", 'import sys\n\nPath(os.environ["PROBE"]).write_text("top-level")\n', 1)
|
||||
fixture["proton"].write_text(source + "\nthis is not valid =\n")
|
||||
result = self.run_wrapper(fixture, check=True)
|
||||
|
||||
self.assertEqual(result.returncode, 1, result.stderr)
|
||||
self.assertIn("DroidDeck DXVK profile:", result.stderr)
|
||||
self.assertFalse(fixture["probe"].exists())
|
||||
|
||||
def test_preflight_rejects_each_missing_or_empty_payload_before_proton_runs(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
for state in ("missing", "empty"):
|
||||
for architecture in ("x32", "x64"):
|
||||
for name in DLL_NAMES:
|
||||
with self.subTest(state=state, architecture=architecture, name=name):
|
||||
fixture = self.fixture(root / f"{state}-{architecture}-{name}")
|
||||
payload = fixture["dxvk"] / architecture / name
|
||||
if state == "missing":
|
||||
payload.unlink()
|
||||
else:
|
||||
payload.write_bytes(b"")
|
||||
result = self.run_wrapper(fixture, "waitforexitandrun", "game.exe")
|
||||
self.assertEqual(result.returncode, 1, result.stderr)
|
||||
self.assertIn(f"{state} DXVK file", result.stderr)
|
||||
self.assertFalse(fixture["probe"].exists())
|
||||
|
||||
def test_preflight_rejects_changed_proton_layout_or_syntax_before_proton_runs(self):
|
||||
mutations = []
|
||||
for label, anchor in (("x64", DXVK_X64_ANCHOR), ("x32", DXVK_X32_ANCHOR),
|
||||
("prefix", PREFIX_ANCHOR)):
|
||||
mutations.extend(((f"missing-{label}", lambda text, anchor=anchor: text.replace(anchor, "missing_anchor", 1)),
|
||||
(f"duplicate-{label}", lambda text, anchor=anchor: text + "\n# " + anchor + "\n")))
|
||||
mutations.append(("syntax-error", lambda text: text + "\nthis is not valid =\n"))
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
for label, mutate in mutations:
|
||||
with self.subTest(layout=label):
|
||||
fixture = self.fixture(root / label)
|
||||
fixture["proton"].write_text(mutate(fixture["proton"].read_text()))
|
||||
result = self.run_wrapper(fixture, "waitforexitandrun", "game.exe")
|
||||
self.assertEqual(result.returncode, 1, result.stderr)
|
||||
self.assertIn("DroidDeck DXVK profile:", result.stderr)
|
||||
self.assertFalse(fixture["probe"].exists())
|
||||
|
||||
def test_proton_exit_status_is_propagated(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
fixture = self.fixture(Path(tmp))
|
||||
result = self.run_wrapper(fixture, "waitforexitandrun", "game.exe", exit_status=23)
|
||||
|
||||
self.assertEqual(result.returncode, 23, result.stderr)
|
||||
self.assertTrue(fixture["probe"].exists())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -6,6 +6,7 @@ import subprocess
|
||||
import tarfile
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
from unittest import mock
|
||||
from zipfile import ZipFile
|
||||
|
||||
@@ -20,6 +21,10 @@ class RuntimeInputsTest(unittest.TestCase):
|
||||
self.temp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self.temp.cleanup)
|
||||
self.root = Path(self.temp.name)
|
||||
# Component archive validation has its own binary/archive fixtures.
|
||||
component_check = patch.object(runtime, 'verify_powervr')
|
||||
component_check.start()
|
||||
self.addCleanup(component_check.stop)
|
||||
paths = runtime.outputs(self.root)
|
||||
for name in runtime.required():
|
||||
path = self.root / paths.get(name, 'app/src/main/' + name)
|
||||
@@ -115,6 +120,20 @@ class RuntimeInputsTest(unittest.TestCase):
|
||||
with self.assertRaisesRegex(ValueError, 'quest1.tzst'):
|
||||
runtime.record(self.root)
|
||||
|
||||
def test_changed_powervr_wrapper_rejects_old_outputs(self):
|
||||
wrapper = self.root / 'tools/hybris/run-proton.py'
|
||||
wrapper.parent.mkdir(parents=True)
|
||||
wrapper.write_text('current wrapper')
|
||||
runtime.record(self.root)
|
||||
wrapper.write_text('changed wrapper')
|
||||
with self.assertRaisesRegex(ValueError, 'sources changed'):
|
||||
runtime.verify(self.root)
|
||||
|
||||
def test_missing_powervr_bundle_cannot_be_attested(self):
|
||||
(self.root / 'app/src/main/assets/hybris/runtime.tzst').unlink()
|
||||
with self.assertRaisesRegex(ValueError, 'assets/hybris/runtime.tzst'):
|
||||
runtime.record(self.root)
|
||||
|
||||
def test_modified_prebuilt_binary_is_rejected(self):
|
||||
runtime.record(self.root)
|
||||
(self.root / 'app/src/main/jniLibs/arm64-v8a/libproot.so').write_bytes(b'old APK binary')
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shlex
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
WRAPPER = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-steam-taskset"
|
||||
|
||||
|
||||
class SteamHelperAffinityTest(unittest.TestCase):
|
||||
def launch(self, status, form="helper", configured=True):
|
||||
with tempfile.TemporaryDirectory(prefix="droiddeck-helper-") as temporary:
|
||||
root = Path(temporary)
|
||||
helper = root / "steamwebhelper"
|
||||
helper.write_text(f"#!{sys.executable}\n" +
|
||||
'import json, os, sys\n'
|
||||
'with open(os.environ["STARTS"],"a") as f: f.write(json.dumps(sys.argv[1:])+"\\n")\n'
|
||||
'sys.exit(23)\n')
|
||||
helper.chmod(0o755)
|
||||
real = root / "real-taskset"
|
||||
real.write_text(f"#!{sys.executable}\n" +
|
||||
'import json, os, sys\n'
|
||||
'with open(os.environ["TRACE"],"a") as f: f.write(json.dumps(sys.argv[1:])+"\\n")\n'
|
||||
f'sys.exit({status})\n')
|
||||
real.chmod(0o755)
|
||||
wrapper = root / "taskset"
|
||||
wrapper.write_text(WRAPPER.read_text().replace("/usr/bin/taskset", shlex.quote(str(real))))
|
||||
helper_path = helper
|
||||
if form == "alias":
|
||||
helper_path = root / "helper symlink"
|
||||
helper_path.symlink_to(helper)
|
||||
elif form == "other":
|
||||
helper_path = root / "other/steamwebhelper"
|
||||
helper_path.parent.mkdir()
|
||||
helper_path.write_text(helper.read_text())
|
||||
helper_path.chmod(0o755)
|
||||
args = ["0x7c", str(helper_path), "arg with spaces", "--literal=$HOME"]
|
||||
if form == "query":
|
||||
args = ["-p", "12345"]
|
||||
elif form == "invalid":
|
||||
args[0] = "not-a-mask"
|
||||
elif form == "empty":
|
||||
args = []
|
||||
env = dict(os.environ, TRACE=str(root / "trace"), STARTS=str(root / "starts"))
|
||||
env.pop("BL_STEAM_WEBHELPER", None)
|
||||
if configured:
|
||||
env["BL_STEAM_WEBHELPER"] = str(helper)
|
||||
result = subprocess.run(["bash", str(wrapper), *args], env=env,
|
||||
capture_output=True, text=True, timeout=5)
|
||||
trace = [json.loads(x) for x in (root / "trace").read_text().splitlines()]
|
||||
starts = ([json.loads(x) for x in (root / "starts").read_text().splitlines()]
|
||||
if (root / "starts").exists() else [])
|
||||
return result, trace, starts, args
|
||||
|
||||
def test_denied_pinning_still_executes_helper_once(self):
|
||||
result, trace, starts, args = self.launch(1)
|
||||
self.assertEqual(result.returncode, 23)
|
||||
self.assertEqual(starts, [args[2:]])
|
||||
self.assertEqual(len(trace), 1)
|
||||
self.assertEqual(trace[0][:2], ["-p", "0x7c"])
|
||||
self.assertRegex(trace[0][2], r"^[1-9][0-9]*$")
|
||||
self.assertIn("using the allowed CPUs", result.stderr)
|
||||
|
||||
def test_successful_pinning_preserves_helper_exit_status(self):
|
||||
result, trace, starts, args = self.launch(0)
|
||||
self.assertEqual(result.returncode, 23)
|
||||
self.assertEqual(starts, [args[2:]])
|
||||
self.assertEqual(trace[0][:2], ["-p", "0x7c"])
|
||||
self.assertNotIn("pinning unavailable", result.stderr)
|
||||
|
||||
def test_symlink_to_actual_helper_is_recognized(self):
|
||||
result, _, starts, args = self.launch(1, "alias")
|
||||
self.assertEqual(result.returncode, 23)
|
||||
self.assertEqual(starts, [args[2:]])
|
||||
|
||||
def test_other_taskset_forms_and_targets_pass_through(self):
|
||||
for form, configured in [("other", True), ("query", True), ("invalid", True),
|
||||
("empty", True), ("helper", False)]:
|
||||
with self.subTest(form=form, configured=configured):
|
||||
result, trace, starts, args = self.launch(47, form, configured)
|
||||
self.assertEqual(result.returncode, 47)
|
||||
self.assertEqual(trace, [args])
|
||||
self.assertEqual(starts, [])
|
||||
self.assertNotIn("pinning unavailable", result.stderr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,75 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
SESSION = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-session"
|
||||
|
||||
|
||||
class SteamPresentationTest(unittest.TestCase):
|
||||
def launch(self, enabled=None, inherited=None):
|
||||
source = SESSION.read_text()
|
||||
begin = source.index(" bl_steam_path=$PATH")
|
||||
end = source.index("\n decky_loader=", begin)
|
||||
command = source.index(' PATH="$bl_steam_path"')
|
||||
command_end = source.index("\n rc=$?", command)
|
||||
script = (source[begin:end] + '\n_bl_ui=(-gamepadui); _bl_cdp=(); _bl_lang=()\n'
|
||||
# 0.5.0 launches through steam_client (the arm64 client, or the x86-64 one under FEX).
|
||||
+ 'steam_client=("$steam_root/steamrtarm64/steam")\n'
|
||||
+ source[command:command_end])
|
||||
env = dict(os.environ)
|
||||
for key in ("BL_STEAM_GL_PRESENT", "DISABLE_GAMESCOPE_WSI", "LIBGL_KOPPER_DISABLE"):
|
||||
env.pop(key, None)
|
||||
if enabled is not None:
|
||||
env["BL_STEAM_GL_PRESENT"] = enabled
|
||||
env.update(inherited or {})
|
||||
with tempfile.TemporaryDirectory(prefix="droiddeck-steam-gl-") as tmp:
|
||||
program = Path(tmp) / "steamrtarm64/steam"
|
||||
program.parent.mkdir()
|
||||
program.write_text(f"#!{sys.executable}\n" +
|
||||
'import json, os, sys\nprint(json.dumps({"args":sys.argv[1:],'
|
||||
'"disable":os.getenv("DISABLE_GAMESCOPE_WSI"),'
|
||||
'"kopper":os.getenv("LIBGL_KOPPER_DISABLE"),'
|
||||
'"path":os.getenv("PATH"),'
|
||||
'"helper":os.getenv("BL_STEAM_WEBHELPER")}))\n')
|
||||
program.chmod(0o755)
|
||||
env.update(steam_root=tmp, steam_channel="steamdeck_publicbeta")
|
||||
result = subprocess.run(["bash", "-c", script, "test", "steam://open/main"],
|
||||
env=env, capture_output=True, text=True, timeout=5)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
launch = json.loads(result.stdout.splitlines()[-1])
|
||||
self.assertEqual(enabled == "1", launch["path"].startswith("/usr/local/libexec/droiddeck-steam:"))
|
||||
self.assertEqual(launch["helper"], str(Path(tmp) / "steamrtarm64/steamwebhelper"))
|
||||
return launch
|
||||
|
||||
def test_default_keeps_vulkan(self):
|
||||
result = self.launch()
|
||||
self.assertIn("-cef-use-angle=vulkan", result["args"])
|
||||
self.assertNotIn("-cef-disable-gpu-compositing", result["args"])
|
||||
self.assertIsNone(result["disable"])
|
||||
self.assertIsNone(result["kopper"])
|
||||
|
||||
def test_system_powervr_keeps_gpu_gl_with_software_web_compositing(self):
|
||||
result = self.launch("1")
|
||||
self.assertIn("-cef-use-angle=gl", result["args"])
|
||||
self.assertIn("-cef-use-gl=angle", result["args"])
|
||||
self.assertIn("-cef-force-gpu", result["args"])
|
||||
self.assertIn("-cef-disable-gpu-compositing", result["args"])
|
||||
self.assertNotIn("-cef-disable-gpu", result["args"])
|
||||
self.assertEqual(result["disable"], "1")
|
||||
self.assertEqual(result["kopper"], "true")
|
||||
self.assertEqual(result["args"][-1], "steam://open/main")
|
||||
|
||||
def test_disabled_option_preserves_existing_environment(self):
|
||||
result = self.launch("0", {"DISABLE_GAMESCOPE_WSI": "0", "LIBGL_KOPPER_DISABLE": "false"})
|
||||
self.assertIn("-cef-use-angle=vulkan", result["args"])
|
||||
self.assertNotIn("-cef-disable-gpu-compositing", result["args"])
|
||||
self.assertEqual(result["disable"], "0")
|
||||
self.assertEqual(result["kopper"], "false")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,120 @@
|
||||
"""Exercise production DMA-BUF release/ownership paths without a GPU.
|
||||
|
||||
Wayland resources and OS timer/Android AHB endpoints are fake; list macros and
|
||||
the compositor/AHB lifecycle functions come directly from the repository.
|
||||
"""
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from test_vk_pending_completion import function
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
SRC = ROOT / 'app/src/main/cpp/waylandcomp/src'
|
||||
|
||||
|
||||
class VkDmabufQuarantineTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cc = shutil.which(os.environ.get('CC', 'cc'))
|
||||
if not cc:
|
||||
raise AssertionError('C compiler required')
|
||||
# Optional old-head input allows a genuine negative control using the
|
||||
# identical harness, rather than a model of the previous behaviour.
|
||||
source_dir = Path(os.environ.get('DROIDDECK_DMABUF_TEST_SOURCE', SRC))
|
||||
comp = (source_dir / 'compositor.c').read_text()
|
||||
ahb = (source_dir / 'ahb_swapchain.c').read_text()
|
||||
vk = (source_dir / 'vk_present.c').read_text()
|
||||
names = ['get_dmabuf', 'pending_release_free',
|
||||
'pending_releases_forget_surface', 'on_pending_release_buffer_destroyed',
|
||||
'arm_release_timer', 'on_release_timer', 'release_buffer',
|
||||
'dmabuf_buffer_unref', 'drop_dmabuf', 'on_dmabuf_destroyed',
|
||||
'droiddeck_dmabuf_ahb_slot', 'droiddeck_dmabuf_unref',
|
||||
'droiddeck_release_buffer']
|
||||
helpers = []
|
||||
if re.search(r'\bstatic int buffer_release_blocked\(', comp):
|
||||
helpers = [function(comp, 'buffer_release_blocked')]
|
||||
if re.search(r'\bstatic void send_buffer_release_at\(', comp):
|
||||
# send_buffer_release is a macro over send_buffer_release_at (with buffer tracing).
|
||||
helpers += ['static void buf_trace_release(struct wl_resource *b, int line) { (void)b; (void)line; }',
|
||||
'#define send_buffer_release(b) send_buffer_release_at((b), __LINE__)',
|
||||
function(comp, 'send_buffer_release_at')]
|
||||
else:
|
||||
helpers += [function(comp, 'send_buffer_release')]
|
||||
else:
|
||||
helpers = ['static int __attribute__((unused)) buffer_release_blocked(struct wl_resource *b) { (void)b; return 0; }']
|
||||
if re.search(r'\bstatic int buffer_shown_elsewhere\(', comp):
|
||||
# One surface per buffer in these scenarios: never shown elsewhere.
|
||||
helpers += ['static int buffer_shown_elsewhere(struct wl_resource *b, const struct surface *e) '
|
||||
'{ (void)b; (void)e; return 0; }']
|
||||
if re.search(r'\bvolatile int g_release_unpaced;', comp):
|
||||
# Releases stay paced in these scenarios (fps limit -1 sends them at once).
|
||||
helpers.insert(0, 'static int g_release_unpaced;')
|
||||
query = function(vk, 'vkp_completion_unknown') if 'int vkp_completion_unknown(' in vk else \
|
||||
'int vkp_completion_unknown(void) { return g_dev_state == -3; }'
|
||||
comp_functions = [function(comp, names[0])] + helpers + [function(comp, n) for n in names[1:]]
|
||||
ahb_functions = [function(ahb, n) for n in ('buf_free', 'maybe_free',
|
||||
'on_buffer_resource_destroyed', 'send_deferred_release',
|
||||
'on_fence_readable', 'ahb_swapchain_defer_release',
|
||||
'ahb_swapchain_surface_gone')]
|
||||
structs = re.search(r'struct pending_release \{.*?\n\};', comp, re.S).group() + '\n' + \
|
||||
re.search(r'struct ahb_buf \{.*?\n\};', ahb, re.S).group()
|
||||
harness = Path(__file__).with_name('vk_dmabuf_quarantine_test.c').read_text()
|
||||
harness = harness.replace('/* PRODUCTION_STRUCTS */', structs)
|
||||
harness = harness.replace('/* PRODUCTION_FUNCTIONS */', '\n'.join([query] + comp_functions + ahb_functions))
|
||||
cls.tmp = tempfile.TemporaryDirectory(prefix='droiddeck-dmabuf-')
|
||||
cls.addClassCleanup(cls.tmp.cleanup)
|
||||
probe = Path(cls.tmp.name) / 'probe.c'
|
||||
probe.write_text(harness)
|
||||
cls.binary = probe.with_suffix('')
|
||||
built = subprocess.run([cc, '-std=c11', '-Wall', '-Wextra', '-Werror',
|
||||
'-Wno-unused-parameter', '-UNDEBUG',
|
||||
'-I', str(SRC.parent / 'prebuilt/include'),
|
||||
str(probe), '-o', str(cls.binary)], capture_output=True, text=True)
|
||||
if built.returncode:
|
||||
raise AssertionError(built.stdout + built.stderr)
|
||||
|
||||
def run_scenario(self, name):
|
||||
result = subprocess.run([str(self.binary), name], capture_output=True, text=True, timeout=10)
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
|
||||
def test_replacement_retains_reference_and_release(self):
|
||||
self.run_scenario('replacement')
|
||||
|
||||
def test_surface_destroy_retains_reference_and_release(self):
|
||||
self.run_scenario('surface-gone')
|
||||
|
||||
def test_queued_release_is_held_and_timer_disarmed(self):
|
||||
self.run_scenario('queued')
|
||||
|
||||
def test_mixed_queue_releases_only_copied_shm(self):
|
||||
self.run_scenario('mixed')
|
||||
|
||||
def test_client_destroy_retains_backing_fd(self):
|
||||
self.run_scenario('client-gone')
|
||||
|
||||
def test_ahb_callback_retains_ownership_and_release(self):
|
||||
self.run_scenario('ahb')
|
||||
|
||||
def test_active_client_destroy_retains_reference(self):
|
||||
self.run_scenario('active-client-gone')
|
||||
|
||||
def test_healthy_ahb_callback_and_cleanup(self):
|
||||
self.run_scenario('ahb-healthy')
|
||||
|
||||
def test_device_lost_ahb_callback_and_cleanup(self):
|
||||
self.run_scenario('ahb-device-lost')
|
||||
|
||||
def test_healthy_release_and_reference_cleanup(self):
|
||||
self.run_scenario('healthy')
|
||||
|
||||
def test_genuine_device_loss_keeps_existing_cleanup(self):
|
||||
self.run_scenario('device-lost')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,63 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
def vulkan_include_args():
|
||||
candidates = []
|
||||
for name in ("ANDROID_NDK_HOME", "ANDROID_NDK_ROOT"):
|
||||
if os.environ.get(name):
|
||||
candidates.append(Path(os.environ[name]))
|
||||
|
||||
android_home = os.environ.get("ANDROID_HOME")
|
||||
if android_home:
|
||||
ndk_root = Path(android_home) / "ndk"
|
||||
version = os.environ.get("NDK_VERSION")
|
||||
if version:
|
||||
candidates.append(ndk_root / version)
|
||||
if ndk_root.is_dir():
|
||||
candidates.extend(sorted(ndk_root.iterdir(), reverse=True))
|
||||
|
||||
for ndk in candidates:
|
||||
include = ndk / "toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include"
|
||||
if (include / "vulkan/vulkan.h").is_file():
|
||||
return ["-idirafter", str(include)]
|
||||
return []
|
||||
|
||||
|
||||
class VkExternalImageSyncTest(unittest.TestCase):
|
||||
def test_client_barrier_pair(self):
|
||||
compiler = shutil.which(os.environ.get("CC", "cc"))
|
||||
if not compiler:
|
||||
self.fail("A C compiler is required for the Vulkan image-sync regression test")
|
||||
|
||||
tests = Path(__file__).resolve().parent
|
||||
source = tests / "vk_external_image_sync_test.c"
|
||||
includes = tests.parents[1] / "app/src/main/cpp/waylandcomp/src"
|
||||
with tempfile.TemporaryDirectory(prefix="droiddeck-vk-sync-") as tmp:
|
||||
program = Path(tmp) / "vk-external-image-sync"
|
||||
command = [
|
||||
compiler,
|
||||
"-std=c11",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-UNDEBUG",
|
||||
"-I",
|
||||
str(includes),
|
||||
*vulkan_include_args(),
|
||||
str(source),
|
||||
"-o",
|
||||
str(program),
|
||||
]
|
||||
built = subprocess.run(command, capture_output=True, text=True)
|
||||
self.assertEqual(built.returncode, 0, built.stdout + built.stderr)
|
||||
ran = subprocess.run([str(program)], capture_output=True, text=True, timeout=30)
|
||||
self.assertEqual(ran.returncode, 0, ran.stdout + ran.stderr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,187 @@
|
||||
"""Fault-inject the production fence wait and imported-image destructor.
|
||||
|
||||
No GPU is wedged: a fake dispatch table returns the same result a timed-out
|
||||
submit would return. The compiled functions come from vk_present.c itself.
|
||||
"""
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
SOURCE = Path(__file__).resolve().parents[2] / 'app/src/main/cpp/waylandcomp/src/vk_present.c'
|
||||
|
||||
|
||||
def function(text, name):
|
||||
match = re.search(r'^(?:static )?[^\n;]+\b' + name + r'\([^;]*?\)\s*\{', text, re.M)
|
||||
if not match:
|
||||
raise AssertionError('Production function not found: ' + name)
|
||||
start = match.start()
|
||||
pos = text.index('{', match.start())
|
||||
depth = 1
|
||||
end = pos + 1
|
||||
while depth:
|
||||
depth += (text[end] == '{') - (text[end] == '}')
|
||||
end += 1
|
||||
return text[start:end]
|
||||
|
||||
|
||||
HARNESS = r'''
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
typedef int VkResult;
|
||||
typedef uintptr_t VkFence;
|
||||
#define VK_TRUE 1
|
||||
#define VK_SUCCESS 0
|
||||
#define VK_TIMEOUT 2
|
||||
#define VK_ERROR_DEVICE_LOST -4
|
||||
#define VK_ERROR_OUT_OF_HOST_MEMORY -1
|
||||
#define VK_ERROR_UNKNOWN -13
|
||||
static int g_dev_state, g_base_black;
|
||||
static uintptr_t g_dev = 1;
|
||||
static struct { int64_t wait_ns, wait_max_ns; unsigned waits; } g_perf;
|
||||
static VkResult answer;
|
||||
static unsigned destroyed, unmapped, freed_memory, forgotten, errors;
|
||||
static int64_t perf_now(void) { return 10; }
|
||||
static void perf_add(int64_t *s, int64_t *m, unsigned *c, int64_t d) { *s+=d; *m=d; ++*c; }
|
||||
static void __attribute__((unused)) droiddeck_log(const char *tag, const char *fmt, ...) { (void)tag; (void)fmt; ++errors; }
|
||||
#define LOGE(...) droiddeck_log("error", __VA_ARGS__)
|
||||
static VkResult wait_fn(uintptr_t dev, unsigned n, const VkFence *f, int all, uint64_t timeout) {
|
||||
(void)dev; (void)n; (void)f; (void)all; (void)timeout; return answer;
|
||||
}
|
||||
static void unmap_fn(uintptr_t dev, uintptr_t mem) { (void)dev; (void)mem; ++unmapped; }
|
||||
static void destroy_fn(uintptr_t dev, uintptr_t img, void *allocator) { (void)dev; (void)img; (void)allocator; ++destroyed; }
|
||||
static void free_fn(uintptr_t dev, uintptr_t mem, void *allocator) { (void)dev; (void)mem; (void)allocator; ++freed_memory; }
|
||||
static struct {
|
||||
VkResult (*WaitForFences)(uintptr_t, unsigned, const VkFence *, int, uint64_t);
|
||||
void (*UnmapMemory)(uintptr_t, uintptr_t);
|
||||
void (*DestroyImage)(uintptr_t, uintptr_t, void *);
|
||||
void (*FreeMemory)(uintptr_t, uintptr_t, void *);
|
||||
} g_vk = {wait_fn, unmap_fn, destroy_fn, free_fn};
|
||||
typedef struct AHardwareBuffer AHardwareBuffer;
|
||||
static int released_buffers;
|
||||
static void AHardwareBuffer_release(AHardwareBuffer *b) { (void)b; ++released_buffers; }
|
||||
struct vkp_image { uintptr_t image, mem; void *map; AHardwareBuffer *android_buffer; };
|
||||
static void blendp_forget_image(uintptr_t image) { (void)image; ++forgotten; }
|
||||
/* PRODUCTION_FUNCTIONS */
|
||||
static struct vkp_image *image(void) {
|
||||
struct vkp_image *p = calloc(1, sizeof(*p)); assert(p);
|
||||
p->image=1; p->mem=2; p->map=p; return p;
|
||||
}
|
||||
int main(void) {
|
||||
g_dev_state=1; answer=VK_SUCCESS;
|
||||
assert(timed_wait(1, 1000)==VK_SUCCESS);
|
||||
assert(g_dev_state==1);
|
||||
vkp_image_destroy(image());
|
||||
assert(destroyed==1 && unmapped==1 && freed_memory==1 && forgotten==1);
|
||||
|
||||
g_dev_state=1; g_base_black=1; answer=VK_TIMEOUT;
|
||||
assert(timed_wait(1, 1000)==VK_TIMEOUT);
|
||||
assert(g_dev_state!=1 && g_dev_state!=-2); /* pending work is not DEVICE_LOST */
|
||||
struct vkp_image *pending=image();
|
||||
vkp_image_destroy(pending);
|
||||
assert(destroyed==1 && unmapped==1 && freed_memory==1 && forgotten==1);
|
||||
unsigned first_errors=errors;
|
||||
assert(first_errors>0);
|
||||
assert(timed_wait(1, 1000)==VK_ERROR_UNKNOWN);
|
||||
assert(errors==first_errors); /* one terminal diagnostic, no repeated recovery */
|
||||
free(pending); /* fake GPU exists only in this test */
|
||||
|
||||
g_dev_state=1; answer=VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
assert(timed_wait(1, 1000)==VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||
assert(g_dev_state!=1 && g_dev_state!=-2);
|
||||
pending=image(); vkp_image_destroy(pending);
|
||||
assert(destroyed==1 && unmapped==1 && freed_memory==1 && forgotten==1);
|
||||
free(pending);
|
||||
|
||||
g_dev_state=1; answer=VK_ERROR_DEVICE_LOST;
|
||||
assert(timed_wait(1, 1000)==VK_ERROR_DEVICE_LOST);
|
||||
assert(g_dev_state==1); /* existing caller performs genuine device-loss cleanup */
|
||||
return 0;
|
||||
}
|
||||
'''
|
||||
|
||||
SWAPCHAIN_HARNESS = r'''
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
typedef int VkResult;
|
||||
#define VK_SUCCESS 0
|
||||
#define VK_ERROR_DEVICE_LOST -4
|
||||
#define VK_ERROR_OUT_OF_HOST_MEMORY -1
|
||||
#define VK_NULL_HANDLE 0
|
||||
static int g_dev_state, g_base_black, g_swap_md_identity;
|
||||
static uintptr_t g_dev=1, g_inst=1, g_swapchain, g_surface, *g_images;
|
||||
static uint32_t g_nimg;
|
||||
static unsigned resets, forgotten, destroyed, errors, lost;
|
||||
static VkResult answer;
|
||||
#define LOGE(...) (++errors)
|
||||
static VkResult idle_fn(uintptr_t dev) { (void)dev; return answer; }
|
||||
static void destroy_fn(uintptr_t dev, uintptr_t obj, void *alloc) {
|
||||
(void)dev; (void)obj; (void)alloc; ++destroyed;
|
||||
}
|
||||
static struct {
|
||||
VkResult (*DeviceWaitIdle)(uintptr_t);
|
||||
void (*DestroySwapchainKHR)(uintptr_t, uintptr_t, void *);
|
||||
void (*DestroySurfaceKHR)(uintptr_t, uintptr_t, void *);
|
||||
} g_vk={idle_fn, destroy_fn, destroy_fn};
|
||||
static void reset_sync(void) { ++resets; }
|
||||
static void blendp_forget_image(uintptr_t img) { (void)img; ++forgotten; }
|
||||
static void device_lost(const char *where) { (void)where; ++lost; g_dev_state=-2; }
|
||||
/* PRODUCTION_FUNCTIONS */
|
||||
static void setup(void) {
|
||||
g_dev_state=1; g_base_black=1; g_swap_md_identity=1;
|
||||
g_swapchain=2; g_surface=3; g_nimg=1;
|
||||
g_images=calloc(1,sizeof(*g_images)); assert(g_images); *g_images=4;
|
||||
}
|
||||
int main(void) {
|
||||
setup(); answer=VK_SUCCESS; destroy_swapchain();
|
||||
assert(resets==1 && destroyed==2 && forgotten==1);
|
||||
assert(!g_swapchain && !g_surface && !g_images && !g_nimg && !g_swap_md_identity);
|
||||
setup(); answer=VK_ERROR_OUT_OF_HOST_MEMORY; destroy_swapchain();
|
||||
assert(g_dev_state==-3 && errors==1);
|
||||
assert(resets==1 && destroyed==2 && forgotten==1);
|
||||
assert(g_swapchain && g_surface && g_images && g_nimg);
|
||||
destroy_swapchain();
|
||||
assert(errors==1 && resets==1 && destroyed==2);
|
||||
free(g_images); /* fake GPU resources only */
|
||||
setup(); answer=VK_ERROR_DEVICE_LOST; destroy_swapchain();
|
||||
assert(lost==1 && g_dev_state==-2);
|
||||
assert(resets==1 && destroyed==2 && forgotten==1);
|
||||
free(g_images);
|
||||
return 0;
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
class VkPendingCompletionTest(unittest.TestCase):
|
||||
def compile_and_run(self, harness, names):
|
||||
cc = shutil.which(os.environ.get('CC', 'cc'))
|
||||
self.assertIsNotNone(cc, 'A C compiler is required')
|
||||
text = SOURCE.read_text()
|
||||
production = '\n'.join(function(text, n) for n in names)
|
||||
with tempfile.TemporaryDirectory(prefix='droiddeck-pending-') as tmp:
|
||||
source=Path(tmp)/'probe.c'; binary=Path(tmp)/'probe'
|
||||
source.write_text(harness.replace('/* PRODUCTION_FUNCTIONS */', production))
|
||||
built=subprocess.run([cc,'-std=c11','-Wall','-Wextra','-Werror','-UNDEBUG',str(source),'-o',str(binary)],capture_output=True,text=True)
|
||||
self.assertEqual(built.returncode,0,built.stdout+built.stderr)
|
||||
ran=subprocess.run([str(binary)],capture_output=True,text=True,timeout=10)
|
||||
self.assertEqual(ran.returncode,0,ran.stdout+ran.stderr)
|
||||
|
||||
def test_unknown_completion_retains_gpu_resources(self):
|
||||
self.compile_and_run(HARNESS, ['quarantine_pending_work', 'timed_wait', 'vkp_image_destroy'])
|
||||
|
||||
def test_failed_device_idle_does_not_destroy_swapchain(self):
|
||||
# LOGE's arguments must be evaluated as real production logging does.
|
||||
harness = SWAPCHAIN_HARNESS.replace('#define LOGE(...) (++errors)',
|
||||
'static void log_error(const char *fmt, int result, const char *where) { '
|
||||
'(void)fmt; (void)result; (void)where; ++errors; }\n#define LOGE(...) log_error(__VA_ARGS__)')
|
||||
self.compile_and_run(harness, ['quarantine_pending_work', 'destroy_swapchain'])
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,140 @@
|
||||
"""Fault-inject complete production render/blit/upload callers, without a GPU.
|
||||
|
||||
Uses Vulkan-Headers from the Android NDK (as installed by APK CI), or the host
|
||||
Vulkan development package. Only Android platform declarations and the external
|
||||
effect/frame-generation modules are mocked; vk_present.c is compiled unmodified.
|
||||
"""
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from test_vk_pending_completion import function
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
SOURCE = ROOT / 'app/src/main/cpp/waylandcomp/src/vk_present.c'
|
||||
|
||||
|
||||
def vulkan_include():
|
||||
candidates = [Path(p) for p in [os.environ.get('DROIDDECK_VULKAN_INCLUDE', ''),
|
||||
'/usr/include', '/usr/local/include'] if p]
|
||||
for name in ('ANDROID_HOME', 'ANDROID_SDK_ROOT', 'ANDROID_NDK_HOME', 'NDK'):
|
||||
if os.environ.get(name):
|
||||
root = Path(os.environ[name])
|
||||
candidates += sorted(root.glob('ndk/*/toolchains/llvm/prebuilt/*/sysroot/usr/include'), reverse=True)
|
||||
candidates += list(root.glob('toolchains/llvm/prebuilt/*/sysroot/usr/include'))
|
||||
return next((p for p in candidates if (p / 'vulkan/vulkan.h').is_file()), None)
|
||||
|
||||
|
||||
class VkTerminalCallersTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
headers = vulkan_include()
|
||||
if headers is None:
|
||||
raise unittest.SkipTest('NDK or host Vulkan-Headers required for full production-C caller tests')
|
||||
cc = shutil.which(os.environ.get('CC', 'cc'))
|
||||
if not cc:
|
||||
raise AssertionError('C compiler required')
|
||||
cls.tmp = tempfile.TemporaryDirectory(prefix='droiddeck-callers-')
|
||||
cls.addClassCleanup(cls.tmp.cleanup)
|
||||
tmp = Path(cls.tmp.name)
|
||||
(tmp / 'android').mkdir()
|
||||
(tmp / 'android/native_window.h').write_text('''
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
typedef struct ANativeWindow ANativeWindow;
|
||||
int32_t ANativeWindow_getWidth(ANativeWindow *);
|
||||
int32_t ANativeWindow_getHeight(ANativeWindow *);
|
||||
void ANativeWindow_release(ANativeWindow *);
|
||||
''')
|
||||
(tmp / 'android/hardware_buffer.h').write_text('''
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
typedef struct AHardwareBuffer AHardwareBuffer;
|
||||
typedef struct AHardwareBuffer_Desc {
|
||||
uint32_t width, height, layers, format;
|
||||
uint64_t usage;
|
||||
uint32_t stride, rfu0;
|
||||
uint64_t rfu1;
|
||||
} AHardwareBuffer_Desc;
|
||||
#define AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE (1ULL << 8)
|
||||
#define AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT (1ULL << 14)
|
||||
#define AHARDWAREBUFFER_USAGE_GPU_MIPMAP_COMPLETE (1ULL << 26)
|
||||
static inline void AHardwareBuffer_describe(const AHardwareBuffer *b, AHardwareBuffer_Desc *d) { (void)b; *d = (AHardwareBuffer_Desc){0}; }
|
||||
static inline void AHardwareBuffer_acquire(AHardwareBuffer *b) { (void)b; }
|
||||
static inline void AHardwareBuffer_release(AHardwareBuffer *b) { (void)b; }
|
||||
''')
|
||||
(tmp / 'sys').mkdir()
|
||||
(tmp / 'sys/system_properties.h').write_text('''
|
||||
#pragma once
|
||||
#define PROP_VALUE_MAX 92
|
||||
static inline int __system_property_get(const char *name, char *value) { (void)name; value[0] = 0; return 0; }
|
||||
''')
|
||||
(tmp / 'android/log.h').write_text('''
|
||||
#pragma once
|
||||
#define ANDROID_LOG_INFO 4
|
||||
int __android_log_print(int, const char *, const char *, ...);
|
||||
''')
|
||||
(tmp / 'wayland-server.h').write_text('#pragma once\nstruct wl_display; struct wl_resource; struct wl_client;\n')
|
||||
compositor = (SOURCE.parent / 'compositor.c').read_text()
|
||||
# send_buffer_release is a macro over send_buffer_release_at (with buffer tracing).
|
||||
callers = ('static void buf_trace_release(struct wl_resource *b, int line) { (void)b; (void)line; }\n'
|
||||
+ '#define send_buffer_release(b) send_buffer_release_at((b), __LINE__)\n'
|
||||
+ '\n'.join(function(compositor, n) for n in ('buffer_release_blocked', 'send_buffer_release_at', 'take_shm', 'take_pixel')))
|
||||
harness = (Path(__file__).with_name('vk_terminal_callers_test.c')).read_text()
|
||||
probe = tmp / 'probe.c'
|
||||
probe.write_text(harness.replace('/* COMPOSITOR_CALLERS */', callers))
|
||||
cls.binary = tmp / 'probe'
|
||||
built = subprocess.run([cc, '-std=c11', '-Wall', '-Wextra', '-Werror',
|
||||
'-Wno-unused-parameter', '-Wno-missing-field-initializers', '-UNDEBUG',
|
||||
'-I', str(tmp), '-idirafter', str(headers), '-I', str(SOURCE.parent),
|
||||
str(probe), '-pthread', '-o', str(cls.binary)],
|
||||
capture_output=True, text=True)
|
||||
if built.returncode:
|
||||
raise AssertionError(built.stdout + built.stderr)
|
||||
|
||||
def run_scenario(self, name):
|
||||
ran = subprocess.run([str(self.binary), name], capture_output=True, text=True, timeout=10)
|
||||
self.assertEqual(ran.returncode, 0, ran.stdout + ran.stderr)
|
||||
|
||||
def test_first_acquire_idle_failure(self):
|
||||
self.run_scenario('first-out-of-date')
|
||||
|
||||
def test_first_surface_lost_idle_failure(self):
|
||||
self.run_scenario('first-surface-lost')
|
||||
|
||||
def test_later_framegen_acquire_idle_failure(self):
|
||||
self.run_scenario('later-out-of-date')
|
||||
|
||||
def test_later_framegen_surface_lost_idle_failure(self):
|
||||
self.run_scenario('later-surface-lost')
|
||||
|
||||
def test_finite_blit_timeout_same_size_shm_upload(self):
|
||||
self.run_scenario('shm-timeout')
|
||||
|
||||
def test_finite_blit_timeout_same_size_pixel_upload(self):
|
||||
self.run_scenario('pixel-timeout')
|
||||
|
||||
def test_normal_present(self):
|
||||
self.run_scenario('normal')
|
||||
|
||||
def test_normal_framegen_present(self):
|
||||
self.run_scenario('framegen')
|
||||
|
||||
def test_healthy_later_acquire_timeout_drains_work(self):
|
||||
self.run_scenario('later-timeout')
|
||||
|
||||
def test_real_device_lost_on_acquire(self):
|
||||
self.run_scenario('acquire-device-lost')
|
||||
|
||||
def test_real_device_lost_on_present(self):
|
||||
self.run_scenario('present-device-lost')
|
||||
|
||||
def test_pass_copy_and_abort_terminal_entry(self):
|
||||
self.run_scenario('pass-terminal')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,47 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
TOOLS = Path(__file__).resolve().parents[1]
|
||||
LAYER = TOOLS / "linuxfs/xclipse-layer"
|
||||
|
||||
|
||||
class XclipseLayerTest(unittest.TestCase):
|
||||
def test_layer_against_a_mock_loader_and_driver(self):
|
||||
compiler = shutil.which(os.environ.get("CC", "cc"))
|
||||
if not compiler:
|
||||
self.fail("A C compiler is required for the Xclipse layer regression test")
|
||||
# The build compiles the layer against the distribution's headers (libvulkan-dev);
|
||||
# VULKAN_INCLUDE points elsewhere, e.g. a Vulkan-Headers checkout on macOS.
|
||||
include = Path(os.environ.get("VULKAN_INCLUDE", "/usr/include"))
|
||||
if not (include / "vulkan/vk_layer.h").is_file():
|
||||
self.fail("Vulkan headers are required: install libvulkan-dev or set VULKAN_INCLUDE")
|
||||
with tempfile.TemporaryDirectory(prefix="droiddeck-xclipse-") as tmp:
|
||||
program = Path(tmp) / "xclipse-layer"
|
||||
built = subprocess.run([compiler, "-std=gnu11", "-Wall", "-Wextra", "-Werror", "-Wno-unused-parameter",
|
||||
"-UNDEBUG", "-pthread", "-I", str(LAYER), "-I", str(include),
|
||||
str(Path(__file__).with_name("xclipse_layer_test.c")), "-ldl", "-o", str(program)],
|
||||
capture_output=True, text=True)
|
||||
self.assertEqual(built.returncode, 0, built.stdout + built.stderr)
|
||||
ran = subprocess.run([str(program)], capture_output=True, text=True, timeout=30)
|
||||
self.assertEqual(ran.returncode, 0, ran.stdout + ran.stderr)
|
||||
self.assertIn("xclipse layer ok", ran.stdout)
|
||||
|
||||
def test_device_chain_table_matches_its_generator(self):
|
||||
registry = os.environ.get("VULKAN_REGISTRY")
|
||||
if not registry:
|
||||
self.skipTest("set VULKAN_REGISTRY to a Vulkan-Headers 1.3.275 checkout to recheck device_chain.inc")
|
||||
with tempfile.TemporaryDirectory(prefix="droiddeck-chain-") as tmp:
|
||||
output = Path(tmp) / "device_chain.inc"
|
||||
subprocess.run(["python3", str(LAYER / "gen_device_chain.py"), str(Path(registry) / "registry/vk.xml"),
|
||||
str(Path(registry) / "include/vulkan/vulkan_core.h"), str(output)],
|
||||
check=True, capture_output=True)
|
||||
self.assertEqual(output.read_text(), (LAYER / "device_chain.inc").read_text())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,199 @@
|
||||
/* Production lifecycle functions are inserted verbatim by Python. No GPU,
|
||||
* Android app, external client or real timer is involved in this probe. */
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <wayland-util.h>
|
||||
#ifndef __linux__
|
||||
struct itimerspec { struct timespec it_interval, it_value; };
|
||||
#endif
|
||||
|
||||
struct wl_listener { struct wl_list link; void (*notify)(struct wl_listener *, void *); };
|
||||
struct wl_resource { int dma; void *user_data; struct wl_list listeners; unsigned releases; };
|
||||
struct wl_client;
|
||||
struct wl_event_source { int unused; };
|
||||
typedef struct AHardwareBuffer { int unused; } AHardwareBuffer;
|
||||
struct vkp_image { int unused; };
|
||||
struct dmabuf_buffer {
|
||||
int refs, n_planes, fd[4];
|
||||
struct vkp_image *img;
|
||||
void *ahb_state;
|
||||
};
|
||||
struct surface {
|
||||
struct wl_resource *dmabuf;
|
||||
struct dmabuf_buffer *dmabuf_buf;
|
||||
struct wl_listener dmabuf_destroy;
|
||||
int releases_pending;
|
||||
int64_t next_release_ns;
|
||||
};
|
||||
/* PRODUCTION_STRUCTS */
|
||||
static int g_dev_state, g_fps_limit, g_release_timer_fd;
|
||||
static int64_t g_refresh_ns;
|
||||
static struct wl_list g_pending_releases, g_bufs;
|
||||
static void *g_display;
|
||||
static unsigned image_destroys, ahb_releases, source_removes;
|
||||
static struct itimerspec last_timer;
|
||||
static const int wl_buffer_interface = 1, dbuf_buffer_impl = 2;
|
||||
#define TFD_TIMER_ABSTIME 1
|
||||
|
||||
/* List operations use the real Wayland layouts/macros. OS/IPC endpoints alone
|
||||
* are fakes, so no event is sent and no process or hardware is touched. */
|
||||
void wl_list_init(struct wl_list *l) { l->prev = l; l->next = l; }
|
||||
void wl_list_insert(struct wl_list *l, struct wl_list *e) {
|
||||
e->next = l->next; e->prev = l; l->next->prev = e; l->next = e;
|
||||
}
|
||||
void wl_list_remove(struct wl_list *e) { e->next->prev = e->prev; e->prev->next = e->next; }
|
||||
static int wl_resource_instance_of(struct wl_resource *r, const void *i, const void *impl) { return r->dma; }
|
||||
static void *wl_resource_get_user_data(struct wl_resource *r) { return r->user_data; }
|
||||
static void wl_resource_add_destroy_listener(struct wl_resource *r, struct wl_listener *l) {
|
||||
wl_list_insert(r->listeners.prev, &l->link);
|
||||
}
|
||||
static void wl_buffer_send_release(struct wl_resource *r) { ++r->releases; }
|
||||
static void wl_display_flush_clients(void *d) {}
|
||||
static int timerfd_settime(int fd, int flags, const struct itimerspec *v, void *old) { last_timer = *v; return 0; }
|
||||
static void perf_note_release(int64_t since) {}
|
||||
static int64_t now_ns(void) { return 1000000000LL; }
|
||||
static void vkp_image_destroy(struct vkp_image *img) { ++image_destroys; }
|
||||
static void AHardwareBuffer_release(AHardwareBuffer *ahb) { ++ahb_releases; }
|
||||
static int wl_event_source_remove(struct wl_event_source *src) { ++source_removes; return 0; }
|
||||
static struct dmabuf_buffer *get_dmabuf(struct wl_resource *r);
|
||||
int ahb_swapchain_defer_release(struct dmabuf_buffer *, struct wl_resource *, struct surface *, int);
|
||||
/* PRODUCTION_FUNCTIONS */
|
||||
|
||||
static void init_resource(struct wl_resource *r, struct dmabuf_buffer *b) {
|
||||
*r = (struct wl_resource){.dma = b != NULL, .user_data = b};
|
||||
wl_list_init(&r->listeners);
|
||||
}
|
||||
static struct dmabuf_buffer *init_buffer(struct surface *s, struct wl_resource *r) {
|
||||
struct dmabuf_buffer *b = calloc(1, sizeof(*b)); assert(b);
|
||||
b->refs = 2; b->n_planes = 1;
|
||||
int fds[2]; assert(pipe(fds) == 0); b->fd[0] = fds[0]; close(fds[1]);
|
||||
init_resource(r, b);
|
||||
assert(get_dmabuf(r) == b);
|
||||
*s = (struct surface){.dmabuf = r, .dmabuf_buf = b};
|
||||
s->dmabuf_destroy.notify = on_dmabuf_destroyed;
|
||||
wl_resource_add_destroy_listener(r, &s->dmabuf_destroy);
|
||||
return b;
|
||||
}
|
||||
static void destroy_resource(struct wl_resource *r) {
|
||||
while (r->listeners.next != &r->listeners) {
|
||||
struct wl_listener *l = wl_container_of(r->listeners.next, l, link);
|
||||
l->notify(l, r);
|
||||
}
|
||||
if (r->dma) dmabuf_buffer_unref(r->user_data);
|
||||
r->user_data = NULL;
|
||||
}
|
||||
static void fire_timer(void) {
|
||||
int fd[2]; uint64_t expirations = 1;
|
||||
assert(pipe(fd) == 0 && write(fd[1], &expirations, sizeof(expirations)) == sizeof(expirations));
|
||||
on_release_timer(fd[0], 0, NULL); close(fd[0]); close(fd[1]);
|
||||
}
|
||||
static void assert_retained(struct dmabuf_buffer *b, int refs) {
|
||||
assert(b->refs == refs && fcntl(b->fd[0], F_GETFD) >= 0 && !image_destroys);
|
||||
}
|
||||
static void test_drop(int paced) {
|
||||
struct surface s; struct wl_resource r;
|
||||
struct dmabuf_buffer *b = init_buffer(&s, &r);
|
||||
g_dev_state = -3; drop_dmabuf(&s, paced);
|
||||
assert(!s.dmabuf && !s.dmabuf_buf && !r.releases && !s.releases_pending);
|
||||
assert(r.listeners.next == &r.listeners); /* no listener into a dead surface */
|
||||
assert_retained(b, 2);
|
||||
destroy_resource(&r); assert_retained(b, 2);
|
||||
close(b->fd[0]); free(b); /* fake GPU only */
|
||||
}
|
||||
static void test_queue(int mixed, int client_gone) {
|
||||
struct surface s; struct wl_resource r, shm;
|
||||
struct dmabuf_buffer *b = init_buffer(&s, &r);
|
||||
g_release_timer_fd = 123; g_refresh_ns = 100000;
|
||||
drop_dmabuf(&s, 1); assert(s.releases_pending == 1 && !r.releases);
|
||||
assert(last_timer.it_value.tv_sec || last_timer.it_value.tv_nsec);
|
||||
if (mixed) { init_resource(&shm, NULL); release_buffer(&s, &shm, now_ns()); }
|
||||
pending_releases_forget_surface(&s);
|
||||
g_dev_state = -3;
|
||||
fire_timer();
|
||||
assert(!r.releases && g_pending_releases.next != &g_pending_releases);
|
||||
if (mixed) assert(shm.releases == 1);
|
||||
assert(!last_timer.it_value.tv_sec && !last_timer.it_value.tv_nsec);
|
||||
assert_retained(b, 1);
|
||||
if (client_gone) {
|
||||
destroy_resource(&r);
|
||||
assert(g_pending_releases.next == &g_pending_releases);
|
||||
assert_retained(b, 1);
|
||||
}
|
||||
close(b->fd[0]); free(b); /* fake GPU only */
|
||||
}
|
||||
static void test_active_client_destroy(void) {
|
||||
struct surface s; struct wl_resource r;
|
||||
struct dmabuf_buffer *b = init_buffer(&s, &r);
|
||||
g_dev_state = -3;
|
||||
destroy_resource(&r);
|
||||
assert(!s.dmabuf && s.dmabuf_buf == b && !r.releases);
|
||||
drop_dmabuf(&s, 0); assert(!s.dmabuf_buf);
|
||||
assert_retained(b, 2);
|
||||
close(b->fd[0]); free(b); /* fake GPU only */
|
||||
}
|
||||
static void test_ahb(int terminal, int lost) {
|
||||
struct surface s; struct wl_resource r;
|
||||
struct dmabuf_buffer *b = init_buffer(&s, &r);
|
||||
struct ahb_buf *ab = calloc(1, sizeof(*ab)); assert(ab);
|
||||
AHardwareBuffer ahb;
|
||||
*ab = (struct ahb_buf){.b = b, .ahb = &ahb, .resource = &r, .on_layer = 1, .fence_fd = -1};
|
||||
b->ahb_state = ab; ++b->refs;
|
||||
ab->resource_destroy.notify = on_buffer_resource_destroyed;
|
||||
wl_resource_add_destroy_listener(&r, &ab->resource_destroy);
|
||||
wl_list_insert(&g_bufs, &ab->link);
|
||||
drop_dmabuf(&s, 1); assert(ab->release_pending && ab->surface == &s);
|
||||
int backing_fd = b->fd[0];
|
||||
g_dev_state = terminal ? -3 : lost ? -2 : 1;
|
||||
ahb_swapchain_surface_gone(&s); assert(!ab->surface);
|
||||
/* Actual event-loop callback after the display's fence becomes readable. */
|
||||
struct wl_event_source source; int fds[2]; assert(pipe(fds) == 0);
|
||||
ab->on_layer = 0; ab->fence_src = &source; ab->fence_fd = fds[0];
|
||||
on_fence_readable(fds[0], 0, ab); close(fds[1]);
|
||||
assert(source_removes == 1 && ab->fence_fd == -1 && !ab->fence_src);
|
||||
assert(r.releases == (terminal ? 0u : 1u));
|
||||
assert(ab->release_pending == terminal && !ahb_releases);
|
||||
destroy_resource(&r);
|
||||
if (terminal) {
|
||||
assert(!ab->resource && b->ahb_state == ab && !ahb_releases);
|
||||
assert_retained(b, 2);
|
||||
close(b->fd[0]); free(ab); free(b); /* fake GPU only */
|
||||
} else {
|
||||
assert(ahb_releases == 1 && image_destroys == 1);
|
||||
errno = 0; assert(fcntl(backing_fd, F_GETFD) == -1 && errno == EBADF);
|
||||
}
|
||||
}
|
||||
static void test_cleanup(int lost) {
|
||||
struct surface s; struct wl_resource r;
|
||||
struct dmabuf_buffer *b = init_buffer(&s, &r);
|
||||
int fd = b->fd[0]; g_dev_state = lost ? -2 : 1;
|
||||
assert(!vkp_completion_unknown());
|
||||
drop_dmabuf(&s, 0);
|
||||
assert(r.releases == 1 && b->refs == 1 && !image_destroys);
|
||||
destroy_resource(&r); assert(image_destroys == 1);
|
||||
errno = 0; assert(fcntl(fd, F_GETFD) == -1 && errno == EBADF);
|
||||
}
|
||||
int main(int argc, char **argv) {
|
||||
assert(argc == 2);
|
||||
wl_list_init(&g_pending_releases); wl_list_init(&g_bufs);
|
||||
g_dev_state = 1; g_release_timer_fd = -1;
|
||||
if (!strcmp(argv[1], "replacement")) test_drop(1);
|
||||
else if (!strcmp(argv[1], "surface-gone")) test_drop(0);
|
||||
else if (!strcmp(argv[1], "queued")) test_queue(0, 0);
|
||||
else if (!strcmp(argv[1], "mixed")) test_queue(1, 0);
|
||||
else if (!strcmp(argv[1], "client-gone")) test_queue(0, 1);
|
||||
else if (!strcmp(argv[1], "ahb")) test_ahb(1, 0);
|
||||
else if (!strcmp(argv[1], "ahb-healthy")) test_ahb(0, 0);
|
||||
else if (!strcmp(argv[1], "ahb-device-lost")) test_ahb(0, 1);
|
||||
else if (!strcmp(argv[1], "active-client-gone")) test_active_client_destroy();
|
||||
else if (!strcmp(argv[1], "healthy")) test_cleanup(0);
|
||||
else if (!strcmp(argv[1], "device-lost")) test_cleanup(1);
|
||||
else assert(0 && "unknown scenario");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "vk_external_image_sync.h"
|
||||
|
||||
static void check_external_pair(const struct vkp_external_client_barrier_pair *pair,
|
||||
VkImage image, uint32_t queue_family) {
|
||||
assert(pair->acquire.sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER);
|
||||
assert(pair->acquire.oldLayout == VK_IMAGE_LAYOUT_GENERAL);
|
||||
assert(pair->acquire.newLayout == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
||||
assert(pair->acquire.srcQueueFamilyIndex == VK_QUEUE_FAMILY_FOREIGN_EXT);
|
||||
assert(pair->acquire.dstQueueFamilyIndex == queue_family);
|
||||
assert(pair->acquire.image == image);
|
||||
assert(pair->acquire.srcAccessMask == 0);
|
||||
assert(pair->acquire.dstAccessMask == VK_ACCESS_TRANSFER_READ_BIT);
|
||||
assert(pair->acquire.subresourceRange.aspectMask == VK_IMAGE_ASPECT_COLOR_BIT);
|
||||
assert(pair->acquire.subresourceRange.baseMipLevel == 0);
|
||||
assert(pair->acquire.subresourceRange.levelCount == 1);
|
||||
assert(pair->acquire.subresourceRange.baseArrayLayer == 0);
|
||||
assert(pair->acquire.subresourceRange.layerCount == 1);
|
||||
|
||||
assert(pair->release.sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER);
|
||||
assert(pair->release.oldLayout == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
||||
assert(pair->release.newLayout == VK_IMAGE_LAYOUT_GENERAL);
|
||||
assert(pair->release.srcQueueFamilyIndex == queue_family);
|
||||
assert(pair->release.dstQueueFamilyIndex == VK_QUEUE_FAMILY_FOREIGN_EXT);
|
||||
assert(pair->release.image == image);
|
||||
assert(pair->release.srcAccessMask == VK_ACCESS_MEMORY_READ_BIT);
|
||||
assert(pair->release.dstAccessMask == 0);
|
||||
assert(pair->release.subresourceRange.aspectMask == VK_IMAGE_ASPECT_COLOR_BIT);
|
||||
assert(pair->release.subresourceRange.levelCount == 1);
|
||||
assert(pair->release.subresourceRange.layerCount == 1);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
const VkImage image = (VkImage)(uintptr_t)0x1234;
|
||||
const VkImage ahb_image = (VkImage)(uintptr_t)0x5678;
|
||||
const uint32_t queue_family = 7;
|
||||
struct vkp_external_client_barrier_pair generic, ahb;
|
||||
|
||||
assert(vkp_external_client_barrier_pair(image, queue_family, 1, 0, &generic));
|
||||
check_external_pair(&generic, image, queue_family);
|
||||
|
||||
/* AHardwareBuffer imports deliberately use the same client flags and lifecycle. */
|
||||
assert(vkp_external_client_barrier_pair(ahb_image, queue_family, 1, 0, &ahb));
|
||||
check_external_pair(&ahb, ahb_image, queue_family);
|
||||
|
||||
unsigned char untouched[sizeof(generic)];
|
||||
memset(&generic, 0xa5, sizeof(generic));
|
||||
memcpy(untouched, &generic, sizeof(generic));
|
||||
assert(!vkp_external_client_barrier_pair(image, queue_family, 0, 0, &generic));
|
||||
assert(memcmp(&generic, untouched, sizeof(generic)) == 0);
|
||||
assert(!vkp_is_external_client_image(0, 0));
|
||||
|
||||
memset(&generic, 0x5a, sizeof(generic));
|
||||
memcpy(untouched, &generic, sizeof(generic));
|
||||
assert(!vkp_external_client_barrier_pair(image, queue_family, 1, 1, &generic));
|
||||
assert(memcmp(&generic, untouched, sizeof(generic)) == 0);
|
||||
assert(!vkp_is_external_client_image(1, 1));
|
||||
assert(vkp_is_external_client_image(1, 0));
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,290 @@
|
||||
/* Compiled with the complete, unmodified production translation unit. The
|
||||
* compositor's take_shm/take_pixel functions are inserted verbatim by Python. */
|
||||
#include "vk_present.c"
|
||||
#include <assert.h>
|
||||
|
||||
struct vk_api g_vk;
|
||||
static unsigned operations, acquires, submits, markers, waits, idle_calls, resets;
|
||||
static unsigned destroys, releases, lost_notifications, presented_notifications;
|
||||
static VkResult idle_answer, fence_answer, acquire_answer, present_answer;
|
||||
static unsigned fail_acquire_at;
|
||||
static int generated;
|
||||
|
||||
/* Every work-issuing callback is an oracle: no GPU operation after a terminal
|
||||
* result. Object destruction is counted separately for genuine device loss. */
|
||||
static void live(void) { assert(g_dev_state == 1); ++operations; }
|
||||
static VkResult acquire(VkDevice d, VkSwapchainKHR s, uint64_t t, VkSemaphore a, VkFence f, uint32_t *i) {
|
||||
live(); ++acquires; *i = 0;
|
||||
return acquires == fail_acquire_at ? acquire_answer : VK_SUCCESS;
|
||||
}
|
||||
static VkResult idle(VkDevice d) { live(); ++idle_calls; return idle_answer; }
|
||||
static VkResult wait_fences(VkDevice d, uint32_t n, const VkFence *f, VkBool32 all, uint64_t t) {
|
||||
live(); ++waits; return fence_answer;
|
||||
}
|
||||
static VkResult submit(VkQueue q, uint32_t n, const VkSubmitInfo *s, VkFence f) {
|
||||
live(); ++submits; if (!s->commandBufferCount) ++markers; return VK_SUCCESS;
|
||||
}
|
||||
static VkResult present(VkQueue q, const VkPresentInfoKHR *p) { live(); return present_answer; }
|
||||
static VkResult reset_cmd(VkCommandBuffer c, VkCommandBufferResetFlags f) { live(); ++resets; return VK_SUCCESS; }
|
||||
static VkResult reset_fence(VkDevice d, uint32_t n, const VkFence *f) { live(); ++resets; return VK_SUCCESS; }
|
||||
static VkResult begin_cmd(VkCommandBuffer c, const VkCommandBufferBeginInfo *b) { live(); return VK_SUCCESS; }
|
||||
static VkResult end_cmd(VkCommandBuffer c) { live(); return VK_SUCCESS; }
|
||||
static void barrier(VkCommandBuffer c, VkPipelineStageFlags s, VkPipelineStageFlags d, VkDependencyFlags f,
|
||||
uint32_t nm, const VkMemoryBarrier *m, uint32_t nb, const VkBufferMemoryBarrier *b,
|
||||
uint32_t ni, const VkImageMemoryBarrier *i) { live(); }
|
||||
static void clear(VkCommandBuffer c, VkImage i, VkImageLayout l, const VkClearColorValue *v,
|
||||
uint32_t n, const VkImageSubresourceRange *r) { live(); }
|
||||
static void blit(VkCommandBuffer c, VkImage s, VkImageLayout sl, VkImage d, VkImageLayout dl,
|
||||
uint32_t n, const VkImageBlit *b, VkFilter f) { live(); }
|
||||
static void destroy_swap(VkDevice d, VkSwapchainKHR s, const VkAllocationCallbacks *a) { ++destroys; }
|
||||
static void destroy_surface(VkInstance i, VkSurfaceKHR s, const VkAllocationCallbacks *a) { ++destroys; }
|
||||
static void destroy_sem(VkDevice d, VkSemaphore s, const VkAllocationCallbacks *a) { live(); ++destroys; }
|
||||
static VkResult create_sem(VkDevice d, const VkSemaphoreCreateInfo *c, const VkAllocationCallbacks *a, VkSemaphore *s) {
|
||||
live(); *s = (VkSemaphore)(uintptr_t)1; return VK_SUCCESS;
|
||||
}
|
||||
static void destroy_image(VkDevice d, VkImage i, const VkAllocationCallbacks *a) { ++destroys; }
|
||||
static void free_memory(VkDevice d, VkDeviceMemory m, const VkAllocationCallbacks *a) { ++destroys; }
|
||||
static void unmap(VkDevice d, VkDeviceMemory m) { ++destroys; }
|
||||
|
||||
/* External modules are not the subject of this fault injection. Their declared
|
||||
* signatures remain checked by the production headers. */
|
||||
int __android_log_print(int p, const char *t, const char *f, ...) { return 0; }
|
||||
void droiddeck_log(const char *t, const char *f, ...) {}
|
||||
void droiddeck_on_first_frame(void) {}
|
||||
int32_t ANativeWindow_getWidth(ANativeWindow *w) { return 64; }
|
||||
int32_t ANativeWindow_getHeight(ANativeWindow *w) { return 64; }
|
||||
void ANativeWindow_release(ANativeWindow *w) {}
|
||||
void sc_layer_window_gone(void) {}
|
||||
int sc_layer_present_pass(const struct vkp_draw *d, int n, int w, int h) { return 0; }
|
||||
void sc_layer_hide(void) {}
|
||||
int sc_layer_base_black(int w, int h) { return 0; }
|
||||
void sc_layer_hide_base(void) {}
|
||||
void sc_layer_hide_overlay(void) {}
|
||||
void vkp_cardboard_bind_device(VkDevice d, const VkPhysicalDeviceMemoryProperties *m) {}
|
||||
int vkp_cardboard_active(void) { return 0; }
|
||||
void vkp_cardboard_begin_frame(void) {}
|
||||
VkImage vkp_cardboard_run(VkCommandBuffer c, VkImage s, int sw, int sh, int ow, int oh) { return s; }
|
||||
int vk_loader_open(const char *a, const char *b, const char *c) { assert(0); return -1; }
|
||||
void vk_loader_load_instance(VkInstance i) { assert(0); }
|
||||
void vk_loader_load_device(VkDevice d) { assert(0); }
|
||||
PFN_vkGetInstanceProcAddr vk_loader_gipa(void) { return NULL; }
|
||||
void vkp_effects_bind_device(VkDevice d, VkPhysicalDevice p, const VkPhysicalDeviceMemoryProperties *m) {}
|
||||
int vkp_effects_active(void) { return 0; }
|
||||
int vkp_effects_upscaling(void) { return 0; }
|
||||
int vkp_effects_postprocessing(void) { return 0; }
|
||||
VkFilter vkp_effects_blit_filter(void) { return VK_FILTER_NEAREST; }
|
||||
void vkp_effects_set_formats(VkFormat a, VkFormat b) {}
|
||||
VkImage vkp_effects_run(VkCommandBuffer c, VkImage i, int w, int h, int ow, int oh, int *rw, int *rh) {
|
||||
*rw = w; *rh = h; return i;
|
||||
}
|
||||
const void *vkp_framegen_device_features(VkInstance i, PFN_vkGetInstanceProcAddr p, VkPhysicalDevice d) { return NULL; }
|
||||
void vkp_framegen_device_ready(VkDevice d, VkQueue q, uint32_t f, int e) {}
|
||||
void vkp_framegen_device_lost(void) { ++lost_notifications; }
|
||||
int vkp_framegen_active(void) { return generated != 0; }
|
||||
int vkp_framegen_extra_images(void) { return generated; }
|
||||
int vkp_framegen_format_ok(VkFormat f) { return 0; }
|
||||
int vkp_framegen_run(VkCommandBuffer c, VkImage s, VkImageView v, int w, int h,
|
||||
VkFormat f, VkImage images[VKP_FG_MAX_GENERATIONS]) {
|
||||
for (int i = 0; i < generated; ++i) images[i] = s;
|
||||
return generated;
|
||||
}
|
||||
void vkp_framegen_presented(int n) { ++presented_notifications; }
|
||||
void vkp_gpu_busy_device(VkPhysicalDevice p, VkDevice d, uint32_t f) {}
|
||||
void vkp_gpu_busy_device_lost(void) {}
|
||||
void hdrc_bind_device(VkDevice d, const VkPhysicalDeviceMemoryProperties *m) {}
|
||||
void hdrc_forget_image(VkImage i) {}
|
||||
int hdrc_encode(VkCommandBuffer c, VkImage a, VkImage b, VkFormat f, int w, int h, const struct hdrc_params *p) { return -1; }
|
||||
void blendp_bind_device(VkDevice d) {}
|
||||
void blendp_forget_image(VkImage i) {}
|
||||
void vkp_effects_forget_image(VkImage i) {}
|
||||
void blendp_begin_frame(void) {}
|
||||
int blendp_draw(VkCommandBuffer c, VkImage s, VkFormat sf, int sw, int sh, int sg,
|
||||
VkImage d, VkFormat df, int dw, int dh, const VkImageBlit *b) { return -1; }
|
||||
int droiddeck_color_requested(void) { return 0; }
|
||||
float droiddeck_color_sdr_white(void) { return 203.0f; }
|
||||
|
||||
enum surface_role { ROLE_NONE, ROLE_TOPLEVEL };
|
||||
struct damage_list { int n; };
|
||||
struct surface {
|
||||
struct vkp_image *shm_img;
|
||||
struct wl_resource *resource;
|
||||
int buf_w, buf_h, buf_alpha, has_content;
|
||||
/* Read by take_shm's game-frame detection; with no damage it stays off here. */
|
||||
int src_set; float src[4];
|
||||
struct damage_list damage_buf, damage_local;
|
||||
struct surface *parent; enum surface_role role; int mapped;
|
||||
};
|
||||
static void surface_size(const struct surface *s, int *w, int *h) { *w = s->buf_w; *h = s->buf_h; }
|
||||
static void scene_size(int *w, int *h) { *w = *h = 0; }
|
||||
static int64_t damage_area(const struct damage_list *d, int bound_w, int bound_h) { return 0; }
|
||||
static int64_t now_ns(void) { return 0; }
|
||||
static struct surface *g_hud_surface, *g_hud_shm;
|
||||
static int64_t g_hud_shm_ns, g_hud_last_ns;
|
||||
static int g_hud_new;
|
||||
static void droiddeck_on_game_frame(void) {}
|
||||
struct client_info { int asked_feedback, shm_frames; };
|
||||
struct wl_shm_buffer { int w, h, stride; const void *data; };
|
||||
#define WL_SHM_FORMAT_ARGB8888 0
|
||||
static unsigned g_stat_shm;
|
||||
static int wl_shm_buffer_get_width(struct wl_shm_buffer *b) { return b->w; }
|
||||
static int wl_shm_buffer_get_height(struct wl_shm_buffer *b) { return b->h; }
|
||||
static int wl_shm_buffer_get_stride(struct wl_shm_buffer *b) { return b->stride; }
|
||||
static int wl_shm_buffer_get_format(struct wl_shm_buffer *b) { return WL_SHM_FORMAT_ARGB8888; }
|
||||
static const void *wl_shm_buffer_get_data(struct wl_shm_buffer *b) { return b->data; }
|
||||
static void wl_shm_buffer_begin_access(struct wl_shm_buffer *b) {}
|
||||
static void wl_shm_buffer_end_access(struct wl_shm_buffer *b) {}
|
||||
struct wl_resource { int dmabuf; };
|
||||
static struct wl_resource *expected_release;
|
||||
static void wl_buffer_send_release(struct wl_resource *b) { assert(b && b == expected_release); ++releases; }
|
||||
static struct wl_client *wl_resource_get_client(struct wl_resource *r) { return NULL; }
|
||||
static struct client_info *client_info_of(struct wl_client *c) { return NULL; }
|
||||
struct dmabuf_buffer { int unused; };
|
||||
static struct dmabuf_buffer dmabuf_fixture;
|
||||
static struct dmabuf_buffer *get_dmabuf(struct wl_resource *buffer) {
|
||||
assert(buffer);
|
||||
return buffer->dmabuf ? &dmabuf_fixture : NULL;
|
||||
}
|
||||
/* COMPOSITOR_CALLERS */
|
||||
|
||||
static void setup(int extra) {
|
||||
g_vk = (struct vk_api){.AcquireNextImageKHR = acquire, .DeviceWaitIdle = idle,
|
||||
.WaitForFences = wait_fences, .QueueSubmit = submit, .QueuePresentKHR = present,
|
||||
.ResetCommandBuffer = reset_cmd, .ResetFences = reset_fence, .BeginCommandBuffer = begin_cmd,
|
||||
.EndCommandBuffer = end_cmd, .CmdPipelineBarrier = barrier, .CmdClearColorImage = clear,
|
||||
.CmdBlitImage = blit, .DestroySwapchainKHR = destroy_swap, .DestroySurfaceKHR = destroy_surface,
|
||||
.DestroySemaphore = destroy_sem, .CreateSemaphore = create_sem,
|
||||
.DestroyImage = destroy_image, .FreeMemory = free_memory, .UnmapMemory = unmap};
|
||||
idle_answer = fence_answer = acquire_answer = present_answer = VK_SUCCESS;
|
||||
generated = g_swap_extra = extra;
|
||||
g_dev_state = 1;
|
||||
g_dev = (VkDevice)(uintptr_t)1; g_inst = (VkInstance)(uintptr_t)1;
|
||||
g_window = (ANativeWindow *)(uintptr_t)1; g_queue = (VkQueue)(uintptr_t)1;
|
||||
g_swapchain = (VkSwapchainKHR)(uintptr_t)2; g_surface = (VkSurfaceKHR)(uintptr_t)3;
|
||||
g_images = calloc(1, sizeof(*g_images)); assert(g_images);
|
||||
*g_images = (VkImage)(uintptr_t)4; g_nimg = 1;
|
||||
g_extent = g_caps_extent = (VkExtent2D){64, 64};
|
||||
g_surface_checked_ns = INT64_MAX; /* no simulated geometry change */
|
||||
g_scene.img = (VkImage)(uintptr_t)5; g_scene.mem = (VkDeviceMemory)(uintptr_t)6;
|
||||
g_scene.w = g_scene.h = 64;
|
||||
for (int k = 0; k < MAX_PRESENTS; ++k) {
|
||||
g_cmds[k] = (VkCommandBuffer)(uintptr_t)(10 + k);
|
||||
g_acqs[k] = (VkSemaphore)(uintptr_t)(20 + k);
|
||||
g_rnds[k] = (VkSemaphore)(uintptr_t)(30 + k);
|
||||
}
|
||||
g_fence = (VkFence)(uintptr_t)40;
|
||||
}
|
||||
|
||||
/* Probe the public GPU entry points after a terminal result. This includes an
|
||||
* active off-screen pass and consumed release fds, not just the render guard. */
|
||||
static void assert_stopped(void) {
|
||||
unsigned before = operations, before_destroys = destroys;
|
||||
struct vkp_image src = {.image = (VkImage)(uintptr_t)7, .w = 1, .h = 1};
|
||||
struct vkp_image dst = {.image = (VkImage)(uintptr_t)8, .w = 1, .h = 1, .blit_dst = 1};
|
||||
uint32_t pixel = 0; uint64_t mod = 0;
|
||||
assert(vkp_render(64, 64, NULL, 0) == -1);
|
||||
assert(vkp_render_plain(64, 64) == -1);
|
||||
assert(vkp_render_hdr(64, 64, NULL, 0, NULL, NULL) == -1);
|
||||
assert(vkp_base_black(64, 64) == -1);
|
||||
assert(vkp_update_map(64, 64) == -1);
|
||||
assert(vkp_ready() == -1);
|
||||
assert(vkp_image_create_shm(1, 1) == NULL);
|
||||
assert(vkp_image_import_dmabuf(-1, 0, VKP_MOD_LINEAR, 1, 1, 4, 0, 0) == NULL);
|
||||
assert(vkp_dmabuf_modifiers(0, &mod, 1) == 0);
|
||||
assert(vkp_image_readback(&src, &pixel, 1) == -1);
|
||||
assert(vkp_pass_begin(64, 64, NULL, 0, NULL, NULL) == -1);
|
||||
int fd[2]; assert(pipe(fd) == 0);
|
||||
assert(vkp_blit_image(&src, &dst, fd[0]) == -1);
|
||||
errno = 0; assert(close(fd[0]) == -1 && errno == EBADF); close(fd[1]);
|
||||
g_pass.active = 1;
|
||||
assert(pipe(fd) == 0);
|
||||
assert(vkp_pass_copy_to(&dst, fd[0]) == -1 && !g_pass.active);
|
||||
errno = 0; assert(close(fd[0]) == -1 && errno == EBADF); close(fd[1]);
|
||||
g_pass.active = 1; vkp_pass_abort(); assert(!g_pass.active);
|
||||
assert(timed_wait(g_fence, UINT64_MAX) != VK_SUCCESS);
|
||||
assert(operations == before && destroys == before_destroys);
|
||||
}
|
||||
|
||||
static void acquire_failure(int later, VkResult result) {
|
||||
setup(later ? 1 : 0);
|
||||
fail_acquire_at = later ? 2 : 1; acquire_answer = result;
|
||||
idle_answer = VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
VkImage *retained = g_images;
|
||||
assert(vkp_render(64, 64, NULL, 0) == -1);
|
||||
assert(g_dev_state == -3 && vkp_completion_unknown() && !vkp_device_lost());
|
||||
assert(acquires == fail_acquire_at && idle_calls == 1);
|
||||
assert(submits == (unsigned)later && markers == 0 && waits == 0);
|
||||
assert(destroys == 0 && g_images == retained && g_nimg == 1);
|
||||
assert(g_swapchain && g_surface && g_fence && g_scene.img && g_scene.mem);
|
||||
assert_stopped();
|
||||
free(g_images); /* test-owned fake resources only */
|
||||
}
|
||||
|
||||
static void upload_timeout(int single_pixel) {
|
||||
setup(0);
|
||||
uint8_t bytes[48], saved[48], data[16];
|
||||
memset(bytes, 0xa5, sizeof(bytes)); memset(data, 0x3c, sizeof(data));
|
||||
struct vkp_image *img = calloc(1, sizeof(*img)); assert(img);
|
||||
*img = (struct vkp_image){.image = (VkImage)(uintptr_t)7, .mem = (VkDeviceMemory)(uintptr_t)8,
|
||||
.map = bytes, .offset = 3, .row_pitch = 16,
|
||||
.w = single_pixel ? 1 : 2, .h = single_pixel ? 1 : 2};
|
||||
struct surface s = {.shm_img = img};
|
||||
struct wl_shm_buffer b = {.w = img->w, .h = img->h, .stride = img->w * 4, .data = data};
|
||||
struct wl_resource resource = {0};
|
||||
expected_release = &resource;
|
||||
if (single_pixel) take_pixel(&s, data, &resource); else take_shm(&s, &b, &resource);
|
||||
assert(bytes[3] == 0x3c && bytes[0] == 0xa5 && releases == 1);
|
||||
memcpy(saved, bytes, sizeof(saved));
|
||||
struct vkp_image dst = {.image = (VkImage)(uintptr_t)9, .blit_dst = 1, .w = img->w, .h = img->h};
|
||||
fence_answer = VK_TIMEOUT;
|
||||
assert(vkp_blit_image(img, &dst, -1) == -1);
|
||||
assert(g_dev_state == -3 && submits == 1 && waits == 1);
|
||||
memset(data, 0x7e, sizeof(data));
|
||||
if (single_pixel) take_pixel(&s, data, &resource); else take_shm(&s, &b, &resource);
|
||||
assert(s.shm_img == img && memcmp(saved, bytes, sizeof(saved)) == 0 && releases == 2);
|
||||
struct wl_resource dmabuf = {.dmabuf = 1};
|
||||
expected_release = &dmabuf;
|
||||
assert(buffer_release_blocked(&dmabuf));
|
||||
send_buffer_release(&dmabuf);
|
||||
assert(releases == 2);
|
||||
vkp_image_destroy(img);
|
||||
assert(destroys == 0 && img->map == bytes && img->image && img->mem);
|
||||
assert_stopped();
|
||||
g_dev_state = 1;
|
||||
assert(!buffer_release_blocked(&dmabuf));
|
||||
send_buffer_release(&dmabuf);
|
||||
assert(releases == 3);
|
||||
free(img); free(g_images); /* fake resources only, not production cleanup */
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
assert(argc == 2);
|
||||
const char *name = argv[1];
|
||||
if (!strcmp(name, "first-out-of-date")) acquire_failure(0, VK_ERROR_OUT_OF_DATE_KHR);
|
||||
else if (!strcmp(name, "first-surface-lost")) acquire_failure(0, VK_ERROR_SURFACE_LOST_KHR);
|
||||
else if (!strcmp(name, "later-out-of-date")) acquire_failure(1, VK_ERROR_OUT_OF_DATE_KHR);
|
||||
else if (!strcmp(name, "later-surface-lost")) acquire_failure(1, VK_ERROR_SURFACE_LOST_KHR);
|
||||
else if (!strcmp(name, "shm-timeout")) upload_timeout(0);
|
||||
else if (!strcmp(name, "pixel-timeout")) upload_timeout(1);
|
||||
else if (!strcmp(name, "pass-terminal")) { setup(0); g_dev_state = -3; assert_stopped(); free(g_images); }
|
||||
else if (!strcmp(name, "normal") || !strcmp(name, "framegen")) {
|
||||
int extra = !strcmp(name, "framegen"); setup(extra);
|
||||
assert(vkp_render(64, 64, NULL, 0) == 0 && g_dev_state == 1);
|
||||
assert(acquires == (unsigned)(1 + extra) && submits == (unsigned)(1 + extra));
|
||||
assert(waits == 1 && markers == 0 && idle_calls == 0 && destroys == 0);
|
||||
assert(presented_notifications == (unsigned)extra); free(g_images);
|
||||
} else if (!strcmp(name, "later-timeout")) {
|
||||
setup(1); fail_acquire_at = 2; acquire_answer = VK_TIMEOUT;
|
||||
assert(vkp_render(64, 64, NULL, 0) == -1 && g_dev_state == 1);
|
||||
assert(acquires == 2 && submits == 2 && markers == 1 && waits == 1); free(g_images);
|
||||
} else if (!strcmp(name, "acquire-device-lost") || !strcmp(name, "present-device-lost")) {
|
||||
setup(1);
|
||||
if (!strcmp(name, "acquire-device-lost")) { fail_acquire_at = 2; acquire_answer = VK_ERROR_DEVICE_LOST; }
|
||||
else present_answer = VK_ERROR_DEVICE_LOST;
|
||||
assert(vkp_render(64, 64, NULL, 0) == -1 && vkp_device_lost());
|
||||
assert(!vkp_completion_unknown());
|
||||
assert(g_dev_state == -2 && lost_notifications == 1 && markers == 0 && waits == 0);
|
||||
assert(!g_images && !g_swapchain && !g_surface && destroys == 2);
|
||||
assert_stopped();
|
||||
} else assert(0 && "unknown scenario");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
/* The Xclipse layer between a simulated loader and a mock driver. The driver refuses what the compat
|
||||
* layer and Samsung's driver refuse: textureCompressionBC, and a compute layout holding an immutable
|
||||
* YCbCr sampler. Built by test_xclipse_layer.py with the layer source included directly. */
|
||||
#include "xclipse_layer.c"
|
||||
#include <assert.h>
|
||||
|
||||
struct object { void *dispatch; };
|
||||
static int instance_table, device_table[4];
|
||||
static struct object mock_instance = {&instance_table}, mock_physical = {&instance_table};
|
||||
static struct object mock_devices[4] = {{&device_table[0]}, {&device_table[1]}, {&device_table[2]}, {&device_table[3]}};
|
||||
static int devices_created;
|
||||
|
||||
/* What the driver last saw. */
|
||||
static int driver_saw_bc, driver_saw_layout_sampler_count;
|
||||
static VkSampler driver_layout_samplers[16];
|
||||
static uint64_t next_sampler = 0x100;
|
||||
static VkSampler driver_ycbcr[16];
|
||||
static int driver_ycbcr_count;
|
||||
|
||||
static VkResult VKAPI_CALL mock_create_instance(const VkInstanceCreateInfo *info, const VkAllocationCallbacks *allocator,
|
||||
VkInstance *instance) {
|
||||
*instance = (VkInstance)&mock_instance;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
static void VKAPI_CALL mock_features(VkPhysicalDevice physical, VkPhysicalDeviceFeatures *features) {
|
||||
memset(features, 0, sizeof(*features));
|
||||
}
|
||||
|
||||
static void VKAPI_CALL mock_features2(VkPhysicalDevice physical, VkPhysicalDeviceFeatures2 *features) {
|
||||
mock_features(physical, &features->features);
|
||||
}
|
||||
|
||||
/* The compat layer's emulation: BC formats sample, the feature bit stays off. */
|
||||
static void VKAPI_CALL mock_format_properties(VkPhysicalDevice physical, VkFormat format, VkFormatProperties *out) {
|
||||
memset(out, 0, sizeof(*out));
|
||||
if (format >= VK_FORMAT_BC1_RGB_UNORM_BLOCK && format <= VK_FORMAT_BC7_SRGB_BLOCK)
|
||||
out->optimalTilingFeatures = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT;
|
||||
}
|
||||
|
||||
static void VKAPI_CALL mock_format_properties2(VkPhysicalDevice physical, VkFormat format, VkFormatProperties2 *out) {
|
||||
mock_format_properties(physical, format, &out->formatProperties);
|
||||
}
|
||||
|
||||
static VkResult VKAPI_CALL mock_time_domains(VkPhysicalDevice physical, uint32_t *count, VkTimeDomainEXT *domains) {
|
||||
if (domains) { domains[0] = VK_TIME_DOMAIN_DEVICE_EXT; domains[1] = VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT; }
|
||||
*count = 2;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
static VkResult VKAPI_CALL mock_create_device(VkPhysicalDevice physical, const VkDeviceCreateInfo *info,
|
||||
const VkAllocationCallbacks *allocator, VkDevice *device) {
|
||||
driver_saw_bc = info->pEnabledFeatures && info->pEnabledFeatures->textureCompressionBC;
|
||||
for (const VkBaseInStructure *p = info->pNext; p; p = p->pNext)
|
||||
if (p->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2 &&
|
||||
((const VkPhysicalDeviceFeatures2 *)p)->features.textureCompressionBC) driver_saw_bc = 1;
|
||||
if (driver_saw_bc) return VK_ERROR_FEATURE_NOT_PRESENT;
|
||||
assert(devices_created < 4);
|
||||
*device = (VkDevice)&mock_devices[devices_created++];
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
static VkResult VKAPI_CALL mock_create_sampler(VkDevice device, const VkSamplerCreateInfo *info,
|
||||
const VkAllocationCallbacks *allocator, VkSampler *sampler) {
|
||||
*sampler = (VkSampler)next_sampler++;
|
||||
for (const VkBaseInStructure *p = info->pNext; p; p = p->pNext)
|
||||
if (p->sType == VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO) driver_ycbcr[driver_ycbcr_count++] = *sampler;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
static void VKAPI_CALL mock_destroy_sampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks *allocator) {
|
||||
for (int i = 0; i < driver_ycbcr_count; i++)
|
||||
if (driver_ycbcr[i] == sampler) driver_ycbcr[i] = driver_ycbcr[--driver_ycbcr_count];
|
||||
}
|
||||
|
||||
static VkResult VKAPI_CALL mock_create_set_layout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *info,
|
||||
const VkAllocationCallbacks *allocator, VkDescriptorSetLayout *layout) {
|
||||
driver_saw_layout_sampler_count = 0;
|
||||
for (uint32_t b = 0; b < info->bindingCount; b++) {
|
||||
const VkDescriptorSetLayoutBinding *binding = &info->pBindings[b];
|
||||
for (uint32_t s = 0; binding->pImmutableSamplers && s < binding->descriptorCount; s++) {
|
||||
VkSampler sampler = binding->pImmutableSamplers[s];
|
||||
driver_layout_samplers[driver_saw_layout_sampler_count++] = sampler;
|
||||
for (int i = 0; i < driver_ycbcr_count; i++)
|
||||
if ((binding->stageFlags & VK_SHADER_STAGE_COMPUTE_BIT) && driver_ycbcr[i] == sampler)
|
||||
return VK_ERROR_UNKNOWN;
|
||||
}
|
||||
}
|
||||
*layout = (VkDescriptorSetLayout)0x5000;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
static void VKAPI_CALL mock_destroy_device(VkDevice device, const VkAllocationCallbacks *allocator) {}
|
||||
|
||||
static VkResult VKAPI_CALL mock_timestamps(VkDevice device, uint32_t count, const VkCalibratedTimestampInfoEXT *infos,
|
||||
uint64_t *timestamps, uint64_t *deviation) {
|
||||
for (uint32_t i = 0; i < count; i++) timestamps[i] = 42;
|
||||
*deviation = 1;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
#define MOCK(name, function) if (!strcmp(requested, name)) return (PFN_vkVoidFunction)function
|
||||
static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL mock_gipa(VkInstance instance, const char *requested) {
|
||||
MOCK("vkCreateInstance", mock_create_instance);
|
||||
MOCK("vkCreateDevice", mock_create_device);
|
||||
MOCK("vkGetPhysicalDeviceFeatures", mock_features);
|
||||
MOCK("vkGetPhysicalDeviceFeatures2", mock_features2);
|
||||
MOCK("vkGetPhysicalDeviceFormatProperties", mock_format_properties);
|
||||
MOCK("vkGetPhysicalDeviceFormatProperties2", mock_format_properties2);
|
||||
MOCK("vkGetPhysicalDeviceCalibrateableTimeDomainsEXT", mock_time_domains);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL mock_gdpa(VkDevice device, const char *requested) {
|
||||
MOCK("vkCreateSampler", mock_create_sampler);
|
||||
MOCK("vkDestroySampler", mock_destroy_sampler);
|
||||
MOCK("vkCreateDescriptorSetLayout", mock_create_set_layout);
|
||||
MOCK("vkDestroyDevice", mock_destroy_device);
|
||||
MOCK("vkGetCalibratedTimestampsEXT", mock_timestamps);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* The loader's link for one vkCreateDevice call, then the caller's own chain. */
|
||||
static VkResult create(const void *chain, const VkPhysicalDeviceFeatures *enabled, VkDevice *device) {
|
||||
VkLayerDeviceLink link = {NULL, mock_gipa, mock_gdpa};
|
||||
VkLayerDeviceCreateInfo loader = {VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO, chain, VK_LAYER_LINK_INFO, {&link}};
|
||||
VkDeviceCreateInfo info = {VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, &loader, 0, 0, NULL, 0, NULL, 0, NULL, enabled};
|
||||
PFN_vkCreateDevice create_device = (PFN_vkCreateDevice)vkGetInstanceProcAddr((VkInstance)&mock_instance, "vkCreateDevice");
|
||||
return create_device((VkPhysicalDevice)&mock_physical, &info, NULL, device);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
VkNegotiateLayerInterface negotiate = {LAYER_NEGOTIATE_INTERFACE_STRUCT, NULL, 2, NULL, NULL, NULL};
|
||||
assert(vkNegotiateLoaderLayerInterfaceVersion(&negotiate) == VK_SUCCESS);
|
||||
|
||||
VkLayerInstanceLink instance_link = {NULL, mock_gipa, NULL};
|
||||
VkLayerInstanceCreateInfo instance_loader = {VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO, NULL, VK_LAYER_LINK_INFO,
|
||||
{&instance_link}};
|
||||
VkInstanceCreateInfo instance_info = {.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, .pNext = &instance_loader};
|
||||
VkInstance instance;
|
||||
PFN_vkCreateInstance create_instance_fn = (PFN_vkCreateInstance)vkGetInstanceProcAddr(NULL, "vkCreateInstance");
|
||||
assert(create_instance_fn(&instance_info, NULL, &instance) == VK_SUCCESS);
|
||||
|
||||
/* The emulated bit is reported... */
|
||||
VkPhysicalDeviceFeatures features;
|
||||
((PFN_vkGetPhysicalDeviceFeatures)vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceFeatures"))(
|
||||
(VkPhysicalDevice)&mock_physical, &features);
|
||||
assert(features.textureCompressionBC);
|
||||
|
||||
/* ...and cleared before the driver, through pEnabledFeatures... */
|
||||
VkDevice device;
|
||||
VkPhysicalDeviceFeatures legacy = {.textureCompressionBC = VK_TRUE};
|
||||
assert(create(NULL, &legacy, &device) == VK_SUCCESS && !driver_saw_bc && legacy.textureCompressionBC);
|
||||
|
||||
/* ...and through a VkPhysicalDeviceFeatures2 behind another structure, leaving the caller's chain intact. */
|
||||
VkPhysicalDeviceVulkan12Features vk12 = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES};
|
||||
VkPhysicalDeviceFeatures2 features2 = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &vk12,
|
||||
{.textureCompressionBC = VK_TRUE}};
|
||||
VkPhysicalDeviceTimelineSemaphoreFeatures timeline = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES,
|
||||
&features2, VK_TRUE};
|
||||
VkPhysicalDeviceFeatures2 features2_before = features2;
|
||||
VkPhysicalDeviceTimelineSemaphoreFeatures timeline_before = timeline;
|
||||
VkDevice chained;
|
||||
assert(create(&timeline, NULL, &chained) == VK_SUCCESS && !driver_saw_bc);
|
||||
assert(!memcmp(&features2, &features2_before, sizeof(features2)));
|
||||
assert(!memcmp(&timeline, &timeline_before, sizeof(timeline)));
|
||||
|
||||
/* A structure newer than the headers this was built with cannot be copied: the chain passes as it
|
||||
* is and the driver refuses the bit, without the caller's structures being written. */
|
||||
struct { VkStructureType sType; const void *pNext; uint32_t payload; } future = {(VkStructureType)0x7ffffff0, &features2, 7};
|
||||
VkDevice unused;
|
||||
assert(create(&future, NULL, &unused) == VK_ERROR_FEATURE_NOT_PRESENT);
|
||||
assert(!memcmp(&features2, &features2_before, sizeof(features2)) && future.pNext == &features2);
|
||||
|
||||
/* Compute layouts get a plain sampler in place of a YCbCr one. */
|
||||
PFN_vkCreateSampler create_sampler_fn = (PFN_vkCreateSampler)vkGetDeviceProcAddr(device, "vkCreateSampler");
|
||||
PFN_vkDestroySampler destroy_sampler_fn = (PFN_vkDestroySampler)vkGetDeviceProcAddr(device, "vkDestroySampler");
|
||||
PFN_vkCreateDescriptorSetLayout create_layout = (PFN_vkCreateDescriptorSetLayout)vkGetDeviceProcAddr(device, "vkCreateDescriptorSetLayout");
|
||||
VkSamplerYcbcrConversionInfo conversion = {VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO, NULL, (VkSamplerYcbcrConversion)1};
|
||||
VkSamplerCreateInfo ycbcr_info = {.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, .pNext = &conversion};
|
||||
VkSamplerCreateInfo plain_info = {.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO};
|
||||
VkSampler ycbcr;
|
||||
assert(create_sampler_fn(device, &ycbcr_info, NULL, &ycbcr) == VK_SUCCESS);
|
||||
VkSampler immutable[2] = {ycbcr, ycbcr};
|
||||
VkDescriptorSetLayoutBinding binding = {4, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2, VK_SHADER_STAGE_COMPUTE_BIT, immutable};
|
||||
VkDescriptorSetLayoutCreateInfo layout_info = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, NULL, 0, 1, &binding};
|
||||
VkDescriptorSetLayout layout;
|
||||
assert(create_layout(device, &layout_info, NULL, &layout) == VK_SUCCESS);
|
||||
assert(driver_layout_samplers[0] != ycbcr && immutable[0] == ycbcr);
|
||||
|
||||
/* A destroyed YCbCr sampler's handle, reused for a plain sampler, is left alone. */
|
||||
destroy_sampler_fn(device, ycbcr, NULL);
|
||||
next_sampler = (uint64_t)ycbcr;
|
||||
VkSampler reused;
|
||||
assert(create_sampler_fn(device, &plain_info, NULL, &reused) == VK_SUCCESS && reused == ycbcr);
|
||||
immutable[0] = immutable[1] = reused;
|
||||
assert(create_layout(device, &layout_info, NULL, &layout) == VK_SUCCESS && driver_layout_samplers[0] == reused);
|
||||
|
||||
/* Registrations belong to their device and go with it. */
|
||||
VkSampler other;
|
||||
assert(create_sampler_fn(chained, &ycbcr_info, NULL, &other) == VK_SUCCESS && ycbcr_count == 1);
|
||||
((PFN_vkDestroyDevice)vkGetDeviceProcAddr(chained, "vkDestroyDevice"))(chained, NULL);
|
||||
assert(ycbcr_count == 0);
|
||||
|
||||
/* The KHR calibrated-timestamp entry points reach the EXT ones. */
|
||||
uint32_t domains = 0;
|
||||
PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT time_domains = (PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT)
|
||||
vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceCalibrateableTimeDomainsKHR");
|
||||
assert(time_domains((VkPhysicalDevice)&mock_physical, &domains, NULL) == VK_SUCCESS && domains == 2);
|
||||
VkCalibratedTimestampInfoEXT stamp = {VK_STRUCTURE_TYPE_CALIBRATED_TIMESTAMP_INFO_EXT, NULL, VK_TIME_DOMAIN_DEVICE_EXT};
|
||||
uint64_t value = 0, deviation = 0;
|
||||
PFN_vkGetCalibratedTimestampsEXT timestamps = (PFN_vkGetCalibratedTimestampsEXT)vkGetDeviceProcAddr(device, "vkGetCalibratedTimestampsKHR");
|
||||
assert(timestamps(device, 1, &stamp, &value, &deviation) == VK_SUCCESS && value == 42);
|
||||
|
||||
puts("xclipse layer ok");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
# Function, source line and disassembly at offsets into an aarch64 library, with the NDK's tools.
|
||||
# Run in WSL: bash addr2line.sh <library> <offset>...
|
||||
# The offset is the crash pc minus the library's start in the process's maps (tools/venus/watch-maps.sh).
|
||||
LIB=${1:?library}
|
||||
shift
|
||||
B=/home/delo/android-sdk/ndk/27.3.13750724/toolchains/llvm/prebuilt/linux-x86_64/bin
|
||||
md5sum "$LIB"
|
||||
$B/llvm-addr2line -f -C -i -e "$LIB" "$@"
|
||||
for a in "$@"; do
|
||||
start=$(printf "0x%x" $((a - 48)))
|
||||
stop=$(printf "0x%x" $((a + 16)))
|
||||
$B/llvm-objdump -d --no-show-raw-insn --start-address=$start --stop-address=$stop "$LIB" | tail -n +7
|
||||
done
|
||||
Executable
+146
@@ -0,0 +1,146 @@
|
||||
#!/bin/bash
|
||||
# Builds the Mali (Venus) component in CI, from David Cimo's tools/venus recipes (build-venus-icd.sh,
|
||||
# build-virgl-android.sh, build-layer.sh), into venus.tzst rooted at app/src/main:
|
||||
# jniLibs/arm64-v8a/ libvirgl_test_server.so, libvirgl_render_server.so, libvirglrenderer.so,
|
||||
# libepoxy.so (bionic: the vtest server the app runs over the phone's Vulkan)
|
||||
# assets/venus/ libvulkan_virtio.so (glibc: Mesa's Venus ICD for the session)
|
||||
# assets/linuxfs/usr/local/... the Mali compatibility layer and its manifest
|
||||
# Needs: docker (Debian trixie for the glibc parts), the NDK in $ANDROID_NDK_HOME, meson, ninja.
|
||||
set -euo pipefail
|
||||
REPO=$(cd "$(dirname "$0")/../.." && pwd)
|
||||
W=${WORK:-$PWD/venus-work}
|
||||
OUT=$W/out
|
||||
rm -rf "$OUT" && mkdir -p "$OUT/jniLibs/arm64-v8a" "$OUT/assets/venus" \
|
||||
"$OUT/assets/linuxfs/usr/local/lib/droiddeck-mali" "$OUT/assets/linuxfs/usr/local/share/vulkan/implicit_layer.d"
|
||||
|
||||
# --- Linux side: Mesa 26.2.5's Venus ICD and the Mali compatibility layer (aarch64 glibc) ---
|
||||
docker run --rm --platform linux/amd64 -v "$W":/w -v "$REPO/tools/venus":/venus:ro -w /tmp debian:trixie bash -c '
|
||||
set -euo pipefail
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
dpkg --add-architecture arm64
|
||||
apt-get update -qq
|
||||
apt-get install -y -qq --no-install-recommends git ca-certificates curl crossbuild-essential-arm64 meson ninja-build \
|
||||
pkg-config python3-mako python3-yaml python3-packaging bison flex glslang-tools libwayland-bin wayland-protocols \
|
||||
libdrm-dev:arm64 libwayland-dev:arm64 libx11-dev:arm64 libx11-xcb-dev:arm64 libxcb1-dev:arm64 \
|
||||
libxcb-dri3-dev:arm64 libxcb-present-dev:arm64 libxcb-randr0-dev:arm64 libxcb-shm0-dev:arm64 \
|
||||
libxcb-sync-dev:arm64 libxcb-xfixes0-dev:arm64 libxshmfence-dev:arm64 libxrandr-dev:arm64 \
|
||||
libexpat1-dev:arm64 zlib1g-dev:arm64 libzstd-dev:arm64 >/dev/null
|
||||
cat > /tmp/arm64.ini <<EOC
|
||||
[binaries]
|
||||
c = '"'"'aarch64-linux-gnu-gcc'"'"'
|
||||
cpp = '"'"'aarch64-linux-gnu-g++'"'"'
|
||||
ar = '"'"'aarch64-linux-gnu-ar'"'"'
|
||||
strip = '"'"'aarch64-linux-gnu-strip'"'"'
|
||||
nm = '"'"'aarch64-linux-gnu-nm'"'"'
|
||||
pkg-config = '"'"'pkg-config'"'"'
|
||||
[properties]
|
||||
pkg_config_libdir = ['"'"'/usr/lib/aarch64-linux-gnu/pkgconfig'"'"', '"'"'/usr/share/pkgconfig'"'"']
|
||||
[host_machine]
|
||||
system = '"'"'linux'"'"'
|
||||
cpu_family = '"'"'aarch64'"'"'
|
||||
cpu = '"'"'armv8-a'"'"'
|
||||
endian = '"'"'little'"'"'
|
||||
EOC
|
||||
git clone -q --depth 1 -b mesa-26.2.5 https://gitlab.freedesktop.org/mesa/mesa.git
|
||||
(cd mesa && git apply /venus/mesa-venus-vtest.patch)
|
||||
meson setup venus-build mesa --cross-file /tmp/arm64.ini --prefix=/usr --libdir=lib \
|
||||
--buildtype=release -Db_ndebug=true \
|
||||
-Dvulkan-drivers=virtio -Dgallium-drivers= -Dplatforms=x11,wayland \
|
||||
-Dllvm=disabled -Dglx=disabled -Degl=disabled -Dgbm=disabled -Dopengl=false -Dgles1=disabled -Dgles2=disabled \
|
||||
-Dvideo-codecs= -Dvulkan-layers= -Dtools= -Dbuild-tests=false -Dvalgrind=disabled -Dlibunwind=disabled \
|
||||
-Dzstd=enabled -Dshared-glapi=disabled >/dev/null
|
||||
ninja -C venus-build src/virtio/vulkan/libvulkan_virtio.so
|
||||
aarch64-linux-gnu-strip --strip-unneeded -o /w/out/assets/venus/libvulkan_virtio.so venus-build/src/virtio/vulkan/libvulkan_virtio.so
|
||||
echo "venus icd min glibc: $(aarch64-linux-gnu-objdump -T /w/out/assets/venus/libvulkan_virtio.so | grep -o "GLIBC_[0-9.]*" | sort -Vu | tail -1)"
|
||||
SDK=vulkan-sdk-1.4.357.0
|
||||
git -c advice.detachedHead=false clone -q --depth 1 -b $SDK https://github.com/KhronosGroup/Vulkan-Headers.git /tmp/vulkan
|
||||
git -c advice.detachedHead=false clone -q --depth 1 -b $SDK https://github.com/KhronosGroup/SPIRV-Headers.git /tmp/spirv
|
||||
mkdir -p /tmp/bcdec
|
||||
curl -sSfL -o /tmp/bcdec/bcdec.h https://raw.githubusercontent.com/iOrange/bcdec/80859ed3b7afb1c527a2a99d70c61457bea72d0c/bcdec.h
|
||||
L=/w/out/assets/linuxfs/usr/local
|
||||
aarch64-linux-gnu-gcc -shared -fPIC -O2 -Wall -Wextra -Wno-unused-parameter -fvisibility=hidden -pthread \
|
||||
-I/tmp/vulkan/include -I/tmp/spirv/include -I/tmp/bcdec \
|
||||
-o $L/lib/droiddeck-mali/libVkLayer_droiddeck_mali_compat.so /venus/layer/*.c
|
||||
aarch64-linux-gnu-strip --strip-unneeded $L/lib/droiddeck-mali/libVkLayer_droiddeck_mali_compat.so
|
||||
cp /venus/layer/VkLayer_droiddeck_mali_compat.json $L/share/vulkan/implicit_layer.d/
|
||||
chmod -R a+rwX /w/out
|
||||
'
|
||||
|
||||
# --- Android side: libepoxy + virglrenderer 1.3.0 (venus, vtest) for arm64 with the NDK ---
|
||||
NDK=${ANDROID_NDK_HOME:?}
|
||||
TC=$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin
|
||||
API=29
|
||||
A=$W/android
|
||||
AOUT=$A/out
|
||||
mkdir -p "$A/cross" "$A/compat/log" "$A/compat/cutils" "$AOUT/lib/pkgconfig"
|
||||
cd "$A"
|
||||
git clone -q --depth 1 -b 1.5.10 https://github.com/anholt/libepoxy.git
|
||||
git clone -q --depth 1 -b v1.4.365 https://github.com/KhronosGroup/Vulkan-Headers.git
|
||||
git clone -q --depth 1 -b virglrenderer-1.3.0 https://gitlab.freedesktop.org/virgl/virglrenderer.git
|
||||
git -C virglrenderer apply "$REPO/tools/venus/virglrenderer-android.patch"
|
||||
git -C virglrenderer apply "$REPO/tools/venus/virglrenderer-destroy-unknown-pipeline.patch"
|
||||
git -C virglrenderer apply "$REPO/tools/venus/virglrenderer-destroy-mutex-after-objects.patch"
|
||||
cat > compat/log/log.h <<'EOC'
|
||||
#pragma once
|
||||
#include <android/log.h>
|
||||
#define LOG_PRI(prio, tag, ...) __android_log_print(prio, tag, __VA_ARGS__)
|
||||
EOC
|
||||
cat > compat/cutils/properties.h <<'EOC'
|
||||
#pragma once
|
||||
#include <string.h>
|
||||
#include <sys/system_properties.h>
|
||||
#define PROPERTY_VALUE_MAX PROP_VALUE_MAX
|
||||
#define PROPERTY_KEY_MAX 32
|
||||
static inline int property_get(const char *key, char *value, const char *def)
|
||||
{
|
||||
int len = __system_property_get(key, value);
|
||||
if (len <= 0 && def) { strcpy(value, def); len = (int)strlen(def); }
|
||||
return len;
|
||||
}
|
||||
EOC
|
||||
cat > "$AOUT/lib/pkgconfig/vulkan.pc" <<EOC
|
||||
prefix=$A/Vulkan-Headers
|
||||
includedir=\${prefix}/include
|
||||
Name: vulkan
|
||||
Description: Vulkan headers
|
||||
Version: 1.4.365
|
||||
Cflags: -I\${includedir}
|
||||
Libs: -lvulkan
|
||||
EOC
|
||||
cat > cross/android.ini <<EOC
|
||||
[binaries]
|
||||
c = '$TC/aarch64-linux-android$API-clang'
|
||||
cpp = '$TC/aarch64-linux-android$API-clang++'
|
||||
ar = '$TC/llvm-ar'
|
||||
strip = '$TC/llvm-strip'
|
||||
pkg-config = '/usr/bin/pkg-config'
|
||||
[built-in options]
|
||||
c_args = ['-I$A/Vulkan-Headers/include', '-I$A/compat']
|
||||
c_link_args = ['-llog', '-lnativewindow', '-Wl,-rpath=\$ORIGIN', '-Wl,-z,max-page-size=16384']
|
||||
cpp_link_args = ['-Wl,-rpath=\$ORIGIN', '-Wl,-z,max-page-size=16384']
|
||||
[properties]
|
||||
pkg_config_libdir = '$AOUT/lib/pkgconfig'
|
||||
[host_machine]
|
||||
system = 'android'
|
||||
cpu_family = 'aarch64'
|
||||
cpu = 'armv8'
|
||||
endian = 'little'
|
||||
EOC
|
||||
export PKG_CONFIG_LIBDIR=$AOUT/lib/pkgconfig PKG_CONFIG_PATH=
|
||||
meson setup epoxy-build libepoxy --cross-file cross/android.ini --prefix="$AOUT" --libdir=lib \
|
||||
--buildtype=release -Degl=yes -Dglx=no -Dx11=false -Dtests=false >/dev/null
|
||||
ninja -C epoxy-build install >/dev/null
|
||||
meson setup virgl-build virglrenderer --cross-file cross/android.ini --prefix="$AOUT" --libdir=lib \
|
||||
--buildtype=release -Dvenus=true -Dplatforms=auto -Drender-server-worker=thread \
|
||||
-Dvulkan-dload=true -Dcheck-gl-errors=false -Dtests=false >/dev/null
|
||||
ninja -C virgl-build install >/dev/null
|
||||
J=$OUT/jniLibs/arm64-v8a
|
||||
cp "$AOUT/bin/virgl_test_server" "$J/libvirgl_test_server.so"
|
||||
cp "$AOUT/libexec/virgl_render_server" "$J/libvirgl_render_server.so"
|
||||
cp "$AOUT/lib/libvirglrenderer.so" "$AOUT/lib/libepoxy.so" "$J/"
|
||||
for f in "$J"/*.so; do "$TC/llvm-strip" --strip-unneeded "$f"; done
|
||||
|
||||
cd "$OUT"
|
||||
find . -type f | sort
|
||||
tar --owner=0 --group=0 --numeric-owner --sort=name -cf - . | zstd -19 -T0 -q -o "$W/venus.tzst"
|
||||
sha256sum "$W/venus.tzst" | tee "$W/venus.tzst.sha256"
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* droiddeck-glprobe: does OpenGL through GLX start on this session's display, the way the Steam
|
||||
* client's first window asks for it (glXChooseVisual, then a context)? Run once before the client
|
||||
* on the Mali (Venus) route, where Zink failed on a Mali-G615 with nothing but "failed to load
|
||||
* driver: zink" and the client gave up ("UpdateUI GL not available"). Exit 0 when a visual and a
|
||||
* context come back, 1 when GL does not start, 2 when there is no X display or no libGL.
|
||||
* libX11 and libGL are opened at run time, so this builds without their headers.
|
||||
*/
|
||||
#include <dlfcn.h>
|
||||
#include <stdio.h>
|
||||
|
||||
typedef void *(*open_display_fn)(const char *);
|
||||
typedef int (*close_display_fn)(void *);
|
||||
typedef int (*default_screen_fn)(void *);
|
||||
typedef void *(*choose_visual_fn)(void *, int, int *);
|
||||
typedef void *(*create_context_fn)(void *, void *, void *, int);
|
||||
typedef void (*destroy_context_fn)(void *, void *);
|
||||
typedef int (*free_fn)(void *);
|
||||
|
||||
#define GLX_RGBA 4
|
||||
#define GLX_DOUBLEBUFFER 5
|
||||
#define GLX_RED_SIZE 8
|
||||
#define GLX_GREEN_SIZE 9
|
||||
#define GLX_BLUE_SIZE 10
|
||||
|
||||
int main(void)
|
||||
{
|
||||
void *x11 = dlopen("libX11.so.6", RTLD_NOW | RTLD_GLOBAL);
|
||||
void *gl = dlopen("libGL.so.1", RTLD_NOW | RTLD_GLOBAL);
|
||||
if (!x11 || !gl) {
|
||||
printf("glprobe: cannot open %s: %s\n", x11 ? "libGL.so.1" : "libX11.so.6", dlerror());
|
||||
return 2;
|
||||
}
|
||||
open_display_fn open_display = (open_display_fn)dlsym(x11, "XOpenDisplay");
|
||||
close_display_fn close_display = (close_display_fn)dlsym(x11, "XCloseDisplay");
|
||||
default_screen_fn default_screen = (default_screen_fn)dlsym(x11, "XDefaultScreen");
|
||||
free_fn x_free = (free_fn)dlsym(x11, "XFree");
|
||||
choose_visual_fn choose_visual = (choose_visual_fn)dlsym(gl, "glXChooseVisual");
|
||||
create_context_fn create_context = (create_context_fn)dlsym(gl, "glXCreateContext");
|
||||
destroy_context_fn destroy_context = (destroy_context_fn)dlsym(gl, "glXDestroyContext");
|
||||
if (!open_display || !close_display || !default_screen || !x_free || !choose_visual || !create_context ||
|
||||
!destroy_context) {
|
||||
printf("glprobe: missing X11/GLX entry points\n");
|
||||
return 2;
|
||||
}
|
||||
void *dpy = open_display(NULL);
|
||||
if (!dpy) {
|
||||
printf("glprobe: no X display\n");
|
||||
return 2;
|
||||
}
|
||||
int attrs[] = {GLX_RGBA, GLX_DOUBLEBUFFER, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, 0};
|
||||
void *visual = choose_visual(dpy, default_screen(dpy), attrs);
|
||||
if (!visual) {
|
||||
printf("glprobe: FAIL glXChooseVisual\n");
|
||||
close_display(dpy);
|
||||
return 1;
|
||||
}
|
||||
void *ctx = create_context(dpy, visual, NULL, 1);
|
||||
x_free(visual);
|
||||
if (!ctx) {
|
||||
printf("glprobe: FAIL glXCreateContext\n");
|
||||
close_display(dpy);
|
||||
return 1;
|
||||
}
|
||||
destroy_context(dpy, ctx);
|
||||
close_display(dpy);
|
||||
printf("glprobe: OK (visual and context)\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
# vulkaninfo as the session's Linux processes see the GPU: through Venus, and through the Mali
|
||||
# compatibility layer when DROIDDECK_MALI_COMPAT is 1. Needs a running session (the vtest server).
|
||||
# Run from Git Bash: MSYS_NO_PATHCONV=1 bash tools/venus/guest-vulkaninfo.sh [0|1] > vulkaninfo.txt
|
||||
set -euo pipefail
|
||||
COMPAT=${1:-1}
|
||||
A=/c/Users/derab/tools/platform-tools/adb.exe
|
||||
PKG=com.droiddeck.launcher
|
||||
F=/data/user/0/$PKG/files
|
||||
APK=$($A shell pm path $PKG | head -1 | tr -d '\r' | sed 's/^package://')
|
||||
L=${APK%/base.apk}/lib/arm64
|
||||
$A exec-out "run-as $PKG sh -c 'PROOT_TMP_DIR=/data/user/0/$PKG/cache PROOT_LOADER=$L/libproot-loader.so \
|
||||
$L/libproot.so -r $F/linuxfs -w /root -b /dev -b /proc -b /sys -b $F /usr/bin/env -i HOME=/root \
|
||||
PATH=/usr/bin:/bin DROIDDECK_MALI_COMPAT=$COMPAT VK_ICD_FILENAMES=$F/venus/virtio_icd.json VN_DEBUG=vtest \
|
||||
VTEST_SOCKET_NAME=$F/venus/vtest.sock vulkaninfo 2>&1'"
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"file_format_version": "1.2.0",
|
||||
"layer": {
|
||||
"name": "VK_LAYER_DROIDDECK_mali_compat",
|
||||
"type": "GLOBAL",
|
||||
"library_path": "/usr/local/lib/droiddeck-mali/libVkLayer_droiddeck_mali_compat.so",
|
||||
"api_version": "1.4.357",
|
||||
"implementation_version": "1",
|
||||
"description": "Features DXVK requires and Mali lacks, made up for",
|
||||
"functions": {
|
||||
"vkNegotiateLoaderLayerInterfaceVersion": "vkNegotiateLoaderLayerInterfaceVersion"
|
||||
},
|
||||
"disable_environment": {
|
||||
"DROIDDECK_MALI_COMPAT_DISABLE": "1"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,869 @@
|
||||
/*
|
||||
* BC1-BC7 textures on a GPU without them: each BC image is created in an uncompressed format, and
|
||||
* every upload into one is decoded on the CPU while the copy is recorded. The decoded texels go
|
||||
* through a staging buffer of the layer's own, which lives until the command buffer is reset.
|
||||
* Uploads must come from memory the application has mapped, as DXVK's staging memory always is.
|
||||
*/
|
||||
#include "mali_compat.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define BCDEC_IMPLEMENTATION
|
||||
#define BCDEC_STATIC
|
||||
#define BCDEC_BC4BC5_PRECISE
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#include "bcdec.h"
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#define HANDLE(h) ((uint64_t)(uintptr_t)(h))
|
||||
#define STAGING_BLOCK_SIZE (16u << 20)
|
||||
#define STAGING_KEPT (64u << 20)
|
||||
|
||||
enum bc_kind { BC1, BC2, BC3, BC4, BC5, BC6H, BC7 };
|
||||
|
||||
struct bc_format {
|
||||
VkFormat format;
|
||||
VkFormat substitute;
|
||||
enum bc_kind kind;
|
||||
uint32_t block_bytes;
|
||||
uint32_t texel_bytes;
|
||||
bool is_signed;
|
||||
/* BC1's RGB formats have no alpha; its 1-bit transparency must read as opaque. */
|
||||
bool opaque;
|
||||
};
|
||||
|
||||
static const struct bc_format bc_formats[] = {
|
||||
{VK_FORMAT_BC1_RGB_UNORM_BLOCK, VK_FORMAT_R8G8B8A8_UNORM, BC1, 8, 4, false, true},
|
||||
{VK_FORMAT_BC1_RGB_SRGB_BLOCK, VK_FORMAT_R8G8B8A8_SRGB, BC1, 8, 4, false, true},
|
||||
{VK_FORMAT_BC1_RGBA_UNORM_BLOCK, VK_FORMAT_R8G8B8A8_UNORM, BC1, 8, 4, false, false},
|
||||
{VK_FORMAT_BC1_RGBA_SRGB_BLOCK, VK_FORMAT_R8G8B8A8_SRGB, BC1, 8, 4, false, false},
|
||||
{VK_FORMAT_BC2_UNORM_BLOCK, VK_FORMAT_R8G8B8A8_UNORM, BC2, 16, 4, false, false},
|
||||
{VK_FORMAT_BC2_SRGB_BLOCK, VK_FORMAT_R8G8B8A8_SRGB, BC2, 16, 4, false, false},
|
||||
{VK_FORMAT_BC3_UNORM_BLOCK, VK_FORMAT_R8G8B8A8_UNORM, BC3, 16, 4, false, false},
|
||||
{VK_FORMAT_BC3_SRGB_BLOCK, VK_FORMAT_R8G8B8A8_SRGB, BC3, 16, 4, false, false},
|
||||
{VK_FORMAT_BC4_UNORM_BLOCK, VK_FORMAT_R8_UNORM, BC4, 8, 1, false, false},
|
||||
{VK_FORMAT_BC4_SNORM_BLOCK, VK_FORMAT_R8_SNORM, BC4, 8, 1, true, false},
|
||||
{VK_FORMAT_BC5_UNORM_BLOCK, VK_FORMAT_R8G8_UNORM, BC5, 16, 2, false, false},
|
||||
{VK_FORMAT_BC5_SNORM_BLOCK, VK_FORMAT_R8G8_SNORM, BC5, 16, 2, true, false},
|
||||
{VK_FORMAT_BC6H_UFLOAT_BLOCK, VK_FORMAT_R16G16B16A16_SFLOAT, BC6H, 16, 8, false, false},
|
||||
{VK_FORMAT_BC6H_SFLOAT_BLOCK, VK_FORMAT_R16G16B16A16_SFLOAT, BC6H, 16, 8, true, false},
|
||||
{VK_FORMAT_BC7_UNORM_BLOCK, VK_FORMAT_R8G8B8A8_UNORM, BC7, 16, 4, false, false},
|
||||
{VK_FORMAT_BC7_SRGB_BLOCK, VK_FORMAT_R8G8B8A8_SRGB, BC7, 16, 4, false, false},
|
||||
};
|
||||
|
||||
static const struct bc_format *find_bc(VkFormat format)
|
||||
{
|
||||
for (size_t i = 0; i < sizeof(bc_formats) / sizeof(bc_formats[0]); i++) {
|
||||
if (bc_formats[i].format == format)
|
||||
return &bc_formats[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
VkFormat bc_substitute(VkFormat format)
|
||||
{
|
||||
const struct bc_format *bc = find_bc(format);
|
||||
return bc ? bc->substitute : VK_FORMAT_UNDEFINED;
|
||||
}
|
||||
|
||||
/* What a real BC format allows: sampling and copies. */
|
||||
#define BC_FEATURES \
|
||||
(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT | \
|
||||
VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT | VK_FORMAT_FEATURE_TRANSFER_SRC_BIT | \
|
||||
VK_FORMAT_FEATURE_TRANSFER_DST_BIT | VK_FORMAT_FEATURE_BLIT_SRC_BIT)
|
||||
#define BC_USAGE (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT)
|
||||
|
||||
static const struct bc_format *physical_bc(VkPhysicalDevice physical_device, VkFormat format, struct instance **inst)
|
||||
{
|
||||
*inst = instance_from_handle(physical_device);
|
||||
if (!(physical_device_gaps(*inst, physical_device) & GAP_BC))
|
||||
return NULL;
|
||||
return find_bc(format);
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceFormatProperties(VkPhysicalDevice physical_device, VkFormat format,
|
||||
VkFormatProperties *properties)
|
||||
{
|
||||
struct instance *inst;
|
||||
const struct bc_format *bc = physical_bc(physical_device, format, &inst);
|
||||
inst->GetPhysicalDeviceFormatProperties(physical_device, bc ? bc->substitute : format, properties);
|
||||
if (bc) {
|
||||
properties->optimalTilingFeatures &= BC_FEATURES;
|
||||
properties->linearTilingFeatures = 0;
|
||||
properties->bufferFeatures = 0;
|
||||
}
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceFormatProperties2(VkPhysicalDevice physical_device, VkFormat format,
|
||||
VkFormatProperties2 *properties)
|
||||
{
|
||||
struct instance *inst;
|
||||
const struct bc_format *bc = physical_bc(physical_device, format, &inst);
|
||||
inst->GetPhysicalDeviceFormatProperties2(physical_device, bc ? bc->substitute : format, properties);
|
||||
if (!bc)
|
||||
return;
|
||||
properties->formatProperties.optimalTilingFeatures &= BC_FEATURES;
|
||||
properties->formatProperties.linearTilingFeatures = 0;
|
||||
properties->formatProperties.bufferFeatures = 0;
|
||||
for (VkBaseOutStructure *s = properties->pNext; s; s = s->pNext) {
|
||||
if (s->sType == VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_3) {
|
||||
VkFormatProperties3 *p3 = (VkFormatProperties3 *)s;
|
||||
p3->optimalTilingFeatures &= (VkFormatFeatureFlags2)BC_FEATURES;
|
||||
p3->linearTilingFeatures = 0;
|
||||
p3->bufferFeatures = 0;
|
||||
} else if (s->sType == VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT) {
|
||||
((VkDrmFormatModifierPropertiesListEXT *)s)->drmFormatModifierCount = 0;
|
||||
} else if (s->sType == VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_2_EXT) {
|
||||
((VkDrmFormatModifierPropertiesList2EXT *)s)->drmFormatModifierCount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceImageFormatProperties(
|
||||
VkPhysicalDevice physical_device, VkFormat format, VkImageType type, VkImageTiling tiling,
|
||||
VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties *properties)
|
||||
{
|
||||
struct instance *inst;
|
||||
const struct bc_format *bc = physical_bc(physical_device, format, &inst);
|
||||
if (!bc)
|
||||
return inst->GetPhysicalDeviceImageFormatProperties(physical_device, format, type, tiling, usage, flags,
|
||||
properties);
|
||||
if (tiling != VK_IMAGE_TILING_OPTIMAL || (usage & ~BC_USAGE))
|
||||
return VK_ERROR_FORMAT_NOT_SUPPORTED;
|
||||
return inst->GetPhysicalDeviceImageFormatProperties(physical_device, bc->substitute, type, tiling, usage,
|
||||
flags & ~VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT,
|
||||
properties);
|
||||
}
|
||||
|
||||
/* A view format list naming BC formats, as one naming their substitutes. */
|
||||
struct format_list {
|
||||
VkImageFormatListCreateInfo *list;
|
||||
const VkFormat *original;
|
||||
VkFormat formats[16];
|
||||
};
|
||||
|
||||
static void substitute_format_list(const void *chain, VkFormat substitute, struct format_list *saved)
|
||||
{
|
||||
saved->list = NULL;
|
||||
for (const VkBaseInStructure *s = chain; s; s = s->pNext) {
|
||||
if (s->sType != VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO)
|
||||
continue;
|
||||
VkImageFormatListCreateInfo *list = (VkImageFormatListCreateInfo *)s;
|
||||
uint32_t count = 0;
|
||||
saved->formats[count++] = substitute;
|
||||
for (uint32_t i = 0; i < list->viewFormatCount && count < 16; i++) {
|
||||
VkFormat format = bc_substitute(list->pViewFormats[i]);
|
||||
/* Uncompressed views of the compressed blocks have nothing to alias any more. */
|
||||
if (format == VK_FORMAT_UNDEFINED)
|
||||
continue;
|
||||
bool seen = false;
|
||||
for (uint32_t k = 0; k < count; k++)
|
||||
seen |= saved->formats[k] == format;
|
||||
if (!seen)
|
||||
saved->formats[count++] = format;
|
||||
}
|
||||
saved->list = list;
|
||||
saved->original = list->pViewFormats;
|
||||
list->pViewFormats = saved->formats;
|
||||
list->viewFormatCount = count;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void restore_format_list(struct format_list *saved, uint32_t original_count)
|
||||
{
|
||||
if (saved->list) {
|
||||
saved->list->pViewFormats = saved->original;
|
||||
saved->list->viewFormatCount = original_count;
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t format_list_count(const void *chain)
|
||||
{
|
||||
for (const VkBaseInStructure *s = chain; s; s = s->pNext) {
|
||||
if (s->sType == VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO)
|
||||
return ((const VkImageFormatListCreateInfo *)s)->viewFormatCount;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceImageFormatProperties2(
|
||||
VkPhysicalDevice physical_device, const VkPhysicalDeviceImageFormatInfo2 *info,
|
||||
VkImageFormatProperties2 *properties)
|
||||
{
|
||||
struct instance *inst;
|
||||
const struct bc_format *bc = physical_bc(physical_device, info->format, &inst);
|
||||
if (!bc)
|
||||
return inst->GetPhysicalDeviceImageFormatProperties2(physical_device, info, properties);
|
||||
if (info->tiling != VK_IMAGE_TILING_OPTIMAL || (info->usage & ~BC_USAGE))
|
||||
return VK_ERROR_FORMAT_NOT_SUPPORTED;
|
||||
VkPhysicalDeviceImageFormatInfo2 copy = *info;
|
||||
copy.format = bc->substitute;
|
||||
copy.flags &= ~VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT;
|
||||
uint32_t list_count = format_list_count(info->pNext);
|
||||
struct format_list saved;
|
||||
substitute_format_list(info->pNext, bc->substitute, &saved);
|
||||
VkResult result = inst->GetPhysicalDeviceImageFormatProperties2(physical_device, ©, properties);
|
||||
restore_format_list(&saved, list_count);
|
||||
return result;
|
||||
}
|
||||
|
||||
struct bc_image {
|
||||
const struct bc_format *format;
|
||||
uint32_t array_layers;
|
||||
};
|
||||
|
||||
static void substitute_image_info(const struct bc_format *bc, VkImageCreateInfo *info)
|
||||
{
|
||||
info->format = bc->substitute;
|
||||
info->flags &= ~VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT;
|
||||
info->usage &= BC_USAGE;
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL CreateImage(VkDevice device, const VkImageCreateInfo *info,
|
||||
const VkAllocationCallbacks *allocator, VkImage *image)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
const struct bc_format *bc = find_bc(info->format);
|
||||
if (!bc)
|
||||
return dev->CreateImage(device, info, allocator, image);
|
||||
|
||||
VkImageCreateInfo copy = *info;
|
||||
substitute_image_info(bc, ©);
|
||||
uint32_t list_count = format_list_count(info->pNext);
|
||||
struct format_list saved;
|
||||
substitute_format_list(info->pNext, bc->substitute, &saved);
|
||||
VkResult result = dev->CreateImage(device, ©, allocator, image);
|
||||
restore_format_list(&saved, list_count);
|
||||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
|
||||
struct bc_image *tracked = malloc(sizeof(*tracked));
|
||||
tracked->format = bc;
|
||||
tracked->array_layers = info->arrayLayers;
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
map_put(&dev->images, HANDLE(*image), tracked);
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL DestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *allocator)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
free(map_remove(&dev->images, HANDLE(image)));
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
dev->DestroyImage(device, image, allocator);
|
||||
}
|
||||
|
||||
static const struct bc_image *tracked_image(struct device *dev, VkImage image)
|
||||
{
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
const struct bc_image *tracked = map_get(&dev->images, HANDLE(image));
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
return tracked;
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL CreateImageView(VkDevice device, const VkImageViewCreateInfo *info,
|
||||
const VkAllocationCallbacks *allocator, VkImageView *view)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
const struct bc_image *tracked = tracked_image(dev, info->image);
|
||||
if (!tracked)
|
||||
return dev->CreateImageView(device, info, allocator, view);
|
||||
VkImageViewCreateInfo copy = *info;
|
||||
VkFormat format = bc_substitute(info->format);
|
||||
copy.format = format != VK_FORMAT_UNDEFINED ? format : tracked->format->substitute;
|
||||
return dev->CreateImageView(device, ©, allocator, view);
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL GetDeviceImageMemoryRequirements(VkDevice device,
|
||||
const VkDeviceImageMemoryRequirements *info,
|
||||
VkMemoryRequirements2 *requirements)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
const struct bc_format *bc = find_bc(info->pCreateInfo->format);
|
||||
if (!bc) {
|
||||
dev->GetDeviceImageMemoryRequirements(device, info, requirements);
|
||||
return;
|
||||
}
|
||||
VkImageCreateInfo image = *info->pCreateInfo;
|
||||
substitute_image_info(bc, &image);
|
||||
VkDeviceImageMemoryRequirements copy = *info;
|
||||
copy.pCreateInfo = ℑ
|
||||
dev->GetDeviceImageMemoryRequirements(device, ©, requirements);
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL GetDeviceImageSparseMemoryRequirements(
|
||||
VkDevice device, const VkDeviceImageMemoryRequirements *info, uint32_t *count,
|
||||
VkSparseImageMemoryRequirements2 *requirements)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
const struct bc_format *bc = find_bc(info->pCreateInfo->format);
|
||||
if (!bc) {
|
||||
dev->GetDeviceImageSparseMemoryRequirements(device, info, count, requirements);
|
||||
return;
|
||||
}
|
||||
VkImageCreateInfo image = *info->pCreateInfo;
|
||||
substitute_image_info(bc, &image);
|
||||
VkDeviceImageMemoryRequirements copy = *info;
|
||||
copy.pCreateInfo = ℑ
|
||||
dev->GetDeviceImageSparseMemoryRequirements(device, ©, count, requirements);
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL GetDeviceImageSubresourceLayout(VkDevice device,
|
||||
const VkDeviceImageSubresourceInfo *info,
|
||||
VkSubresourceLayout2 *layout)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
const struct bc_format *bc = find_bc(info->pCreateInfo->format);
|
||||
if (!bc) {
|
||||
dev->GetDeviceImageSubresourceLayout(device, info, layout);
|
||||
return;
|
||||
}
|
||||
VkImageCreateInfo image = *info->pCreateInfo;
|
||||
substitute_image_info(bc, &image);
|
||||
VkDeviceImageSubresourceInfo copy = *info;
|
||||
copy.pCreateInfo = ℑ
|
||||
dev->GetDeviceImageSubresourceLayout(device, ©, layout);
|
||||
}
|
||||
|
||||
struct bound_buffer {
|
||||
VkDeviceMemory memory;
|
||||
VkDeviceSize offset;
|
||||
};
|
||||
|
||||
static void track_binding(struct device *dev, VkBuffer buffer, VkDeviceMemory memory, VkDeviceSize offset)
|
||||
{
|
||||
struct bound_buffer *bound = malloc(sizeof(*bound));
|
||||
bound->memory = memory;
|
||||
bound->offset = offset;
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
free(map_remove(&dev->buffers, HANDLE(buffer)));
|
||||
map_put(&dev->buffers, HANDLE(buffer), bound);
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL BindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory memory,
|
||||
VkDeviceSize offset)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
VkResult result = dev->BindBufferMemory(device, buffer, memory, offset);
|
||||
if (result == VK_SUCCESS)
|
||||
track_binding(dev, buffer, memory, offset);
|
||||
return result;
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL BindBufferMemory2(VkDevice device, uint32_t count, const VkBindBufferMemoryInfo *infos)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
VkResult result = dev->BindBufferMemory2(device, count, infos);
|
||||
if (result == VK_SUCCESS) {
|
||||
for (uint32_t i = 0; i < count; i++)
|
||||
track_binding(dev, infos[i].buffer, infos[i].memory, infos[i].memoryOffset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL DestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *allocator)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
free(map_remove(&dev->buffers, HANDLE(buffer)));
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
dev->DestroyBuffer(device, buffer, allocator);
|
||||
}
|
||||
|
||||
/* The memory's start as the application sees it mapped. */
|
||||
static void track_mapping(struct device *dev, VkDeviceMemory memory, VkDeviceSize offset, void *data)
|
||||
{
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
map_put(&dev->memories, HANDLE(memory), (uint8_t *)data - offset);
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
}
|
||||
|
||||
static void forget_mapping(struct device *dev, VkDeviceMemory memory)
|
||||
{
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
map_remove(&dev->memories, HANDLE(memory));
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL MapMemory(VkDevice device, VkDeviceMemory memory, VkDeviceSize offset,
|
||||
VkDeviceSize size, VkMemoryMapFlags flags, void **data)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
VkResult result = dev->MapMemory(device, memory, offset, size, flags, data);
|
||||
if (result == VK_SUCCESS)
|
||||
track_mapping(dev, memory, offset, *data);
|
||||
return result;
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL MapMemory2(VkDevice device, const VkMemoryMapInfo *info, void **data)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
VkResult result = dev->MapMemory2(device, info, data);
|
||||
if (result == VK_SUCCESS)
|
||||
track_mapping(dev, info->memory, info->offset, *data);
|
||||
return result;
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL UnmapMemory(VkDevice device, VkDeviceMemory memory)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
forget_mapping(dev, memory);
|
||||
dev->UnmapMemory(device, memory);
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL UnmapMemory2(VkDevice device, const VkMemoryUnmapInfo *info)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
forget_mapping(dev, info->memory);
|
||||
return dev->UnmapMemory2(device, info);
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL FreeMemory(VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks *allocator)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
forget_mapping(dev, memory);
|
||||
dev->FreeMemory(device, memory, allocator);
|
||||
}
|
||||
|
||||
struct staging_block {
|
||||
VkBuffer buffer;
|
||||
VkDeviceMemory memory;
|
||||
uint8_t *data;
|
||||
VkDeviceSize size;
|
||||
VkDeviceSize used;
|
||||
struct staging_block *next;
|
||||
};
|
||||
|
||||
struct command_buffer {
|
||||
VkCommandPool pool;
|
||||
struct staging_block *staging;
|
||||
};
|
||||
|
||||
static void destroy_block(struct device *dev, struct staging_block *block)
|
||||
{
|
||||
dev->DestroyBuffer(dev->handle, block->buffer, NULL);
|
||||
dev->FreeMemory(dev->handle, block->memory, NULL);
|
||||
free(block);
|
||||
}
|
||||
|
||||
static struct staging_block *create_block(struct device *dev, VkDeviceSize size)
|
||||
{
|
||||
struct staging_block *block = calloc(1, sizeof(*block));
|
||||
block->size = size;
|
||||
VkBufferCreateInfo buffer_info = {
|
||||
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
||||
.size = size,
|
||||
.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
|
||||
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
||||
};
|
||||
if (dev->CreateBuffer(dev->handle, &buffer_info, NULL, &block->buffer) != VK_SUCCESS) {
|
||||
free(block);
|
||||
return NULL;
|
||||
}
|
||||
VkMemoryRequirements requirements;
|
||||
dev->GetBufferMemoryRequirements(dev->handle, block->buffer, &requirements);
|
||||
const VkMemoryPropertyFlags wanted = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
||||
uint32_t type = UINT32_MAX;
|
||||
for (uint32_t i = 0; i < dev->memory_properties.memoryTypeCount && type == UINT32_MAX; i++) {
|
||||
if ((requirements.memoryTypeBits & (1u << i)) &&
|
||||
(dev->memory_properties.memoryTypes[i].propertyFlags & wanted) == wanted)
|
||||
type = i;
|
||||
}
|
||||
VkMemoryAllocateInfo allocate_info = {
|
||||
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
|
||||
.allocationSize = requirements.size,
|
||||
.memoryTypeIndex = type,
|
||||
};
|
||||
void *data = NULL;
|
||||
if (type == UINT32_MAX || dev->AllocateMemory(dev->handle, &allocate_info, NULL, &block->memory) != VK_SUCCESS) {
|
||||
dev->DestroyBuffer(dev->handle, block->buffer, NULL);
|
||||
free(block);
|
||||
return NULL;
|
||||
}
|
||||
if (dev->BindBufferMemory(dev->handle, block->buffer, block->memory, 0) != VK_SUCCESS ||
|
||||
dev->MapMemory(dev->handle, block->memory, 0, VK_WHOLE_SIZE, 0, &data) != VK_SUCCESS) {
|
||||
destroy_block(dev, block);
|
||||
return NULL;
|
||||
}
|
||||
block->data = data;
|
||||
return block;
|
||||
}
|
||||
|
||||
/* Called with the device lock held: the command buffer is done with its staging. */
|
||||
static void recycle_staging(struct device *dev, struct command_buffer *state)
|
||||
{
|
||||
VkDeviceSize kept = 0;
|
||||
for (struct staging_block *b = dev->free_staging; b; b = b->next)
|
||||
kept += b->size;
|
||||
while (state->staging) {
|
||||
struct staging_block *block = state->staging;
|
||||
state->staging = block->next;
|
||||
if (kept + block->size > STAGING_KEPT) {
|
||||
destroy_block(dev, block);
|
||||
continue;
|
||||
}
|
||||
block->used = 0;
|
||||
block->next = dev->free_staging;
|
||||
dev->free_staging = block;
|
||||
kept += block->size;
|
||||
}
|
||||
}
|
||||
|
||||
/* Room for `size` bytes in a staging buffer that lives as long as the command buffer's recording. */
|
||||
static struct staging_block *staging_for(struct device *dev, VkCommandBuffer cmd, VkDeviceSize size,
|
||||
VkDeviceSize *offset)
|
||||
{
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
struct command_buffer *state = map_get(&dev->command_buffers, HANDLE(cmd));
|
||||
if (!state) {
|
||||
state = calloc(1, sizeof(*state));
|
||||
map_put(&dev->command_buffers, HANDLE(cmd), state);
|
||||
}
|
||||
struct staging_block *block = state->staging;
|
||||
VkDeviceSize start = block ? (block->used + 63) & ~(VkDeviceSize)63 : 0;
|
||||
if (!block || start + size > block->size) {
|
||||
struct staging_block **link = &dev->free_staging;
|
||||
while (*link && (*link)->size < size)
|
||||
link = &(*link)->next;
|
||||
block = *link;
|
||||
if (block)
|
||||
*link = block->next;
|
||||
else
|
||||
block = create_block(dev, size > STAGING_BLOCK_SIZE ? size : STAGING_BLOCK_SIZE);
|
||||
if (block) {
|
||||
block->next = state->staging;
|
||||
state->staging = block;
|
||||
}
|
||||
start = 0;
|
||||
}
|
||||
if (block)
|
||||
block->used = start + size;
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
*offset = start;
|
||||
return block;
|
||||
}
|
||||
|
||||
/* Where the application has the buffer's contents mapped, or NULL. */
|
||||
static const uint8_t *mapped_buffer(struct device *dev, VkBuffer buffer)
|
||||
{
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
const struct bound_buffer *bound = map_get(&dev->buffers, HANDLE(buffer));
|
||||
const uint8_t *base = bound ? map_get(&dev->memories, HANDLE(bound->memory)) : NULL;
|
||||
const uint8_t *data = base ? base + bound->offset : NULL;
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
return data;
|
||||
}
|
||||
|
||||
static void decode_block(const struct bc_format *bc, const uint8_t *block, uint8_t *texels)
|
||||
{
|
||||
switch (bc->kind) {
|
||||
case BC1:
|
||||
bcdec_bc1(block, texels, 16);
|
||||
if (bc->opaque) {
|
||||
for (int i = 0; i < 16; i++)
|
||||
texels[i * 4 + 3] = 0xff;
|
||||
}
|
||||
break;
|
||||
case BC2:
|
||||
bcdec_bc2(block, texels, 16);
|
||||
break;
|
||||
case BC3:
|
||||
bcdec_bc3(block, texels, 16);
|
||||
break;
|
||||
case BC4:
|
||||
bcdec_bc4(block, texels, 4, bc->is_signed);
|
||||
break;
|
||||
case BC5:
|
||||
bcdec_bc5(block, texels, 8, bc->is_signed);
|
||||
break;
|
||||
case BC6H: {
|
||||
uint16_t rgb[16 * 3];
|
||||
bcdec_bc6h_half(block, rgb, 12, bc->is_signed);
|
||||
uint16_t *rgba = (uint16_t *)texels;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
rgba[i * 4 + 0] = rgb[i * 3 + 0];
|
||||
rgba[i * 4 + 1] = rgb[i * 3 + 1];
|
||||
rgba[i * 4 + 2] = rgb[i * 3 + 2];
|
||||
rgba[i * 4 + 3] = 0x3c00;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BC7:
|
||||
bcdec_bc7(block, texels, 16);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
struct upload {
|
||||
VkDeviceSize offset;
|
||||
uint32_t row_length;
|
||||
uint32_t image_height;
|
||||
VkImageSubresourceLayers subresource;
|
||||
VkOffset3D image_offset;
|
||||
VkExtent3D extent;
|
||||
};
|
||||
|
||||
static uint32_t warned;
|
||||
|
||||
static void warn_once(uint32_t bit, const char *message)
|
||||
{
|
||||
if (!(__atomic_fetch_or(&warned, bit, __ATOMIC_RELAXED) & bit))
|
||||
layer_log("%s", message);
|
||||
}
|
||||
|
||||
static void upload_region(struct device *dev, VkCommandBuffer cmd, const struct bc_image *image,
|
||||
const uint8_t *source, VkImage dst, VkImageLayout layout, const struct upload *region)
|
||||
{
|
||||
const struct bc_format *bc = image->format;
|
||||
uint32_t width = region->extent.width, height = region->extent.height;
|
||||
uint32_t layers = region->subresource.layerCount;
|
||||
if (layers == VK_REMAINING_ARRAY_LAYERS)
|
||||
layers = image->array_layers - region->subresource.baseArrayLayer;
|
||||
uint32_t slices = region->extent.depth * layers;
|
||||
uint32_t row_texels = region->row_length ? region->row_length : width;
|
||||
uint32_t height_texels = region->image_height ? region->image_height : height;
|
||||
size_t source_row = (size_t)((row_texels + 3) / 4) * bc->block_bytes;
|
||||
size_t source_slice = (size_t)((height_texels + 3) / 4) * source_row;
|
||||
size_t row_bytes = (size_t)width * bc->texel_bytes;
|
||||
VkDeviceSize size = (VkDeviceSize)row_bytes * height * slices;
|
||||
if (!size)
|
||||
return;
|
||||
|
||||
VkDeviceSize offset;
|
||||
struct staging_block *block = staging_for(dev, cmd, size, &offset);
|
||||
if (!block) {
|
||||
warn_once(1u << 0, "out of staging memory for BC texture uploads; textures left empty");
|
||||
return;
|
||||
}
|
||||
uint8_t *out = block->data + offset;
|
||||
const uint8_t *in = source + region->offset;
|
||||
uint8_t texels[16 * 8];
|
||||
for (uint32_t s = 0; s < slices; s++) {
|
||||
for (uint32_t by = 0; by < (height + 3) / 4; by++) {
|
||||
for (uint32_t bx = 0; bx < (width + 3) / 4; bx++) {
|
||||
decode_block(bc, in + s * source_slice + by * source_row + (size_t)bx * bc->block_bytes, texels);
|
||||
for (uint32_t y = 0; y < 4 && by * 4 + y < height; y++) {
|
||||
uint32_t columns = width - bx * 4 < 4 ? width - bx * 4 : 4;
|
||||
memcpy(out + ((size_t)s * height + by * 4 + y) * row_bytes + (size_t)bx * 4 * bc->texel_bytes,
|
||||
texels + (size_t)y * 4 * bc->texel_bytes, (size_t)columns * bc->texel_bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VkBufferImageCopy copy = {
|
||||
.bufferOffset = offset,
|
||||
.imageSubresource = region->subresource,
|
||||
.imageOffset = region->image_offset,
|
||||
.imageExtent = region->extent,
|
||||
};
|
||||
copy.imageSubresource.layerCount = layers;
|
||||
dev->CmdCopyBufferToImage(cmd, block->buffer, dst, layout, 1, ©);
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL CmdCopyBufferToImage(VkCommandBuffer cmd, VkBuffer buffer, VkImage image,
|
||||
VkImageLayout layout, uint32_t count,
|
||||
const VkBufferImageCopy *regions)
|
||||
{
|
||||
struct device *dev = device_from_handle(cmd);
|
||||
const struct bc_image *tracked = tracked_image(dev, image);
|
||||
if (!tracked) {
|
||||
dev->CmdCopyBufferToImage(cmd, buffer, image, layout, count, regions);
|
||||
return;
|
||||
}
|
||||
const uint8_t *source = mapped_buffer(dev, buffer);
|
||||
if (!source) {
|
||||
warn_once(1u << 1, "BC texture upload from memory that is not mapped; texture left empty");
|
||||
return;
|
||||
}
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
struct upload region = {regions[i].bufferOffset, regions[i].bufferRowLength, regions[i].bufferImageHeight,
|
||||
regions[i].imageSubresource, regions[i].imageOffset, regions[i].imageExtent};
|
||||
upload_region(dev, cmd, tracked, source, image, layout, ®ion);
|
||||
}
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL CmdCopyBufferToImage2(VkCommandBuffer cmd, const VkCopyBufferToImageInfo2 *info)
|
||||
{
|
||||
struct device *dev = device_from_handle(cmd);
|
||||
const struct bc_image *tracked = tracked_image(dev, info->dstImage);
|
||||
if (!tracked) {
|
||||
dev->CmdCopyBufferToImage2(cmd, info);
|
||||
return;
|
||||
}
|
||||
const uint8_t *source = mapped_buffer(dev, info->srcBuffer);
|
||||
if (!source) {
|
||||
warn_once(1u << 1, "BC texture upload from memory that is not mapped; texture left empty");
|
||||
return;
|
||||
}
|
||||
for (uint32_t i = 0; i < info->regionCount; i++) {
|
||||
const VkBufferImageCopy2 *r = &info->pRegions[i];
|
||||
struct upload region = {r->bufferOffset, r->bufferRowLength, r->bufferImageHeight,
|
||||
r->imageSubresource, r->imageOffset, r->imageExtent};
|
||||
upload_region(dev, cmd, tracked, source, info->dstImage, info->dstImageLayout, ®ion);
|
||||
}
|
||||
}
|
||||
|
||||
/* Reading compressed blocks back would hand out decoded texels the buffer has no room for. */
|
||||
VKAPI_ATTR void VKAPI_CALL CmdCopyImageToBuffer(VkCommandBuffer cmd, VkImage image, VkImageLayout layout,
|
||||
VkBuffer buffer, uint32_t count, const VkBufferImageCopy *regions)
|
||||
{
|
||||
struct device *dev = device_from_handle(cmd);
|
||||
if (tracked_image(dev, image)) {
|
||||
warn_once(1u << 2, "BC texture read back into a buffer; skipped");
|
||||
return;
|
||||
}
|
||||
dev->CmdCopyImageToBuffer(cmd, image, layout, buffer, count, regions);
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL CmdCopyImageToBuffer2(VkCommandBuffer cmd, const VkCopyImageToBufferInfo2 *info)
|
||||
{
|
||||
struct device *dev = device_from_handle(cmd);
|
||||
if (tracked_image(dev, info->srcImage)) {
|
||||
warn_once(1u << 2, "BC texture read back into a buffer; skipped");
|
||||
return;
|
||||
}
|
||||
dev->CmdCopyImageToBuffer2(cmd, info);
|
||||
}
|
||||
|
||||
/* Between two BC images the texels line up; between BC and anything else they cannot. */
|
||||
VKAPI_ATTR void VKAPI_CALL CmdCopyImage(VkCommandBuffer cmd, VkImage src, VkImageLayout src_layout, VkImage dst,
|
||||
VkImageLayout dst_layout, uint32_t count, const VkImageCopy *regions)
|
||||
{
|
||||
struct device *dev = device_from_handle(cmd);
|
||||
if (!tracked_image(dev, src) != !tracked_image(dev, dst)) {
|
||||
warn_once(1u << 3, "copy between a BC texture and an uncompressed one; skipped");
|
||||
return;
|
||||
}
|
||||
dev->CmdCopyImage(cmd, src, src_layout, dst, dst_layout, count, regions);
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL CmdCopyImage2(VkCommandBuffer cmd, const VkCopyImageInfo2 *info)
|
||||
{
|
||||
struct device *dev = device_from_handle(cmd);
|
||||
if (!tracked_image(dev, info->srcImage) != !tracked_image(dev, info->dstImage)) {
|
||||
warn_once(1u << 3, "copy between a BC texture and an uncompressed one; skipped");
|
||||
return;
|
||||
}
|
||||
dev->CmdCopyImage2(cmd, info);
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL AllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *info,
|
||||
VkCommandBuffer *buffers)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
VkResult result = dev->AllocateCommandBuffers(device, info, buffers);
|
||||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
for (uint32_t i = 0; i < info->commandBufferCount; i++) {
|
||||
struct command_buffer *state = calloc(1, sizeof(*state));
|
||||
state->pool = info->commandPool;
|
||||
map_put(&dev->command_buffers, HANDLE(buffers[i]), state);
|
||||
}
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
return result;
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL FreeCommandBuffers(VkDevice device, VkCommandPool pool, uint32_t count,
|
||||
const VkCommandBuffer *buffers)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
struct command_buffer *state = buffers[i] ? map_remove(&dev->command_buffers, HANDLE(buffers[i])) : NULL;
|
||||
if (state) {
|
||||
recycle_staging(dev, state);
|
||||
free(state);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
dev->FreeCommandBuffers(device, pool, count, buffers);
|
||||
}
|
||||
|
||||
static void recycle_command_buffer(struct device *dev, VkCommandBuffer cmd)
|
||||
{
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
struct command_buffer *state = map_get(&dev->command_buffers, HANDLE(cmd));
|
||||
if (state)
|
||||
recycle_staging(dev, state);
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL BeginCommandBuffer(VkCommandBuffer cmd, const VkCommandBufferBeginInfo *info)
|
||||
{
|
||||
struct device *dev = device_from_handle(cmd);
|
||||
recycle_command_buffer(dev, cmd);
|
||||
return dev->BeginCommandBuffer(cmd, info);
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL ResetCommandBuffer(VkCommandBuffer cmd, VkCommandBufferResetFlags flags)
|
||||
{
|
||||
struct device *dev = device_from_handle(cmd);
|
||||
recycle_command_buffer(dev, cmd);
|
||||
return dev->ResetCommandBuffer(cmd, flags);
|
||||
}
|
||||
|
||||
/* Every command buffer of the pool is done with its staging; `forget` drops them as well. */
|
||||
static void recycle_pool(struct device *dev, VkCommandPool pool, bool forget)
|
||||
{
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
struct handle_map *map = &dev->command_buffers;
|
||||
for (uint32_t i = 0; i < map->capacity;) {
|
||||
struct command_buffer *state = map->values[i];
|
||||
if (!map->keys[i] || state->pool != pool) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
recycle_staging(dev, state);
|
||||
if (forget) {
|
||||
/* Removal shifts a later entry into this slot, so look at it again. */
|
||||
free(map_remove(map, map->keys[i]));
|
||||
continue;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL ResetCommandPool(VkDevice device, VkCommandPool pool, VkCommandPoolResetFlags flags)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
recycle_pool(dev, pool, false);
|
||||
return dev->ResetCommandPool(device, pool, flags);
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL DestroyCommandPool(VkDevice device, VkCommandPool pool,
|
||||
const VkAllocationCallbacks *allocator)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
recycle_pool(dev, pool, true);
|
||||
dev->DestroyCommandPool(device, pool, allocator);
|
||||
}
|
||||
|
||||
void bc_destroy_device(struct device *dev)
|
||||
{
|
||||
struct handle_map *maps[] = {&dev->images, &dev->buffers, &dev->command_buffers};
|
||||
for (size_t m = 0; m < sizeof(maps) / sizeof(maps[0]); m++) {
|
||||
for (uint32_t i = 0; i < maps[m]->capacity; i++) {
|
||||
if (!maps[m]->keys[i])
|
||||
continue;
|
||||
if (maps[m] == &dev->command_buffers)
|
||||
recycle_staging(dev, maps[m]->values[i]);
|
||||
free(maps[m]->values[i]);
|
||||
}
|
||||
map_free(maps[m]);
|
||||
}
|
||||
map_free(&dev->memories);
|
||||
while (dev->free_staging) {
|
||||
struct staging_block *block = dev->free_staging;
|
||||
dev->free_staging = block->next;
|
||||
destroy_block(dev, block);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,452 @@
|
||||
/*
|
||||
* The Mali compatibility layer's draw and descriptor emulation (added to David Cimo's layer):
|
||||
*
|
||||
* - multiDrawIndirect: an indirect draw with drawCount > 1 is recorded as drawCount single draws
|
||||
* at offset + i * stride. Mali-G57 (Bifrost/Valhall v9) has none, and DXVK refuses the device.
|
||||
* - robustness2's nullDescriptor: VK_NULL_HANDLE buffers, image views and vertex buffers in
|
||||
* descriptor writes (plain, template and push) and vertex-buffer binds are replaced with small
|
||||
* stand-ins the layer owns. robustBufferAccess2 itself maps to robustBufferAccess (layer.c).
|
||||
* A null texel-buffer view gets an RGBA8 (uniform) or R32_UINT (storage) view of the stand-in
|
||||
* buffer: its format is not known here, but Zink leaves them unbound and never reads them.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mali_compat.h"
|
||||
|
||||
/* --- multiDrawIndirect --- */
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL CmdDrawIndirect(VkCommandBuffer cmd, VkBuffer buffer, VkDeviceSize offset,
|
||||
uint32_t draw_count, uint32_t stride)
|
||||
{
|
||||
struct device *dev = device_from_handle(cmd);
|
||||
if (draw_count <= 1) {
|
||||
dev->CmdDrawIndirect(cmd, buffer, offset, draw_count, stride);
|
||||
return;
|
||||
}
|
||||
for (uint32_t i = 0; i < draw_count; i++)
|
||||
dev->CmdDrawIndirect(cmd, buffer, offset + (VkDeviceSize)i * stride, 1, stride);
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL CmdDrawIndexedIndirect(VkCommandBuffer cmd, VkBuffer buffer, VkDeviceSize offset,
|
||||
uint32_t draw_count, uint32_t stride)
|
||||
{
|
||||
struct device *dev = device_from_handle(cmd);
|
||||
if (draw_count <= 1) {
|
||||
dev->CmdDrawIndexedIndirect(cmd, buffer, offset, draw_count, stride);
|
||||
return;
|
||||
}
|
||||
for (uint32_t i = 0; i < draw_count; i++)
|
||||
dev->CmdDrawIndexedIndirect(cmd, buffer, offset + (VkDeviceSize)i * stride, 1, stride);
|
||||
}
|
||||
|
||||
/* --- nullDescriptor stand-ins --- */
|
||||
|
||||
/* A template's entries, to find the null handles in the data it is given. */
|
||||
struct template_info {
|
||||
uint32_t count;
|
||||
VkDescriptorUpdateTemplateEntry *entries;
|
||||
size_t size; /* bytes the data spans */
|
||||
};
|
||||
|
||||
#define NULL_BUFFER_SIZE 65536
|
||||
|
||||
static uint32_t memory_type(const struct device *dev, uint32_t bits, VkMemoryPropertyFlags want)
|
||||
{
|
||||
for (uint32_t i = 0; i < dev->memory_properties.memoryTypeCount; i++)
|
||||
if ((bits & (1u << i)) && (dev->memory_properties.memoryTypes[i].propertyFlags & want) == want)
|
||||
return i;
|
||||
for (uint32_t i = 0; i < dev->memory_properties.memoryTypeCount; i++)
|
||||
if (bits & (1u << i))
|
||||
return i;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Made once per device, under its lock, the first time a null descriptor is seen. */
|
||||
static bool null_resources(struct device *dev)
|
||||
{
|
||||
if (dev->null_ready)
|
||||
return dev->null_ready > 0;
|
||||
dev->null_ready = -1;
|
||||
|
||||
VkBufferCreateInfo binfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
||||
.size = NULL_BUFFER_SIZE,
|
||||
.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
|
||||
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT |
|
||||
VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT,
|
||||
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
||||
};
|
||||
if (dev->CreateBuffer(dev->handle, &binfo, NULL, &dev->null_buffer) != VK_SUCCESS)
|
||||
return false;
|
||||
VkMemoryRequirements breq;
|
||||
dev->GetBufferMemoryRequirements(dev->handle, dev->null_buffer, &breq);
|
||||
VkMemoryAllocateInfo balloc = {
|
||||
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
|
||||
.allocationSize = breq.size,
|
||||
.memoryTypeIndex = memory_type(dev, breq.memoryTypeBits,
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT),
|
||||
};
|
||||
if (dev->AllocateMemory(dev->handle, &balloc, NULL, &dev->null_buffer_memory) != VK_SUCCESS)
|
||||
return false;
|
||||
dev->BindBufferMemory(dev->handle, dev->null_buffer, dev->null_buffer_memory, 0);
|
||||
/* A null buffer reads as zeros. */
|
||||
void *data = NULL;
|
||||
if ((dev->memory_properties.memoryTypes[balloc.memoryTypeIndex].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) &&
|
||||
dev->MapMemory(dev->handle, dev->null_buffer_memory, 0, VK_WHOLE_SIZE, 0, &data) == VK_SUCCESS) {
|
||||
memset(data, 0, (size_t)breq.size);
|
||||
dev->UnmapMemory(dev->handle, dev->null_buffer_memory);
|
||||
}
|
||||
|
||||
VkImageCreateInfo iinfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
|
||||
.imageType = VK_IMAGE_TYPE_2D,
|
||||
.format = VK_FORMAT_R8G8B8A8_UNORM,
|
||||
.extent = {1, 1, 1},
|
||||
.mipLevels = 1,
|
||||
.arrayLayers = 1,
|
||||
.samples = VK_SAMPLE_COUNT_1_BIT,
|
||||
.tiling = VK_IMAGE_TILING_OPTIMAL,
|
||||
.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT,
|
||||
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
||||
.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
};
|
||||
if (dev->CreateImage(dev->handle, &iinfo, NULL, &dev->null_image) != VK_SUCCESS)
|
||||
return false;
|
||||
VkMemoryRequirements ireq;
|
||||
dev->GetImageMemoryRequirements(dev->handle, dev->null_image, &ireq);
|
||||
VkMemoryAllocateInfo ialloc = {
|
||||
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
|
||||
.allocationSize = ireq.size,
|
||||
.memoryTypeIndex = memory_type(dev, ireq.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT),
|
||||
};
|
||||
if (dev->AllocateMemory(dev->handle, &ialloc, NULL, &dev->null_image_memory) != VK_SUCCESS)
|
||||
return false;
|
||||
dev->BindImageMemory(dev->handle, dev->null_image, dev->null_image_memory, 0);
|
||||
VkImageViewCreateInfo vinfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
||||
.image = dev->null_image,
|
||||
.viewType = VK_IMAGE_VIEW_TYPE_2D,
|
||||
.format = VK_FORMAT_R8G8B8A8_UNORM,
|
||||
.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
|
||||
};
|
||||
if (dev->CreateImageView(dev->handle, &vinfo, NULL, &dev->null_view) != VK_SUCCESS)
|
||||
return false;
|
||||
/* Texel views are optional: a write that needs one and has none keeps its null. */
|
||||
VkBufferViewCreateInfo tinfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO,
|
||||
.buffer = dev->null_buffer,
|
||||
.format = VK_FORMAT_R8G8B8A8_UNORM,
|
||||
.range = VK_WHOLE_SIZE,
|
||||
};
|
||||
if (dev->CreateBufferView(dev->handle, &tinfo, NULL, &dev->null_uniform_texel) != VK_SUCCESS)
|
||||
dev->null_uniform_texel = VK_NULL_HANDLE;
|
||||
tinfo.format = VK_FORMAT_R32_UINT;
|
||||
if (dev->CreateBufferView(dev->handle, &tinfo, NULL, &dev->null_storage_texel) != VK_SUCCESS)
|
||||
dev->null_storage_texel = VK_NULL_HANDLE;
|
||||
dev->null_ready = 1;
|
||||
layer_log("nullDescriptor: stand-in buffer and 1x1 image ready");
|
||||
return true;
|
||||
}
|
||||
|
||||
void null_resources_destroy(struct device *dev)
|
||||
{
|
||||
for (uint32_t i = 0; i < dev->templates.capacity; i++) {
|
||||
struct template_info *t = dev->templates.values ? dev->templates.values[i] : NULL;
|
||||
if (t) {
|
||||
free(t->entries);
|
||||
free(t);
|
||||
}
|
||||
}
|
||||
map_free(&dev->templates);
|
||||
if (dev->null_uniform_texel) dev->DestroyBufferView(dev->handle, dev->null_uniform_texel, NULL);
|
||||
if (dev->null_storage_texel) dev->DestroyBufferView(dev->handle, dev->null_storage_texel, NULL);
|
||||
if (dev->null_view) dev->DestroyImageView(dev->handle, dev->null_view, NULL);
|
||||
if (dev->null_image) dev->DestroyImage(dev->handle, dev->null_image, NULL);
|
||||
if (dev->null_image_memory) dev->FreeMemory(dev->handle, dev->null_image_memory, NULL);
|
||||
if (dev->null_buffer) dev->DestroyBuffer(dev->handle, dev->null_buffer, NULL);
|
||||
if (dev->null_buffer_memory) dev->FreeMemory(dev->handle, dev->null_buffer_memory, NULL);
|
||||
}
|
||||
|
||||
static bool is_buffer_type(VkDescriptorType t)
|
||||
{
|
||||
return t == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER || t == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER ||
|
||||
t == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC || t == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC;
|
||||
}
|
||||
|
||||
static bool is_image_type(VkDescriptorType t)
|
||||
{
|
||||
return t == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE || t == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE ||
|
||||
t == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER || t == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
|
||||
}
|
||||
|
||||
static bool is_texel_type(VkDescriptorType t)
|
||||
{
|
||||
return t == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER || t == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
|
||||
}
|
||||
|
||||
static void fix_texel(struct device *dev, VkDescriptorType t, VkBufferView *view)
|
||||
{
|
||||
if (*view != VK_NULL_HANDLE || !null_resources(dev))
|
||||
return;
|
||||
*view = t == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER ? dev->null_storage_texel : dev->null_uniform_texel;
|
||||
}
|
||||
|
||||
static void fix_buffer(struct device *dev, VkDescriptorBufferInfo *info)
|
||||
{
|
||||
if (info->buffer != VK_NULL_HANDLE || !null_resources(dev))
|
||||
return;
|
||||
info->buffer = dev->null_buffer;
|
||||
info->offset = 0;
|
||||
info->range = VK_WHOLE_SIZE;
|
||||
}
|
||||
|
||||
static void fix_image(struct device *dev, VkDescriptorImageInfo *info)
|
||||
{
|
||||
if (info->imageView != VK_NULL_HANDLE || !null_resources(dev))
|
||||
return;
|
||||
info->imageView = dev->null_view;
|
||||
}
|
||||
|
||||
/* Copies of the writes with stand-ins for null handles; NULL when nothing needed changing. */
|
||||
static VkWriteDescriptorSet *fix_writes(struct device *dev, uint32_t count, const VkWriteDescriptorSet *writes,
|
||||
void ***scratch, uint32_t *scratch_count)
|
||||
{
|
||||
VkWriteDescriptorSet *copies = NULL;
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
const VkWriteDescriptorSet *w = &writes[i];
|
||||
bool null_found = false;
|
||||
for (uint32_t j = 0; j < w->descriptorCount && !null_found; j++) {
|
||||
if (is_buffer_type(w->descriptorType) && w->pBufferInfo && w->pBufferInfo[j].buffer == VK_NULL_HANDLE)
|
||||
null_found = true;
|
||||
if (is_image_type(w->descriptorType) && w->pImageInfo && w->pImageInfo[j].imageView == VK_NULL_HANDLE &&
|
||||
w->descriptorType != VK_DESCRIPTOR_TYPE_SAMPLER)
|
||||
null_found = true;
|
||||
if (is_texel_type(w->descriptorType) && w->pTexelBufferView && w->pTexelBufferView[j] == VK_NULL_HANDLE)
|
||||
null_found = true;
|
||||
}
|
||||
if (!null_found)
|
||||
continue;
|
||||
if (!copies) {
|
||||
copies = malloc(count * sizeof(*copies));
|
||||
memcpy(copies, writes, count * sizeof(*copies));
|
||||
*scratch = calloc(count, sizeof(void *));
|
||||
}
|
||||
if (is_buffer_type(w->descriptorType)) {
|
||||
VkDescriptorBufferInfo *b = malloc(w->descriptorCount * sizeof(*b));
|
||||
memcpy(b, w->pBufferInfo, w->descriptorCount * sizeof(*b));
|
||||
for (uint32_t j = 0; j < w->descriptorCount; j++)
|
||||
fix_buffer(dev, &b[j]);
|
||||
copies[i].pBufferInfo = b;
|
||||
(*scratch)[(*scratch_count)++] = b;
|
||||
} else if (is_texel_type(w->descriptorType)) {
|
||||
VkBufferView *v = malloc(w->descriptorCount * sizeof(*v));
|
||||
memcpy(v, w->pTexelBufferView, w->descriptorCount * sizeof(*v));
|
||||
for (uint32_t j = 0; j < w->descriptorCount; j++)
|
||||
fix_texel(dev, w->descriptorType, &v[j]);
|
||||
copies[i].pTexelBufferView = v;
|
||||
(*scratch)[(*scratch_count)++] = v;
|
||||
} else {
|
||||
VkDescriptorImageInfo *im = malloc(w->descriptorCount * sizeof(*im));
|
||||
memcpy(im, w->pImageInfo, w->descriptorCount * sizeof(*im));
|
||||
for (uint32_t j = 0; j < w->descriptorCount; j++)
|
||||
fix_image(dev, &im[j]);
|
||||
copies[i].pImageInfo = im;
|
||||
(*scratch)[(*scratch_count)++] = im;
|
||||
}
|
||||
}
|
||||
return copies;
|
||||
}
|
||||
|
||||
static void free_scratch(void **scratch, uint32_t count)
|
||||
{
|
||||
for (uint32_t i = 0; i < count; i++)
|
||||
free(scratch[i]);
|
||||
free(scratch);
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL UpdateDescriptorSets(VkDevice device, uint32_t write_count, const VkWriteDescriptorSet *writes,
|
||||
uint32_t copy_count, const VkCopyDescriptorSet *copies)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
void **scratch = NULL;
|
||||
uint32_t scratch_count = 0;
|
||||
VkWriteDescriptorSet *fixed = fix_writes(dev, write_count, writes, &scratch, &scratch_count);
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
dev->UpdateDescriptorSets(device, write_count, fixed ? fixed : writes, copy_count, copies);
|
||||
free(fixed);
|
||||
free_scratch(scratch, scratch_count);
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL CmdPushDescriptorSet(VkCommandBuffer cmd, VkPipelineBindPoint bind_point,
|
||||
VkPipelineLayout layout, uint32_t set, uint32_t write_count,
|
||||
const VkWriteDescriptorSet *writes)
|
||||
{
|
||||
struct device *dev = device_from_handle(cmd);
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
void **scratch = NULL;
|
||||
uint32_t scratch_count = 0;
|
||||
VkWriteDescriptorSet *fixed = fix_writes(dev, write_count, writes, &scratch, &scratch_count);
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
dev->CmdPushDescriptorSet(cmd, bind_point, layout, set, write_count, fixed ? fixed : writes);
|
||||
free(fixed);
|
||||
free_scratch(scratch, scratch_count);
|
||||
}
|
||||
|
||||
static size_t entry_size(VkDescriptorType t)
|
||||
{
|
||||
if (is_buffer_type(t))
|
||||
return sizeof(VkDescriptorBufferInfo);
|
||||
if (is_image_type(t) || t == VK_DESCRIPTOR_TYPE_SAMPLER)
|
||||
return sizeof(VkDescriptorImageInfo);
|
||||
if (t == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK)
|
||||
return 1;
|
||||
return sizeof(uint64_t);
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL CreateDescriptorUpdateTemplate(VkDevice device,
|
||||
const VkDescriptorUpdateTemplateCreateInfo *info,
|
||||
const VkAllocationCallbacks *allocator,
|
||||
VkDescriptorUpdateTemplate *tmpl)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
VkResult result = dev->CreateDescriptorUpdateTemplate(device, info, allocator, tmpl);
|
||||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
struct template_info *t = calloc(1, sizeof(*t));
|
||||
t->count = info->descriptorUpdateEntryCount;
|
||||
t->entries = malloc(t->count * sizeof(*t->entries));
|
||||
memcpy(t->entries, info->pDescriptorUpdateEntries, t->count * sizeof(*t->entries));
|
||||
for (uint32_t i = 0; i < t->count; i++) {
|
||||
const VkDescriptorUpdateTemplateEntry *e = &t->entries[i];
|
||||
size_t end = e->descriptorType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK
|
||||
? e->offset + e->descriptorCount
|
||||
: e->offset + (e->descriptorCount ? (e->descriptorCount - 1) * e->stride : 0) + entry_size(e->descriptorType);
|
||||
if (end > t->size)
|
||||
t->size = end;
|
||||
}
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
map_put(&dev->templates, (uint64_t)*tmpl, t);
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL DestroyDescriptorUpdateTemplate(VkDevice device, VkDescriptorUpdateTemplate tmpl,
|
||||
const VkAllocationCallbacks *allocator)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
struct template_info *t = map_remove(&dev->templates, (uint64_t)tmpl);
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
if (t) {
|
||||
free(t->entries);
|
||||
free(t);
|
||||
}
|
||||
dev->DestroyDescriptorUpdateTemplate(device, tmpl, allocator);
|
||||
}
|
||||
|
||||
/* A copy of the template's data with stand-ins for null handles; NULL when nothing changed. */
|
||||
static void *fix_template_data(struct device *dev, VkDescriptorUpdateTemplate tmpl, const void *data)
|
||||
{
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
struct template_info *t = map_get(&dev->templates, (uint64_t)tmpl);
|
||||
void *copy = NULL;
|
||||
if (t && data) {
|
||||
for (uint32_t i = 0; i < t->count; i++) {
|
||||
const VkDescriptorUpdateTemplateEntry *e = &t->entries[i];
|
||||
bool buffer = is_buffer_type(e->descriptorType);
|
||||
bool image = is_image_type(e->descriptorType);
|
||||
bool texel = is_texel_type(e->descriptorType);
|
||||
if (!buffer && !image && !texel)
|
||||
continue;
|
||||
for (uint32_t j = 0; j < e->descriptorCount; j++) {
|
||||
size_t at = e->offset + (size_t)j * e->stride;
|
||||
const char *src = (const char *)(copy ? copy : data) + at;
|
||||
bool null_handle = buffer ? ((const VkDescriptorBufferInfo *)src)->buffer == VK_NULL_HANDLE
|
||||
: texel ? *(const VkBufferView *)src == VK_NULL_HANDLE
|
||||
: ((const VkDescriptorImageInfo *)src)->imageView == VK_NULL_HANDLE;
|
||||
if (!null_handle)
|
||||
continue;
|
||||
if (!copy) {
|
||||
copy = malloc(t->size);
|
||||
memcpy(copy, data, t->size);
|
||||
}
|
||||
if (buffer)
|
||||
fix_buffer(dev, (VkDescriptorBufferInfo *)((char *)copy + at));
|
||||
else if (texel)
|
||||
fix_texel(dev, e->descriptorType, (VkBufferView *)((char *)copy + at));
|
||||
else
|
||||
fix_image(dev, (VkDescriptorImageInfo *)((char *)copy + at));
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
return copy;
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL UpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet set,
|
||||
VkDescriptorUpdateTemplate tmpl, const void *data)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
void *fixed = fix_template_data(dev, tmpl, data);
|
||||
dev->UpdateDescriptorSetWithTemplate(device, set, tmpl, fixed ? fixed : data);
|
||||
free(fixed);
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL CmdPushDescriptorSetWithTemplate(VkCommandBuffer cmd, VkDescriptorUpdateTemplate tmpl,
|
||||
VkPipelineLayout layout, uint32_t set, const void *data)
|
||||
{
|
||||
struct device *dev = device_from_handle(cmd);
|
||||
void *fixed = fix_template_data(dev, tmpl, data);
|
||||
dev->CmdPushDescriptorSetWithTemplate(cmd, tmpl, layout, set, fixed ? fixed : data);
|
||||
free(fixed);
|
||||
}
|
||||
|
||||
/* Null vertex buffers read as zeros: bound to the stand-in at offset 0. */
|
||||
VKAPI_ATTR void VKAPI_CALL CmdBindVertexBuffers(VkCommandBuffer cmd, uint32_t first, uint32_t count,
|
||||
const VkBuffer *buffers, const VkDeviceSize *offsets)
|
||||
{
|
||||
struct device *dev = device_from_handle(cmd);
|
||||
VkBuffer fixed[64];
|
||||
VkDeviceSize fixed_offsets[64];
|
||||
bool any = false;
|
||||
for (uint32_t i = 0; i < count && i < 64; i++) any |= buffers[i] == VK_NULL_HANDLE;
|
||||
if (!any || count > 64) {
|
||||
dev->CmdBindVertexBuffers(cmd, first, count, buffers, offsets);
|
||||
return;
|
||||
}
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
bool ready = null_resources(dev);
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
fixed[i] = buffers[i] == VK_NULL_HANDLE && ready ? dev->null_buffer : buffers[i];
|
||||
fixed_offsets[i] = buffers[i] == VK_NULL_HANDLE ? 0 : offsets[i];
|
||||
}
|
||||
dev->CmdBindVertexBuffers(cmd, first, count, fixed, fixed_offsets);
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL CmdBindVertexBuffers2(VkCommandBuffer cmd, uint32_t first, uint32_t count,
|
||||
const VkBuffer *buffers, const VkDeviceSize *offsets,
|
||||
const VkDeviceSize *sizes, const VkDeviceSize *strides)
|
||||
{
|
||||
struct device *dev = device_from_handle(cmd);
|
||||
VkBuffer fixed[64];
|
||||
VkDeviceSize fixed_offsets[64], fixed_sizes[64];
|
||||
bool any = false;
|
||||
for (uint32_t i = 0; i < count && i < 64; i++) any |= buffers[i] == VK_NULL_HANDLE;
|
||||
if (!any || count > 64) {
|
||||
dev->CmdBindVertexBuffers2(cmd, first, count, buffers, offsets, sizes, strides);
|
||||
return;
|
||||
}
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
bool ready = null_resources(dev);
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
bool null_buffer = buffers[i] == VK_NULL_HANDLE;
|
||||
fixed[i] = null_buffer && ready ? dev->null_buffer : buffers[i];
|
||||
fixed_offsets[i] = null_buffer ? 0 : offsets[i];
|
||||
fixed_sizes[i] = sizes ? (null_buffer ? NULL_BUFFER_SIZE : sizes[i]) : 0;
|
||||
}
|
||||
dev->CmdBindVertexBuffers2(cmd, first, count, fixed, fixed_offsets, sizes ? fixed_sizes : NULL, strides);
|
||||
}
|
||||
@@ -0,0 +1,812 @@
|
||||
#define _GNU_SOURCE
|
||||
#include "mali_compat.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LAYER_NAME "VK_LAYER_DROIDDECK_mali_compat"
|
||||
|
||||
static pthread_mutex_t global_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static struct instance *instances;
|
||||
static struct device *devices;
|
||||
|
||||
void layer_log(const char *format, ...)
|
||||
{
|
||||
char line[512];
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vsnprintf(line, sizeof(line), format, args);
|
||||
va_end(args);
|
||||
fprintf(stderr, "droiddeck-mali-compat: %s\n", line);
|
||||
}
|
||||
|
||||
/* The loader's dispatch table pointer: shared by an instance and its physical devices, and by a
|
||||
* device and its queues and command buffers. */
|
||||
static void *dispatch_key(const void *dispatchable)
|
||||
{
|
||||
return *(void *const *)dispatchable;
|
||||
}
|
||||
|
||||
struct instance *instance_from_handle(const void *dispatchable)
|
||||
{
|
||||
void *key = dispatch_key(dispatchable);
|
||||
pthread_mutex_lock(&global_lock);
|
||||
struct instance *inst = instances;
|
||||
while (inst && inst->key != key)
|
||||
inst = inst->next;
|
||||
pthread_mutex_unlock(&global_lock);
|
||||
return inst;
|
||||
}
|
||||
|
||||
struct device *device_from_handle(const void *dispatchable)
|
||||
{
|
||||
void *key = dispatch_key(dispatchable);
|
||||
pthread_mutex_lock(&global_lock);
|
||||
struct device *dev = devices;
|
||||
while (dev && dev->key != key)
|
||||
dev = dev->next;
|
||||
pthread_mutex_unlock(&global_lock);
|
||||
return dev;
|
||||
}
|
||||
|
||||
static uint64_t hash(uint64_t key)
|
||||
{
|
||||
key ^= key >> 33;
|
||||
key *= 0xff51afd7ed558ccdull;
|
||||
key ^= key >> 33;
|
||||
return key;
|
||||
}
|
||||
|
||||
void *map_get(const struct handle_map *map, uint64_t key)
|
||||
{
|
||||
if (!map->capacity)
|
||||
return NULL;
|
||||
for (uint32_t i = hash(key) & (map->capacity - 1);; i = (i + 1) & (map->capacity - 1)) {
|
||||
if (map->keys[i] == key)
|
||||
return map->values[i];
|
||||
if (!map->keys[i])
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void map_grow(struct handle_map *map)
|
||||
{
|
||||
struct handle_map bigger = {
|
||||
.capacity = map->capacity ? map->capacity * 2 : 64,
|
||||
};
|
||||
bigger.keys = calloc(bigger.capacity, sizeof(*bigger.keys));
|
||||
bigger.values = calloc(bigger.capacity, sizeof(*bigger.values));
|
||||
for (uint32_t i = 0; i < map->capacity; i++) {
|
||||
if (map->keys[i])
|
||||
map_put(&bigger, map->keys[i], map->values[i]);
|
||||
}
|
||||
free(map->keys);
|
||||
free(map->values);
|
||||
*map = bigger;
|
||||
}
|
||||
|
||||
void map_put(struct handle_map *map, uint64_t key, void *value)
|
||||
{
|
||||
if ((map->count + 1) * 4 > map->capacity * 3)
|
||||
map_grow(map);
|
||||
uint32_t i = hash(key) & (map->capacity - 1);
|
||||
while (map->keys[i] && map->keys[i] != key)
|
||||
i = (i + 1) & (map->capacity - 1);
|
||||
if (!map->keys[i])
|
||||
map->count++;
|
||||
map->keys[i] = key;
|
||||
map->values[i] = value;
|
||||
}
|
||||
|
||||
void *map_remove(struct handle_map *map, uint64_t key)
|
||||
{
|
||||
if (!map->capacity)
|
||||
return NULL;
|
||||
uint32_t mask = map->capacity - 1;
|
||||
uint32_t i = hash(key) & mask;
|
||||
while (map->keys[i] != key) {
|
||||
if (!map->keys[i])
|
||||
return NULL;
|
||||
i = (i + 1) & mask;
|
||||
}
|
||||
void *value = map->values[i];
|
||||
map->count--;
|
||||
/* Backward-shift deletion keeps every remaining key reachable from its home slot. */
|
||||
for (uint32_t j = (i + 1) & mask; map->keys[j]; j = (j + 1) & mask) {
|
||||
uint32_t home = hash(map->keys[j]) & mask;
|
||||
if (((j - home) & mask) >= ((j - i) & mask)) {
|
||||
map->keys[i] = map->keys[j];
|
||||
map->values[i] = map->values[j];
|
||||
i = j;
|
||||
}
|
||||
}
|
||||
map->keys[i] = 0;
|
||||
map->values[i] = NULL;
|
||||
return value;
|
||||
}
|
||||
|
||||
void map_free(struct handle_map *map)
|
||||
{
|
||||
free(map->keys);
|
||||
free(map->values);
|
||||
*map = (struct handle_map){0};
|
||||
}
|
||||
|
||||
/* Wine processes by default. DROIDDECK_MALI_COMPAT=1 (the app's Venus route) turns it on everywhere
|
||||
* but gamescope, so Zink in the Steam client and Xwayland gets robustness2's nullDescriptor, which it
|
||||
* requires; gamescope runs fine on the driver's own features. =all includes gamescope too. */
|
||||
static bool wanted(void)
|
||||
{
|
||||
const char *setting = getenv("DROIDDECK_MALI_COMPAT");
|
||||
if (setting) {
|
||||
if (strcmp(setting, "0") == 0)
|
||||
return false;
|
||||
if (strcmp(setting, "all") == 0)
|
||||
return true;
|
||||
return strcmp(program_invocation_short_name, "gamescope") != 0;
|
||||
}
|
||||
return getenv("WINEPREFIX") != NULL;
|
||||
}
|
||||
|
||||
/* DROIDDECK_MALI_COMPAT_TRACE=1: what an application asks before it creates a device (Zink on a
|
||||
* Mali-G615 through Venus gave up before vkCreateDevice without a word). */
|
||||
static bool tracing(void)
|
||||
{
|
||||
static int on = -1;
|
||||
if (on < 0) {
|
||||
const char *v = getenv("DROIDDECK_MALI_COMPAT_TRACE");
|
||||
on = v && *v && strcmp(v, "0") != 0;
|
||||
}
|
||||
return on;
|
||||
}
|
||||
|
||||
static bool has_extension(struct instance *inst, VkPhysicalDevice physical_device, const char *name)
|
||||
{
|
||||
uint32_t count = 0;
|
||||
inst->EnumerateDeviceExtensionProperties(physical_device, NULL, &count, NULL);
|
||||
VkExtensionProperties *extensions = calloc(count, sizeof(*extensions));
|
||||
inst->EnumerateDeviceExtensionProperties(physical_device, NULL, &count, extensions);
|
||||
bool found = false;
|
||||
for (uint32_t i = 0; i < count && !found; i++)
|
||||
found = strcmp(extensions[i].extensionName, name) == 0;
|
||||
free(extensions);
|
||||
return found;
|
||||
}
|
||||
|
||||
uint32_t physical_device_gaps(struct instance *inst, VkPhysicalDevice physical_device)
|
||||
{
|
||||
pthread_mutex_lock(&inst->lock);
|
||||
for (uint32_t i = 0; i < inst->physical_device_count; i++) {
|
||||
if (inst->physical_devices[i].handle == physical_device) {
|
||||
uint32_t gaps = inst->physical_devices[i].gaps;
|
||||
pthread_mutex_unlock(&inst->lock);
|
||||
return gaps;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&inst->lock);
|
||||
|
||||
bool robustness2 = has_extension(inst, physical_device, "VK_EXT_robustness2");
|
||||
VkPhysicalDeviceRobustness2FeaturesEXT robust = {
|
||||
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT,
|
||||
};
|
||||
VkPhysicalDeviceFeatures2 features = {
|
||||
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2,
|
||||
.pNext = robustness2 ? &robust : NULL,
|
||||
};
|
||||
inst->GetPhysicalDeviceFeatures2(physical_device, &features);
|
||||
uint32_t gaps = 0;
|
||||
if (!features.features.fillModeNonSolid)
|
||||
gaps |= GAP_FILL_MODE;
|
||||
if (!features.features.multiViewport)
|
||||
gaps |= GAP_MULTI_VIEWPORT;
|
||||
if (!features.features.shaderClipDistance)
|
||||
gaps |= GAP_CLIP_DISTANCE;
|
||||
if (!features.features.shaderCullDistance)
|
||||
gaps |= GAP_CULL_DISTANCE;
|
||||
if (!features.features.textureCompressionBC)
|
||||
gaps |= GAP_BC;
|
||||
if (robustness2 && !robust.robustBufferAccess2)
|
||||
gaps |= GAP_ROBUSTNESS2;
|
||||
if (!features.features.multiDrawIndirect)
|
||||
gaps |= GAP_MULTI_DRAW;
|
||||
if (!has_extension(inst, physical_device, VK_EXT_DEPTH_CLIP_ENABLE_EXTENSION_NAME))
|
||||
gaps |= GAP_DEPTH_CLIP;
|
||||
/* No robustness2 at all: the extension is offered with robustBufferAccess2 (as robustBufferAccess)
|
||||
* and nullDescriptor (stand-ins, draw.c). */
|
||||
if (!robustness2)
|
||||
gaps |= GAP_ROBUSTNESS2 | GAP_NULL_DESCRIPTOR;
|
||||
|
||||
pthread_mutex_lock(&inst->lock);
|
||||
if (inst->physical_device_count < sizeof(inst->physical_devices) / sizeof(inst->physical_devices[0])) {
|
||||
inst->physical_devices[inst->physical_device_count++] =
|
||||
(struct physical_device){.handle = physical_device, .gaps = gaps};
|
||||
}
|
||||
pthread_mutex_unlock(&inst->lock);
|
||||
return gaps;
|
||||
}
|
||||
|
||||
/* Structures of extensions the driver does not have are taken out of a chain for the call down and
|
||||
* put back after it: the driver (and Venus) must not see them. */
|
||||
struct unlinked {
|
||||
VkBaseOutStructure *prev, *node;
|
||||
};
|
||||
|
||||
static uint32_t unlink_types(void *head, const VkStructureType *types, uint32_t type_count,
|
||||
struct unlinked *out, uint32_t max)
|
||||
{
|
||||
uint32_t n = 0;
|
||||
VkBaseOutStructure *prev = head;
|
||||
while (prev && prev->pNext && n < max) {
|
||||
VkBaseOutStructure *s = prev->pNext;
|
||||
bool drop = false;
|
||||
for (uint32_t i = 0; i < type_count; i++)
|
||||
drop |= s->sType == types[i];
|
||||
if (drop) {
|
||||
out[n++] = (struct unlinked){prev, s};
|
||||
prev->pNext = s->pNext;
|
||||
} else {
|
||||
prev = s;
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
static void relink(struct unlinked *list, uint32_t n)
|
||||
{
|
||||
while (n--)
|
||||
list[n].prev->pNext = list[n].node;
|
||||
}
|
||||
|
||||
static uint32_t foreign_types(uint32_t gaps, VkStructureType *types)
|
||||
{
|
||||
uint32_t n = 0;
|
||||
if (gaps & GAP_DEPTH_CLIP)
|
||||
types[n++] = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT;
|
||||
if (gaps & GAP_NULL_DESCRIPTOR)
|
||||
types[n++] = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT;
|
||||
return n;
|
||||
}
|
||||
|
||||
static void report_features(VkPhysicalDeviceFeatures *features, uint32_t gaps)
|
||||
{
|
||||
if (gaps & GAP_FILL_MODE)
|
||||
features->fillModeNonSolid = VK_TRUE;
|
||||
if (gaps & GAP_MULTI_VIEWPORT)
|
||||
features->multiViewport = VK_TRUE;
|
||||
if (gaps & GAP_CLIP_DISTANCE)
|
||||
features->shaderClipDistance = VK_TRUE;
|
||||
if (gaps & GAP_CULL_DISTANCE)
|
||||
features->shaderCullDistance = VK_TRUE;
|
||||
if (gaps & GAP_BC)
|
||||
features->textureCompressionBC = VK_TRUE;
|
||||
if (gaps & GAP_MULTI_DRAW)
|
||||
features->multiDrawIndirect = VK_TRUE;
|
||||
}
|
||||
|
||||
/* Which made-up features the application asked for, and off with them before the driver sees them. */
|
||||
static uint32_t take_features(VkPhysicalDeviceFeatures *features, uint32_t gaps)
|
||||
{
|
||||
uint32_t requested = 0;
|
||||
if ((gaps & GAP_FILL_MODE) && features->fillModeNonSolid) {
|
||||
requested |= GAP_FILL_MODE;
|
||||
features->fillModeNonSolid = VK_FALSE;
|
||||
}
|
||||
if ((gaps & GAP_MULTI_VIEWPORT) && features->multiViewport) {
|
||||
requested |= GAP_MULTI_VIEWPORT;
|
||||
features->multiViewport = VK_FALSE;
|
||||
}
|
||||
if ((gaps & GAP_CLIP_DISTANCE) && features->shaderClipDistance) {
|
||||
requested |= GAP_CLIP_DISTANCE;
|
||||
features->shaderClipDistance = VK_FALSE;
|
||||
}
|
||||
if ((gaps & GAP_CULL_DISTANCE) && features->shaderCullDistance) {
|
||||
requested |= GAP_CULL_DISTANCE;
|
||||
features->shaderCullDistance = VK_FALSE;
|
||||
}
|
||||
if ((gaps & GAP_BC) && features->textureCompressionBC) {
|
||||
requested |= GAP_BC;
|
||||
features->textureCompressionBC = VK_FALSE;
|
||||
}
|
||||
if ((gaps & GAP_MULTI_DRAW) && features->multiDrawIndirect) {
|
||||
requested |= GAP_MULTI_DRAW;
|
||||
features->multiDrawIndirect = VK_FALSE;
|
||||
}
|
||||
return requested;
|
||||
}
|
||||
|
||||
static void report_limits(VkPhysicalDeviceLimits *limits, uint32_t gaps)
|
||||
{
|
||||
if (gaps & GAP_MULTI_VIEWPORT)
|
||||
limits->maxViewports = 16;
|
||||
if ((gaps & GAP_MULTI_DRAW) && limits->maxDrawIndirectCount < (1u << 30))
|
||||
limits->maxDrawIndirectCount = 1u << 30;
|
||||
if (gaps & GAPS_SHADER) {
|
||||
limits->maxClipDistances = 8;
|
||||
limits->maxCullDistances = 8;
|
||||
limits->maxCombinedClipAndCullDistances = 8;
|
||||
}
|
||||
}
|
||||
|
||||
static VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceFeatures(VkPhysicalDevice physical_device,
|
||||
VkPhysicalDeviceFeatures *features)
|
||||
{
|
||||
struct instance *inst = instance_from_handle(physical_device);
|
||||
inst->GetPhysicalDeviceFeatures(physical_device, features);
|
||||
report_features(features, physical_device_gaps(inst, physical_device));
|
||||
}
|
||||
|
||||
static VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceFeatures2(VkPhysicalDevice physical_device,
|
||||
VkPhysicalDeviceFeatures2 *features)
|
||||
{
|
||||
struct instance *inst = instance_from_handle(physical_device);
|
||||
uint32_t gaps = physical_device_gaps(inst, physical_device);
|
||||
VkStructureType types[4];
|
||||
struct unlinked dropped[8];
|
||||
uint32_t dropped_count = unlink_types(features, types, foreign_types(gaps, types), dropped, 8);
|
||||
inst->GetPhysicalDeviceFeatures2(physical_device, features);
|
||||
relink(dropped, dropped_count);
|
||||
report_features(&features->features, gaps);
|
||||
if (tracing()) {
|
||||
char chain[512] = "";
|
||||
size_t used = 0;
|
||||
for (VkBaseOutStructure *s = features->pNext; s && used + 16 < sizeof(chain); s = s->pNext)
|
||||
used += (size_t)snprintf(chain + used, sizeof(chain) - used, " %d", (int)s->sType);
|
||||
layer_log("trace: vkGetPhysicalDeviceFeatures2 (gaps 0x%x, %u structures held back), chain:%s", gaps, dropped_count, chain);
|
||||
}
|
||||
for (VkBaseOutStructure *s = features->pNext; s; s = s->pNext) {
|
||||
if (s->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT && (gaps & GAP_ROBUSTNESS2)) {
|
||||
((VkPhysicalDeviceRobustness2FeaturesEXT *)s)->robustBufferAccess2 = VK_TRUE;
|
||||
if (gaps & GAP_NULL_DESCRIPTOR)
|
||||
((VkPhysicalDeviceRobustness2FeaturesEXT *)s)->nullDescriptor = VK_TRUE;
|
||||
}
|
||||
if (s->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT && (gaps & GAP_DEPTH_CLIP))
|
||||
((VkPhysicalDeviceDepthClipEnableFeaturesEXT *)s)->depthClipEnable = VK_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
static VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceProperties(VkPhysicalDevice physical_device,
|
||||
VkPhysicalDeviceProperties *properties)
|
||||
{
|
||||
struct instance *inst = instance_from_handle(physical_device);
|
||||
inst->GetPhysicalDeviceProperties(physical_device, properties);
|
||||
report_limits(&properties->limits, physical_device_gaps(inst, physical_device));
|
||||
}
|
||||
|
||||
static VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceProperties2(VkPhysicalDevice physical_device,
|
||||
VkPhysicalDeviceProperties2 *properties)
|
||||
{
|
||||
struct instance *inst = instance_from_handle(physical_device);
|
||||
inst->GetPhysicalDeviceProperties2(physical_device, properties);
|
||||
report_limits(&properties->properties.limits, physical_device_gaps(inst, physical_device));
|
||||
if (tracing())
|
||||
layer_log("trace: vkGetPhysicalDeviceProperties2: %s, Vulkan %u.%u.%u, type %d", properties->properties.deviceName,
|
||||
VK_API_VERSION_MAJOR(properties->properties.apiVersion), VK_API_VERSION_MINOR(properties->properties.apiVersion),
|
||||
VK_API_VERSION_PATCH(properties->properties.apiVersion), (int)properties->properties.deviceType);
|
||||
}
|
||||
|
||||
/* The extensions the layer stands in for, added to the driver's list. */
|
||||
static VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceExtensionProperties(VkPhysicalDevice physical_device,
|
||||
const char *layer_name, uint32_t *count,
|
||||
VkExtensionProperties *properties)
|
||||
{
|
||||
struct instance *inst = instance_from_handle(physical_device);
|
||||
if (layer_name)
|
||||
return inst->EnumerateDeviceExtensionProperties(physical_device, layer_name, count, properties);
|
||||
uint32_t gaps = physical_device_gaps(inst, physical_device);
|
||||
VkExtensionProperties extra[2];
|
||||
uint32_t extra_count = 0;
|
||||
if (gaps & GAP_DEPTH_CLIP)
|
||||
extra[extra_count++] = (VkExtensionProperties){VK_EXT_DEPTH_CLIP_ENABLE_EXTENSION_NAME, 1};
|
||||
if (gaps & GAP_NULL_DESCRIPTOR)
|
||||
extra[extra_count++] = (VkExtensionProperties){VK_EXT_ROBUSTNESS_2_EXTENSION_NAME, 1};
|
||||
uint32_t own = 0;
|
||||
VkResult result = inst->EnumerateDeviceExtensionProperties(physical_device, NULL, &own, NULL);
|
||||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
if (!properties) {
|
||||
*count = own + extra_count;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
VkExtensionProperties *all = calloc(own + extra_count, sizeof(*all));
|
||||
inst->EnumerateDeviceExtensionProperties(physical_device, NULL, &own, all);
|
||||
memcpy(all + own, extra, extra_count * sizeof(*extra));
|
||||
uint32_t total = own + extra_count;
|
||||
if (tracing()) {
|
||||
layer_log("trace: vkEnumerateDeviceExtensionProperties: %u from the driver, %u added by the layer", own, extra_count);
|
||||
trace_extension_names(all, total);
|
||||
}
|
||||
uint32_t n = *count < total ? *count : total;
|
||||
memcpy(properties, all, n * sizeof(*all));
|
||||
free(all);
|
||||
*count = n;
|
||||
return n < total ? VK_INCOMPLETE : VK_SUCCESS;
|
||||
}
|
||||
|
||||
static VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo *info,
|
||||
const VkAllocationCallbacks *allocator, VkInstance *instance)
|
||||
{
|
||||
VkLayerInstanceCreateInfo *link = (VkLayerInstanceCreateInfo *)info->pNext;
|
||||
while (link && !(link->sType == VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO && link->function == VK_LAYER_LINK_INFO))
|
||||
link = (VkLayerInstanceCreateInfo *)link->pNext;
|
||||
if (!link)
|
||||
return VK_ERROR_INITIALIZATION_FAILED;
|
||||
PFN_vkGetInstanceProcAddr gipa = link->u.pLayerInfo->pfnNextGetInstanceProcAddr;
|
||||
link->u.pLayerInfo = link->u.pLayerInfo->pNext;
|
||||
|
||||
PFN_vkCreateInstance create = (PFN_vkCreateInstance)gipa(VK_NULL_HANDLE, "vkCreateInstance");
|
||||
VkResult result = create(info, allocator, instance);
|
||||
if (tracing())
|
||||
layer_log("trace: vkCreateInstance for %s (API %u.%u): %d, layer %s", info->pApplicationInfo && info->pApplicationInfo->pApplicationName ?
|
||||
info->pApplicationInfo->pApplicationName : "?", info->pApplicationInfo ? VK_API_VERSION_MAJOR(info->pApplicationInfo->apiVersion) : 0,
|
||||
info->pApplicationInfo ? VK_API_VERSION_MINOR(info->pApplicationInfo->apiVersion) : 0, (int)result, wanted() ? "active" : "idle");
|
||||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
|
||||
struct instance *inst = calloc(1, sizeof(*inst));
|
||||
inst->key = dispatch_key(*instance);
|
||||
inst->handle = *instance;
|
||||
inst->active = wanted();
|
||||
inst->gipa = gipa;
|
||||
pthread_mutex_init(&inst->lock, NULL);
|
||||
#define LOAD(name) inst->name = (PFN_vk##name)gipa(*instance, "vk" #name);
|
||||
#define LOAD_KHR(name) \
|
||||
if (!inst->name) \
|
||||
inst->name = (PFN_vk##name)gipa(*instance, "vk" #name "KHR");
|
||||
LOAD(DestroyInstance)
|
||||
LOAD(EnumerateDeviceExtensionProperties)
|
||||
LOAD(GetPhysicalDeviceFeatures)
|
||||
LOAD(GetPhysicalDeviceFeatures2)
|
||||
LOAD_KHR(GetPhysicalDeviceFeatures2)
|
||||
LOAD(GetPhysicalDeviceProperties)
|
||||
LOAD(GetPhysicalDeviceProperties2)
|
||||
LOAD_KHR(GetPhysicalDeviceProperties2)
|
||||
LOAD(GetPhysicalDeviceMemoryProperties)
|
||||
LOAD(GetPhysicalDeviceFormatProperties)
|
||||
LOAD(GetPhysicalDeviceFormatProperties2)
|
||||
LOAD_KHR(GetPhysicalDeviceFormatProperties2)
|
||||
LOAD(GetPhysicalDeviceImageFormatProperties)
|
||||
LOAD(GetPhysicalDeviceImageFormatProperties2)
|
||||
LOAD_KHR(GetPhysicalDeviceImageFormatProperties2)
|
||||
#undef LOAD
|
||||
#undef LOAD_KHR
|
||||
if (tracing())
|
||||
trace_load(inst);
|
||||
/* Without the Vulkan 1.1 queries there is no way to answer the chained ones. */
|
||||
if (!inst->GetPhysicalDeviceFeatures2 || !inst->GetPhysicalDeviceProperties2 ||
|
||||
!inst->GetPhysicalDeviceFormatProperties2 || !inst->GetPhysicalDeviceImageFormatProperties2)
|
||||
inst->active = false;
|
||||
|
||||
pthread_mutex_lock(&global_lock);
|
||||
inst->next = instances;
|
||||
instances = inst;
|
||||
pthread_mutex_unlock(&global_lock);
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
static VKAPI_ATTR void VKAPI_CALL DestroyInstance(VkInstance instance, const VkAllocationCallbacks *allocator)
|
||||
{
|
||||
void *key = dispatch_key(instance);
|
||||
pthread_mutex_lock(&global_lock);
|
||||
struct instance **link = &instances;
|
||||
while (*link && (*link)->key != key)
|
||||
link = &(*link)->next;
|
||||
struct instance *inst = *link;
|
||||
if (inst)
|
||||
*link = inst->next;
|
||||
pthread_mutex_unlock(&global_lock);
|
||||
if (!inst)
|
||||
return;
|
||||
inst->DestroyInstance(instance, allocator);
|
||||
pthread_mutex_destroy(&inst->lock);
|
||||
free(inst);
|
||||
}
|
||||
|
||||
static VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice physical_device, const VkDeviceCreateInfo *info,
|
||||
const VkAllocationCallbacks *allocator, VkDevice *device)
|
||||
{
|
||||
VkLayerDeviceCreateInfo *link = (VkLayerDeviceCreateInfo *)info->pNext;
|
||||
while (link && !(link->sType == VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO && link->function == VK_LAYER_LINK_INFO))
|
||||
link = (VkLayerDeviceCreateInfo *)link->pNext;
|
||||
if (!link)
|
||||
return VK_ERROR_INITIALIZATION_FAILED;
|
||||
PFN_vkGetInstanceProcAddr gipa = link->u.pLayerInfo->pfnNextGetInstanceProcAddr;
|
||||
PFN_vkGetDeviceProcAddr gdpa = link->u.pLayerInfo->pfnNextGetDeviceProcAddr;
|
||||
link->u.pLayerInfo = link->u.pLayerInfo->pNext;
|
||||
|
||||
struct instance *inst = instance_from_handle(physical_device);
|
||||
PFN_vkCreateDevice create = (PFN_vkCreateDevice)gipa(inst->handle, "vkCreateDevice");
|
||||
uint32_t gaps = inst->active ? physical_device_gaps(inst, physical_device) : 0;
|
||||
|
||||
/* The application's own structures are put back after the call: DXVK reads its enabled
|
||||
* features again later, and must keep seeing what it asked for. */
|
||||
VkDeviceCreateInfo copy = *info;
|
||||
VkPhysicalDeviceFeatures features;
|
||||
VkPhysicalDeviceFeatures2 *features2 = NULL;
|
||||
VkPhysicalDeviceRobustness2FeaturesEXT *robust = NULL;
|
||||
for (VkBaseOutStructure *s = (VkBaseOutStructure *)info->pNext; s; s = s->pNext) {
|
||||
if (s->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2)
|
||||
features2 = (VkPhysicalDeviceFeatures2 *)s;
|
||||
else if (s->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT)
|
||||
robust = (VkPhysicalDeviceRobustness2FeaturesEXT *)s;
|
||||
}
|
||||
VkPhysicalDeviceFeatures *enabled = NULL;
|
||||
VkPhysicalDeviceFeatures saved_features = {0};
|
||||
if (info->pEnabledFeatures) {
|
||||
features = *info->pEnabledFeatures;
|
||||
copy.pEnabledFeatures = &features;
|
||||
enabled = &features;
|
||||
} else if (features2) {
|
||||
saved_features = features2->features;
|
||||
enabled = &features2->features;
|
||||
}
|
||||
uint32_t requested = enabled ? take_features(enabled, gaps) : 0;
|
||||
VkBool32 saved_robust = robust ? robust->robustBufferAccess2 : VK_FALSE;
|
||||
if (robust && (gaps & GAP_ROBUSTNESS2) && robust->robustBufferAccess2) {
|
||||
requested |= GAP_ROBUSTNESS2;
|
||||
robust->robustBufferAccess2 = VK_FALSE;
|
||||
/* The first version of robust buffer access is the nearest the driver has. */
|
||||
if (enabled)
|
||||
enabled->robustBufferAccess = VK_TRUE;
|
||||
}
|
||||
|
||||
/* The extensions the layer stands in for leave the list, and their structures the chain. */
|
||||
const char **names = NULL;
|
||||
if (gaps & (GAP_DEPTH_CLIP | GAP_NULL_DESCRIPTOR)) {
|
||||
names = malloc((info->enabledExtensionCount ? info->enabledExtensionCount : 1) * sizeof(*names));
|
||||
copy.enabledExtensionCount = 0;
|
||||
for (uint32_t i = 0; i < info->enabledExtensionCount; i++) {
|
||||
const char *name = info->ppEnabledExtensionNames[i];
|
||||
if ((gaps & GAP_DEPTH_CLIP) && !strcmp(name, VK_EXT_DEPTH_CLIP_ENABLE_EXTENSION_NAME)) {
|
||||
requested |= GAP_DEPTH_CLIP;
|
||||
continue;
|
||||
}
|
||||
if ((gaps & GAP_NULL_DESCRIPTOR) && !strcmp(name, VK_EXT_ROBUSTNESS_2_EXTENSION_NAME)) {
|
||||
requested |= GAP_NULL_DESCRIPTOR;
|
||||
if (enabled)
|
||||
enabled->robustBufferAccess = VK_TRUE;
|
||||
continue;
|
||||
}
|
||||
names[copy.enabledExtensionCount++] = name;
|
||||
}
|
||||
copy.ppEnabledExtensionNames = names;
|
||||
}
|
||||
VkStructureType foreign[4];
|
||||
struct unlinked dropped[8];
|
||||
uint32_t dropped_count = unlink_types(©, foreign, foreign_types(gaps, foreign), dropped, 8);
|
||||
|
||||
VkResult result = create(physical_device, ©, allocator, device);
|
||||
|
||||
relink(dropped, dropped_count);
|
||||
free(names);
|
||||
if (features2 && !info->pEnabledFeatures)
|
||||
features2->features = saved_features;
|
||||
if (robust)
|
||||
robust->robustBufferAccess2 = saved_robust;
|
||||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
|
||||
struct device *dev = calloc(1, sizeof(*dev));
|
||||
dev->key = dispatch_key(*device);
|
||||
dev->handle = *device;
|
||||
dev->gdpa = gdpa;
|
||||
dev->emulated = requested;
|
||||
pthread_mutex_init(&dev->lock, NULL);
|
||||
#define LOAD(name) \
|
||||
dev->name = (PFN_vk##name)gdpa(*device, "vk" #name); \
|
||||
if (!dev->name) \
|
||||
dev->name = (PFN_vk##name)gdpa(*device, "vk" #name "KHR"); \
|
||||
if (!dev->name) \
|
||||
dev->name = (PFN_vk##name)gdpa(*device, "vk" #name "EXT");
|
||||
DEVICE_FUNCTIONS(LOAD)
|
||||
#undef LOAD
|
||||
inst->GetPhysicalDeviceMemoryProperties(physical_device, &dev->memory_properties);
|
||||
VkPhysicalDeviceProperties properties;
|
||||
inst->GetPhysicalDeviceProperties(physical_device, &properties);
|
||||
uint32_t components = properties.limits.maxVertexOutputComponents;
|
||||
if (properties.limits.maxFragmentInputComponents < components)
|
||||
components = properties.limits.maxFragmentInputComponents;
|
||||
dev->max_varying_locations = components / 4;
|
||||
|
||||
pthread_mutex_lock(&global_lock);
|
||||
dev->next = devices;
|
||||
devices = dev;
|
||||
pthread_mutex_unlock(&global_lock);
|
||||
|
||||
if (requested) {
|
||||
layer_log("emulating%s%s%s%s%s%s%s%s%s for %s", (requested & GAP_FILL_MODE) ? " fillModeNonSolid" : "",
|
||||
(requested & GAP_MULTI_VIEWPORT) ? " multiViewport" : "",
|
||||
(requested & GAP_CLIP_DISTANCE) ? " shaderClipDistance" : "",
|
||||
(requested & GAP_CULL_DISTANCE) ? " shaderCullDistance" : "",
|
||||
(requested & GAP_ROBUSTNESS2) ? " robustBufferAccess2" : "",
|
||||
(requested & GAP_BC) ? " textureCompressionBC" : "",
|
||||
(requested & GAP_MULTI_DRAW) ? " multiDrawIndirect" : "",
|
||||
(requested & GAP_DEPTH_CLIP) ? " depthClipEnable" : "",
|
||||
(requested & GAP_NULL_DESCRIPTOR) ? " nullDescriptor" : "", properties.deviceName);
|
||||
}
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
static VKAPI_ATTR void VKAPI_CALL DestroyDevice(VkDevice device, const VkAllocationCallbacks *allocator)
|
||||
{
|
||||
void *key = dispatch_key(device);
|
||||
pthread_mutex_lock(&global_lock);
|
||||
struct device **link = &devices;
|
||||
while (*link && (*link)->key != key)
|
||||
link = &(*link)->next;
|
||||
struct device *dev = *link;
|
||||
if (dev)
|
||||
*link = dev->next;
|
||||
pthread_mutex_unlock(&global_lock);
|
||||
if (!dev)
|
||||
return;
|
||||
bc_destroy_device(dev);
|
||||
null_resources_destroy(dev);
|
||||
dev->DestroyDevice(device, allocator);
|
||||
for (uint32_t i = 0; i < dev->shader_modules.capacity; i++) {
|
||||
struct spirv_code *code = dev->shader_modules.values[i];
|
||||
if (code) {
|
||||
free(code->words);
|
||||
free(code);
|
||||
}
|
||||
}
|
||||
map_free(&dev->shader_modules);
|
||||
pthread_mutex_destroy(&dev->lock);
|
||||
free(dev);
|
||||
}
|
||||
|
||||
struct hook {
|
||||
const char *name;
|
||||
PFN_vkVoidFunction function;
|
||||
uint32_t gaps;
|
||||
};
|
||||
|
||||
#define HOOK(name, gaps) {"vk" #name, (PFN_vkVoidFunction)name, gaps}
|
||||
#define HOOK_ALIAS(name, alias, gaps) {"vk" #alias, (PFN_vkVoidFunction)name, gaps}
|
||||
|
||||
static const struct hook device_hooks[] = {
|
||||
HOOK(CreateShaderModule, GAPS_SHADER),
|
||||
HOOK(DestroyShaderModule, GAPS_SHADER),
|
||||
HOOK(CreateGraphicsPipelines, GAPS_PIPELINE),
|
||||
HOOK(CmdSetViewport, GAP_MULTI_VIEWPORT),
|
||||
HOOK(CmdSetScissor, GAP_MULTI_VIEWPORT),
|
||||
HOOK(CmdSetViewportWithCount, GAP_MULTI_VIEWPORT),
|
||||
HOOK_ALIAS(CmdSetViewportWithCount, CmdSetViewportWithCountEXT, GAP_MULTI_VIEWPORT),
|
||||
HOOK(CmdSetScissorWithCount, GAP_MULTI_VIEWPORT),
|
||||
HOOK_ALIAS(CmdSetScissorWithCount, CmdSetScissorWithCountEXT, GAP_MULTI_VIEWPORT),
|
||||
HOOK(CreateImage, GAP_BC),
|
||||
HOOK(DestroyImage, GAP_BC),
|
||||
HOOK(CreateImageView, GAP_BC),
|
||||
HOOK(GetDeviceImageMemoryRequirements, GAP_BC),
|
||||
HOOK_ALIAS(GetDeviceImageMemoryRequirements, GetDeviceImageMemoryRequirementsKHR, GAP_BC),
|
||||
HOOK(GetDeviceImageSparseMemoryRequirements, GAP_BC),
|
||||
HOOK_ALIAS(GetDeviceImageSparseMemoryRequirements, GetDeviceImageSparseMemoryRequirementsKHR, GAP_BC),
|
||||
HOOK(GetDeviceImageSubresourceLayout, GAP_BC),
|
||||
HOOK_ALIAS(GetDeviceImageSubresourceLayout, GetDeviceImageSubresourceLayoutKHR, GAP_BC),
|
||||
HOOK(CmdCopyBufferToImage, GAP_BC),
|
||||
HOOK(CmdCopyBufferToImage2, GAP_BC),
|
||||
HOOK_ALIAS(CmdCopyBufferToImage2, CmdCopyBufferToImage2KHR, GAP_BC),
|
||||
HOOK(CmdCopyImageToBuffer, GAP_BC),
|
||||
HOOK(CmdCopyImageToBuffer2, GAP_BC),
|
||||
HOOK_ALIAS(CmdCopyImageToBuffer2, CmdCopyImageToBuffer2KHR, GAP_BC),
|
||||
HOOK(CmdCopyImage, GAP_BC),
|
||||
HOOK(CmdCopyImage2, GAP_BC),
|
||||
HOOK_ALIAS(CmdCopyImage2, CmdCopyImage2KHR, GAP_BC),
|
||||
HOOK(BindBufferMemory, GAP_BC),
|
||||
HOOK(BindBufferMemory2, GAP_BC),
|
||||
HOOK_ALIAS(BindBufferMemory2, BindBufferMemory2KHR, GAP_BC),
|
||||
HOOK(DestroyBuffer, GAP_BC),
|
||||
HOOK(FreeMemory, GAP_BC),
|
||||
HOOK(MapMemory, GAP_BC),
|
||||
HOOK(MapMemory2, GAP_BC),
|
||||
HOOK_ALIAS(MapMemory2, MapMemory2KHR, GAP_BC),
|
||||
HOOK(UnmapMemory, GAP_BC),
|
||||
HOOK(UnmapMemory2, GAP_BC),
|
||||
HOOK_ALIAS(UnmapMemory2, UnmapMemory2KHR, GAP_BC),
|
||||
HOOK(AllocateCommandBuffers, GAP_BC),
|
||||
HOOK(FreeCommandBuffers, GAP_BC),
|
||||
HOOK(BeginCommandBuffer, GAP_BC),
|
||||
HOOK(ResetCommandBuffer, GAP_BC),
|
||||
HOOK(ResetCommandPool, GAP_BC),
|
||||
HOOK(DestroyCommandPool, GAP_BC),
|
||||
HOOK(CmdDrawIndirect, GAP_MULTI_DRAW),
|
||||
HOOK(CmdDrawIndexedIndirect, GAP_MULTI_DRAW),
|
||||
HOOK(UpdateDescriptorSets, GAP_NULL_DESCRIPTOR),
|
||||
HOOK(CmdPushDescriptorSet, GAP_NULL_DESCRIPTOR),
|
||||
HOOK_ALIAS(CmdPushDescriptorSet, CmdPushDescriptorSetKHR, GAP_NULL_DESCRIPTOR),
|
||||
HOOK(CreateDescriptorUpdateTemplate, GAP_NULL_DESCRIPTOR),
|
||||
HOOK_ALIAS(CreateDescriptorUpdateTemplate, CreateDescriptorUpdateTemplateKHR, GAP_NULL_DESCRIPTOR),
|
||||
HOOK(DestroyDescriptorUpdateTemplate, GAP_NULL_DESCRIPTOR),
|
||||
HOOK_ALIAS(DestroyDescriptorUpdateTemplate, DestroyDescriptorUpdateTemplateKHR, GAP_NULL_DESCRIPTOR),
|
||||
HOOK(UpdateDescriptorSetWithTemplate, GAP_NULL_DESCRIPTOR),
|
||||
HOOK_ALIAS(UpdateDescriptorSetWithTemplate, UpdateDescriptorSetWithTemplateKHR, GAP_NULL_DESCRIPTOR),
|
||||
HOOK(CmdPushDescriptorSetWithTemplate, GAP_NULL_DESCRIPTOR),
|
||||
HOOK_ALIAS(CmdPushDescriptorSetWithTemplate, CmdPushDescriptorSetWithTemplateKHR, GAP_NULL_DESCRIPTOR),
|
||||
HOOK(CmdBindVertexBuffers, GAP_NULL_DESCRIPTOR),
|
||||
HOOK(CmdBindVertexBuffers2, GAP_NULL_DESCRIPTOR),
|
||||
HOOK_ALIAS(CmdBindVertexBuffers2, CmdBindVertexBuffers2EXT, GAP_NULL_DESCRIPTOR),
|
||||
};
|
||||
|
||||
static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char *name);
|
||||
|
||||
static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char *name)
|
||||
{
|
||||
if (!strcmp(name, "vkGetDeviceProcAddr"))
|
||||
return (PFN_vkVoidFunction)GetDeviceProcAddr;
|
||||
struct device *dev = device_from_handle(device);
|
||||
if (!dev)
|
||||
return NULL;
|
||||
if (!strcmp(name, "vkDestroyDevice"))
|
||||
return (PFN_vkVoidFunction)DestroyDevice;
|
||||
PFN_vkVoidFunction next = dev->gdpa(device, name);
|
||||
if (!next)
|
||||
return NULL;
|
||||
for (size_t i = 0; i < sizeof(device_hooks) / sizeof(device_hooks[0]); i++) {
|
||||
if ((dev->emulated & device_hooks[i].gaps) && !strcmp(name, device_hooks[i].name))
|
||||
return device_hooks[i].function;
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
static const struct hook physical_device_hooks[] = {
|
||||
HOOK(EnumerateDeviceExtensionProperties, 0),
|
||||
HOOK(GetPhysicalDeviceFeatures, 0),
|
||||
HOOK(GetPhysicalDeviceFeatures2, 0),
|
||||
HOOK_ALIAS(GetPhysicalDeviceFeatures2, GetPhysicalDeviceFeatures2KHR, 0),
|
||||
HOOK(GetPhysicalDeviceProperties, 0),
|
||||
HOOK(GetPhysicalDeviceProperties2, 0),
|
||||
HOOK_ALIAS(GetPhysicalDeviceProperties2, GetPhysicalDeviceProperties2KHR, 0),
|
||||
HOOK(GetPhysicalDeviceFormatProperties, 0),
|
||||
HOOK(GetPhysicalDeviceFormatProperties2, 0),
|
||||
HOOK_ALIAS(GetPhysicalDeviceFormatProperties2, GetPhysicalDeviceFormatProperties2KHR, 0),
|
||||
HOOK(GetPhysicalDeviceImageFormatProperties, 0),
|
||||
HOOK(GetPhysicalDeviceImageFormatProperties2, 0),
|
||||
HOOK_ALIAS(GetPhysicalDeviceImageFormatProperties2, GetPhysicalDeviceImageFormatProperties2KHR, 0),
|
||||
};
|
||||
|
||||
static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance instance, const char *name)
|
||||
{
|
||||
if (!strcmp(name, "vkGetInstanceProcAddr"))
|
||||
return (PFN_vkVoidFunction)GetInstanceProcAddr;
|
||||
if (!strcmp(name, "vkCreateInstance"))
|
||||
return (PFN_vkVoidFunction)CreateInstance;
|
||||
if (!strcmp(name, "vkGetDeviceProcAddr"))
|
||||
return (PFN_vkVoidFunction)GetDeviceProcAddr;
|
||||
if (!instance)
|
||||
return NULL;
|
||||
struct instance *inst = instance_from_handle(instance);
|
||||
if (!inst)
|
||||
return NULL;
|
||||
if (!strcmp(name, "vkDestroyInstance"))
|
||||
return (PFN_vkVoidFunction)DestroyInstance;
|
||||
/* Always ours, even when inactive: each layer moves the device chain one link on. */
|
||||
if (!strcmp(name, "vkCreateDevice"))
|
||||
return (PFN_vkVoidFunction)CreateDevice;
|
||||
PFN_vkVoidFunction next = inst->gipa(instance, name);
|
||||
if (next && tracing()) {
|
||||
PFN_vkVoidFunction traced = trace_hook(inst, name);
|
||||
if (traced)
|
||||
return traced;
|
||||
}
|
||||
if (!next || !inst->active)
|
||||
return next;
|
||||
for (size_t i = 0; i < sizeof(physical_device_hooks) / sizeof(physical_device_hooks[0]); i++) {
|
||||
if (!strcmp(name, physical_device_hooks[i].name))
|
||||
return physical_device_hooks[i].function;
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
__attribute__((visibility("default"))) VKAPI_ATTR VkResult VKAPI_CALL
|
||||
vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *interface)
|
||||
{
|
||||
if (interface->loaderLayerInterfaceVersion < 2)
|
||||
return VK_ERROR_INITIALIZATION_FAILED;
|
||||
interface->loaderLayerInterfaceVersion = 2;
|
||||
interface->pfnGetInstanceProcAddr = GetInstanceProcAddr;
|
||||
interface->pfnGetDeviceProcAddr = GetDeviceProcAddr;
|
||||
interface->pfnGetPhysicalDeviceProcAddr = NULL;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
/*
|
||||
* VK_LAYER_DROIDDECK_mali_compat: makes up for what Mali lacks and DXVK requires.
|
||||
*
|
||||
* DXVK refuses any GPU without fillModeNonSolid, multiViewport, shaderClipDistance,
|
||||
* shaderCullDistance, textureCompressionBC and robustBufferAccess2, and Mali has none of them.
|
||||
* The layer reports each missing feature as supported, keeps it out of the driver's device, and
|
||||
* handles what uses it: polygon modes draw filled, only the first viewport is kept, clip distances
|
||||
* become a varying the fragment shader discards on, cull distances are dropped, and BC textures
|
||||
* are decoded on the CPU into uncompressed images as they are uploaded.
|
||||
*/
|
||||
#ifndef MALI_COMPAT_H
|
||||
#define MALI_COMPAT_H
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <vulkan/vk_layer.h>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
enum gap {
|
||||
GAP_FILL_MODE = 1u << 0,
|
||||
GAP_MULTI_VIEWPORT = 1u << 1,
|
||||
GAP_CLIP_DISTANCE = 1u << 2,
|
||||
GAP_CULL_DISTANCE = 1u << 3,
|
||||
GAP_ROBUSTNESS2 = 1u << 4,
|
||||
GAP_BC = 1u << 5,
|
||||
/* draw.c and pipeline.c (added for Mali-G57 and drivers without these, on top of David Cimo's six) */
|
||||
GAP_MULTI_DRAW = 1u << 6, /* multiDrawIndirect: indirect draws looped one by one */
|
||||
GAP_DEPTH_CLIP = 1u << 7, /* VK_EXT_depth_clip_enable: depthClipEnable off becomes depth clamp */
|
||||
GAP_NULL_DESCRIPTOR = 1u << 8, /* VK_EXT_robustness2 missing entirely: nullDescriptor stand-ins */
|
||||
};
|
||||
|
||||
#define GAPS_SHADER (GAP_CLIP_DISTANCE | GAP_CULL_DISTANCE)
|
||||
#define GAPS_PIPELINE (GAP_FILL_MODE | GAP_MULTI_VIEWPORT | GAPS_SHADER | GAP_DEPTH_CLIP)
|
||||
|
||||
void layer_log(const char *format, ...) __attribute__((format(printf, 1, 2)));
|
||||
|
||||
/* Open addressing from a Vulkan handle to a pointer. Not locked: the owner holds its lock. */
|
||||
struct handle_map {
|
||||
uint64_t *keys;
|
||||
void **values;
|
||||
uint32_t capacity;
|
||||
uint32_t count;
|
||||
};
|
||||
|
||||
void *map_get(const struct handle_map *map, uint64_t key);
|
||||
void map_put(struct handle_map *map, uint64_t key, void *value);
|
||||
void *map_remove(struct handle_map *map, uint64_t key);
|
||||
void map_free(struct handle_map *map);
|
||||
|
||||
struct physical_device {
|
||||
VkPhysicalDevice handle;
|
||||
uint32_t gaps;
|
||||
};
|
||||
|
||||
struct instance {
|
||||
void *key;
|
||||
VkInstance handle;
|
||||
bool active;
|
||||
PFN_vkGetInstanceProcAddr gipa;
|
||||
PFN_vkDestroyInstance DestroyInstance;
|
||||
PFN_vkEnumerateDeviceExtensionProperties EnumerateDeviceExtensionProperties;
|
||||
PFN_vkGetPhysicalDeviceFeatures GetPhysicalDeviceFeatures;
|
||||
PFN_vkGetPhysicalDeviceFeatures2 GetPhysicalDeviceFeatures2;
|
||||
PFN_vkGetPhysicalDeviceProperties GetPhysicalDeviceProperties;
|
||||
PFN_vkGetPhysicalDeviceProperties2 GetPhysicalDeviceProperties2;
|
||||
PFN_vkGetPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties;
|
||||
PFN_vkGetPhysicalDeviceFormatProperties GetPhysicalDeviceFormatProperties;
|
||||
PFN_vkGetPhysicalDeviceFormatProperties2 GetPhysicalDeviceFormatProperties2;
|
||||
PFN_vkGetPhysicalDeviceImageFormatProperties GetPhysicalDeviceImageFormatProperties;
|
||||
PFN_vkGetPhysicalDeviceImageFormatProperties2 GetPhysicalDeviceImageFormatProperties2;
|
||||
PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices;
|
||||
PFN_vkGetPhysicalDeviceMemoryProperties2 GetPhysicalDeviceMemoryProperties2;
|
||||
PFN_vkGetPhysicalDeviceQueueFamilyProperties GetPhysicalDeviceQueueFamilyProperties;
|
||||
PFN_vkGetPhysicalDeviceQueueFamilyProperties2 GetPhysicalDeviceQueueFamilyProperties2;
|
||||
PFN_vkGetPhysicalDeviceExternalBufferProperties GetPhysicalDeviceExternalBufferProperties;
|
||||
PFN_vkGetPhysicalDeviceExternalSemaphoreProperties GetPhysicalDeviceExternalSemaphoreProperties;
|
||||
PFN_vkGetPhysicalDeviceExternalFenceProperties GetPhysicalDeviceExternalFenceProperties;
|
||||
pthread_mutex_t lock;
|
||||
struct physical_device physical_devices[8];
|
||||
uint32_t physical_device_count;
|
||||
struct instance *next;
|
||||
};
|
||||
|
||||
#define DEVICE_FUNCTIONS(X) \
|
||||
X(DestroyDevice) \
|
||||
X(CreateShaderModule) \
|
||||
X(DestroyShaderModule) \
|
||||
X(CreateGraphicsPipelines) \
|
||||
X(CmdSetViewport) \
|
||||
X(CmdSetScissor) \
|
||||
X(CmdSetViewportWithCount) \
|
||||
X(CmdSetScissorWithCount) \
|
||||
X(CreateImage) \
|
||||
X(DestroyImage) \
|
||||
X(CreateImageView) \
|
||||
X(GetDeviceImageMemoryRequirements) \
|
||||
X(GetDeviceImageSparseMemoryRequirements) \
|
||||
X(GetDeviceImageSubresourceLayout) \
|
||||
X(CmdCopyBufferToImage) \
|
||||
X(CmdCopyBufferToImage2) \
|
||||
X(CmdCopyImageToBuffer) \
|
||||
X(CmdCopyImageToBuffer2) \
|
||||
X(CmdCopyImage) \
|
||||
X(CmdCopyImage2) \
|
||||
X(CreateBuffer) \
|
||||
X(DestroyBuffer) \
|
||||
X(GetBufferMemoryRequirements) \
|
||||
X(BindBufferMemory) \
|
||||
X(BindBufferMemory2) \
|
||||
X(AllocateMemory) \
|
||||
X(FreeMemory) \
|
||||
X(MapMemory) \
|
||||
X(MapMemory2) \
|
||||
X(UnmapMemory) \
|
||||
X(UnmapMemory2) \
|
||||
X(AllocateCommandBuffers) \
|
||||
X(FreeCommandBuffers) \
|
||||
X(BeginCommandBuffer) \
|
||||
X(ResetCommandBuffer) \
|
||||
X(ResetCommandPool) \
|
||||
X(DestroyCommandPool) \
|
||||
X(CmdDrawIndirect) \
|
||||
X(CmdDrawIndexedIndirect) \
|
||||
X(GetImageMemoryRequirements) \
|
||||
X(BindImageMemory) \
|
||||
X(DestroyImageView) \
|
||||
X(CreateBufferView) \
|
||||
X(DestroyBufferView) \
|
||||
X(UpdateDescriptorSets) \
|
||||
X(CmdPushDescriptorSet) \
|
||||
X(CreateDescriptorUpdateTemplate) \
|
||||
X(DestroyDescriptorUpdateTemplate) \
|
||||
X(UpdateDescriptorSetWithTemplate) \
|
||||
X(CmdPushDescriptorSetWithTemplate) \
|
||||
X(CmdBindVertexBuffers) \
|
||||
X(CmdBindVertexBuffers2)
|
||||
|
||||
struct staging_block;
|
||||
|
||||
struct device {
|
||||
void *key;
|
||||
VkDevice handle;
|
||||
PFN_vkGetDeviceProcAddr gdpa;
|
||||
/* The gaps the application enabled a made-up feature for. */
|
||||
uint32_t emulated;
|
||||
/* Locations a clip distance varying may use, from the vertex output and fragment input limits. */
|
||||
uint32_t max_varying_locations;
|
||||
VkPhysicalDeviceMemoryProperties memory_properties;
|
||||
#define DECLARE(name) PFN_vk##name name;
|
||||
DEVICE_FUNCTIONS(DECLARE)
|
||||
#undef DECLARE
|
||||
pthread_mutex_t lock;
|
||||
struct handle_map shader_modules; /* VkShaderModule -> struct spirv_code, for modules with distances */
|
||||
struct handle_map images; /* VkImage -> struct bc_image */
|
||||
struct handle_map buffers; /* VkBuffer -> struct bound_buffer */
|
||||
struct handle_map memories; /* VkDeviceMemory -> struct mapped_memory */
|
||||
struct handle_map command_buffers; /* VkCommandBuffer -> struct command_buffer */
|
||||
struct staging_block *free_staging;
|
||||
struct handle_map templates; /* VkDescriptorUpdateTemplate -> struct template_info (draw.c) */
|
||||
/* nullDescriptor stand-ins (draw.c): 0 not made yet, 1 ready, -1 failed. */
|
||||
int null_ready;
|
||||
VkBuffer null_buffer;
|
||||
VkDeviceMemory null_buffer_memory;
|
||||
VkImage null_image;
|
||||
VkDeviceMemory null_image_memory;
|
||||
VkImageView null_view;
|
||||
/* Texel-buffer stand-ins: RGBA8 for uniform (sampled) texel buffers, R32_UINT for storage. */
|
||||
VkBufferView null_uniform_texel;
|
||||
VkBufferView null_storage_texel;
|
||||
struct device *next;
|
||||
};
|
||||
|
||||
struct device *device_from_handle(const void *dispatchable);
|
||||
|
||||
struct spirv_code {
|
||||
uint32_t *words;
|
||||
size_t count;
|
||||
};
|
||||
|
||||
/* spirv.c */
|
||||
bool spirv_uses_distances(const uint32_t *words, size_t count);
|
||||
/* The module with clip and cull distances taken out; false when it cannot be rewritten. */
|
||||
bool spirv_strip_distances(const uint32_t *words, size_t count, struct spirv_code *out);
|
||||
|
||||
enum clip_role { CLIP_STRIP, CLIP_PRODUCER, CLIP_CONSUMER };
|
||||
|
||||
struct clip_info {
|
||||
bool has_clip; /* a standalone ClipDistance variable this stage could hand on */
|
||||
uint32_t clip_count; /* its array length */
|
||||
uint32_t locations_used; /* one past the highest varying location, outputs or inputs per role */
|
||||
};
|
||||
|
||||
void spirv_clip_info(const uint32_t *words, size_t count, enum clip_role role, struct clip_info *info);
|
||||
/*
|
||||
* Producer: the last stage before rasterization writes its clip distances to `location` instead.
|
||||
* Consumer: the fragment shader reads them there and discards when any is negative.
|
||||
* Both drop cull distances. False when the module cannot be rewritten.
|
||||
*/
|
||||
bool spirv_emulate_clip(const uint32_t *words, size_t count, enum clip_role role, uint32_t location,
|
||||
uint32_t clip_count, struct spirv_code *out);
|
||||
|
||||
/* pipeline.c */
|
||||
VKAPI_ATTR VkResult VKAPI_CALL CreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *info,
|
||||
const VkAllocationCallbacks *allocator, VkShaderModule *module);
|
||||
VKAPI_ATTR void VKAPI_CALL DestroyShaderModule(VkDevice device, VkShaderModule module,
|
||||
const VkAllocationCallbacks *allocator);
|
||||
VKAPI_ATTR VkResult VKAPI_CALL CreateGraphicsPipelines(VkDevice device, VkPipelineCache cache, uint32_t count,
|
||||
const VkGraphicsPipelineCreateInfo *infos,
|
||||
const VkAllocationCallbacks *allocator, VkPipeline *pipelines);
|
||||
VKAPI_ATTR void VKAPI_CALL CmdSetViewport(VkCommandBuffer cmd, uint32_t first, uint32_t count,
|
||||
const VkViewport *viewports);
|
||||
VKAPI_ATTR void VKAPI_CALL CmdSetScissor(VkCommandBuffer cmd, uint32_t first, uint32_t count,
|
||||
const VkRect2D *scissors);
|
||||
VKAPI_ATTR void VKAPI_CALL CmdSetViewportWithCount(VkCommandBuffer cmd, uint32_t count,
|
||||
const VkViewport *viewports);
|
||||
VKAPI_ATTR void VKAPI_CALL CmdSetScissorWithCount(VkCommandBuffer cmd, uint32_t count, const VkRect2D *scissors);
|
||||
|
||||
/* bc.c */
|
||||
VkFormat bc_substitute(VkFormat format);
|
||||
VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceFormatProperties(VkPhysicalDevice physical_device, VkFormat format,
|
||||
VkFormatProperties *properties);
|
||||
VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceFormatProperties2(VkPhysicalDevice physical_device, VkFormat format,
|
||||
VkFormatProperties2 *properties);
|
||||
VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceImageFormatProperties(
|
||||
VkPhysicalDevice physical_device, VkFormat format, VkImageType type, VkImageTiling tiling,
|
||||
VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties *properties);
|
||||
VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceImageFormatProperties2(
|
||||
VkPhysicalDevice physical_device, const VkPhysicalDeviceImageFormatInfo2 *info,
|
||||
VkImageFormatProperties2 *properties);
|
||||
VKAPI_ATTR VkResult VKAPI_CALL CreateImage(VkDevice device, const VkImageCreateInfo *info,
|
||||
const VkAllocationCallbacks *allocator, VkImage *image);
|
||||
VKAPI_ATTR void VKAPI_CALL DestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *allocator);
|
||||
VKAPI_ATTR VkResult VKAPI_CALL CreateImageView(VkDevice device, const VkImageViewCreateInfo *info,
|
||||
const VkAllocationCallbacks *allocator, VkImageView *view);
|
||||
VKAPI_ATTR void VKAPI_CALL GetDeviceImageMemoryRequirements(VkDevice device,
|
||||
const VkDeviceImageMemoryRequirements *info,
|
||||
VkMemoryRequirements2 *requirements);
|
||||
VKAPI_ATTR void VKAPI_CALL GetDeviceImageSparseMemoryRequirements(
|
||||
VkDevice device, const VkDeviceImageMemoryRequirements *info, uint32_t *count,
|
||||
VkSparseImageMemoryRequirements2 *requirements);
|
||||
VKAPI_ATTR void VKAPI_CALL GetDeviceImageSubresourceLayout(VkDevice device,
|
||||
const VkDeviceImageSubresourceInfo *info,
|
||||
VkSubresourceLayout2 *layout);
|
||||
VKAPI_ATTR void VKAPI_CALL CmdCopyBufferToImage(VkCommandBuffer cmd, VkBuffer buffer, VkImage image,
|
||||
VkImageLayout layout, uint32_t count,
|
||||
const VkBufferImageCopy *regions);
|
||||
VKAPI_ATTR void VKAPI_CALL CmdCopyBufferToImage2(VkCommandBuffer cmd, const VkCopyBufferToImageInfo2 *info);
|
||||
VKAPI_ATTR void VKAPI_CALL CmdCopyImageToBuffer(VkCommandBuffer cmd, VkImage image, VkImageLayout layout,
|
||||
VkBuffer buffer, uint32_t count, const VkBufferImageCopy *regions);
|
||||
VKAPI_ATTR void VKAPI_CALL CmdCopyImageToBuffer2(VkCommandBuffer cmd, const VkCopyImageToBufferInfo2 *info);
|
||||
VKAPI_ATTR void VKAPI_CALL CmdCopyImage(VkCommandBuffer cmd, VkImage src, VkImageLayout src_layout, VkImage dst,
|
||||
VkImageLayout dst_layout, uint32_t count, const VkImageCopy *regions);
|
||||
VKAPI_ATTR void VKAPI_CALL CmdCopyImage2(VkCommandBuffer cmd, const VkCopyImageInfo2 *info);
|
||||
VKAPI_ATTR VkResult VKAPI_CALL BindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory memory,
|
||||
VkDeviceSize offset);
|
||||
VKAPI_ATTR VkResult VKAPI_CALL BindBufferMemory2(VkDevice device, uint32_t count,
|
||||
const VkBindBufferMemoryInfo *infos);
|
||||
VKAPI_ATTR void VKAPI_CALL DestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *allocator);
|
||||
VKAPI_ATTR void VKAPI_CALL FreeMemory(VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks *allocator);
|
||||
VKAPI_ATTR VkResult VKAPI_CALL MapMemory(VkDevice device, VkDeviceMemory memory, VkDeviceSize offset,
|
||||
VkDeviceSize size, VkMemoryMapFlags flags, void **data);
|
||||
VKAPI_ATTR VkResult VKAPI_CALL MapMemory2(VkDevice device, const VkMemoryMapInfo *info, void **data);
|
||||
VKAPI_ATTR void VKAPI_CALL UnmapMemory(VkDevice device, VkDeviceMemory memory);
|
||||
VKAPI_ATTR VkResult VKAPI_CALL UnmapMemory2(VkDevice device, const VkMemoryUnmapInfo *info);
|
||||
VKAPI_ATTR VkResult VKAPI_CALL AllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *info,
|
||||
VkCommandBuffer *buffers);
|
||||
VKAPI_ATTR void VKAPI_CALL FreeCommandBuffers(VkDevice device, VkCommandPool pool, uint32_t count,
|
||||
const VkCommandBuffer *buffers);
|
||||
VKAPI_ATTR VkResult VKAPI_CALL BeginCommandBuffer(VkCommandBuffer cmd, const VkCommandBufferBeginInfo *info);
|
||||
VKAPI_ATTR VkResult VKAPI_CALL ResetCommandBuffer(VkCommandBuffer cmd, VkCommandBufferResetFlags flags);
|
||||
VKAPI_ATTR VkResult VKAPI_CALL ResetCommandPool(VkDevice device, VkCommandPool pool, VkCommandPoolResetFlags flags);
|
||||
VKAPI_ATTR void VKAPI_CALL DestroyCommandPool(VkDevice device, VkCommandPool pool,
|
||||
const VkAllocationCallbacks *allocator);
|
||||
void bc_destroy_device(struct device *dev);
|
||||
|
||||
/* layer.c */
|
||||
struct instance *instance_from_handle(const void *dispatchable);
|
||||
/* What the GPU lacks of the features the layer can make up for. */
|
||||
uint32_t physical_device_gaps(struct instance *inst, VkPhysicalDevice physical_device);
|
||||
|
||||
/* trace.c (DROIDDECK_MALI_COMPAT_TRACE=1) */
|
||||
void trace_load(struct instance *inst);
|
||||
PFN_vkVoidFunction trace_hook(struct instance *inst, const char *name);
|
||||
void trace_extension_names(const VkExtensionProperties *ext, uint32_t n);
|
||||
|
||||
|
||||
/* draw.c */
|
||||
VKAPI_ATTR void VKAPI_CALL CmdDrawIndirect(VkCommandBuffer cmd, VkBuffer buffer, VkDeviceSize offset, uint32_t draw_count, uint32_t stride);
|
||||
VKAPI_ATTR void VKAPI_CALL CmdDrawIndexedIndirect(VkCommandBuffer cmd, VkBuffer buffer, VkDeviceSize offset, uint32_t draw_count, uint32_t stride);
|
||||
VKAPI_ATTR void VKAPI_CALL UpdateDescriptorSets(VkDevice device, uint32_t write_count, const VkWriteDescriptorSet *writes, uint32_t copy_count, const VkCopyDescriptorSet *copies);
|
||||
VKAPI_ATTR void VKAPI_CALL CmdPushDescriptorSet(VkCommandBuffer cmd, VkPipelineBindPoint bind_point, VkPipelineLayout layout, uint32_t set, uint32_t write_count, const VkWriteDescriptorSet *writes);
|
||||
VKAPI_ATTR VkResult VKAPI_CALL CreateDescriptorUpdateTemplate(VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *info, const VkAllocationCallbacks *allocator, VkDescriptorUpdateTemplate *tmpl);
|
||||
VKAPI_ATTR void VKAPI_CALL DestroyDescriptorUpdateTemplate(VkDevice device, VkDescriptorUpdateTemplate tmpl, const VkAllocationCallbacks *allocator);
|
||||
VKAPI_ATTR void VKAPI_CALL UpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet set, VkDescriptorUpdateTemplate tmpl, const void *data);
|
||||
VKAPI_ATTR void VKAPI_CALL CmdPushDescriptorSetWithTemplate(VkCommandBuffer cmd, VkDescriptorUpdateTemplate tmpl, VkPipelineLayout layout, uint32_t set, const void *data);
|
||||
VKAPI_ATTR void VKAPI_CALL CmdBindVertexBuffers(VkCommandBuffer cmd, uint32_t first, uint32_t count, const VkBuffer *buffers, const VkDeviceSize *offsets);
|
||||
VKAPI_ATTR void VKAPI_CALL CmdBindVertexBuffers2(VkCommandBuffer cmd, uint32_t first, uint32_t count, const VkBuffer *buffers, const VkDeviceSize *offsets, const VkDeviceSize *sizes, const VkDeviceSize *strides);
|
||||
void null_resources_destroy(struct device *dev);
|
||||
#endif
|
||||
@@ -0,0 +1,308 @@
|
||||
#include "mali_compat.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define HANDLE(h) ((uint64_t)(uintptr_t)(h))
|
||||
#define MAX_STAGES 8
|
||||
|
||||
/* A module with distances goes to the driver without them; its original stays here, for the
|
||||
* pipeline that can emulate its clip distances. */
|
||||
VKAPI_ATTR VkResult VKAPI_CALL CreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *info,
|
||||
const VkAllocationCallbacks *allocator, VkShaderModule *module)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
size_t count = info->codeSize / sizeof(uint32_t);
|
||||
if (!spirv_uses_distances(info->pCode, count))
|
||||
return dev->CreateShaderModule(device, info, allocator, module);
|
||||
|
||||
struct spirv_code stripped;
|
||||
if (!spirv_strip_distances(info->pCode, count, &stripped)) {
|
||||
layer_log("could not take the clip and cull distances out of a shader module");
|
||||
return dev->CreateShaderModule(device, info, allocator, module);
|
||||
}
|
||||
VkShaderModuleCreateInfo copy = *info;
|
||||
copy.pCode = stripped.words;
|
||||
copy.codeSize = stripped.count * sizeof(uint32_t);
|
||||
VkResult result = dev->CreateShaderModule(device, ©, allocator, module);
|
||||
free(stripped.words);
|
||||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
|
||||
struct spirv_code *original = malloc(sizeof(*original));
|
||||
original->count = count;
|
||||
original->words = malloc(info->codeSize);
|
||||
memcpy(original->words, info->pCode, info->codeSize);
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
map_put(&dev->shader_modules, HANDLE(*module), original);
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL DestroyShaderModule(VkDevice device, VkShaderModule module,
|
||||
const VkAllocationCallbacks *allocator)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
struct spirv_code *original = map_remove(&dev->shader_modules, HANDLE(module));
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
if (original) {
|
||||
free(original->words);
|
||||
free(original);
|
||||
}
|
||||
dev->DestroyShaderModule(device, module, allocator);
|
||||
}
|
||||
|
||||
struct stage_code {
|
||||
const uint32_t *words;
|
||||
size_t count;
|
||||
/* The application's own, when the code comes inline in the stage. */
|
||||
VkShaderModuleCreateInfo *inline_info;
|
||||
/* A module whose distances were already taken out at creation. */
|
||||
bool stripped_module;
|
||||
};
|
||||
|
||||
static void find_stage_code(struct device *dev, const VkPipelineShaderStageCreateInfo *stage, struct stage_code *code)
|
||||
{
|
||||
memset(code, 0, sizeof(*code));
|
||||
for (const VkBaseInStructure *s = stage->pNext; s; s = s->pNext) {
|
||||
if (s->sType == VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO) {
|
||||
code->inline_info = (VkShaderModuleCreateInfo *)s;
|
||||
code->words = code->inline_info->pCode;
|
||||
code->count = code->inline_info->codeSize / sizeof(uint32_t);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (stage->module == VK_NULL_HANDLE)
|
||||
return;
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
struct spirv_code *original = map_get(&dev->shader_modules, HANDLE(stage->module));
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
if (original) {
|
||||
code->words = original->words;
|
||||
code->count = original->count;
|
||||
code->stripped_module = true;
|
||||
}
|
||||
}
|
||||
|
||||
struct pipeline_rewrite {
|
||||
VkPipelineRasterizationStateCreateInfo rasterization;
|
||||
/* VK_EXT_depth_clip_enable's state, taken out of the application's chain for the call. */
|
||||
VkBaseOutStructure *clip_prev, *clip_node;
|
||||
VkPipelineViewportStateCreateInfo viewport;
|
||||
VkPipelineShaderStageCreateInfo stages[MAX_STAGES];
|
||||
VkShaderModuleCreateInfo modules[MAX_STAGES];
|
||||
struct spirv_code code[MAX_STAGES];
|
||||
VkShaderModule temporary[MAX_STAGES];
|
||||
/* Rewritten where they are, when they are not first in their stage's chain. */
|
||||
VkShaderModuleCreateInfo *in_place[MAX_STAGES];
|
||||
const uint32_t *in_place_code[MAX_STAGES];
|
||||
size_t in_place_size[MAX_STAGES];
|
||||
};
|
||||
|
||||
static void use_code(struct device *dev, VkGraphicsPipelineCreateInfo *info, struct pipeline_rewrite *rw,
|
||||
const struct stage_code *code, uint32_t i)
|
||||
{
|
||||
if (info->pStages != rw->stages) {
|
||||
memcpy(rw->stages, info->pStages, info->stageCount * sizeof(*rw->stages));
|
||||
info->pStages = rw->stages;
|
||||
}
|
||||
const struct spirv_code *out = &rw->code[i];
|
||||
if (code->inline_info && rw->stages[i].pNext == code->inline_info) {
|
||||
rw->modules[i] = *code->inline_info;
|
||||
rw->modules[i].pCode = out->words;
|
||||
rw->modules[i].codeSize = out->count * sizeof(uint32_t);
|
||||
rw->stages[i].pNext = &rw->modules[i];
|
||||
} else if (code->inline_info) {
|
||||
rw->in_place[i] = code->inline_info;
|
||||
rw->in_place_code[i] = code->inline_info->pCode;
|
||||
rw->in_place_size[i] = code->inline_info->codeSize;
|
||||
code->inline_info->pCode = out->words;
|
||||
code->inline_info->codeSize = out->count * sizeof(uint32_t);
|
||||
} else {
|
||||
VkShaderModuleCreateInfo module_info = {
|
||||
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
|
||||
.codeSize = out->count * sizeof(uint32_t),
|
||||
.pCode = out->words,
|
||||
};
|
||||
if (dev->CreateShaderModule(dev->handle, &module_info, NULL, &rw->temporary[i]) == VK_SUCCESS)
|
||||
rw->stages[i].module = rw->temporary[i];
|
||||
}
|
||||
}
|
||||
|
||||
static int stage_index(const VkGraphicsPipelineCreateInfo *info, VkShaderStageFlagBits stage)
|
||||
{
|
||||
for (uint32_t i = 0; i < info->stageCount; i++) {
|
||||
if (info->pStages[i].stage == stage)
|
||||
return (int)i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Clip distances are emulated when the last stage before rasterization is the only one that
|
||||
* hands them on: a vertex shader feeding a geometry shader would need a varying of its own.
|
||||
* Anywhere else they are dropped, along with every cull distance.
|
||||
*/
|
||||
static void rewrite_shaders(struct device *dev, VkGraphicsPipelineCreateInfo *info, struct pipeline_rewrite *rw)
|
||||
{
|
||||
uint32_t n = info->stageCount;
|
||||
if (!n || n > MAX_STAGES || !info->pStages)
|
||||
return;
|
||||
struct stage_code code[MAX_STAGES];
|
||||
bool uses[MAX_STAGES];
|
||||
bool any = false;
|
||||
for (uint32_t i = 0; i < n; i++) {
|
||||
find_stage_code(dev, &info->pStages[i], &code[i]);
|
||||
uses[i] = code[i].words && spirv_uses_distances(code[i].words, code[i].count);
|
||||
any |= uses[i];
|
||||
}
|
||||
if (!any)
|
||||
return;
|
||||
|
||||
int producer = stage_index(info, VK_SHADER_STAGE_GEOMETRY_BIT);
|
||||
if (producer < 0)
|
||||
producer = stage_index(info, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT);
|
||||
if (producer < 0)
|
||||
producer = stage_index(info, VK_SHADER_STAGE_VERTEX_BIT);
|
||||
int consumer = stage_index(info, VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||
bool emulate = (dev->emulated & GAP_CLIP_DISTANCE) && producer >= 0 && consumer >= 0 && uses[producer] &&
|
||||
code[consumer].words;
|
||||
for (uint32_t i = 0; i < n && emulate; i++) {
|
||||
if ((int)i != producer && (int)i != consumer && uses[i])
|
||||
emulate = false;
|
||||
}
|
||||
if (emulate) {
|
||||
struct clip_info produced, consumed;
|
||||
spirv_clip_info(code[producer].words, code[producer].count, CLIP_PRODUCER, &produced);
|
||||
spirv_clip_info(code[consumer].words, code[consumer].count, CLIP_CONSUMER, &consumed);
|
||||
uint32_t location = produced.locations_used > consumed.locations_used ? produced.locations_used
|
||||
: consumed.locations_used;
|
||||
emulate = produced.has_clip && location != UINT32_MAX &&
|
||||
location + produced.clip_count <= dev->max_varying_locations &&
|
||||
spirv_emulate_clip(code[producer].words, code[producer].count, CLIP_PRODUCER, location,
|
||||
produced.clip_count, &rw->code[producer]) &&
|
||||
spirv_emulate_clip(code[consumer].words, code[consumer].count, CLIP_CONSUMER, location,
|
||||
produced.clip_count, &rw->code[consumer]);
|
||||
if (!emulate) {
|
||||
free(rw->code[producer].words);
|
||||
free(rw->code[consumer].words);
|
||||
rw->code[producer] = rw->code[consumer] = (struct spirv_code){0};
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < n; i++) {
|
||||
if (!rw->code[i].words && uses[i] && !code[i].stripped_module &&
|
||||
!spirv_strip_distances(code[i].words, code[i].count, &rw->code[i])) {
|
||||
layer_log("could not take the clip and cull distances out of a pipeline's shader");
|
||||
}
|
||||
if (rw->code[i].words)
|
||||
use_code(dev, info, rw, &code[i], i);
|
||||
}
|
||||
}
|
||||
|
||||
static void rewrite_pipeline(struct device *dev, VkGraphicsPipelineCreateInfo *info, struct pipeline_rewrite *rw)
|
||||
{
|
||||
if ((dev->emulated & GAP_FILL_MODE) && info->pRasterizationState &&
|
||||
info->pRasterizationState->polygonMode != VK_POLYGON_MODE_FILL) {
|
||||
rw->rasterization = *info->pRasterizationState;
|
||||
rw->rasterization.polygonMode = VK_POLYGON_MODE_FILL;
|
||||
info->pRasterizationState = &rw->rasterization;
|
||||
}
|
||||
/* No VK_EXT_depth_clip_enable: depth clipping off is the nearest the driver has as depth clamp. */
|
||||
if ((dev->emulated & GAP_DEPTH_CLIP) && info->pRasterizationState) {
|
||||
VkBaseOutStructure *prev = (VkBaseOutStructure *)info->pRasterizationState;
|
||||
while (prev->pNext && prev->pNext->sType != VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_DEPTH_CLIP_STATE_CREATE_INFO_EXT)
|
||||
prev = prev->pNext;
|
||||
VkBaseOutStructure *node = prev->pNext;
|
||||
if (node) {
|
||||
bool clip = ((VkPipelineRasterizationDepthClipStateCreateInfoEXT *)node)->depthClipEnable;
|
||||
if (info->pRasterizationState != &rw->rasterization) {
|
||||
rw->rasterization = *info->pRasterizationState;
|
||||
if (prev == (VkBaseOutStructure *)info->pRasterizationState)
|
||||
prev = (VkBaseOutStructure *)&rw->rasterization;
|
||||
info->pRasterizationState = &rw->rasterization;
|
||||
}
|
||||
if (!clip)
|
||||
rw->rasterization.depthClampEnable = VK_TRUE;
|
||||
if (prev != (VkBaseOutStructure *)&rw->rasterization) {
|
||||
rw->clip_prev = prev;
|
||||
rw->clip_node = node;
|
||||
}
|
||||
prev->pNext = node->pNext;
|
||||
}
|
||||
}
|
||||
if ((dev->emulated & GAP_MULTI_VIEWPORT) && info->pViewportState &&
|
||||
(info->pViewportState->viewportCount > 1 || info->pViewportState->scissorCount > 1)) {
|
||||
rw->viewport = *info->pViewportState;
|
||||
if (rw->viewport.viewportCount > 1)
|
||||
rw->viewport.viewportCount = 1;
|
||||
if (rw->viewport.scissorCount > 1)
|
||||
rw->viewport.scissorCount = 1;
|
||||
info->pViewportState = &rw->viewport;
|
||||
}
|
||||
if (dev->emulated & GAPS_SHADER)
|
||||
rewrite_shaders(dev, info, rw);
|
||||
}
|
||||
|
||||
static void undo_rewrite(struct device *dev, struct pipeline_rewrite *rw)
|
||||
{
|
||||
if (rw->clip_prev)
|
||||
rw->clip_prev->pNext = rw->clip_node;
|
||||
for (uint32_t i = 0; i < MAX_STAGES; i++) {
|
||||
if (rw->in_place[i]) {
|
||||
rw->in_place[i]->pCode = rw->in_place_code[i];
|
||||
rw->in_place[i]->codeSize = rw->in_place_size[i];
|
||||
}
|
||||
if (rw->temporary[i] != VK_NULL_HANDLE)
|
||||
dev->DestroyShaderModule(dev->handle, rw->temporary[i], NULL);
|
||||
free(rw->code[i].words);
|
||||
}
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL CreateGraphicsPipelines(VkDevice device, VkPipelineCache cache, uint32_t count,
|
||||
const VkGraphicsPipelineCreateInfo *infos,
|
||||
const VkAllocationCallbacks *allocator, VkPipeline *pipelines)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
VkGraphicsPipelineCreateInfo *copies = malloc(count * sizeof(*copies));
|
||||
struct pipeline_rewrite *rewrites = calloc(count, sizeof(*rewrites));
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
copies[i] = infos[i];
|
||||
rewrite_pipeline(dev, &copies[i], &rewrites[i]);
|
||||
}
|
||||
VkResult result = dev->CreateGraphicsPipelines(device, cache, count, copies, allocator, pipelines);
|
||||
for (uint32_t i = 0; i < count; i++)
|
||||
undo_rewrite(dev, &rewrites[i]);
|
||||
free(rewrites);
|
||||
free(copies);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* The driver has one viewport and one scissor; anything past the first is left out. */
|
||||
VKAPI_ATTR void VKAPI_CALL CmdSetViewport(VkCommandBuffer cmd, uint32_t first, uint32_t count,
|
||||
const VkViewport *viewports)
|
||||
{
|
||||
struct device *dev = device_from_handle(cmd);
|
||||
if (first == 0 && count > 0)
|
||||
dev->CmdSetViewport(cmd, 0, 1, viewports);
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL CmdSetScissor(VkCommandBuffer cmd, uint32_t first, uint32_t count, const VkRect2D *scissors)
|
||||
{
|
||||
struct device *dev = device_from_handle(cmd);
|
||||
if (first == 0 && count > 0)
|
||||
dev->CmdSetScissor(cmd, 0, 1, scissors);
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL CmdSetViewportWithCount(VkCommandBuffer cmd, uint32_t count, const VkViewport *viewports)
|
||||
{
|
||||
struct device *dev = device_from_handle(cmd);
|
||||
dev->CmdSetViewportWithCount(cmd, count > 1 ? 1 : count, viewports);
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL CmdSetScissorWithCount(VkCommandBuffer cmd, uint32_t count, const VkRect2D *scissors)
|
||||
{
|
||||
struct device *dev = device_from_handle(cmd);
|
||||
dev->CmdSetScissorWithCount(cmd, count > 1 ? 1 : count, scissors);
|
||||
}
|
||||
@@ -0,0 +1,833 @@
|
||||
/*
|
||||
* Clip and cull distances out of SPIR-V, for a GPU without either.
|
||||
*
|
||||
* Stripping: every ClipDistance or CullDistance variable becomes a Private one, so the shader still
|
||||
* writes and reads it but the rasterizer never sees it. Members of a gl_PerVertex block stay
|
||||
* declared (as glslang declares them unused anyway) and their accesses move to a Private stand-in.
|
||||
* Emulating: the last stage before rasterization writes its clip distances to a free varying
|
||||
* location instead, and the fragment shader reads them there and discards when one is negative.
|
||||
*/
|
||||
#include "mali_compat.h"
|
||||
|
||||
#include <spirv/unified1/spirv.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define OPCODE(word) ((word) & 0xffffu)
|
||||
#define LENGTH(word) ((word) >> 16)
|
||||
#define VERSION_1_4 0x00010400u
|
||||
|
||||
struct words {
|
||||
uint32_t *data;
|
||||
size_t count;
|
||||
size_t capacity;
|
||||
};
|
||||
|
||||
static void push(struct words *words, uint32_t word)
|
||||
{
|
||||
if (words->count == words->capacity) {
|
||||
words->capacity = words->capacity ? words->capacity * 2 : 64;
|
||||
words->data = realloc(words->data, words->capacity * sizeof(uint32_t));
|
||||
}
|
||||
words->data[words->count++] = word;
|
||||
}
|
||||
|
||||
static void emit(struct words *words, SpvOp op, size_t count, const uint32_t *operands)
|
||||
{
|
||||
push(words, (uint32_t)(count + 1) << 16 | op);
|
||||
for (size_t i = 0; i < count; i++)
|
||||
push(words, operands[i]);
|
||||
}
|
||||
|
||||
#define EMIT(words, op, ...) \
|
||||
do { \
|
||||
const uint32_t operands_[] = {__VA_ARGS__}; \
|
||||
emit(words, op, sizeof(operands_) / sizeof(operands_[0]), operands_); \
|
||||
} while (0)
|
||||
|
||||
enum place { BEFORE, INSTEAD, AFTER };
|
||||
|
||||
struct edit {
|
||||
size_t offset;
|
||||
enum place place;
|
||||
struct words words;
|
||||
};
|
||||
|
||||
struct new_type {
|
||||
SpvOp op;
|
||||
uint32_t operands[3];
|
||||
uint32_t count;
|
||||
uint32_t id;
|
||||
};
|
||||
|
||||
struct module {
|
||||
uint32_t *w;
|
||||
size_t count;
|
||||
uint32_t version;
|
||||
uint32_t original_bound;
|
||||
uint32_t bound;
|
||||
size_t *def;
|
||||
size_t first_declaration;
|
||||
size_t first_function;
|
||||
struct edit *edits;
|
||||
size_t edit_count;
|
||||
struct new_type *new_types;
|
||||
size_t new_type_count;
|
||||
struct words globals;
|
||||
uint8_t *private_ids;
|
||||
uint32_t *interface_add;
|
||||
size_t interface_add_count;
|
||||
uint8_t *interface_remove;
|
||||
bool failed;
|
||||
};
|
||||
|
||||
static bool declares_result_first(uint32_t op)
|
||||
{
|
||||
return (op >= SpvOpTypeVoid && op <= SpvOpTypePipe) || op == SpvOpLabel || op == SpvOpExtInstImport ||
|
||||
op == SpvOpString;
|
||||
}
|
||||
|
||||
static bool declares_result_second(uint32_t op)
|
||||
{
|
||||
switch (op) {
|
||||
case SpvOpConstantTrue:
|
||||
case SpvOpConstantFalse:
|
||||
case SpvOpConstant:
|
||||
case SpvOpConstantComposite:
|
||||
case SpvOpConstantNull:
|
||||
case SpvOpSpecConstantTrue:
|
||||
case SpvOpSpecConstantFalse:
|
||||
case SpvOpSpecConstant:
|
||||
case SpvOpSpecConstantComposite:
|
||||
case SpvOpSpecConstantOp:
|
||||
case SpvOpUndef:
|
||||
case SpvOpVariable:
|
||||
case SpvOpFunction:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool is_declaration(uint32_t op)
|
||||
{
|
||||
return (op >= SpvOpTypeVoid && op <= SpvOpTypeForwardPointer) || declares_result_second(op);
|
||||
}
|
||||
|
||||
static void unload(struct module *m)
|
||||
{
|
||||
free(m->w);
|
||||
free(m->def);
|
||||
for (size_t i = 0; i < m->edit_count; i++)
|
||||
free(m->edits[i].words.data);
|
||||
free(m->edits);
|
||||
free(m->new_types);
|
||||
free(m->globals.data);
|
||||
free(m->private_ids);
|
||||
free(m->interface_add);
|
||||
free(m->interface_remove);
|
||||
}
|
||||
|
||||
static bool load(struct module *m, const uint32_t *words, size_t count)
|
||||
{
|
||||
memset(m, 0, sizeof(*m));
|
||||
if (count < 5 || words[0] != SpvMagicNumber || words[3] == 0 || words[3] > (1u << 22))
|
||||
return false;
|
||||
m->w = malloc(count * sizeof(uint32_t));
|
||||
memcpy(m->w, words, count * sizeof(uint32_t));
|
||||
m->count = count;
|
||||
m->version = words[1];
|
||||
m->original_bound = m->bound = words[3];
|
||||
m->def = calloc(m->bound, sizeof(size_t));
|
||||
/* Room for every id the rewrite can add. */
|
||||
m->private_ids = calloc(m->bound + 4096, 1);
|
||||
m->interface_remove = calloc(m->bound, 1);
|
||||
for (size_t i = 5; i < count;) {
|
||||
uint32_t length = LENGTH(m->w[i]);
|
||||
uint32_t op = OPCODE(m->w[i]);
|
||||
if (length == 0 || i + length > count) {
|
||||
unload(m);
|
||||
return false;
|
||||
}
|
||||
uint32_t result = 0;
|
||||
if (declares_result_first(op) && length > 1)
|
||||
result = m->w[i + 1];
|
||||
else if (declares_result_second(op) && length > 2)
|
||||
result = m->w[i + 2];
|
||||
if (result && result < m->bound)
|
||||
m->def[result] = i;
|
||||
if (!m->first_declaration && is_declaration(op))
|
||||
m->first_declaration = i;
|
||||
if (!m->first_function && op == SpvOpFunction)
|
||||
m->first_function = i;
|
||||
i += length;
|
||||
}
|
||||
if (!m->first_declaration || !m->first_function) {
|
||||
unload(m);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static struct words *edit(struct module *m, size_t offset, enum place place)
|
||||
{
|
||||
m->edits = realloc(m->edits, (m->edit_count + 1) * sizeof(*m->edits));
|
||||
struct edit *e = &m->edits[m->edit_count++];
|
||||
*e = (struct edit){.offset = offset, .place = place};
|
||||
return &e->words;
|
||||
}
|
||||
|
||||
static uint32_t new_id(struct module *m)
|
||||
{
|
||||
return m->bound++;
|
||||
}
|
||||
|
||||
static bool is_private(const struct module *m, uint32_t id)
|
||||
{
|
||||
return id < m->original_bound + 4096 && m->private_ids[id];
|
||||
}
|
||||
|
||||
static void mark_private(struct module *m, uint32_t id)
|
||||
{
|
||||
if (id < m->original_bound + 4096)
|
||||
m->private_ids[id] = 1;
|
||||
else
|
||||
m->failed = true;
|
||||
}
|
||||
|
||||
/* The defining instruction of an id from the original module, or 0. */
|
||||
static size_t definition(const struct module *m, uint32_t id)
|
||||
{
|
||||
return id < m->original_bound ? m->def[id] : 0;
|
||||
}
|
||||
|
||||
static uint32_t find_type(struct module *m, SpvOp op, const uint32_t *operands, uint32_t count)
|
||||
{
|
||||
for (size_t i = 5; i < m->first_function; i += LENGTH(m->w[i])) {
|
||||
if (OPCODE(m->w[i]) == op && LENGTH(m->w[i]) == count + 2 &&
|
||||
!memcmp(&m->w[i + 2], operands, count * sizeof(uint32_t)))
|
||||
return m->w[i + 1];
|
||||
}
|
||||
for (size_t i = 0; i < m->new_type_count; i++) {
|
||||
struct new_type *t = &m->new_types[i];
|
||||
if (t->op == op && t->count == count && !memcmp(t->operands, operands, count * sizeof(uint32_t)))
|
||||
return t->id;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint32_t add_type(struct module *m, struct words *where, SpvOp op, const uint32_t *operands, uint32_t count)
|
||||
{
|
||||
uint32_t id = new_id(m);
|
||||
push(where, (count + 2) << 16 | op);
|
||||
push(where, id);
|
||||
for (uint32_t i = 0; i < count; i++)
|
||||
push(where, operands[i]);
|
||||
m->new_types = realloc(m->new_types, (m->new_type_count + 1) * sizeof(*m->new_types));
|
||||
struct new_type *t = &m->new_types[m->new_type_count++];
|
||||
*t = (struct new_type){.op = op, .count = count, .id = id};
|
||||
memcpy(t->operands, operands, count * sizeof(uint32_t));
|
||||
return id;
|
||||
}
|
||||
|
||||
/* Right after its pointee, so a global variable declared before the end of the types can use it. */
|
||||
static uint32_t pointer_type(struct module *m, uint32_t storage, uint32_t pointee)
|
||||
{
|
||||
uint32_t operands[2] = {storage, pointee};
|
||||
uint32_t id = find_type(m, SpvOpTypePointer, operands, 2);
|
||||
if (id)
|
||||
return id;
|
||||
size_t pointee_def = definition(m, pointee);
|
||||
struct words *where = pointee_def ? edit(m, pointee_def, AFTER) : &m->globals;
|
||||
return add_type(m, where, SpvOpTypePointer, operands, 2);
|
||||
}
|
||||
|
||||
static uint32_t scalar_type(struct module *m, SpvOp op, const uint32_t *operands, uint32_t count)
|
||||
{
|
||||
uint32_t id = find_type(m, op, operands, count);
|
||||
return id ? id : add_type(m, &m->globals, op, operands, count);
|
||||
}
|
||||
|
||||
static uint32_t float_type(struct module *m)
|
||||
{
|
||||
const uint32_t width = 32;
|
||||
return scalar_type(m, SpvOpTypeFloat, &width, 1);
|
||||
}
|
||||
|
||||
static uint32_t uint_type(struct module *m)
|
||||
{
|
||||
const uint32_t operands[2] = {32, 0};
|
||||
return scalar_type(m, SpvOpTypeInt, operands, 2);
|
||||
}
|
||||
|
||||
static uint32_t bool_type(struct module *m)
|
||||
{
|
||||
return scalar_type(m, SpvOpTypeBool, NULL, 0);
|
||||
}
|
||||
|
||||
static uint32_t constant(struct module *m, uint32_t type, uint32_t value)
|
||||
{
|
||||
for (size_t i = 5; i < m->first_function; i += LENGTH(m->w[i])) {
|
||||
if (OPCODE(m->w[i]) == SpvOpConstant && LENGTH(m->w[i]) == 4 && m->w[i + 1] == type && m->w[i + 3] == value)
|
||||
return m->w[i + 2];
|
||||
}
|
||||
uint32_t id = new_id(m);
|
||||
EMIT(&m->globals, SpvOpConstant, type, id, value);
|
||||
return id;
|
||||
}
|
||||
|
||||
static bool constant_value(const struct module *m, uint32_t id, uint32_t *value)
|
||||
{
|
||||
size_t d = definition(m, id);
|
||||
if (!d || OPCODE(m->w[d]) != SpvOpConstant || LENGTH(m->w[d]) != 4)
|
||||
return false;
|
||||
*value = m->w[d + 3];
|
||||
return true;
|
||||
}
|
||||
|
||||
/* What a pointer type points to, and where. */
|
||||
static bool pointer_parts(const struct module *m, uint32_t pointer, uint32_t *storage, uint32_t *pointee)
|
||||
{
|
||||
size_t d = definition(m, pointer);
|
||||
if (!d || OPCODE(m->w[d]) != SpvOpTypePointer)
|
||||
return false;
|
||||
*storage = m->w[d + 2];
|
||||
*pointee = m->w[d + 3];
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool is_float32(const struct module *m, uint32_t type)
|
||||
{
|
||||
size_t d = definition(m, type);
|
||||
return d && OPCODE(m->w[d]) == SpvOpTypeFloat && m->w[d + 2] == 32;
|
||||
}
|
||||
|
||||
/* Varying locations a type takes up. */
|
||||
static uint32_t location_span(const struct module *m, uint32_t type, int depth)
|
||||
{
|
||||
size_t d = definition(m, type);
|
||||
if (!d || depth > 8)
|
||||
return 1;
|
||||
uint32_t value;
|
||||
switch (OPCODE(m->w[d])) {
|
||||
case SpvOpTypeArray:
|
||||
return constant_value(m, m->w[d + 3], &value) ? value * location_span(m, m->w[d + 2], depth + 1) : 1;
|
||||
case SpvOpTypeMatrix:
|
||||
return m->w[d + 3] * location_span(m, m->w[d + 2], depth + 1);
|
||||
case SpvOpTypeStruct: {
|
||||
uint32_t span = 0;
|
||||
for (uint32_t i = 2; i < LENGTH(m->w[d]); i++)
|
||||
span += location_span(m, m->w[d + i], depth + 1);
|
||||
return span;
|
||||
}
|
||||
case SpvOpTypeVector: {
|
||||
size_t component = definition(m, m->w[d + 2]);
|
||||
bool wide = component && m->w[component + 2] == 64;
|
||||
return wide && m->w[d + 3] > 2 ? 2 : 1;
|
||||
}
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
struct distance_var {
|
||||
uint32_t id;
|
||||
uint32_t built_in;
|
||||
uint32_t storage;
|
||||
size_t decoration;
|
||||
};
|
||||
|
||||
struct distance_member {
|
||||
uint32_t structure;
|
||||
uint32_t member;
|
||||
};
|
||||
|
||||
struct analysis {
|
||||
struct distance_var vars[8];
|
||||
uint32_t var_count;
|
||||
struct distance_member members[8];
|
||||
uint32_t member_count;
|
||||
bool member_locations;
|
||||
};
|
||||
|
||||
static bool is_distance(uint32_t built_in)
|
||||
{
|
||||
return built_in == SpvBuiltInClipDistance || built_in == SpvBuiltInCullDistance;
|
||||
}
|
||||
|
||||
static void analyze(struct module *m, struct analysis *a)
|
||||
{
|
||||
memset(a, 0, sizeof(*a));
|
||||
for (size_t i = 5; i < m->first_declaration; i += LENGTH(m->w[i])) {
|
||||
uint32_t op = OPCODE(m->w[i]);
|
||||
if (op == SpvOpDecorate && LENGTH(m->w[i]) == 4 && m->w[i + 2] == SpvDecorationBuiltIn &&
|
||||
is_distance(m->w[i + 3])) {
|
||||
uint32_t storage, pointee;
|
||||
size_t d = definition(m, m->w[i + 1]);
|
||||
if (a->var_count < 8 && d && OPCODE(m->w[d]) == SpvOpVariable &&
|
||||
pointer_parts(m, m->w[d + 1], &storage, &pointee)) {
|
||||
a->vars[a->var_count++] =
|
||||
(struct distance_var){.id = m->w[i + 1], .built_in = m->w[i + 3], .storage = storage, .decoration = i};
|
||||
} else {
|
||||
m->failed = true;
|
||||
}
|
||||
} else if (op == SpvOpMemberDecorate && LENGTH(m->w[i]) == 5 && m->w[i + 3] == SpvDecorationBuiltIn &&
|
||||
is_distance(m->w[i + 4])) {
|
||||
if (a->member_count < 8)
|
||||
a->members[a->member_count++] = (struct distance_member){m->w[i + 1], m->w[i + 2]};
|
||||
else
|
||||
m->failed = true;
|
||||
} else if (op == SpvOpMemberDecorate && LENGTH(m->w[i]) >= 5 && m->w[i + 3] == SpvDecorationLocation) {
|
||||
a->member_locations = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool uses_distances(const uint32_t *words, size_t count)
|
||||
{
|
||||
for (size_t i = 5; i + 1 < count && LENGTH(words[i]); i += LENGTH(words[i])) {
|
||||
uint32_t op = OPCODE(words[i]);
|
||||
if (op == SpvOpCapability && (words[i + 1] == SpvCapabilityClipDistance || words[i + 1] == SpvCapabilityCullDistance))
|
||||
return true;
|
||||
if (op != SpvOpCapability && op != SpvOpExtension && op != SpvOpExtInstImport && op != SpvOpMemoryModel)
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool spirv_uses_distances(const uint32_t *words, size_t count)
|
||||
{
|
||||
return count > 5 && words[0] == SpvMagicNumber && uses_distances(words, count);
|
||||
}
|
||||
|
||||
static void remove_capabilities(struct module *m)
|
||||
{
|
||||
for (size_t i = 5; i < m->first_declaration; i += LENGTH(m->w[i])) {
|
||||
if (OPCODE(m->w[i]) == SpvOpCapability &&
|
||||
(m->w[i + 1] == SpvCapabilityClipDistance || m->w[i + 1] == SpvCapabilityCullDistance))
|
||||
edit(m, i, INSTEAD);
|
||||
}
|
||||
}
|
||||
|
||||
static void add_to_interface(struct module *m, uint32_t id)
|
||||
{
|
||||
m->interface_add = realloc(m->interface_add, (m->interface_add_count + 1) * sizeof(uint32_t));
|
||||
m->interface_add[m->interface_add_count++] = id;
|
||||
}
|
||||
|
||||
/* A standalone distance variable becomes Private, and its decorations go. */
|
||||
static void privatize(struct module *m, const struct distance_var *var)
|
||||
{
|
||||
size_t d = definition(m, var->id);
|
||||
uint32_t storage, pointee;
|
||||
pointer_parts(m, m->w[d + 1], &storage, &pointee);
|
||||
m->w[d + 1] = pointer_type(m, SpvStorageClassPrivate, pointee);
|
||||
m->w[d + 3] = SpvStorageClassPrivate;
|
||||
mark_private(m, var->id);
|
||||
/* Before SPIR-V 1.4 an entry point lists only its inputs and outputs. */
|
||||
if (m->version < VERSION_1_4)
|
||||
m->interface_remove[var->id] = 1;
|
||||
for (size_t i = 5; i < m->first_declaration; i += LENGTH(m->w[i])) {
|
||||
if (OPCODE(m->w[i]) == SpvOpDecorate && m->w[i + 1] == var->id)
|
||||
edit(m, i, INSTEAD);
|
||||
}
|
||||
}
|
||||
|
||||
struct block_var {
|
||||
uint32_t id;
|
||||
uint32_t structure;
|
||||
bool arrayed;
|
||||
uint32_t array_length;
|
||||
};
|
||||
|
||||
struct stand_in {
|
||||
uint32_t block;
|
||||
uint32_t member;
|
||||
uint32_t variable;
|
||||
};
|
||||
|
||||
/* Every variable of a block type with a distance member, and a Private stand-in per member. */
|
||||
static uint32_t make_stand_ins(struct module *m, const struct analysis *a, struct stand_in *stand_ins, uint32_t max)
|
||||
{
|
||||
uint32_t count = 0;
|
||||
for (size_t i = m->first_declaration; i < m->first_function; i += LENGTH(m->w[i])) {
|
||||
if (OPCODE(m->w[i]) != SpvOpVariable)
|
||||
continue;
|
||||
uint32_t storage, pointee;
|
||||
if (!pointer_parts(m, m->w[i + 1], &storage, &pointee))
|
||||
continue;
|
||||
struct block_var var = {.id = m->w[i + 2], .structure = pointee};
|
||||
size_t d = definition(m, pointee);
|
||||
if (d && OPCODE(m->w[d]) == SpvOpTypeArray) {
|
||||
var.arrayed = true;
|
||||
var.structure = m->w[d + 2];
|
||||
var.array_length = m->w[d + 3];
|
||||
}
|
||||
for (uint32_t k = 0; k < a->member_count; k++) {
|
||||
if (a->members[k].structure != var.structure)
|
||||
continue;
|
||||
if (count == max) {
|
||||
m->failed = true;
|
||||
return count;
|
||||
}
|
||||
size_t s = definition(m, var.structure);
|
||||
uint32_t member_type = m->w[s + 2 + a->members[k].member];
|
||||
uint32_t type = member_type;
|
||||
if (var.arrayed) {
|
||||
const uint32_t operands[2] = {member_type, var.array_length};
|
||||
type = add_type(m, &m->globals, SpvOpTypeArray, operands, 2);
|
||||
}
|
||||
uint32_t variable = new_id(m);
|
||||
EMIT(&m->globals, SpvOpVariable, pointer_type(m, SpvStorageClassPrivate, type), variable,
|
||||
SpvStorageClassPrivate);
|
||||
if (m->version >= VERSION_1_4)
|
||||
add_to_interface(m, variable);
|
||||
stand_ins[count++] = (struct stand_in){var.id, a->members[k].member, variable};
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static const struct stand_in *find_stand_in(const struct module *m, const struct stand_in *stand_ins, uint32_t count,
|
||||
uint32_t base, uint32_t member_index)
|
||||
{
|
||||
uint32_t member;
|
||||
if (!constant_value(m, member_index, &member))
|
||||
return NULL;
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
if (stand_ins[i].block == base && stand_ins[i].member == member)
|
||||
return &stand_ins[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool is_arrayed_block(const struct module *m, uint32_t variable)
|
||||
{
|
||||
size_t d = definition(m, variable);
|
||||
uint32_t storage, pointee;
|
||||
if (!d || !pointer_parts(m, m->w[d + 1], &storage, &pointee))
|
||||
return false;
|
||||
size_t p = definition(m, pointee);
|
||||
return p && OPCODE(m->w[p]) == SpvOpTypeArray;
|
||||
}
|
||||
|
||||
/*
|
||||
* One pass over the function bodies: accesses to a distance member go to its stand-in, and every
|
||||
* pointer derived from a Private one becomes Private too. A Private pointer handed to a function
|
||||
* or merged through a phi would need its types changed beyond this, so that fails the rewrite.
|
||||
*/
|
||||
static void retarget_accesses(struct module *m, const struct stand_in *stand_ins, uint32_t stand_in_count)
|
||||
{
|
||||
for (size_t i = m->first_function; i < m->count; i += LENGTH(m->w[i])) {
|
||||
uint32_t op = OPCODE(m->w[i]);
|
||||
uint32_t length = LENGTH(m->w[i]);
|
||||
switch (op) {
|
||||
case SpvOpAccessChain:
|
||||
case SpvOpInBoundsAccessChain: {
|
||||
uint32_t base = m->w[i + 3];
|
||||
bool arrayed = is_arrayed_block(m, base);
|
||||
uint32_t member_position = arrayed ? 5 : 4;
|
||||
const struct stand_in *stand_in =
|
||||
length > member_position
|
||||
? find_stand_in(m, stand_ins, stand_in_count, base, m->w[i + member_position])
|
||||
: NULL;
|
||||
uint32_t storage, pointee;
|
||||
if (stand_in) {
|
||||
if (!pointer_parts(m, m->w[i + 1], &storage, &pointee)) {
|
||||
m->failed = true;
|
||||
break;
|
||||
}
|
||||
/* Before edit(): a new pointer type is an edit too, and would move the chain's buffer. */
|
||||
uint32_t type = pointer_type(m, SpvStorageClassPrivate, pointee);
|
||||
struct words *chain = edit(m, i, INSTEAD);
|
||||
push(chain, (length - 1) << 16 | op);
|
||||
push(chain, type);
|
||||
push(chain, m->w[i + 2]);
|
||||
push(chain, stand_in->variable);
|
||||
for (uint32_t k = 4; k < length; k++) {
|
||||
if (k != member_position)
|
||||
push(chain, m->w[i + k]);
|
||||
}
|
||||
mark_private(m, m->w[i + 2]);
|
||||
} else if (is_private(m, base)) {
|
||||
if (!pointer_parts(m, m->w[i + 1], &storage, &pointee)) {
|
||||
m->failed = true;
|
||||
break;
|
||||
}
|
||||
m->w[i + 1] = pointer_type(m, SpvStorageClassPrivate, pointee);
|
||||
mark_private(m, m->w[i + 2]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SpvOpPtrAccessChain:
|
||||
case SpvOpCopyObject:
|
||||
if (is_private(m, m->w[i + 3])) {
|
||||
uint32_t storage, pointee;
|
||||
if (!pointer_parts(m, m->w[i + 1], &storage, &pointee)) {
|
||||
m->failed = true;
|
||||
break;
|
||||
}
|
||||
m->w[i + 1] = pointer_type(m, SpvStorageClassPrivate, pointee);
|
||||
mark_private(m, m->w[i + 2]);
|
||||
}
|
||||
break;
|
||||
case SpvOpFunctionCall:
|
||||
for (uint32_t k = 4; k < length; k++) {
|
||||
if (is_private(m, m->w[i + k]))
|
||||
m->failed = true;
|
||||
}
|
||||
break;
|
||||
case SpvOpPhi:
|
||||
case SpvOpSelect:
|
||||
for (uint32_t k = 3; k < length; k++) {
|
||||
if (is_private(m, m->w[i + k]))
|
||||
m->failed = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t string_words(const uint32_t *words, uint32_t available)
|
||||
{
|
||||
for (uint32_t i = 0; i < available; i++) {
|
||||
uint32_t word = words[i];
|
||||
if (!(word & 0xff) || !(word & 0xff00) || !(word & 0xff0000) || !(word & 0xff000000))
|
||||
return i + 1;
|
||||
}
|
||||
return available;
|
||||
}
|
||||
|
||||
static void rewrite_interfaces(struct module *m)
|
||||
{
|
||||
for (size_t i = 5; i < m->first_declaration; i += LENGTH(m->w[i])) {
|
||||
if (OPCODE(m->w[i]) != SpvOpEntryPoint)
|
||||
continue;
|
||||
uint32_t length = LENGTH(m->w[i]);
|
||||
uint32_t first = 3 + string_words(&m->w[i + 3], length - 3);
|
||||
struct words *entry = edit(m, i, INSTEAD);
|
||||
push(entry, 0);
|
||||
for (uint32_t k = 1; k < first; k++)
|
||||
push(entry, m->w[i + k]);
|
||||
for (uint32_t k = first; k < length; k++) {
|
||||
uint32_t id = m->w[i + k];
|
||||
if (id >= m->original_bound || !m->interface_remove[id])
|
||||
push(entry, id);
|
||||
}
|
||||
for (size_t k = 0; k < m->interface_add_count; k++)
|
||||
push(entry, m->interface_add[k]);
|
||||
entry->data[0] = (uint32_t)entry->count << 16 | SpvOpEntryPoint;
|
||||
}
|
||||
}
|
||||
|
||||
static void emit_edits(const struct module *m, struct words *out, size_t offset, enum place place, bool *replaced)
|
||||
{
|
||||
for (size_t k = 0; k < m->edit_count; k++) {
|
||||
const struct edit *e = &m->edits[k];
|
||||
if (e->offset != offset || e->place != place)
|
||||
continue;
|
||||
for (size_t j = 0; j < e->words.count; j++)
|
||||
push(out, e->words.data[j]);
|
||||
if (replaced)
|
||||
*replaced = true;
|
||||
}
|
||||
}
|
||||
|
||||
static bool finish(struct module *m, struct spirv_code *out)
|
||||
{
|
||||
if (m->failed)
|
||||
return false;
|
||||
rewrite_interfaces(m);
|
||||
struct words result = {0};
|
||||
for (int i = 0; i < 5; i++)
|
||||
push(&result, m->w[i]);
|
||||
result.data[3] = m->bound;
|
||||
for (size_t i = 5; i < m->count; i += LENGTH(m->w[i])) {
|
||||
if (i == m->first_function) {
|
||||
for (size_t j = 0; j < m->globals.count; j++)
|
||||
push(&result, m->globals.data[j]);
|
||||
}
|
||||
emit_edits(m, &result, i, BEFORE, NULL);
|
||||
bool replaced = false;
|
||||
emit_edits(m, &result, i, INSTEAD, &replaced);
|
||||
if (!replaced) {
|
||||
for (uint32_t j = 0; j < LENGTH(m->w[i]); j++)
|
||||
push(&result, m->w[i + j]);
|
||||
}
|
||||
emit_edits(m, &result, i, AFTER, NULL);
|
||||
}
|
||||
out->words = result.data;
|
||||
out->count = result.count;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void strip(struct module *m, const struct analysis *a, uint32_t keep)
|
||||
{
|
||||
for (uint32_t i = 0; i < a->var_count; i++) {
|
||||
if (a->vars[i].id != keep)
|
||||
privatize(m, &a->vars[i]);
|
||||
}
|
||||
struct stand_in stand_ins[16];
|
||||
uint32_t count = make_stand_ins(m, a, stand_ins, 16);
|
||||
retarget_accesses(m, stand_ins, count);
|
||||
remove_capabilities(m);
|
||||
}
|
||||
|
||||
bool spirv_strip_distances(const uint32_t *words, size_t count, struct spirv_code *out)
|
||||
{
|
||||
struct module m;
|
||||
if (!load(&m, words, count))
|
||||
return false;
|
||||
struct analysis a;
|
||||
analyze(&m, &a);
|
||||
strip(&m, &a, 0);
|
||||
bool done = finish(&m, out);
|
||||
unload(&m);
|
||||
return done;
|
||||
}
|
||||
|
||||
static const struct distance_var *clip_output(const struct module *m, const struct analysis *a, uint32_t *length)
|
||||
{
|
||||
for (uint32_t i = 0; i < a->var_count; i++) {
|
||||
const struct distance_var *var = &a->vars[i];
|
||||
if (var->built_in != SpvBuiltInClipDistance || var->storage != SpvStorageClassOutput)
|
||||
continue;
|
||||
uint32_t storage, pointee;
|
||||
pointer_parts(m, m->w[definition(m, var->id) + 1], &storage, &pointee);
|
||||
size_t d = definition(m, pointee);
|
||||
if (d && OPCODE(m->w[d]) == SpvOpTypeArray && is_float32(m, m->w[d + 2]) &&
|
||||
constant_value(m, m->w[d + 3], length))
|
||||
return var;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void spirv_clip_info(const uint32_t *words, size_t count, enum clip_role role, struct clip_info *info)
|
||||
{
|
||||
memset(info, 0, sizeof(*info));
|
||||
struct module m;
|
||||
if (!load(&m, words, count)) {
|
||||
info->locations_used = UINT32_MAX;
|
||||
return;
|
||||
}
|
||||
struct analysis a;
|
||||
analyze(&m, &a);
|
||||
if (role == CLIP_PRODUCER)
|
||||
info->has_clip = clip_output(&m, &a, &info->clip_count) != NULL;
|
||||
uint32_t storage_wanted = role == CLIP_PRODUCER ? SpvStorageClassOutput : SpvStorageClassInput;
|
||||
for (size_t i = 5; i < m.first_declaration; i += LENGTH(m.w[i])) {
|
||||
if (OPCODE(m.w[i]) != SpvOpDecorate || LENGTH(m.w[i]) != 4 || m.w[i + 2] != SpvDecorationLocation)
|
||||
continue;
|
||||
size_t d = definition(&m, m.w[i + 1]);
|
||||
uint32_t storage, pointee;
|
||||
if (!d || OPCODE(m.w[d]) != SpvOpVariable || !pointer_parts(&m, m.w[d + 1], &storage, &pointee) ||
|
||||
storage != storage_wanted)
|
||||
continue;
|
||||
uint32_t end = m.w[i + 3] + location_span(&m, pointee, 0);
|
||||
if (end > info->locations_used)
|
||||
info->locations_used = end;
|
||||
}
|
||||
if (a.member_locations || m.failed)
|
||||
info->locations_used = UINT32_MAX;
|
||||
unload(&m);
|
||||
}
|
||||
|
||||
/* Fragment shader: read the clip distances at `location` and discard when any is negative. */
|
||||
static void add_clip_test(struct module *m, uint32_t location, uint32_t clip_count)
|
||||
{
|
||||
uint32_t float_id = float_type(m);
|
||||
uint32_t uint_id = uint_type(m);
|
||||
uint32_t bool_id = bool_type(m);
|
||||
const uint32_t array_operands[2] = {float_id, constant(m, uint_id, clip_count)};
|
||||
uint32_t array_id = add_type(m, &m->globals, SpvOpTypeArray, array_operands, 2);
|
||||
uint32_t input_pointer = pointer_type(m, SpvStorageClassInput, array_id);
|
||||
uint32_t element_pointer = pointer_type(m, SpvStorageClassInput, float_id);
|
||||
uint32_t zero = constant(m, float_id, 0);
|
||||
uint32_t indices[8];
|
||||
for (uint32_t i = 0; i < clip_count; i++)
|
||||
indices[i] = constant(m, uint_id, i);
|
||||
uint32_t input = new_id(m);
|
||||
EMIT(&m->globals, SpvOpVariable, input_pointer, input, SpvStorageClassInput);
|
||||
EMIT(edit(m, m->first_declaration, BEFORE), SpvOpDecorate, input, SpvDecorationLocation, location);
|
||||
add_to_interface(m, input);
|
||||
|
||||
for (size_t i = 5; i < m->first_declaration; i += LENGTH(m->w[i])) {
|
||||
if (OPCODE(m->w[i]) != SpvOpEntryPoint || m->w[i + 1] != SpvExecutionModelFragment)
|
||||
continue;
|
||||
size_t function = definition(m, m->w[i + 2]);
|
||||
if (!function) {
|
||||
m->failed = true;
|
||||
return;
|
||||
}
|
||||
size_t label = function + LENGTH(m->w[function]);
|
||||
if (label >= m->count || OPCODE(m->w[label]) != SpvOpLabel) {
|
||||
m->failed = true;
|
||||
return;
|
||||
}
|
||||
/* Function variables must open the entry block, so the test goes after them. */
|
||||
size_t last = label;
|
||||
for (size_t k = label + LENGTH(m->w[label]); k < m->count; k += LENGTH(m->w[k])) {
|
||||
uint32_t op = OPCODE(m->w[k]);
|
||||
if (op != SpvOpVariable && op != SpvOpLine && op != SpvOpNoLine)
|
||||
break;
|
||||
last = k;
|
||||
}
|
||||
uint32_t original_label = m->w[label + 1];
|
||||
uint32_t entry = new_id(m), kill = new_id(m), join = new_id(m);
|
||||
EMIT(edit(m, label, INSTEAD), SpvOpLabel, entry);
|
||||
struct words *test = edit(m, last, AFTER);
|
||||
uint32_t any = 0;
|
||||
for (uint32_t c = 0; c < clip_count; c++) {
|
||||
uint32_t pointer = new_id(m), value = new_id(m), negative = new_id(m);
|
||||
EMIT(test, SpvOpAccessChain, element_pointer, pointer, input, indices[c]);
|
||||
EMIT(test, SpvOpLoad, float_id, value, pointer);
|
||||
EMIT(test, SpvOpFOrdLessThan, bool_id, negative, value, zero);
|
||||
if (any) {
|
||||
uint32_t either = new_id(m);
|
||||
EMIT(test, SpvOpLogicalOr, bool_id, either, any, negative);
|
||||
any = either;
|
||||
} else {
|
||||
any = negative;
|
||||
}
|
||||
}
|
||||
EMIT(test, SpvOpSelectionMerge, join, SpvSelectionControlMaskNone);
|
||||
EMIT(test, SpvOpBranchConditional, any, kill, join);
|
||||
EMIT(test, SpvOpLabel, kill);
|
||||
push(test, 1u << 16 | SpvOpKill);
|
||||
EMIT(test, SpvOpLabel, join);
|
||||
EMIT(test, SpvOpBranch, original_label);
|
||||
EMIT(test, SpvOpLabel, original_label);
|
||||
}
|
||||
}
|
||||
|
||||
bool spirv_emulate_clip(const uint32_t *words, size_t count, enum clip_role role, uint32_t location,
|
||||
uint32_t clip_count, struct spirv_code *out)
|
||||
{
|
||||
if (clip_count == 0 || clip_count > 8)
|
||||
return false;
|
||||
struct module m;
|
||||
if (!load(&m, words, count))
|
||||
return false;
|
||||
struct analysis a;
|
||||
analyze(&m, &a);
|
||||
uint32_t keep = 0;
|
||||
if (role == CLIP_PRODUCER) {
|
||||
uint32_t length = 0;
|
||||
const struct distance_var *clip = clip_output(&m, &a, &length);
|
||||
if (!clip || length != clip_count) {
|
||||
unload(&m);
|
||||
return false;
|
||||
}
|
||||
keep = clip->id;
|
||||
m.w[clip->decoration + 2] = SpvDecorationLocation;
|
||||
m.w[clip->decoration + 3] = location;
|
||||
}
|
||||
strip(&m, &a, keep);
|
||||
if (role == CLIP_CONSUMER)
|
||||
add_clip_test(&m, location, clip_count);
|
||||
bool done = finish(&m, out);
|
||||
unload(&m);
|
||||
return done;
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
/*
|
||||
* DROIDDECK_MALI_COMPAT_TRACE=1: the physical-device queries an application makes before
|
||||
* vkCreateDevice, logged as they pass through. Zink on Venus over an older Mali driver gave up
|
||||
* after vkGetPhysicalDeviceProperties2 without a word (its release builds print nothing there),
|
||||
* so the last query in the log is where it stopped.
|
||||
*/
|
||||
#include "mali_compat.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static uint32_t format_queries;
|
||||
|
||||
static bool format_worth_logging(uint32_t n, VkFormatFeatureFlags linear, VkFormatFeatureFlags optimal, VkFormatFeatureFlags buffer)
|
||||
{
|
||||
return n == 1 || n % 25 == 0 || (!linear && !optimal && !buffer);
|
||||
}
|
||||
|
||||
static VKAPI_ATTR VkResult VKAPI_CALL TraceEnumeratePhysicalDevices(VkInstance instance, uint32_t *count, VkPhysicalDevice *devices)
|
||||
{
|
||||
struct instance *inst = instance_from_handle(instance);
|
||||
VkResult r = inst->EnumeratePhysicalDevices(instance, count, devices);
|
||||
layer_log("trace: vkEnumeratePhysicalDevices (%s): %d, %u device(s)", devices ? "list" : "count", (int)r, count ? *count : 0);
|
||||
return r;
|
||||
}
|
||||
|
||||
static VKAPI_ATTR void VKAPI_CALL TraceGetPhysicalDeviceMemoryProperties(VkPhysicalDevice pd, VkPhysicalDeviceMemoryProperties *p)
|
||||
{
|
||||
struct instance *inst = instance_from_handle(pd);
|
||||
inst->GetPhysicalDeviceMemoryProperties(pd, p);
|
||||
char types[384] = "";
|
||||
size_t o = 0;
|
||||
for (uint32_t i = 0; i < p->memoryTypeCount && o + 16 < sizeof(types); i++)
|
||||
o += (size_t)snprintf(types + o, sizeof(types) - o, " %u:h%u/0x%x", i, p->memoryTypes[i].heapIndex,
|
||||
(unsigned)p->memoryTypes[i].propertyFlags);
|
||||
layer_log("trace: vkGetPhysicalDeviceMemoryProperties: %u heaps, %u types:%s", p->memoryHeapCount, p->memoryTypeCount, types);
|
||||
}
|
||||
|
||||
static VKAPI_ATTR void VKAPI_CALL TraceGetPhysicalDeviceMemoryProperties2(VkPhysicalDevice pd, VkPhysicalDeviceMemoryProperties2 *p)
|
||||
{
|
||||
struct instance *inst = instance_from_handle(pd);
|
||||
inst->GetPhysicalDeviceMemoryProperties2(pd, p);
|
||||
char chain[160] = "";
|
||||
size_t o = 0;
|
||||
for (VkBaseOutStructure *s = p->pNext; s && o + 16 < sizeof(chain); s = s->pNext)
|
||||
o += (size_t)snprintf(chain + o, sizeof(chain) - o, " %d", (int)s->sType);
|
||||
layer_log("trace: vkGetPhysicalDeviceMemoryProperties2: %u heaps, %u types, chain:%s", p->memoryProperties.memoryHeapCount,
|
||||
p->memoryProperties.memoryTypeCount, chain);
|
||||
}
|
||||
|
||||
static void log_queue_families(const char *what, uint32_t n, const VkQueueFamilyProperties *(*at)(const void *, uint32_t), const void *arr)
|
||||
{
|
||||
char fams[256] = "";
|
||||
size_t o = 0;
|
||||
for (uint32_t i = 0; arr && i < n && o + 24 < sizeof(fams); i++) {
|
||||
const VkQueueFamilyProperties *q = at(arr, i);
|
||||
o += (size_t)snprintf(fams + o, sizeof(fams) - o, " %u:0x%x*%u", i, (unsigned)q->queueFlags, q->queueCount);
|
||||
}
|
||||
layer_log("trace: %s: %u famil%s%s", what, n, n == 1 ? "y" : "ies", fams);
|
||||
}
|
||||
|
||||
static const VkQueueFamilyProperties *qf1(const void *a, uint32_t i) { return &((const VkQueueFamilyProperties *)a)[i]; }
|
||||
static const VkQueueFamilyProperties *qf2(const void *a, uint32_t i) { return &((const VkQueueFamilyProperties2 *)a)[i].queueFamilyProperties; }
|
||||
|
||||
static VKAPI_ATTR void VKAPI_CALL TraceGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice pd, uint32_t *n, VkQueueFamilyProperties *p)
|
||||
{
|
||||
struct instance *inst = instance_from_handle(pd);
|
||||
inst->GetPhysicalDeviceQueueFamilyProperties(pd, n, p);
|
||||
log_queue_families("vkGetPhysicalDeviceQueueFamilyProperties", n ? *n : 0, qf1, p);
|
||||
}
|
||||
|
||||
static VKAPI_ATTR void VKAPI_CALL TraceGetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice pd, uint32_t *n, VkQueueFamilyProperties2 *p)
|
||||
{
|
||||
struct instance *inst = instance_from_handle(pd);
|
||||
inst->GetPhysicalDeviceQueueFamilyProperties2(pd, n, p);
|
||||
log_queue_families("vkGetPhysicalDeviceQueueFamilyProperties2", n ? *n : 0, qf2, p);
|
||||
}
|
||||
|
||||
static VKAPI_ATTR void VKAPI_CALL TraceGetPhysicalDeviceFormatProperties(VkPhysicalDevice pd, VkFormat format, VkFormatProperties *p)
|
||||
{
|
||||
struct instance *inst = instance_from_handle(pd);
|
||||
if (inst->active) GetPhysicalDeviceFormatProperties(pd, format, p);
|
||||
else inst->GetPhysicalDeviceFormatProperties(pd, format, p);
|
||||
uint32_t n = __atomic_add_fetch(&format_queries, 1, __ATOMIC_RELAXED);
|
||||
if (format_worth_logging(n, p->linearTilingFeatures, p->optimalTilingFeatures, p->bufferFeatures))
|
||||
layer_log("trace: vkGetPhysicalDeviceFormatProperties #%u: format %d linear 0x%x optimal 0x%x buffer 0x%x", n, (int)format,
|
||||
(unsigned)p->linearTilingFeatures, (unsigned)p->optimalTilingFeatures, (unsigned)p->bufferFeatures);
|
||||
}
|
||||
|
||||
static VKAPI_ATTR void VKAPI_CALL TraceGetPhysicalDeviceFormatProperties2(VkPhysicalDevice pd, VkFormat format, VkFormatProperties2 *p)
|
||||
{
|
||||
struct instance *inst = instance_from_handle(pd);
|
||||
if (inst->active) GetPhysicalDeviceFormatProperties2(pd, format, p);
|
||||
else inst->GetPhysicalDeviceFormatProperties2(pd, format, p);
|
||||
uint32_t n = __atomic_add_fetch(&format_queries, 1, __ATOMIC_RELAXED);
|
||||
const VkFormatProperties *f = &p->formatProperties;
|
||||
if (format_worth_logging(n, f->linearTilingFeatures, f->optimalTilingFeatures, f->bufferFeatures))
|
||||
layer_log("trace: vkGetPhysicalDeviceFormatProperties2 #%u: format %d linear 0x%x optimal 0x%x buffer 0x%x", n, (int)format,
|
||||
(unsigned)f->linearTilingFeatures, (unsigned)f->optimalTilingFeatures, (unsigned)f->bufferFeatures);
|
||||
}
|
||||
|
||||
static VKAPI_ATTR VkResult VKAPI_CALL TraceGetPhysicalDeviceImageFormatProperties(VkPhysicalDevice pd, VkFormat format, VkImageType type,
|
||||
VkImageTiling tiling, VkImageUsageFlags usage,
|
||||
VkImageCreateFlags flags, VkImageFormatProperties *p)
|
||||
{
|
||||
struct instance *inst = instance_from_handle(pd);
|
||||
VkResult r = inst->active ? GetPhysicalDeviceImageFormatProperties(pd, format, type, tiling, usage, flags, p)
|
||||
: inst->GetPhysicalDeviceImageFormatProperties(pd, format, type, tiling, usage, flags, p);
|
||||
if (r != VK_SUCCESS)
|
||||
layer_log("trace: vkGetPhysicalDeviceImageFormatProperties: format %d type %d tiling %d usage 0x%x flags 0x%x -> %d", (int)format,
|
||||
(int)type, (int)tiling, (unsigned)usage, (unsigned)flags, (int)r);
|
||||
return r;
|
||||
}
|
||||
|
||||
static VKAPI_ATTR VkResult VKAPI_CALL TraceGetPhysicalDeviceImageFormatProperties2(VkPhysicalDevice pd, const VkPhysicalDeviceImageFormatInfo2 *info,
|
||||
VkImageFormatProperties2 *p)
|
||||
{
|
||||
struct instance *inst = instance_from_handle(pd);
|
||||
VkResult r = inst->active ? GetPhysicalDeviceImageFormatProperties2(pd, info, p) : inst->GetPhysicalDeviceImageFormatProperties2(pd, info, p);
|
||||
if (r != VK_SUCCESS)
|
||||
layer_log("trace: vkGetPhysicalDeviceImageFormatProperties2: format %d type %d tiling %d usage 0x%x flags 0x%x -> %d", (int)info->format,
|
||||
(int)info->type, (int)info->tiling, (unsigned)info->usage, (unsigned)info->flags, (int)r);
|
||||
return r;
|
||||
}
|
||||
|
||||
static VKAPI_ATTR void VKAPI_CALL TraceGetPhysicalDeviceExternalBufferProperties(VkPhysicalDevice pd, const VkPhysicalDeviceExternalBufferInfo *info,
|
||||
VkExternalBufferProperties *p)
|
||||
{
|
||||
struct instance *inst = instance_from_handle(pd);
|
||||
inst->GetPhysicalDeviceExternalBufferProperties(pd, info, p);
|
||||
layer_log("trace: vkGetPhysicalDeviceExternalBufferProperties: handle 0x%x usage 0x%x -> features 0x%x", (unsigned)info->handleType,
|
||||
(unsigned)info->usage, (unsigned)p->externalMemoryProperties.externalMemoryFeatures);
|
||||
}
|
||||
|
||||
static VKAPI_ATTR void VKAPI_CALL TraceGetPhysicalDeviceExternalSemaphoreProperties(VkPhysicalDevice pd,
|
||||
const VkPhysicalDeviceExternalSemaphoreInfo *info,
|
||||
VkExternalSemaphoreProperties *p)
|
||||
{
|
||||
struct instance *inst = instance_from_handle(pd);
|
||||
inst->GetPhysicalDeviceExternalSemaphoreProperties(pd, info, p);
|
||||
layer_log("trace: vkGetPhysicalDeviceExternalSemaphoreProperties: handle 0x%x -> features 0x%x", (unsigned)info->handleType,
|
||||
(unsigned)p->externalSemaphoreFeatures);
|
||||
}
|
||||
|
||||
static VKAPI_ATTR void VKAPI_CALL TraceGetPhysicalDeviceExternalFenceProperties(VkPhysicalDevice pd, const VkPhysicalDeviceExternalFenceInfo *info,
|
||||
VkExternalFenceProperties *p)
|
||||
{
|
||||
struct instance *inst = instance_from_handle(pd);
|
||||
inst->GetPhysicalDeviceExternalFenceProperties(pd, info, p);
|
||||
layer_log("trace: vkGetPhysicalDeviceExternalFenceProperties: handle 0x%x -> features 0x%x", (unsigned)info->handleType,
|
||||
(unsigned)p->externalFenceFeatures);
|
||||
}
|
||||
|
||||
void trace_extension_names(const VkExtensionProperties *ext, uint32_t n)
|
||||
{
|
||||
char line[400];
|
||||
size_t o = 0;
|
||||
line[0] = 0;
|
||||
for (uint32_t i = 0; i < n; i++) {
|
||||
size_t len = strlen(ext[i].extensionName);
|
||||
if (o && o + len + 2 > sizeof(line)) {
|
||||
layer_log("trace: extensions:%s", line);
|
||||
o = 0;
|
||||
line[0] = 0;
|
||||
}
|
||||
o += (size_t)snprintf(line + o, sizeof(line) - o, " %s", ext[i].extensionName);
|
||||
}
|
||||
if (o) layer_log("trace: extensions:%s", line);
|
||||
}
|
||||
|
||||
void trace_load(struct instance *inst)
|
||||
{
|
||||
#define T_LOAD(name) inst->name = (PFN_vk##name)inst->gipa(inst->handle, "vk" #name);
|
||||
#define T_LOAD_KHR(name) \
|
||||
if (!inst->name) \
|
||||
inst->name = (PFN_vk##name)inst->gipa(inst->handle, "vk" #name "KHR");
|
||||
T_LOAD(EnumeratePhysicalDevices)
|
||||
T_LOAD(GetPhysicalDeviceMemoryProperties2)
|
||||
T_LOAD_KHR(GetPhysicalDeviceMemoryProperties2)
|
||||
T_LOAD(GetPhysicalDeviceQueueFamilyProperties)
|
||||
T_LOAD(GetPhysicalDeviceQueueFamilyProperties2)
|
||||
T_LOAD_KHR(GetPhysicalDeviceQueueFamilyProperties2)
|
||||
T_LOAD(GetPhysicalDeviceExternalBufferProperties)
|
||||
T_LOAD_KHR(GetPhysicalDeviceExternalBufferProperties)
|
||||
T_LOAD(GetPhysicalDeviceExternalSemaphoreProperties)
|
||||
T_LOAD_KHR(GetPhysicalDeviceExternalSemaphoreProperties)
|
||||
T_LOAD(GetPhysicalDeviceExternalFenceProperties)
|
||||
T_LOAD_KHR(GetPhysicalDeviceExternalFenceProperties)
|
||||
#undef T_LOAD
|
||||
#undef T_LOAD_KHR
|
||||
}
|
||||
|
||||
struct trace_hook {
|
||||
const char *name;
|
||||
PFN_vkVoidFunction function;
|
||||
size_t next_offset;
|
||||
};
|
||||
|
||||
#define TH(fn, field) {"vk" #fn, (PFN_vkVoidFunction)Trace##field, offsetof(struct instance, field)}
|
||||
|
||||
static const struct trace_hook trace_hooks[] = {
|
||||
TH(EnumeratePhysicalDevices, EnumeratePhysicalDevices),
|
||||
TH(GetPhysicalDeviceMemoryProperties, GetPhysicalDeviceMemoryProperties),
|
||||
TH(GetPhysicalDeviceMemoryProperties2, GetPhysicalDeviceMemoryProperties2),
|
||||
TH(GetPhysicalDeviceMemoryProperties2KHR, GetPhysicalDeviceMemoryProperties2),
|
||||
TH(GetPhysicalDeviceQueueFamilyProperties, GetPhysicalDeviceQueueFamilyProperties),
|
||||
TH(GetPhysicalDeviceQueueFamilyProperties2, GetPhysicalDeviceQueueFamilyProperties2),
|
||||
TH(GetPhysicalDeviceQueueFamilyProperties2KHR, GetPhysicalDeviceQueueFamilyProperties2),
|
||||
TH(GetPhysicalDeviceFormatProperties, GetPhysicalDeviceFormatProperties),
|
||||
TH(GetPhysicalDeviceFormatProperties2, GetPhysicalDeviceFormatProperties2),
|
||||
TH(GetPhysicalDeviceFormatProperties2KHR, GetPhysicalDeviceFormatProperties2),
|
||||
TH(GetPhysicalDeviceImageFormatProperties, GetPhysicalDeviceImageFormatProperties),
|
||||
TH(GetPhysicalDeviceImageFormatProperties2, GetPhysicalDeviceImageFormatProperties2),
|
||||
TH(GetPhysicalDeviceImageFormatProperties2KHR, GetPhysicalDeviceImageFormatProperties2),
|
||||
TH(GetPhysicalDeviceExternalBufferProperties, GetPhysicalDeviceExternalBufferProperties),
|
||||
TH(GetPhysicalDeviceExternalBufferPropertiesKHR, GetPhysicalDeviceExternalBufferProperties),
|
||||
TH(GetPhysicalDeviceExternalSemaphoreProperties, GetPhysicalDeviceExternalSemaphoreProperties),
|
||||
TH(GetPhysicalDeviceExternalSemaphorePropertiesKHR, GetPhysicalDeviceExternalSemaphoreProperties),
|
||||
TH(GetPhysicalDeviceExternalFenceProperties, GetPhysicalDeviceExternalFenceProperties),
|
||||
TH(GetPhysicalDeviceExternalFencePropertiesKHR, GetPhysicalDeviceExternalFenceProperties),
|
||||
};
|
||||
|
||||
PFN_vkVoidFunction trace_hook(struct instance *inst, const char *name)
|
||||
{
|
||||
for (size_t i = 0; i < sizeof(trace_hooks) / sizeof(trace_hooks[0]); i++) {
|
||||
if (strcmp(name, trace_hooks[i].name)) continue;
|
||||
void *next = *(void **)((char *)inst + trace_hooks[i].next_offset);
|
||||
return next ? trace_hooks[i].function : NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
Loaded 100 of 215 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user