mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Use impellerc for engine FragmentProgram unit tests (flutter/engine#33824)
This commit is contained in:
parent
4ff5915e97
commit
9a73afb34d
@ -138,8 +138,14 @@ Compiler::Compiler(const fml::Mapping& source_mapping,
|
||||
shaderc_spirv_version::shaderc_spirv_version_1_3);
|
||||
break;
|
||||
case TargetPlatform::kFlutterSPIRV:
|
||||
// With any optimization level above 'zero' enabled, shaderc will emit
|
||||
// ops that are not supported by the Engine's SPIR-V -> SkSL transpiler.
|
||||
// In particular, with 'shaderc_optimization_level_size' enabled, it will
|
||||
// generate OpPhi (opcode 245) for test 246_OpLoopMerge.frag instead of
|
||||
// the OpLoopMerge op expected by that test.
|
||||
// See: https://github.com/flutter/flutter/issues/105396.
|
||||
spirv_options.SetOptimizationLevel(
|
||||
shaderc_optimization_level::shaderc_optimization_level_size);
|
||||
shaderc_optimization_level::shaderc_optimization_level_zero);
|
||||
spirv_options.SetTargetEnvironment(
|
||||
shaderc_target_env::shaderc_target_env_opengl,
|
||||
shaderc_env_version::shaderc_env_version_opengl_4_5);
|
||||
|
||||
@ -15,12 +15,4 @@ if (enable_unittests) {
|
||||
"//third_party/swiftshader_flutter:spvtools_val",
|
||||
]
|
||||
}
|
||||
|
||||
executable("glsl_to_spirv") {
|
||||
sources = [ "glsl_to_spirv.cc" ]
|
||||
|
||||
configs += [ "//third_party/shaderc_flutter:shaderc_util_config" ]
|
||||
|
||||
deps = [ "//third_party/shaderc_flutter" ]
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,25 +3,21 @@
|
||||
# found in the LICENSE file.
|
||||
|
||||
import("//build/compiled_action.gni")
|
||||
import("//flutter/impeller/tools/impeller.gni")
|
||||
import("//flutter/testing/testing.gni")
|
||||
|
||||
if (enable_unittests) {
|
||||
compiled_action_foreach("spirv_compile_general_shaders") {
|
||||
tool = "//flutter/lib/spirv/test:glsl_to_spirv"
|
||||
|
||||
sources = [
|
||||
"blue_green_sampler.glsl",
|
||||
"children_and_uniforms.glsl",
|
||||
"functions.glsl",
|
||||
"simple.glsl",
|
||||
"uniforms.glsl",
|
||||
impellerc("spirv_compile_general_shaders") {
|
||||
shaders = [
|
||||
"blue_green_sampler.frag",
|
||||
"children_and_uniforms.frag",
|
||||
"functions.frag",
|
||||
"simple.frag",
|
||||
"uniforms.frag",
|
||||
]
|
||||
|
||||
outputs = [ "$target_gen_dir/{{source_name_part}}.spv" ]
|
||||
sl_file_extension = ".spirv"
|
||||
|
||||
args = [
|
||||
"{{source}}",
|
||||
rebase_path(target_gen_dir, root_build_dir) + "/{{source_name_part}}.spv",
|
||||
]
|
||||
shader_target_flag = "--flutter-spirv"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,66 +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 <cstdint>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "third_party/shaderc/libshaderc/include/shaderc/shaderc.hpp"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
if (argc != 3) {
|
||||
std::cerr << "Invalid argument count." << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
fs::path path(argv[1]);
|
||||
if (!fs::is_regular_file(path)) {
|
||||
std::cerr << "File is not a regular file." << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::fstream input;
|
||||
input.open(argv[1]);
|
||||
input.seekg(0, std::ios::end);
|
||||
std::streampos size = input.tellg();
|
||||
input.seekg(0, std::ios::beg);
|
||||
std::vector<char> buf(static_cast<int>(size) + 1);
|
||||
input.read(buf.data(), size);
|
||||
buf[size] = 0; // make sure the string is null terminated.
|
||||
input.close();
|
||||
|
||||
shaderc::Compiler compiler;
|
||||
shaderc::CompileOptions options;
|
||||
options.SetOptimizationLevel(shaderc_optimization_level_zero);
|
||||
options.SetTargetEnvironment(shaderc_target_env_opengl, 0);
|
||||
shaderc::SpvCompilationResult result = compiler.CompileGlslToSpv(
|
||||
buf.data(), shaderc_glsl_default_fragment_shader, argv[1], options);
|
||||
|
||||
if (result.GetCompilationStatus() != shaderc_compilation_status_success) {
|
||||
std::cerr << "Failed to transpile: " + result.GetErrorMessage() << argv[1]
|
||||
<< std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::vector<uint32_t> spirv =
|
||||
std::vector<uint32_t>(result.cbegin(), result.cend());
|
||||
|
||||
std::fstream output;
|
||||
output.open(argv[2], std::fstream::out | std::fstream::trunc);
|
||||
|
||||
if (!output.is_open()) {
|
||||
output.close();
|
||||
std::cerr << "failed to open output file" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
output.write(reinterpret_cast<const char*>(spirv.data()),
|
||||
sizeof(uint32_t) * spirv.size());
|
||||
output.close();
|
||||
return 0;
|
||||
}
|
||||
@ -3,53 +3,49 @@
|
||||
# found in the LICENSE file.
|
||||
|
||||
import("//build/compiled_action.gni")
|
||||
import("//flutter/impeller/tools/impeller.gni")
|
||||
import("//flutter/testing/testing.gni")
|
||||
|
||||
if (enable_unittests) {
|
||||
compiled_action_foreach("spirv_compile_supported_glsl_shaders") {
|
||||
tool = "//flutter/lib/spirv/test:glsl_to_spirv"
|
||||
|
||||
sources = [
|
||||
"10_fract.glsl",
|
||||
"11_radians.glsl",
|
||||
"12_degrees.glsl",
|
||||
"13_sin.glsl",
|
||||
"14_cos.glsl",
|
||||
"15_tan.glsl",
|
||||
"16_asin.glsl",
|
||||
"17_acos.glsl",
|
||||
"18_atan.glsl",
|
||||
"25_atan2.glsl",
|
||||
"26_pow.glsl",
|
||||
"27_exp.glsl",
|
||||
"28_log.glsl",
|
||||
"29_exp2.glsl",
|
||||
"30_log2.glsl",
|
||||
"31_sqrt.glsl",
|
||||
"32_inversesqrt.glsl",
|
||||
"37_fmin.glsl",
|
||||
"40_fmax.glsl",
|
||||
"43_fclamp.glsl",
|
||||
"46_fmix.glsl",
|
||||
"48_step.glsl",
|
||||
"49_smoothstep.glsl",
|
||||
"4_abs.glsl",
|
||||
"66_length.glsl",
|
||||
"67_distance.glsl",
|
||||
"68_cross.glsl",
|
||||
"69_normalize.glsl",
|
||||
"6_sign.glsl",
|
||||
"70_faceforward.glsl",
|
||||
"71_reflect.glsl",
|
||||
"8_floor.glsl",
|
||||
"9_ceil.glsl",
|
||||
impellerc("spirv_compile_supported_glsl_shaders") {
|
||||
shaders = [
|
||||
"10_fract.frag",
|
||||
"11_radians.frag",
|
||||
"12_degrees.frag",
|
||||
"13_sin.frag",
|
||||
"14_cos.frag",
|
||||
"15_tan.frag",
|
||||
"16_asin.frag",
|
||||
"17_acos.frag",
|
||||
"18_atan.frag",
|
||||
"25_atan2.frag",
|
||||
"26_pow.frag",
|
||||
"27_exp.frag",
|
||||
"28_log.frag",
|
||||
"29_exp2.frag",
|
||||
"30_log2.frag",
|
||||
"31_sqrt.frag",
|
||||
"32_inversesqrt.frag",
|
||||
"37_fmin.frag",
|
||||
"40_fmax.frag",
|
||||
"43_fclamp.frag",
|
||||
"46_fmix.frag",
|
||||
"48_step.frag",
|
||||
"49_smoothstep.frag",
|
||||
"4_abs.frag",
|
||||
"66_length.frag",
|
||||
"67_distance.frag",
|
||||
"68_cross.frag",
|
||||
"69_normalize.frag",
|
||||
"6_sign.frag",
|
||||
"70_faceforward.frag",
|
||||
"71_reflect.frag",
|
||||
"8_floor.frag",
|
||||
"9_ceil.frag",
|
||||
]
|
||||
|
||||
outputs = [ "$target_gen_dir/{{source_name_part}}.spv" ]
|
||||
sl_file_extension = ".spirv"
|
||||
|
||||
args = [
|
||||
"{{source}}",
|
||||
rebase_path(target_gen_dir, root_build_dir) + "/{{source_name_part}}.spv",
|
||||
]
|
||||
shader_target_flag = "--flutter-spirv"
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,49 +3,45 @@
|
||||
# found in the LICENSE file.
|
||||
|
||||
import("//build/compiled_action.gni")
|
||||
import("//flutter/impeller/tools/impeller.gni")
|
||||
import("//flutter/testing/testing.gni")
|
||||
|
||||
if (enable_unittests) {
|
||||
compiled_action_foreach("spirv_compile_supported_op_shaders") {
|
||||
tool = "//flutter/lib/spirv/test:glsl_to_spirv"
|
||||
|
||||
sources = [
|
||||
"127_OpFNegate.glsl",
|
||||
"129_OpFAdd.glsl",
|
||||
"131_OpFSub.glsl",
|
||||
"142_OpVectorTimesScalar.glsl",
|
||||
"143_OpMatrixTimesScalar.glsl",
|
||||
"144_OpVectorTimesMatrix.glsl",
|
||||
"145_OpMatrixTimesVector.glsl",
|
||||
"146_OpMatrixTimesMatrix.glsl",
|
||||
"148_OpDot.glsl",
|
||||
"164_OpLogicalEqual.glsl",
|
||||
"165_OpLogicalNotEqual.glsl",
|
||||
"166_OpLogicalOr.glsl",
|
||||
"167_OpLogicalAnd.glsl",
|
||||
"168_OpLogicalNot.glsl",
|
||||
"180_OpFOrdEqual.glsl",
|
||||
"183_OpFUnordNotEqual.glsl",
|
||||
"184_OpFOrdLessThan.glsl",
|
||||
"186_OpFOrdGreaterThan.glsl",
|
||||
"188_OpFOrdLessThanEqual.glsl",
|
||||
"190_OpFOrdGreaterThanEqual.glsl",
|
||||
"19_OpTypeVoid.glsl",
|
||||
"20_OpTypeBool.glsl",
|
||||
"21_OpTypeInt.glsl",
|
||||
"22_OpTypeFloat.glsl",
|
||||
"23_OpTypeVector.glsl",
|
||||
"246_OpLoopMerge.glsl",
|
||||
"24_OpTypeMatrix.glsl",
|
||||
"250_OpBranchConditional.glsl",
|
||||
"33_OpTypeFunction.glsl",
|
||||
impellerc("spirv_compile_supported_op_shaders") {
|
||||
shaders = [
|
||||
"127_OpFNegate.frag",
|
||||
"129_OpFAdd.frag",
|
||||
"131_OpFSub.frag",
|
||||
"142_OpVectorTimesScalar.frag",
|
||||
"143_OpMatrixTimesScalar.frag",
|
||||
"144_OpVectorTimesMatrix.frag",
|
||||
"145_OpMatrixTimesVector.frag",
|
||||
"146_OpMatrixTimesMatrix.frag",
|
||||
"148_OpDot.frag",
|
||||
"164_OpLogicalEqual.frag",
|
||||
"165_OpLogicalNotEqual.frag",
|
||||
"166_OpLogicalOr.frag",
|
||||
"167_OpLogicalAnd.frag",
|
||||
"168_OpLogicalNot.frag",
|
||||
"180_OpFOrdEqual.frag",
|
||||
"183_OpFUnordNotEqual.frag",
|
||||
"184_OpFOrdLessThan.frag",
|
||||
"186_OpFOrdGreaterThan.frag",
|
||||
"188_OpFOrdLessThanEqual.frag",
|
||||
"190_OpFOrdGreaterThanEqual.frag",
|
||||
"19_OpTypeVoid.frag",
|
||||
"20_OpTypeBool.frag",
|
||||
"21_OpTypeInt.frag",
|
||||
"22_OpTypeFloat.frag",
|
||||
"23_OpTypeVector.frag",
|
||||
"246_OpLoopMerge.frag",
|
||||
"24_OpTypeMatrix.frag",
|
||||
"250_OpBranchConditional.frag",
|
||||
"33_OpTypeFunction.frag",
|
||||
]
|
||||
|
||||
outputs = [ "$target_gen_dir/{{source_name_part}}.spv" ]
|
||||
sl_file_extension = ".spirv"
|
||||
|
||||
args = [
|
||||
"{{source}}",
|
||||
rebase_path(target_gen_dir, root_build_dir) + "/{{source_name_part}}.spv",
|
||||
]
|
||||
shader_target_flag = "--flutter-spirv"
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('simple shader renders correctly', () async {
|
||||
final Uint8List shaderBytes = await spvFile('general_shaders', 'functions.spv').readAsBytes();
|
||||
final Uint8List shaderBytes = await spvFile('general_shaders', 'functions.frag.spirv').readAsBytes();
|
||||
final FragmentProgram program = await FragmentProgram.compile(
|
||||
spirv: shaderBytes.buffer,
|
||||
);
|
||||
@ -35,7 +35,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('shader with functions renders green', () async {
|
||||
final ByteBuffer spirv = spvFile('general_shaders', 'functions.spv').readAsBytesSync().buffer;
|
||||
final ByteBuffer spirv = spvFile('general_shaders', 'functions.frag.spirv').readAsBytesSync().buffer;
|
||||
final FragmentProgram program = await FragmentProgram.compile(
|
||||
spirv: spirv,
|
||||
);
|
||||
@ -46,7 +46,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('blue-green image renders green', () async {
|
||||
final ByteBuffer spirv = spvFile('general_shaders', 'blue_green_sampler.spv').readAsBytesSync().buffer;
|
||||
final ByteBuffer spirv = spvFile('general_shaders', 'blue_green_sampler.frag.spirv').readAsBytesSync().buffer;
|
||||
final FragmentProgram program = await FragmentProgram.compile(
|
||||
debugPrint: true,
|
||||
spirv: spirv,
|
||||
@ -61,7 +61,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('shader with uniforms renders correctly', () async {
|
||||
final Uint8List shaderBytes = await spvFile('general_shaders', 'uniforms.spv').readAsBytes();
|
||||
final Uint8List shaderBytes = await spvFile('general_shaders', 'uniforms.frag.spirv').readAsBytes();
|
||||
final FragmentProgram program = await FragmentProgram.compile(spirv: shaderBytes.buffer);
|
||||
|
||||
final Shader shader = program.shader(
|
||||
@ -100,7 +100,7 @@ void main() {
|
||||
_expectShadersHaveOp(supportedOpShaders, false /* glsl ops */);
|
||||
|
||||
test('equality depends on floatUniforms', () async {
|
||||
final ByteBuffer spirv = spvFile('general_shaders', 'simple.spv')
|
||||
final ByteBuffer spirv = spvFile('general_shaders', 'simple.frag.spirv')
|
||||
.readAsBytesSync().buffer;
|
||||
final FragmentProgram program = await FragmentProgram.compile(spirv: spirv);
|
||||
final Float32List ones = Float32List.fromList(<double>[1]);
|
||||
@ -122,9 +122,9 @@ void main() {
|
||||
});
|
||||
|
||||
test('equality depends on spirv', () async {
|
||||
final ByteBuffer spirvA = spvFile('general_shaders', 'simple.spv')
|
||||
final ByteBuffer spirvA = spvFile('general_shaders', 'simple.frag.spirv')
|
||||
.readAsBytesSync().buffer;
|
||||
final ByteBuffer spirvB = spvFile('general_shaders', 'uniforms.spv')
|
||||
final ByteBuffer spirvB = spvFile('general_shaders', 'uniforms.frag.spirv')
|
||||
.readAsBytesSync().buffer;
|
||||
final FragmentProgram programA = await FragmentProgram.compile(spirv: spirvA);
|
||||
final FragmentProgram programB = await FragmentProgram.compile(spirv: spirvB);
|
||||
@ -136,7 +136,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('Compilation does not create a Timer object', () async {
|
||||
final ByteBuffer spirvA = spvFile('general_shaders', 'simple.spv')
|
||||
final ByteBuffer spirvA = spvFile('general_shaders', 'simple.frag.spirv')
|
||||
.readAsBytesSync().buffer;
|
||||
bool createdTimer = false;
|
||||
final ZoneSpecification specification = ZoneSpecification(createTimer: (Zone self, ZoneDelegate parent, Zone zone, Duration duration, void Function() f) {
|
||||
@ -254,7 +254,7 @@ Map<String, ByteBuffer> _loadSpv(String leafFolderName) {
|
||||
|
||||
directory
|
||||
.listSync()
|
||||
.where((FileSystemEntity entry) => path.extension(entry.path) == '.spv')
|
||||
.where((FileSystemEntity entry) => path.extension(entry.path) == '.spirv')
|
||||
.forEach((FileSystemEntity entry) {
|
||||
final String key = path.basenameWithoutExtension(entry.path);
|
||||
out[key] = (entry as File).readAsBytesSync().buffer;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user