Vulkan: Free up 5 bits in RenderPassDesc

Leveraging the fact that there are only a handful of depth/stencil
formats, the last element of RenderPassDesc::mAttachmentFormats can
contain other information in addition to the depth/stencil format ID.

The FormatID enum is rearranged such that depth/stencil formats are
placed first, as a result occupying values in [1, 7].  These values take
up 3 bits in an element of RenderPassDesc::mAttachmentFormats (which
could be the last element if all color draw buffers are attached).

As a result, the upper 5 bits of the last element of
RenderPassDesc::mAttachmentFormats is unused.  It is intended for these
bits to be used in the implementation of multisampled-render-to-texture
depth/stencil renderbuffers.

Bug: angleproject:4836
Change-Id: I0786e0712539cdbbf5494ec83aeee1dd93f936dd
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2413165
Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Reviewed-by: Tim Van Patten <timvp@google.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
This commit is contained in:
Shahbaz Youssefi
2020-09-16 00:42:08 -04:00
committed by Commit Bot
parent 32de9efebc
commit 8d4331eeb5
6 changed files with 62 additions and 28 deletions

View File

@@ -1,8 +1,8 @@
{
"src/libANGLE/renderer/FormatID_autogen.h":
"8d1efd0b5c683c121e58a988ba0751c1",
"ce83c2449cc723131e4681ff380b59a2",
"src/libANGLE/renderer/Format_table_autogen.cpp":
"42e6d1c1688201c7eefb2dd4a69bd1b7",
"046f4c311e45f0ee32a6fe42f0928854",
"src/libANGLE/renderer/angle_format.py":
"32ba71942c0fd00e6807104f1bb80a3c",
"src/libANGLE/renderer/angle_format_data.json":
@@ -10,5 +10,5 @@
"src/libANGLE/renderer/angle_format_map.json":
"aa4a0d3463b76858a75787b9cdec8e98",
"src/libANGLE/renderer/gen_angle_format_table.py":
"8e349a643e81a028ebb54bde3756f9f7"
"34ab57bb88958e320f509bd5fbd04495"
}

View File

