[Impeller] [vulkan] Wire descriptor set layouts (flutter/engine#35363)
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/renderer/backend/vulkan/vk.h"
|
||||
#include "impeller/renderer/descriptor_set_layout.h"
|
||||
#include "impeller/renderer/formats.h"
|
||||
#include "impeller/renderer/shader_types.h"
|
||||
|
||||
@@ -227,4 +228,64 @@ constexpr vk::SamplerAddressMode ToVKSamplerAddressMode(
|
||||
FML_UNREACHABLE();
|
||||
}
|
||||
|
||||
constexpr vk::ShaderStageFlags ToVkShaderStage(ShaderStage stage) {
|
||||
switch (stage) {
|
||||
case ShaderStage::kUnknown:
|
||||
return vk::ShaderStageFlagBits::eAll;
|
||||
case ShaderStage::kFragment:
|
||||
return vk::ShaderStageFlagBits::eFragment;
|
||||
case ShaderStage::kTessellationControl:
|
||||
return vk::ShaderStageFlagBits::eTessellationControl;
|
||||
case ShaderStage::kTessellationEvaluation:
|
||||
return vk::ShaderStageFlagBits::eTessellationEvaluation;
|
||||
case ShaderStage::kCompute:
|
||||
return vk::ShaderStageFlagBits::eCompute;
|
||||
case ShaderStage::kVertex:
|
||||
return vk::ShaderStageFlagBits::eVertex;
|
||||
}
|
||||
}
|
||||
|
||||
constexpr vk::DescriptorSetLayoutBinding ToVKDescriptorSetLayoutBinding(
|
||||
const DescriptorSetLayout& layout) {
|
||||
vk::DescriptorSetLayoutBinding binding;
|
||||
binding.binding = layout.binding;
|
||||
binding.descriptorCount = layout.descriptor_count;
|
||||
vk::DescriptorType desc_type = vk::DescriptorType();
|
||||
switch (layout.descriptor_type) {
|
||||
case DescriptorType::kSampledImage:
|
||||
desc_type = vk::DescriptorType::eCombinedImageSampler;
|
||||
break;
|
||||
case DescriptorType::kUniformBuffer:
|
||||
desc_type = vk::DescriptorType::eUniformBuffer;
|
||||
break;
|
||||
}
|
||||
binding.descriptorType = desc_type;
|
||||
binding.stageFlags = ToVkShaderStage(layout.shader_stage);
|
||||
return binding;
|
||||
}
|
||||
|
||||
constexpr vk::AttachmentLoadOp ToVKAttachmentLoadOp(LoadAction load_action) {
|
||||
switch (load_action) {
|
||||
case LoadAction::kLoad:
|
||||
return vk::AttachmentLoadOp::eLoad;
|
||||
case LoadAction::kClear:
|
||||
return vk::AttachmentLoadOp::eClear;
|
||||
case LoadAction::kDontCare:
|
||||
return vk::AttachmentLoadOp::eDontCare;
|
||||
}
|
||||
}
|
||||
|
||||
constexpr vk::AttachmentStoreOp ToVKAttachmentStoreOp(
|
||||
StoreAction store_action) {
|
||||
switch (store_action) {
|
||||
case StoreAction::kStore:
|
||||
return vk::AttachmentStoreOp::eStore;
|
||||
case StoreAction::kDontCare:
|
||||
return vk::AttachmentStoreOp::eDontCare;
|
||||
case StoreAction::kMultisampleResolve:
|
||||
// TODO (kaushikiska): vulkan doesn't support multisample resolve.
|
||||
return vk::AttachmentStoreOp::eDontCare;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -155,7 +155,9 @@ std::optional<vk::UniqueRenderPass> PipelineLibraryVK::CreateRenderPass(
|
||||
vk::SubpassDescription subpass_info;
|
||||
subpass_info.setPipelineBindPoint(vk::PipelineBindPoint::eGraphics);
|
||||
subpass_info.setColorAttachments(color_attachment_references);
|
||||
subpass_info.setResolveAttachments(resolve_attachment_references);
|
||||
if (sample_count != SampleCount::kCount1) {
|
||||
subpass_info.setResolveAttachments(resolve_attachment_references);
|
||||
}
|
||||
if (depth_stencil_attachment_reference.has_value()) {
|
||||
subpass_info.setPDepthStencilAttachment(
|
||||
&depth_stencil_attachment_reference.value());
|
||||
@@ -280,13 +282,58 @@ std::unique_ptr<PipelineCreateInfoVK> PipelineLibraryVK::CreatePipeline(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// only 1 stream of data is supported for now.
|
||||
vk::VertexInputBindingDescription binding_description = {};
|
||||
binding_description.setBinding(0);
|
||||
binding_description.setInputRate(vk::VertexInputRate::eVertex);
|
||||
|
||||
std::vector<vk::VertexInputAttributeDescription> attr_descs;
|
||||
uint32_t stride = 0;
|
||||
const auto& stage_inputs = desc.GetVertexDescriptor()->GetStageInputs();
|
||||
for (const ShaderStageIOSlot& stage_in : stage_inputs) {
|
||||
vk::VertexInputAttributeDescription attr_desc;
|
||||
attr_desc.setBinding(stage_in.binding);
|
||||
attr_desc.setLocation(stage_in.location);
|
||||
attr_desc.setFormat(vk::Format::eR8G8B8A8Unorm);
|
||||
attr_desc.setOffset(stride);
|
||||
attr_descs.push_back(attr_desc);
|
||||
stride += stage_in.bit_width * stage_in.vec_size;
|
||||
}
|
||||
|
||||
binding_description.setStride(stride);
|
||||
|
||||
vk::PipelineVertexInputStateCreateInfo vertex_input_state;
|
||||
vertex_input_state.setVertexAttributeDescriptions(attr_descs);
|
||||
vertex_input_state.setVertexBindingDescriptionCount(1);
|
||||
vertex_input_state.setPVertexBindingDescriptions(&binding_description);
|
||||
|
||||
pipeline_info.setPVertexInputState(&vertex_input_state);
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// Pipeline Layout a.k.a the descriptor sets and uniforms.
|
||||
///
|
||||
std::vector<vk::DescriptorSetLayout> descriptor_set_layouts;
|
||||
// TODO(106377): Wire this up from the C++ generated headers.
|
||||
std::vector<vk::DescriptorSetLayoutBinding> bindings = {};
|
||||
|
||||
for (auto layout : desc.GetVertexDescriptor()->GetDescriptorSetLayouts()) {
|
||||
auto vk_desc_layout = ToVKDescriptorSetLayoutBinding(layout);
|
||||
bindings.push_back(vk_desc_layout);
|
||||
}
|
||||
|
||||
vk::DescriptorSetLayoutCreateInfo descriptor_set_create;
|
||||
descriptor_set_create.setBindings(bindings);
|
||||
|
||||
auto descriptor_set_create_res =
|
||||
device_.createDescriptorSetLayoutUnique(descriptor_set_create);
|
||||
if (descriptor_set_create_res.result != vk::Result::eSuccess) {
|
||||
VALIDATION_LOG << "unable to create uniform descriptors";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
vk::UniqueDescriptorSetLayout descriptor_set_layout =
|
||||
std::move(descriptor_set_create_res.value);
|
||||
|
||||
vk::PipelineLayoutCreateInfo pipeline_layout_info;
|
||||
pipeline_layout_info.setSetLayouts(descriptor_set_layouts);
|
||||
pipeline_layout_info.setSetLayouts(descriptor_set_layout.get());
|
||||
auto pipeline_layout =
|
||||
device_.createPipelineLayoutUnique(pipeline_layout_info);
|
||||
if (pipeline_layout.result != vk::Result::eSuccess) {
|
||||
@@ -298,7 +345,6 @@ std::unique_ptr<PipelineCreateInfoVK> PipelineLibraryVK::CreatePipeline(
|
||||
pipeline_info.setLayout(pipeline_layout.value.get());
|
||||
|
||||
// TODO(WIP)
|
||||
// pipeline_info.setPVertexInputState(&vertex_input_state);
|
||||
// pipeline_info.setPDepthStencilState(&depth_stencil_state_);
|
||||
|
||||
// See the note in the header about why this is a reader lock.
|
||||
|
||||
Reference in New Issue
Block a user