Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions impeller/playground/imgui/imgui_impl_impeller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <memory>
#include <vector>

#include "fml/mapping.h"
#include "impeller/core/buffer_view.h"
#include "impeller/core/host_buffer.h"
#include "impeller/core/platform.h"
Expand Down Expand Up @@ -78,8 +79,8 @@ bool ImGui_ImplImpeller_Init(
int width, height;
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);

auto texture_descriptor = impeller::TextureDescriptor{};
texture_descriptor.storage_mode = impeller::StorageMode::kHostVisible;
impeller::TextureDescriptor texture_descriptor;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really related but this was also tripping validation errors for me, because molten vk actually creates the linear texture but then we can't actually do anything with it.

texture_descriptor.storage_mode = impeller::StorageMode::kDevicePrivate;
texture_descriptor.format = impeller::PixelFormat::kR8G8B8A8UNormInt;
texture_descriptor.size = {width, height};
texture_descriptor.mip_count = 1u;
Expand All @@ -90,8 +91,20 @@ bool ImGui_ImplImpeller_Init(
"Could not allocate ImGui font texture.");
bd->font_texture->SetLabel("ImGui Font Texture");

[[maybe_unused]] bool uploaded = bd->font_texture->SetContents(
pixels, texture_descriptor.GetByteSizeOfBaseMipLevel());
auto command_buffer = context->CreateCommandBuffer();
auto blit_pass = command_buffer->CreateBlitPass();
auto mapping = std::make_shared<fml::NonOwnedMapping>(
reinterpret_cast<const uint8_t*>(pixels),
texture_descriptor.GetByteSizeOfBaseMipLevel());
auto device_buffer =
context->GetResourceAllocator()->CreateBufferWithCopy(*mapping);

blit_pass->AddCopy(impeller::DeviceBuffer::AsBufferView(device_buffer),
bd->font_texture);
blit_pass->EncodeCommands(context->GetResourceAllocator());

[[maybe_unused]] bool uploaded =
context->GetCommandQueue()->Submit({command_buffer}).ok();
IM_ASSERT(uploaded &&
"Could not upload ImGui font texture to device memory.");
}
Expand Down
8 changes: 4 additions & 4 deletions impeller/playground/playground.cc
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ static std::shared_ptr<Texture> CreateTextureForDecompressedImage(
const std::shared_ptr<Context>& context,
DecompressedImage& decompressed_image,
bool enable_mipmapping) {
auto texture_descriptor = TextureDescriptor{};
texture_descriptor.storage_mode = StorageMode::kHostVisible;
TextureDescriptor texture_descriptor;
texture_descriptor.storage_mode = StorageMode::kDevicePrivate;
texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt;
texture_descriptor.size = decompressed_image.GetSize();
texture_descriptor.mip_count =
Expand Down Expand Up @@ -463,8 +463,8 @@ std::shared_ptr<Texture> Playground::CreateTextureCubeForFixture(
images[i] = image.value();
}

auto texture_descriptor = TextureDescriptor{};
texture_descriptor.storage_mode = StorageMode::kHostVisible;
TextureDescriptor texture_descriptor;
texture_descriptor.storage_mode = StorageMode::kDevicePrivate;
texture_descriptor.type = TextureType::kTextureCube;
texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt;
texture_descriptor.size = images[0].GetSize();
Expand Down
11 changes: 9 additions & 2 deletions impeller/renderer/backend/vulkan/render_pass_builder_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

#include <vector>

#include "impeller/core/formats.h"
#include "impeller/renderer/backend/vulkan/formats_vk.h"
#include "vulkan/vulkan_enums.hpp"

namespace impeller {

Expand All @@ -31,15 +33,20 @@ RenderPassBuilderVK& RenderPassBuilderVK::SetColorAttachment(
PixelFormat format,
SampleCount sample_count,
LoadAction load_action,
StoreAction store_action) {
StoreAction store_action,
vk::ImageLayout current_layout) {
vk::AttachmentDescription desc;
desc.format = ToVKImageFormat(format);
desc.samples = ToVKSampleCount(sample_count);
desc.loadOp = ToVKAttachmentLoadOp(load_action);
desc.storeOp = ToVKAttachmentStoreOp(store_action, false);
desc.stencilLoadOp = vk::AttachmentLoadOp::eDontCare;
desc.stencilStoreOp = vk::AttachmentStoreOp::eDontCare;
desc.initialLayout = vk::ImageLayout::eUndefined;
if (load_action == LoadAction::kLoad) {
desc.initialLayout = current_layout;
} else {
desc.initialLayout = vk::ImageLayout::eUndefined;
}
desc.finalLayout = vk::ImageLayout::eGeneral;
colors_[index] = desc;

Expand Down
12 changes: 7 additions & 5 deletions impeller/renderer/backend/vulkan/render_pass_builder_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ class RenderPassBuilderVK {

RenderPassBuilderVK& operator=(const RenderPassBuilderVK&) = delete;

RenderPassBuilderVK& SetColorAttachment(size_t index,
PixelFormat format,
SampleCount sample_count,
LoadAction load_action,
StoreAction store_action);
RenderPassBuilderVK& SetColorAttachment(
size_t index,
PixelFormat format,
SampleCount sample_count,
LoadAction load_action,
StoreAction store_action,
vk::ImageLayout current_layout = vk::ImageLayout::eUndefined);

RenderPassBuilderVK& SetDepthStencilAttachment(PixelFormat format,
SampleCount sample_count,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,37 @@ TEST(RenderPassBuilder, CreatesRenderPassWithNoDepthStencil) {
EXPECT_FALSE(builder.GetDepthStencil().has_value());
}

TEST(RenderPassBuilder, RenderPassWithLoadOpUsesCurrentLayout) {
RenderPassBuilderVK builder = RenderPassBuilderVK();
auto const context = MockVulkanContextBuilder().Build();

builder.SetColorAttachment(0, PixelFormat::kR8G8B8A8UNormInt,
SampleCount::kCount1, LoadAction::kLoad,
StoreAction::kStore,
vk::ImageLayout::eColorAttachmentOptimal);

auto render_pass = builder.Build(context->GetDevice());

EXPECT_TRUE(!!render_pass);

auto maybe_color = builder.GetColorAttachments().find(0u);
ASSERT_NE(maybe_color, builder.GetColorAttachments().end());
auto color = maybe_color->second;

EXPECT_EQ(color.initialLayout, vk::ImageLayout::eColorAttachmentOptimal);
EXPECT_EQ(color.finalLayout, vk::ImageLayout::eGeneral);
EXPECT_EQ(color.loadOp, vk::AttachmentLoadOp::eLoad);
EXPECT_EQ(color.storeOp, vk::AttachmentStoreOp::eStore);
}

TEST(RenderPassBuilder, CreatesRenderPassWithCombinedDepthStencil) {
RenderPassBuilderVK builder = RenderPassBuilderVK();
auto const context = MockVulkanContextBuilder().Build();

// Create a single color attachment with a transient depth stencil.
builder.SetColorAttachment(0, PixelFormat::kR8G8B8A8UNormInt,
SampleCount::kCount1, LoadAction::kClear,
StoreAction::kStore);
StoreAction::kStore, vk::ImageLayout::eGeneral);
builder.SetDepthStencilAttachment(PixelFormat::kD24UnormS8Uint,
SampleCount::kCount1, LoadAction::kDontCare,
StoreAction::kDontCare);
Expand Down
3 changes: 2 additions & 1 deletion impeller/renderer/backend/vulkan/render_pass_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ SharedHandleVK<vk::RenderPass> RenderPassVK::CreateVKRenderPass(
color.texture->GetTextureDescriptor().format, //
color.texture->GetTextureDescriptor().sample_count, //
color.load_action, //
color.store_action //
color.store_action, //
TextureVK::Cast(*color.texture).GetLayout() //
);
TextureVK::Cast(*color.texture)
.SetLayoutWithoutEncoding(vk::ImageLayout::eGeneral);
Expand Down