Commit 115e8a26 by Jamie Madill Committed by Commit Bot

Vulkan: Store "is packed" in buffer formats.

This more easily allows us to compute the format alignment for use with the vertex input stage. Bug: angleproject:2797 Change-Id: If15281ce18fbed743b6a0c843cece4626bc4ce72 Reviewed-on: https://chromium-review.googlesource.com/1245841Reviewed-by: 's avatarFrank Henigman <fjhenigman@chromium.org> Reviewed-by: 's avatarJie A Chen <jie.a.chen@intel.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent af8b73c9
......@@ -68,7 +68,7 @@
"Vulkan format:src/libANGLE/renderer/angle_format_map.json":
"ea6dfe3ebbc86e04f0d4b9f568ba22ae",
"Vulkan format:src/libANGLE/renderer/vulkan/gen_vk_format_table.py":
"1d7d1b6a1f2b4b6f5080197c56b908b4",
"4bbb2e4aff55839cdfb0ca92e633d541",
"Vulkan format:src/libANGLE/renderer/vulkan/vk_format_map.json":
"a22cdfceb4f0c43b5ed498bc9ebc2e98",
"Vulkan internal shader programs:src/libANGLE/renderer/vulkan/gen_vk_internal_shaders.py":
......
......@@ -41,6 +41,7 @@ struct Format final : private angle::NonCopyable
static FormatID InternalFormatToID(GLenum internalFormat);
constexpr bool hasDepthOrStencilBits() const;
constexpr GLuint channelCount() const;
bool operator==(const Format &other) const { return this->id == other.id; }
......@@ -115,6 +116,12 @@ constexpr bool Format::hasDepthOrStencilBits() const
{
return depthBits > 0 || stencilBits > 0;
}
constexpr GLuint Format::channelCount() const
{
return (redBits > 0) + (greenBits > 0) + (blueBits > 0) + (alphaBits > 0) + (depthBits > 0) +
(stencilBits > 0);
}
} // namespace angle
#include "libANGLE/renderer/FormatID_autogen.inc"
......
......@@ -72,7 +72,9 @@ break;
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));
......@@ -80,15 +82,21 @@ initTextureFallback(physicalDevice, kInfo, ArraySize(kInfo));
buffer_basic_template = """bufferFormatID = {buffer};
vkBufferFormat = {vk_buffer_format};
vkBufferFormatIsPacked = {vk_buffer_format_is_packed};
vertexLoadFunction = {vertex_load_function};
vertexLoadRequiresConversion = {vertex_load_converts};"""
buffer_struct_template="""{{{buffer}, {vk_buffer_format}, {vertex_load_function},
{vertex_load_converts}}}"""
buffer_struct_template="""{{{buffer}, {vk_buffer_format}, {vk_buffer_format_is_packed},
{vertex_load_function}, {vertex_load_converts}}}"""
buffer_fallback_template = """{{
static constexpr BufferFormatInitInfo kInfo[] = {{{buffer_list}}};
initBufferFallback(physicalDevice, kInfo, ArraySize(kInfo));
}}"""
def is_packed(format_id):
return "true" if "_PACK" in format_id else "false"
def gen_format_case(angle, internal_format, vk_json_data):
vk_map = vk_json_data["map"]
vk_overrides = vk_json_data["overrides"]
......@@ -121,6 +129,7 @@ def gen_format_case(angle, internal_format, vk_json_data):
return dict(
buffer="angle::FormatID::" + format,
vk_buffer_format=vk_map[format],
vk_buffer_format_is_packed=is_packed(vk_map[format]),
vertex_load_function=angle_format.get_vertex_copy_function(angle, format),
vertex_load_converts='false' if angle == format else 'true',
)
......
......@@ -123,6 +123,7 @@ Format::Format()
vkTextureFormat(VK_FORMAT_UNDEFINED),
bufferFormatID(angle::FormatID::NONE),
vkBufferFormat(VK_FORMAT_UNDEFINED),
vkBufferFormatIsPacked(false),
textureInitializerFunction(nullptr),
textureLoadFunctions()
{
......@@ -145,6 +146,7 @@ void Format::initBufferFallback(VkPhysicalDevice physicalDevice,
int i = FindSupportedFormat(physicalDevice, info, numInfo, HasFullBufferFormatSupport);
bufferFormatID = info[i].format;
vkBufferFormat = info[i].vkFormat;
vkBufferFormatIsPacked = info[i].vkFormatIsPacked;
vertexLoadFunction = info[i].vertexLoadFunction;
vertexLoadRequiresConversion = info[i].vertexLoadRequiresConversion;
}
......@@ -232,4 +234,10 @@ const Format &FormatTable::operator[](angle::FormatID formatID) const
} // namespace vk
size_t GetVertexInputAlignment(const vk::Format &format)
{
const angle::Format &bufferFormat = format.bufferFormat();
size_t pixelBytes = bufferFormat.pixelBytes;
return format.vkBufferFormatIsPacked ? pixelBytes : (pixelBytes / bufferFormat.channelCount());
}
} // namespace rx
......@@ -44,6 +44,7 @@ struct BufferFormatInitInfo final
{
angle::FormatID format;
VkFormat vkFormat;
bool vkFormatIsPacked;
VertexCopyFunction vertexLoadFunction;
bool vertexLoadRequiresConversion;
};
......@@ -64,9 +65,9 @@ struct Format final : private angle::NonCopyable
const BufferFormatInitInfo *info,
int numInfo);
const angle::Format &angleFormat() const;
const angle::Format &textureFormat() const;
const angle::Format &bufferFormat() const;
const angle::Format &angleFormat() const;
angle::FormatID angleFormatID;
GLenum internalFormat;
......@@ -74,6 +75,7 @@ struct Format final : private angle::NonCopyable
VkFormat vkTextureFormat;
angle::FormatID bufferFormatID;
VkFormat vkBufferFormat;
bool vkBufferFormatIsPacked;
InitializeTextureDataFunction textureInitializerFunction;
LoadFunctionMap textureLoadFunctions;
VertexCopyFunction vertexLoadFunction;
......@@ -110,6 +112,9 @@ const VkFormatProperties &GetMandatoryFormatSupport(VkFormat vkFormat);
} // namespace vk
// Returns the alignment for a buffer to be used with the vertex input stage in Vulkan. This
// calculation is listed in the Vulkan spec at the end of the section 'Vertex Input Description'.
size_t GetVertexInputAlignment(const vk::Format &format);
} // namespace rx
#endif // LIBANGLE_RENDERER_VULKAN_VK_FORMAT_UTILS_H_
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