[Flutter GPU] Fix assert failure in createDeviceBufferWithCopy. (flutter/engine#56039)

Resolves https://github.com/flutter/flutter/issues/157336

`DartByteData` gets raw pointers into the Dart heap via `Dart_TypedDataAcquireData`. So it must be destructed before `AssociateWithDartWrapper` is called, which mutates the heap.

Re-enables failing test for Linux unopt.
This commit is contained in:
Brandon DeRosier
2024-10-22 22:08:03 -07:00
committed by GitHub
parent 1fbd217c0e
commit 026062f08b
2 changed files with 12 additions and 14 deletions

View File

@@ -74,12 +74,18 @@ bool InternalFlutterGpu_DeviceBuffer_InitializeWithHostData(
Dart_Handle wrapper,
flutter::gpu::Context* gpu_context,
Dart_Handle byte_data) {
auto data = tonic::DartByteData(byte_data);
auto mapping = fml::NonOwnedMapping(reinterpret_cast<uint8_t*>(data.data()),
data.length_in_bytes());
auto device_buffer =
gpu_context->GetContext()->GetResourceAllocator()->CreateBufferWithCopy(
mapping);
std::shared_ptr<impeller::DeviceBuffer> device_buffer = nullptr;
{
// `DartByteData` gets raw pointers into the Dart heap via
// `Dart_TypedDataAcquireData`. So it must be destructed before
// `AssociateWithDartWrapper` is called, which mutates the heap.
auto data = tonic::DartByteData(byte_data);
auto mapping = fml::NonOwnedMapping(reinterpret_cast<uint8_t*>(data.data()),
data.length_in_bytes());
device_buffer =
gpu_context->GetContext()->GetResourceAllocator()->CreateBufferWithCopy(
mapping);
}
if (!device_buffer) {
FML_LOG(ERROR) << "Failed to create device buffer with copy.";
return false;

View File

@@ -7,7 +7,6 @@
// ignore_for_file: avoid_relative_lib_imports
import 'dart:io';
import 'dart:typed_data';
import 'dart:ui' as ui;
@@ -398,13 +397,6 @@ void main() async {
// Regression test for https://github.com/flutter/flutter/issues/157324
test('Can bind uniforms in range', () async {
// TODO(bdero): createDeviceBufferWithCopy triggers an assert in
// third_party/dart on Linux.
// https://github.com/flutter/flutter/issues/157336
if (Platform.isLinux) {
return;
}
final state = createSimpleRenderPass();
final gpu.RenderPipeline pipeline = createUnlitRenderPipeline();