mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-02 20:21:59 -05:00
fix(venus): OpenGL quads no longer crash Mali's shader compiler through Zink (#3283)
* fix(venus): OpenGL quads no longer crash Mali's shader compiler through Zink The Mali-G610's driver crashes compiling Zink's geometry shaders (SIGSEGV at 0x40 in cmpbe_v2_compile_multiple_shaders), and the render server and the application die with it. A plain geometry shader that only passes triangles on does not crash it, but draws nothing. Zink draws GL_QUADS through a geometry shader when the device has the feature, so OpenGL programs died on their first quad. The Mali layer now reports no geometryShader to Zink on ARM GPUs. Mesa then splits quads into triangles itself. DXVK keeps the feature, which it needs for D3D10 and 11. DROIDDECK_MALI_COMPAT_NO_GS=0 keeps it for Zink, =1 hides it from every application. * test(venus): clear DROIDDECK_MALI_COMPAT_NO_GS before the layer tests The geometry shader test checks the default first. With the variable exported in the shell, it failed before it reached its own settings. * test(venus): check that other ARM applications keep the geometry shader
This commit is contained in:
1 parent
2b6ded9fd4
commit
90df30f4d7
4 files changed
+97
-1
No files matched your search
@@ -150,6 +150,19 @@ The SPIR-V version the driver gets:
|
|||||||
- This is what Dawn ("Disable SPIR-V 1.4 on Android ARM"), ANGLE (`supportsSPIRV14`) and naga
|
- This is what Dawn ("Disable SPIR-V 1.4 on Android ARM"), ANGLE (`supportsSPIRV14`) and naga
|
||||||
(`AVOID_SPIRV_COPY_LOGICAL`) do for a proprietary compiler they cannot trust.
|
(`AVOID_SPIRV_COPY_LOGICAL`) do for a proprietary compiler they cannot trust.
|
||||||
|
|
||||||
|
Geometry shaders:
|
||||||
|
- The Mali-G610's driver (r38p1) crashes compiling Zink's geometry shaders, always at the same
|
||||||
|
place (SIGSEGV at 0x40 in `cmpbe_v2_compile_multiple_shaders`): its shader for `GL_QUADS`, and
|
||||||
|
a GLSL geometry shader that only passes triangles on.
|
||||||
|
- A geometry shader that only passes triangles on, from a plain Vulkan program, does not crash it
|
||||||
|
but draws nothing, in SPIR-V 1.0, 1.3 and 1.6, with and without the layer.
|
||||||
|
- Zink writes them in SPIR-V 1.6 with the Vulkan memory model, which the version cap leaves alone.
|
||||||
|
Lowering them would not help, since the plain shader draws nothing at 1.0 and 1.3 either.
|
||||||
|
- On ARM GPUs the layer reports no `geometryShader` to Zink (engine name `mesa zink`). Mesa then
|
||||||
|
splits quads into triangles itself, and Zink still offers OpenGL 3.2. DXVK keeps the feature: it
|
||||||
|
needs it for D3D10 and 11.
|
||||||
|
- `DROIDDECK_MALI_COMPAT_NO_GS=0` keeps the feature for Zink, `=1` hides it from every application.
|
||||||
|
|
||||||
Files:
|
Files:
|
||||||
- `layer.c`: loader plumbing, feature and limit reporting, device creation, the hook table.
|
- `layer.c`: loader plumbing, feature and limit reporting, device creation, the hook table.
|
||||||
- `pipeline.c`: pipelines, shader modules, viewports.
|
- `pipeline.c`: pipelines, shader modules, viewports.
|
||||||
|
|||||||
@@ -203,10 +203,17 @@ static void test_handle_map_null_key(void)
|
|||||||
map_free(&map);
|
map_free(&map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int zink_instance_table;
|
||||||
|
static struct object mock_zink_instance = {&zink_instance_table};
|
||||||
|
static struct object mock_arm = {&instance_table};
|
||||||
|
static struct object mock_zink_arm = {&zink_instance_table}, mock_zink_other = {&zink_instance_table};
|
||||||
|
|
||||||
static VkResult VKAPI_CALL mock_create_instance(const VkInstanceCreateInfo *info, const VkAllocationCallbacks *allocator,
|
static VkResult VKAPI_CALL mock_create_instance(const VkInstanceCreateInfo *info, const VkAllocationCallbacks *allocator,
|
||||||
VkInstance *instance)
|
VkInstance *instance)
|
||||||
{
|
{
|
||||||
*instance = (VkInstance)&mock_instance;
|
const VkApplicationInfo *app = info->pApplicationInfo;
|
||||||
|
bool zink = app && app->pEngineName && !strcmp(app->pEngineName, "mesa zink");
|
||||||
|
*instance = (VkInstance)(zink ? &mock_zink_instance : &mock_instance);
|
||||||
return VK_SUCCESS;
|
return VK_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,6 +230,7 @@ static void VKAPI_CALL mock_features(VkPhysicalDevice physical, VkPhysicalDevice
|
|||||||
{
|
{
|
||||||
memset(features, 0, sizeof(*features));
|
memset(features, 0, sizeof(*features));
|
||||||
features->dualSrcBlend = physical == (VkPhysicalDevice)&mock_capable;
|
features->dualSrcBlend = physical == (VkPhysicalDevice)&mock_capable;
|
||||||
|
features->geometryShader = VK_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void VKAPI_CALL mock_features2(VkPhysicalDevice physical, VkPhysicalDeviceFeatures2 *features)
|
static void VKAPI_CALL mock_features2(VkPhysicalDevice physical, VkPhysicalDeviceFeatures2 *features)
|
||||||
@@ -234,6 +242,8 @@ static void VKAPI_CALL mock_properties(VkPhysicalDevice physical, VkPhysicalDevi
|
|||||||
{
|
{
|
||||||
memset(properties, 0, sizeof(*properties));
|
memset(properties, 0, sizeof(*properties));
|
||||||
strcpy(properties->deviceName, "mock");
|
strcpy(properties->deviceName, "mock");
|
||||||
|
bool arm = physical == (VkPhysicalDevice)&mock_arm || physical == (VkPhysicalDevice)&mock_zink_arm;
|
||||||
|
properties->vendorID = arm ? 0x13b5 : 0;
|
||||||
properties->limits.maxFragmentDualSrcAttachments = physical == (VkPhysicalDevice)&mock_capable;
|
properties->limits.maxFragmentDualSrcAttachments = physical == (VkPhysicalDevice)&mock_capable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,6 +395,50 @@ static void destroy_device(VkDevice device)
|
|||||||
((PFN_vkDestroyDevice)layer_gdpa(device, "vkDestroyDevice"))(device, NULL);
|
((PFN_vkDestroyDevice)layer_gdpa(device, "vkDestroyDevice"))(device, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_geometry_shader_hidden_from_zink(void)
|
||||||
|
{
|
||||||
|
VkPhysicalDeviceFeatures features;
|
||||||
|
PFN_vkGetPhysicalDeviceFeatures plain_features =
|
||||||
|
(PFN_vkGetPhysicalDeviceFeatures)layer_gipa((VkInstance)&mock_instance, "vkGetPhysicalDeviceFeatures");
|
||||||
|
PFN_vkGetPhysicalDeviceFeatures2 plain_features2 =
|
||||||
|
(PFN_vkGetPhysicalDeviceFeatures2)layer_gipa((VkInstance)&mock_instance, "vkGetPhysicalDeviceFeatures2");
|
||||||
|
VkPhysicalDeviceFeatures2 queried = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2};
|
||||||
|
plain_features((VkPhysicalDevice)&mock_lacking, &features);
|
||||||
|
assert(features.geometryShader);
|
||||||
|
plain_features((VkPhysicalDevice)&mock_arm, &features);
|
||||||
|
assert(features.geometryShader);
|
||||||
|
plain_features2((VkPhysicalDevice)&mock_arm, &queried);
|
||||||
|
assert(queried.features.geometryShader);
|
||||||
|
|
||||||
|
VkApplicationInfo app = {.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, .pEngineName = "mesa zink"};
|
||||||
|
VkLayerInstanceLink link = {NULL, mock_gipa, NULL};
|
||||||
|
VkLayerInstanceCreateInfo loader = {VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO, NULL, VK_LAYER_LINK_INFO, {&link}};
|
||||||
|
VkInstanceCreateInfo info = {.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, .pNext = &loader,
|
||||||
|
.pApplicationInfo = &app};
|
||||||
|
VkInstance zink;
|
||||||
|
assert(((PFN_vkCreateInstance)layer_gipa(NULL, "vkCreateInstance"))(&info, NULL, &zink) == VK_SUCCESS);
|
||||||
|
assert(zink == (VkInstance)&mock_zink_instance);
|
||||||
|
PFN_vkGetPhysicalDeviceFeatures zink_features =
|
||||||
|
(PFN_vkGetPhysicalDeviceFeatures)layer_gipa(zink, "vkGetPhysicalDeviceFeatures");
|
||||||
|
PFN_vkGetPhysicalDeviceFeatures2 zink_features2 =
|
||||||
|
(PFN_vkGetPhysicalDeviceFeatures2)layer_gipa(zink, "vkGetPhysicalDeviceFeatures2");
|
||||||
|
zink_features((VkPhysicalDevice)&mock_zink_arm, &features);
|
||||||
|
assert(!features.geometryShader && features.dualSrcBlend);
|
||||||
|
zink_features2((VkPhysicalDevice)&mock_zink_arm, &queried);
|
||||||
|
assert(!queried.features.geometryShader && queried.features.dualSrcBlend);
|
||||||
|
zink_features((VkPhysicalDevice)&mock_zink_other, &features);
|
||||||
|
assert(features.geometryShader);
|
||||||
|
|
||||||
|
setenv("DROIDDECK_MALI_COMPAT_NO_GS", "0", 1);
|
||||||
|
zink_features((VkPhysicalDevice)&mock_zink_arm, &features);
|
||||||
|
assert(features.geometryShader);
|
||||||
|
setenv("DROIDDECK_MALI_COMPAT_NO_GS", "1", 1);
|
||||||
|
plain_features((VkPhysicalDevice)&mock_lacking, &features);
|
||||||
|
assert(!features.geometryShader);
|
||||||
|
unsetenv("DROIDDECK_MALI_COMPAT_NO_GS");
|
||||||
|
((PFN_vkDestroyInstance)layer_gipa(zink, "vkDestroyInstance"))(zink, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static const VkPipelineColorBlendAttachmentState dual_attachment = {
|
static const VkPipelineColorBlendAttachmentState dual_attachment = {
|
||||||
VK_TRUE, VK_BLEND_FACTOR_ONE, VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR, VK_BLEND_OP_ADD,
|
VK_TRUE, VK_BLEND_FACTOR_ONE, VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR, VK_BLEND_OP_ADD,
|
||||||
VK_BLEND_FACTOR_SRC1_ALPHA, VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA, VK_BLEND_OP_ADD, 0xf,
|
VK_BLEND_FACTOR_SRC1_ALPHA, VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA, VK_BLEND_OP_ADD, 0xf,
|
||||||
@@ -575,6 +629,7 @@ int main(int argc, char **argv)
|
|||||||
setenv("WINEPREFIX", "/nonexistent", 1);
|
setenv("WINEPREFIX", "/nonexistent", 1);
|
||||||
unsetenv("DROIDDECK_MALI_COMPAT");
|
unsetenv("DROIDDECK_MALI_COMPAT");
|
||||||
unsetenv("DROIDDECK_MALI_COMPAT_TRACE");
|
unsetenv("DROIDDECK_MALI_COMPAT_TRACE");
|
||||||
|
unsetenv("DROIDDECK_MALI_COMPAT_NO_GS");
|
||||||
VkNegotiateLayerInterface negotiate = {LAYER_NEGOTIATE_INTERFACE_STRUCT, NULL, 2, NULL, NULL, NULL};
|
VkNegotiateLayerInterface negotiate = {LAYER_NEGOTIATE_INTERFACE_STRUCT, NULL, 2, NULL, NULL, NULL};
|
||||||
assert(vkNegotiateLoaderLayerInterfaceVersion(&negotiate) == VK_SUCCESS);
|
assert(vkNegotiateLoaderLayerInterfaceVersion(&negotiate) == VK_SUCCESS);
|
||||||
layer_gipa = negotiate.pfnGetInstanceProcAddr;
|
layer_gipa = negotiate.pfnGetInstanceProcAddr;
|
||||||
@@ -587,6 +642,7 @@ int main(int argc, char **argv)
|
|||||||
PFN_vkCreateInstance create_instance = (PFN_vkCreateInstance)layer_gipa(NULL, "vkCreateInstance");
|
PFN_vkCreateInstance create_instance = (PFN_vkCreateInstance)layer_gipa(NULL, "vkCreateInstance");
|
||||||
assert(create_instance(&info, NULL, &instance) == VK_SUCCESS);
|
assert(create_instance(&info, NULL, &instance) == VK_SUCCESS);
|
||||||
|
|
||||||
|
test_geometry_shader_hidden_from_zink();
|
||||||
test_lacking_device();
|
test_lacking_device();
|
||||||
test_capable_device();
|
test_capable_device();
|
||||||
test_depth_compare_op();
|
test_depth_compare_op();
|
||||||
|
|||||||
@@ -344,12 +344,31 @@ static void report_limits(VkPhysicalDeviceLimits *limits, uint32_t gaps)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Mali's driver crashes compiling Zink's geometry shaders (SIGSEGV at 0x40 in
|
||||||
|
* cmpbe_v2_compile_multiple_shaders) and takes the render server and the application with it; a plain
|
||||||
|
* one draws nothing. Zink draws GL_QUADS through one; without the feature Mesa splits quads into
|
||||||
|
* triangles itself. DXVK needs the feature for D3D10 and 11, so only Zink loses it.
|
||||||
|
* DROIDDECK_MALI_COMPAT_NO_GS=0 keeps it for Zink, =1 hides it from every application. */
|
||||||
|
static bool hide_geometry_shader(struct instance *inst, VkPhysicalDevice physical_device)
|
||||||
|
{
|
||||||
|
const char *setting = getenv("DROIDDECK_MALI_COMPAT_NO_GS");
|
||||||
|
if (setting && *setting)
|
||||||
|
return strcmp(setting, "1") == 0;
|
||||||
|
if (!inst->zink)
|
||||||
|
return false;
|
||||||
|
VkPhysicalDeviceProperties properties;
|
||||||
|
inst->GetPhysicalDeviceProperties(physical_device, &properties);
|
||||||
|
return properties.vendorID == 0x13b5; /* ARM */
|
||||||
|
}
|
||||||
|
|
||||||
static VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceFeatures(VkPhysicalDevice physical_device,
|
static VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceFeatures(VkPhysicalDevice physical_device,
|
||||||
VkPhysicalDeviceFeatures *features)
|
VkPhysicalDeviceFeatures *features)
|
||||||
{
|
{
|
||||||
struct instance *inst = instance_from_handle(physical_device);
|
struct instance *inst = instance_from_handle(physical_device);
|
||||||
inst->GetPhysicalDeviceFeatures(physical_device, features);
|
inst->GetPhysicalDeviceFeatures(physical_device, features);
|
||||||
report_features(features, physical_device_gaps(inst, physical_device));
|
report_features(features, physical_device_gaps(inst, physical_device));
|
||||||
|
if (hide_geometry_shader(inst, physical_device))
|
||||||
|
features->geometryShader = VK_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceFeatures2(VkPhysicalDevice physical_device,
|
static VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceFeatures2(VkPhysicalDevice physical_device,
|
||||||
@@ -363,6 +382,8 @@ static VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceFeatures2(VkPhysicalDevice ph
|
|||||||
inst->GetPhysicalDeviceFeatures2(physical_device, features);
|
inst->GetPhysicalDeviceFeatures2(physical_device, features);
|
||||||
relink(dropped, dropped_count);
|
relink(dropped, dropped_count);
|
||||||
report_features(&features->features, gaps);
|
report_features(&features->features, gaps);
|
||||||
|
if (hide_geometry_shader(inst, physical_device))
|
||||||
|
features->features.geometryShader = VK_FALSE;
|
||||||
if (tracing()) {
|
if (tracing()) {
|
||||||
char chain[512] = "";
|
char chain[512] = "";
|
||||||
size_t used = 0;
|
size_t used = 0;
|
||||||
@@ -463,6 +484,8 @@ static VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo
|
|||||||
inst->key = dispatch_key(*instance);
|
inst->key = dispatch_key(*instance);
|
||||||
inst->handle = *instance;
|
inst->handle = *instance;
|
||||||
inst->active = wanted();
|
inst->active = wanted();
|
||||||
|
const char *engine = info->pApplicationInfo ? info->pApplicationInfo->pEngineName : NULL;
|
||||||
|
inst->zink = engine && strcmp(engine, "mesa zink") == 0;
|
||||||
inst->gipa = gipa;
|
inst->gipa = gipa;
|
||||||
pthread_mutex_init(&inst->lock, NULL);
|
pthread_mutex_init(&inst->lock, NULL);
|
||||||
#define LOAD(name) inst->name = (PFN_vk##name)gipa(*instance, "vk" #name);
|
#define LOAD(name) inst->name = (PFN_vk##name)gipa(*instance, "vk" #name);
|
||||||
@@ -624,6 +647,9 @@ static VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice physical_dev
|
|||||||
if (properties.limits.maxFragmentInputComponents < components)
|
if (properties.limits.maxFragmentInputComponents < components)
|
||||||
components = properties.limits.maxFragmentInputComponents;
|
components = properties.limits.maxFragmentInputComponents;
|
||||||
dev->max_varying_locations = components / 4;
|
dev->max_varying_locations = components / 4;
|
||||||
|
if (inst->active && hide_geometry_shader(inst, physical_device))
|
||||||
|
layer_log("geometryShader is hidden from %s: the driver crashes compiling geometry shaders",
|
||||||
|
inst->zink ? "Zink" : "every application");
|
||||||
|
|
||||||
pthread_mutex_lock(&global_lock);
|
pthread_mutex_lock(&global_lock);
|
||||||
dev->next = devices;
|
dev->next = devices;
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ struct instance {
|
|||||||
void *key;
|
void *key;
|
||||||
VkInstance handle;
|
VkInstance handle;
|
||||||
bool active;
|
bool active;
|
||||||
|
bool zink; /* the engine is Mesa's Zink */
|
||||||
PFN_vkGetInstanceProcAddr gipa;
|
PFN_vkGetInstanceProcAddr gipa;
|
||||||
PFN_vkDestroyInstance DestroyInstance;
|
PFN_vkDestroyInstance DestroyInstance;
|
||||||
PFN_vkEnumerateDeviceExtensionProperties EnumerateDeviceExtensionProperties;
|
PFN_vkEnumerateDeviceExtensionProperties EnumerateDeviceExtensionProperties;
|
||||||
|
|||||||
Reference in new issue
Block a user