Commit abaab233 by Jamie Madill Committed by Commit Bot

Vulkan: Introduce vk::Format.

BUG=angleproject:1319 Change-Id: I88bcc6caa5d29565728848bada1563e47e383b29 Reviewed-on: https://chromium-review.googlesource.com/367753Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 2f90a9b5
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
import json import json
import os import os
import re
def reject_duplicate_keys(pairs): def reject_duplicate_keys(pairs):
found_keys = {} found_keys = {}
...@@ -34,12 +35,136 @@ def load_inverse_table(path): ...@@ -34,12 +35,136 @@ def load_inverse_table(path):
reject_duplicate_keys(pairs) reject_duplicate_keys(pairs)
return { angle: gl for gl, angle in pairs } return { angle: gl for gl, angle in pairs }
def load_with_override(override_path): def load_without_override():
map_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'angle_format_map.json') map_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'angle_format_map.json')
results = load_forward_table(map_path) return load_forward_table(map_path)
def load_with_override(override_path):
results = load_without_override()
overrides = load_json(override_path) overrides = load_json(override_path)
for k, v in overrides.iteritems(): for k, v in overrides.iteritems():
results[k] = v results[k] = v
return results return results
def get_component_type(format_id):
if "SNORM" in format_id:
return "snorm"
elif "UNORM" in format_id:
return "unorm"
elif "FLOAT" in format_id:
return "float"
elif "UINT" in format_id:
return "uint"
elif "SINT" in format_id:
return "int"
elif format_id == "NONE":
return "none"
elif "SRGB" in format_id:
return "unorm"
elif format_id == "R9G9B9E5_SHAREDEXP":
return "float"
else:
raise ValueError("Unknown component type for " + format_id)
def get_channel_tokens(format_id):
r = re.compile(r'([ABDGLRS][\d]+)')
return filter(r.match, r.split(format_id))
def get_channels(format_id):
channels = ''
tokens = get_channel_tokens(format_id)
if len(tokens) == 0:
return None
for token in tokens:
channels += token[0].lower()
return channels
def get_bits(format_id):
bits = {}
tokens = get_channel_tokens(format_id)
if len(tokens) == 0:
return None
for token in tokens:
bits[token[0]] = int(token[1:])
return bits
def get_format_info(format_id):
return get_component_type(format_id), get_bits(format_id), get_channels(format_id)
# TODO(oetuaho): Expand this code so that it could generate the gl format info tables as well.
def gl_format_channels(internal_format):
if internal_format == 'GL_BGR5_A1_ANGLEX':
return 'bgra'
if internal_format == 'GL_R11F_G11F_B10F':
return 'rgb'
if internal_format == 'GL_RGB5_A1':
return 'rgba'
if internal_format.find('GL_RGB10_A2') == 0:
return 'rgba'
channels_pattern = re.compile('GL_(COMPRESSED_)?(SIGNED_)?(ETC\d_)?([A-Z]+)')
match = re.search(channels_pattern, internal_format)
channels_string = match.group(4)
if channels_string == 'ALPHA':
return 'a'
if channels_string == 'LUMINANCE':
if (internal_format.find('ALPHA') >= 0):
return 'la'
return 'l'
if channels_string == 'SRGB':
if (internal_format.find('ALPHA') >= 0):
return 'rgba'
return 'rgb'
if channels_string == 'DEPTH':
if (internal_format.find('STENCIL') >= 0):
return 'ds'
return 'd'
if channels_string == 'STENCIL':
return 's'
return channels_string.lower()
def get_internal_format_initializer(internal_format, format_id):
gl_channels = gl_format_channels(internal_format)
gl_format_no_alpha = gl_channels == 'rgb' or gl_channels == 'l'
component_type, bits, channels = get_format_info(format_id)
if not gl_format_no_alpha or channels != 'rgba':
return 'nullptr'
elif 'BC1_' in format_id:
# BC1 is a special case since the texture data determines whether each block has an alpha channel or not.
# This if statement is hit by COMPRESSED_RGB_S3TC_DXT1, which is a bit of a mess.
# TODO(oetuaho): Look into whether COMPRESSED_RGB_S3TC_DXT1 works right in general.
# Reference: https://www.opengl.org/registry/specs/EXT/texture_compression_s3tc.txt
return 'nullptr'
elif component_type == 'uint' and bits['R'] == 8:
return 'Initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0x01>'
elif component_type == 'unorm' and bits['R'] == 8:
return 'Initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0xFF>'
elif component_type == 'unorm' and bits['R'] == 16:
return 'Initialize4ComponentData<GLubyte, 0x0000, 0x0000, 0x0000, 0xFFFF>'
elif component_type == 'int' and bits['R'] == 8:
return 'Initialize4ComponentData<GLbyte, 0x00, 0x00, 0x00, 0x01>'
elif component_type == 'snorm' and bits['R'] == 8:
return 'Initialize4ComponentData<GLbyte, 0x00, 0x00, 0x00, 0x7F>'
elif component_type == 'snorm' and bits['R'] == 16:
return 'Initialize4ComponentData<GLushort, 0x0000, 0x0000, 0x0000, 0x7FFF>'
elif component_type == 'float' and bits['R'] == 16:
return 'Initialize4ComponentData<GLhalf, 0x0000, 0x0000, 0x0000, gl::Float16One>'
elif component_type == 'uint' and bits['R'] == 16:
return 'Initialize4ComponentData<GLushort, 0x0000, 0x0000, 0x0000, 0x0001>'
elif component_type == 'int' and bits['R'] == 16:
return 'Initialize4ComponentData<GLshort, 0x0000, 0x0000, 0x0000, 0x0001>'
elif component_type == 'float' and bits['R'] == 32:
return 'Initialize4ComponentData<GLfloat, 0x00000000, 0x00000000, 0x00000000, gl::Float32One>'
elif component_type == 'int' and bits['R'] == 32:
return 'Initialize4ComponentData<GLint, 0x00000000, 0x00000000, 0x00000000, 0x00000001>'
elif component_type == 'uint' and bits['R'] == 32:
return 'Initialize4ComponentData<GLuint, 0x00000000, 0x00000000, 0x00000000, 0x00000001>'
else:
raise ValueError('warning: internal format initializer could not be generated and may be needed for ' + internal_format)
...@@ -12,7 +12,6 @@ import json ...@@ -12,7 +12,6 @@ import json
import math import math
import pprint import pprint
import os import os
import re
import sys import sys
sys.path.append('../..') sys.path.append('../..')
...@@ -69,81 +68,6 @@ const Format &Format::Get(GLenum internalFormat, const Renderer11DeviceCaps &dev ...@@ -69,81 +68,6 @@ const Format &Format::Get(GLenum internalFormat, const Renderer11DeviceCaps &dev
}} // namespace rx }} // namespace rx
""" """
# TODO(oetuaho): Expand this code so that it could generate the gl format info tables as well.
def gl_format_channels(internal_format):
if internal_format == 'GL_BGR5_A1_ANGLEX':
return 'bgra'
if internal_format == 'GL_R11F_G11F_B10F':
return 'rgb'
if internal_format == 'GL_RGB5_A1':
return 'rgba'
if internal_format.find('GL_RGB10_A2') == 0:
return 'rgba'
channels_pattern = re.compile('GL_(COMPRESSED_)?(SIGNED_)?(ETC\d_)?([A-Z]+)')
match = re.search(channels_pattern, internal_format)
channels_string = match.group(4)
if channels_string == 'ALPHA':
return 'a'
if channels_string == 'LUMINANCE':
if (internal_format.find('ALPHA') >= 0):
return 'la'
return 'l'
if channels_string == 'SRGB':
if (internal_format.find('ALPHA') >= 0):
return 'rgba'
return 'rgb'
if channels_string == 'DEPTH':
if (internal_format.find('STENCIL') >= 0):
return 'ds'
return 'd'
if channels_string == 'STENCIL':
return 's'
return channels_string.lower()
def get_internal_format_initializer(internal_format, angle_format):
internal_format_initializer = 'nullptr'
gl_channels = gl_format_channels(internal_format)
gl_format_no_alpha = gl_channels == 'rgb' or gl_channels == 'l'
if gl_format_no_alpha and angle_format['channels'] == 'rgba':
if angle_format['texFormat'].startswith('DXGI_FORMAT_BC1_UNORM'):
# BC1 is a special case since the texture data determines whether each block has an alpha channel or not.
# This if statement is hit by COMPRESSED_RGB_S3TC_DXT1, which is a bit of a mess.
# TODO(oetuaho): Look into whether COMPRESSED_RGB_S3TC_DXT1 works right in general.
# Reference: https://www.opengl.org/registry/specs/EXT/texture_compression_s3tc.txt
pass
elif 'componentType' not in angle_format:
raise ValueError('warning: internal format initializer could not be generated and may be needed for ' + internal_format)
elif angle_format['componentType'] == 'uint' and angle_format['bits']['red'] == 8:
internal_format_initializer = 'Initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0x01>'
elif angle_format['componentType'] == 'unorm' and angle_format['bits']['red'] == 8:
internal_format_initializer = 'Initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0xFF>'
elif angle_format['componentType'] == 'unorm' and angle_format['bits']['red'] == 16:
internal_format_initializer = 'Initialize4ComponentData<GLubyte, 0x0000, 0x0000, 0x0000, 0xFFFF>'
elif angle_format['componentType'] == 'int' and angle_format['bits']['red'] == 8:
internal_format_initializer = 'Initialize4ComponentData<GLbyte, 0x00, 0x00, 0x00, 0x01>'
elif angle_format['componentType'] == 'snorm' and angle_format['bits']['red'] == 8:
internal_format_initializer = 'Initialize4ComponentData<GLbyte, 0x00, 0x00, 0x00, 0x7F>'
elif angle_format['componentType'] == 'snorm' and angle_format['bits']['red'] == 16:
internal_format_initializer = 'Initialize4ComponentData<GLushort, 0x0000, 0x0000, 0x0000, 0x7FFF>'
elif angle_format['componentType'] == 'float' and angle_format['bits']['red'] == 16:
internal_format_initializer = 'Initialize4ComponentData<GLhalf, 0x0000, 0x0000, 0x0000, gl::Float16One>'
elif angle_format['componentType'] == 'uint' and angle_format['bits']['red'] == 16:
internal_format_initializer = 'Initialize4ComponentData<GLushort, 0x0000, 0x0000, 0x0000, 0x0001>'
elif angle_format['componentType'] == 'int' and angle_format['bits']['red'] == 16:
internal_format_initializer = 'Initialize4ComponentData<GLshort, 0x0000, 0x0000, 0x0000, 0x0001>'
elif angle_format['componentType'] == 'float' and angle_format['bits']['red'] == 32:
internal_format_initializer = 'Initialize4ComponentData<GLfloat, 0x00000000, 0x00000000, 0x00000000, gl::Float32One>'
elif angle_format['componentType'] == 'int' and angle_format['bits']['red'] == 32:
internal_format_initializer = 'Initialize4ComponentData<GLint, 0x00000000, 0x00000000, 0x00000000, 0x00000001>'
elif angle_format['componentType'] == 'uint' and angle_format['bits']['red'] == 32:
internal_format_initializer = 'Initialize4ComponentData<GLuint, 0x00000000, 0x00000000, 0x00000000, 0x00000001>'
else:
raise ValueError('warning: internal format initializer could not be generated and may be needed for ' + internal_format)
return internal_format_initializer
def get_swizzle_format_id(internal_format, angle_format): def get_swizzle_format_id(internal_format, angle_format):
angle_format_id = angle_format["formatName"] angle_format_id = angle_format["formatName"]
if (internal_format == 'GL_NONE') or (angle_format_id == 'NONE'): if (internal_format == 'GL_NONE') or (angle_format_id == 'NONE'):
...@@ -265,7 +189,8 @@ def json_to_table_data(internal_format, format_name, prefix, json): ...@@ -265,7 +189,8 @@ def json_to_table_data(internal_format, format_name, prefix, json):
# Derived values. # Derived values.
parsed["blitSRVFormat"] = get_blit_srv_format(parsed) parsed["blitSRVFormat"] = get_blit_srv_format(parsed)
parsed["swizzleFormat"] = get_swizzle_format_id(internal_format, parsed) parsed["swizzleFormat"] = get_swizzle_format_id(internal_format, parsed)
parsed["initializer"] = get_internal_format_initializer(internal_format, json) parsed["initializer"] = angle_format.get_internal_format_initializer(
internal_format, parsed["formatName"])
if len(prefix) > 0: if len(prefix) > 0:
return split_format_entry_template.format(**parsed) return split_format_entry_template.format(**parsed)
...@@ -332,29 +257,16 @@ def parse_json_into_switch_angle_format_string(json_map, json_data): ...@@ -332,29 +257,16 @@ def parse_json_into_switch_angle_format_string(json_map, json_data):
return table_data return table_data
def reject_duplicate_keys(pairs):
found_keys = {}
for key, value in pairs:
if key in found_keys:
raise ValueError("duplicate key: %r" % (key,))
else:
found_keys[key] = value
return found_keys
json_map = angle_format.load_with_override(os.path.abspath('texture_format_map.json')) json_map = angle_format.load_with_override(os.path.abspath('texture_format_map.json'))
data_source_name = 'texture_format_data.json' data_source_name = 'texture_format_data.json'
json_data = angle_format.load_json(data_source_name)
with open(data_source_name) as texture_format_json_file:
texture_format_data = texture_format_json_file.read() angle_format_cases = parse_json_into_switch_angle_format_string(json_map, json_data)
texture_format_json_file.close() output_cpp = template_texture_format_table_autogen_cpp.format(
json_data = json.loads(texture_format_data, object_pairs_hook=angle_format.reject_duplicate_keys) script_name = sys.argv[0],
copyright_year = date.today().year,
angle_format_cases = parse_json_into_switch_angle_format_string(json_map, json_data) angle_format_info_cases = angle_format_cases,
output_cpp = template_texture_format_table_autogen_cpp.format( data_source_name = data_source_name)
script_name = sys.argv[0], with open('texture_format_table_autogen.cpp', 'wt') as out_file:
copyright_year = date.today().year, out_file.write(output_cpp)
angle_format_info_cases = angle_format_cases, out_file.close()
data_source_name = data_source_name)
with open('texture_format_table_autogen.cpp', 'wt') as out_file:
out_file.write(output_cpp)
out_file.close()
...@@ -24,9 +24,6 @@ struct FormatType; ...@@ -24,9 +24,6 @@ struct FormatType;
namespace rx namespace rx
{ {
typedef void (*InitializeTextureDataFunction)(size_t width, size_t height, size_t depth,
uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch);
typedef void (*VertexCopyFunction)(const uint8_t *input, size_t stride, size_t count, uint8_t *output); typedef void (*VertexCopyFunction)(const uint8_t *input, size_t stride, size_t count, uint8_t *output);
enum VertexConversionType enum VertexConversionType
......
...@@ -126,47 +126,6 @@ def get_color_read_function(angle_format): ...@@ -126,47 +126,6 @@ def get_color_read_function(angle_format):
format_entry_template = """ {{ Format::ID::{id}, {glInternalFormat}, {fboImplementationInternalFormat}, {mipGenerationFunction}, {fastCopyFunctions}, {colorReadFunction}, {namedComponentType}, {R}, {G}, {B}, {A}, {D}, {S} }}, format_entry_template = """ {{ Format::ID::{id}, {glInternalFormat}, {fboImplementationInternalFormat}, {mipGenerationFunction}, {fastCopyFunctions}, {colorReadFunction}, {namedComponentType}, {R}, {G}, {B}, {A}, {D}, {S} }},
""" """
def get_component_type(format_id):
if "SNORM" in format_id:
return "snorm"
elif "UNORM" in format_id:
return "unorm"
elif "FLOAT" in format_id:
return "float"
elif "UINT" in format_id:
return "uint"
elif "SINT" in format_id:
return "int"
elif format_id == "NONE":
return "none"
elif "SRGB" in format_id:
return "unorm"
else:
raise ValueError("Unknown component type for " + format_id)
def get_channel_tokens(format_id):
r = re.compile(r'([ABDGLRS][\d]+)')
return filter(r.match, r.split(format_id))
def get_channels(format_id):
channels = ''
tokens = get_channel_tokens(format_id)
if len(tokens) == 0:
return None
for token in tokens:
channels += token[0].lower()
return channels
def get_bits(format_id):
bits = {}
tokens = get_channel_tokens(format_id)
if len(tokens) == 0:
return None
for token in tokens:
bits[token[0]] = int(token[1:])
return bits
def get_named_component_type(component_type): def get_named_component_type(component_type):
if component_type == "snorm": if component_type == "snorm":
return "GL_SIGNED_NORMALIZED" return "GL_SIGNED_NORMALIZED"
...@@ -202,13 +161,13 @@ def json_to_table_data(format_id, json, angle_to_gl): ...@@ -202,13 +161,13 @@ def json_to_table_data(format_id, json, angle_to_gl):
parsed["fboImplementationInternalFormat"] = parsed["glInternalFormat"] parsed["fboImplementationInternalFormat"] = parsed["glInternalFormat"]
if "componentType" not in parsed: if "componentType" not in parsed:
parsed["componentType"] = get_component_type(format_id) parsed["componentType"] = angle_format.get_component_type(format_id)
if "channels" not in parsed: if "channels" not in parsed:
parsed["channels"] = get_channels(format_id) parsed["channels"] = angle_format.get_channels(format_id)
if "bits" not in parsed: if "bits" not in parsed:
parsed["bits"] = get_bits(format_id) parsed["bits"] = angle_format.get_bits(format_id)
# Derived values. # Derived values.
parsed["mipGenerationFunction"] = get_mip_generation_function(parsed) parsed["mipGenerationFunction"] = get_mip_generation_function(parsed)
......
...@@ -95,6 +95,13 @@ ColorWriteFunction GetColorWriteFunction(const gl::FormatType &formatType); ...@@ -95,6 +95,13 @@ ColorWriteFunction GetColorWriteFunction(const gl::FormatType &formatType);
ColorCopyFunction GetFastCopyFunction(const FastCopyFunctionMap &fastCopyFunctions, ColorCopyFunction GetFastCopyFunction(const FastCopyFunctionMap &fastCopyFunctions,
const gl::FormatType &formatType); const gl::FormatType &formatType);
using InitializeTextureDataFunction = void (*)(size_t width,
size_t height,
size_t depth,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch);
using LoadImageFunction = void (*)(size_t width, using LoadImageFunction = void (*)(size_t width,
size_t height, size_t height,
size_t depth, size_t depth,
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "libANGLE/renderer/vulkan/DisplayVk.h" #include "libANGLE/renderer/vulkan/DisplayVk.h"
#include "libANGLE/renderer/vulkan/FramebufferVk.h" #include "libANGLE/renderer/vulkan/FramebufferVk.h"
#include "libANGLE/renderer/vulkan/RendererVk.h" #include "libANGLE/renderer/vulkan/RendererVk.h"
#include "libANGLE/renderer/vulkan/formatutilsvk.h"
namespace rx namespace rx
{ {
...@@ -21,10 +22,10 @@ namespace rx ...@@ -21,10 +22,10 @@ namespace rx
namespace namespace
{ {
VkFormat GetVkFormatFromConfig(const egl::Config &config) const vk::Format &GetVkFormatFromConfig(const egl::Config &config)
{ {
// TODO(jmadill): Properly handle format interpretation. // TODO(jmadill): Properly handle format interpretation.
return VK_FORMAT_B8G8R8A8_UNORM; return vk::Format::Get(GL_BGRA8_EXT);
} }
} // namespace } // namespace
...@@ -239,7 +240,7 @@ vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer) ...@@ -239,7 +240,7 @@ vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer)
preTransform = surfaceCaps.currentTransform; preTransform = surfaceCaps.currentTransform;
} }
VkFormat configSurfaceFormat = GetVkFormatFromConfig(*mState.config); const vk::Format &configSurfaceFormat = GetVkFormatFromConfig(*mState.config);
uint32_t surfaceFormatCount = 0; uint32_t surfaceFormatCount = 0;
ANGLE_VK_TRY(vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, mSurface, &surfaceFormatCount, ANGLE_VK_TRY(vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, mSurface, &surfaceFormatCount,
...@@ -258,7 +259,7 @@ vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer) ...@@ -258,7 +259,7 @@ vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer)
bool foundFormat = false; bool foundFormat = false;
for (const auto &surfaceFormat : surfaceFormats) for (const auto &surfaceFormat : surfaceFormats)
{ {
if (surfaceFormat.format == configSurfaceFormat) if (surfaceFormat.format == configSurfaceFormat.native)
{ {
foundFormat = true; foundFormat = true;
break; break;
...@@ -274,7 +275,7 @@ vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer) ...@@ -274,7 +275,7 @@ vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer)
swapchainInfo.flags = 0; swapchainInfo.flags = 0;
swapchainInfo.surface = mSurface; swapchainInfo.surface = mSurface;
swapchainInfo.minImageCount = minImageCount; swapchainInfo.minImageCount = minImageCount;
swapchainInfo.imageFormat = configSurfaceFormat; swapchainInfo.imageFormat = configSurfaceFormat.native;
swapchainInfo.imageColorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; swapchainInfo.imageColorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR;
swapchainInfo.imageExtent.width = mWidth; swapchainInfo.imageExtent.width = mWidth;
swapchainInfo.imageExtent.height = mHeight; swapchainInfo.imageExtent.height = mHeight;
...@@ -311,7 +312,7 @@ vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer) ...@@ -311,7 +312,7 @@ vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer)
imageViewInfo.flags = 0; imageViewInfo.flags = 0;
imageViewInfo.image = swapchainImage; imageViewInfo.image = swapchainImage;
imageViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; imageViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
imageViewInfo.format = configSurfaceFormat; imageViewInfo.format = configSurfaceFormat.native;
imageViewInfo.components.r = VK_COMPONENT_SWIZZLE_R; imageViewInfo.components.r = VK_COMPONENT_SWIZZLE_R;
imageViewInfo.components.g = VK_COMPONENT_SWIZZLE_G; imageViewInfo.components.g = VK_COMPONENT_SWIZZLE_G;
imageViewInfo.components.b = VK_COMPONENT_SWIZZLE_B; imageViewInfo.components.b = VK_COMPONENT_SWIZZLE_B;
......
//
// Copyright 2016 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.
//
// formatutilsvk:
// Helper for Vulkan format code.
#include "libANGLE/renderer/vulkan/formatutilsvk.h"
#include "libANGLE/renderer/load_functions_table.h"
namespace rx
{
namespace vk
{
const angle::Format &Format::format() const
{
return angle::Format::Get(formatID);
}
LoadFunctionMap Format::getLoadFunctions() const
{
return GetLoadFunctionsMap(internalFormat, formatID);
}
} // namespace vk
} // namespace rx
//
// Copyright 2016 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:
// Vulkan implementation of a storage format.
#ifndef LIBANGLE_RENDERER_VULKAN_FORMAT_H_
#define LIBANGLE_RENDERER_VULKAN_FORMAT_H_
#include <vulkan/vulkan.h>
#include "libANGLE/renderer/Format.h"
#include "libANGLE/renderer/renderer_utils.h"
namespace rx
{
namespace vk
{
struct Format final : angle::NonCopyable
{
constexpr Format(GLenum internalFormat,
angle::Format::ID formatID,
VkFormat native,
InitializeTextureDataFunction initFunction);
static const Format &Get(GLenum internalFormat);
const angle::Format &format() const;
LoadFunctionMap getLoadFunctions() const;
GLenum internalFormat;
angle::Format::ID formatID;
VkFormat native;
InitializeTextureDataFunction dataInitializerFunction;
};
constexpr Format::Format(GLenum internalFormat,
angle::Format::ID formatID,
VkFormat native,
InitializeTextureDataFunction initFunction)
: internalFormat(internalFormat),
formatID(formatID),
native(native),
dataInitializerFunction(initFunction)
{
}
} // namespace vk
} // namespace rx
#endif // LIBANGLE_RENDERER_VULKAN_FORMAT_H_
#!/usr/bin/python
# Copyright 2016 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.
#
# gen_vk_format_table.py:
# Code generation for vk format map
from datetime import date
import json
import math
import pprint
import os
import re
import sys
sys.path.append('..')
import angle_format
template_table_autogen_cpp = """// GENERATED FILE - DO NOT EDIT.
// Generated by {script_name} using data from {input_file_name}
//
// Copyright {copyright_year} 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.
//
// {out_file_name}:
// Queries for full Vulkan format information based on GL format.
#include "libANGLE/renderer/vulkan/formatutilsvk.h"
#include "image_util/copyimage.h"
#include "image_util/generatemip.h"
#include "image_util/loadimage.h"
using namespace angle;
namespace rx
{{
namespace vk
{{
// static
const Format &Format::Get(GLenum internalFormat)
{{
// clang-format off
switch (internalFormat)
{{
{format_case_data}
default:
break;
}}
// clang-format on
UNREACHABLE();
static const Format noInfo(GL_NONE, angle::Format::ID::NONE, VK_FORMAT_UNDEFINED, nullptr);
return noInfo;
}}
}} // namespace vk
}} // namespace rx
"""
format_entry_template = """{space}{{
{space} static constexpr Format info({internalFormat},
{space} angle::Format::ID::{formatName},
{space} {vkFormat},
{space} {initializer});
{space} return info;
{space}}}
"""
def parse_format_case(internal_format, format_name, native_format):
table_data = ""
parsed = {
"space": " ",
"internalFormat": internal_format,
"formatName": format_name,
"vkFormat": native_format,
}
# Derived values.
parsed["initializer"] = angle_format.get_internal_format_initializer(
internal_format, format_name)
return format_entry_template.format(**parsed)
def parse_json_into_cases(json_map, vk_map):
table_data = ''
for internal_format, format_name in sorted(json_map.iteritems()):
if format_name not in vk_map:
continue
native_format = vk_map[format_name]
table_data += ' case ' + internal_format + ':\n'
table_data += parse_format_case(internal_format, format_name, native_format)
return table_data
input_file_name = 'vk_format_map.json'
out_file_name = 'vk_format_table'
json_map = angle_format.load_without_override()
vk_map = angle_format.load_json(input_file_name)
format_case_data = parse_json_into_cases(json_map, vk_map)
output_cpp = template_table_autogen_cpp.format(
copyright_year = date.today().year,
format_case_data = format_case_data,
script_name = __file__,
out_file_name = out_file_name,
input_file_name = input_file_name)
with open(out_file_name + '_autogen.cpp', 'wt') as out_file:
out_file.write(output_cpp)
out_file.close()
{
"NONE": "VK_FORMAT_UNDEFINED",
"R4G4B4A4_UNORM": "VK_FORMAT_R4G4B4A4_UNORM_PACK16",
"B4G4R4A4_UNORM": "VK_FORMAT_B4G4R4A4_UNORM_PACK16",
"R5G6B5_UNORM": "VK_FORMAT_R5G6B5_UNORM_PACK16",
"B5G6R5_UNORM": "VK_FORMAT_B5G6R5_UNORM_PACK16",
"R5G5B5A1_UNORM": "VK_FORMAT_R5G5B5A1_UNORM_PACK16",
"B5G5R5A1_UNORM": "VK_FORMAT_B5G5R5A1_UNORM_PACK16",
"A1R5G5B5_UNORM": "VK_FORMAT_A1R5G5B5_UNORM_PACK16",
"R8_UNORM": "VK_FORMAT_R8_UNORM",
"R8_SNORM": "VK_FORMAT_R8_SNORM",
"R8_UINT": "VK_FORMAT_R8_UINT",
"R8_SINT": "VK_FORMAT_R8_SINT",
"R8_SRGB": "VK_FORMAT_R8_SRGB",
"R8G8_UNORM": "VK_FORMAT_R8G8_UNORM",
"R8G8_SNORM": "VK_FORMAT_R8G8_SNORM",
"R8G8_UINT": "VK_FORMAT_R8G8_UINT",
"R8G8_SINT": "VK_FORMAT_R8G8_SINT",
"R8G8_SRGB": "VK_FORMAT_R8G8_SRGB",
"R8G8B8_UNORM": "VK_FORMAT_R8G8B8_UNORM",
"R8G8B8_SNORM": "VK_FORMAT_R8G8B8_SNORM",
"R8G8B8_UINT": "VK_FORMAT_R8G8B8_UINT",
"R8G8B8_SINT": "VK_FORMAT_R8G8B8_SINT",
"R8G8B8_SRGB": "VK_FORMAT_R8G8B8_SRGB",
"B8G8R8_UNORM": "VK_FORMAT_B8G8R8_UNORM",
"B8G8R8_SNORM": "VK_FORMAT_B8G8R8_SNORM",
"B8G8R8_UINT": "VK_FORMAT_B8G8R8_UINT",
"B8G8R8_SINT": "VK_FORMAT_B8G8R8_SINT",
"B8G8R8_SRGB": "VK_FORMAT_B8G8R8_SRGB",
"R8G8B8A8_UNORM": "VK_FORMAT_R8G8B8A8_UNORM",
"R8G8B8A8_SNORM": "VK_FORMAT_R8G8B8A8_SNORM",
"R8G8B8A8_UINT": "VK_FORMAT_R8G8B8A8_UINT",
"R8G8B8A8_SINT": "VK_FORMAT_R8G8B8A8_SINT",
"R8G8B8A8_SRGB": "VK_FORMAT_R8G8B8A8_SRGB",
"B8G8R8A8_UNORM": "VK_FORMAT_B8G8R8A8_UNORM",
"B8G8R8A8_SNORM": "VK_FORMAT_B8G8R8A8_SNORM",
"B8G8R8A8_USCALED": "VK_FORMAT_B8G8R8A8_USCALED",
"B8G8R8A8_SSCALED": "VK_FORMAT_B8G8R8A8_SSCALED",
"B8G8R8A8_UINT": "VK_FORMAT_B8G8R8A8_UINT",
"B8G8R8A8_SINT": "VK_FORMAT_B8G8R8A8_SINT",
"B8G8R8A8_SRGB": "VK_FORMAT_B8G8R8A8_SRGB",
"A2R10G10B10_UNORM_PACK32": "VK_FORMAT_A2R10G10B10_UNORM_PACK32",
"A2R10G10B10_SNORM_PACK32": "VK_FORMAT_A2R10G10B10_SNORM_PACK32",
"A2R10G10B10_USCALED_PACK32": "VK_FORMAT_A2R10G10B10_USCALED_PACK32",
"A2R10G10B10_SSCALED_PACK32": "VK_FORMAT_A2R10G10B10_SSCALED_PACK32",
"A2R10G10B10_UINT_PACK32": "VK_FORMAT_A2R10G10B10_UINT_PACK32",
"A2R10G10B10_SINT_PACK32": "VK_FORMAT_A2R10G10B10_SINT_PACK32",
"A2B10G10R10_UNORM_PACK32": "VK_FORMAT_A2B10G10R10_UNORM_PACK32",
"A2B10G10R10_SNORM_PACK32": "VK_FORMAT_A2B10G10R10_SNORM_PACK32",
"A2B10G10R10_USCALED_PACK32": "VK_FORMAT_A2B10G10R10_USCALED_PACK32",
"A2B10G10R10_SSCALED_PACK32": "VK_FORMAT_A2B10G10R10_SSCALED_PACK32",
"A2B10G10R10_UINT_PACK32": "VK_FORMAT_A2B10G10R10_UINT_PACK32",
"A2B10G10R10_SINT_PACK32": "VK_FORMAT_A2B10G10R10_SINT_PACK32",
"R16_UNORM": "VK_FORMAT_R16_UNORM",
"R16_SNORM": "VK_FORMAT_R16_SNORM",
"R16_UINT": "VK_FORMAT_R16_UINT",
"R16_SINT": "VK_FORMAT_R16_SINT",
"R16_FLOAT": "VK_FORMAT_R16_SFLOAT",
"R16G16_UNORM": "VK_FORMAT_R16G16_UNORM",
"R16G16_SNORM": "VK_FORMAT_R16G16_SNORM",
"R16G16_UINT": "VK_FORMAT_R16G16_UINT",
"R16G16_SINT": "VK_FORMAT_R16G16_SINT",
"R16G16_FLOAT": "VK_FORMAT_R16G16_SFLOAT",
"R16G16B16_UNORM": "VK_FORMAT_R16G16B16_UNORM",
"R16G16B16_SNORM": "VK_FORMAT_R16G16B16_SNORM",
"R16G16B16_UINT": "VK_FORMAT_R16G16B16_UINT",
"R16G16B16_SINT": "VK_FORMAT_R16G16B16_SINT",
"R16G16B16_FLOAT": "VK_FORMAT_R16G16B16_SFLOAT",
"R16G16B16A16_UNORM": "VK_FORMAT_R16G16B16A16_UNORM",
"R16G16B16A16_SNORM": "VK_FORMAT_R16G16B16A16_SNORM",
"R16G16B16A16_UINT": "VK_FORMAT_R16G16B16A16_UINT",
"R16G16B16A16_SINT": "VK_FORMAT_R16G16B16A16_SINT",
"R16G16B16A16_FLOAT": "VK_FORMAT_R16G16B16A16_SFLOAT",
"R32_UINT": "VK_FORMAT_R32_UINT",
"R32_SINT": "VK_FORMAT_R32_SINT",
"R32_FLOAT": "VK_FORMAT_R32_SFLOAT",
"R32G32_UINT": "VK_FORMAT_R32G32_UINT",
"R32G32_SINT": "VK_FORMAT_R32G32_SINT",
"R32G32_FLOAT": "VK_FORMAT_R32G32_SFLOAT",
"R32G32B32_UINT": "VK_FORMAT_R32G32B32_UINT",
"R32G32B32_SINT": "VK_FORMAT_R32G32B32_SINT",
"R32G32B32_FLOAT": "VK_FORMAT_R32G32B32_SFLOAT",
"R32G32B32A32_UINT": "VK_FORMAT_R32G32B32A32_UINT",
"R32G32B32A32_SINT": "VK_FORMAT_R32G32B32A32_SINT",
"R32G32B32A32_FLOAT": "VK_FORMAT_R32G32B32A32_SFLOAT",
"R64_UINT": "VK_FORMAT_R64_UINT",
"R64_SINT": "VK_FORMAT_R64_SINT",
"R64_FLOAT": "VK_FORMAT_R64_SFLOAT",
"R64G64_UINT": "VK_FORMAT_R64G64_UINT",
"R64G64_SINT": "VK_FORMAT_R64G64_SINT",
"R64G64_FLOAT": "VK_FORMAT_R64G64_SFLOAT",
"R64G64B64_UINT": "VK_FORMAT_R64G64B64_UINT",
"R64G64B64_SINT": "VK_FORMAT_R64G64B64_SINT",
"R64G64B64_FLOAT": "VK_FORMAT_R64G64B64_SFLOAT",
"R64G64B64A64_UINT": "VK_FORMAT_R64G64B64A64_UINT",
"R64G64B64A64_SINT": "VK_FORMAT_R64G64B64A64_SINT",
"R64G64B64A64_FLOAT": "VK_FORMAT_R64G64B64A64_SFLOAT",
"B10G11R11_UFLOAT_PACK32": "VK_FORMAT_B10G11R11_UFLOAT_PACK32",
"E5B9G9R9_UFLOAT_PACK32": "VK_FORMAT_E5B9G9R9_UFLOAT_PACK32",
"D16_UNORM": "VK_FORMAT_D16_UNORM",
"X8_D24_UNORM_PACK32": "VK_FORMAT_X8_D24_UNORM_PACK32",
"D32_FLOAT": "VK_FORMAT_D32_SFLOAT",
"S8_UINT": "VK_FORMAT_S8_UINT",
"D16_UNORM_S8_UINT": "VK_FORMAT_D16_UNORM_S8_UINT",
"D24_UNORM_S8_UINT": "VK_FORMAT_D24_UNORM_S8_UINT",
"D32_SFLOAT_S8_UINT": "VK_FORMAT_D32_SFLOAT_S8_UINT",
"BC1_RGB_UNORM_BLOCK": "VK_FORMAT_BC1_RGB_UNORM_BLOCK",
"BC1_RGB_SRGB_BLOCK": "VK_FORMAT_BC1_RGB_SRGB_BLOCK",
"BC1_RGBA_UNORM_BLOCK": "VK_FORMAT_BC1_RGBA_UNORM_BLOCK",
"BC1_RGBA_SRGB_BLOCK": "VK_FORMAT_BC1_RGBA_SRGB_BLOCK",
"BC2_UNORM_BLOCK": "VK_FORMAT_BC2_UNORM_BLOCK",
"BC2_SRGB_BLOCK": "VK_FORMAT_BC2_SRGB_BLOCK",
"BC3_UNORM_BLOCK": "VK_FORMAT_BC3_UNORM_BLOCK",
"BC3_SRGB_BLOCK": "VK_FORMAT_BC3_SRGB_BLOCK",
"BC4_UNORM_BLOCK": "VK_FORMAT_BC4_UNORM_BLOCK",
"BC4_SNORM_BLOCK": "VK_FORMAT_BC4_SNORM_BLOCK",
"BC5_UNORM_BLOCK": "VK_FORMAT_BC5_UNORM_BLOCK",
"BC5_SNORM_BLOCK": "VK_FORMAT_BC5_SNORM_BLOCK",
"BC6H_UFLOAT_BLOCK": "VK_FORMAT_BC6H_UFLOAT_BLOCK",
"BC6H_SFLOAT_BLOCK": "VK_FORMAT_BC6H_SFLOAT_BLOCK",
"BC7_UNORM_BLOCK": "VK_FORMAT_BC7_UNORM_BLOCK",
"BC7_SRGB_BLOCK": "VK_FORMAT_BC7_SRGB_BLOCK",
"ETC2_R8G8B8_UNORM_BLOCK": "VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK",
"ETC2_R8G8B8_SRGB_BLOCK": "VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK",
"ETC2_R8G8B8A1_UNORM_BLOCK": "VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK",
"ETC2_R8G8B8A1_SRGB_BLOCK": "VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK",
"ETC2_R8G8B8A8_UNORM_BLOCK": "VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK",
"ETC2_R8G8B8A8_SRGB_BLOCK": "VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK",
"EAC_R11_UNORM_BLOCK": "VK_FORMAT_EAC_R11_UNORM_BLOCK",
"EAC_R11_SNORM_BLOCK": "VK_FORMAT_EAC_R11_SNORM_BLOCK",
"EAC_R11G11_UNORM_BLOCK": "VK_FORMAT_EAC_R11G11_UNORM_BLOCK",
"EAC_R11G11_SNORM_BLOCK": "VK_FORMAT_EAC_R11G11_SNORM_BLOCK",
"ASTC_4x4_UNORM_BLOCK": "VK_FORMAT_ASTC_4x4_UNORM_BLOCK",
"ASTC_4x4_SRGB_BLOCK": "VK_FORMAT_ASTC_4x4_SRGB_BLOCK",
"ASTC_5x4_UNORM_BLOCK": "VK_FORMAT_ASTC_5x4_UNORM_BLOCK",
"ASTC_5x4_SRGB_BLOCK": "VK_FORMAT_ASTC_5x4_SRGB_BLOCK",
"ASTC_5x5_UNORM_BLOCK": "VK_FORMAT_ASTC_5x5_UNORM_BLOCK",
"ASTC_5x5_SRGB_BLOCK": "VK_FORMAT_ASTC_5x5_SRGB_BLOCK",
"ASTC_6x5_UNORM_BLOCK": "VK_FORMAT_ASTC_6x5_UNORM_BLOCK",
"ASTC_6x5_SRGB_BLOCK": "VK_FORMAT_ASTC_6x5_SRGB_BLOCK",
"ASTC_6x6_UNORM_BLOCK": "VK_FORMAT_ASTC_6x6_UNORM_BLOCK",
"ASTC_6x6_SRGB_BLOCK": "VK_FORMAT_ASTC_6x6_SRGB_BLOCK",
"ASTC_8x5_UNORM_BLOCK": "VK_FORMAT_ASTC_8x5_UNORM_BLOCK",
"ASTC_8x5_SRGB_BLOCK": "VK_FORMAT_ASTC_8x5_SRGB_BLOCK",
"ASTC_8x6_UNORM_BLOCK": "VK_FORMAT_ASTC_8x6_UNORM_BLOCK",
"ASTC_8x6_SRGB_BLOCK": "VK_FORMAT_ASTC_8x6_SRGB_BLOCK",
"ASTC_8x8_UNORM_BLOCK": "VK_FORMAT_ASTC_8x8_UNORM_BLOCK",
"ASTC_8x8_SRGB_BLOCK": "VK_FORMAT_ASTC_8x8_SRGB_BLOCK",
"ASTC_10x5_UNORM_BLOCK": "VK_FORMAT_ASTC_10x5_UNORM_BLOCK",
"ASTC_10x5_SRGB_BLOCK": "VK_FORMAT_ASTC_10x5_SRGB_BLOCK",
"ASTC_10x6_UNORM_BLOCK": "VK_FORMAT_ASTC_10x6_UNORM_BLOCK",
"ASTC_10x6_SRGB_BLOCK": "VK_FORMAT_ASTC_10x6_SRGB_BLOCK",
"ASTC_10x8_UNORM_BLOCK": "VK_FORMAT_ASTC_10x8_UNORM_BLOCK",
"ASTC_10x8_SRGB_BLOCK": "VK_FORMAT_ASTC_10x8_SRGB_BLOCK",
"ASTC_10x10_UNORM_BLOCK": "VK_FORMAT_ASTC_10x10_UNORM_BLOCK",
"ASTC_10x10_SRGB_BLOCK": "VK_FORMAT_ASTC_10x10_SRGB_BLOCK",
"ASTC_12x10_UNORM_BLOCK": "VK_FORMAT_ASTC_12x10_UNORM_BLOCK",
"ASTC_12x10_SRGB_BLOCK": "VK_FORMAT_ASTC_12x10_SRGB_BLOCK",
"ASTC_12x12_UNORM_BLOCK": "VK_FORMAT_ASTC_12x12_UNORM_BLOCK",
"ASTC_12x12_SRGB_BLOC": "VK_FORMAT_ASTC_12x12_SRGB_BLOCK"
}
...@@ -643,8 +643,11 @@ ...@@ -643,8 +643,11 @@
'libANGLE/renderer/vulkan/TransformFeedbackVk.h', 'libANGLE/renderer/vulkan/TransformFeedbackVk.h',
'libANGLE/renderer/vulkan/VertexArrayVk.cpp', 'libANGLE/renderer/vulkan/VertexArrayVk.cpp',
'libANGLE/renderer/vulkan/VertexArrayVk.h', 'libANGLE/renderer/vulkan/VertexArrayVk.h',
'libANGLE/renderer/vulkan/formatutilsvk.h',
'libANGLE/renderer/vulkan/formatutilsvk.cpp',
'libANGLE/renderer/vulkan/renderervk_utils.cpp', 'libANGLE/renderer/vulkan/renderervk_utils.cpp',
'libANGLE/renderer/vulkan/renderervk_utils.h', 'libANGLE/renderer/vulkan/renderervk_utils.h',
'libANGLE/renderer/vulkan/vk_format_table_autogen.cpp',
], ],
'libangle_null_sources': 'libangle_null_sources':
[ [
......
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