Commit 84c074cf by Shahbaz Youssefi Committed by Commit Bot

Vulkan: Simplify AppendToPNextChain use

The function is turned into a template to avoid the reinterpret_cast at call sites. Additionally, uses Vulkan's own VkBaseOutStructure instead of a bespoke definition. Bug: angleproject:4027 Change-Id: Ib236d44a12c0363e7e89b9bf2ed5ab8166252730 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1924992 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarTobin Ehlis <tobine@google.com>
parent b0a9de95
......@@ -979,12 +979,10 @@ angle::Result RendererVk::initializeDevice(DisplayVk *displayVk, uint32_t queueF
// Query line rasterization capabilities
VkPhysicalDeviceFeatures2KHR availableFeatures = {};
availableFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
AppendToPNextChain(reinterpret_cast<vk::CommonStructHeader *>(&availableFeatures),
&mLineRasterizationFeatures);
vk::AppendToPNextChain(&availableFeatures, &mLineRasterizationFeatures);
vkGetPhysicalDeviceFeatures2KHR(mPhysicalDevice, &availableFeatures);
AppendToPNextChain(reinterpret_cast<vk::CommonStructHeader *>(&createInfo),
&mLineRasterizationFeatures);
vk::AppendToPNextChain(&createInfo, &mLineRasterizationFeatures);
}
mProvokingVertexFeatures = {};
......@@ -998,12 +996,10 @@ angle::Result RendererVk::initializeDevice(DisplayVk *displayVk, uint32_t queueF
// Query line rasterization capabilities
VkPhysicalDeviceFeatures2KHR availableFeatures = {};
availableFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
AppendToPNextChain(reinterpret_cast<vk::CommonStructHeader *>(&availableFeatures),
&mProvokingVertexFeatures);
vk::AppendToPNextChain(&availableFeatures, &mProvokingVertexFeatures);
vkGetPhysicalDeviceFeatures2KHR(mPhysicalDevice, &availableFeatures);
AppendToPNextChain(reinterpret_cast<vk::CommonStructHeader *>(&createInfo),
&mProvokingVertexFeatures);
vk::AppendToPNextChain(&createInfo, &mProvokingVertexFeatures);
}
if (!displayVk->getState().featuresAllDisabled)
......@@ -1089,8 +1085,7 @@ angle::Result RendererVk::initializeDevice(DisplayVk *displayVk, uint32_t queueF
{
enabledDeviceExtensions.push_back(VK_EXT_VERTEX_ATTRIBUTE_DIVISOR_EXTENSION_NAME);
divisorFeatures.vertexAttributeInstanceRateDivisor = true;
AppendToPNextChain(reinterpret_cast<vk::CommonStructHeader *>(&enabledFeatures),
&divisorFeatures);
vk::AppendToPNextChain(&enabledFeatures, &divisorFeatures);
VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT divisorProperties = {};
divisorProperties.sType =
......@@ -1098,8 +1093,7 @@ angle::Result RendererVk::initializeDevice(DisplayVk *displayVk, uint32_t queueF
VkPhysicalDeviceProperties2 deviceProperties = {};
deviceProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
AppendToPNextChain(reinterpret_cast<vk::CommonStructHeader *>(&deviceProperties),
&divisorProperties);
vk::AppendToPNextChain(&deviceProperties, &divisorProperties);
vkGetPhysicalDeviceProperties2KHR(mPhysicalDevice, &deviceProperties);
// We only store 8 bit divisor in GraphicsPipelineDesc so capping value & we emulate if
......@@ -1107,8 +1101,7 @@ angle::Result RendererVk::initializeDevice(DisplayVk *displayVk, uint32_t queueF
mMaxVertexAttribDivisor =
std::min(divisorProperties.maxVertexAttribDivisor,
static_cast<uint32_t>(std::numeric_limits<uint8_t>::max()));
AppendToPNextChain(reinterpret_cast<vk::CommonStructHeader *>(&createInfo),
&enabledFeatures);
vk::AppendToPNextChain(&createInfo, &enabledFeatures);
}
else
{
......@@ -1120,8 +1113,7 @@ angle::Result RendererVk::initializeDevice(DisplayVk *displayVk, uint32_t queueF
{
VkPhysicalDeviceProperties2 deviceProperties = {};
deviceProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
AppendToPNextChain(reinterpret_cast<vk::CommonStructHeader *>(&deviceProperties),
&mPhysicalDeviceSubgroupProperties);
vk::AppendToPNextChain(&deviceProperties, &mPhysicalDeviceSubgroupProperties);
vkGetPhysicalDeviceProperties2KHR(mPhysicalDevice, &deviceProperties);
}
......
......@@ -260,16 +260,6 @@ 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) |
......
......@@ -101,14 +101,17 @@ namespace vk
{
struct Format;
struct CommonStructHeader
// Append ptr to end of pNext chain beginning at chainStart
template <typename VulkanStruct1, typename VulkanStruct2>
void AppendToPNextChain(VulkanStruct1 *chainStart, VulkanStruct2 *ptr)
{
VkStructureType sType;
void *pNext;
};
// Append ptr to end of pNext chain beginning at chainStart->pNext
void AppendToPNextChain(CommonStructHeader *chainStart, void *ptr);
VkBaseOutStructure *localPtr = reinterpret_cast<VkBaseOutStructure *>(chainStart);
while (localPtr->pNext)
{
localPtr = localPtr->pNext;
}
localPtr->pNext = reinterpret_cast<VkBaseOutStructure *>(ptr);
}
extern const char *gLoaderLayersPathEnv;
extern const char *gLoaderICDFilenamesEnv;
......
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