From c5cdcfee4212e86296552218aa20d48bc22c2207 Mon Sep 17 00:00:00 2001 From: Utkarsh Dalal Date: Fri, 20 Nov 2026 10:23:11 +0530 Subject: [PATCH 1/2] wrapper: emulate VK_EXT_depth_clip_enable for non-D3D clients on drivers with depthClamp zink exposes GL_ARB_depth_clamp only with VK_EXT_depth_clip_enable, and that extension is the last missing GL 3.2 requirement on Mali-G615 r44p1: zink gives OpenGL 3.1 there and 3.2 core and compatibility context requests fail. The driver does not list the extension but has depthClamp. Without the extension the driver clips against the depth planes exactly when depthClampEnable is false. When the base driver lacks the extension, has depthClamp and the client is not DXVK or vkd3d, the wrapper now lists VK_EXT_depth_clip_enable with depthClipEnable and reports extendedDynamicState3DepthClipEnable as unsupported. At device creation the extension is not passed to the driver and its feature struct is unlinked from the chain before the feature masking, so the caller's depthClipEnable stays set. At pipeline creation a VkPipelineRasterizationDepthClipStateCreateInfoEXT in a pipeline that owns pre-rasterization state is removed from a copy of the rasterization state, and depthClampEnable becomes !depthClipEnable (clamping only when the device enabled depthClamp). D3D clients, drivers with the extension and drivers without depthClamp are unchanged. WRAPPER_EMULATE_DEPTH_CLIP_ENABLE=0 turns it off. --- src/vulkan/wrapper/wrapper_device.c | 93 +++++++++++++++++++- src/vulkan/wrapper/wrapper_physical_device.c | 13 +++ src/vulkan/wrapper/wrapper_private.h | 2 + 3 files changed, 105 insertions(+), 3 deletions(-) diff --git a/src/vulkan/wrapper/wrapper_device.c b/src/vulkan/wrapper/wrapper_device.c index 2602532d383..2e3e5cc5d79 100644 --- a/src/vulkan/wrapper/wrapper_device.c +++ b/src/vulkan/wrapper/wrapper_device.c @@ -224,6 +224,12 @@ static void process_pnext_chain(VkBaseInStructure *create_info, struct wrapper_p "Unlinking emulated VkPhysicalDeviceImagelessFramebufferFeatures from pNext chain"); unlink_vk_struct(create_info, ¤t, &prev); continue; + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT: + if (!pdevice->emulate_depth_clip_enable) + break; + WRAPPER_LOG(info, "Unlinking emulated VkPhysicalDeviceDepthClipEnableFeaturesEXT from pNext chain"); + unlink_vk_struct(create_info, ¤t, &prev); + continue; case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_UNUSED_ATTACHMENTS_FEATURES_EXT: if (pdevice->base_supported_extensions.EXT_dynamic_rendering_unused_attachments) break; @@ -1482,6 +1488,9 @@ if (pdf2 && pdf2->features.f) { \ else if (device->emulate_zero_divisor) WRAPPER_LOG(info, "Emulating the zero vertex attribute divisor"); + device->emulate_depth_clip_enable = physical_device->emulate_depth_clip_enable && + device->vk.enabled_extensions.EXT_depth_clip_enable; + device->cmdbuf_entry_barrier = debug_get_bool_option("WRAPPER_CMDBUF_ENTRY_BARRIER", physical_device->driver_properties.driverID == VK_DRIVER_ID_IMAGINATION_PROPRIETARY); @@ -4078,6 +4087,71 @@ wrapper_CreateComputePipelines(VkDevice _device, VkPipelineCache pipelineCache, return result; } +static bool +wrapper_has_pre_rasterization_state(const VkGraphicsPipelineCreateInfo *info) +{ + const VkGraphicsPipelineLibraryCreateInfoEXT *gpl = + vk_find_struct_const(info->pNext, GRAPHICS_PIPELINE_LIBRARY_CREATE_INFO_EXT); + if (gpl) + return gpl->flags & VK_GRAPHICS_PIPELINE_LIBRARY_PRE_RASTERIZATION_SHADERS_BIT_EXT; + const VkPipelineCreateFlags2CreateInfo *flags2 = + vk_find_struct_const(info->pNext, PIPELINE_CREATE_FLAGS_2_CREATE_INFO); + const VkPipelineLibraryCreateInfoKHR *libs = + vk_find_struct_const(info->pNext, PIPELINE_LIBRARY_CREATE_INFO_KHR); + bool library = flags2 ? (flags2->flags & VK_PIPELINE_CREATE_2_LIBRARY_BIT_KHR) + : (info->flags & VK_PIPELINE_CREATE_LIBRARY_BIT_KHR); + return !library && !(libs && libs->libraryCount); +} + +/* Without VK_EXT_depth_clip_enable the driver clips exactly when + * depthClampEnable is false, so clip=1/clamp=0 and clip=0/clamp=1 map exactly, + * with clip=1 a clamp is a no-op, and clip=0/clamp=0 gets clamping when the + * device enabled depthClamp, the closest native behavior (as DXVK does + * without the extension). */ +static VkResult +wrapper_lower_depth_clip(const struct wrapper_device *device, void *mem, + const VkGraphicsPipelineCreateInfo **infos, uint32_t count) +{ + VkGraphicsPipelineCreateInfo *out = NULL; + + for (uint32_t i = 0; i < count; i++) { + const VkGraphicsPipelineCreateInfo *info = &(*infos)[i]; + const VkPipelineRasterizationStateCreateInfo *rs = info->pRasterizationState; + if (!rs || !wrapper_has_pre_rasterization_state(info)) + continue; + const VkPipelineRasterizationDepthClipStateCreateInfoEXT *clip = + vk_find_struct_const(rs->pNext, PIPELINE_RASTERIZATION_DEPTH_CLIP_STATE_CREATE_INFO_EXT); + if (!clip) + continue; + + if (!out) { + out = ralloc_array(mem, VkGraphicsPipelineCreateInfo, count); + if (!out) + return VK_ERROR_OUT_OF_HOST_MEMORY; + memcpy(out, *infos, count * sizeof(*out)); + } + + VkPipelineRasterizationStateCreateInfo *copy = ralloc_memdup(mem, rs, sizeof(*rs)); + if (!copy) + return VK_ERROR_OUT_OF_HOST_MEMORY; + VkBaseOutStructure *tail = (VkBaseOutStructure *)copy; + for (const VkBaseInStructure *in = rs->pNext; in != (const void *)clip; in = in->pNext) { + VkBaseOutStructure *node = ralloc_memdup(mem, in, vk_structure_type_size(in)); + if (!node) + return VK_ERROR_OUT_OF_HOST_MEMORY; + tail->pNext = node; + tail = node; + } + tail->pNext = (VkBaseOutStructure *)clip->pNext; + copy->depthClampEnable = !clip->depthClipEnable && device->vk.enabled_features.depthClamp; + out[i].pRasterizationState = copy; + } + + if (out) + *infos = out; + return VK_SUCCESS; +} + VKAPI_ATTR VkResult VKAPI_CALL wrapper_CreateGraphicsPipelines(VkDevice _device, VkPipelineCache pipelineCache, uint32_t createInfoCount, @@ -4245,9 +4319,19 @@ wrapper_CreateGraphicsPipelines(VkDevice _device, VkPipelineCache pipelineCache, driver_infos = legacy; } + VkResult result = VK_SUCCESS; + void *clip_mem = NULL; + if (device->emulate_depth_clip_enable && createInfoCount) { + clip_mem = ralloc_context(NULL); + result = clip_mem + ? wrapper_lower_depth_clip(device, clip_mem, &driver_infos, createInfoCount) + : VK_ERROR_OUT_OF_HOST_MEMORY; + } + VkGraphicsPipelineCreateInfo *div_infos = NULL; void **div_lowerings = NULL; - if ((device->emulate_vertex_divisor || device->emulate_zero_divisor) && createInfoCount) { + if (result == VK_SUCCESS && + (device->emulate_vertex_divisor || device->emulate_zero_divisor) && createInfoCount) { div_infos = malloc(createInfoCount * sizeof(*div_infos)); div_lowerings = calloc(createInfoCount, sizeof(*div_lowerings)); if (div_infos && div_lowerings) { @@ -4257,12 +4341,14 @@ wrapper_CreateGraphicsPipelines(VkDevice _device, VkPipelineCache pipelineCache, } } - VkResult result = VK_SUCCESS; bool stride_emulated = false; for (uint32_t i = 0; i < createInfoCount && !stride_emulated; i++) stride_emulated = wrapper_stride_wants(device, &driver_infos[i]); - if (stride_emulated) { + if (result != VK_SUCCESS) { + for (uint32_t i = 0; i < createInfoCount; i++) + pPipelines[i] = VK_NULL_HANDLE; + } else if (stride_emulated) { for (uint32_t i = 0; i < createInfoCount; i++) { VkResult r = wrapper_stride_wants(device, &driver_infos[i]) ? wrapper_stride_create(device, pipelineCache, &driver_infos[i], pAllocator, @@ -4290,6 +4376,7 @@ wrapper_CreateGraphicsPipelines(VkDevice _device, VkPipelineCache pipelineCache, } free(div_lowerings); free(div_infos); + ralloc_free(clip_mem); if (render_passes) { for (uint32_t i = 0; i < createInfoCount; i++) { diff --git a/src/vulkan/wrapper/wrapper_physical_device.c b/src/vulkan/wrapper/wrapper_physical_device.c index 3b1d7c34a11..5976a58043b 100644 --- a/src/vulkan/wrapper/wrapper_physical_device.c +++ b/src/vulkan/wrapper/wrapper_physical_device.c @@ -532,6 +532,19 @@ VkResult enumerate_physical_device(struct vk_instance *_instance) pdevice->vk.supported_extensions.EXT_extended_dynamic_state3 = false; } + /* zink needs VK_EXT_depth_clip_enable for GL_ARB_depth_clamp (GL 3.2). + * D3D clients fall back to depth clamp themselves. */ + if (!strstr(engine_name, "DXVK") && !strstr(engine_name, "vkd3d") && + !pdevice->base_supported_extensions.EXT_depth_clip_enable && + pdevice->base_supported_features.depthClamp && + debug_get_bool_option("WRAPPER_EMULATE_DEPTH_CLIP_ENABLE", true)) { + WRAPPER_LOG(info, "Emulating VK_EXT_depth_clip_enable with depthClampEnable"); + pdevice->emulate_depth_clip_enable = true; + pdevice->vk.supported_extensions.EXT_depth_clip_enable = true; + supported_features->depthClipEnable = true; + supported_features->extendedDynamicState3DepthClipEnable = false; + } + /* Samsung Xclipse: vkd3d 3.x needs VK_EXT_dynamic_rendering_unused_attachments * for correct rendering (draws with unused/mismatched render targets get * dropped -> objects vanish, e.g. the player character), but Xclipse doesn't diff --git a/src/vulkan/wrapper/wrapper_private.h b/src/vulkan/wrapper/wrapper_private.h index d87b019ba39..015ca30dd95 100644 --- a/src/vulkan/wrapper/wrapper_private.h +++ b/src/vulkan/wrapper/wrapper_private.h @@ -48,6 +48,7 @@ struct wrapper_physical_device { bool fold_sets; bool emulate_vertex_divisor; bool emulate_zero_divisor; + bool emulate_depth_clip_enable; char *resource_type; VkPhysicalDevice dispatch_handle; VkPhysicalDeviceProperties2 properties2; @@ -121,6 +122,7 @@ struct wrapper_device { bool emulate_null_descriptor; bool device_fault_enabled; bool emulate_imageless_framebuffer; + bool emulate_depth_clip_enable; /* VK_KHR_push_descriptor emulation (for drivers lacking it, e.g. Mali r44). * Enabled when the app uses push descriptors and either the base driver From 43688d958c47d5703828fe028ba2af264d1ff87a Mon Sep 17 00:00:00 2001 From: Utkarsh Dalal Date: Fri, 20 Nov 2026 11:22:03 +0530 Subject: [PATCH 2/2] wrapper: expose VK_EXT_rasterization_order_attachment_access on drivers with only the ARM name zink only recognizes VK_EXT_rasterization_order_attachment_access, which it needs for coherent framebuffer fetch. Mali-G68 r38p1 and Mali-G710 r36p0 list only VK_ARM_rasterization_order_attachment_access. The EXT extension promoted the ARM one unchanged: the feature struct, its sType, the pipeline color blend and depth stencil create flags and the subpass description flags are aliases with the same values. When the driver lists the ARM name but not the EXT name, the wrapper now also lists the EXT name. The feature bits are the driver's own: the wrapper's feature query always chains the struct, whose sType the driver knows through the ARM extension. At device creation an enabled EXT name is passed to the driver as the ARM name and the feature struct stays in the chain. Drivers that list the EXT name or neither are unchanged. It applies to every client, like the vertex_attribute_divisor alias: DXVK and vkd3d-proton do not use the extension, and it reports only what the driver supports. --- src/vulkan/wrapper/wrapper_device.c | 7 +++++++ src/vulkan/wrapper/wrapper_physical_device.c | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/src/vulkan/wrapper/wrapper_device.c b/src/vulkan/wrapper/wrapper_device.c index 2e3e5cc5d79..a3f61a9d73d 100644 --- a/src/vulkan/wrapper/wrapper_device.c +++ b/src/vulkan/wrapper/wrapper_device.c @@ -122,6 +122,13 @@ wrapper_filter_enabled_extensions(const struct wrapper_device *device, enable_extensions[(*enable_extension_count)++] = "VK_EXT_vertex_attribute_divisor"; } + + if (device->vk.enabled_extensions.EXT_rasterization_order_attachment_access && + !device->vk.enabled_extensions.ARM_rasterization_order_attachment_access && + !device->physical->base_supported_extensions.EXT_rasterization_order_attachment_access) { + enable_extensions[(*enable_extension_count)++] = + "VK_ARM_rasterization_order_attachment_access"; + } } static inline void diff --git a/src/vulkan/wrapper/wrapper_physical_device.c b/src/vulkan/wrapper/wrapper_physical_device.c index 5976a58043b..77cf92acf3e 100644 --- a/src/vulkan/wrapper/wrapper_physical_device.c +++ b/src/vulkan/wrapper/wrapper_physical_device.c @@ -545,6 +545,15 @@ VkResult enumerate_physical_device(struct vk_instance *_instance) supported_features->extendedDynamicState3DepthClipEnable = false; } + /* zink only knows the EXT name, which promoted the ARM one unchanged. The + * feature struct shares its sType, so its bits already come from the driver. */ + if (pdevice->vk.supported_extensions.ARM_rasterization_order_attachment_access && + !pdevice->base_supported_extensions.EXT_rasterization_order_attachment_access) { + WRAPPER_LOG(info, "Exposing VK_ARM_rasterization_order_attachment_access " + "as VK_EXT_rasterization_order_attachment_access"); + pdevice->vk.supported_extensions.EXT_rasterization_order_attachment_access = true; + } + /* Samsung Xclipse: vkd3d 3.x needs VK_EXT_dynamic_rendering_unused_attachments * for correct rendering (draws with unused/mismatched render targets get * dropped -> objects vanish, e.g. the player character), but Xclipse doesn't