-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Impeller] Vulkan framebuffer fetch via VK_ARM_RASTERIZATION_ORDER_ATTACHMENT_ACCESS #48458
Changes from 10 commits
9180bfb
a9fd144
6921c1b
5c395cb
b6cb2cb
1869497
b428f5f
808d257
4e79b47
a1153d9
76c4336
d5bff60
cef3581
371fbdd
55d111d
f5949b8
8dfb942
da822f4
4501eb3
7bf4115
b9ef69b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,13 +13,23 @@ | |
layout(constant_id = 0) const int blend_type = 0; | ||
layout(constant_id = 1) const int supports_decal = 1; | ||
|
||
#ifdef IMPELLER_TARGET_OPENGLES | ||
layout(set = 0, | ||
binding = 0, | ||
input_attachment_index = 0) uniform subpassInput uSub; | ||
|
||
vec4 ReadDestination() { | ||
return subpassLoad(uSub); | ||
} | ||
#else | ||
layout(set = 0, | ||
binding = 0, | ||
input_attachment_index = 0) uniform subpassInputMS uSub; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😮💨 |
||
|
||
vec4 ReadDestination() { | ||
return subpassLoad(uSub, gl_SampleID); | ||
} | ||
#endif | ||
|
||
uniform sampler2D texture_sampler_src; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
#include "impeller/renderer/backend/vulkan/vk.h" | ||
#include "impeller/renderer/command.h" | ||
#include "impeller/renderer/compute_command.h" | ||
#include "vulkan/vulkan_core.h" | ||
|
||
namespace impeller { | ||
|
||
|
@@ -117,7 +118,8 @@ static bool BindBuffers(const Bindings& bindings, | |
fml::StatusOr<std::vector<vk::DescriptorSet>> AllocateAndBindDescriptorSets( | ||
const ContextVK& context, | ||
const std::shared_ptr<CommandEncoderVK>& encoder, | ||
const std::vector<Command>& commands) { | ||
const std::vector<Command>& commands, | ||
const TextureVK& input_attachment) { | ||
if (commands.empty()) { | ||
return std::vector<vk::DescriptorSet>{}; | ||
} | ||
|
@@ -127,19 +129,22 @@ fml::StatusOr<std::vector<vk::DescriptorSet>> AllocateAndBindDescriptorSets( | |
// to allocate a correctly sized descriptor pool. | ||
size_t buffer_count = 0; | ||
size_t samplers_count = 0; | ||
size_t subpass_count = 0; | ||
std::vector<vk::DescriptorSetLayout> layouts; | ||
layouts.reserve(commands.size()); | ||
|
||
for (const auto& command : commands) { | ||
buffer_count += command.vertex_bindings.buffers.size(); | ||
buffer_count += command.fragment_bindings.buffers.size(); | ||
samplers_count += command.fragment_bindings.sampled_images.size(); | ||
subpass_count += | ||
command.pipeline->GetDescriptor().UsesSubpassInput() ? 1 : 0; | ||
|
||
layouts.emplace_back( | ||
PipelineVK::Cast(*command.pipeline).GetDescriptorSetLayout()); | ||
} | ||
auto descriptor_result = | ||
encoder->AllocateDescriptorSets(buffer_count, samplers_count, layouts); | ||
auto descriptor_result = encoder->AllocateDescriptorSets( | ||
buffer_count, samplers_count, subpass_count, layouts); | ||
if (!descriptor_result.ok()) { | ||
return descriptor_result.status(); | ||
} | ||
|
@@ -153,9 +158,9 @@ fml::StatusOr<std::vector<vk::DescriptorSet>> AllocateAndBindDescriptorSets( | |
std::vector<vk::DescriptorImageInfo> images; | ||
std::vector<vk::DescriptorBufferInfo> buffers; | ||
std::vector<vk::WriteDescriptorSet> writes; | ||
images.reserve(samplers_count); | ||
images.reserve(samplers_count + subpass_count); | ||
buffers.reserve(buffer_count); | ||
writes.reserve(samplers_count + buffer_count); | ||
writes.reserve(samplers_count + buffer_count + subpass_count); | ||
|
||
auto& allocator = *context.GetResourceAllocator(); | ||
auto desc_index = 0u; | ||
|
@@ -173,6 +178,24 @@ fml::StatusOr<std::vector<vk::DescriptorSet>> AllocateAndBindDescriptorSets( | |
return fml::Status(fml::StatusCode::kUnknown, | ||
"Failed to bind texture or buffer."); | ||
} | ||
|
||
if (command.pipeline->GetDescriptor().UsesSubpassInput()) { | ||
vk::DescriptorImageInfo image_info; | ||
image_info.imageLayout = vk::ImageLayout::eGeneral; | ||
image_info.sampler = VK_NULL_HANDLE; | ||
image_info.imageView = input_attachment.GetImageView(); | ||
images.push_back(image_info); | ||
|
||
vk::WriteDescriptorSet write_set; | ||
write_set.dstSet = descriptor_sets[desc_index]; | ||
// MAGIC! see description in pipeline_library_vk.cc | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe just look this up on the descriptor sets. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because the subpass doesn't show up in host builds I can't use any of the constants. |
||
write_set.dstBinding = 64u; | ||
write_set.descriptorCount = 1u; | ||
write_set.descriptorType = vk::DescriptorType::eInputAttachment; | ||
write_set.pImageInfo = &images.back(); | ||
|
||
writes.push_back(write_set); | ||
} | ||
desc_index += 1; | ||
} | ||
|
||
|
@@ -203,7 +226,7 @@ fml::StatusOr<std::vector<vk::DescriptorSet>> AllocateAndBindDescriptorSets( | |
ComputePipelineVK::Cast(*command.pipeline).GetDescriptorSetLayout()); | ||
} | ||
auto descriptor_result = | ||
encoder->AllocateDescriptorSets(buffer_count, samplers_count, layouts); | ||
encoder->AllocateDescriptorSets(buffer_count, samplers_count, 0, layouts); | ||
if (!descriptor_result.ok()) { | ||
return descriptor_result.status(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think its a bit of a mistake to assume that all bindings are in the set index zero. We should fix that separately as that affects all instances of
DescriptorSetLayout
in the generated header. For example, if we were to manually specifylayout(set=2, binding=n)
, we'd keel over.In the same vein, I think its a mistake to assume that we can only have one input attachment and at index zero. I'd also put the input_attachment_index in the descriptor set layout. The previous attempt at this patch did the same.
You should be able to reproduce this by manually specifying the input_attachment_index to anything other than zero and checking the validity of the setup.
For the descriptor set index, we can file a separate followup issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think practically speaking we can't really do bindings any other way. The actual render_pass_vk logic can only handle descriptors at index set zero.
Perhaps it would be possible with some refactoring, but it seems really in the weeds of what will yield a performance improvement.