[Impeller] [Vulkan] Generate descriptor set layouts in backend agnostic way (flutter/engine#35091)
This commit is contained in:
@@ -800,6 +800,7 @@ FILE: ../../../flutter/impeller/renderer/command_buffer.cc
|
||||
FILE: ../../../flutter/impeller/renderer/command_buffer.h
|
||||
FILE: ../../../flutter/impeller/renderer/context.cc
|
||||
FILE: ../../../flutter/impeller/renderer/context.h
|
||||
FILE: ../../../flutter/impeller/renderer/descriptor_set_layout.h
|
||||
FILE: ../../../flutter/impeller/renderer/device_buffer.cc
|
||||
FILE: ../../../flutter/impeller/renderer/device_buffer.h
|
||||
FILE: ../../../flutter/impeller/renderer/device_buffer_unittests.cc
|
||||
|
||||
@@ -16,15 +16,17 @@ constexpr std::string_view kReflectionHeaderTemplate =
|
||||
{# Note: The nogncheck decorations are only to make GN not mad at the template#}
|
||||
{# this file is generated from. There are no GN rule violations in the generated#}
|
||||
{# file itself and the no-check declarations will be stripped in generated files.#}
|
||||
#include "impeller/renderer/buffer_view.h" {# // nogncheck #}
|
||||
#include "impeller/renderer/buffer_view.h" {# // nogncheck #}
|
||||
|
||||
#include "impeller/renderer/command.h" {# // nogncheck #}
|
||||
#include "impeller/renderer/command.h" {# // nogncheck #}
|
||||
|
||||
#include "impeller/renderer/sampler.h" {# // nogncheck #}
|
||||
#include "impeller/renderer/descriptor_set_layout.h" {# // nogncheck #}
|
||||
|
||||
#include "impeller/renderer/shader_types.h" {# // nogncheck #}
|
||||
#include "impeller/renderer/sampler.h" {# // nogncheck #}
|
||||
|
||||
#include "impeller/renderer/texture.h" {# // nogncheck #}
|
||||
#include "impeller/renderer/shader_types.h" {# // nogncheck #}
|
||||
|
||||
#include "impeller/renderer/texture.h" {# // nogncheck #}
|
||||
|
||||
|
||||
namespace impeller {
|
||||
@@ -150,30 +152,26 @@ std::move({{ arg.argument_name }}){% if not loop.is_last %}, {% endif %}
|
||||
// ===========================================================================
|
||||
// Metadata for Vulkan =======================================================
|
||||
// ===========================================================================
|
||||
#ifdef IMPELLER_ENABLE_VULKAN_REFLECTION
|
||||
{% if length(buffers)+length(sampled_images) > 0 %}
|
||||
static constexpr std::array<VkDescriptorSetLayoutBinding,{{length(buffers)+length(sampled_images)}}> kDescriptorSetLayouts{
|
||||
static constexpr std::array<DescriptorSetLayout,{{length(buffers)+length(sampled_images)}}> kDescriptorSetLayouts{
|
||||
{% for buffer in buffers %}
|
||||
VkDescriptorSetLayoutBinding{
|
||||
DescriptorSetLayout{
|
||||
{{buffer.binding}}, // binding = {{buffer.binding}}
|
||||
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, // descriptorType = Uniform Buffer
|
||||
DescriptorType::kUniformBuffer, // descriptorType = Uniform Buffer
|
||||
1, // descriptorCount = 1
|
||||
{{to_vk_shader_stage_flag_bits(shader_stage)}}, // stageFlags = {{to_shader_stage(shader_stage)}}
|
||||
nullptr, // pImmutableSamplers = NULL
|
||||
{{to_shader_stage(shader_stage)}}, // stageFlags = {{to_shader_stage(shader_stage)}}
|
||||
},
|
||||
{% endfor %}
|
||||
{% for sampled_image in sampled_images %}
|
||||
VkDescriptorSetLayoutBinding{
|
||||
DescriptorSetLayout{
|
||||
{{sampled_image.binding}}, // binding = {{sampled_image.binding}}
|
||||
VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, // descriptorType = Sampled Image
|
||||
DescriptorType::kSampledImage, // descriptorType = Sampled Image
|
||||
1, // descriptorCount = 1
|
||||
{{to_vk_shader_stage_flag_bits(shader_stage)}},// stageFlags = {{to_shader_stage(shader_stage)}}
|
||||
nullptr, // pImmutableSamplers = NULL
|
||||
{{to_shader_stage(shader_stage)}}, // stageFlags = {{to_shader_stage(shader_stage)}}
|
||||
},
|
||||
{% endfor %}
|
||||
};
|
||||
{% endif %}
|
||||
#endif
|
||||
|
||||
}; // struct {{camel_case(shader_name)}}{{camel_case(shader_stage)}}Shader
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ impeller_component("renderer") {
|
||||
"command_buffer.h",
|
||||
"context.cc",
|
||||
"context.h",
|
||||
"descriptor_set_layout.h",
|
||||
"device_buffer.cc",
|
||||
"device_buffer.h",
|
||||
"formats.cc",
|
||||
|
||||
27
engine/src/flutter/impeller/renderer/descriptor_set_layout.h
Normal file
27
engine/src/flutter/impeller/renderer/descriptor_set_layout.h
Normal file
@@ -0,0 +1,27 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/renderer/shader_types.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
enum class DescriptorType {
|
||||
kSampledImage,
|
||||
kUniformBuffer,
|
||||
};
|
||||
|
||||
struct DescriptorSetLayout {
|
||||
uint32_t binding;
|
||||
DescriptorType descriptor_type;
|
||||
uint32_t descriptor_count;
|
||||
ShaderStage shader_stage;
|
||||
};
|
||||
|
||||
} // namespace impeller
|
||||
@@ -93,6 +93,13 @@ struct PipelineBuilder {
|
||||
<< VertexShader::kLabel << "'.";
|
||||
return false;
|
||||
}
|
||||
if (!vertex_descriptor->SetDescriptorSetLayouts(
|
||||
VertexShader::kDescriptorSetLayouts)) {
|
||||
VALIDATION_LOG << "Cound not configure vertex descriptor set layout for"
|
||||
" pipeline named '"
|
||||
<< VertexShader::kLabel << "'.";
|
||||
return false;
|
||||
}
|
||||
desc.SetVertexDescriptor(std::move(vertex_descriptor));
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,16 @@ bool VertexDescriptor::SetStageInputs(
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VertexDescriptor::SetDescriptorSetLayouts(
|
||||
const DescriptorSetLayout desc_set_layout[],
|
||||
size_t count) {
|
||||
desc_set_layouts_.reserve(desc_set_layouts_.size() + count);
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
desc_set_layouts_.emplace_back(desc_set_layout[i]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// |Comparable<VertexDescriptor>|
|
||||
size_t VertexDescriptor::GetHash() const {
|
||||
auto seed = fml::HashCombine();
|
||||
@@ -38,4 +48,9 @@ const std::vector<ShaderStageIOSlot>& VertexDescriptor::GetStageInputs() const {
|
||||
return inputs_;
|
||||
}
|
||||
|
||||
const std::vector<DescriptorSetLayout>&
|
||||
VertexDescriptor::GetDescriptorSetLayouts() const {
|
||||
return desc_set_layouts_;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/base/comparable.h"
|
||||
#include "impeller/renderer/descriptor_set_layout.h"
|
||||
#include "impeller/renderer/shader_types.h"
|
||||
|
||||
namespace impeller {
|
||||
@@ -36,11 +37,22 @@ class VertexDescriptor final : public Comparable<VertexDescriptor> {
|
||||
return SetStageInputs(inputs.data(), inputs.size());
|
||||
}
|
||||
|
||||
template <size_t Size>
|
||||
bool SetDescriptorSetLayouts(
|
||||
const std::array<DescriptorSetLayout, Size>& inputs) {
|
||||
return SetDescriptorSetLayouts(inputs.data(), inputs.size());
|
||||
}
|
||||
|
||||
bool SetStageInputs(const ShaderStageIOSlot* const stage_inputs[],
|
||||
size_t count);
|
||||
|
||||
bool SetDescriptorSetLayouts(const DescriptorSetLayout desc_set_layout[],
|
||||
size_t count);
|
||||
|
||||
const std::vector<ShaderStageIOSlot>& GetStageInputs() const;
|
||||
|
||||
const std::vector<DescriptorSetLayout>& GetDescriptorSetLayouts() const;
|
||||
|
||||
// |Comparable<VertexDescriptor>|
|
||||
std::size_t GetHash() const override;
|
||||
|
||||
@@ -49,6 +61,7 @@ class VertexDescriptor final : public Comparable<VertexDescriptor> {
|
||||
|
||||
private:
|
||||
std::vector<ShaderStageIOSlot> inputs_;
|
||||
std::vector<DescriptorSetLayout> desc_set_layouts_;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(VertexDescriptor);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user