Skip to content

Commit 7f81331

Browse files
authored
Remove explicit checks against kp::Memory::type() (#455)
* 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 <anders@hellerup-madsen.dk> * 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 <anders@hellerup-madsen.dk> --------- Signed-off-by: Anders Hellerup Madsen <anders@hellerup-madsen.dk>
1 parent 6e5380d commit 7f81331

2 files changed

Lines changed: 3 additions & 4 deletions

File tree

src/Algorithm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Algorithm::createParameters()
134134
KP_LOG_DEBUG("Kompute Algorithm createParameters started");
135135

136136
for (const std::shared_ptr<Memory>& mem : this->mMemObjects) {
137-
if (mem->type() == Memory::Type::eImage) {
137+
if (mem->getDescriptorType() == vk::DescriptorType::eStorageImage) {
138138
numImages++;
139139
} else {
140140
numTensors++;

src/OpAlgoDispatch.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ OpAlgoDispatch::record(const vk::CommandBuffer& commandBuffer)
2525

2626
// For images the image layout needs to be set to eGeneral before using
2727
// it for imageLoad/imageStore in a shader.
28-
if (mem->type() == Memory::Type::eImage) {
29-
std::shared_ptr<Image> image = std::static_pointer_cast<Image>(mem);
30-
28+
std::shared_ptr<Image> image = std::dynamic_pointer_cast<Image>(mem);
29+
if (image) {
3130
image->recordPrimaryImageBarrier(
3231
commandBuffer,
3332
vk::AccessFlagBits::eTransferWrite,

0 commit comments

Comments
 (0)