@@ -18,6 +18,13 @@ namespace angle
enum class FormatID
{
NONE,
D16_UNORM,
D24_UNORM_S8_UINT,
D24_UNORM_X8_UINT,
D32_FLOAT,
D32_FLOAT_S8X24_UINT,
D32_UNORM,
S8_UINT,
A16_FLOAT,
A1R5G5B5_UNORM,
A2R10G10B10_SINT_VERTEX,
@@ -101,12 +108,6 @@ enum class FormatID
BPTC_RGB_SIGNED_FLOAT_BLOCK,
BPTC_RGB_UNSIGNED_FLOAT_BLOCK,
BPTC_SRGB_ALPHA_UNORM_BLOCK,
D16_UNORM,
D24_UNORM_S8_UINT,
D24_UNORM_X8_UINT,
D32_FLOAT,
D32_FLOAT_S8X24_UINT,
D32_UNORM,
EAC_R11G11_SNORM_BLOCK,
EAC_R11G11_UNORM_BLOCK,
EAC_R11_SNORM_BLOCK,
@@ -234,7 +235,6 @@ enum class FormatID
R8_UNORM_SRGB,
R8_USCALED,
R9G9B9E5_SHAREDEXP,
S8_UINT,
X2R10G10B10_SINT_VERTEX,
X2R10G10B10_SNORM_VERTEX,
X2R10G10B10_SSCALED_VERTEX,

View File

@@ -25,6 +25,13 @@ static constexpr rx::FastCopyFunctionMap NoCopyFunctions;
const Format gFormatInfoTable[] = {
// clang-format off
{ FormatID::NONE, GL_NONE, GL_NONE, nullptr, NoCopyFunctions, nullptr, nullptr, GL_NONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, false, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::D16_UNORM, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT16, nullptr, NoCopyFunctions, ReadDepthStencil<D16>, WriteDepthStencil<D16>, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 16, 0, 2, std::numeric_limits<GLuint>::max(), false, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::D24_UNORM_S8_UINT, GL_DEPTH24_STENCIL8, GL_DEPTH24_STENCIL8, nullptr, NoCopyFunctions, ReadDepthStencil<D24S8>, WriteDepthStencil<D24S8>, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 24, 8, 4, std::numeric_limits<GLuint>::max(), false, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::D24_UNORM_X8_UINT, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT24, nullptr, NoCopyFunctions, ReadDepthStencil<D24X8>, WriteDepthStencil<D24X8>, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 24, 0, 4, std::numeric_limits<GLuint>::max(), false, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::D32_FLOAT, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT32F, nullptr, NoCopyFunctions, ReadDepthStencil<D32F>, WriteDepthStencil<D32F>, GL_FLOAT, 0, 0, 0, 0, 0, 32, 0, 4, std::numeric_limits<GLuint>::max(), false, false, false, gl::VertexAttribType::Float },
{ FormatID::D32_FLOAT_S8X24_UINT, GL_DEPTH32F_STENCIL8, GL_DEPTH32F_STENCIL8, nullptr, NoCopyFunctions, ReadDepthStencil<D32FS8X24>, WriteDepthStencil<D32FS8X24>, GL_FLOAT, 0, 0, 0, 0, 0, 32, 8, 8, std::numeric_limits<GLuint>::max(), false, false, false, gl::VertexAttribType::Float },
{ FormatID::D32_UNORM, GL_DEPTH_COMPONENT32_OES, GL_DEPTH_COMPONENT32_OES, nullptr, NoCopyFunctions, ReadDepthStencil<D32>, WriteDepthStencil<D32>, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 32, 0, 4, std::numeric_limits<GLuint>::max(), false, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::S8_UINT, GL_STENCIL_INDEX8, GL_STENCIL_INDEX8, nullptr, NoCopyFunctions, ReadDepthStencil<S8>, WriteDepthStencil<S8>, GL_UNSIGNED_INT, 0, 0, 0, 0, 0, 0, 8, 1, std::numeric_limits<GLuint>::max(), false, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::A16_FLOAT, GL_ALPHA16F_EXT, GL_ALPHA16F_EXT, GenerateMip<A16F>, NoCopyFunctions, ReadColor<A16F, GLfloat>, WriteColor<A16F, GLfloat>, GL_FLOAT, 0, 0, 0, 16, 0, 0, 0, 2, 1, false, false, false, gl::VertexAttribType::Float },
{ FormatID::A1R5G5B5_UNORM, GL_A1RGB5_ANGLEX, GL_A1RGB5_ANGLEX, GenerateMip<A1R5G5B5>, NoCopyFunctions, ReadColor<A1R5G5B5, GLfloat>, WriteColor<A1R5G5B5, GLfloat>, GL_UNSIGNED_NORMALIZED, 5, 5, 5, 1, 0, 0, 0, 2, std::numeric_limits<GLuint>::max(), false, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::A2R10G10B10_SINT_VERTEX, GL_INT_10_10_10_2_OES, GL_INT_10_10_10_2_OES, nullptr, NoCopyFunctions, nullptr, nullptr, GL_INT, 10, 10, 10, 2, 0, 0, 0, 4, std::numeric_limits<GLuint>::max(), false, false, false, gl::VertexAttribType::Int1010102 },
@@ -108,12 +115,6 @@ const Format gFormatInfoTable[] = {
{ FormatID::BPTC_RGB_SIGNED_FLOAT_BLOCK, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT, nullptr, NoCopyFunctions, nullptr, nullptr, GL_FLOAT, 0, 0, 0, 0, 0, 0, 0, 16, std::numeric_limits<GLuint>::max(), true, false, false, gl::VertexAttribType::Float },
{ FormatID::BPTC_RGB_UNSIGNED_FLOAT_BLOCK, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT, nullptr, NoCopyFunctions, nullptr, nullptr, GL_FLOAT, 0, 0, 0, 0, 0, 0, 0, 16, std::numeric_limits<GLuint>::max(), true, false, false, gl::VertexAttribType::Float },
{ FormatID::BPTC_SRGB_ALPHA_UNORM_BLOCK, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 0, 0, 16, std::numeric_limits<GLuint>::max(), true, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::D16_UNORM, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT16, nullptr, NoCopyFunctions, ReadDepthStencil<D16>, WriteDepthStencil<D16>, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 16, 0, 2, std::numeric_limits<GLuint>::max(), false, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::D24_UNORM_S8_UINT, GL_DEPTH24_STENCIL8, GL_DEPTH24_STENCIL8, nullptr, NoCopyFunctions, ReadDepthStencil<D24S8>, WriteDepthStencil<D24S8>, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 24, 8, 4, std::numeric_limits<GLuint>::max(), false, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::D24_UNORM_X8_UINT, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT24, nullptr, NoCopyFunctions, ReadDepthStencil<D24X8>, WriteDepthStencil<D24X8>, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 24, 0, 4, std::numeric_limits<GLuint>::max(), false, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::D32_FLOAT, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT32F, nullptr, NoCopyFunctions, ReadDepthStencil<D32F>, WriteDepthStencil<D32F>, GL_FLOAT, 0, 0, 0, 0, 0, 32, 0, 4, std::numeric_limits<GLuint>::max(), false, false, false, gl::VertexAttribType::Float },
{ FormatID::D32_FLOAT_S8X24_UINT, GL_DEPTH32F_STENCIL8, GL_DEPTH32F_STENCIL8, nullptr, NoCopyFunctions, ReadDepthStencil<D32FS8X24>, WriteDepthStencil<D32FS8X24>, GL_FLOAT, 0, 0, 0, 0, 0, 32, 8, 8, std::numeric_limits<GLuint>::max(), false, false, false, gl::VertexAttribType::Float },
{ FormatID::D32_UNORM, GL_DEPTH_COMPONENT32_OES, GL_DEPTH_COMPONENT32_OES, nullptr, NoCopyFunctions, ReadDepthStencil<D32>, WriteDepthStencil<D32>, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 32, 0, 4, std::numeric_limits<GLuint>::max(), false, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::EAC_R11G11_SNORM_BLOCK, GL_COMPRESSED_SIGNED_RG11_EAC, GL_COMPRESSED_SIGNED_RG11_EAC, nullptr, NoCopyFunctions, nullptr, nullptr, GL_SIGNED_NORMALIZED, 11, 11, 0, 0, 0, 0, 0, 16, 0, true, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::EAC_R11G11_UNORM_BLOCK, GL_COMPRESSED_RG11_EAC, GL_COMPRESSED_RG11_EAC, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 11, 11, 0, 0, 0, 0, 0, 16, 0, true, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::EAC_R11_SNORM_BLOCK, GL_COMPRESSED_SIGNED_R11_EAC, GL_COMPRESSED_SIGNED_R11_EAC, nullptr, NoCopyFunctions, nullptr, nullptr, GL_SIGNED_NORMALIZED, 11, 0, 0, 0, 0, 0, 0, 8, 0, true, false, false, gl::VertexAttribType::InvalidEnum },
@@ -241,7 +242,6 @@ const Format gFormatInfoTable[] = {
{ FormatID::R8_UNORM_SRGB, GL_SR8_EXT, GL_SR8_EXT, GenerateMip<R8>, NoCopyFunctions, ReadColor<R8, GLfloat>, WriteColor<R8, GLfloat>, GL_UNSIGNED_NORMALIZED, 8, 0, 0, 0, 0, 0, 0, 1, 0, false, false, false, gl::VertexAttribType::Byte },
{ FormatID::R8_USCALED, GL_R8_USCALED_ANGLEX, GL_R8_USCALED_ANGLEX, GenerateMip<R8>, NoCopyFunctions, ReadColor<R8, GLuint>, WriteColor<R8, GLuint>, GL_UNSIGNED_INT, 8, 0, 0, 0, 0, 0, 0, 1, 0, false, false, true, gl::VertexAttribType::UnsignedByte },
{ FormatID::R9G9B9E5_SHAREDEXP, GL_RGB9_E5, GL_RGB9_E5, GenerateMip<R9G9B9E5>, NoCopyFunctions, ReadColor<R9G9B9E5, GLfloat>, WriteColor<R9G9B9E5, GLfloat>, GL_FLOAT, 9, 9, 9, 0, 0, 0, 0, 4, std::numeric_limits<GLuint>::max(), false, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::S8_UINT, GL_STENCIL_INDEX8, GL_STENCIL_INDEX8, nullptr, NoCopyFunctions, ReadDepthStencil<S8>, WriteDepthStencil<S8>, GL_UNSIGNED_INT, 0, 0, 0, 0, 0, 0, 8, 1, std::numeric_limits<GLuint>::max(), false, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::X2R10G10B10_SINT_VERTEX, GL_X2_RGB10_SINT_ANGLEX, GL_X2_RGB10_SINT_ANGLEX, nullptr, NoCopyFunctions, nullptr, nullptr, GL_INT, 10, 10, 10, 0, 0, 0, 0, 4, std::numeric_limits<GLuint>::max(), false, false, false, gl::VertexAttribType::Int1010102 },
{ FormatID::X2R10G10B10_SNORM_VERTEX, GL_X2_RGB10_SNORM_ANGLEX, GL_X2_RGB10_SNORM_ANGLEX, nullptr, NoCopyFunctions, nullptr, nullptr, GL_SIGNED_NORMALIZED, 10, 10, 10, 0, 0, 0, 0, 4, std::numeric_limits<GLuint>::max(), false, false, false, gl::VertexAttribType::Int1010102 },
{ FormatID::X2R10G10B10_SSCALED_VERTEX, GL_X2_RGB10_SSCALED_ANGLEX, GL_X2_RGB10_SSCALED_ANGLEX, nullptr, NoCopyFunctions, nullptr, nullptr, GL_INT, 10, 10, 10, 0, 0, 0, 0, 4, std::numeric_limits<GLuint>::max(), false, false, true, gl::VertexAttribType::Int1010102 },

View File

@@ -343,21 +343,36 @@ def json_to_table_data(format_id, json, angle_to_gl):
return format_entry_template.format(**parsed)
# For convenience of the Vulkan backend, place depth/stencil formats first. This allows
# depth/stencil format IDs to be placed in only a few bits.
def sorted_ds_first(all_angle):
ds_sorted = []
color_sorted = []
for format_id in sorted(all_angle):
if format_id == 'NONE':
continue
if format_id[0] == 'D' or format_id[0] == 'S':
ds_sorted.append(format_id)
else:
color_sorted.append(format_id)
return ds_sorted + color_sorted
def parse_angle_format_table(all_angle, json_data, angle_to_gl):
table_data = ''
for format_id in sorted(all_angle):
if format_id != "NONE":
format_info = json_data[format_id] if format_id in json_data else {}
table_data += json_to_table_data(format_id, format_info, angle_to_gl)
for format_id in sorted_ds_first(all_angle):
assert (format_id != 'NONE')
format_info = json_data[format_id] if format_id in json_data else {}
table_data += json_to_table_data(format_id, format_info, angle_to_gl)
return table_data
def gen_enum_string(all_angle):
enum_data = ' NONE'
for format_id in sorted(all_angle):
if format_id == 'NONE':
continue
for format_id in sorted_ds_first(all_angle):
assert (format_id != 'NONE')
enum_data += ',\n ' + format_id
return enum_data

View File

@@ -510,8 +510,10 @@ void RenderPassDesc::packColorAttachment(size_t colorIndexGL, angle::FormatID fo
uint8_t &packedFormat = mAttachmentFormats[colorIndexGL];
SetBitField(packedFormat, formatID);
// Set color attachment range such that it covers the range from index 0 through last
// active index. This is the reason why we need depth/stencil to be packed last.
// Set color attachment range such that it covers the range from index 0 through last active
// index. Additionally, a few bits at the end of the array are used for other purposes, so we
// need the last format to use only a few bits. These are the reasons why we need depth/stencil
// to be packed last.
SetBitField(mPackedColorAttachmentRangeAndDSAccess,
std::max<size_t>(mPackedColorAttachmentRangeAndDSAccess, colorIndexGL + 1));
}
@@ -534,11 +536,15 @@ void RenderPassDesc::packDepthStencilAttachment(angle::FormatID formatID, Resour
ASSERT(access != ResourceAccess::Unused);
ASSERT(!hasDepthStencilAttachment());
// 3 bits are used to store the depth/stencil attachment format.
ASSERT(static_cast<uint8_t>(formatID) <= kDepthStencilFormatStorageMask);
size_t index = depthStencilAttachmentIndex();
ASSERT(index < mAttachmentFormats.size());
uint8_t &packedFormat = mAttachmentFormats[index];
SetBitField(packedFormat, formatID);
packedFormat &= ~kDepthStencilFormatStorageMask;
packedFormat |= static_cast<uint8_t>(formatID);
size_t colorRange = colorAttachmentRange();
size_t offset =

View File

@@ -165,7 +165,13 @@ class alignas(4) RenderPassDesc final
angle::FormatID operator[](size_t index) const
{
ASSERT(index < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS + 1);
return static_cast<angle::FormatID>(mAttachmentFormats[index]);
uint8_t format = mAttachmentFormats[index];
if (index >= depthStencilAttachmentIndex())
{
format &= kDepthStencilFormatStorageMask;
}
return static_cast<angle::FormatID>(format);
}
private:
@@ -213,7 +219,14 @@ class alignas(4) RenderPassDesc final
//
// The resolve attachments are packed after the non-resolve attachments. They use the same
// formats, so they are not specified in this array.
//
// The depth/stencil angle::FormatID values are in the range [1, 7], and therefore require only
// 3 bits to be stored. As a result, the upper 5 bits of mAttachmentFormats.back() is free to
// use for other purposes.
FramebufferNonResolveAttachmentArray<uint8_t> mAttachmentFormats;
// Depth/stencil format is stored in 3 bits.
static constexpr uint8_t kDepthStencilFormatStorageMask = 0x7;
};
bool operator==(const RenderPassDesc &lhs, const RenderPassDesc &rhs);