Commit cb2b5136 by Courtney Goeltzenleuchter Committed by Commit Bot

Vulkan: Simplify format table generation

Remove the "override" table. That gets in the way of some solutions. If a format cannot be supported by a native Vulkan format as indicated in the "map" table, then check fallbacks. Also add support for native RGBA4 and R5G5B5A1 support. Previously those formats would be emulated with RGBA8 due to the override, but now code will check if the native format is available and use it. Bug: angleproject:4282 Change-Id: Ib33ea40543d91a2c2a95075b277f825a8822037c Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1994538Reviewed-by: 's avatarTobin Ehlis <tobine@google.com> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Courtney Goeltzenleuchter <courtneygo@google.com>
parent f1f082e1
......@@ -4,7 +4,7 @@
"src/libANGLE/renderer/gen_load_functions_table.py":
"9b4ea6bcb4eb4c43f48a097a9ec920f1",
"src/libANGLE/renderer/load_functions_data.json":
"e3e6e908bdaa6e125c9a48069446eb84",
"9c4f8ff5ef6cab7b22fe76bce643fadd",
"src/libANGLE/renderer/load_functions_table_autogen.cpp":
"ee0793c71b3fdc14b40d6ccc4295d2a5"
"2cccad635bba34a8e2ee7ef26c13649f"
}
\ No newline at end of file
......@@ -4,9 +4,9 @@
"src/libANGLE/renderer/angle_format_map.json":
"bca5e686001f6dd0af306af234a36677",
"src/libANGLE/renderer/vulkan/gen_vk_format_table.py":
"7c0c4f309f9d4864651510efb4c948cf",
"d8a0f2278c09a49049a73930b9da3719",
"src/libANGLE/renderer/vulkan/vk_format_map.json":
"00337a5ee252cf90a903dcb090f48ad8",
"70213e23a9a2246a69ba1b2eb8edb133",
"src/libANGLE/renderer/vulkan/vk_format_table_autogen.cpp":
"3f9f2ab5393d77a061e7dda701e9f015"
"5e03a1d5168224f9a54206239418d2f4"
}
\ No newline at end of file
......@@ -694,6 +694,37 @@ void LoadRGBA8ToBGRA4(size_t width,
}
}
void LoadRGBA8ToRGBA4(size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch)
{
for (size_t z = 0; z < depth; z++)
{
for (size_t y = 0; y < height; y++)
{
const uint32_t *source =
priv::OffsetDataPointer<uint32_t>(input, y, z, inputRowPitch, inputDepthPitch);
uint16_t *dest =
priv::OffsetDataPointer<uint16_t>(output, y, z, outputRowPitch, outputDepthPitch);
for (size_t x = 0; x < width; x++)
{
uint32_t rgba8 = source[x];
auto r4 = static_cast<uint16_t>((rgba8 & 0x000000FF) >> 4);
auto g4 = static_cast<uint16_t>((rgba8 & 0x0000FF00) >> 12);
auto b4 = static_cast<uint16_t>((rgba8 & 0x00FF0000) >> 20);
auto a4 = static_cast<uint16_t>((rgba8 & 0xFF000000) >> 28);
dest[x] = (r4 << 12) | (g4 << 8) | (b4 << 4) | a4;
}
}
}
}
void LoadRGBA4ToARGB4(size_t width,
size_t height,
size_t depth,
......@@ -853,6 +884,37 @@ void LoadRGBA8ToBGR5A1(size_t width,
}
}
void LoadRGBA8ToRGB5A1(size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch)
{
for (size_t z = 0; z < depth; z++)
{
for (size_t y = 0; y < height; y++)
{
const uint32_t *source =
priv::OffsetDataPointer<uint32_t>(input, y, z, inputRowPitch, inputDepthPitch);
uint16_t *dest =
priv::OffsetDataPointer<uint16_t>(output, y, z, outputRowPitch, outputDepthPitch);
for (size_t x = 0; x < width; x++)
{
uint32_t rgba8 = source[x];
auto r5 = static_cast<uint16_t>((rgba8 & 0x000000FF) >> 3);
auto g5 = static_cast<uint16_t>((rgba8 & 0x0000FF00) >> 11);
auto b5 = static_cast<uint16_t>((rgba8 & 0x00FF0000) >> 19);
auto a1 = static_cast<uint16_t>((rgba8 & 0xFF000000) >> 31);
dest[x] = (r5 << 11) | (g5 << 6) | (b5 << 1) | a1;
}
}
}
}
void LoadRGB10A2ToBGR5A1(size_t width,
size_t height,
size_t depth,
......@@ -886,6 +948,39 @@ void LoadRGB10A2ToBGR5A1(size_t width,
}
}
void LoadRGB10A2ToRGB5A1(size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch)
{
for (size_t z = 0; z < depth; z++)
{
for (size_t y = 0; y < height; y++)
{
const R10G10B10A2 *source =
priv::OffsetDataPointer<R10G10B10A2>(input, y, z, inputRowPitch, inputDepthPitch);
uint16_t *dest =
priv::OffsetDataPointer<uint16_t>(output, y, z, outputRowPitch, outputDepthPitch);
for (size_t x = 0; x < width; x++)
{
R10G10B10A2 rgb10a2 = source[x];
uint16_t r5 = static_cast<uint16_t>(rgb10a2.R >> 5u);
uint16_t g5 = static_cast<uint16_t>(rgb10a2.G >> 5u);
uint16_t b5 = static_cast<uint16_t>(rgb10a2.B >> 5u);
uint16_t a1 = static_cast<uint16_t>(rgb10a2.A >> 1u);
dest[x] = (r5 << 11) | (g5 << 6) | (b5 << 1) | a1;
}
}
}
}
void LoadRGB5A1ToA1RGB5(size_t width,
size_t height,
size_t depth,
......@@ -912,6 +1007,37 @@ void LoadRGB5A1ToA1RGB5(size_t width,
}
}
void LoadRGB5A1ToBGR5A1(size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch)
{
for (size_t z = 0; z < depth; z++)
{
for (size_t y = 0; y < height; y++)
{
const uint16_t *source =
priv::OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
uint16_t *dest =
priv::OffsetDataPointer<uint16_t>(output, y, z, outputRowPitch, outputDepthPitch);
for (size_t x = 0; x < width; x++)
{
uint16_t rgba = source[x];
auto r5 = static_cast<uint16_t>((rgba & 0xF800) >> 11);
auto g5 = static_cast<uint16_t>((rgba & 0x07c0) >> 6);
auto b5 = static_cast<uint16_t>((rgba & 0x003e) >> 1);
auto a1 = static_cast<uint16_t>((rgba & 0x0001));
dest[x] = (b5 << 11) | (g5 << 6) | (r5 << 1) | a1;
}
}
}
}
void LoadRGB5A1ToBGRA8(size_t width,
size_t height,
size_t depth,
......
......@@ -225,6 +225,16 @@ void LoadRGBA8ToBGRA4(size_t width,
size_t outputRowPitch,
size_t outputDepthPitch);
void LoadRGBA8ToRGBA4(size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch);
void LoadRGBA4ToARGB4(size_t width,
size_t height,
size_t depth,
......@@ -235,6 +245,16 @@ void LoadRGBA4ToARGB4(size_t width,
size_t outputRowPitch,
size_t outputDepthPitch);
void LoadRGBA4ToRGBA4(size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch);
void LoadRGBA4ToBGRA8(size_t width,
size_t height,
size_t depth,
......@@ -275,6 +295,16 @@ void LoadRGBA8ToBGR5A1(size_t width,
size_t outputRowPitch,
size_t outputDepthPitch);
void LoadRGBA8ToRGB5A1(size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch);
void LoadRGB10A2ToBGR5A1(size_t width,
size_t height,
size_t depth,
......@@ -285,6 +315,36 @@ void LoadRGB10A2ToBGR5A1(size_t width,
size_t outputRowPitch,
size_t outputDepthPitch);
void LoadRGB10A2ToRGB5A1(size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch);
void LoadRGB5A1ToRGB5A1(size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch);
void LoadRGB5A1ToBGR5A1(size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch);
void LoadRGB5A1ToA1RGB5(size_t width,
size_t height,
size_t depth,
......
......@@ -7,6 +7,9 @@
"GL_SRGB8": {
"R8G8B8A8_UNORM_SRGB": {
"GL_UNSIGNED_BYTE": "LoadToNative3To4<GLubyte, 0xFF>"
},
"R8G8B8_UNORM_SRGB": {
"GL_UNSIGNED_BYTE": "LoadToNative<GLbyte, 3>"
}
},
"GL_RGBA8I": {
......@@ -164,6 +167,11 @@
"GL_UNSIGNED_INT_2_10_10_10_REV": "LoadRGB10A2ToBGR5A1",
"GL_UNSIGNED_BYTE": "LoadRGBA8ToBGR5A1",
"GL_UNSIGNED_SHORT_5_5_5_1": "LoadRGB5A1ToA1RGB5"
},
"R5G5B5A1_UNORM": {
"GL_UNSIGNED_INT_2_10_10_10_REV": "LoadRGB10A2ToRGB5A1",
"GL_UNSIGNED_BYTE": "LoadRGBA8ToRGB5A1",
"GL_UNSIGNED_SHORT_5_5_5_1": "LoadToNative<GLushort, 1>"
}
},
"GL_RGB16UI": {
......@@ -269,6 +277,9 @@
"GL_RGB8": {
"R8G8B8A8_UNORM": {
"GL_UNSIGNED_BYTE": "LoadToNative3To4<GLubyte, 0xFF>"
},
"R8G8B8_UNORM": {
"GL_UNSIGNED_BYTE": "LoadToNative<GLbyte, 3>"
}
},
"GL_LUMINANCE_ALPHA": {
......@@ -734,6 +745,10 @@
"B4G4R4A4_UNORM": {
"GL_UNSIGNED_BYTE": "LoadRGBA8ToBGRA4",
"GL_UNSIGNED_SHORT_4_4_4_4": "LoadRGBA4ToARGB4"
},
"R4G4B4A4_UNORM": {
"GL_UNSIGNED_BYTE": "LoadRGBA8ToRGBA4",
"GL_UNSIGNED_SHORT_4_4_4_4": "LoadToNative<GLushort, 1>"
}
},
"GL_RGBA8": {
......
......@@ -2582,6 +2582,22 @@ LoadImageFunctionInfo RGB5_A1_to_B5G5R5A1_UNORM(GLenum type)
}
}
LoadImageFunctionInfo RGB5_A1_to_R5G5B5A1_UNORM(GLenum type)
{
switch (type)
{
case GL_UNSIGNED_BYTE:
return LoadImageFunctionInfo(LoadRGBA8ToRGB5A1, true);
case GL_UNSIGNED_INT_2_10_10_10_REV:
return LoadImageFunctionInfo(LoadRGB10A2ToRGB5A1, true);
case GL_UNSIGNED_SHORT_5_5_5_1:
return LoadImageFunctionInfo(LoadToNative<GLushort, 1>, false);
default:
UNREACHABLE();
return LoadImageFunctionInfo(UnreachableLoadFunction, true);
}
}
LoadImageFunctionInfo RGB5_A1_to_R8G8B8A8_UNORM(GLenum type)
{
switch (type)
......@@ -2610,6 +2626,18 @@ LoadImageFunctionInfo RGB8_to_R8G8B8A8_UNORM(GLenum type)
}
}
LoadImageFunctionInfo RGB8_to_R8G8B8_UNORM(GLenum type)
{
switch (type)
{
case GL_UNSIGNED_BYTE:
return LoadImageFunctionInfo(LoadToNative<GLbyte, 3>, false);
default:
UNREACHABLE();
return LoadImageFunctionInfo(UnreachableLoadFunction, true);
}
}
LoadImageFunctionInfo RGB8I_to_R8G8B8A8_SINT(GLenum type)
{
switch (type)
......@@ -2878,6 +2906,20 @@ LoadImageFunctionInfo RGBA4_to_B4G4R4A4_UNORM(GLenum type)
}
}
LoadImageFunctionInfo RGBA4_to_R4G4B4A4_UNORM(GLenum type)
{
switch (type)
{
case GL_UNSIGNED_BYTE:
return LoadImageFunctionInfo(LoadRGBA8ToRGBA4, true);
case GL_UNSIGNED_SHORT_4_4_4_4:
return LoadImageFunctionInfo(LoadToNative<GLushort, 1>, false);
default:
UNREACHABLE();
return LoadImageFunctionInfo(UnreachableLoadFunction, true);
}
}
LoadImageFunctionInfo RGBA4_to_R8G8B8A8_UNORM(GLenum type)
{
switch (type)
......@@ -2976,6 +3018,18 @@ LoadImageFunctionInfo SRGB8_to_R8G8B8A8_UNORM_SRGB(GLenum type)
}
}
LoadImageFunctionInfo SRGB8_to_R8G8B8_UNORM_SRGB(GLenum type)
{
switch (type)
{
case GL_UNSIGNED_BYTE:
return LoadImageFunctionInfo(LoadToNative<GLbyte, 3>, false);
default:
UNREACHABLE();
return LoadImageFunctionInfo(UnreachableLoadFunction, true);
}
}
LoadImageFunctionInfo SRGB8_ALPHA8_to_R8G8B8A8_UNORM_SRGB(GLenum type)
{
switch (type)
......@@ -4080,6 +4134,8 @@ LoadFunctionMap GetLoadFunctionsMap(GLenum internalFormat, FormatID angleFormat)
return RGB5_A1_to_A1R5G5B5_UNORM;
case FormatID::B5G5R5A1_UNORM:
return RGB5_A1_to_B5G5R5A1_UNORM;
case FormatID::R5G5B5A1_UNORM:
return RGB5_A1_to_R5G5B5A1_UNORM;
case FormatID::R8G8B8A8_UNORM:
return RGB5_A1_to_R8G8B8A8_UNORM;
default:
......@@ -4093,6 +4149,8 @@ LoadFunctionMap GetLoadFunctionsMap(GLenum internalFormat, FormatID angleFormat)
{
case FormatID::R8G8B8A8_UNORM:
return RGB8_to_R8G8B8A8_UNORM;
case FormatID::R8G8B8_UNORM:
return RGB8_to_R8G8B8_UNORM;
default:
break;
}
......@@ -4252,6 +4310,8 @@ LoadFunctionMap GetLoadFunctionsMap(GLenum internalFormat, FormatID angleFormat)
{
case FormatID::B4G4R4A4_UNORM:
return RGBA4_to_B4G4R4A4_UNORM;
case FormatID::R4G4B4A4_UNORM:
return RGBA4_to_R4G4B4A4_UNORM;
case FormatID::R8G8B8A8_UNORM:
return RGBA4_to_R8G8B8A8_UNORM;
default:
......@@ -4313,6 +4373,8 @@ LoadFunctionMap GetLoadFunctionsMap(GLenum internalFormat, FormatID angleFormat)
{
case FormatID::R8G8B8A8_UNORM_SRGB:
return SRGB8_to_R8G8B8A8_UNORM_SRGB;
case FormatID::R8G8B8_UNORM_SRGB:
return SRGB8_to_R8G8B8_UNORM_SRGB;
default:
break;
}
......
......@@ -106,7 +106,7 @@ def verify_vk_map_keys(angle_to_gl, vk_json_data):
entry in the Vulkan file is incorrect and needs to be fixed."""
no_error = True
for table in ["map", "overrides", "fallbacks"]:
for table in ["map", "fallbacks"]:
for angle_format in vk_json_data[table].keys():
if not angle_format in angle_to_gl.keys():
print "Invalid format " + angle_format + " in vk_format_map.json in " + table
......@@ -140,13 +140,11 @@ def get_vertex_copy_function(src_format, dst_format, vk_format):
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 = dict(
format_id=angle, internal_format=internal_format, image_template="", buffer_template="")
if ((angle not in vk_map) and (angle not in vk_overrides) and
(angle not in vk_fallbacks)) or angle == 'NONE':
if ((angle not in vk_map) and (angle not in vk_fallbacks)) or angle == 'NONE':
return empty_format_entry_template.format(**args)
# get_formats returns override format (if any) + fallbacks
......@@ -154,7 +152,6 @@ def gen_format_case(angle, internal_format, vk_json_data):
# us to fallback to D32_FLOAT, so now we leave the image override empty and function will
# give us the fallbacks.
def get_formats(format, type):
format = vk_overrides.get(format, {}).get(type, format)
fallbacks = vk_fallbacks.get(format, {}).get(type, [])
if not isinstance(fallbacks, list):
fallbacks = [fallbacks]
......
......@@ -10,17 +10,12 @@
"ANGLE format ID, and the value is the Vulkan format enum. Note some formats",
"are missing from the map, these formats are either unsupported or emulated",
"on Vulkan. The map matches GL formats to identical Vulkan formats; missing",
"formats use the overrides table for emulation.",
"formats use the fallback table for emulation.",
"",
"We implement formats that aren't natively supported in Vulkan using",
"fallback and override formats. These are specified as dictionaries (also keyed on",
"fallback formats. These are specified as dictionaries (also keyed on",
"the angle format ID), with two optional entries for Buffer and Image",
"formats. Each entry specifies a fallback or override format.",
"",
"Override formats are used for emulated support for formats we assume are never",
"supported by any Vulkan device, although they might exist. Fallback formats",
"differ in that they are tested at runtime for support, and we only fall back",
"if the main format is not available on this device.",
"formats. Each entry specifies a fallback format.",
"",
"Also see gen_vk_format_table.py for the code generation step."
],
......@@ -165,7 +160,7 @@
"ASTC_12x12_UNORM_BLOCK": "VK_FORMAT_ASTC_12x12_UNORM_BLOCK",
"ASTC_12x12_SRGB_BLOCK": "VK_FORMAT_ASTC_12x12_SRGB_BLOCK"
},
"overrides": {
"fallbacks": {
"A16_FLOAT": {
"image": "R16_FLOAT"
},
......@@ -200,7 +195,8 @@
"image": "A1R5G5B5_UNORM"
},
"R8G8B8_UNORM": {
"image": "R8G8B8A8_UNORM"
"image": "R8G8B8A8_UNORM",
"buffer": "R32G32B32_FLOAT"
},
"R8G8B8_UNORM_SRGB": {
"image": "R8G8B8A8_UNORM_SRGB"
......@@ -211,14 +207,15 @@
},
"D24_UNORM_X8_UINT": {
"buffer": "NONE",
"image": "D24_UNORM_S8_UINT"
"image": ["D24_UNORM_S8_UINT", "D32_FLOAT_S8X24_UINT"]
},
"D32_UNORM": {
"buffer": "NONE"
"buffer": "NONE",
"image": ["D24_UNORM_S8_UINT", "D32_FLOAT"]
},
"ETC1_R8G8B8_UNORM_BLOCK": {
"buffer": "NONE",
"image": "ETC2_R8G8B8_UNORM_BLOCK"
"image": ["ETC2_R8G8B8_UNORM_BLOCK", "R8G8B8A8_UNORM"]
},
"R32_FIXED": {
"buffer": "R32_FLOAT"
......@@ -331,11 +328,6 @@
"X2R10G10B10_UNORM_VERTEX": {
"image": "NONE",
"buffer": "R32G32B32A32_FLOAT"
}
},
"fallbacks": {
"D32_UNORM": {
"image": ["D24_UNORM_S8_UINT", "D32_FLOAT"]
},
"D32_FLOAT_S8X24_UINT": {
"image": ["D24_UNORM_S8_UINT", "D32_FLOAT_S8X24_UINT"]
......@@ -343,9 +335,6 @@
"D24_UNORM_S8_UINT": {
"image": ["D32_FLOAT_S8X24_UINT", "D24_UNORM_S8_UINT"]
},
"D24_UNORM_X8_UINT": {
"image": ["D32_FLOAT_S8X24_UINT", "D24_UNORM_S8_UINT"]
},
"S8_UINT": {
"image": ["D24_UNORM_S8_UINT", "D32_FLOAT_S8X24_UINT", "S8_UINT"]
},
......@@ -374,9 +363,6 @@
"R8G8_SSCALED": {
"buffer": "R32G32_FLOAT"
},
"R8G8B8_UNORM": {
"buffer": "R32G32B32_FLOAT"
},
"R8G8B8_SNORM": {
"image": "R8G8B8A8_SNORM",
"buffer": "R32G32B32_FLOAT"
......
......@@ -807,8 +807,7 @@ void Format::initialize(RendererVk *renderer, const angle::Format &angleFormat)
{
static constexpr ImageFormatInitInfo kInfo[] = {
{angle::FormatID::D24_UNORM_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT, nullptr},
{angle::FormatID::D32_FLOAT_S8X24_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT, nullptr},
{angle::FormatID::D24_UNORM_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT, nullptr}};
{angle::FormatID::D32_FLOAT_S8X24_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT, nullptr}};
initImageFallback(renderer, kInfo, ArraySize(kInfo));
}
actualBufferFormatID = angle::FormatID::NONE;
......@@ -2008,10 +2007,13 @@ void Format::initialize(RendererVk *renderer, const angle::Format &angleFormat)
break;
case angle::FormatID::R4G4B4A4_UNORM:
internalFormat = GL_RGBA4;
actualImageFormatID = angle::FormatID::R8G8B8A8_UNORM;
vkImageFormat = VK_FORMAT_R8G8B8A8_UNORM;
imageInitializerFunction = nullptr;
internalFormat = GL_RGBA4;
{
static constexpr ImageFormatInitInfo kInfo[] = {
{angle::FormatID::R4G4B4A4_UNORM, VK_FORMAT_R4G4B4A4_UNORM_PACK16, nullptr},
{angle::FormatID::R8G8B8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM, nullptr}};
initImageFallback(renderer, kInfo, ArraySize(kInfo));
}
actualBufferFormatID = angle::FormatID::R4G4B4A4_UNORM;
vkBufferFormat = VK_FORMAT_R4G4B4A4_UNORM_PACK16;
vkBufferFormatIsPacked = true;
......@@ -2020,10 +2022,13 @@ void Format::initialize(RendererVk *renderer, const angle::Format &angleFormat)
break;
case angle::FormatID::R5G5B5A1_UNORM:
internalFormat = GL_RGB5_A1;
actualImageFormatID = angle::FormatID::A1R5G5B5_UNORM;
vkImageFormat = VK_FORMAT_A1R5G5B5_UNORM_PACK16;
imageInitializerFunction = nullptr;
internalFormat = GL_RGB5_A1;
{
static constexpr ImageFormatInitInfo kInfo[] = {
{angle::FormatID::R5G5B5A1_UNORM, VK_FORMAT_R5G5B5A1_UNORM_PACK16, nullptr},
{angle::FormatID::A1R5G5B5_UNORM, VK_FORMAT_A1R5G5B5_UNORM_PACK16, nullptr}};
initImageFallback(renderer, kInfo, ArraySize(kInfo));
}
actualBufferFormatID = angle::FormatID::R5G5B5A1_UNORM;
vkBufferFormat = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
vkBufferFormatIsPacked = true;
......@@ -2220,10 +2225,14 @@ void Format::initialize(RendererVk *renderer, const angle::Format &angleFormat)
break;
case angle::FormatID::R8G8B8_UNORM:
internalFormat = GL_RGB8;
actualImageFormatID = angle::FormatID::R8G8B8A8_UNORM;
vkImageFormat = VK_FORMAT_R8G8B8A8_UNORM;
imageInitializerFunction = Initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0xFF>;
internalFormat = GL_RGB8;
{
static constexpr ImageFormatInitInfo kInfo[] = {
{angle::FormatID::R8G8B8_UNORM, VK_FORMAT_R8G8B8_UNORM, nullptr},
{angle::FormatID::R8G8B8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM,
Initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0xFF>}};
initImageFallback(renderer, kInfo, ArraySize(kInfo));
}
{
static constexpr BufferFormatInitInfo kInfo[] = {
{angle::FormatID::R8G8B8_UNORM, VK_FORMAT_R8G8B8_UNORM, false,
......@@ -2235,14 +2244,18 @@ void Format::initialize(RendererVk *renderer, const angle::Format &angleFormat)
break;
case angle::FormatID::R8G8B8_UNORM_SRGB:
internalFormat = GL_SRGB8;
actualImageFormatID = angle::FormatID::R8G8B8A8_UNORM_SRGB;
vkImageFormat = VK_FORMAT_R8G8B8A8_SRGB;
imageInitializerFunction = Initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0xFF>;
actualBufferFormatID = angle::FormatID::R8G8B8_UNORM_SRGB;
vkBufferFormat = VK_FORMAT_R8G8B8_SRGB;
vkBufferFormatIsPacked = false;
vertexLoadFunction = CopyNativeVertexData<GLubyte, 3, 3, 0>;
internalFormat = GL_SRGB8;
{
static constexpr ImageFormatInitInfo kInfo[] = {
{angle::FormatID::R8G8B8_UNORM_SRGB, VK_FORMAT_R8G8B8_SRGB, nullptr},
{angle::FormatID::R8G8B8A8_UNORM_SRGB, VK_FORMAT_R8G8B8A8_SRGB,
Initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0xFF>}};
initImageFallback(renderer, kInfo, ArraySize(kInfo));
}
actualBufferFormatID = angle::FormatID::R8G8B8_UNORM_SRGB;
vkBufferFormat = VK_FORMAT_R8G8B8_SRGB;
vkBufferFormatIsPacked = false;
vertexLoadFunction = CopyNativeVertexData<GLubyte, 3, 3, 0>;
vertexLoadRequiresConversion = false;
break;
......
......@@ -72,20 +72,26 @@ using SupportTest = bool (*)(RendererVk *renderer, VkFormat vkFormat);
template <class FormatInitInfo>
int FindSupportedFormat(RendererVk *renderer,
const FormatInitInfo *info,
size_t skip,
int numInfo,
SupportTest hasSupport)
{
ASSERT(numInfo > 0);
const int last = numInfo - 1;
for (int i = 0; i < last; ++i)
for (int i = static_cast<int>(skip); i < last; ++i)
{
ASSERT(info[i].format != angle::FormatID::NONE);
if (hasSupport(renderer, info[i].vkFormat))
return i;
}
// List must contain a supported item. We failed on all the others so the last one must be it.
if (skip > 0 && !hasSupport(renderer, info[last].vkFormat))
{
// We couldn't find a valid fallback, try again without skip
return FindSupportedFormat(renderer, info, 0, numInfo, hasSupport);
}
ASSERT(info[last].format != angle::FormatID::NONE);
ASSERT(hasSupport(renderer, info[last].vkFormat));
return last;
......@@ -132,9 +138,7 @@ void Format::initImageFallback(RendererVk *renderer, const ImageFormatInitInfo *
// Compressed textures also need to perform this check.
testFunction = HasNonRenderableTextureFormatSupport;
}
int i = FindSupportedFormat(renderer, info + skip, static_cast<uint32_t>(numInfo - skip),
testFunction);
i += skip;
int i = FindSupportedFormat(renderer, info, skip, static_cast<uint32_t>(numInfo), testFunction);
actualImageFormatID = info[i].format;
vkImageFormat = info[i].vkFormat;
......@@ -144,9 +148,8 @@ void Format::initImageFallback(RendererVk *renderer, const ImageFormatInitInfo *
void Format::initBufferFallback(RendererVk *renderer, const BufferFormatInitInfo *info, int numInfo)
{
size_t skip = renderer->getFeatures().forceFallbackFormat.enabled ? 1 : 0;
int i = FindSupportedFormat(renderer, info + skip, static_cast<uint32_t>(numInfo - skip),
int i = FindSupportedFormat(renderer, info, skip, static_cast<uint32_t>(numInfo),
HasFullBufferFormatSupport);
i += skip;
actualBufferFormatID = info[i].format;
vkBufferFormat = info[i].vkFormat;
......
......@@ -361,7 +361,7 @@ TEST_P(TextureUploadFormatTest, All)
(EncodeNormUint<4>(srcVals[2]) << 4) | (EncodeNormUint<4>(srcVals[3]) << 0))};
ZeroAndCopy(srcBuffer, src);
// fnTest({GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4}, {16,16,16,16});
fnTest({GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4}, {16, 16, 16, 16});
fnTest({GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4}, {16, 16, 16, 16});
}
......@@ -372,7 +372,6 @@ TEST_P(TextureUploadFormatTest, All)
(EncodeNormUint<5>(srcVals[2]) << 1) | (EncodeNormUint<1>(srcVals[3]) << 0))};
ZeroAndCopy(srcBuffer, src);
fnTest({GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1}, {8, 8, 8, 255});
fnTest({GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1}, {8, 8, 8, 255});
}
......
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