Check for support
VkPhysicalDeviceMeshShaderFeaturesNV meshShader = {}; meshShader.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MESH_SHADER_FEATURES_NV; VkPhysicalDeviceFeatures2 features2 = {}; features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR; features2.pNext = &meshShader; vkGetPhysicalDeviceFeatures2(gpu, &features2); if (meshShader.meshShader && meshShader.taskShader) { exit(-1); }
Enable device extension
vectorextensions({ VK_KHR_SWAPCHAIN_EXTENSION_NAME }); if (vk.supportsMeshShaders) { extensions.push_back(VK_NV_MESH_SHADER_EXTENSION_NAME); }
Enable device features
VkPhysicalDeviceMeshShaderFeaturesNV meshFeatures = {}; meshFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MESH_SHADER_FEATURES_NV; meshFeatures.meshShader = true; meshFeatures.taskShader = true; VkPhysicalDeviceFeatures2 features = {}; features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR; if (vk.supportsMeshShaders) { features.pNext = &meshFeatures; } VkDeviceCreateInfo createInfo = {}; createInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; createInfo.pNext = &features; createInfo.queueCreateInfoCount = static_cast<uint32_t>( queueCreateInfos.size() ); createInfo.pQueueCreateInfos = queueCreateInfos.data(); createInfo.enabledExtensionCount = (uint32_t)extensions.size(); createInfo.ppEnabledExtensionNames = extensions.data(); checkSuccess(vkCreateDevice(vk.gpu, &createInfo, nullptr, &vk.device));
Get function pointer
PFN_vkVoidFunction getFunction(Vulkan& vk, const char* name) { auto result = vkGetDeviceProcAddr(vk.device, name); if (result == NULL) { LOG(ERROR) << "could not find " << name; exit(-1); } return result; } void getFunctions(Vulkan& vk) { vk.cmdDrawMeshTasksNV = (PFN_vkCmdDrawMeshTasksNV) getFunction(vk, "vkCmdDrawMeshTasksNV"); }
Fill out empty vertex input stage for pipeline
VkPipelineVertexInputStateCreateInfo vertexInput = {};