Commit be1fa7d8 by Tobin Ehlis Committed by Commit Bot

Vulkan: Enable VK_EXT_line_rasterization

Plumbing to make ANGLE use VK_EXT_line_rasterization extension when available. Bug: angleproject:3981 Change-Id: I12913c20bff69ab0b7c16462c10b8b5fd8e1c2a5 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1865027Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarAlexis Hétu <sugoi@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 9122bec2
......@@ -29,6 +29,12 @@ struct FeaturesVk : FeatureSetBase
"rasterization rules",
&members};
// If the VK_EXT_line_rasterization extension is available we'll use it to get
// Bresenham line rasterization.
Feature bresenhamLineRasterization = {
"bresenham_line_rasterization", FeatureCategory::VulkanFeatures,
"Enable Bresenham line rasterization via VK_EXT_line_rasterization extension", &members};
// Flips the viewport to render upside-down. This has the effect to render the same way as
// OpenGL. If this feature gets enabled, we enable the KHR_MAINTENANCE_1 extension to allow
// negative viewports. We inverse rendering to the backbuffer by reversing the height of the
......
......@@ -961,6 +961,42 @@ angle::Result RendererVk::initializeDevice(DisplayVk *displayVk, uint32_t queueF
ExtensionNameList enabledDeviceExtensions;
enabledDeviceExtensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
float zeroPriority = 0.0f;
VkDeviceQueueCreateInfo queueCreateInfo = {};
queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
queueCreateInfo.flags = 0;
queueCreateInfo.queueFamilyIndex = queueFamilyIndex;
queueCreateInfo.queueCount = 1;
queueCreateInfo.pQueuePriorities = &zeroPriority;
// Setup device initialization struct
VkDeviceCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
createInfo.flags = 0;
createInfo.queueCreateInfoCount = 1;
createInfo.pQueueCreateInfos = &queueCreateInfo;
createInfo.enabledLayerCount = static_cast<uint32_t>(enabledDeviceLayerNames.size());
createInfo.ppEnabledLayerNames = enabledDeviceLayerNames.data();
mLineRasterizationFeatures = {};
mLineRasterizationFeatures.sType =
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT;
ASSERT(mLineRasterizationFeatures.bresenhamLines == VK_FALSE);
if (vkGetPhysicalDeviceFeatures2KHR &&
ExtensionFound(VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME, deviceExtensionNames))
{
enabledDeviceExtensions.push_back(VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME);
// Query line rasterization capabilities
VkPhysicalDeviceFeatures2KHR availableFeatures = {};
availableFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
AppendToPNextChain(reinterpret_cast<vk::CommonStructHeader *>(&availableFeatures),
&mLineRasterizationFeatures);
vkGetPhysicalDeviceFeatures2KHR(mPhysicalDevice, &availableFeatures);
AppendToPNextChain(reinterpret_cast<vk::CommonStructHeader *>(&createInfo),
&mLineRasterizationFeatures);
}
initFeatures(deviceExtensionNames);
OverrideFeaturesWithDisplayState(&mFeatures, displayVk->getState());
mFeaturesInitialized = true;
......@@ -1036,31 +1072,13 @@ angle::Result RendererVk::initializeDevice(DisplayVk *displayVk, uint32_t queueF
VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT divisorFeatures = {};
divisorFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT;
divisorFeatures.vertexAttributeInstanceRateDivisor = true;
float zeroPriority = 0.0f;
VkDeviceQueueCreateInfo queueCreateInfo = {};
queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
queueCreateInfo.flags = 0;
queueCreateInfo.queueFamilyIndex = queueFamilyIndex;
queueCreateInfo.queueCount = 1;
queueCreateInfo.pQueuePriorities = &zeroPriority;
// Initialize the device
VkDeviceCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
createInfo.flags = 0;
createInfo.queueCreateInfoCount = 1;
createInfo.pQueueCreateInfos = &queueCreateInfo;
createInfo.enabledLayerCount = static_cast<uint32_t>(enabledDeviceLayerNames.size());
createInfo.ppEnabledLayerNames = enabledDeviceLayerNames.data();
if (vkGetPhysicalDeviceProperties2KHR &&
ExtensionFound(VK_EXT_VERTEX_ATTRIBUTE_DIVISOR_EXTENSION_NAME, deviceExtensionNames))
{
enabledDeviceExtensions.push_back(VK_EXT_VERTEX_ATTRIBUTE_DIVISOR_EXTENSION_NAME);
enabledFeatures.pNext = &divisorFeatures;
divisorFeatures.vertexAttributeInstanceRateDivisor = true;
AppendToPNextChain(reinterpret_cast<vk::CommonStructHeader *>(&enabledFeatures),
&divisorFeatures);
VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT divisorProperties = {};
divisorProperties.sType =
......@@ -1068,7 +1086,8 @@ angle::Result RendererVk::initializeDevice(DisplayVk *displayVk, uint32_t queueF
VkPhysicalDeviceProperties2 deviceProperties = {};
deviceProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
deviceProperties.pNext = &divisorProperties;
AppendToPNextChain(reinterpret_cast<vk::CommonStructHeader *>(&deviceProperties),
&divisorProperties);
vkGetPhysicalDeviceProperties2KHR(mPhysicalDevice, &deviceProperties);
// We only store 8 bit divisor in GraphicsPipelineDesc so capping value & we emulate if
......@@ -1076,11 +1095,13 @@ angle::Result RendererVk::initializeDevice(DisplayVk *displayVk, uint32_t queueF
mMaxVertexAttribDivisor =
std::min(divisorProperties.maxVertexAttribDivisor,
static_cast<uint32_t>(std::numeric_limits<uint8_t>::max()));
createInfo.pNext = &enabledFeatures;
AppendToPNextChain(reinterpret_cast<vk::CommonStructHeader *>(&createInfo),
&enabledFeatures);
}
else
if (createInfo.pNext == nullptr)
{
// Enable all available features
createInfo.pEnabledFeatures = &enabledFeatures.features;
}
......@@ -1088,7 +1109,8 @@ angle::Result RendererVk::initializeDevice(DisplayVk *displayVk, uint32_t queueF
{
VkPhysicalDeviceProperties2 deviceProperties = {};
deviceProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
deviceProperties.pNext = &mPhysicalDeviceSubgroupProperties;
AppendToPNextChain(reinterpret_cast<vk::CommonStructHeader *>(&deviceProperties),
&mPhysicalDeviceSubgroupProperties);
vkGetPhysicalDeviceProperties2KHR(mPhysicalDevice, &deviceProperties);
}
......@@ -1285,9 +1307,18 @@ void RendererVk::initFeatures(const ExtensionNameList &deviceExtensionNames)
bool isNvidia = IsNvidia(mPhysicalDeviceProperties.vendorID);
bool isQualcomm = IsQualcomm(mPhysicalDeviceProperties.vendorID);
// Use OpenGL line rasterization rules by default.
// TODO(jmadill): Fix Android support. http://anglebug.com/2830
ANGLE_FEATURE_CONDITION((&mFeatures), basicGLLineRasterization, !IsAndroid());
if (mLineRasterizationFeatures.bresenhamLines == VK_TRUE)
{
ASSERT(mLineRasterizationFeatures.sType ==
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT);
ANGLE_FEATURE_CONDITION((&mFeatures), bresenhamLineRasterization, true);
}
else
{
// Use OpenGL line rasterization rules if extension not available by default.
// TODO(jmadill): Fix Android support. http://anglebug.com/2830
ANGLE_FEATURE_CONDITION((&mFeatures), basicGLLineRasterization, !IsAndroid());
}
// TODO(lucferron): Currently disabled on Intel only since many tests are failing and need
// investigation. http://anglebug.com/2728
......
......@@ -246,6 +246,7 @@ class RendererVk : angle::NonCopyable
VkPhysicalDeviceProperties mPhysicalDeviceProperties;
VkPhysicalDeviceSubgroupProperties mPhysicalDeviceSubgroupProperties;
VkPhysicalDeviceFeatures mPhysicalDeviceFeatures;
VkPhysicalDeviceLineRasterizationFeaturesEXT mLineRasterizationFeatures;
std::vector<VkQueueFamilyProperties> mQueueFamilyProperties;
std::mutex mQueueMutex;
VkQueue mQueue;
......
......@@ -789,6 +789,14 @@ angle::Result GraphicsPipelineDesc::initializePipeline(
rasterState.depthBiasClamp = rasterAndMS.depthBiasClamp;
rasterState.depthBiasSlopeFactor = rasterAndMS.depthBiasSlopeFactor;
rasterState.lineWidth = rasterAndMS.lineWidth;
VkPipelineRasterizationLineStateCreateInfoEXT rasterLineState = {};
rasterLineState.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_LINE_STATE_CREATE_INFO_EXT;
// Always enable Bresenham line rasterization if available.
if (contextVk->getFeatures().bresenhamLineRasterization.enabled)
{
rasterLineState.lineRasterizationMode = VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT;
rasterState.pNext = &rasterLineState;
}
// Multisample state.
multisampleState.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
......
......@@ -260,6 +260,16 @@ namespace vk
const char *gLoaderLayersPathEnv = "VK_LAYER_PATH";
const char *gLoaderICDFilenamesEnv = "VK_ICD_FILENAMES";
void AppendToPNextChain(CommonStructHeader *chainStart, void *ptr)
{
CommonStructHeader *localPtr = chainStart;
while (localPtr->pNext)
{
localPtr = static_cast<CommonStructHeader *>(localPtr->pNext);
}
localPtr->pNext = ptr;
}
VkImageAspectFlags GetDepthStencilAspectFlags(const angle::Format &format)
{
return (format.depthBits > 0 ? VK_IMAGE_ASPECT_DEPTH_BIT : 0) |
......@@ -608,6 +618,7 @@ PFN_vkDestroyDebugReportCallbackEXT vkDestroyDebugReportCallbackEXT = nullptr;
// VK_KHR_get_physical_device_properties2
PFN_vkGetPhysicalDeviceProperties2KHR vkGetPhysicalDeviceProperties2KHR = nullptr;
PFN_vkGetPhysicalDeviceFeatures2KHR vkGetPhysicalDeviceFeatures2KHR = nullptr;
// VK_KHR_external_semaphore_fd
PFN_vkImportSemaphoreFdKHR vkImportSemaphoreFdKHR = nullptr;
......@@ -642,6 +653,7 @@ void InitDebugReportEXTFunctions(VkInstance instance)
void InitGetPhysicalDeviceProperties2KHRFunctions(VkInstance instance)
{
GET_FUNC(vkGetPhysicalDeviceProperties2KHR);
GET_FUNC(vkGetPhysicalDeviceFeatures2KHR);
}
#if defined(ANGLE_PLATFORM_FUCHSIA)
......
......@@ -101,6 +101,15 @@ namespace vk
{
struct Format;
struct CommonStructHeader
{
VkStructureType sType;
void *pNext;
};
// Append ptr to end of pNext chain beginning at chainStart->pNext
void AppendToPNextChain(CommonStructHeader *chainStart, void *ptr);
extern const char *gLoaderLayersPathEnv;
extern const char *gLoaderICDFilenamesEnv;
......@@ -608,6 +617,7 @@ extern PFN_vkDestroyDebugReportCallbackEXT vkDestroyDebugReportCallbackEXT;
// VK_KHR_get_physical_device_properties2
extern PFN_vkGetPhysicalDeviceProperties2KHR vkGetPhysicalDeviceProperties2KHR;
extern PFN_vkGetPhysicalDeviceFeatures2KHR vkGetPhysicalDeviceFeatures2KHR;
// VK_KHR_external_semaphore_fd
extern PFN_vkImportSemaphoreFdKHR vkImportSemaphoreFdKHR;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment