[Impeller] when binding to READ_FRAMEBUFFER, treat multisampled textures as single sampled. (#163345)

I noticed this causes crashes when doing readback, but only on some
deivces. I suspect that this is the more correct binding choice, and
other drivers are just more lenient.
This commit is contained in:
Jonah Williams 2025-02-18 10:20:09 -08:00 committed by GitHub
parent c12330fd21
commit 063d0da3c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 1 deletions

View File

@ -65,4 +65,23 @@ TEST_P(TextureGLESTest, CanSetSyncFence) {
ASSERT_FALSE(sync_fence.has_value());
}
TEST_P(TextureGLESTest, Binds2DTexture) {
TextureDescriptor desc;
desc.storage_mode = StorageMode::kDevicePrivate;
desc.size = {100, 100};
desc.format = PixelFormat::kR8G8B8A8UNormInt;
desc.type = TextureType::kTexture2DMultisample;
desc.sample_count = SampleCount::kCount4;
auto texture = GetContext()->GetResourceAllocator()->CreateTexture(desc);
ASSERT_TRUE(texture);
EXPECT_EQ(
TextureGLES::Cast(*texture).ComputeTypeForBinding(GL_READ_FRAMEBUFFER),
TextureGLES::Type::kTexture);
EXPECT_EQ(TextureGLES::Cast(*texture).ComputeTypeForBinding(GL_FRAMEBUFFER),
TextureGLES::Type::kTextureMultisampled);
}
} // namespace impeller::testing

View File

@ -392,6 +392,15 @@ static std::optional<GLenum> ToRenderBufferFormat(PixelFormat format) {
FML_UNREACHABLE();
}
TextureGLES::Type TextureGLES::ComputeTypeForBinding(GLenum target) const {
// When binding to a GL_READ_FRAMEBUFFER, any multisampled
// textures must be bound as single sampled.
if (target == GL_READ_FRAMEBUFFER && type_ == Type::kTextureMultisampled) {
return Type::kTexture;
}
return type_;
}
void TextureGLES::InitializeContentsIfNecessary() const {
if (!IsValid() || slices_initialized_[0]) {
return;
@ -588,7 +597,7 @@ bool TextureGLES::SetAsFramebufferAttachment(
}
const auto& gl = reactor_->GetProcTable();
switch (type_) {
switch (ComputeTypeForBinding(target)) {
case Type::kTexture:
gl.FramebufferTexture2D(target, // target
ToAttachmentType(attachment_type), // attachment

View File

@ -144,6 +144,9 @@ class TextureGLES final : public Texture,
// Visible for testing.
std::optional<HandleGLES> GetSyncFence() const;
// visible for testing
Type ComputeTypeForBinding(GLenum target) const;
private:
std::shared_ptr<ReactorGLES> reactor_;
const Type type_;