Commit 3b1fe64f by Frank Henigman Committed by Commit Bot

Vulkan: allow a list of fallback formats.

Allow a list of fallback formats as well as a single one in the format map. The first supported format is used. No functional change. BUG=angleproject:2655 Change-Id: Ica312b7899471a7a65184a6921713b79da056f31 Reviewed-on: https://chromium-review.googlesource.com/1214847Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org> Commit-Queue: Yuly Novikov <ynovikov@chromium.org>
parent a59ae05b
......@@ -66,7 +66,7 @@
"Vulkan format:src/libANGLE/renderer/angle_format_map.json":
"ea6dfe3ebbc86e04f0d4b9f568ba22ae",
"Vulkan format:src/libANGLE/renderer/vulkan/gen_vk_format_table.py":
"4a69cb1e69194ca237b94642edbd3f69",
"1d7d1b6a1f2b4b6f5080197c56b908b4",
"Vulkan format:src/libANGLE/renderer/vulkan/vk_format_map.json":
"f7cb189ab41f1ce48ff26e7c328c5cd0",
"Vulkan internal shader programs:src/libANGLE/renderer/vulkan/gen_vk_internal_shaders.py":
......@@ -82,7 +82,7 @@
"Vulkan mandatory format support table:src/libANGLE/renderer/vulkan/vk_mandatory_format_support_data.json":
"fa2bd54c1bb0ab2cf1d386061a4bc5c5",
"Vulkan mandatory format support table:third_party/vulkan-headers/src/registry/vk.xml":
"c73903f9411b54db01d4891bc24ebd0e",
"de9fb16e43de8ab4b69f673c2ca03704",
"packed enum:src/common/gen_packed_gl_enums.py":
"a9b1c38b4e4d8a1038e743be323f1a51",
"packed enum:src/common/packed_egl_enums.json":
......@@ -92,7 +92,7 @@
"proc table:src/libGLESv2/gen_proc_table.py":
"027bfd5a8a8dffe91f492bf199029cde",
"proc table:src/libGLESv2/proc_table_data.json":
"2c452ae503df669222e85961ab75fb22",
"77dd1356708c3c8014bb22f890db6e08",
"uniform type:src/common/gen_uniform_type_table.py":
"59cb4ffd0f584c4bd37f2f4ff59a2b93"
}
\ No newline at end of file
......@@ -69,79 +69,82 @@ internalFormat = {internal_format};
break;
"""
texture_basic_template = """textureFormatID = angle::FormatID::{texture};
texture_basic_template = """textureFormatID = {texture};
vkTextureFormat = {vk_texture_format};
textureInitializerFunction = {texture_initializer};"""
texture_struct_template="{{{texture}, {vk_texture_format}, {texture_initializer}}}"
texture_fallback_template = """{{
static constexpr TextureFormatInitInfo kInfo[] = {{{texture_list}}};
initTextureFallback(physicalDevice, kInfo, ArraySize(kInfo));
}}"""
texture_fallback_template = """initTextureFallback(physicalDevice,
angle::FormatID::{texture},
{vk_texture_format},
{texture_initializer},
angle::FormatID::{texture_fallback},
{vk_texture_format_fallback},
{texture_initializer_fallback});"""
buffer_basic_template = """bufferFormatID = angle::FormatID::{buffer};
buffer_basic_template = """bufferFormatID = {buffer};
vkBufferFormat = {vk_buffer_format};
vertexLoadFunction = {vertex_load_function};
vertexLoadRequiresConversion = {vertex_load_converts};"""
buffer_fallback_template = """initBufferFallback(physicalDevice,
angle::FormatID::{buffer},
{vk_buffer_format},
{vertex_load_function},
{vertex_load_converts},
angle::FormatID::{buffer_fallback},
{vk_buffer_format_fallback},
{vertex_load_function_fallback});"""
buffer_struct_template="""{{{buffer}, {vk_buffer_format}, {vertex_load_function},
{vertex_load_converts}}}"""
buffer_fallback_template = """{{
static constexpr BufferFormatInitInfo kInfo[] = {{{buffer_list}}};
initBufferFallback(physicalDevice, kInfo, ArraySize(kInfo));
}}"""
def gen_format_case(angle, internal_format, vk_json_data):
vk_map = vk_json_data["map"]
vk_overrides = vk_json_data["overrides"]
vk_fallbacks = vk_json_data["fallbacks"]
args = { "format_id" : angle }
args = dict(format_id=angle, internal_format=internal_format,
texture_template="", buffer_template="")
if ((angle not in vk_map) and (angle not in vk_overrides) and
(angle not in vk_fallbacks)) or angle == 'NONE':
return empty_format_entry_template.format(**args)
def get_formats_and_template(format, type, basic_template, fallback_template):
def get_formats(format, type):
format = vk_overrides.get(format, {}).get(type, format)
fallback = vk_fallbacks.get(format, {}).get(type, "NONE")
if format not in vk_map:
format = "NONE"
template = ""
elif fallback == "NONE":
template = basic_template
else:
template = fallback_template
return format, fallback, template
texture_format, texture_fallback, texture_template = get_formats_and_template(
angle, "texture", texture_basic_template, texture_fallback_template)
buffer_format, buffer_fallback, buffer_template = get_formats_and_template(
angle, "buffer", buffer_basic_template, buffer_fallback_template)
args.update(
internal_format=internal_format,
texture_template=texture_template,
texture=texture_format,
vk_texture_format=vk_map[texture_format],
texture_initializer=angle_format.get_internal_format_initializer(internal_format,
texture_format),
texture_fallback=texture_fallback,
vk_texture_format_fallback=vk_map[texture_fallback],
texture_initializer_fallback=angle_format.get_internal_format_initializer(internal_format,
texture_fallback),
buffer_template=buffer_template,
buffer=buffer_format,
vk_buffer_format=vk_map[buffer_format],
vertex_load_function=angle_format.get_vertex_copy_function(angle, buffer_format),
vertex_load_converts='false' if angle == buffer_format else 'true',
buffer_fallback=buffer_fallback,
vk_buffer_format_fallback=vk_map[buffer_fallback],
vertex_load_function_fallback=angle_format.get_vertex_copy_function(angle, buffer_fallback),
)
return []
fallbacks = vk_fallbacks.get(format, {}).get(type, [])
if not isinstance(fallbacks, list):
fallbacks = [fallbacks]
return [format] + fallbacks
def texture_args(format):
return dict(
texture="angle::FormatID::" + format,
vk_texture_format=vk_map[format],
texture_initializer=angle_format.get_internal_format_initializer(internal_format,
format)
)
def buffer_args(format):
return dict(
buffer="angle::FormatID::" + format,
vk_buffer_format=vk_map[format],
vertex_load_function=angle_format.get_vertex_copy_function(angle, format),
vertex_load_converts='false' if angle == format else 'true',
)
textures = get_formats(angle, "texture")
if len(textures) == 1:
args.update(texture_template=texture_basic_template)
args.update(texture_args(textures[0]))
elif len(textures) > 1:
args.update(
texture_template=texture_fallback_template,
texture_list=", ".join(texture_struct_template.format(**texture_args(i))
for i in textures)
)
buffers = get_formats(angle, "buffer")
if len(buffers) == 1:
args.update(buffer_template=buffer_basic_template)
args.update(buffer_args(buffers[0]))
elif len(buffers) > 1:
args.update(
buffer_template=buffer_fallback_template,
buffer_list=", ".join(buffer_struct_template.format(**buffer_args(i)) for i in buffers)
)
return format_entry_template.format(**args).format(**args)
......
......@@ -63,6 +63,30 @@ bool HasFullBufferFormatSupport(VkPhysicalDevice physicalDevice, VkFormat vkForm
return formatProperties.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT;
}
using SupportTest = bool (*)(VkPhysicalDevice physicalDevice, VkFormat vkFormat);
template <class FormatInitInfo>
int FindSupportedFormat(VkPhysicalDevice physicalDevice,
const FormatInitInfo *info,
int numInfo,
SupportTest hasSupport)
{
ASSERT(numInfo > 1);
const int last = numInfo - 1;
for (int i = 0; i < last; ++i)
{
ASSERT(info[i].format != angle::FormatID::NONE);
if (hasSupport(physicalDevice, info[i].vkFormat))
return i;
}
// List must contain a supported item. We failed on all the others so the last one must be it.
ASSERT(info[last].format != angle::FormatID::NONE);
ASSERT(hasSupport(physicalDevice, info[last].vkFormat));
return last;
}
} // anonymous namespace
namespace vk
......@@ -105,58 +129,24 @@ Format::Format()
}
void Format::initTextureFallback(VkPhysicalDevice physicalDevice,
angle::FormatID format,
VkFormat vkFormat,
InitializeTextureDataFunction initializer,
angle::FormatID fallbackFormat,
VkFormat fallbackVkFormat,
InitializeTextureDataFunction fallbackInitializer)
const TextureFormatInitInfo *info,
int numInfo)
{
ASSERT(format != angle::FormatID::NONE);
ASSERT(fallbackFormat != angle::FormatID::NONE);
if (HasFullTextureFormatSupport(physicalDevice, vkFormat))
{
textureFormatID = format;
vkTextureFormat = vkFormat;
textureInitializerFunction = initializer;
}
else
{
textureFormatID = fallbackFormat;
vkTextureFormat = fallbackVkFormat;
textureInitializerFunction = fallbackInitializer;
ASSERT(HasFullTextureFormatSupport(physicalDevice, vkTextureFormat));
}
int i = FindSupportedFormat(physicalDevice, info, numInfo, HasFullTextureFormatSupport);
textureFormatID = info[i].format;
vkTextureFormat = info[i].vkFormat;
textureInitializerFunction = info[i].initializer;
}
void Format::initBufferFallback(VkPhysicalDevice physicalDevice,
angle::FormatID format,
VkFormat vkFormat,
VertexCopyFunction function,
bool functionConverts,
angle::FormatID fallbackFormat,
VkFormat fallbackVkFormat,
VertexCopyFunction fallbackFunction)
{
ASSERT(format != angle::FormatID::NONE);
ASSERT(fallbackFormat != angle::FormatID::NONE);
if (HasFullBufferFormatSupport(physicalDevice, vkFormat))
{
bufferFormatID = format;
vkBufferFormat = vkFormat;
vertexLoadFunction = function;
vertexLoadRequiresConversion = functionConverts;
}
else
{
bufferFormatID = fallbackFormat;
vkBufferFormat = fallbackVkFormat;
vertexLoadFunction = fallbackFunction;
vertexLoadRequiresConversion = true;
ASSERT(HasFullBufferFormatSupport(physicalDevice, vkBufferFormat));
}
const BufferFormatInitInfo *info,
int numInfo)
{
int i = FindSupportedFormat(physicalDevice, info, numInfo, HasFullBufferFormatSupport);
bufferFormatID = info[i].format;
vkBufferFormat = info[i].vkFormat;
vertexLoadFunction = info[i].vertexLoadFunction;
vertexLoadRequiresConversion = info[i].vertexLoadRequiresConversion;
}
const angle::Format &Format::textureFormat() const
......
......@@ -33,6 +33,21 @@ void GetFormatProperties(VkPhysicalDevice physicalDevice,
VkFormat vkFormat,
VkFormatProperties *propertiesOut);
struct TextureFormatInitInfo final
{
angle::FormatID format;
VkFormat vkFormat;
InitializeTextureDataFunction initializer;
};
struct BufferFormatInitInfo final
{
angle::FormatID format;
VkFormat vkFormat;
VertexCopyFunction vertexLoadFunction;
bool vertexLoadRequiresConversion;
};
struct Format final : private angle::NonCopyable
{
Format();
......@@ -43,21 +58,11 @@ struct Format final : private angle::NonCopyable
void initialize(VkPhysicalDevice physicalDevice, const angle::Format &angleFormat);
void initTextureFallback(VkPhysicalDevice physicalDevice,
angle::FormatID format,
VkFormat vkFormat,
InitializeTextureDataFunction initializer,
angle::FormatID fallbackFormat,
VkFormat fallbackVkFormat,
InitializeTextureDataFunction fallbackInitializer);
const TextureFormatInitInfo *info,
int numInfo);
void initBufferFallback(VkPhysicalDevice physicalDevice,
angle::FormatID format,
VkFormat vkFormat,
VertexCopyFunction function,
bool functionConverts,
angle::FormatID fallbackFormat,
VkFormat fallbackVkFormat,
VertexCopyFunction fallbackFunction);
const BufferFormatInitInfo *info,
int numInfo);
const angle::Format &textureFormat() const;
const angle::Format &bufferFormat() const;
......
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