11 R
"~~(// THIS FILE IS GENERATED BY impellerc.
12// DO NOT EDIT OR CHECK THIS INTO SOURCE CONTROL
16{# Note: The nogncheck decorations are only to make GN not mad at the template#}
17{# this file is generated from. There are no GN rule violations in the generated#}
18{# file itself and the no-check declarations will be stripped in generated files.#}
19#include "impeller/core/buffer_view.h" {# // nogncheck #}
21#include "impeller/core/sampler.h" {# // nogncheck #}
23#include "impeller/core/shader_types.h" {# // nogncheck #}
25#include "impeller/core/resource_binder.h" {# // nogncheck #}
27#include "impeller/core/texture.h" {# // nogncheck #}
32struct {{camel_case(shader_name)}}{{camel_case(shader_stage)}}Shader {
33 // ===========================================================================
34 // Stage Info ================================================================
35 // ===========================================================================
36 static constexpr std::string_view kLabel = "{{camel_case(shader_name)}}";
37 static constexpr std::string_view kEntrypointName = "{{entrypoint}}";
38 static constexpr ShaderStage kShaderStage = {{to_shader_stage(shader_stage)}};
39 // The generator used to prepare these bindings. Metal generators may be used
40 // by GLES backends but GLES generators are unsuitable for the metal backend.
41 static constexpr std::string_view kGeneratorName = "{{get_generator_name()}}";
42{% if length(struct_definitions) > 0 %}
43 // ===========================================================================
44 // Struct Definitions ========================================================
45 // ===========================================================================
46{% for def in struct_definitions %}
48{% if last(def.members).array_elements == 0 %}
49 template <size_t FlexCount>
52{% for member in def.members %}
53{{" "}}{% if member.element_padding > 0 %}Padded<{{member.type}}, {{member.element_padding}}>{% else %}{{member.type}}{% endif %}{{" " + member.name}}{% if member.array_elements != "std::nullopt" %}[{% if member.array_elements == 0 %}FlexCount{% else %}{{member.array_elements}}{% endif %}]{% endif %}; // (offset {{member.offset}}, size {{member.byte_length}})
55 }; // struct {{def.name}} (size {{def.byte_length}})
58{% if length(buffers) > 0 %}
60 // ===========================================================================
61 // Stage Uniform & Storage Buffers ===========================================
62 // ===========================================================================
63{% for buffer in buffers %}
65 static constexpr auto kResource{{camel_case(buffer.name)}} = ShaderUniformSlot { // {{buffer.name}}
66 "{{buffer.name}}", // name
67 {{buffer.ext_res_0}}u, // ext_res_0
68 {{buffer.set}}u, // set
69 {{buffer.binding}}u, // binding
71 static ShaderMetadata kMetadata{{camel_case(buffer.name)}};
75 // ===========================================================================
76 // Stage Inputs ==============================================================
77 // ===========================================================================
78{% if length(stage_inputs) > 0 %}
79{% for stage_input in stage_inputs %}
81 static constexpr auto kInput{{camel_case(stage_input.name)}} = ShaderStageIOSlot { // {{stage_input.name}}
82 "{{stage_input.name}}", // name
83 {{stage_input.location}}u, // attribute location
84 {{stage_input.descriptor_set}}u, // attribute set
85 {{stage_input.binding}}u, // attribute binding
86 {{stage_input.type.type_name}}, // type
87 {{stage_input.type.bit_width}}u, // bit width of type
88 {{stage_input.type.vec_size}}u, // vec size
89 {{stage_input.type.columns}}u, // number of columns
90 {{stage_input.offset}}u, // offset for interleaved layout
95 static constexpr std::array<const ShaderStageIOSlot*, {{length(stage_inputs)}}> kAllShaderStageInputs = {
96{% for stage_input in stage_inputs %}
97 &kInput{{camel_case(stage_input.name)}}, // {{stage_input.name}}
101{% if shader_stage == "vertex" %}
102 static constexpr auto kInterleavedLayout = ShaderStageBufferLayout {
103{% if length(stage_inputs) > 0 %}
104 sizeof(PerVertexData), // stride for interleaved layout
108 0u, // attribute binding
110 static constexpr std::array<const ShaderStageBufferLayout*, 1> kInterleavedBufferLayout = {
115{% if length(sampled_images) > 0 %}
116 // ===========================================================================
117 // Sampled Images ============================================================
118 // ===========================================================================
119{% for sampled_image in sampled_images %}
121 static constexpr auto kResource{{camel_case(sampled_image.name)}} = SampledImageSlot { // {{sampled_image.name}}
122 "{{sampled_image.name}}", // name
123 {{sampled_image.ext_res_0}}u, // ext_res_0
124 {{sampled_image.set}}u, // set
125 {{sampled_image.binding}}u, // binding
127 static ShaderMetadata kMetadata{{camel_case(sampled_image.name)}};
130 // ===========================================================================
131 // Stage Outputs =============================================================
132 // ===========================================================================
133{% if length(stage_outputs) > 0 %}
134{% for stage_output in stage_outputs %}
135 static constexpr auto kOutput{{camel_case(stage_output.name)}} = ShaderStageIOSlot { // {{stage_output.name}}
136 "{{stage_output.name}}", // name
137 {{stage_output.location}}u, // attribute location
138 {{stage_output.descriptor_set}}u, // attribute set
139 {{stage_output.binding}}u, // attribute binding
140 {{stage_output.type.type_name}}, // type
141 {{stage_output.type.bit_width}}u, // bit width of type
142 {{stage_output.type.vec_size}}u, // vec size
143 {{stage_output.type.columns}}u // number of columns
146 static constexpr std::array<const ShaderStageIOSlot*, {{length(stage_outputs)}}> kAllShaderStageOutputs = {
147{% for stage_output in stage_outputs %}
148 &kOutput{{camel_case(stage_output.name)}}, // {{stage_output.name}}
153 // ===========================================================================
154 // Resource Binding Utilities ================================================
155 // ===========================================================================
157{% for proto in bind_prototypes %}
159 static {{proto.return_type}} Bind{{proto.name}}({% for arg in proto.args %}
160{{arg.type_name}} {{arg.argument_name}}{% if not loop.is_last %}, {% endif %}
162 return {{ proto.args.0.argument_name }}.BindResource({% for arg in proto.args %}
163 {% if loop.is_first %}
164{{to_shader_stage(shader_stage)}}, {{ proto.descriptor_type }}, kResource{{ proto.name }}, kMetadata{{ proto.name }}, {% else %}
165std::move({{ arg.argument_name }}){% if not loop.is_last %}, {% endif %}
172 // ===========================================================================
173 // Metadata for Vulkan =======================================================
174 // ===========================================================================
175 static constexpr std::array<DescriptorSetLayout,{{length(buffers)+length(sampled_images)+length(subpass_inputs)}}> kDescriptorSetLayouts{
176{% for subpass_input in subpass_inputs %}
178 {{subpass_input.binding}}, // binding = {{subpass_input.binding}}
179 {{subpass_input.descriptor_type}}, // descriptor_type = {{subpass_input.descriptor_type}}
180 {{to_shader_stage(shader_stage)}}, // shader_stage = {{to_shader_stage(shader_stage)}}
183{% for buffer in buffers %}
185 {{buffer.binding}}, // binding = {{buffer.binding}}
186 {{buffer.descriptor_type}}, // descriptor_type = {{buffer.descriptor_type}}
187 {{to_shader_stage(shader_stage)}}, // shader_stage = {{to_shader_stage(shader_stage)}}
190{% for sampled_image in sampled_images %}
192 {{sampled_image.binding}}, // binding = {{sampled_image.binding}}
193 {{sampled_image.descriptor_type}}, // descriptor_type = {{sampled_image.descriptor_type}}
194 {{to_shader_stage(shader_stage)}}, // shader_stage = {{to_shader_stage(shader_stage)}}
199}; // struct {{camel_case(shader_name)}}{{camel_case(shader_stage)}}Shader
201} // namespace impeller
205 R
"~~(// THIS FILE IS GENERATED BY impellerc.
206// DO NOT EDIT OR CHECK THIS INTO SOURCE CONTROL
208#include "{{header_file_name}}"
210#include <type_traits>
214using Shader = {{camel_case(shader_name)}}{{camel_case(shader_stage)}}Shader;
216{% for def in struct_definitions %}
217// Sanity checks for {{def.name}}
218{% if last(def.members).array_elements == 0 %}
219static_assert(std::is_standard_layout_v<Shader::{{def.name}}<0>>);
220{% for member in def.members %}
221static_assert(offsetof(Shader::{{def.name}}<0>, {{member.name}}) == {{member.offset}});
224static_assert(std::is_standard_layout_v<Shader::{{def.name}}>);
225static_assert(sizeof(Shader::{{def.name}}) == {{def.byte_length}});
226{% for member in def.members %}
227static_assert(offsetof(Shader::{{def.name}}, {{member.name}}) == {{member.offset}});
232{% for buffer in buffers %}
233ShaderMetadata Shader::kMetadata{{camel_case(buffer.name)}} = {
234 "{{buffer.name}}", // name
235 std::vector<ShaderStructMemberMetadata> {
236 {% for member in buffer.type.members %}
237 ShaderStructMemberMetadata {
238 {{ member.base_type }}, // type
239 "{{ member.name }}", // name
240 {{ member.offset }}, // offset
241 {{ member.size }}, // size
242 {{ member.byte_length }}, // byte_length
243 {{ member.array_elements }}, // array_elements
250{% for sampled_image in sampled_images %}
251ShaderMetadata Shader::kMetadata{{camel_case(sampled_image.name)}} = {
252 "{{sampled_image.name}}", // name
253 std::vector<ShaderStructMemberMetadata> {}, // 0 members
257} // namespace impeller
constexpr std::string_view kReflectionHeaderTemplate
constexpr std::string_view kReflectionCCTemplate