zink: Simplify MoltenVK support a bit
authorAdam Jackson <ajax@redhat.com>
Wed, 9 Dec 2020 17:20:45 +0000 (12:20 -0500)
committerMarge Bot <eric+marge@anholt.net>
Tue, 15 Dec 2020 17:20:13 +0000 (17:20 +0000)
There's no harm in checking for the extension on non-macOS, just do it.
Nor can I see any point in checking for both the layer and the
extension, since you're never going to see the extension if the layer
isn't available, so just check for the extension instead of the reduced
boolean. Simplify some variable naming while we're at it.

Acked-by: Hoe Hao Cheng <haochengho12907@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8019>

src/gallium/drivers/zink/zink_instance.py
src/gallium/drivers/zink/zink_screen.c

index 918f97ffc870482d8522e30c0dc80c94e62d2818..dfd2fc0346dac762fd140812ae8b147ef2eae17d 100644 (file)
@@ -7,6 +7,7 @@ EXTENSIONS = [
     Extension("VK_EXT_debug_utils"),
     Extension("VK_KHR_get_physical_device_properties2"),
     Extension("VK_KHR_external_memory_capabilities"),
+    Extension("VK_MVK_moltenvk"),
 ]
 
 LAYERS = [
@@ -45,12 +46,6 @@ struct zink_instance_info {
 %for layer in layers:
    bool have_layer_${layer.pure_name()};
 %endfor
-
-#if defined(MVK_VERSION)
-   bool have_moltenvk_layer_ext;
-   bool have_moltenvk_layer;
-   bool have_moltenvk;
-#endif
 };
 
 VkInstance
@@ -82,9 +77,7 @@ zink_create_instance(struct zink_screen *screen)
 %endfor
 
 #if defined(MVK_VERSION)
-   bool have_moltenvk_layer_ext = false;
    bool have_moltenvk_layer = false;
-   bool have_moltenvk = false;
 #endif
 
    // Build up the extensions from the reported ones but only for the unnamed layer
@@ -95,17 +88,11 @@ zink_create_instance(struct zink_screen *screen)
            if (vkEnumerateInstanceExtensionProperties(NULL, &extension_count, extension_props) == VK_SUCCESS) {
               for (uint32_t i = 0; i < extension_count; i++) {
 %for ext in extensions:
-                 if (!strcmp(extension_props[i].extensionName, ${ext.extension_name()})) {
+                 if (!strcmp(extension_props[i].extensionName, ${ext.extension_name_literal()})) {
                     have_${ext.name_with_vendor()} = true;
-                    extensions[num_extensions++] = ${ext.extension_name()};
+                    extensions[num_extensions++] = ${ext.extension_name_literal()};
                  }
 %endfor
-#if defined(MVK_VERSION)
-                 if (!strcmp(extension_props[i].extensionName, VK_MVK_MOLTENVK_EXTENSION_NAME)) {
-                    have_moltenvk_layer_ext = true;
-                    extensions[num_extensions++] = VK_MVK_MOLTENVK_EXTENSION_NAME;
-                 }
-#endif
               }
            }
        free(extension_props);
@@ -160,12 +147,6 @@ zink_create_instance(struct zink_screen *screen)
    }
 %endfor
 
-#if defined(MVK_VERSION)
-   screen->instance_info.have_moltenvk_layer_ext = have_moltenvk_layer_ext;
-   screen->instance_info.have_moltenvk_layer = have_moltenvk_layer;
-   screen->have_moltenvk = have_moltenvk_layer_ext && have_moltenvk_layer;
-#endif
-
    VkApplicationInfo ai = {};
    ai.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
 
index b39bae6de976ffd6c04c68c924b812fc4f465f35..074d206a12869c4d02dbac07002aa340f1fda9ec 100644 (file)
@@ -874,11 +874,11 @@ create_debug(struct zink_screen *screen)
    return true;
 }
 
-#if defined(MVK_VERSION)
 static bool
 zink_internal_setup_moltenvk(struct zink_screen *screen)
 {
-   if (!screen->have_moltenvk)
+#if defined(MVK_VERSION)
+   if (!screen->have_MVK_moltenvk)
       return true;
 
    GET_PROC_ADDR_INSTANCE(GetMoltenVKConfigurationMVK);
@@ -910,10 +910,10 @@ zink_internal_setup_moltenvk(struct zink_screen *screen)
          (*screen->vk_SetMoltenVKConfigurationMVK)(screen->instance, &molten_config, &molten_config_size);
       }
    }
+#endif // MVK_VERSION
 
    return true;
 }
-#endif // MVK_VERSION
 
 static void
 check_device_needs_mesa_wsi(struct zink_screen *screen)
@@ -1013,9 +1013,7 @@ zink_internal_create_screen(const struct pipe_screen_config *config)
     */
    check_device_needs_mesa_wsi(screen);
 
-#if defined(MVK_VERSION)
    zink_internal_setup_moltenvk(screen);
-#endif
 
    screen->dev = zink_create_logical_device(screen);
    if (!screen->dev)