Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if (enable_unittests) {
"uniforms_reordered.frag",
"uniforms_sorted.frag",
"uniforms.frag",
"uniforms_renamed.frag",
"vec3_uniform.frag",
]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#version 320 es

// 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.

// Note: Don't update this file without updating `uniforms_reordered.frag`.
// Note: Don't update this file without updating `uniforms_inserted.frag`.

precision highp float;

layout(location = 0) out vec4 oColor;

layout(location = 0) uniform float iFloatUniformRenamed;
layout(location = 1) uniform vec2 iVec2Uniform;
layout(location = 2) uniform mat2 iMat2Uniform;

void main() {
oColor = vec4(iFloatUniformRenamed, iVec2Uniform, iMat2Uniform[1][1]);
}
8 changes: 8 additions & 0 deletions engine/src/flutter/lib/ui/painting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5391,6 +5391,10 @@ base class FragmentProgram extends NativeFieldWrapperClass1 {
return true;
}

if (!program._hasUniform(slot.name)) {
return true;
}

slot._shaderIndex = program._getUniformFloatIndex(slot.name, slot.index);
return false;
});
Expand All @@ -5409,6 +5413,10 @@ base class FragmentProgram extends NativeFieldWrapperClass1 {
});
}

bool _hasUniform(String name) {
return _uniformInfo.any((dynamic entry) => (entry! as Map<String, Object>)['name'] == name);
}

int _getImageSamplerIndex(String name) {
var index = 0;
var found = false;
Expand Down
37 changes: 37 additions & 0 deletions engine/src/flutter/testing/dart/vm_service/shader_reload_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,43 @@ void main() {
}
});

test('rename uniforms', () async {
if (impellerEnabled) {
// Needs https://github.com/flutter/flutter/issues/129659
return;
}
final testAssetName = 'test_rename_uniforms_${DateTime.now().millisecondsSinceEpoch}.frag.iplr';
final String buildDir = Platform.environment['FLUTTER_BUILD_DIRECTORY']!;
final String assetsDir = path.join(buildDir, 'gen/flutter/lib/ui/assets');
final String shaderSrcA = path.join(assetsDir, 'uniforms.frag.iplr');
final String shaderSrcB = path.join(assetsDir, 'uniforms_renamed.frag.iplr');
final String shaderSrcC = path.join(assetsDir, testAssetName);

final fileC = File(shaderSrcC);
final Uint8List sourceA = File(shaderSrcA).readAsBytesSync();
final Uint8List sourceB = File(shaderSrcB).readAsBytesSync();

fileC.writeAsBytesSync(sourceA, flush: true);

try {
final FragmentProgram program = await FragmentProgram.fromAsset(testAssetName);
final FragmentShader shader = program.fragmentShader();
final UniformFloatSlot slotA = shader.getUniformFloat('iFloatUniform');
slotA.set(1.0);

fileC.writeAsBytesSync(sourceB, flush: true);
await _performReload(testAssetName);

final UniformFloatSlot slotB = shader.getUniformFloat('iFloatUniformRenamed');
// Make sure this doesn't break.
slotB.set(0.0);
} finally {
if (fileC.existsSync()) {
fileC.deleteSync();
}
}
});

test('reorder samplers', () async {
if (impellerEnabled) {
// Needs https://github.com/flutter/flutter/issues/129659
Expand Down