Files
DroidDeck/tools/upscale/layer/fsr4_pipeline.h
T
The412Banner 7aa54ab9c7 upscale: hide VK_EXT_descriptor_buffer from games so Full FSR 4.1 shows the picture
Root cause of the black Full FSR 4.1 frame in D3D12 games on Turnip: vkd3d-proton uses its own
descriptor buffers in the command buffers the upscaler records into. Measured on the Red Magic 12
Pro (Adreno 850) with the XeSS DX12 sample: Full black in 9/9 shots, and still black with the direct
output write off and with the exposure pass off; with VKD3D_DISABLE_EXTENSIONS=VK_EXT_descriptor_buffer
the picture is there (5/6 shots coloured, the sixth caught the triangle off screen, as with the other
engines), with the direct write on.

The layer now hides the extension from the game (vkd3d then uses its classic descriptors) and still
enables it for itself; DROIDDECK_UPSCALE_APP_DESCRIPTOR_BUFFER=1 shows it again. The Lite fallback
now triggers only when the game enabled descriptor buffers anyway (Turnip), not for every D3D12
frame. The FULL_DIRECT_OUT / FULL_AUTO_EXPOSURE test switches are removed.
2026-12-04 20:43:28 -05:00

172 lines
8.7 KiB
C

// Vulkan FSR 4.1.1 INT8 + Qualcomm Hexagon HTP v81 NPU pipeline for libVkLayer_winlator_fsr4_npu.so
#pragma once
#include <vulkan/vulkan.h>
#include <vulkan/vulkan_android.h>
#include "fsr4_seam_proto.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct WlVkDispatch {
VkInstance instance;
VkPhysicalDevice phys_dev;
VkDevice device;
uint32_t graphics_qf;
// Detected optional extension/feature availability
int has_desc_buf;
int app_desc_buf; // the game itself enabled VK_EXT_descriptor_buffer
int has_mut_desc;
int has_ext_ahb;
int has_bda;
int has_f16;
int has_i8;
int has_int_dot;
int has_sync2;
int has_qf_foreign;
int has_compute_derivs;
int has_8bit_storage;
int has_16bit_storage;
int has_timestamps;
float timestamp_period;
uint32_t subgroup_req_stages;
uint32_t subgroup_min;
uint32_t subgroup_max;
// Instance-level dispatch
PFN_vkGetPhysicalDeviceProperties GetPhysicalDeviceProperties;
PFN_vkGetPhysicalDeviceProperties2 GetPhysicalDeviceProperties2;
PFN_vkGetPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties;
PFN_vkGetPhysicalDeviceFormatProperties GetPhysicalDeviceFormatProperties;
PFN_vkGetPhysicalDeviceQueueFamilyProperties GetPhysicalDeviceQueueFamilyProperties;
// Device-level dispatch
PFN_vkGetDeviceProcAddr GetDeviceProcAddr;
PFN_vkCreateBuffer CreateBuffer;
PFN_vkDestroyBuffer DestroyBuffer;
PFN_vkGetBufferMemoryRequirements GetBufferMemoryRequirements;
PFN_vkBindBufferMemory BindBufferMemory;
PFN_vkGetBufferDeviceAddress GetBufferDeviceAddress;
PFN_vkAllocateMemory AllocateMemory;
PFN_vkFreeMemory FreeMemory;
PFN_vkMapMemory MapMemory;
PFN_vkUnmapMemory UnmapMemory;
PFN_vkCreateImage CreateImage;
PFN_vkDestroyImage DestroyImage;
PFN_vkGetImageMemoryRequirements GetImageMemoryRequirements;
PFN_vkBindImageMemory BindImageMemory;
PFN_vkCreateImageView CreateImageView;
PFN_vkDestroyImageView DestroyImageView;
PFN_vkCreateSampler CreateSampler;
PFN_vkDestroySampler DestroySampler;
PFN_vkCreateShaderModule CreateShaderModule;
PFN_vkDestroyShaderModule DestroyShaderModule;
PFN_vkCreateDescriptorSetLayout CreateDescriptorSetLayout;
PFN_vkDestroyDescriptorSetLayout DestroyDescriptorSetLayout;
PFN_vkCreateDescriptorPool CreateDescriptorPool;
PFN_vkDestroyDescriptorPool DestroyDescriptorPool;
PFN_vkAllocateDescriptorSets AllocateDescriptorSets;
PFN_vkUpdateDescriptorSets UpdateDescriptorSets;
PFN_vkCmdBindDescriptorSets CmdBindDescriptorSets;
PFN_vkCreatePipelineLayout CreatePipelineLayout;
PFN_vkDestroyPipelineLayout DestroyPipelineLayout;
PFN_vkCreateComputePipelines CreateComputePipelines;
PFN_vkDestroyPipeline DestroyPipeline;
PFN_vkCmdBindPipeline CmdBindPipeline;
PFN_vkCmdPushConstants CmdPushConstants;
PFN_vkCmdDispatch CmdDispatch;
PFN_vkCmdPipelineBarrier CmdPipelineBarrier;
PFN_vkCmdPipelineBarrier2 CmdPipelineBarrier2;
PFN_vkCmdClearColorImage CmdClearColorImage;
PFN_vkCmdClearDepthStencilImage CmdClearDepthStencilImage;
PFN_vkCmdFillBuffer CmdFillBuffer;
PFN_vkCmdCopyBuffer CmdCopyBuffer;
PFN_vkCmdCopyImageToBuffer CmdCopyImageToBuffer;
PFN_vkCmdCopyBufferToImage CmdCopyBufferToImage;
PFN_vkCmdBlitImage CmdBlitImage;
PFN_vkCmdCopyImage CmdCopyImage;
PFN_vkDeviceWaitIdle DeviceWaitIdle;
// Events (for same-frame NPU Sync mode + slot retirement)
PFN_vkCreateEvent CreateEvent;
PFN_vkDestroyEvent DestroyEvent;
PFN_vkSetEvent SetEvent;
PFN_vkResetEvent ResetEvent;
PFN_vkGetEventStatus GetEventStatus;
PFN_vkCmdSetEvent CmdSetEvent;
PFN_vkCmdResetEvent CmdResetEvent;
PFN_vkCmdWaitEvents CmdWaitEvents;
// Timestamp query pool (for per-frame GPU ms HUD telemetry)
PFN_vkCreateQueryPool CreateQueryPool;
PFN_vkDestroyQueryPool DestroyQueryPool;
PFN_vkCmdResetQueryPool CmdResetQueryPool;
PFN_vkCmdWriteTimestamp CmdWriteTimestamp;
PFN_vkGetQueryPoolResults GetQueryPoolResults;
// Extension dispatch
PFN_vkGetDescriptorSetLayoutSizeEXT GetDescriptorSetLayoutSizeEXT;
PFN_vkGetDescriptorSetLayoutBindingOffsetEXT GetDescriptorSetLayoutBindingOffsetEXT;
PFN_vkGetDescriptorEXT GetDescriptorEXT;
PFN_vkCmdBindDescriptorBuffersEXT CmdBindDescriptorBuffersEXT;
PFN_vkCmdSetDescriptorBufferOffsetsEXT CmdSetDescriptorBufferOffsetsEXT;
PFN_vkCmdBindDescriptorBufferEmbeddedSamplersEXT CmdBindDescriptorBufferEmbeddedSamplersEXT;
PFN_vkGetAndroidHardwareBufferPropertiesANDROID GetAndroidHardwareBufferPropertiesANDROID;
} WlVkDispatch;
typedef struct WlFsr4Pipeline WlFsr4Pipeline;
// Legacy aliases kept for source clarity
enum {
WL_FSR_ENGINE_FSR4_NPU = WL_FSR_BACKEND_FSR4_1_LITE_NPU,
WL_FSR_ENGINE_FSR3_GPU = WL_FSR_BACKEND_FSR3_GPU,
};
typedef struct WlFsrDispatchConfig {
int force_bypass; /* 1 = live OFF bypass */
int backend; /* WL_FSR_BACKEND_* (including WL_FSR_BACKEND_AUTO) */
int npu_sync; /* 1 = Sync (low-latency same-frame wait), 0 = Async (pipelined 1-frame) */
float sharpness; /* 0.0f..1.0f user RCAS sharpness (-1.0f = default 0.55f) */
int fps_limit; /* 0 = uncapped, >0 = active FPS limit */
int has_supported_npu; /* 1 = Snapdragon 8 Elite / 8 Elite Gen 5 with bundled HTP v79/v81 pack */
int anti_throttle; /* 1 = proactive anti-throttling enabled (Auto mode + capped FPS ONLY) */
float thermal_headroom; /* Android PowerManager.getThermalHeadroom(10); < 0 if unavailable/NaN */
float batt_temp_c; /* Battery temperature in C (fallback if thermal_headroom < 0); <= 0 if unknown */
} WlFsrDispatchConfig;
typedef struct WlFsrDispatchResult {
int rc; /* 2 = active upscaler, 1 = fallback blit, 0 = invalid */
int npu_used; /* 1 if Hexagon HTP NPU executed this path */
int fallback_used; /* 1 if automatic fallback to FSR 3.1 / Lite GPU engaged */
int preset; /* 0 = perf, 1 = ultraperf */
uint32_t htp_us; /* Hexagon HTP execution time (us) */
uint32_t gpu_us; /* Vulkan GPU compute execution time (us) */
uint64_t dispatches; /* total upscaler dispatches */
const char *backend_tag; /* Exact HUD string: "FSR3.1-GPU", "FSR4.1-Lite-GPU", etc. */
const char *reason; /* Diagnostic reason string */
} WlFsrDispatchResult;
WlFsr4Pipeline *wl_fsr4_pipe_create(const WlVkDispatch *vk);
void wl_fsr4_pipe_destroy(WlFsr4Pipeline *p);
uint64_t wl_fsr4_pipe_caps(const WlFsr4Pipeline *p);
void wl_fsr4_pipe_diag(const WlFsr4Pipeline *p, const char **out_ahb, const char **out_npu_state);
void wl_fsr4_pipe_release_sync_events(WlFsr4Pipeline *p);
void wl_fsr4_pipe_record_present(WlFsr4Pipeline *p, int64_t dt_ns);
// Execute one upscaling dispatch inside the game's command buffer.
int wl_fsr4_pipe_dispatch(WlFsr4Pipeline *p, VkCommandBuffer cb,
const WlFsr4FrameDesc *frame,
const WlFsrDispatchConfig *cfg,
WlFsrDispatchResult *out_res);
// Helper to resolve tracked image info from the layer's image table
int wl_fsr4_lookup_image_info(VkDevice dev, VkImage img,
VkFormat *out_fmt, uint32_t *out_w, uint32_t *out_h,
VkImageUsageFlags *out_usage);
#ifdef __cplusplus
}
#endif