Commit fb4eea2e by Jamie Madill Committed by Commit Bot

Vulkan: Index mandatory support table by ANGLE format.

This removes another instance of indexing a flat array by VkFormat. With the introduction of YUV formats we no longer have a compact table. Switching to ANGLE format indexing allows us to keep a flat array and avoid using an unordered map. Bug: angleproject:5438 Change-Id: I96caa19e3b7ce419ce09680399919447f002b0bd Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2622238Reviewed-by: 's avatarIan Elliott <ianelliott@google.com> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 8db7915e
......@@ -2,11 +2,13 @@
"src/libANGLE/renderer/angle_format.py":
"32ba71942c0fd00e6807104f1bb80a3c",
"src/libANGLE/renderer/vulkan/gen_vk_mandatory_format_support_table.py":
"791db4381676327e49c7a9046423136a",
"0d798546ff1b4932164a64b9404396bb",
"src/libANGLE/renderer/vulkan/vk_format_map.json":
"b62588b1e9f6d9fa98aeea886d8ed2bd",
"src/libANGLE/renderer/vulkan/vk_mandatory_format_support_data.json":
"fa2bd54c1bb0ab2cf1d386061a4bc5c5",
"src/libANGLE/renderer/vulkan/vk_mandatory_format_support_table_autogen.cpp":
"8bfd8a3857c2b9062d7ada46c7d27bcf",
"ed2e75f0b4eec5ad9f55227c5578e0d6",
"third_party/vulkan-deps/vulkan-headers/src/registry/vk.xml":
"e7129a174322b4f0a2c8c1229e91f04c"
}
\ No newline at end of file
......@@ -2330,16 +2330,16 @@ VkFormatFeatureFlags RendererVk::getFormatFeatureBits(angle::FormatID formatID,
if (deviceProperties.bufferFeatures == kInvalidFormatFeatureFlags)
{
VkFormat vkFormat = vk::GetVkFormatFromFormatID(formatID);
// If we don't have the actual device features, see if the requested features are mandatory.
// If so, there's no need to query the device.
const VkFormatProperties &mandatoryProperties = vk::GetMandatoryFormatSupport(vkFormat);
const VkFormatProperties &mandatoryProperties = vk::GetMandatoryFormatSupport(formatID);
if (IsMaskFlagSet(mandatoryProperties.*features, featureBits))
{
return featureBits;
}
VkFormat vkFormat = vk::GetVkFormatFromFormatID(formatID);
// Otherwise query the format features and cache it.
vkGetPhysicalDeviceFormatProperties(mPhysicalDevice, vkFormat, &deviceProperties);
// Workaround for some Android devices that don't indicate filtering
......
......@@ -15,7 +15,7 @@ import angle_format
import xml.etree.ElementTree as etree
import sys, os
template_table_autogen_cpp = """// GENERATED FILE - DO NOT EDIT.
TEMPLATE_TABLE_AUTOGEN_CPP = """// GENERATED FILE - DO NOT EDIT.
// Generated by {script_name} using data from {input_file_name} and
// the vk.xml file situated at
// /third_party/vulkan-validation-layers/src/scripts/vk.xml
......@@ -33,53 +33,63 @@ using namespace angle;
namespace rx
{{
namespace vk
{{
namespace
{{
static_assert({num_formats} == kNumVkFormats, "Update kNumVkFormats");
constexpr std::array<VkFormatProperties, kNumVkFormats> kFormatProperties = {{{{
constexpr VkFormatFeatureFlagBits BLIT_DST = VK_FORMAT_FEATURE_BLIT_DST_BIT;
constexpr VkFormatFeatureFlagBits BLIT_SRC = VK_FORMAT_FEATURE_BLIT_SRC_BIT;
constexpr VkFormatFeatureFlagBits COLOR_ATTACHMENT = VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
constexpr VkFormatFeatureFlagBits COLOR_ATTACHMENT_BLEND = VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT;
constexpr VkFormatFeatureFlagBits DEPTH_STENCIL_ATTACHMENT = VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
constexpr VkFormatFeatureFlagBits SAMPLED_IMAGE = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT;
constexpr VkFormatFeatureFlagBits SAMPLED_IMAGE_FILTER_LINEAR = VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
constexpr VkFormatFeatureFlagBits STORAGE_IMAGE = VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT;
constexpr VkFormatFeatureFlagBits STORAGE_IMAGE_ATOMIC = VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT;
constexpr VkFormatFeatureFlagBits STORAGE_TEXEL_BUFFER = VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT;
constexpr VkFormatFeatureFlagBits STORAGE_TEXEL_BUFFER_ATOMIC = VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT;
constexpr VkFormatFeatureFlagBits UNIFORM_TEXEL_BUFFER = VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT;
constexpr VkFormatFeatureFlagBits VERTEX_BUFFER = VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT;
using namespace angle;
constexpr FormatMap<VkFormatProperties> kFormatProperties = {{
{format_case_data}
}}}};
}};
}} // anonymous namespace
const VkFormatProperties& GetMandatoryFormatSupport(VkFormat vkFormat)
const VkFormatProperties& GetMandatoryFormatSupport(FormatID formatID)
{{
ASSERT(static_cast<uint64_t>(vkFormat) < sizeof(kFormatProperties));
return kFormatProperties[vkFormat];
return kFormatProperties[formatID];
}}
}} // namespace vk
}} // namespace rx
"""
template_format_property = """
/* {vk_format} */
{{0, {optimal_features}, {buffer_features}}}"""
TEMPLATE_FORMAT_PROPERTY = """{{FormatID::{format_id}, {{0, {optimal_features}, {buffer_features}}}}}"""
def script_relative(path):
return os.path.join(os.path.dirname(sys.argv[0]), path)
def gen_format_case(index, vk_to_index_to_format_map, vk_map):
vk_format = vk_to_index_to_format_map[index]
def gen_format_case(format_id, vk_format, vk_map):
def de(str):
return str.replace("VK_FORMAT_FEATURE_", "").replace("_BIT", "")
if vk_format in vk_map and len(vk_map[vk_format]) > 0:
# Check which feature is a buffer feature or not.
buffer_features = [x for x in vk_map[vk_format] if x.find("_BUFFER_") != -1]
optimal_features = [x for x in vk_map[vk_format] if x.find("_BUFFER_") == -1]
optimal_features_str = "|".join(optimal_features) if len(optimal_features) else "0"
buffer_features_str = "|".join(buffer_features) if len(buffer_features) else "0"
buffer_features = [de(x) for x in vk_map[vk_format] if x.find("_BUFFER_") != -1]
optimal_features = [de(x) for x in vk_map[vk_format] if x.find("_BUFFER_") == -1]
optimal_features_str = "|".join(sorted(optimal_features)) if len(optimal_features) else "0"
buffer_features_str = "|".join(sorted(buffer_features)) if len(buffer_features) else "0"
else:
optimal_features_str = "0"
buffer_features_str = "0"
return template_format_property.format(
return TEMPLATE_FORMAT_PROPERTY.format(
format_id=format_id,
vk_format=vk_format,
optimal_features=optimal_features_str,
buffer_features=buffer_features_str)
......@@ -88,6 +98,7 @@ def gen_format_case(index, vk_to_index_to_format_map, vk_map):
def main():
input_file_name = 'vk_mandatory_format_support_data.json'
vk_format_map_path = 'vk_format_map.json'
out_file_name = 'vk_mandatory_format_support_table_autogen.cpp'
vk_xml_file = '../../../../third_party/vulkan-deps/vulkan-headers/src/registry/vk.xml'
......@@ -96,6 +107,7 @@ def main():
inputs = [
'../angle_format.py',
input_file_name,
vk_format_map_path,
vk_xml_file,
]
outputs = [out_file_name]
......@@ -112,22 +124,15 @@ def main():
tree = etree.parse(script_relative(vk_xml_file))
root = tree.getroot()
vk_format_enums = root.findall(".//enums[@name='VkFormat']/enum")
vk_format_name_to_index_map = {}
num_formats = len(vk_format_enums)
for format_enum in vk_format_enums:
index = int(format_enum.attrib['value'])
vk_format = format_enum.attrib['name']
vk_format_name_to_index_map[index] = vk_format
vk_map = angle_format.load_json(input_file_name)
vk_format_map = angle_format.load_json(vk_format_map_path)
vk_cases = [
gen_format_case(index, vk_format_name_to_index_map, vk_map)
for index in vk_format_name_to_index_map
gen_format_case(format_id, vk_format, vk_map)
for format_id, vk_format in vk_format_map["map"].iteritems()
]
output_cpp = template_table_autogen_cpp.format(
num_formats=num_formats,
format_case_data="\n,".join(vk_cases),
output_cpp = TEMPLATE_TABLE_AUTOGEN_CPP.format(
format_case_data=",\n".join(vk_cases),
script_name=__file__,
out_file_name=out_file_name,
input_file_name=input_file_name)
......
......@@ -178,7 +178,7 @@ class FormatTable final : angle::NonCopyable
// if the format is a mandatory format described in section 31.3.3. Required Format Support
// of the Vulkan spec. If the vkFormat isn't mandatory, it will return a VkFormatProperties
// initialized to 0.
const VkFormatProperties &GetMandatoryFormatSupport(VkFormat vkFormat);
const VkFormatProperties &GetMandatoryFormatSupport(angle::FormatID formatID);
VkImageUsageFlags GetMaximalImageUsageFlags(RendererVk *renderer, angle::FormatID formatID);
......
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