Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit c0dda02

Browse files
cclaoCommit Bot
authored andcommitted
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/+/2378179 Reviewed-by: back sept 10 - Jamie Madill <[email protected]> Reviewed-by: Courtney Goeltzenleuchter <[email protected]> Reviewed-by: Shahbaz Youssefi <[email protected]> Commit-Queue: Charlie Lao <[email protected]>
1 parent 59d2853 commit c0dda02

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

src/libANGLE/renderer/vulkan/TextureVk.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,8 @@ angle::Result TextureVk::setSubImageImpl(const gl::Context *context,
373373
// Use context's staging buffer for immutable textures and flush out updates
374374
// immediately.
375375
vk::DynamicBuffer *stagingBuffer = nullptr;
376-
if (!mOwnsImage || mState.getImmutableFormat())
376+
if (!mOwnsImage || mState.getImmutableFormat() ||
377+
(mImage->valid() && !shouldUpdateBeStaged(gl::LevelIndex(index.getLevelIndex()))))
377378
{
378379
stagingBuffer = contextVk->getStagingBuffer();
379380
}

src/libANGLE/renderer/vulkan/vk_helpers.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4598,6 +4598,7 @@ angle::Result ImageHelper::flushStagedUpdates(ContextVk *contextVk,
45984598
if (mSubresourceUpdates.empty())
45994599
{
46004600
mStagingBuffer.releaseInFlightBuffers(contextVk);
4601+
mStagingBuffer.release(contextVk->getRenderer());
46014602
}
46024603

46034604
return angle::Result::Continue;

src/tests/gl_tests/TextureTest.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3175,6 +3175,51 @@ TEST_P(Texture2DBaseMaxTestES3, GenerateMipmapAfterRedefiningBaseAndChangingMax)
31753175
}
31763176
}
31773177

3178+
// Test that stage invalid texture levels work.
3179+
TEST_P(Texture2DBaseMaxTestES3, StageInvalidLevels)
3180+
{
3181+
constexpr uint32_t kMaxLevel = 2;
3182+
const GLColor kMipColor[kMaxLevel + 1] = {GLColor::red, GLColor::green, GLColor::blue};
3183+
3184+
initTest();
3185+
3186+
GLTexture texture;
3187+
glBindTexture(GL_TEXTURE_2D, texture);
3188+
3189+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3190+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3191+
std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
3192+
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataCyan.data());
3193+
setLodUniform(0);
3194+
drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
3195+
EXPECT_GL_NO_ERROR();
3196+
3197+
std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
3198+
glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3199+
texDataGreen.data());
3200+
glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::blue);
3201+
drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
3202+
EXPECT_GL_NO_ERROR();
3203+
3204+
std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
3205+
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
3206+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
3207+
drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
3208+
3209+
// Test that the texture looks as expected.
3210+
const int w = getWindowWidth() - 1;
3211+
const int h = getWindowHeight() - 1;
3212+
for (uint32_t lod = 0; lod <= kMaxLevel; ++lod)
3213+
{
3214+
setLodUniform(lod);
3215+
drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
3216+
EXPECT_PIXEL_COLOR_EQ(0, 0, kMipColor[lod]);
3217+
EXPECT_PIXEL_COLOR_EQ(w, 0, kMipColor[lod]);
3218+
EXPECT_PIXEL_COLOR_EQ(0, h, kMipColor[lod]);
3219+
EXPECT_PIXEL_COLOR_EQ(w, h, kMipColor[lod]);
3220+
}
3221+
}
3222+
31783223
// Test to check that texture completeness is determined correctly when the texture base level is
31793224
// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
31803225
TEST_P(Texture2DTestES3, DrawWithBaseLevel1)

0 commit comments

Comments
 (0)