Commit c0dda021 by Charlie Lao Committed by Commit Bot

Vulkan: release the ImageHelper's staging buffer after flush

For mutable textures, right now glTexImage call and some of other cases, we are still using the ImageHelper's staging buffer. This will release the staging buffer after flush to reduce memory footprint. Bug: b/164511310 Change-Id: Ie1e52865a1c3a8f235c88331c4bb83c50d3f04da Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2378179Reviewed-by: 's avatarback sept 10 - Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCourtney Goeltzenleuchter <courtneygo@google.com> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Charlie Lao <cclao@google.com>
parent 59d28532
...@@ -373,7 +373,8 @@ angle::Result TextureVk::setSubImageImpl(const gl::Context *context, ...@@ -373,7 +373,8 @@ angle::Result TextureVk::setSubImageImpl(const gl::Context *context,
// Use context's staging buffer for immutable textures and flush out updates // Use context's staging buffer for immutable textures and flush out updates
// immediately. // immediately.
vk::DynamicBuffer *stagingBuffer = nullptr; vk::DynamicBuffer *stagingBuffer = nullptr;
if (!mOwnsImage || mState.getImmutableFormat()) if (!mOwnsImage || mState.getImmutableFormat() ||
(mImage->valid() && !shouldUpdateBeStaged(gl::LevelIndex(index.getLevelIndex()))))
{ {
stagingBuffer = contextVk->getStagingBuffer(); stagingBuffer = contextVk->getStagingBuffer();
} }
......
...@@ -4598,6 +4598,7 @@ angle::Result ImageHelper::flushStagedUpdates(ContextVk *contextVk, ...@@ -4598,6 +4598,7 @@ angle::Result ImageHelper::flushStagedUpdates(ContextVk *contextVk,
if (mSubresourceUpdates.empty()) if (mSubresourceUpdates.empty())
{ {
mStagingBuffer.releaseInFlightBuffers(contextVk); mStagingBuffer.releaseInFlightBuffers(contextVk);
mStagingBuffer.release(contextVk->getRenderer());
} }
return angle::Result::Continue; return angle::Result::Continue;
......
...@@ -3175,6 +3175,51 @@ TEST_P(Texture2DBaseMaxTestES3, GenerateMipmapAfterRedefiningBaseAndChangingMax) ...@@ -3175,6 +3175,51 @@ TEST_P(Texture2DBaseMaxTestES3, GenerateMipmapAfterRedefiningBaseAndChangingMax)
} }
} }
// Test that stage invalid texture levels work.
TEST_P(Texture2DBaseMaxTestES3, StageInvalidLevels)
{
constexpr uint32_t kMaxLevel = 2;
const GLColor kMipColor[kMaxLevel + 1] = {GLColor::red, GLColor::green, GLColor::blue};
initTest();
GLTexture texture;
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataCyan.data());
setLodUniform(0);
drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
EXPECT_GL_NO_ERROR();
std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
texDataGreen.data());
glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::blue);
drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
EXPECT_GL_NO_ERROR();
std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
// Test that the texture looks as expected.
const int w = getWindowWidth() - 1;
const int h = getWindowHeight() - 1;
for (uint32_t lod = 0; lod <= kMaxLevel; ++lod)
{
setLodUniform(lod);
drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
EXPECT_PIXEL_COLOR_EQ(0, 0, kMipColor[lod]);
EXPECT_PIXEL_COLOR_EQ(w, 0, kMipColor[lod]);
EXPECT_PIXEL_COLOR_EQ(0, h, kMipColor[lod]);
EXPECT_PIXEL_COLOR_EQ(w, h, kMipColor[lod]);
}
}
// Test to check that texture completeness is determined correctly when the texture base level is // Test to check that texture completeness is determined correctly when the texture base level is
// greater than 0, and also that level 0 is not sampled when base level is greater than 0. // greater than 0, and also that level 0 is not sampled when base level is greater than 0.
TEST_P(Texture2DTestES3, DrawWithBaseLevel1) TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
......
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