Disambiguate stages.

This commit is contained in:
Chinmay Garde
2021-05-20 14:11:32 -07:00
committed by Dan Field
parent ee3b16e857
commit 8da39c0afb
9 changed files with 67 additions and 12 deletions

View File

@@ -16,16 +16,16 @@ constexpr std::string_view kReflectionHeaderTemplate = R"~~(
namespace impeller {
namespace shader {
struct {{camel_case(shader_name)}} {
struct {{camel_case(shader_name)}}{{camel_case(shader_stage)}}Info {
static constexpr std::string_view kEntrypointName = "{{entrypoint}}";
static constexpr ShaderStage kShaderStage = {{shader_stage}};
static constexpr ShaderStage kShaderStage = {{to_shader_stage(shader_stage)}};
// Stage Inputs
{% for stage_input in stage_inputs %}
// Stage input {{stage_input.name}}
static constexpr ShaderStageInput kInput{{camel_case(stage_input.name)}} = {"{{stage_input.name}}", {{stage_input.location}}};
{% endfor %}
}; // struct {{camel_case(shader_name)}}
}; // struct {{camel_case(shader_name)}}{{camel_case(shader_stage)}}Info
} // namespace shader
} // namespace impeller

View File

@@ -263,7 +263,6 @@ Compiler::Compiler(const fml::Mapping& source_mapping,
source_options.entry_point_name.c_str(), // entry_point_name
options // options
));
if (spv_result_->GetCompilationStatus() !=
shaderc_compilation_status::shaderc_compilation_status_success) {
COMPILER_ERROR << "GLSL to SPIRV failed; "

View File

@@ -150,14 +150,26 @@ static bool ReflectUniformBuffer(Writer& writer,
static std::string ExecutionModelToString(spv::ExecutionModel model) {
switch (model) {
case spv::ExecutionModel::ExecutionModelVertex:
return "ShaderStage::kVertex";
return "vertex";
case spv::ExecutionModel::ExecutionModelFragment:
return "ShaderStage::kFragment";
return "fragment";
default:
return "ShaderStage::kUnsupported";
return "unsupported";
}
}
static std::string StringToShaderStage(std::string str) {
if (str == "vertex") {
return "ShaderStage::kVertex";
}
if (str == "fragment") {
return "ShaderStage::kFragment";
}
return "ShaderStage::kUnknown";
}
static std::shared_ptr<fml::Mapping> ReflectTemplateArguments(
const Reflector::Options& options,
const spirv_cross::CompilerMSL& compiler) {
@@ -235,6 +247,10 @@ static std::shared_ptr<fml::Mapping> InflateTemplate(
return ConvertToCamelCase(args.at(0u)->get<std::string>());
});
env.add_callback("to_shader_stage", 1u, [](inja::Arguments& args) {
return StringToShaderStage(args.at(0u)->get<std::string>());
});
auto template_data = inja::json::parse(
reinterpret_cast<const char*>(reflection_args->GetMapping()));

View File

@@ -62,7 +62,18 @@ template("impeller_shaders") {
}
shader_glue_target_name = "glue_$target_name"
shader_glue_config_name = "glue_config_$target_name"
config(shader_glue_config_name) {
# Contains the generated header headers.
include_dirs = [ target_gen_dir ]
}
source_set(shader_glue_target_name) {
public_configs = [ ":$shader_glue_config_name" ]
public =
filter_include(get_target_outputs(":$impellerc_target_name"), [ "*.h" ])
sources = filter_include(get_target_outputs(":$impellerc_target_name"),
[
"*.h",
@@ -75,7 +86,7 @@ template("impeller_shaders") {
}
group(target_name) {
deps = [
public_deps = [
":$metal_library_target_name",
":$shader_glue_target_name",
]

View File

@@ -4,7 +4,7 @@
import("//flutter/impeller/tools/impeller.gni")
impeller_shaders("shaders") {
impeller_shaders("impeller_shaders") {
name = "impeller"
shaders = [
"box.vert",
@@ -20,5 +20,5 @@ impeller_component("primitives") {
public_deps = [ "../compositor" ]
deps = [ ":shaders" ]
deps = [ ":impeller_shaders" ]
}

View File

@@ -0,0 +1,14 @@
// 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 "impeller/primitives/box.h"
#include "box.frag.h"
#include "box.vert.h"
namespace impeller {
void RenderBox() {}
} // namespace impeller

View File

@@ -0,0 +1,9 @@
// 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.
namespace impeller {
void RenderBox();
} // namespace impeller

View File

@@ -2,10 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
uniform UniformBuffer{
uniform UniformBuffer {
mat4 mvp;
} uniforms;
uniform UniformBuffer2 {
uniform mat4 longGOP;
} uniforms2;
in vec3 vertexPosition;
in vec3 vertexColor;
@@ -13,6 +17,6 @@ out vec3 color;
void main()
{
gl_Position = uniforms.mvp * vec4(vertexPosition, 1.0);
gl_Position = uniforms2.longGOP * uniforms.mvp * vec4(vertexPosition, 1.0);
color = vertexColor;
}

View File

@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#pragma once
#include <cstddef>
#include <string_view>