Dump shader outputs.

This commit is contained in:
Chinmay Garde
2021-05-25 13:09:24 -07:00
committed by Dan Field
parent 9793900968
commit 2364e5990c
8 changed files with 44 additions and 15 deletions

View File

@@ -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<const ShaderStageInput*, {{length(stage_inputs)}}> kAllShaderStageInputs[] = {
static constexpr std::array<const ShaderStageIOSlot*, {{length(stage_inputs)}}> 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<const ShaderStageIOSlot*, {{length(stage_outputs)}}> kAllShaderStageOutputs = {
{% for stage_output in stage_outputs %}
&kOutput{{camel_case(stage_output.name)}}, // {{stage_output.name}}
{% endfor %}
};

View File

@@ -29,8 +29,7 @@
return self;
}
- (void)applicationWillFinishLaunching:(NSNotification*)notification {
[window_ makeMainWindow];
- (void)applicationDidFinishLaunching:(NSNotification*)notification {
[window_ setTitle:@"Impeller Host"];
[window_ makeKeyAndOrderFront:self];
}

View File

@@ -20,7 +20,7 @@ class VertexDescriptor final : public Comparable<VertexDescriptor> {
virtual ~VertexDescriptor();
bool SetStageInputs(const ShaderStageInput* const stage_inputs[],
bool SetStageInputs(const ShaderStageIOSlot* const stage_inputs[],
size_t count);
MTLVertexDescriptor* GetMTLVertexDescriptor() const;

View File

@@ -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.";

View File

@@ -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;
}

View File

@@ -31,8 +31,8 @@ bool RenderBox(std::shared_ptr<Context> context) {
{
auto vertex_descriptor = std::make_shared<VertexDescriptor>();
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));

View File

@@ -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);
}

View File

@@ -38,7 +38,7 @@ enum class ShaderType {
kSampler,
};
struct ShaderStageInput {
struct ShaderStageIOSlot {
const char* name;
size_t location;
ShaderType type;