[Flutter GPU] Replace HostBuffer with Dart version. (flutter/engine#56054)
Resolves https://github.com/flutter/flutter/issues/157431.
This commit is contained in:
@@ -43546,8 +43546,6 @@ ORIGIN: ../../../flutter/lib/gpu/export.cc + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/lib/gpu/export.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/lib/gpu/formats.cc + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/lib/gpu/formats.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/command_buffer.dart + ../../../flutter/LICENSE
|
||||
@@ -46415,8 +46413,6 @@ FILE: ../../../flutter/lib/gpu/export.cc
|
||||
FILE: ../../../flutter/lib/gpu/export.h
|
||||
FILE: ../../../flutter/lib/gpu/formats.cc
|
||||
FILE: ../../../flutter/lib/gpu/formats.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/command_buffer.dart
|
||||
|
||||
@@ -61,48 +61,6 @@ gpu.RenderPipeline createUnlitRenderPipeline() {
|
||||
return gpu.gpuContext.createRenderPipeline(vertex!, fragment!);
|
||||
}
|
||||
|
||||
gpu.RenderPass createRenderPass() {
|
||||
final gpu.Texture? renderTexture =
|
||||
gpu.gpuContext.createTexture(gpu.StorageMode.devicePrivate, 100, 100);
|
||||
assert(renderTexture != null);
|
||||
|
||||
final gpu.CommandBuffer commandBuffer = gpu.gpuContext.createCommandBuffer();
|
||||
|
||||
final gpu.RenderTarget renderTarget = gpu.RenderTarget.singleColor(
|
||||
gpu.ColorAttachment(texture: renderTexture!),
|
||||
);
|
||||
return commandBuffer.createRenderPass(renderTarget);
|
||||
}
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void uniformBindFailsForInvalidHostBufferOffset() {
|
||||
final gpu.RenderPass encoder = createRenderPass();
|
||||
|
||||
final gpu.RenderPipeline pipeline = createUnlitRenderPipeline();
|
||||
encoder.bindPipeline(pipeline);
|
||||
|
||||
final gpu.HostBuffer transients = gpu.gpuContext.createHostBuffer();
|
||||
final gpu.BufferView vertInfoData = transients.emplace(float32(<double>[
|
||||
1, 0, 0, 0, // mvp
|
||||
0, 1, 0, 0, // mvp
|
||||
0, 0, 1, 0, // mvp
|
||||
0, 0, 0, 1, // mvp
|
||||
0, 1, 0, 1, // color
|
||||
]));
|
||||
final gpu.BufferView viewWithBadOffset = gpu.BufferView(vertInfoData.buffer,
|
||||
offsetInBytes: 1, lengthInBytes: vertInfoData.lengthInBytes);
|
||||
|
||||
final gpu.UniformSlot vertInfo =
|
||||
pipeline.vertexShader.getUniformSlot('VertInfo');
|
||||
String? exception;
|
||||
try {
|
||||
encoder.bindUniform(vertInfo, viewWithBadOffset);
|
||||
} catch (e) {
|
||||
exception = e.toString();
|
||||
}
|
||||
assert(exception!.contains('Failed to bind uniform'));
|
||||
}
|
||||
|
||||
ByteData float32(List<double> values) {
|
||||
return Float32List.fromList(values).buffer.asByteData();
|
||||
}
|
||||
|
||||
@@ -295,10 +295,6 @@ TEST_P(RendererDartTest, CanReflectUniformStructs) {
|
||||
ASSERT_TRUE(RunDartFunction("canReflectUniformStructs"));
|
||||
}
|
||||
|
||||
TEST_P(RendererDartTest, UniformBindFailsForInvalidHostBufferOffset) {
|
||||
ASSERT_TRUE(RunDartFunction("uniformBindFailsForInvalidHostBufferOffset"));
|
||||
}
|
||||
|
||||
TEST_P(RendererDartTest, CanCreateRenderPassAndSubmit) {
|
||||
ASSERT_TRUE(RenderDartToPlayground("canCreateRenderPassAndSubmit"));
|
||||
}
|
||||
|
||||
@@ -42,8 +42,6 @@ source_set("gpu") {
|
||||
"export.h",
|
||||
"formats.cc",
|
||||
"formats.h",
|
||||
"host_buffer.cc",
|
||||
"host_buffer.h",
|
||||
"render_pass.cc",
|
||||
"render_pass.h",
|
||||
"render_pipeline.cc",
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
// 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 <optional>
|
||||
|
||||
#include "dart_api.h"
|
||||
#include "impeller/core/host_buffer.h"
|
||||
#include "impeller/core/platform.h"
|
||||
#include "third_party/tonic/typed_data/dart_byte_data.h"
|
||||
|
||||
namespace flutter {
|
||||
namespace gpu {
|
||||
|
||||
IMPLEMENT_WRAPPERTYPEINFO(flutter_gpu, HostBuffer);
|
||||
|
||||
HostBuffer::HostBuffer(Context* context)
|
||||
: host_buffer_(impeller::HostBuffer::Create(
|
||||
context->GetContext()->GetResourceAllocator())) {}
|
||||
|
||||
HostBuffer::~HostBuffer() = default;
|
||||
|
||||
std::shared_ptr<impeller::HostBuffer> HostBuffer::GetBuffer() {
|
||||
return host_buffer_;
|
||||
}
|
||||
|
||||
size_t HostBuffer::EmplaceBytes(const tonic::DartByteData& byte_data) {
|
||||
auto view =
|
||||
host_buffer_->Emplace(byte_data.data(), byte_data.length_in_bytes(),
|
||||
impeller::DefaultUniformAlignment());
|
||||
emplacements_[current_offset_] = view;
|
||||
size_t previous_offset = current_offset_;
|
||||
current_offset_ += view.range.length;
|
||||
return previous_offset;
|
||||
}
|
||||
|
||||
std::optional<impeller::BufferView> HostBuffer::GetBufferViewForOffset(
|
||||
size_t offset) {
|
||||
return emplacements_[offset];
|
||||
}
|
||||
|
||||
} // namespace gpu
|
||||
} // namespace flutter
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// Exports
|
||||
///
|
||||
|
||||
void InternalFlutterGpu_HostBuffer_Initialize(Dart_Handle wrapper,
|
||||
flutter::gpu::Context* context) {
|
||||
auto res = fml::MakeRefCounted<flutter::gpu::HostBuffer>(context);
|
||||
res->AssociateWithDartWrapper(wrapper);
|
||||
}
|
||||
|
||||
size_t InternalFlutterGpu_HostBuffer_EmplaceBytes(
|
||||
flutter::gpu::HostBuffer* wrapper,
|
||||
Dart_Handle byte_data) {
|
||||
return wrapper->EmplaceBytes(tonic::DartByteData(byte_data));
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef FLUTTER_LIB_GPU_HOST_BUFFER_H_
|
||||
#define FLUTTER_LIB_GPU_HOST_BUFFER_H_
|
||||
|
||||
#include "flutter/lib/gpu/export.h"
|
||||
#include "flutter/lib/ui/dart_wrapper.h"
|
||||
#include "impeller/core/buffer_view.h"
|
||||
#include "impeller/core/host_buffer.h"
|
||||
#include "lib/gpu/context.h"
|
||||
#include "third_party/tonic/typed_data/dart_byte_data.h"
|
||||
|
||||
namespace flutter {
|
||||
namespace gpu {
|
||||
|
||||
class HostBuffer : public RefCountedDartWrappable<HostBuffer> {
|
||||
DEFINE_WRAPPERTYPEINFO();
|
||||
FML_FRIEND_MAKE_REF_COUNTED(HostBuffer);
|
||||
|
||||
public:
|
||||
explicit HostBuffer(Context* context);
|
||||
|
||||
~HostBuffer() override;
|
||||
|
||||
std::shared_ptr<impeller::HostBuffer> GetBuffer();
|
||||
|
||||
size_t EmplaceBytes(const tonic::DartByteData& byte_data);
|
||||
|
||||
std::optional<impeller::BufferView> GetBufferViewForOffset(size_t offset);
|
||||
|
||||
private:
|
||||
size_t current_offset_ = 0;
|
||||
std::shared_ptr<impeller::HostBuffer> host_buffer_;
|
||||
std::unordered_map<size_t, impeller::BufferView> emplacements_;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(HostBuffer);
|
||||
};
|
||||
|
||||
} // namespace gpu
|
||||
} // namespace flutter
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// Exports
|
||||
///
|
||||
|
||||
extern "C" {
|
||||
|
||||
FLUTTER_GPU_EXPORT
|
||||
extern void InternalFlutterGpu_HostBuffer_Initialize(
|
||||
Dart_Handle wrapper,
|
||||
flutter::gpu::Context* context);
|
||||
|
||||
FLUTTER_GPU_EXPORT
|
||||
extern size_t InternalFlutterGpu_HostBuffer_EmplaceBytes(
|
||||
flutter::gpu::HostBuffer* wrapper,
|
||||
Dart_Handle byte_data);
|
||||
|
||||
} // extern "C"
|
||||
|
||||
#endif // FLUTTER_LIB_GPU_HOST_BUFFER_H_
|
||||
@@ -8,8 +8,8 @@ part of flutter_gpu;
|
||||
|
||||
/// A reference to a byte range within a GPU-resident [Buffer].
|
||||
class BufferView {
|
||||
/// The buffer of this view.
|
||||
final Buffer buffer;
|
||||
/// The device buffer of this view.
|
||||
final DeviceBuffer buffer;
|
||||
|
||||
/// The start of the view, in bytes starting from the beginning of the
|
||||
/// [buffer].
|
||||
@@ -23,21 +23,9 @@ class BufferView {
|
||||
{required this.offsetInBytes, required this.lengthInBytes});
|
||||
}
|
||||
|
||||
/// A buffer that can be referenced by commands on the GPU.
|
||||
mixin Buffer {
|
||||
void _bindAsVertexBuffer(RenderPass renderPass, int offsetInBytes,
|
||||
int lengthInBytes, int vertexCount);
|
||||
|
||||
void _bindAsIndexBuffer(RenderPass renderPass, int offsetInBytes,
|
||||
int lengthInBytes, IndexType indexType, int indexCount);
|
||||
|
||||
bool _bindAsUniform(RenderPass renderPass, UniformSlot slot,
|
||||
int offsetInBytes, int lengthInBytes);
|
||||
}
|
||||
|
||||
/// [DeviceBuffer] is a region of memory allocated on the device heap
|
||||
/// (GPU-resident memory).
|
||||
base class DeviceBuffer extends NativeFieldWrapperClass1 with Buffer {
|
||||
base class DeviceBuffer extends NativeFieldWrapperClass1 {
|
||||
bool _valid = false;
|
||||
get isValid {
|
||||
return _valid;
|
||||
@@ -61,21 +49,18 @@ base class DeviceBuffer extends NativeFieldWrapperClass1 with Buffer {
|
||||
final StorageMode storageMode;
|
||||
final int sizeInBytes;
|
||||
|
||||
@override
|
||||
void _bindAsVertexBuffer(RenderPass renderPass, int offsetInBytes,
|
||||
int lengthInBytes, int vertexCount) {
|
||||
renderPass._bindVertexBufferDevice(
|
||||
this, offsetInBytes, lengthInBytes, vertexCount);
|
||||
}
|
||||
|
||||
@override
|
||||
void _bindAsIndexBuffer(RenderPass renderPass, int offsetInBytes,
|
||||
int lengthInBytes, IndexType indexType, int indexCount) {
|
||||
renderPass._bindIndexBufferDevice(
|
||||
this, offsetInBytes, lengthInBytes, indexType.index, indexCount);
|
||||
}
|
||||
|
||||
@override
|
||||
bool _bindAsUniform(RenderPass renderPass, UniformSlot slot,
|
||||
int offsetInBytes, int lengthInBytes) {
|
||||
return renderPass._bindUniformDevice(
|
||||
@@ -156,49 +141,94 @@ base class DeviceBuffer extends NativeFieldWrapperClass1 with Buffer {
|
||||
external void _flush(int offsetInBytes, int lengthInBytes);
|
||||
}
|
||||
|
||||
/// [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.
|
||||
/// [HostBuffer] is a bump allocator that managed a [DeviceBuffer] block list.
|
||||
///
|
||||
/// This is useful for efficiently chunking sparse data uploads, especially
|
||||
/// ephemeral uniform data that needs to change from frame to frame.
|
||||
/// This is useful for chunking sparse data uploads, especially ephemeral
|
||||
/// uniform or vertex data that needs to change from frame to frame.
|
||||
///
|
||||
/// 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 with Buffer {
|
||||
/// Different platforms have different data alignment requirements when reading
|
||||
/// [DeviceBuffer] data for shader uniforms. [HostBuffer] uses
|
||||
/// [GpuContext.minimumUniformByteAlignment] to align each emplacement
|
||||
/// automatically, so that they may be used in uniform bindings.
|
||||
///
|
||||
/// The length of each [DeviceBuffer] block is determined by
|
||||
/// [blockLengthInBytes] and cannot be changed after creation of the
|
||||
/// [HostBuffer]. If [HostBuffer.emplace] is given a [ByteData] that is larger
|
||||
/// than [blockLengthInBytes], a new [DeviceBuffer] block is created that
|
||||
/// matches the size of the oversized [ByteData].
|
||||
base class HostBuffer {
|
||||
/// The default length to use for each [DeviceBuffer] block.
|
||||
static const int kDefaultBlockLengthInBytes = 1024000; // 1024 Kb
|
||||
|
||||
/// The length to use for each [DeviceBuffer] block.
|
||||
final int blockLengthInBytes;
|
||||
|
||||
static const int _kFrameCount = 4;
|
||||
|
||||
/// The number of frames to cycle through before reusing device buffers.
|
||||
/// Cycling to the next frame happens when [reset] is called.
|
||||
int get frameCount {
|
||||
return _kFrameCount;
|
||||
}
|
||||
|
||||
final GpuContext _gpuContext;
|
||||
|
||||
/// The current frame. Rotates through [frameCount] frames when [reset] is
|
||||
/// called.
|
||||
int _frameCursor = 0;
|
||||
|
||||
/// The buffer within the current frame to be used for the next emplacement.
|
||||
int _bufferCursor = 0;
|
||||
|
||||
/// The offset within the current block to be used for the next emplacement.
|
||||
int _offsetCursor = 0;
|
||||
|
||||
final List<List<DeviceBuffer>> _buffers = [];
|
||||
|
||||
/// Creates a new HostBuffer.
|
||||
HostBuffer._initialize(GpuContext gpuContext) {
|
||||
_initialize(gpuContext);
|
||||
HostBuffer._initialize(this._gpuContext,
|
||||
{this.blockLengthInBytes = HostBuffer.kDefaultBlockLengthInBytes}) {
|
||||
for (int i = 0; i < frameCount; i++) {
|
||||
List<DeviceBuffer> frame = [];
|
||||
_buffers.add(frame);
|
||||
_buffers[i].add(_allocateNewBlock(blockLengthInBytes));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void _bindAsVertexBuffer(RenderPass renderPass, int offsetInBytes,
|
||||
int lengthInBytes, int vertexCount) {
|
||||
renderPass._bindVertexBufferHost(
|
||||
this, offsetInBytes, lengthInBytes, vertexCount);
|
||||
DeviceBuffer _allocateNewBlock(length) {
|
||||
final buffer =
|
||||
_gpuContext.createDeviceBuffer(StorageMode.hostVisible, length);
|
||||
if (buffer == null) {
|
||||
throw Exception('Failed to allocate DeviceBuffer of length $length');
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@override
|
||||
void _bindAsIndexBuffer(RenderPass renderPass, int offsetInBytes,
|
||||
int lengthInBytes, IndexType indexType, int indexCount) {
|
||||
renderPass._bindIndexBufferHost(
|
||||
this, offsetInBytes, lengthInBytes, indexType.index, indexCount);
|
||||
}
|
||||
/// Prepare a new buffer range to be used for storing the given bytes.
|
||||
/// Allocates a new block if necessary.
|
||||
BufferView _allocateEmplacement(ByteData bytes) {
|
||||
if (bytes.lengthInBytes > blockLengthInBytes) {
|
||||
return BufferView(_allocateNewBlock(bytes.lengthInBytes),
|
||||
offsetInBytes: 0, lengthInBytes: bytes.lengthInBytes);
|
||||
}
|
||||
|
||||
@override
|
||||
bool _bindAsUniform(RenderPass renderPass, UniformSlot slot,
|
||||
int offsetInBytes, int lengthInBytes) {
|
||||
return renderPass._bindUniformHost(
|
||||
slot.shader, slot.uniformName, this, offsetInBytes, lengthInBytes);
|
||||
}
|
||||
int padding = _offsetCursor % _gpuContext.minimumUniformByteAlignment;
|
||||
if (_offsetCursor + padding >= blockLengthInBytes) {
|
||||
DeviceBuffer buffer = _allocateNewBlock(blockLengthInBytes);
|
||||
_buffers[_frameCursor].add(buffer);
|
||||
_bufferCursor++;
|
||||
_offsetCursor = bytes.lengthInBytes;
|
||||
|
||||
/// Wrap with native counterpart.
|
||||
@Native<Void Function(Handle, Pointer<Void>)>(
|
||||
symbol: 'InternalFlutterGpu_HostBuffer_Initialize')
|
||||
external void _initialize(GpuContext gpuContext);
|
||||
return BufferView(buffer,
|
||||
offsetInBytes: 0, lengthInBytes: blockLengthInBytes);
|
||||
}
|
||||
|
||||
_offsetCursor += padding;
|
||||
final view = BufferView(_buffers[_frameCursor][_bufferCursor],
|
||||
offsetInBytes: _offsetCursor, lengthInBytes: bytes.lengthInBytes);
|
||||
_offsetCursor += bytes.lengthInBytes;
|
||||
return view;
|
||||
}
|
||||
|
||||
/// Append byte data to the end of the [HostBuffer] and produce a [BufferView]
|
||||
/// that references the new data in the buffer.
|
||||
@@ -207,15 +237,26 @@ base class HostBuffer extends NativeFieldWrapperClass1 with Buffer {
|
||||
/// 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.
|
||||
/// The [DeviceBuffer] referenced in the [BufferView] has already been
|
||||
/// flushed, so there is no need to call [DeviceBuffer.flush] before
|
||||
/// referencing it in a command.
|
||||
BufferView emplace(ByteData bytes) {
|
||||
int resultOffset = _emplaceBytes(bytes);
|
||||
return BufferView(this,
|
||||
offsetInBytes: resultOffset, lengthInBytes: bytes.lengthInBytes);
|
||||
BufferView view = _allocateEmplacement(bytes);
|
||||
if (!view.buffer
|
||||
.overwrite(bytes, destinationOffsetInBytes: view.offsetInBytes)) {
|
||||
throw Exception(
|
||||
'Failed to write range (offset=${view.offsetInBytes}, length=${view.lengthInBytes}) '
|
||||
'to HostBuffer-managed DeviceBuffer (frame=$_frameCursor, buffer=$_bufferCursor, offset=$_offsetCursor).');
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Native<Uint64 Function(Pointer<Void>, Handle)>(
|
||||
symbol: 'InternalFlutterGpu_HostBuffer_EmplaceBytes')
|
||||
external int _emplaceBytes(ByteData bytes);
|
||||
/// Resets the bump allocator to the beginning of the first [DeviceBuffer]
|
||||
/// block.
|
||||
void reset() {
|
||||
_frameCursor = (_frameCursor + 1) % frameCount;
|
||||
_bufferCursor = 0;
|
||||
_offsetCursor = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,8 +87,12 @@ base class GpuContext extends NativeFieldWrapperClass1 {
|
||||
return result.isValid ? result : null;
|
||||
}
|
||||
|
||||
HostBuffer createHostBuffer() {
|
||||
return HostBuffer._initialize(this);
|
||||
/// Creates a bump allocator that managed a [DeviceBuffer] block list.
|
||||
///
|
||||
/// See also [HostBuffer].
|
||||
HostBuffer createHostBuffer(
|
||||
{int blockLengthInBytes = HostBuffer.kDefaultBlockLengthInBytes}) {
|
||||
return HostBuffer._initialize(this, blockLengthInBytes: blockLengthInBytes);
|
||||
}
|
||||
|
||||
/// Allocates a new texture in GPU-resident memory.
|
||||
|
||||
@@ -396,33 +396,17 @@ base class RenderPass extends NativeFieldWrapperClass1 {
|
||||
external void _bindVertexBufferDevice(DeviceBuffer buffer, int offsetInBytes,
|
||||
int lengthInBytes, int vertexCount);
|
||||
|
||||
@Native<Void Function(Pointer<Void>, Pointer<Void>, Int, Int, Int)>(
|
||||
symbol: 'InternalFlutterGpu_RenderPass_BindVertexBufferHost')
|
||||
external void _bindVertexBufferHost(
|
||||
HostBuffer buffer, int offsetInBytes, int lengthInBytes, int vertexCount);
|
||||
|
||||
@Native<Void Function(Pointer<Void>, Pointer<Void>, Int, Int, Int, Int)>(
|
||||
symbol: 'InternalFlutterGpu_RenderPass_BindIndexBufferDevice')
|
||||
external void _bindIndexBufferDevice(DeviceBuffer buffer, int offsetInBytes,
|
||||
int lengthInBytes, int indexType, int indexCount);
|
||||
|
||||
@Native<Void Function(Pointer<Void>, Pointer<Void>, Int, Int, Int, Int)>(
|
||||
symbol: 'InternalFlutterGpu_RenderPass_BindIndexBufferHost')
|
||||
external void _bindIndexBufferHost(HostBuffer buffer, int offsetInBytes,
|
||||
int lengthInBytes, int indexType, int indexCount);
|
||||
|
||||
@Native<
|
||||
Bool Function(Pointer<Void>, Pointer<Void>, Handle, Pointer<Void>, Int,
|
||||
Int)>(symbol: 'InternalFlutterGpu_RenderPass_BindUniformDevice')
|
||||
external bool _bindUniformDevice(Shader shader, String uniformName,
|
||||
DeviceBuffer buffer, int offsetInBytes, int lengthInBytes);
|
||||
|
||||
@Native<
|
||||
Bool Function(Pointer<Void>, Pointer<Void>, Handle, Pointer<Void>, Int,
|
||||
Int)>(symbol: 'InternalFlutterGpu_RenderPass_BindUniformHost')
|
||||
external bool _bindUniformHost(Shader shader, String uniformName,
|
||||
HostBuffer buffer, int offsetInBytes, int lengthInBytes);
|
||||
|
||||
@Native<
|
||||
Bool Function(
|
||||
Pointer<Void>,
|
||||
|
||||
@@ -337,24 +337,6 @@ void InternalFlutterGpu_RenderPass_BindVertexBufferDevice(
|
||||
length_in_bytes, vertex_count);
|
||||
}
|
||||
|
||||
void InternalFlutterGpu_RenderPass_BindVertexBufferHost(
|
||||
flutter::gpu::RenderPass* wrapper,
|
||||
flutter::gpu::HostBuffer* host_buffer,
|
||||
int offset_in_bytes,
|
||||
int length_in_bytes,
|
||||
int vertex_count) {
|
||||
std::optional<impeller::BufferView> view =
|
||||
host_buffer->GetBufferViewForOffset(offset_in_bytes);
|
||||
if (!view.has_value()) {
|
||||
FML_LOG(ERROR)
|
||||
<< "Failed to bind vertex buffer due to invalid HostBuffer offset: "
|
||||
<< offset_in_bytes;
|
||||
return;
|
||||
}
|
||||
BindVertexBuffer(wrapper, view->buffer, view->range.offset,
|
||||
view->range.length, vertex_count);
|
||||
}
|
||||
|
||||
static void BindIndexBuffer(
|
||||
flutter::gpu::RenderPass* wrapper,
|
||||
const std::shared_ptr<const impeller::DeviceBuffer>& buffer,
|
||||
@@ -387,24 +369,6 @@ void InternalFlutterGpu_RenderPass_BindIndexBufferDevice(
|
||||
length_in_bytes, index_type, index_count);
|
||||
}
|
||||
|
||||
void InternalFlutterGpu_RenderPass_BindIndexBufferHost(
|
||||
flutter::gpu::RenderPass* wrapper,
|
||||
flutter::gpu::HostBuffer* host_buffer,
|
||||
int offset_in_bytes,
|
||||
int length_in_bytes,
|
||||
int index_type,
|
||||
int index_count) {
|
||||
auto view = host_buffer->GetBufferViewForOffset(offset_in_bytes);
|
||||
if (!view.has_value()) {
|
||||
FML_LOG(ERROR)
|
||||
<< "Failed to bind index buffer due to invalid HostBuffer offset: "
|
||||
<< offset_in_bytes;
|
||||
return;
|
||||
}
|
||||
BindIndexBuffer(wrapper, view->buffer, view->range.offset, view->range.length,
|
||||
index_type, index_count);
|
||||
}
|
||||
|
||||
static bool BindUniform(
|
||||
flutter::gpu::RenderPass* wrapper,
|
||||
flutter::gpu::Shader* shader,
|
||||
@@ -465,24 +429,6 @@ bool InternalFlutterGpu_RenderPass_BindUniformDevice(
|
||||
length_in_bytes);
|
||||
}
|
||||
|
||||
bool InternalFlutterGpu_RenderPass_BindUniformHost(
|
||||
flutter::gpu::RenderPass* wrapper,
|
||||
flutter::gpu::Shader* shader,
|
||||
Dart_Handle uniform_name_handle,
|
||||
flutter::gpu::HostBuffer* host_buffer,
|
||||
int offset_in_bytes,
|
||||
int length_in_bytes) {
|
||||
auto view = host_buffer->GetBufferViewForOffset(offset_in_bytes);
|
||||
if (!view.has_value()) {
|
||||
FML_LOG(ERROR)
|
||||
<< "Failed to bind index buffer due to invalid HostBuffer offset: "
|
||||
<< offset_in_bytes;
|
||||
return false;
|
||||
}
|
||||
return BindUniform(wrapper, shader, uniform_name_handle, view->buffer,
|
||||
view->range.offset, view->range.length);
|
||||
}
|
||||
|
||||
bool InternalFlutterGpu_RenderPass_BindTexture(
|
||||
flutter::gpu::RenderPass* wrapper,
|
||||
flutter::gpu::Shader* shader,
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include "impeller/renderer/render_pass.h"
|
||||
#include "impeller/renderer/render_target.h"
|
||||
#include "lib/gpu/device_buffer.h"
|
||||
#include "lib/gpu/host_buffer.h"
|
||||
#include "lib/gpu/render_pipeline.h"
|
||||
#include "lib/gpu/texture.h"
|
||||
|
||||
@@ -158,14 +157,6 @@ extern void InternalFlutterGpu_RenderPass_BindVertexBufferDevice(
|
||||
int length_in_bytes,
|
||||
int vertex_count);
|
||||
|
||||
FLUTTER_GPU_EXPORT
|
||||
extern void InternalFlutterGpu_RenderPass_BindVertexBufferHost(
|
||||
flutter::gpu::RenderPass* wrapper,
|
||||
flutter::gpu::HostBuffer* host_buffer,
|
||||
int offset_in_bytes,
|
||||
int length_in_bytes,
|
||||
int vertex_count);
|
||||
|
||||
FLUTTER_GPU_EXPORT
|
||||
extern void InternalFlutterGpu_RenderPass_BindIndexBufferDevice(
|
||||
flutter::gpu::RenderPass* wrapper,
|
||||
@@ -175,15 +166,6 @@ extern void InternalFlutterGpu_RenderPass_BindIndexBufferDevice(
|
||||
int index_type,
|
||||
int index_count);
|
||||
|
||||
FLUTTER_GPU_EXPORT
|
||||
extern void InternalFlutterGpu_RenderPass_BindIndexBufferHost(
|
||||
flutter::gpu::RenderPass* wrapper,
|
||||
flutter::gpu::HostBuffer* host_buffer,
|
||||
int offset_in_bytes,
|
||||
int length_in_bytes,
|
||||
int index_type,
|
||||
int index_count);
|
||||
|
||||
FLUTTER_GPU_EXPORT
|
||||
extern bool InternalFlutterGpu_RenderPass_BindUniformDevice(
|
||||
flutter::gpu::RenderPass* wrapper,
|
||||
@@ -193,15 +175,6 @@ extern bool InternalFlutterGpu_RenderPass_BindUniformDevice(
|
||||
int offset_in_bytes,
|
||||
int length_in_bytes);
|
||||
|
||||
FLUTTER_GPU_EXPORT
|
||||
extern bool InternalFlutterGpu_RenderPass_BindUniformHost(
|
||||
flutter::gpu::RenderPass* wrapper,
|
||||
flutter::gpu::Shader* shader,
|
||||
Dart_Handle uniform_name_handle,
|
||||
flutter::gpu::HostBuffer* host_buffer,
|
||||
int offset_in_bytes,
|
||||
int length_in_bytes);
|
||||
|
||||
FLUTTER_GPU_EXPORT
|
||||
extern bool InternalFlutterGpu_RenderPass_BindTexture(
|
||||
flutter::gpu::RenderPass* wrapper,
|
||||
|
||||
@@ -171,10 +171,41 @@ void main() async {
|
||||
|
||||
final gpu.BufferView view1 = hostBuffer
|
||||
.emplace(Int8List.fromList(<int>[0, 1, 2, 3]).buffer.asByteData());
|
||||
expect(view1.offsetInBytes >= 4, true);
|
||||
expect(view1.offsetInBytes, greaterThanOrEqualTo(4));
|
||||
expect(view1.lengthInBytes, 4);
|
||||
}, skip: !impellerEnabled);
|
||||
|
||||
test('HostBuffer.reset', () async {
|
||||
final gpu.HostBuffer hostBuffer = gpu.gpuContext.createHostBuffer();
|
||||
|
||||
final gpu.BufferView view0 = hostBuffer
|
||||
.emplace(Int8List.fromList(<int>[0, 1, 2, 3]).buffer.asByteData());
|
||||
expect(view0.offsetInBytes, 0);
|
||||
expect(view0.lengthInBytes, 4);
|
||||
|
||||
hostBuffer.reset();
|
||||
|
||||
final gpu.BufferView view1 = hostBuffer
|
||||
.emplace(Int8List.fromList(<int>[0, 1, 2, 3]).buffer.asByteData());
|
||||
expect(view1.offsetInBytes, 0);
|
||||
expect(view1.lengthInBytes, 4);
|
||||
}, skip: !impellerEnabled);
|
||||
|
||||
test('HostBuffer reuses DeviceBuffers after N frames', () async {
|
||||
final gpu.HostBuffer hostBuffer = gpu.gpuContext.createHostBuffer();
|
||||
|
||||
final gpu.BufferView view0 = hostBuffer
|
||||
.emplace(Int8List.fromList(<int>[0, 1, 2, 3]).buffer.asByteData());
|
||||
|
||||
for (int i = 0; i < hostBuffer.frameCount; i++) {
|
||||
hostBuffer.reset();
|
||||
}
|
||||
final gpu.BufferView view1 = hostBuffer
|
||||
.emplace(Int8List.fromList(<int>[0, 1, 2, 3]).buffer.asByteData());
|
||||
|
||||
expect(view0.buffer, equals(view1.buffer));
|
||||
}, skip: !impellerEnabled);
|
||||
|
||||
test('GpuContext.createDeviceBuffer', () async {
|
||||
final gpu.DeviceBuffer? deviceBuffer =
|
||||
gpu.gpuContext.createDeviceBuffer(gpu.StorageMode.hostVisible, 4);
|
||||
|
||||
Reference in New Issue
Block a user