mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-25 15:56:01 +00:00
fix(venus): Zink draws on Mali-G610 when the depth test is off (#3102)
With depthTestEnable off, Vulkan ignores depthCompareOp. The Mali-G610 driver behind Venus (Nothing Phone (2a), Dimensity 7200 Pro) applies it anyway, even without a depth attachment. Zink leaves the op at VK_COMPARE_OP_NEVER whenever GL has the depth test off, so every fragment Zink draws is thrown away: clears and copies work, draws never show. This is the black Steam UI when it renders through Zink and the black picture of OpenGL games such as Stardew Valley. DXVK sets ALWAYS in the same case, which is why D3D games drew. The layer now hands the driver ALWAYS while the depth test is off: - vkCmdSetDepthTestEnable and vkCmdSetDepthCompareOp keep the state per command buffer, which vkBeginCommandBuffer clears. While the test is off the driver gets ALWAYS; turning it on again restores the application's op. - A pipeline with the depth test off and neither state dynamic is created with ALWAYS. It is on for every device with gaps. ALWAYS for a disabled depth test changes nothing on a driver that follows the spec.
This commit is contained in:
1 parent
6e252ea3ad
commit
ae47876386
6 files changed
+175
-4
No files matched your search
@@ -799,7 +799,11 @@ static void recycle_command_buffer(struct device *dev, VkCommandBuffer cmd)
|
||||
VKAPI_ATTR VkResult VKAPI_CALL BeginCommandBuffer(VkCommandBuffer cmd, const VkCommandBufferBeginInfo *info)
|
||||
{
|
||||
struct device *dev = device_from_handle(cmd);
|
||||
recycle_command_buffer(dev, cmd);
|
||||
if (dev->emulated & GAP_BC)
|
||||
recycle_command_buffer(dev, cmd);
|
||||
/* Dynamic state does not carry over from one recording to the next. */
|
||||
if (dev->emulated & GAP_DEPTH_OP)
|
||||
depth_state_forget(dev, cmd);
|
||||
return dev->BeginCommandBuffer(cmd, info);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
* 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.
|
||||
* - depthCompareOp with the depth test off (GAP_DEPTH_OP): the driver is given ALWAYS while a
|
||||
* command buffer has the test off, and the application's op again once it turns the test on.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -450,3 +452,49 @@ VKAPI_ATTR void VKAPI_CALL CmdBindVertexBuffers2(VkCommandBuffer cmd, uint32_t f
|
||||
}
|
||||
dev->CmdBindVertexBuffers2(cmd, first, count, fixed, fixed_offsets, sizes ? fixed_sizes : NULL, strides);
|
||||
}
|
||||
|
||||
/* --- depthCompareOp while the depth test is off --- */
|
||||
|
||||
/* Per command buffer, packed into the map's value pointer so it is never NULL: bit 0 always set,
|
||||
* bit 1 the test enable is known, bit 2 the test is on, bit 3 an op was set, bits 4 and up that op. */
|
||||
enum { DEPTH_VALID = 1, DEPTH_KNOWN = 2, DEPTH_ON = 4, DEPTH_OP = 8 };
|
||||
|
||||
static uintptr_t depth_state(struct device *dev, VkCommandBuffer cmd)
|
||||
{
|
||||
uintptr_t state = (uintptr_t)map_get(&dev->depth_states, (uint64_t)(uintptr_t)cmd);
|
||||
return state ? state : DEPTH_VALID;
|
||||
}
|
||||
|
||||
void depth_state_forget(struct device *dev, VkCommandBuffer cmd)
|
||||
{
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
map_remove(&dev->depth_states, (uint64_t)(uintptr_t)cmd);
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL CmdSetDepthTestEnable(VkCommandBuffer cmd, VkBool32 enable)
|
||||
{
|
||||
struct device *dev = device_from_handle(cmd);
|
||||
dev->CmdSetDepthTestEnable(cmd, enable);
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
uintptr_t state = depth_state(dev, cmd);
|
||||
uintptr_t next = (state & ~(uintptr_t)DEPTH_ON) | DEPTH_KNOWN | (enable ? DEPTH_ON : 0);
|
||||
map_put(&dev->depth_states, (uint64_t)(uintptr_t)cmd, (void *)next);
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
if (!enable)
|
||||
dev->CmdSetDepthCompareOp(cmd, VK_COMPARE_OP_ALWAYS);
|
||||
else if (state & DEPTH_OP)
|
||||
dev->CmdSetDepthCompareOp(cmd, (VkCompareOp)(state >> 4));
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL CmdSetDepthCompareOp(VkCommandBuffer cmd, VkCompareOp op)
|
||||
{
|
||||
struct device *dev = device_from_handle(cmd);
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
uintptr_t state = depth_state(dev, cmd);
|
||||
uintptr_t next = (state & (uintptr_t)(DEPTH_VALID | DEPTH_KNOWN | DEPTH_ON)) | DEPTH_OP | ((uintptr_t)op << 4);
|
||||
map_put(&dev->depth_states, (uint64_t)(uintptr_t)cmd, (void *)next);
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
bool off = (state & DEPTH_KNOWN) && !(state & DEPTH_ON);
|
||||
dev->CmdSetDepthCompareOp(cmd, off ? VK_COMPARE_OP_ALWAYS : op);
|
||||
}
|
||||
@@ -606,7 +606,7 @@ static VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice physical_dev
|
||||
dev->key = dispatch_key(*device);
|
||||
dev->handle = *device;
|
||||
dev->gdpa = gdpa;
|
||||
dev->emulated = requested;
|
||||
dev->emulated = requested | (gaps ? GAP_DEPTH_OP : 0);
|
||||
pthread_mutex_init(&dev->lock, NULL);
|
||||
#define LOAD(name) \
|
||||
dev->name = (PFN_vk##name)gdpa(*device, "vk" #name); \
|
||||
@@ -642,6 +642,8 @@ static VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice physical_dev
|
||||
(requested & GAP_NULL_DESCRIPTOR) ? " nullDescriptor" : "",
|
||||
(requested & GAP_DUAL_SRC_BLEND) ? " dualSrcBlend" : "", properties.deviceName);
|
||||
}
|
||||
if (dev->emulated & GAP_DEPTH_OP)
|
||||
layer_log("depthCompareOp becomes ALWAYS while the depth test is off");
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -669,6 +671,7 @@ static VKAPI_ATTR void VKAPI_CALL DestroyDevice(VkDevice device, const VkAllocat
|
||||
}
|
||||
}
|
||||
map_free(&dev->shader_modules);
|
||||
map_free(&dev->depth_states);
|
||||
pthread_mutex_destroy(&dev->lock);
|
||||
free(dev);
|
||||
}
|
||||
@@ -696,6 +699,10 @@ static const struct hook device_hooks[] = {
|
||||
HOOK(CmdSetScissorWithCount, GAP_MULTI_VIEWPORT),
|
||||
HOOK_ALIAS(CmdSetScissorWithCount, CmdSetScissorWithCountEXT, GAP_MULTI_VIEWPORT),
|
||||
HOOK(CmdSetColorBlendEquationEXT, GAP_DUAL_SRC_BLEND),
|
||||
HOOK(CmdSetDepthTestEnable, GAP_DEPTH_OP),
|
||||
HOOK_ALIAS(CmdSetDepthTestEnable, CmdSetDepthTestEnableEXT, GAP_DEPTH_OP),
|
||||
HOOK(CmdSetDepthCompareOp, GAP_DEPTH_OP),
|
||||
HOOK_ALIAS(CmdSetDepthCompareOp, CmdSetDepthCompareOpEXT, GAP_DEPTH_OP),
|
||||
HOOK(CreateImage, GAP_BC),
|
||||
HOOK(DestroyImage, GAP_BC),
|
||||
HOOK(CreateImageView, GAP_BC),
|
||||
@@ -727,7 +734,7 @@ static const struct hook device_hooks[] = {
|
||||
HOOK_ALIAS(UnmapMemory2, UnmapMemory2KHR, GAP_BC),
|
||||
HOOK(AllocateCommandBuffers, GAP_BC),
|
||||
HOOK(FreeCommandBuffers, GAP_BC),
|
||||
HOOK(BeginCommandBuffer, GAP_BC),
|
||||
HOOK(BeginCommandBuffer, GAP_BC | GAP_DEPTH_OP),
|
||||
HOOK(ResetCommandBuffer, GAP_BC),
|
||||
HOOK(ResetCommandPool, GAP_BC),
|
||||
HOOK(DestroyCommandPool, GAP_BC),
|
||||
|
||||
@@ -30,6 +30,10 @@ enum gap {
|
||||
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 */
|
||||
GAP_DUAL_SRC_BLEND = 1u << 9,
|
||||
/* A driver bug, not a missing feature: the Mali-G610 driver behind Venus applies depthCompareOp
|
||||
* with the depth test off, so Zink's NEVER discards every fragment. On for every device with
|
||||
* gaps; ALWAYS for a disabled test changes nothing on a driver that follows the spec. */
|
||||
GAP_DEPTH_OP = 1u << 10,
|
||||
};
|
||||
|
||||
#define GAPS_SHADER (GAP_CLIP_DISTANCE | GAP_CULL_DISTANCE)
|
||||
@@ -138,7 +142,9 @@ struct instance {
|
||||
X(CmdPushDescriptorSetWithTemplate) \
|
||||
X(CmdBindVertexBuffers) \
|
||||
X(CmdBindVertexBuffers2) \
|
||||
X(CmdSetColorBlendEquationEXT)
|
||||
X(CmdSetColorBlendEquationEXT) \
|
||||
X(CmdSetDepthTestEnable) \
|
||||
X(CmdSetDepthCompareOp)
|
||||
|
||||
struct staging_block;
|
||||
|
||||
@@ -163,6 +169,7 @@ struct device {
|
||||
struct handle_map command_buffers; /* VkCommandBuffer -> struct command_buffer */
|
||||
struct staging_block *free_staging;
|
||||
struct handle_map templates; /* VkDescriptorUpdateTemplate -> struct template_info (draw.c) */
|
||||
struct handle_map depth_states; /* VkCommandBuffer -> packed depth test state (draw.c) */
|
||||
/* nullDescriptor stand-ins (draw.c): 0 not made yet, 1 ready, -1 failed. */
|
||||
int null_ready;
|
||||
VkBuffer null_buffer;
|
||||
@@ -311,4 +318,7 @@ VKAPI_ATTR void VKAPI_CALL CmdPushDescriptorSetWithTemplate(VkCommandBuffer cmd,
|
||||
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);
|
||||
VKAPI_ATTR void VKAPI_CALL CmdSetDepthTestEnable(VkCommandBuffer cmd, VkBool32 enable);
|
||||
VKAPI_ATTR void VKAPI_CALL CmdSetDepthCompareOp(VkCommandBuffer cmd, VkCompareOp op);
|
||||
void depth_state_forget(struct device *dev, VkCommandBuffer cmd);
|
||||
#endif
|
||||
@@ -143,6 +143,7 @@ struct pipeline_rewrite {
|
||||
/* VK_EXT_depth_clip_enable's state, taken out of the application's chain for the call. */
|
||||
VkBaseOutStructure *clip_prev, *clip_node;
|
||||
VkPipelineViewportStateCreateInfo viewport;
|
||||
VkPipelineDepthStencilStateCreateInfo depth_stencil;
|
||||
VkPipelineShaderStageCreateInfo stages[MAX_STAGES];
|
||||
VkShaderModuleCreateInfo modules[MAX_STAGES];
|
||||
struct spirv_code code[MAX_STAGES];
|
||||
@@ -401,6 +402,19 @@ static void rewrite_pipeline(struct device *dev, VkGraphicsPipelineCreateInfo *i
|
||||
rw->viewport.scissorCount = 1;
|
||||
info->pViewportState = &rw->viewport;
|
||||
}
|
||||
if ((dev->emulated & GAP_DEPTH_OP) && info->pDepthStencilState && !info->pDepthStencilState->depthTestEnable &&
|
||||
info->pDepthStencilState->depthCompareOp != VK_COMPARE_OP_ALWAYS) {
|
||||
bool dynamic = false;
|
||||
for (uint32_t i = 0; info->pDynamicState && i < info->pDynamicState->dynamicStateCount; i++) {
|
||||
VkDynamicState state = info->pDynamicState->pDynamicStates[i];
|
||||
dynamic |= state == VK_DYNAMIC_STATE_DEPTH_TEST_ENABLE || state == VK_DYNAMIC_STATE_DEPTH_COMPARE_OP;
|
||||
}
|
||||
if (!dynamic) {
|
||||
rw->depth_stencil = *info->pDepthStencilState;
|
||||
rw->depth_stencil.depthCompareOp = VK_COMPARE_OP_ALWAYS;
|
||||
info->pDepthStencilState = &rw->depth_stencil;
|
||||
}
|
||||
}
|
||||
if (dev->emulated & GAP_DUAL_SRC_BLEND) {
|
||||
rewrite_blend(info, rw);
|
||||
if (rw->attachments)
|
||||
|
||||
Reference in new issue
Block a user