From 2364e5990c7cbc35f2b36ab47afc85c6d359055d Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Tue, 25 May 2021 13:09:24 -0700 Subject: [PATCH] Dump shader outputs. --- .../impeller/compiler/code_gen_template.h | 35 ++++++++++++++++--- engine/src/flutter/impeller/host/main.mm | 3 +- .../impeller/compositor/vertex_descriptor.h | 2 +- .../impeller/compositor/vertex_descriptor.mm | 6 ++-- .../impeller/impeller/primitives/box.frag | 3 +- .../impeller/impeller/primitives/box.mm | 4 +-- .../impeller/impeller/primitives/box.vert | 4 +++ .../impeller/shader_glue/shader_types.h | 2 +- 8 files changed, 44 insertions(+), 15 deletions(-) diff --git a/engine/src/flutter/impeller/compiler/code_gen_template.h b/engine/src/flutter/impeller/compiler/code_gen_template.h index 5948b29631..f958346a7d 100644 --- a/engine/src/flutter/impeller/compiler/code_gen_template.h +++ b/engine/src/flutter/impeller/compiler/code_gen_template.h @@ -17,14 +17,19 @@ namespace impeller { namespace shader { struct {{camel_case(shader_name)}}{{camel_case(shader_stage)}}Info { + // =========================================================================== + // Stage Info ================================================================ + // =========================================================================== static constexpr std::string_view kLabel = "{{camel_case(shader_name)}}"; static constexpr std::string_view kEntrypointName = "{{entrypoint}}"; static constexpr ShaderStage kShaderStage = {{to_shader_stage(shader_stage)}}; - // Stage Inputs + // =========================================================================== + // Stage Inputs ============================================================== + // =========================================================================== {% for stage_input in stage_inputs %} - // Stage input {{stage_input.name}} - static constexpr auto kInput{{camel_case(stage_input.name)}} = ShaderStageInput { + + static constexpr auto kInput{{camel_case(stage_input.name)}} = ShaderStageIOSlot { // {{stage_input.name}} "{{stage_input.name}}", // name {{stage_input.location}}u, // attribute location {{stage_input.type.type_name}}, // type @@ -34,9 +39,29 @@ struct {{camel_case(shader_name)}}{{camel_case(shader_stage)}}Info { }; {% endfor %} - static constexpr std::array kAllShaderStageInputs[] = { + static constexpr std::array kAllShaderStageInputs = { {% for stage_input in stage_inputs %} - { &kInput{{camel_case(stage_input.name)}} }, // {{stage_input.name}} + &kInput{{camel_case(stage_input.name)}}, // {{stage_input.name}} +{% endfor %} + }; + + // =========================================================================== + // Stage Outputs ============================================================= + // =========================================================================== +{% for stage_output in stage_outputs %} + static constexpr auto kOutput{{camel_case(stage_output.name)}} = ShaderStageIOSlot { // {{stage_output.name}} + "{{stage_output.name}}", // name + {{stage_output.location}}u, // attribute location + {{stage_output.type.type_name}}, // type + {{stage_output.type.bit_width}}u, // bit width of type + {{stage_output.type.vec_size}}u, // vec size + {{stage_output.type.columns}}u // number of columns + }; +{% endfor %} + + static constexpr std::array kAllShaderStageOutputs = { +{% for stage_output in stage_outputs %} + &kOutput{{camel_case(stage_output.name)}}, // {{stage_output.name}} {% endfor %} }; diff --git a/engine/src/flutter/impeller/host/main.mm b/engine/src/flutter/impeller/host/main.mm index c16c53b72a..db234115d8 100644 --- a/engine/src/flutter/impeller/host/main.mm +++ b/engine/src/flutter/impeller/host/main.mm @@ -29,8 +29,7 @@ return self; } -- (void)applicationWillFinishLaunching:(NSNotification*)notification { - [window_ makeMainWindow]; +- (void)applicationDidFinishLaunching:(NSNotification*)notification { [window_ setTitle:@"Impeller Host"]; [window_ makeKeyAndOrderFront:self]; } diff --git a/engine/src/flutter/impeller/impeller/compositor/vertex_descriptor.h b/engine/src/flutter/impeller/impeller/compositor/vertex_descriptor.h index ae785c5825..43f8ba9ed1 100644 --- a/engine/src/flutter/impeller/impeller/compositor/vertex_descriptor.h +++ b/engine/src/flutter/impeller/impeller/compositor/vertex_descriptor.h @@ -20,7 +20,7 @@ class VertexDescriptor final : public Comparable { virtual ~VertexDescriptor(); - bool SetStageInputs(const ShaderStageInput* const stage_inputs[], + bool SetStageInputs(const ShaderStageIOSlot* const stage_inputs[], size_t count); MTLVertexDescriptor* GetMTLVertexDescriptor() const; diff --git a/engine/src/flutter/impeller/impeller/compositor/vertex_descriptor.mm b/engine/src/flutter/impeller/impeller/compositor/vertex_descriptor.mm index 448a3b19a3..e592c4f865 100644 --- a/engine/src/flutter/impeller/impeller/compositor/vertex_descriptor.mm +++ b/engine/src/flutter/impeller/impeller/compositor/vertex_descriptor.mm @@ -12,7 +12,7 @@ VertexDescriptor::VertexDescriptor() = default; VertexDescriptor::~VertexDescriptor() = default; -static MTLVertexFormat ReadStageInputFormat(const ShaderStageInput& input) { +static MTLVertexFormat ReadStageInputFormat(const ShaderStageIOSlot& input) { if (input.columns != 1) { // All matrix types are unsupported as vertex inputs. return MTLVertexFormatInvalid; @@ -169,12 +169,12 @@ static MTLVertexFormat ReadStageInputFormat(const ShaderStageInput& input) { } bool VertexDescriptor::SetStageInputs( - const ShaderStageInput* const stage_inputs[], + const ShaderStageIOSlot* const stage_inputs[], size_t count) { stage_inputs_.clear(); for (size_t i = 0; i < count; i++) { - const ShaderStageInput* input = stage_inputs[i]; + const ShaderStageIOSlot* input = stage_inputs[i]; auto vertex_format = ReadStageInputFormat(*input); if (vertex_format == MTLVertexFormatInvalid) { FML_LOG(ERROR) << "Format for input " << input->name << " not supported."; diff --git a/engine/src/flutter/impeller/impeller/primitives/box.frag b/engine/src/flutter/impeller/impeller/primitives/box.frag index 2c45c349d1..8f1aad5edf 100644 --- a/engine/src/flutter/impeller/impeller/primitives/box.frag +++ b/engine/src/flutter/impeller/impeller/primitives/box.frag @@ -3,9 +3,10 @@ // found in the LICENSE file. in vec3 color; +in vec3 color2; out vec3 fragColor; void main() { - fragColor = color; + fragColor = color * color2; } diff --git a/engine/src/flutter/impeller/impeller/primitives/box.mm b/engine/src/flutter/impeller/impeller/primitives/box.mm index 251b93a698..02b832aab8 100644 --- a/engine/src/flutter/impeller/impeller/primitives/box.mm +++ b/engine/src/flutter/impeller/impeller/primitives/box.mm @@ -31,8 +31,8 @@ bool RenderBox(std::shared_ptr context) { { auto vertex_descriptor = std::make_shared(); if (!vertex_descriptor->SetStageInputs( - shader::BoxVertexInfo::kAllShaderStageInputs->data(), - shader::BoxVertexInfo::kAllShaderStageInputs->size())) { + shader::BoxVertexInfo::kAllShaderStageInputs.data(), + shader::BoxVertexInfo::kAllShaderStageInputs.size())) { return false; } desc.SetVertexDescriptor(std::move(vertex_descriptor)); diff --git a/engine/src/flutter/impeller/impeller/primitives/box.vert b/engine/src/flutter/impeller/impeller/primitives/box.vert index ce7ea2c38a..6fa5eb17d0 100644 --- a/engine/src/flutter/impeller/impeller/primitives/box.vert +++ b/engine/src/flutter/impeller/impeller/primitives/box.vert @@ -8,6 +8,10 @@ uniform UniformBuffer { in vec3 vertexPosition; +out vec3 color; +out vec3 color2; + void main() { gl_Position = uniforms.mvp * vec4(vertexPosition, 1.0); + color = vec3(1.0, 1.0, 1.0); } diff --git a/engine/src/flutter/impeller/impeller/shader_glue/shader_types.h b/engine/src/flutter/impeller/impeller/shader_glue/shader_types.h index b9c5233e0c..a33fe41756 100644 --- a/engine/src/flutter/impeller/impeller/shader_glue/shader_types.h +++ b/engine/src/flutter/impeller/impeller/shader_glue/shader_types.h @@ -38,7 +38,7 @@ enum class ShaderType { kSampler, }; -struct ShaderStageInput { +struct ShaderStageIOSlot { const char* name; size_t location; ShaderType type;