diff --git a/engine/src/flutter/lib/gpu/render_pass.cc b/engine/src/flutter/lib/gpu/render_pass.cc index fda1dbbd23..d83d5a661a 100644 --- a/engine/src/flutter/lib/gpu/render_pass.cc +++ b/engine/src/flutter/lib/gpu/render_pass.cc @@ -434,7 +434,7 @@ static bool BindUniform( return false; } - if (!buffer || static_cast(offset_in_bytes + length_in_bytes) >= + if (!buffer || static_cast(offset_in_bytes + length_in_bytes) > buffer->GetDeviceBufferDescriptor().size) { return false; } diff --git a/engine/src/flutter/testing/dart/gpu_test.dart b/engine/src/flutter/testing/dart/gpu_test.dart index 47c0c7d1ea..267d3f0f06 100644 --- a/engine/src/flutter/testing/dart/gpu_test.dart +++ b/engine/src/flutter/testing/dart/gpu_test.dart @@ -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([ + 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();