[Flutter GPU] Fix conditional when checking DeviceBuffer bounds. (flutter/engine#56017)

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

Fix a silly off-by-one that I didn't catch because none of the tests are using `DeviceBuffer` directly. 🤦
This commit is contained in:
Brandon DeRosier
2024-10-22 03:58:38 -07:00
committed by GitHub
parent 94fac8afbe
commit 3b568c8d68
2 changed files with 46 additions and 1 deletions

View File

@@ -434,7 +434,7 @@ static bool BindUniform(
return false;
}
if (!buffer || static_cast<size_t>(offset_in_bytes + length_in_bytes) >=
if (!buffer || static_cast<size_t>(offset_in_bytes + length_in_bytes) >
buffer->GetDeviceBufferDescriptor().size) {
return false;
}

View File

@@ -7,6 +7,7 @@
// ignore_for_file: avoid_relative_lib_imports
import 'dart:io';
import 'dart:typed_data';
import 'dart:ui' as ui;
@@ -395,6 +396,50 @@ void main() async {
await comparer.addGoldenImage(image, 'flutter_gpu_test_clear_color.png');
}, skip: !impellerEnabled);
// 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();
final gpu.UniformSlot vertInfo =
pipeline.vertexShader.getUniformSlot('VertInfo');
final ByteData vertInfoData = 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 uniformBuffer =
gpu.gpuContext.createDeviceBufferWithCopy(vertInfoData)!;
final gooduniformBufferView = gpu.BufferView(
uniformBuffer,
offsetInBytes: 0,
lengthInBytes: uniformBuffer.sizeInBytes,
);
state.renderPass.bindUniform(vertInfo, gooduniformBufferView);
final badUniformBufferView = gpu.BufferView(
uniformBuffer,
offsetInBytes: 0,
lengthInBytes: uniformBuffer.sizeInBytes + 1,
);
try {
state.renderPass.bindUniform(vertInfo, badUniformBufferView);
fail('Exception not thrown for bad buffer view range.');
} catch (e) {
expect(e.toString(), contains('Failed to bind uniform'));
}
}, skip: !impellerEnabled);
// Renders a green triangle pointing downwards.
test('Can render triangle', () async {
final state = createSimpleRenderPass();