Commit 7b5fc46b by Jamie Madill

Vulkan: Add Vk format overrides table.

This generalizes the overriding mechanism in gen_Vk_format_table.py. Instead of defining overrides inline, we keep the vk_format_map as a 1:1 mapping from angle format to vk format, and use the overrides map to specify any additional emulation or features we need to support OpenGL textures on Vulkan. This will simplify the implementation for Depth/Stencil formats by making the generator script a bit easier to work with. No code changes, generator script refactor only. Bug: angleproject:2357 Change-Id: I7132d991795eb91d6ad838481c52545c891215bc Reviewed-on: https://chromium-review.googlesource.com/957433Reviewed-by: 's avatarFrank Henigman <fjhenigman@chromium.org>
parent 67ae6c58
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# found in the LICENSE file. # found in the LICENSE file.
# #
# gen_vk_format_table.py: # gen_vk_format_table.py:
# Code generation for vk format map # Code generation for vk format map. See vk_format_map.json for data source.
from datetime import date from datetime import date
import json import json
...@@ -65,65 +65,52 @@ empty_format_entry_template = """{space}case angle::Format::ID::{format_id}: ...@@ -65,65 +65,52 @@ empty_format_entry_template = """{space}case angle::Format::ID::{format_id}:
format_entry_template = """{space}case angle::Format::ID::{format_id}: format_entry_template = """{space}case angle::Format::ID::{format_id}:
{space}{{ {space}{{
{space} internalFormat = {internal_format}; {space} internalFormat = {internal_format};
{space} textureFormatID = angle::Format::ID::{texture_format_id}; {space} textureFormatID = angle::Format::ID::{texture};
{space} vkTextureFormat = {vk_texture_format}; {space} vkTextureFormat = {vk_texture_format};
{space} bufferFormatID = angle::Format::ID::{buffer_format_id}; {space} bufferFormatID = angle::Format::ID::{buffer};
{space} vkBufferFormat = {vk_buffer_format}; {space} vkBufferFormat = {vk_buffer_format};
{space} dataInitializerFunction = {initializer}; {space} dataInitializerFunction = {initializer};
{space} break; {space} break;
{space}}} {space}}}
""" """
def gen_format_case(angle, internal_format, vk_map): def gen_format_case(angle, internal_format, vk_map, vk_overrides):
if angle not in vk_map or angle == 'NONE': args = {
return empty_format_entry_template.format( "space": " ",
space = ' ', "format_id": angle,
format_id = angle) "internal_format": internal_format
}
texture_format_id = angle
buffer_format_id = angle if (angle not in vk_map and angle not in vk_overrides) or angle == 'NONE':
return empty_format_entry_template.format(**args)
vk_format_name = vk_map[angle]
vk_buffer_format = vk_format_name if angle in vk_map:
vk_texture_format = vk_format_name args["buffer"] = angle
args["texture"] = angle
if isinstance(vk_format_name, dict):
info = vk_format_name if angle in vk_overrides:
args.update(vk_overrides[angle])
if "buffer" in info:
buffer_format_id = info["buffer"] assert "buffer" in args, "Missing buffer format for " + angle
vk_buffer_format = vk_map[buffer_format_id] assert "texture" in args, "Missing texture format for " + angle
assert(not isinstance(vk_buffer_format, dict))
else: args["vk_buffer_format"] = vk_map[args["buffer"]]
vk_buffer_format = info["native"] args["vk_texture_format"] = vk_map[args["texture"]]
if "texture" in info: args["initializer"] = angle_format.get_internal_format_initializer(
texture_format_id = info["texture"] internal_format, args["texture"])
vk_texture_format = vk_map[texture_format_id]
assert(not isinstance(vk_texture_format, dict)) return format_entry_template.format(**args)
else:
vk_texture_format = info["native"]
initializer = angle_format.get_internal_format_initializer(
internal_format, texture_format_id)
return format_entry_template.format(
space = ' ',
internal_format = internal_format,
format_id = angle,
texture_format_id = texture_format_id,
buffer_format_id = buffer_format_id,
vk_buffer_format = vk_buffer_format,
vk_texture_format = vk_texture_format,
initializer = initializer)
input_file_name = 'vk_format_map.json' input_file_name = 'vk_format_map.json'
out_file_name = 'vk_format_table' out_file_name = 'vk_format_table'
angle_to_gl = angle_format.load_inverse_table(os.path.join('..', 'angle_format_map.json')) angle_to_gl = angle_format.load_inverse_table(os.path.join('..', 'angle_format_map.json'))
vk_map = angle_format.load_json(input_file_name) vk_json_data = angle_format.load_json(input_file_name)
vk_cases = [gen_format_case(angle, gl, vk_map) for angle, gl in sorted(angle_to_gl.iteritems())] vk_map = vk_json_data["map"]
vk_overrides = vk_json_data["overrides"]
vk_cases = [gen_format_case(angle, gl, vk_map, vk_overrides) for angle, gl in sorted(angle_to_gl.iteritems())]
output_cpp = template_table_autogen_cpp.format( output_cpp = template_table_autogen_cpp.format(
copyright_year = date.today().year, copyright_year = date.today().year,
......
{ {
"description": [
"Copyright 2018 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_map.json: Texture format mapping between OpenGL and Vulkan.",
"",
"The format of the map is a dictionary where the key of each entry is the",
"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.",
"",
"We implement formats that aren't natively supported in Vulkan using",
"overrides. The overrides are specified by a second dictionary (also keyed on",
"the angle format ID), with two optional entries for Buffer and Texture/Image",
"formats overrides. Each entry specifies a format.",
"",
"Also see gen_vk_format_table.py for the code generation step."
],
"map": {
"NONE": "VK_FORMAT_UNDEFINED", "NONE": "VK_FORMAT_UNDEFINED",
"R4G4B4A4_UNORM": "VK_FORMAT_R4G4B4A4_UNORM_PACK16", "R4G4B4A4_UNORM": "VK_FORMAT_R4G4B4A4_UNORM_PACK16",
"B4G4R4A4_UNORM": "VK_FORMAT_B4G4R4A4_UNORM_PACK16", "B4G4R4A4_UNORM": "VK_FORMAT_B4G4R4A4_UNORM_PACK16",
...@@ -17,10 +38,7 @@ ...@@ -17,10 +38,7 @@
"R8G8_UINT": "VK_FORMAT_R8G8_UINT", "R8G8_UINT": "VK_FORMAT_R8G8_UINT",
"R8G8_SINT": "VK_FORMAT_R8G8_SINT", "R8G8_SINT": "VK_FORMAT_R8G8_SINT",
"R8G8_SRGB": "VK_FORMAT_R8G8_SRGB", "R8G8_SRGB": "VK_FORMAT_R8G8_SRGB",
"R8G8B8_UNORM": { "R8G8B8_UNORM": "VK_FORMAT_R8G8B8_UNORM",
"native": "VK_FORMAT_R8G8B8_UNORM",
"texture": "R8G8B8A8_UNORM"
},
"R8G8B8_SNORM": "VK_FORMAT_R8G8B8_SNORM", "R8G8B8_SNORM": "VK_FORMAT_R8G8B8_SNORM",
"R8G8B8_UINT": "VK_FORMAT_R8G8B8_UINT", "R8G8B8_UINT": "VK_FORMAT_R8G8B8_UINT",
"R8G8B8_SINT": "VK_FORMAT_R8G8B8_SINT", "R8G8B8_SINT": "VK_FORMAT_R8G8B8_SINT",
...@@ -98,14 +116,6 @@ ...@@ -98,14 +116,6 @@
"R64G64B64A64_UINT": "VK_FORMAT_R64G64B64A64_UINT", "R64G64B64A64_UINT": "VK_FORMAT_R64G64B64A64_UINT",
"R64G64B64A64_SINT": "VK_FORMAT_R64G64B64A64_SINT", "R64G64B64A64_SINT": "VK_FORMAT_R64G64B64A64_SINT",
"R64G64B64A64_FLOAT": "VK_FORMAT_R64G64B64A64_SFLOAT", "R64G64B64A64_FLOAT": "VK_FORMAT_R64G64B64A64_SFLOAT",
"L8_UNORM": {
"buffer": "NONE",
"texture": "R8_UNORM"
},
"L8A8_UNORM": {
"buffer": "NONE",
"texture": "R8G8_UNORM"
},
"B10G11R11_UFLOAT_PACK32": "VK_FORMAT_B10G11R11_UFLOAT_PACK32", "B10G11R11_UFLOAT_PACK32": "VK_FORMAT_B10G11R11_UFLOAT_PACK32",
"E5B9G9R9_UFLOAT_PACK32": "VK_FORMAT_E5B9G9R9_UFLOAT_PACK32", "E5B9G9R9_UFLOAT_PACK32": "VK_FORMAT_E5B9G9R9_UFLOAT_PACK32",
"D16_UNORM": "VK_FORMAT_D16_UNORM", "D16_UNORM": "VK_FORMAT_D16_UNORM",
...@@ -169,4 +179,18 @@ ...@@ -169,4 +179,18 @@
"ASTC_12x10_SRGB_BLOCK": "VK_FORMAT_ASTC_12x10_SRGB_BLOCK", "ASTC_12x10_SRGB_BLOCK": "VK_FORMAT_ASTC_12x10_SRGB_BLOCK",
"ASTC_12x12_UNORM_BLOCK": "VK_FORMAT_ASTC_12x12_UNORM_BLOCK", "ASTC_12x12_UNORM_BLOCK": "VK_FORMAT_ASTC_12x12_UNORM_BLOCK",
"ASTC_12x12_SRGB_BLOC": "VK_FORMAT_ASTC_12x12_SRGB_BLOCK" "ASTC_12x12_SRGB_BLOC": "VK_FORMAT_ASTC_12x12_SRGB_BLOCK"
},
"overrides": {
"L8_UNORM": {
"buffer": "NONE",
"texture": "R8_UNORM"
},
"L8A8_UNORM": {
"buffer": "NONE",
"texture": "R8G8_UNORM"
},
"R8G8B8_UNORM": {
"texture": "R8G8B8A8_UNORM"
}
}
} }
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