Hash :
2ad498eb
Author :
Date :
2018-06-20T13:19:01
Vulkan: get vertex formats from format table. Use the Vulkan format table to look up the Vulkan format for vertex data. This will let us support more vertex formats by adding them to the table. It also eliminates one usage of gl::VertexFormatType. No functional change. BUG=angleproject:2405 BUG=angleproject:2531 Change-Id: I73eb69ccac50d427de3e7d5479f92bb17c49aed3 Reviewed-on: https://chromium-review.googlesource.com/1051028 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Luc Ferron <lucferron@chromium.org> Commit-Queue: Frank Henigman <fjhenigman@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
//
// Copyright 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// vk_format_utils:
// Helper for Vulkan format code.
#include "libANGLE/renderer/vulkan/vk_format_utils.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/load_functions_table.h"
#include "libANGLE/renderer/vulkan/vk_caps_utils.h"
namespace rx
{
namespace
{
constexpr VkFormatFeatureFlags kNecessaryBitsFullSupportDepthStencil =
VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT |
VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
constexpr VkFormatFeatureFlags kNecessaryBitsFullSupportColor =
VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT |
VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
bool HasFormatFeatureBits(const VkFormatFeatureFlags featureBits,
const VkFormatProperties &formatProperties)
{
return IsMaskFlagSet(formatProperties.optimalTilingFeatures, featureBits);
}
void FillTextureFormatCaps(const VkFormatProperties &formatProperties,
gl::TextureCaps *outTextureCaps)
{
outTextureCaps->texturable =
HasFormatFeatureBits(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT, formatProperties);
outTextureCaps->filterable =
HasFormatFeatureBits(VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT, formatProperties);
outTextureCaps->textureAttachment =
HasFormatFeatureBits(VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT, formatProperties) ||
HasFormatFeatureBits(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT, formatProperties);
outTextureCaps->renderbuffer = outTextureCaps->textureAttachment;
}
} // anonymous namespace
namespace vk
{
void GetFormatProperties(VkPhysicalDevice physicalDevice,
VkFormat vkFormat,
VkFormatProperties *propertiesOut)
{
// Try filling out the info from our hard coded format data, if we can't find the
// information we need, we'll make the call to Vulkan.
const VkFormatProperties &formatProperties = vk::GetMandatoryFormatSupport(vkFormat);
// Once we filled what we could with the mandatory texture caps, we verify if
// all the bits we need to satify all our checks are present, and if so we can
// skip the device call.
if (!IsMaskFlagSet(formatProperties.optimalTilingFeatures, kNecessaryBitsFullSupportColor) &&
!IsMaskFlagSet(formatProperties.optimalTilingFeatures,
kNecessaryBitsFullSupportDepthStencil))
{
vkGetPhysicalDeviceFormatProperties(physicalDevice, vkFormat, propertiesOut);
}
else
{
*propertiesOut = formatProperties;
}
}
bool HasFullFormatSupport(VkPhysicalDevice physicalDevice, VkFormat vkFormat)
{
VkFormatProperties formatProperties;
GetFormatProperties(physicalDevice, vkFormat, &formatProperties);
constexpr uint32_t kBitsColor =
(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT |
VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
constexpr uint32_t kBitsDepth = (VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);
return HasFormatFeatureBits(kBitsColor, formatProperties) ||
HasFormatFeatureBits(kBitsDepth, formatProperties);
}
// Format implementation.
Format::Format()
: angleFormatID(angle::Format::ID::NONE),
internalFormat(GL_NONE),
textureFormatID(angle::Format::ID::NONE),
vkTextureFormat(VK_FORMAT_UNDEFINED),
bufferFormatID(angle::Format::ID::NONE),
vkBufferFormat(VK_FORMAT_UNDEFINED),
dataInitializerFunction(nullptr),
loadFunctions()
{
}
const angle::Format &Format::textureFormat() const
{
return angle::Format::Get(textureFormatID);
}
const angle::Format &Format::bufferFormat() const
{
return angle::Format::Get(bufferFormatID);
}
const angle::Format &Format::angleFormat() const
{
return angle::Format::Get(angleFormatID);
}
bool operator==(const Format &lhs, const Format &rhs)
{
return &lhs == &rhs;
}
bool operator!=(const Format &lhs, const Format &rhs)
{
return &lhs != &rhs;
}
// FormatTable implementation.
FormatTable::FormatTable()
{
}
FormatTable::~FormatTable()
{
}
void FormatTable::initialize(VkPhysicalDevice physicalDevice,
gl::TextureCapsMap *outTextureCapsMap,
std::vector<GLenum> *outCompressedTextureFormats)
{
for (size_t formatIndex = 0; formatIndex < angle::kNumANGLEFormats; ++formatIndex)
{
const auto formatID = static_cast<angle::Format::ID>(formatIndex);
const angle::Format &angleFormat = angle::Format::Get(formatID);
mFormatData[formatIndex].initialize(physicalDevice, angleFormat);
const GLenum internalFormat = mFormatData[formatIndex].internalFormat;
mFormatData[formatIndex].loadFunctions =
GetLoadFunctionsMap(internalFormat, mFormatData[formatIndex].textureFormatID);
mFormatData[formatIndex].angleFormatID = formatID;
if (!mFormatData[formatIndex].valid())
{
continue;
}
const VkFormat vkFormat = mFormatData[formatIndex].vkTextureFormat;
// Try filling out the info from our hard coded format data, if we can't find the
// information we need, we'll make the call to Vulkan.
VkFormatProperties formatProperties;
GetFormatProperties(physicalDevice, vkFormat, &formatProperties);
gl::TextureCaps textureCaps;
FillTextureFormatCaps(formatProperties, &textureCaps);
outTextureCapsMap->set(formatID, textureCaps);
if (angleFormat.isBlock)
{
outCompressedTextureFormats->push_back(internalFormat);
}
}
}
const Format &FormatTable::operator[](GLenum internalFormat) const
{
angle::Format::ID formatID = angle::Format::InternalFormatToID(internalFormat);
return mFormatData[static_cast<size_t>(formatID)];
}
const Format &FormatTable::operator[](angle::Format::ID formatID) const
{
return mFormatData[static_cast<size_t>(formatID)];
}
} // namespace vk
} // namespace rx