From b8881799d033c3a13570645159994b382e6ef696 Mon Sep 17 00:00:00 2001 From: Anders Hellerup Madsen Date: Mon, 13 Apr 2026 12:43:01 +0200 Subject: [PATCH 1/2] algorithm: check DescriptorType when creating pool The function that was prevously used, `mem->type()`, is not explicitly the same as the descriptor type, so using `mem->getDescriptorType()` is more accurate. It also makes it easier to create new image-like subclasses of `kp::Memory` because as long as they specify the correct descriptor type, the correct pools will be created. Signed-off-by: Anders Hellerup Madsen --- src/Algorithm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Algorithm.cpp b/src/Algorithm.cpp index af12e091..13f8301b 100644 --- a/src/Algorithm.cpp +++ b/src/Algorithm.cpp @@ -134,7 +134,7 @@ Algorithm::createParameters() KP_LOG_DEBUG("Kompute Algorithm createParameters started"); for (const std::shared_ptr& mem : this->mMemObjects) { - if (mem->type() == Memory::Type::eImage) { + if (mem->getDescriptorType() == vk::DescriptorType::eStorageImage) { numImages++; } else { numTensors++; From 94a14496168e2e9aeb50fcd7ff2bff4af14b30f2 Mon Sep 17 00:00:00 2001 From: Anders Hellerup Madsen Date: Mon, 13 Apr 2026 14:49:57 +0200 Subject: [PATCH 2/2] Algorithm: check type before casting The if statement used to assume that if `mem->type() == memory::Type::eImage` then it was safe to assume that the memory object is an instance of `kp::Image`. However, any subclass of `kp::Memory` could implement the virtual `type()` method to return `memory::Type::eImage`, so this is an invalid assumption. This commit fixes the issue by only casting if the memory object actually is an instance of `kp::Memory` Signed-off-by: Anders Hellerup Madsen --- src/OpAlgoDispatch.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/OpAlgoDispatch.cpp b/src/OpAlgoDispatch.cpp index c9ba7f55..1f020979 100644 --- a/src/OpAlgoDispatch.cpp +++ b/src/OpAlgoDispatch.cpp @@ -25,9 +25,8 @@ OpAlgoDispatch::record(const vk::CommandBuffer& commandBuffer) // For images the image layout needs to be set to eGeneral before using // it for imageLoad/imageStore in a shader. - if (mem->type() == Memory::Type::eImage) { - std::shared_ptr image = std::static_pointer_cast(mem); - + std::shared_ptr image = std::dynamic_pointer_cast(mem); + if (image) { image->recordPrimaryImageBarrier( commandBuffer, vk::AccessFlagBits::eTransferWrite,