mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[impellerc] add GLES shader define. (#170375)
Fixes https://github.com/flutter/flutter/issues/169429 For ImageShader.filter we need a way to distinguish between the coordinate system of GL vs Metal/Vulkan. I documented in https://github.com/flutter/flutter/pull/169761 how to do it but neglected to wire up the define. This fixes that.
This commit is contained in:
parent
2bc99def13
commit
2773965a3c
@ -363,6 +363,11 @@ Compiler::Compiler(const std::shared_ptr<const fml::Mapping>& source_mapping,
|
||||
|
||||
spirv_options.target = target;
|
||||
spirv_options.macro_definitions.push_back("IMPELLER_GRAPHICS_BACKEND");
|
||||
if (source_options.target_platform == TargetPlatform::kRuntimeStageGLES ||
|
||||
source_options.target_platform ==
|
||||
TargetPlatform::kRuntimeStageGLES3) {
|
||||
spirv_options.macro_definitions.push_back("IMPELLER_TARGET_OPENGLES");
|
||||
}
|
||||
} break;
|
||||
case TargetPlatform::kSkSL: {
|
||||
SPIRVCompilerTargetEnv target;
|
||||
|
||||
@ -15,6 +15,30 @@ namespace impeller {
|
||||
namespace compiler {
|
||||
namespace testing {
|
||||
|
||||
TEST(CompilerTest, Defines) {
|
||||
std::shared_ptr<const fml::Mapping> fixture =
|
||||
flutter::testing::OpenFixtureAsMapping("check_gles_definition.frag");
|
||||
|
||||
SourceOptions options;
|
||||
options.source_language = SourceLanguage::kGLSL;
|
||||
options.target_platform = TargetPlatform::kRuntimeStageGLES;
|
||||
options.entry_point_name = "main";
|
||||
options.type = SourceType::kFragmentShader;
|
||||
|
||||
Reflector::Options reflector_options;
|
||||
reflector_options.target_platform = TargetPlatform::kRuntimeStageGLES;
|
||||
Compiler compiler = Compiler(fixture, options, reflector_options);
|
||||
|
||||
// Should fail as the shader has a compilation error in it.
|
||||
EXPECT_EQ(compiler.GetSPIRVAssembly(), nullptr);
|
||||
|
||||
// Should succeed as the compilation error is ifdef'd out.
|
||||
options.target_platform = TargetPlatform::kRuntimeStageVulkan;
|
||||
reflector_options.target_platform = TargetPlatform::kRuntimeStageVulkan;
|
||||
Compiler compiler_2 = Compiler(fixture, options, reflector_options);
|
||||
EXPECT_NE(compiler_2.GetSPIRVAssembly(), nullptr);
|
||||
}
|
||||
|
||||
TEST(CompilerTest, ShaderKindMatchingIsSuccessful) {
|
||||
ASSERT_EQ(SourceTypeFromFileName("hello.vert"), SourceType::kVertexShader);
|
||||
ASSERT_EQ(SourceTypeFromFileName("hello.frag"), SourceType::kFragmentShader);
|
||||
|
||||
@ -131,6 +131,7 @@ test_fixtures("file_fixtures") {
|
||||
"sample.comp",
|
||||
"sample.frag",
|
||||
"sample.vert",
|
||||
"check_gles_definition.frag",
|
||||
"sample_with_binding.vert",
|
||||
"simple.vert.hlsl",
|
||||
"sa%m#ple.vert",
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
// 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.
|
||||
|
||||
out vec4 out_color;
|
||||
|
||||
void main() {
|
||||
#ifdef IMPELLER_TARGET_OPENGLES
|
||||
fail
|
||||
#else
|
||||
out_color = vec4(1, 0, 0, 0);
|
||||
#endif
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user