Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 4e195d3

Browse files
committed
got the blit to buffer working
1 parent cbd8c8b commit 4e195d3

File tree

5 files changed

+72
-25
lines changed

5 files changed

+72
-25
lines changed

impeller/renderer/backend/vulkan/blit_command_vk.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ bool BlitCopyTextureToBufferCommandVK::Encode(CommandEncoderVK& encoder) const {
100100
// cast source and destination to TextureVK
101101
const auto& src = TextureVK::Cast(*source);
102102

103-
if (!encoder.Track(source)) {
103+
if (!encoder.Track(source) || !encoder.Track(destination)) {
104104
return false;
105105
}
106106

impeller/renderer/backend/vulkan/blit_command_vk_unittests.cc

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,28 @@ TEST(BlitCommandVkTest, BlitCopyTextureToTextureCommandVK) {
3333
EXPECT_TRUE(encoder.IsTracking(cmd.destination));
3434
}
3535

36-
// TEST(BlitCommandVkTest, BlitCopyTextureToBufferCommandVK) {
37-
// ContextVK::Settings settings;
38-
// auto message_loop = fml::ConcurrentMessageLoop::Create();
39-
// settings.worker_task_runner =
40-
// std::make_shared<fml::ConcurrentTaskRunner>(message_loop);
41-
// settings.proc_address_callback = GetMockVulkanProcAddress;
42-
// auto context = ContextVK::Create(std::move(settings));
43-
// auto pool = CommandPoolVK::GetThreadLocal(context.get());
44-
// CommandEncoderVK encoder(context->GetDevice(), context->GetGraphicsQueue(),
45-
// pool, context->GetFenceWaiter());
46-
// BlitCopyTextureToBufferCommandVK cmd;
47-
// cmd.source = context->GetResourceAllocator()->CreateTexture({
48-
// .size = ISize(100, 100),
49-
// });
50-
// cmd.destination = context->GetResourceAllocator()->CreateTexture({
51-
// .size = ISize(100, 100),
52-
// });
53-
// bool result = cmd.Encode(encoder);
54-
// EXPECT_TRUE(result);
55-
// EXPECT_TRUE(encoder.IsTracking(cmd.source));
56-
// EXPECT_TRUE(encoder.IsTracking(cmd.destination));
57-
// }
36+
TEST(BlitCommandVkTest, BlitCopyTextureToBufferCommandVK) {
37+
ContextVK::Settings settings;
38+
auto message_loop = fml::ConcurrentMessageLoop::Create();
39+
settings.worker_task_runner =
40+
std::make_shared<fml::ConcurrentTaskRunner>(message_loop);
41+
settings.proc_address_callback = GetMockVulkanProcAddress;
42+
auto context = ContextVK::Create(std::move(settings));
43+
auto pool = CommandPoolVK::GetThreadLocal(context.get());
44+
CommandEncoderVK encoder(context->GetDevice(), context->GetGraphicsQueue(),
45+
pool, context->GetFenceWaiter());
46+
BlitCopyTextureToBufferCommandVK cmd;
47+
cmd.source = context->GetResourceAllocator()->CreateTexture({
48+
.size = ISize(100, 100),
49+
});
50+
cmd.destination = context->GetResourceAllocator()->CreateBuffer({
51+
.size = 1,
52+
});
53+
bool result = cmd.Encode(encoder);
54+
EXPECT_TRUE(result);
55+
EXPECT_TRUE(encoder.IsTracking(cmd.source));
56+
EXPECT_TRUE(encoder.IsTracking(cmd.destination));
57+
}
5858

5959
TEST(BlitCommandVkTest, BlitGenerateMipmapCommandVK) {
6060
ContextVK::Settings settings;

impeller/renderer/backend/vulkan/command_encoder_vk.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ class TrackedObjectsVK {
5858
tracked_buffers_.insert(std::move(buffer));
5959
}
6060

61+
bool IsTracking(const std::shared_ptr<const DeviceBuffer>& buffer) const {
62+
if (!buffer) {
63+
return false;
64+
}
65+
return tracked_buffers_.find(buffer) != tracked_buffers_.end();
66+
}
67+
6168
void Track(std::shared_ptr<const TextureSourceVK> texture) {
6269
if (!texture) {
6370
return;
@@ -179,6 +186,14 @@ bool CommandEncoderVK::Track(std::shared_ptr<const DeviceBuffer> buffer) {
179186
return true;
180187
}
181188

189+
bool CommandEncoderVK::IsTracking(
190+
const std::shared_ptr<const DeviceBuffer>& buffer) const {
191+
if (!IsValid()) {
192+
return false;
193+
}
194+
return tracked_objects_->IsTracking(buffer);
195+
}
196+
182197
bool CommandEncoderVK::Track(std::shared_ptr<const TextureSourceVK> texture) {
183198
if (!IsValid()) {
184199
return false;

impeller/renderer/backend/vulkan/command_encoder_vk.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ class CommandEncoderVK {
4141

4242
bool Track(std::shared_ptr<const DeviceBuffer> buffer);
4343

44+
bool IsTracking(const std::shared_ptr<const DeviceBuffer>& texture) const;
45+
4446
bool Track(const std::shared_ptr<const Texture>& texture);
4547

48+
bool IsTracking(const std::shared_ptr<const Texture>& texture) const;
49+
4650
bool Track(std::shared_ptr<const TextureSourceVK> texture);
4751

4852
vk::CommandBuffer GetCommandBuffer() const;
@@ -56,8 +60,6 @@ class CommandEncoderVK {
5660
std::optional<vk::DescriptorSet> AllocateDescriptorSet(
5761
const vk::DescriptorSetLayout& layout);
5862

59-
bool IsTracking(const std::shared_ptr<const Texture>& texture) const;
60-
6163
private:
6264
friend class ContextVK;
6365
friend class ::impeller::testing::

impeller/renderer/backend/vulkan/test/mock_vulkan.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,29 @@ VkResult vkCreateImageView(VkDevice device,
192192
return VK_SUCCESS;
193193
}
194194

195+
VkResult vkCreateBuffer(VkDevice device,
196+
const VkBufferCreateInfo* pCreateInfo,
197+
const VkAllocationCallbacks* pAllocator,
198+
VkBuffer* pBuffer) {
199+
*pBuffer = reinterpret_cast<VkBuffer>(0xDEADDEAD);
200+
return VK_SUCCESS;
201+
}
202+
203+
void vkGetBufferMemoryRequirements2KHR(
204+
VkDevice device,
205+
const VkBufferMemoryRequirementsInfo2* pInfo,
206+
VkMemoryRequirements2* pMemoryRequirements) {
207+
pMemoryRequirements->memoryRequirements.size = 1024;
208+
pMemoryRequirements->memoryRequirements.memoryTypeBits = 1;
209+
}
210+
211+
VkResult vkBindBufferMemory(VkDevice device,
212+
VkBuffer buffer,
213+
VkDeviceMemory memory,
214+
VkDeviceSize memoryOffset) {
215+
return VK_SUCCESS;
216+
}
217+
195218
} // namespace
196219

197220
PFN_vkVoidFunction GetMockVulkanProcAddress(VkInstance instance,
@@ -239,6 +262,13 @@ PFN_vkVoidFunction GetMockVulkanProcAddress(VkInstance instance,
239262
return (PFN_vkVoidFunction)vkBindImageMemory;
240263
} else if (strcmp("vkCreateImageView", pName) == 0) {
241264
return (PFN_vkVoidFunction)vkCreateImageView;
265+
} else if (strcmp("vkCreateBuffer", pName) == 0) {
266+
return (PFN_vkVoidFunction)vkCreateBuffer;
267+
} else if (strcmp("vkGetBufferMemoryRequirements2KHR", pName) == 0 ||
268+
strcmp("vkGetBufferMemoryRequirements2", pName) == 0) {
269+
return (PFN_vkVoidFunction)vkGetBufferMemoryRequirements2KHR;
270+
} else if (strcmp("vkBindBufferMemory", pName) == 0) {
271+
return (PFN_vkVoidFunction)vkBindBufferMemory;
242272
}
243273
return noop;
244274
}

0 commit comments

Comments
 (0)