[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:
parent
c12330fd21
commit
063d0da3c0
@ -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
|
||||
|
@ -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
|
||||
|
@ -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_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user