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 @@ ...@@ -66,7 +66,7 @@
"Vulkan format:src/libANGLE/renderer/angle_format_map.json": "Vulkan format:src/libANGLE/renderer/angle_format_map.json":
"ea6dfe3ebbc86e04f0d4b9f568ba22ae", "ea6dfe3ebbc86e04f0d4b9f568ba22ae",
"Vulkan format:src/libANGLE/renderer/vulkan/gen_vk_format_table.py": "Vulkan format:src/libANGLE/renderer/vulkan/gen_vk_format_table.py":
"4a69cb1e69194ca237b94642edbd3f69", "1d7d1b6a1f2b4b6f5080197c56b908b4",
"Vulkan format:src/libANGLE/renderer/vulkan/vk_format_map.json": "Vulkan format:src/libANGLE/renderer/vulkan/vk_format_map.json":
"f7cb189ab41f1ce48ff26e7c328c5cd0", "f7cb189ab41f1ce48ff26e7c328c5cd0",
"Vulkan internal shader programs:src/libANGLE/renderer/vulkan/gen_vk_internal_shaders.py": "Vulkan internal shader programs:src/libANGLE/renderer/vulkan/gen_vk_internal_shaders.py":
...@@ -82,7 +82,7 @@ ...@@ -82,7 +82,7 @@
"Vulkan mandatory format support table:src/libANGLE/renderer/vulkan/vk_mandatory_format_support_data.json": "Vulkan mandatory format support table:src/libANGLE/renderer/vulkan/vk_mandatory_format_support_data.json":
"fa2bd54c1bb0ab2cf1d386061a4bc5c5", "fa2bd54c1bb0ab2cf1d386061a4bc5c5",
"Vulkan mandatory format support table:third_party/vulkan-headers/src/registry/vk.xml": "Vulkan mandatory format support table:third_party/vulkan-headers/src/registry/vk.xml":
"c73903f9411b54db01d4891bc24ebd0e", "de9fb16e43de8ab4b69f673c2ca03704",
"packed enum:src/common/gen_packed_gl_enums.py": "packed enum:src/common/gen_packed_gl_enums.py":
"a9b1c38b4e4d8a1038e743be323f1a51", "a9b1c38b4e4d8a1038e743be323f1a51",
"packed enum:src/common/packed_egl_enums.json": "packed enum:src/common/packed_egl_enums.json":
...@@ -92,7 +92,7 @@ ...@@ -92,7 +92,7 @@
"proc table:src/libGLESv2/gen_proc_table.py": "proc table:src/libGLESv2/gen_proc_table.py":
"027bfd5a8a8dffe91f492bf199029cde", "027bfd5a8a8dffe91f492bf199029cde",
"proc table:src/libGLESv2/proc_table_data.json": "proc table:src/libGLESv2/proc_table_data.json":
"2c452ae503df669222e85961ab75fb22", "77dd1356708c3c8014bb22f890db6e08",
"uniform type:src/common/gen_uniform_type_table.py": "uniform type:src/common/gen_uniform_type_table.py":
"59cb4ffd0f584c4bd37f2f4ff59a2b93" "59cb4ffd0f584c4bd37f2f4ff59a2b93"
} }
\ No newline at end of file
...@@ -69,79 +69,82 @@ internalFormat = {internal_format}; ...@@ -69,79 +69,82 @@ internalFormat = {internal_format};
break; break;
""" """
texture_basic_template = """textureFormatID = angle::FormatID::{texture}; texture_basic_template = """textureFormatID = {texture};
vkTextureFormat = {vk_texture_format}; vkTextureFormat = {vk_texture_format};
textureInitializerFunction = {texture_initializer};""" 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, buffer_basic_template = """bufferFormatID = {buffer};
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};
vkBufferFormat = {vk_buffer_format}; vkBufferFormat = {vk_buffer_format};
vertexLoadFunction = {vertex_load_function}; vertexLoadFunction = {vertex_load_function};
vertexLoadRequiresConversion = {vertex_load_converts};""" vertexLoadRequiresConversion = {vertex_load_converts};"""
buffer_struct_template="""{{{buffer}, {vk_buffer_format}, {vertex_load_function},
buffer_fallback_template = """initBufferFallback(physicalDevice, {vertex_load_converts}}}"""
angle::FormatID::{buffer}, buffer_fallback_template = """{{
{vk_buffer_format}, static constexpr BufferFormatInitInfo kInfo[] = {{{buffer_list}}};
{vertex_load_function}, initBufferFallback(physicalDevice, kInfo, ArraySize(kInfo));
{vertex_load_converts}, }}"""
angle::FormatID::{buffer_fallback},
{vk_buffer_format_fallback},
{vertex_load_function_fallback});"""
def gen_format_case(angle, internal_format, vk_json_data): def gen_format_case(angle, internal_format, vk_json_data):
vk_map = vk_json_data["map"] vk_map = vk_json_data["map"]
vk_overrides = vk_json_data["overrides"] vk_overrides = vk_json_data["overrides"]
vk_fallbacks = vk_json_data["fallbacks"] 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 if ((angle not in vk_map) and (angle not in vk_overrides) and
(angle not in vk_fallbacks)) or angle == 'NONE': (angle not in vk_fallbacks)) or angle == 'NONE':
return empty_format_entry_template.format(**args) 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) format = vk_overrides.get(format, {}).get(type, format)
fallback = vk_fallbacks.get(format, {}).get(type, "NONE")
if format not in vk_map: if format not in vk_map:
format = "NONE" return []
template = "" fallbacks = vk_fallbacks.get(format, {}).get(type, [])
elif fallback == "NONE": if not isinstance(fallbacks, list):
template = basic_template fallbacks = [fallbacks]
else: return [format] + fallbacks
template = fallback_template
return format, fallback, template def texture_args(format):
return dict(
texture_format, texture_fallback, texture_template = get_formats_and_template( texture="angle::FormatID::" + format,
angle, "texture", texture_basic_template, texture_fallback_template) vk_texture_format=vk_map[format],
buffer_format, buffer_fallback, buffer_template = get_formats_and_template( texture_initializer=angle_format.get_internal_format_initializer(internal_format,
angle, "buffer", buffer_basic_template, buffer_fallback_template) format)
)
args.update(
internal_format=internal_format, def buffer_args(format):
texture_template=texture_template, return dict(
texture=texture_format, buffer="angle::FormatID::" + format,
vk_texture_format=vk_map[texture_format], vk_buffer_format=vk_map[format],
texture_initializer=angle_format.get_internal_format_initializer(internal_format, vertex_load_function=angle_format.get_vertex_copy_function(angle, format),
texture_format), vertex_load_converts='false' if angle == format else 'true',
texture_fallback=texture_fallback, )
vk_texture_format_fallback=vk_map[texture_fallback],
texture_initializer_fallback=angle_format.get_internal_format_initializer(internal_format, textures = get_formats(angle, "texture")
texture_fallback), if len(textures) == 1:
buffer_template=buffer_template, args.update(texture_template=texture_basic_template)
buffer=buffer_format, args.update(texture_args(textures[0]))
vk_buffer_format=vk_map[buffer_format], elif len(textures) > 1:
vertex_load_function=angle_format.get_vertex_copy_function(angle, buffer_format), args.update(
vertex_load_converts='false' if angle == buffer_format else 'true', texture_template=texture_fallback_template,
buffer_fallback=buffer_fallback, texture_list=", ".join(texture_struct_template.format(**texture_args(i))
vk_buffer_format_fallback=vk_map[buffer_fallback], for i in textures)
vertex_load_function_fallback=angle_format.get_vertex_copy_function(angle, buffer_fallback), )
)
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) return format_entry_template.format(**args).format(**args)
......
...@@ -63,6 +63,30 @@ bool HasFullBufferFormatSupport(VkPhysicalDevice physicalDevice, VkFormat vkForm ...@@ -63,6 +63,30 @@ bool HasFullBufferFormatSupport(VkPhysicalDevice physicalDevice, VkFormat vkForm
return formatProperties.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT; 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 } // anonymous namespace
namespace vk namespace vk
...@@ -105,58 +129,24 @@ Format::Format() ...@@ -105,58 +129,24 @@ Format::Format()
} }
void Format::initTextureFallback(VkPhysicalDevice physicalDevice, void Format::initTextureFallback(VkPhysicalDevice physicalDevice,
angle::FormatID format, const TextureFormatInitInfo *info,
VkFormat vkFormat, int numInfo)
InitializeTextureDataFunction initializer,
angle::FormatID fallbackFormat,
VkFormat fallbackVkFormat,
InitializeTextureDataFunction fallbackInitializer)
{ {
ASSERT(format != angle::FormatID::NONE); int i = FindSupportedFormat(physicalDevice, info, numInfo, HasFullTextureFormatSupport);
ASSERT(fallbackFormat != angle::FormatID::NONE); textureFormatID = info[i].format;
vkTextureFormat = info[i].vkFormat;
if (HasFullTextureFormatSupport(physicalDevice, vkFormat)) textureInitializerFunction = info[i].initializer;
{
textureFormatID = format;
vkTextureFormat = vkFormat;
textureInitializerFunction = initializer;
}
else
{
textureFormatID = fallbackFormat;
vkTextureFormat = fallbackVkFormat;
textureInitializerFunction = fallbackInitializer;
ASSERT(HasFullTextureFormatSupport(physicalDevice, vkTextureFormat));
}
} }
void Format::initBufferFallback(VkPhysicalDevice physicalDevice, void Format::initBufferFallback(VkPhysicalDevice physicalDevice,
angle::FormatID format, const BufferFormatInitInfo *info,
VkFormat vkFormat, int numInfo)
VertexCopyFunction function, {
bool functionConverts, int i = FindSupportedFormat(physicalDevice, info, numInfo, HasFullBufferFormatSupport);
angle::FormatID fallbackFormat, bufferFormatID = info[i].format;
VkFormat fallbackVkFormat, vkBufferFormat = info[i].vkFormat;
VertexCopyFunction fallbackFunction) vertexLoadFunction = info[i].vertexLoadFunction;
{ vertexLoadRequiresConversion = info[i].vertexLoadRequiresConversion;
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 angle::Format &Format::textureFormat() const const angle::Format &Format::textureFormat() const
......
...@@ -33,6 +33,21 @@ void GetFormatProperties(VkPhysicalDevice physicalDevice, ...@@ -33,6 +33,21 @@ void GetFormatProperties(VkPhysicalDevice physicalDevice,
VkFormat vkFormat, VkFormat vkFormat,
VkFormatProperties *propertiesOut); 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 struct Format final : private angle::NonCopyable
{ {
Format(); Format();
...@@ -43,21 +58,11 @@ struct Format final : private angle::NonCopyable ...@@ -43,21 +58,11 @@ struct Format final : private angle::NonCopyable
void initialize(VkPhysicalDevice physicalDevice, const angle::Format &angleFormat); void initialize(VkPhysicalDevice physicalDevice, const angle::Format &angleFormat);
void initTextureFallback(VkPhysicalDevice physicalDevice, void initTextureFallback(VkPhysicalDevice physicalDevice,
angle::FormatID format, const TextureFormatInitInfo *info,
VkFormat vkFormat, int numInfo);
InitializeTextureDataFunction initializer,
angle::FormatID fallbackFormat,
VkFormat fallbackVkFormat,
InitializeTextureDataFunction fallbackInitializer);
void initBufferFallback(VkPhysicalDevice physicalDevice, void initBufferFallback(VkPhysicalDevice physicalDevice,
angle::FormatID format, const BufferFormatInitInfo *info,
VkFormat vkFormat, int numInfo);
VertexCopyFunction function,
bool functionConverts,
angle::FormatID fallbackFormat,
VkFormat fallbackVkFormat,
VertexCopyFunction fallbackFunction);
const angle::Format &textureFormat() const; const angle::Format &textureFormat() const;
const angle::Format &bufferFormat() 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