summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHoe Hao Cheng <haochengho12907@gmail.com>2020-11-27 01:32:39 +0800
committerMarge Bot <eric+marge@anholt.net>2020-12-11 12:07:13 +0000
commitfe669ff4a023a98865b5ab6538613e3ae4c4eae9 (patch)
tree104e015e1968ea2d5b3e9e5d1df499ee7f545d33
parent52138ea9b383ff7ca604e93d78c86eabc4266117 (diff)
zink: replace old code with generated zink_instance
Acked-by: Adam Jackson <ajax@redhat.com> Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7800>
-rw-r--r--src/gallium/drivers/zink/zink_screen.c141
-rw-r--r--src/gallium/drivers/zink/zink_screen.h3
2 files changed, 5 insertions, 139 deletions
diff --git a/src/gallium/drivers/zink/zink_screen.c b/src/gallium/drivers/zink/zink_screen.c
index 24a57ad5462..0cf08e56903 100644
--- a/src/gallium/drivers/zink/zink_screen.c
+++ b/src/gallium/drivers/zink/zink_screen.c
@@ -27,6 +27,7 @@
#include "zink_context.h"
#include "zink_device_info.h"
#include "zink_fence.h"
+#include "zink_instance.h"
#include "zink_public.h"
#include "zink_resource.h"
@@ -644,144 +645,6 @@ zink_destroy_screen(struct pipe_screen *pscreen)
FREE(screen);
}
-static VkInstance
-create_instance(struct zink_screen *screen)
-{
- const char *layers[4] = { 0 };
- uint32_t num_layers = 0;
- const char *extensions[4] = { 0 };
- uint32_t num_extensions = 0;
-
- bool have_debug_utils_ext = false;
-#if defined(MVK_VERSION)
- bool have_moltenvk_layer = false;
- bool have_moltenvk_layer_ext = false;
-#endif
-
- screen->loader_version = VK_API_VERSION_1_0;
- {
- // Get the Loader version
- GET_PROC_ADDR_INSTANCE_LOCAL(NULL, EnumerateInstanceVersion);
- if (vk_EnumerateInstanceVersion) {
- uint32_t loader_version_temp = VK_API_VERSION_1_0;
- if (VK_SUCCESS == (*vk_EnumerateInstanceVersion)( &loader_version_temp)) {
- screen->loader_version = loader_version_temp;
- }
- }
- }
-
- {
- // Build up the extensions from the reported ones but only for the unnamed layer
- uint32_t extension_count = 0;
- VkResult err = vkEnumerateInstanceExtensionProperties(NULL, &extension_count, NULL);
- if (err == VK_SUCCESS) {
- VkExtensionProperties *extension_props = malloc(extension_count * sizeof(VkExtensionProperties));
- if (extension_props) {
- err = vkEnumerateInstanceExtensionProperties(NULL, &extension_count, extension_props);
- if (err == VK_SUCCESS) {
- for (uint32_t i = 0; i < extension_count; i++) {
- if (!strcmp(extension_props[i].extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME)) {
- have_debug_utils_ext = true;
- }
- if (!strcmp(extension_props[i].extensionName, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
- extensions[num_extensions++] = VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME;
- screen->have_physical_device_prop2_ext = true;
- }
- if (!strcmp(extension_props[i].extensionName, VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME)) {
- extensions[num_extensions++] = VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME;
- }
-#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);
- }
- }
- }
-
- // Clear have_debug_utils_ext if we do not want debug info
- if (!(zink_debug & ZINK_DEBUG_VALIDATION)) {
- have_debug_utils_ext = false;
- }
-
- {
- // Build up the layers from the reported ones
- uint32_t layer_count = 0;
- // Init has_validation_layer so if we have debug_util allow a validation layer to be added.
- // Once a validation layer has been found, do not add any more.
- bool has_validation_layer = !have_debug_utils_ext;
-
- VkResult err = vkEnumerateInstanceLayerProperties(&layer_count, NULL);
- if (err == VK_SUCCESS) {
- VkLayerProperties *layer_props = malloc(layer_count * sizeof(VkLayerProperties));
- if (layer_props) {
- err = vkEnumerateInstanceLayerProperties(&layer_count, layer_props);
- if (err == VK_SUCCESS) {
- for (uint32_t i = 0; i < layer_count; i++) {
- if (!strcmp(layer_props[i].layerName, "VK_LAYER_KHRONOS_validation") && !has_validation_layer) {
- layers[num_layers++] = "VK_LAYER_KHRONOS_validation";
- has_validation_layer = true;
- }
- if (!strcmp(layer_props[i].layerName, "VK_LAYER_LUNARG_standard_validation") && !has_validation_layer) {
- layers[num_layers++] = "VK_LAYER_LUNARG_standard_validation";
- has_validation_layer = true;
- }
-#if defined(MVK_VERSION)
- if (!strcmp(layer_props[i].layerName, "MoltenVK")) {
- have_moltenvk_layer = true;
- layers[num_layers++] = "MoltenVK";
- }
-#endif
- }
- }
- free(layer_props);
- }
- }
- }
-
- if (have_debug_utils_ext) {
- extensions[num_extensions++] = VK_EXT_DEBUG_UTILS_EXTENSION_NAME;
- screen->have_debug_utils_ext = have_debug_utils_ext;
- }
-
-#if defined(MVK_VERSION)
- if (have_moltenvk_layer_ext && have_moltenvk_layer) {
- screen->have_moltenvk = true;
- }
-#endif
-
- VkApplicationInfo ai = {};
- ai.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
-
- char proc_name[128];
- if (os_get_process_name(proc_name, ARRAY_SIZE(proc_name)))
- ai.pApplicationName = proc_name;
- else
- ai.pApplicationName = "unknown";
-
- ai.pEngineName = "mesa zink";
- ai.apiVersion = screen->loader_version;
-
- VkInstanceCreateInfo ici = {};
- ici.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
- ici.pApplicationInfo = &ai;
- ici.ppEnabledExtensionNames = extensions;
- ici.enabledExtensionCount = num_extensions;
- ici.ppEnabledLayerNames = layers;
- ici.enabledLayerCount = num_layers;
-
- VkInstance instance = VK_NULL_HANDLE;
- VkResult err = vkCreateInstance(&ici, NULL, &instance);
- if (err != VK_SUCCESS)
- return VK_NULL_HANDLE;
-
- return instance;
-}
-
static VkPhysicalDevice
choose_pdev(const VkInstance instance)
{
@@ -1070,7 +933,7 @@ zink_internal_create_screen(struct sw_winsys *winsys, int fd, const struct pipe_
zink_debug = debug_get_option_zink_debug();
- screen->instance = create_instance(screen);
+ screen->instance = zink_create_instance(screen);
if (!screen->instance)
goto fail;
diff --git a/src/gallium/drivers/zink/zink_screen.h b/src/gallium/drivers/zink/zink_screen.h
index 07c5ee4d8b5..45cf5c9f250 100644
--- a/src/gallium/drivers/zink/zink_screen.h
+++ b/src/gallium/drivers/zink/zink_screen.h
@@ -25,6 +25,7 @@
#define ZINK_SCREEN_H
#include "zink_device_info.h"
+#include "zink_instance.h"
#include "pipe/p_screen.h"
#include "util/slab.h"
@@ -53,6 +54,8 @@ struct zink_screen {
unsigned shader_id;
VkInstance instance;
+ struct zink_instance_info instance_info;
+
VkPhysicalDevice pdev;
struct zink_device_info info;