From b47554ba0aecfd9f8d011c0a5bddad970795ff64 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Mon, 14 Aug 2023 12:41:24 -0700 Subject: [PATCH 1/5] [Impeller] Flutter GPU: Add HostBuffer. --- ci/licenses_golden/licenses_flutter | 6 ++ impeller/fixtures/dart_tests.dart | 16 +++++ impeller/renderer/renderer_dart_unittests.cc | 14 ++++ lib/gpu/BUILD.gn | 2 + lib/gpu/context.cc | 14 ++-- lib/gpu/context.h | 9 +-- lib/gpu/host_buffer.cc | 40 +++++++++++ lib/gpu/host_buffer.h | 47 +++++++++++++ lib/gpu/lib/gpu.dart | 4 +- lib/gpu/lib/src/buffer.dart | 73 ++++++++++++++++++++ lib/gpu/lib/src/context.dart | 8 +++ 11 files changed, 223 insertions(+), 10 deletions(-) create mode 100644 lib/gpu/host_buffer.cc create mode 100644 lib/gpu/host_buffer.h create mode 100644 lib/gpu/lib/src/buffer.dart diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 5ea50c1f38d6e..1c8936027b0f5 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -1730,7 +1730,10 @@ ORIGIN: ../../../flutter/lib/gpu/export.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/gpu/export.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/gpu/lib/gpu.dart + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/gpu/lib/src/context.dart + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/lib/gpu/lib/src/host_buffer.dart + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/gpu/lib/src/smoketest.dart + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/lib/gpu/host_buffer.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/lib/gpu/host_buffer.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/gpu/smoketest.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/gpu/smoketest.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/io/dart_io.cc + ../../../flutter/LICENSE @@ -4458,7 +4461,10 @@ FILE: ../../../flutter/lib/gpu/export.cc FILE: ../../../flutter/lib/gpu/export.h FILE: ../../../flutter/lib/gpu/lib/gpu.dart FILE: ../../../flutter/lib/gpu/lib/src/context.dart +FILE: ../../../flutter/lib/gpu/lib/src/host_buffer.dart FILE: ../../../flutter/lib/gpu/lib/src/smoketest.dart +FILE: ../../../flutter/lib/gpu/host_buffer.cc +FILE: ../../../flutter/lib/gpu/host_buffer.h FILE: ../../../flutter/lib/gpu/smoketest.cc FILE: ../../../flutter/lib/gpu/smoketest.h FILE: ../../../flutter/lib/io/dart_io.cc diff --git a/impeller/fixtures/dart_tests.dart b/impeller/fixtures/dart_tests.dart index ad6ad54c335da..72aa7b1ff3a94 100644 --- a/impeller/fixtures/dart_tests.dart +++ b/impeller/fixtures/dart_tests.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:typed_data'; import 'dart:ui' as ui; import '../../lib/gpu/lib/gpu.dart' as gpu; @@ -17,3 +18,18 @@ void instantiateDefaultContext() { // ignore: unused_local_variable final gpu.GpuContext context = gpu.gpuContext; } + +@pragma('vm:entry-point') +void canEmplaceHostBuffer() { + final gpu.HostBuffer hostBuffer = gpu.gpuContext.createHostBuffer(); + + final gpu.BufferView view0 = hostBuffer.emplaceBytes( + bytes: Int8List.fromList([0, 1, 2, 3]).buffer.asByteData()); + assert(view0.offsetInBytes == 0); + assert(view0.lengthInBytes == 4); + + final gpu.BufferView view1 = hostBuffer.emplaceBytes( + bytes: Int8List.fromList([0, 1, 2, 3]).buffer.asByteData()); + assert(view1.offsetInBytes >= 4); + assert(view1.lengthInBytes == 4); +} diff --git a/impeller/renderer/renderer_dart_unittests.cc b/impeller/renderer/renderer_dart_unittests.cc index 91a84bae2b7b9..b8893461e7d7c 100644 --- a/impeller/renderer/renderer_dart_unittests.cc +++ b/impeller/renderer/renderer_dart_unittests.cc @@ -111,5 +111,19 @@ TEST_P(RendererDartTest, CanInstantiateFlutterGPUContext) { ASSERT_TRUE(result); } +TEST_P(RendererDartTest, CanEmplaceHostBuffer) { + auto isolate = GetIsolate(); + bool result = isolate->RunInIsolateScope([]() -> bool { + if (tonic::CheckAndHandleError( + ::Dart_Invoke(Dart_RootLibrary(), + tonic::ToDart("canEmplaceHostBuffer"), 0, nullptr))) { + return false; + } + return true; + }); + + ASSERT_TRUE(result); +} + } // namespace testing } // namespace impeller diff --git a/lib/gpu/BUILD.gn b/lib/gpu/BUILD.gn index 188637666c731..689e2f3ef8974 100644 --- a/lib/gpu/BUILD.gn +++ b/lib/gpu/BUILD.gn @@ -36,6 +36,8 @@ source_set("gpu") { "context.h", "export.cc", "export.h", + "host_buffer.cc", + "host_buffer.h", "smoketest.cc", "smoketest.h", ] diff --git a/lib/gpu/context.cc b/lib/gpu/context.cc index 303c5d4e82c17..34418320b5ddc 100644 --- a/lib/gpu/context.cc +++ b/lib/gpu/context.cc @@ -15,14 +15,14 @@ namespace flutter { IMPLEMENT_WRAPPERTYPEINFO(gpu, Context); -std::shared_ptr Context::override_context_; +std::shared_ptr Context::default_context_; void Context::SetOverrideContext(std::shared_ptr context) { - override_context_ = std::move(context); + default_context_ = std::move(context); } -std::shared_ptr Context::GetOverrideContext() { - return override_context_; +std::shared_ptr Context::GetDefaultContext() { + return default_context_; } Context::Context(std::shared_ptr context) @@ -30,6 +30,10 @@ Context::Context(std::shared_ptr context) Context::~Context() = default; +std::shared_ptr Context::GetContext() { + return context_; +} + } // namespace flutter //---------------------------------------------------------------------------- @@ -40,7 +44,7 @@ Dart_Handle InternalFlutterGpu_Context_InitializeDefault(Dart_Handle wrapper) { auto dart_state = flutter::UIDartState::Current(); std::shared_ptr impeller_context = - flutter::Context::GetOverrideContext(); + flutter::Context::GetDefaultContext(); if (!impeller_context) { if (!dart_state->IsImpellerEnabled()) { diff --git a/lib/gpu/context.h b/lib/gpu/context.h index 3133845624f15..15365386ad0aa 100644 --- a/lib/gpu/context.h +++ b/lib/gpu/context.h @@ -18,18 +18,19 @@ class Context : public RefCountedDartWrappable { public: static void SetOverrideContext(std::shared_ptr context); - static std::shared_ptr GetOverrideContext(); + static std::shared_ptr GetDefaultContext(); explicit Context(std::shared_ptr context); ~Context() override; - protected: + std::shared_ptr GetContext(); + + private: /// An Impeller context that takes precedent over the IO state context when /// set. This is used to inject the context when running with the Impeller /// playground, which doesn't instantiate an Engine instance. - static std::shared_ptr override_context_; + static std::shared_ptr default_context_; - private: std::shared_ptr context_; FML_DISALLOW_COPY_AND_ASSIGN(Context); diff --git a/lib/gpu/host_buffer.cc b/lib/gpu/host_buffer.cc new file mode 100644 index 0000000000000..25581cba78d28 --- /dev/null +++ b/lib/gpu/host_buffer.cc @@ -0,0 +1,40 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/lib/gpu/host_buffer.h" + +#include "impeller/core/host_buffer.h" +#include "impeller/core/platform.h" +#include "third_party/tonic/typed_data/dart_byte_data.h" + +namespace flutter { + +IMPLEMENT_WRAPPERTYPEINFO(gpu, HostBuffer); + +HostBuffer::HostBuffer() : host_buffer_(impeller::HostBuffer::Create()) {} + +HostBuffer::~HostBuffer() = default; + +size_t HostBuffer::EmplaceBytes(const tonic::DartByteData& byte_data) { + auto view = + host_buffer_->Emplace(byte_data.data(), byte_data.length_in_bytes(), + impeller::DefaultUniformAlignment()); + return view.range.offset; +} + +} // namespace flutter + +//---------------------------------------------------------------------------- +/// Exports +/// + +void InternalFlutterGpu_HostBuffer_Initialize(Dart_Handle wrapper) { + auto res = fml::MakeRefCounted(); + res->AssociateWithDartWrapper(wrapper); +} + +size_t InternalFlutterGpu_HostBuffer_EmplaceBytes(flutter::HostBuffer* wrapper, + Dart_Handle byte_data) { + return wrapper->EmplaceBytes(tonic::DartByteData(byte_data)); +} diff --git a/lib/gpu/host_buffer.h b/lib/gpu/host_buffer.h new file mode 100644 index 0000000000000..52d24930de9a6 --- /dev/null +++ b/lib/gpu/host_buffer.h @@ -0,0 +1,47 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#pragma once + +#include "flutter/lib/gpu/export.h" +#include "flutter/lib/ui/dart_wrapper.h" +#include "impeller/core/host_buffer.h" +#include "third_party/tonic/typed_data/dart_byte_data.h" + +namespace flutter { + +class HostBuffer : public RefCountedDartWrappable { + DEFINE_WRAPPERTYPEINFO(); + FML_FRIEND_MAKE_REF_COUNTED(HostBuffer); + + public: + explicit HostBuffer(); + + ~HostBuffer() override; + + size_t EmplaceBytes(const tonic::DartByteData& byte_data); + + private: + std::shared_ptr host_buffer_; + + FML_DISALLOW_COPY_AND_ASSIGN(HostBuffer); +}; + +} // namespace flutter + +//---------------------------------------------------------------------------- +/// Exports +/// + +extern "C" { + +FLUTTER_GPU_EXPORT +extern void InternalFlutterGpu_HostBuffer_Initialize(Dart_Handle wrapper); + +FLUTTER_GPU_EXPORT +extern size_t InternalFlutterGpu_HostBuffer_EmplaceBytes( + flutter::HostBuffer* wrapper, + Dart_Handle byte_data); + +} // extern "C" diff --git a/lib/gpu/lib/gpu.dart b/lib/gpu/lib/gpu.dart index 72cf205f1f49d..b12b4a574b7e9 100644 --- a/lib/gpu/lib/gpu.dart +++ b/lib/gpu/lib/gpu.dart @@ -11,5 +11,7 @@ /// * [Flutter GPU Wiki page](https://github.com/flutter/flutter/wiki/Flutter-GPU). library flutter_gpu; -export 'src/context.dart'; export 'src/smoketest.dart'; + +export 'src/context.dart'; +export 'src/buffer.dart'; diff --git a/lib/gpu/lib/src/buffer.dart b/lib/gpu/lib/src/buffer.dart new file mode 100644 index 0000000000000..6cd0c1ee244a0 --- /dev/null +++ b/lib/gpu/lib/src/buffer.dart @@ -0,0 +1,73 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ffi'; +import 'dart:nativewrappers'; +import 'dart:typed_data'; + +import 'context.dart'; + +/// A buffer data range. +class BufferView { + /// The buffer of this view. + final Buffer buffer; + /// The start of the view, in bytes starting from the beginning of the + /// [buffer]. + final int offsetInBytes; + /// The end of the view + final int lengthInBytes; + + /// Create a new view into a buffer on the GPU. + const BufferView( + {required this.buffer, + required this.offsetInBytes, + required this.lengthInBytes}); +} + +/// A buffer that can be referenced by commands on the GPU. +mixin Buffer {} + +/// [HostBuffer] is a [Buffer] which is allocated on the host and lazily +/// uploaded to the GPU. A [HostBuffer] can be safely mutated or extended at +/// any time on the host, and will be automatically re-uploaded to the GPU +/// the next time a GPU operation needs to access it. +/// +/// This is useful for efficiently chunking sparse data uploads, especially +/// ephemeral uniform data that needs to change from frame to frame. +/// +/// Note: Different platforms have different data alignment requirements for +/// accessing device buffer data. The [HostBuffer] takes these +/// requirements into account and automatically inserts padding between +/// emplaced data if necessary. +class HostBuffer extends NativeFieldWrapperClass1 with Buffer { + /// Creates a new HostBuffer. + HostBuffer() { + _initialize(); + } + + /// Wrap with native counterpart. + @Native( + symbol: 'InternalFlutterGpu_HostBuffer_Initialize') + external void _initialize(); + + /// Append byte data to the end of the [HostBuffer] and produce a [BufferView] + /// that references the new data in the buffer. + /// + /// This method automatically inserts padding in-between emplaced data if + /// necessary to abide by platform-specific uniform alignment requirements. + /// + /// The updated buffer will be uploaded to the GPU if the returned + /// [BufferView] is used by a rendering command. + BufferView emplaceBytes({required ByteData bytes}) { + int resultOffset = _emplaceBytes(bytes); + return BufferView( + buffer: this, + offsetInBytes: resultOffset, + lengthInBytes: bytes.lengthInBytes); + } + + @Native, Handle)>( + symbol: 'InternalFlutterGpu_HostBuffer_EmplaceBytes') + external int _emplaceBytes(ByteData bytes); +} diff --git a/lib/gpu/lib/src/context.dart b/lib/gpu/lib/src/context.dart index 1c1be14267fbb..ea5654d428110 100644 --- a/lib/gpu/lib/src/context.dart +++ b/lib/gpu/lib/src/context.dart @@ -5,6 +5,8 @@ import 'dart:ffi'; import 'dart:nativewrappers'; +import 'buffer.dart'; + /// A handle to a graphics context. Used to create and manage GPU resources. /// /// To obtain the default graphics context, use [getContext]. @@ -22,6 +24,12 @@ class GpuContext extends NativeFieldWrapperClass1 { @Native( symbol: 'InternalFlutterGpu_Context_InitializeDefault') external String? _initializeDefault(); + + /// Create a new [HostBuffer] that can be used for staging and transferring + /// data from the host to the GPU. + HostBuffer createHostBuffer() { + return HostBuffer(); + } } /// The default graphics context. From 871262df61e86e4b781e116cff85cc498d38b5ae Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Mon, 14 Aug 2023 15:22:49 -0700 Subject: [PATCH 2/5] Licenses --- ci/licenses_golden/licenses_flutter | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 1c8936027b0f5..37523d04b4a2c 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -1728,12 +1728,12 @@ ORIGIN: ../../../flutter/lib/gpu/context.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/gpu/context.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/gpu/export.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/gpu/export.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/lib/gpu/host_buffer.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/lib/gpu/host_buffer.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/gpu/lib/gpu.dart + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/lib/gpu/lib/src/buffer.dart + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/gpu/lib/src/context.dart + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/lib/gpu/lib/src/host_buffer.dart + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/gpu/lib/src/smoketest.dart + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/lib/gpu/host_buffer.cc + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/lib/gpu/host_buffer.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/gpu/smoketest.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/gpu/smoketest.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/io/dart_io.cc + ../../../flutter/LICENSE @@ -4459,12 +4459,12 @@ FILE: ../../../flutter/lib/gpu/context.cc FILE: ../../../flutter/lib/gpu/context.h FILE: ../../../flutter/lib/gpu/export.cc FILE: ../../../flutter/lib/gpu/export.h +FILE: ../../../flutter/lib/gpu/host_buffer.cc +FILE: ../../../flutter/lib/gpu/host_buffer.h FILE: ../../../flutter/lib/gpu/lib/gpu.dart +FILE: ../../../flutter/lib/gpu/lib/src/buffer.dart FILE: ../../../flutter/lib/gpu/lib/src/context.dart -FILE: ../../../flutter/lib/gpu/lib/src/host_buffer.dart FILE: ../../../flutter/lib/gpu/lib/src/smoketest.dart -FILE: ../../../flutter/lib/gpu/host_buffer.cc -FILE: ../../../flutter/lib/gpu/host_buffer.h FILE: ../../../flutter/lib/gpu/smoketest.cc FILE: ../../../flutter/lib/gpu/smoketest.h FILE: ../../../flutter/lib/io/dart_io.cc From 0841143244b087815580ba5a85c303a2b3aeacae Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Mon, 14 Aug 2023 15:24:08 -0700 Subject: [PATCH 3/5] Address comments --- impeller/fixtures/dart_tests.dart | 10 +++++----- lib/gpu/lib/src/buffer.dart | 32 +++++++++++++++---------------- lib/gpu/lib/src/context.dart | 6 ------ 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/impeller/fixtures/dart_tests.dart b/impeller/fixtures/dart_tests.dart index 72aa7b1ff3a94..7e213429cd87d 100644 --- a/impeller/fixtures/dart_tests.dart +++ b/impeller/fixtures/dart_tests.dart @@ -21,15 +21,15 @@ void instantiateDefaultContext() { @pragma('vm:entry-point') void canEmplaceHostBuffer() { - final gpu.HostBuffer hostBuffer = gpu.gpuContext.createHostBuffer(); + final gpu.HostBuffer hostBuffer = gpu.HostBuffer(); - final gpu.BufferView view0 = hostBuffer.emplaceBytes( - bytes: Int8List.fromList([0, 1, 2, 3]).buffer.asByteData()); + final gpu.BufferView view0 = hostBuffer + .emplace(Int8List.fromList([0, 1, 2, 3]).buffer.asByteData()); assert(view0.offsetInBytes == 0); assert(view0.lengthInBytes == 4); - final gpu.BufferView view1 = hostBuffer.emplaceBytes( - bytes: Int8List.fromList([0, 1, 2, 3]).buffer.asByteData()); + final gpu.BufferView view1 = hostBuffer + .emplace(Int8List.fromList([0, 1, 2, 3]).buffer.asByteData()); assert(view1.offsetInBytes >= 4); assert(view1.lengthInBytes == 4); } diff --git a/lib/gpu/lib/src/buffer.dart b/lib/gpu/lib/src/buffer.dart index 6cd0c1ee244a0..60da10d8af9a1 100644 --- a/lib/gpu/lib/src/buffer.dart +++ b/lib/gpu/lib/src/buffer.dart @@ -8,30 +8,31 @@ import 'dart:typed_data'; import 'context.dart'; -/// A buffer data range. +/// A reference to a byte range within a GPU-resident [Buffer]. class BufferView { /// The buffer of this view. final Buffer buffer; + /// The start of the view, in bytes starting from the beginning of the /// [buffer]. final int offsetInBytes; + /// The end of the view final int lengthInBytes; /// Create a new view into a buffer on the GPU. - const BufferView( - {required this.buffer, - required this.offsetInBytes, - required this.lengthInBytes}); + const BufferView(this.buffer, + {required this.offsetInBytes, required this.lengthInBytes}); } /// A buffer that can be referenced by commands on the GPU. mixin Buffer {} -/// [HostBuffer] is a [Buffer] which is allocated on the host and lazily -/// uploaded to the GPU. A [HostBuffer] can be safely mutated or extended at -/// any time on the host, and will be automatically re-uploaded to the GPU -/// the next time a GPU operation needs to access it. +/// [HostBuffer] is a [Buffer] which is allocated on the host (native CPU +/// resident memory) and lazily uploaded to the GPU. A [HostBuffer] can be +/// safely mutated or extended at any time on the host, and will be +/// automatically re-uploaded to the GPU the next time a GPU operation needs to +/// access it. /// /// This is useful for efficiently chunking sparse data uploads, especially /// ephemeral uniform data that needs to change from frame to frame. @@ -54,17 +55,16 @@ class HostBuffer extends NativeFieldWrapperClass1 with Buffer { /// Append byte data to the end of the [HostBuffer] and produce a [BufferView] /// that references the new data in the buffer. /// - /// This method automatically inserts padding in-between emplaced data if - /// necessary to abide by platform-specific uniform alignment requirements. + /// This method automatically inserts padding in-between emplace calls in the + /// buffer if necessary to abide by platform-specific uniform alignment + /// requirements. /// /// The updated buffer will be uploaded to the GPU if the returned /// [BufferView] is used by a rendering command. - BufferView emplaceBytes({required ByteData bytes}) { + BufferView emplace(ByteData bytes) { int resultOffset = _emplaceBytes(bytes); - return BufferView( - buffer: this, - offsetInBytes: resultOffset, - lengthInBytes: bytes.lengthInBytes); + return BufferView(this, + offsetInBytes: resultOffset, lengthInBytes: bytes.lengthInBytes); } @Native, Handle)>( diff --git a/lib/gpu/lib/src/context.dart b/lib/gpu/lib/src/context.dart index ea5654d428110..a03fe3cc27544 100644 --- a/lib/gpu/lib/src/context.dart +++ b/lib/gpu/lib/src/context.dart @@ -24,12 +24,6 @@ class GpuContext extends NativeFieldWrapperClass1 { @Native( symbol: 'InternalFlutterGpu_Context_InitializeDefault') external String? _initializeDefault(); - - /// Create a new [HostBuffer] that can be used for staging and transferring - /// data from the host to the GPU. - HostBuffer createHostBuffer() { - return HostBuffer(); - } } /// The default graphics context. From 31e8f794f2f928c87fde9509f3ec8b19f064fc32 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Mon, 14 Aug 2023 15:33:01 -0700 Subject: [PATCH 4/5] Remove unused import --- lib/gpu/lib/src/buffer.dart | 11 +++-------- lib/gpu/lib/src/context.dart | 2 -- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/gpu/lib/src/buffer.dart b/lib/gpu/lib/src/buffer.dart index 60da10d8af9a1..70a960bd19382 100644 --- a/lib/gpu/lib/src/buffer.dart +++ b/lib/gpu/lib/src/buffer.dart @@ -6,18 +6,16 @@ import 'dart:ffi'; import 'dart:nativewrappers'; import 'dart:typed_data'; -import 'context.dart'; - /// A reference to a byte range within a GPU-resident [Buffer]. class BufferView { /// The buffer of this view. - final Buffer buffer; + final HostBuffer buffer; /// The start of the view, in bytes starting from the beginning of the /// [buffer]. final int offsetInBytes; - /// The end of the view + /// The length of the view. final int lengthInBytes; /// Create a new view into a buffer on the GPU. @@ -25,9 +23,6 @@ class BufferView { {required this.offsetInBytes, required this.lengthInBytes}); } -/// A buffer that can be referenced by commands on the GPU. -mixin Buffer {} - /// [HostBuffer] is a [Buffer] which is allocated on the host (native CPU /// resident memory) and lazily uploaded to the GPU. A [HostBuffer] can be /// safely mutated or extended at any time on the host, and will be @@ -41,7 +36,7 @@ mixin Buffer {} /// accessing device buffer data. The [HostBuffer] takes these /// requirements into account and automatically inserts padding between /// emplaced data if necessary. -class HostBuffer extends NativeFieldWrapperClass1 with Buffer { +class HostBuffer extends NativeFieldWrapperClass1 { /// Creates a new HostBuffer. HostBuffer() { _initialize(); diff --git a/lib/gpu/lib/src/context.dart b/lib/gpu/lib/src/context.dart index a03fe3cc27544..1c1be14267fbb 100644 --- a/lib/gpu/lib/src/context.dart +++ b/lib/gpu/lib/src/context.dart @@ -5,8 +5,6 @@ import 'dart:ffi'; import 'dart:nativewrappers'; -import 'buffer.dart'; - /// A handle to a graphics context. Used to create and manage GPU resources. /// /// To obtain the default graphics context, use [getContext]. From 631778ded9b8b2680854485f998bc4582ea257a2 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Tue, 22 Aug 2023 10:44:25 -0700 Subject: [PATCH 5/5] Address comments --- lib/gpu/lib/src/buffer.dart | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/gpu/lib/src/buffer.dart b/lib/gpu/lib/src/buffer.dart index 70a960bd19382..6864f20e12627 100644 --- a/lib/gpu/lib/src/buffer.dart +++ b/lib/gpu/lib/src/buffer.dart @@ -32,11 +32,10 @@ class BufferView { /// This is useful for efficiently chunking sparse data uploads, especially /// ephemeral uniform data that needs to change from frame to frame. /// -/// Note: Different platforms have different data alignment requirements for -/// accessing device buffer data. The [HostBuffer] takes these -/// requirements into account and automatically inserts padding between -/// emplaced data if necessary. -class HostBuffer extends NativeFieldWrapperClass1 { +/// Different platforms have different data alignment requirements for accessing +/// device buffer data. The [HostBuffer] takes these requirements into account +/// and automatically inserts padding between emplaced data if necessary. +base class HostBuffer extends NativeFieldWrapperClass1 { /// Creates a new HostBuffer. HostBuffer() { _initialize();