Commit 9bad7a19 by Shahbaz Youssefi Committed by Angle LUCI CQ

Vulkan: Unpack RenderPassDesc

Upcoming multiview support needs to add 2~3 more bits to this struct, but this struct is already fully packed. As the combination with emulated multisampled render to texture is not planned, some bits used for MSRTT can be aliased with multiview. However, that makes the packing of this struct even more unwieldy. Since only tens of render passes are expected per frame, increasing the size of the render pass cache key should not have a dramatic effect. Bug: angleproject:6048 Change-Id: I5c9a0d155f23a37e2787b38525d3ce721b54ec1e Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2966218 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarCharlie Lao <cclao@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent b6009f64
...@@ -1368,28 +1368,6 @@ RenderPassDesc::RenderPassDesc(const RenderPassDesc &other) ...@@ -1368,28 +1368,6 @@ RenderPassDesc::RenderPassDesc(const RenderPassDesc &other)
memcpy(this, &other, sizeof(RenderPassDesc)); memcpy(this, &other, sizeof(RenderPassDesc));
} }
void RenderPassDesc::setSamples(GLint samples)
{
SetBitField(mLogSamples, PackSampleCount(samples));
}
void RenderPassDesc::setFramebufferFetchMode(bool hasFramebufferFetch)
{
SetBitField(mHasFramebufferFetch, hasFramebufferFetch);
}
void RenderPassDesc::updateRenderToTexture(bool isRenderToTexture)
{
if (isRenderToTexture)
{
mAttachmentFormats.back() |= kIsRenderToTexture;
}
else
{
mAttachmentFormats.back() &= ~kIsRenderToTexture;
}
}
void RenderPassDesc::packColorAttachment(size_t colorIndexGL, angle::FormatID formatID) void RenderPassDesc::packColorAttachment(size_t colorIndexGL, angle::FormatID formatID)
{ {
ASSERT(colorIndexGL < mAttachmentFormats.size()); ASSERT(colorIndexGL < mAttachmentFormats.size());
...@@ -1404,9 +1382,7 @@ void RenderPassDesc::packColorAttachment(size_t colorIndexGL, angle::FormatID fo ...@@ -1404,9 +1382,7 @@ void RenderPassDesc::packColorAttachment(size_t colorIndexGL, angle::FormatID fo
SetBitField(packedFormat, formatID); SetBitField(packedFormat, formatID);
// Set color attachment range such that it covers the range from index 0 through last active // 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 // index. This is the reasons why we need depth/stencil to be packed last.
// need the last format to use only a few bits. These are the reasons why we need depth/stencil
// to be packed last.
SetBitField(mColorAttachmentRange, std::max<size_t>(mColorAttachmentRange, colorIndexGL + 1)); SetBitField(mColorAttachmentRange, std::max<size_t>(mColorAttachmentRange, colorIndexGL + 1));
} }
...@@ -1425,12 +1401,8 @@ void RenderPassDesc::packColorAttachmentGap(size_t colorIndexGL) ...@@ -1425,12 +1401,8 @@ void RenderPassDesc::packColorAttachmentGap(size_t colorIndexGL)
void RenderPassDesc::packDepthStencilAttachment(angle::FormatID formatID) void RenderPassDesc::packDepthStencilAttachment(angle::FormatID formatID)
{ {
// Though written as Count, there is only ever a single depth/stencil attachment.
ASSERT(!hasDepthStencilAttachment()); ASSERT(!hasDepthStencilAttachment());
// 3 bits are used to store the depth/stencil attachment format.
ASSERT(static_cast<uint8_t>(formatID) <= kDepthStencilFormatStorageMask);
size_t index = depthStencilAttachmentIndex(); size_t index = depthStencilAttachmentIndex();
ASSERT(index < mAttachmentFormats.size()); ASSERT(index < mAttachmentFormats.size());
...@@ -1442,7 +1414,7 @@ void RenderPassDesc::packColorResolveAttachment(size_t colorIndexGL) ...@@ -1442,7 +1414,7 @@ void RenderPassDesc::packColorResolveAttachment(size_t colorIndexGL)
{ {
ASSERT(isColorAttachmentEnabled(colorIndexGL)); ASSERT(isColorAttachmentEnabled(colorIndexGL));
ASSERT(!mColorResolveAttachmentMask.test(colorIndexGL)); ASSERT(!mColorResolveAttachmentMask.test(colorIndexGL));
ASSERT(mLogSamples > 0); ASSERT(mSamples > 1);
mColorResolveAttachmentMask.set(colorIndexGL); mColorResolveAttachmentMask.set(colorIndexGL);
} }
...@@ -1467,33 +1439,21 @@ void RenderPassDesc::packDepthStencilResolveAttachment() ...@@ -1467,33 +1439,21 @@ void RenderPassDesc::packDepthStencilResolveAttachment()
ASSERT(hasDepthStencilAttachment()); ASSERT(hasDepthStencilAttachment());
ASSERT(!hasDepthStencilResolveAttachment()); ASSERT(!hasDepthStencilResolveAttachment());
static_assert((kDepthStencilFormatStorageMask & kResolveDepthStencilFlag) == 0, mResolveDepthStencil = true;
"Collision in depth/stencil format and flag bits");
mAttachmentFormats.back() |= kResolveDepthStencilFlag;
} }
void RenderPassDesc::packDepthStencilUnresolveAttachment(bool unresolveDepth, bool unresolveStencil) void RenderPassDesc::packDepthStencilUnresolveAttachment(bool unresolveDepth, bool unresolveStencil)
{ {
ASSERT(hasDepthStencilAttachment()); ASSERT(hasDepthStencilAttachment());
static_assert( mUnresolveDepth = unresolveDepth;
(kDepthStencilFormatStorageMask & (kUnresolveDepthFlag | kUnresolveStencilFlag)) == 0, mUnresolveStencil = unresolveStencil;
"Collision in depth/stencil format and flag bits");
if (unresolveDepth)
{
mAttachmentFormats.back() |= kUnresolveDepthFlag;
}
if (unresolveStencil)
{
mAttachmentFormats.back() |= kUnresolveStencilFlag;
}
} }
void RenderPassDesc::removeDepthStencilUnresolveAttachment() void RenderPassDesc::removeDepthStencilUnresolveAttachment()
{ {
mAttachmentFormats.back() &= ~(kUnresolveDepthFlag | kUnresolveStencilFlag); mUnresolveDepth = false;
mUnresolveStencil = false;
} }
RenderPassDesc &RenderPassDesc::operator=(const RenderPassDesc &other) RenderPassDesc &RenderPassDesc::operator=(const RenderPassDesc &other)
...@@ -1504,14 +1464,7 @@ RenderPassDesc &RenderPassDesc::operator=(const RenderPassDesc &other) ...@@ -1504,14 +1464,7 @@ RenderPassDesc &RenderPassDesc::operator=(const RenderPassDesc &other)
void RenderPassDesc::setWriteControlMode(gl::SrgbWriteControlMode mode) void RenderPassDesc::setWriteControlMode(gl::SrgbWriteControlMode mode)
{ {
if (mode == gl::SrgbWriteControlMode::Default) SetBitField(mSrgbWriteControl, mode);
{
mAttachmentFormats.back() &= ~kSrgbWriteControlFlag;
}
else
{
mAttachmentFormats.back() |= kSrgbWriteControlFlag;
}
} }
size_t RenderPassDesc::hash() const size_t RenderPassDesc::hash() const
......
...@@ -185,61 +185,60 @@ class alignas(4) RenderPassDesc final ...@@ -185,61 +185,60 @@ class alignas(4) RenderPassDesc final
{ {
return mColorUnresolveAttachmentMask.test(colorIndexGL); return mColorUnresolveAttachmentMask.test(colorIndexGL);
} }
bool hasDepthStencilResolveAttachment() const bool hasDepthStencilResolveAttachment() const { return mResolveDepthStencil; }
{ bool hasDepthStencilUnresolveAttachment() const { return mUnresolveDepth || mUnresolveStencil; }
return (mAttachmentFormats.back() & kResolveDepthStencilFlag) != 0; bool hasDepthUnresolveAttachment() const { return mUnresolveDepth; }
} bool hasStencilUnresolveAttachment() const { return mUnresolveStencil; }
bool hasDepthStencilUnresolveAttachment() const
{
return (mAttachmentFormats.back() & (kUnresolveDepthFlag | kUnresolveStencilFlag)) != 0;
}
bool hasDepthUnresolveAttachment() const
{
return (mAttachmentFormats.back() & kUnresolveDepthFlag) != 0;
}
bool hasStencilUnresolveAttachment() const
{
return (mAttachmentFormats.back() & kUnresolveStencilFlag) != 0;
}
gl::SrgbWriteControlMode getSRGBWriteControlMode() const gl::SrgbWriteControlMode getSRGBWriteControlMode() const
{ {
return ((mAttachmentFormats.back() & kSrgbWriteControlFlag) != 0) return static_cast<gl::SrgbWriteControlMode>(mSrgbWriteControl);
? gl::SrgbWriteControlMode::Linear
: gl::SrgbWriteControlMode::Default;
} }
// Get the number of attachments in the Vulkan render pass, i.e. after removing disabled // Get the number of attachments in the Vulkan render pass, i.e. after removing disabled
// color attachments. // color attachments.
size_t attachmentCount() const; size_t attachmentCount() const;
void setSamples(GLint samples); void setSamples(GLint samples) { mSamples = static_cast<uint8_t>(samples); }
uint8_t samples() const { return mSamples; }
uint8_t samples() const { return 1u << mLogSamples; } void setFramebufferFetchMode(bool hasFramebufferFetch)
{
mHasFramebufferFetch = hasFramebufferFetch;
}
void setFramebufferFetchMode(bool hasFramebufferFetch);
bool getFramebufferFetchMode() const { return mHasFramebufferFetch; } bool getFramebufferFetchMode() const { return mHasFramebufferFetch; }
void updateRenderToTexture(bool isRenderToTexture); void updateRenderToTexture(bool isRenderToTexture) { mIsRenderToTexture = isRenderToTexture; }
bool isRenderToTexture() const { return (mAttachmentFormats.back() & kIsRenderToTexture) != 0; } bool isRenderToTexture() const { return mIsRenderToTexture; }
angle::FormatID operator[](size_t index) const angle::FormatID operator[](size_t index) const
{ {
ASSERT(index < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS + 1); 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: private:
// Store log(samples), to be able to store it in 3 bits. uint8_t mSamples;
uint8_t mLogSamples : 3; uint8_t mColorAttachmentRange;
uint8_t mColorAttachmentRange : 4; // TODO: For upcoming multiview support. http://anglebug.com/6048
uint8_t mViewCount;
// sRGB
uint8_t mSrgbWriteControl : 1;
// Framebuffer fetch
uint8_t mHasFramebufferFetch : 1; uint8_t mHasFramebufferFetch : 1;
// Multisampled render to texture
uint8_t mIsRenderToTexture : 1;
uint8_t mResolveDepthStencil : 1;
uint8_t mUnresolveDepth : 1;
uint8_t mUnresolveStencil : 1;
// Available space for expansion.
uint8_t mPadding1 : 2;
uint8_t mPadding2;
// Whether each color attachment has a corresponding resolve attachment. Color resolve // Whether each color attachment has a corresponding resolve attachment. Color resolve
// attachments can be used to optimize resolve through glBlitFramebuffer() as well as support // attachments can be used to optimize resolve through glBlitFramebuffer() as well as support
// GL_EXT_multisampled_render_to_texture and GL_EXT_multisampled_render_to_texture2. // GL_EXT_multisampled_render_to_texture and GL_EXT_multisampled_render_to_texture2.
...@@ -275,27 +274,13 @@ class alignas(4) RenderPassDesc final ...@@ -275,27 +274,13 @@ class alignas(4) RenderPassDesc final
// //
// The resolve attachments are packed after the non-resolve attachments. They use the same // The resolve attachments are packed after the non-resolve attachments. They use the same
// formats, so they are not specified in this array. // 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; FramebufferNonResolveAttachmentArray<uint8_t> mAttachmentFormats;
// Depth/stencil format is stored in 3 bits.
static constexpr uint8_t kDepthStencilFormatStorageMask = 0x7;
// Flags stored in the upper 5 bits of mAttachmentFormats.back().
static constexpr uint8_t kIsRenderToTexture = 0x80;
static constexpr uint8_t kResolveDepthStencilFlag = 0x40;
static constexpr uint8_t kUnresolveDepthFlag = 0x20;
static constexpr uint8_t kUnresolveStencilFlag = 0x10;
static constexpr uint8_t kSrgbWriteControlFlag = 0x08;
}; };
bool operator==(const RenderPassDesc &lhs, const RenderPassDesc &rhs); bool operator==(const RenderPassDesc &lhs, const RenderPassDesc &rhs);
constexpr size_t kRenderPassDescSize = sizeof(RenderPassDesc); constexpr size_t kRenderPassDescSize = sizeof(RenderPassDesc);
static_assert(kRenderPassDescSize == 12, "Size check failed"); static_assert(kRenderPassDescSize == 16, "Size check failed");
struct PackedAttachmentOpsDesc final struct PackedAttachmentOpsDesc final
{ {
......
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