Skip to content

Commit

Permalink
Remove support for 3-channel images.
Browse files Browse the repository at this point in the history
These are not well-supported by Vulkan implementations and not used very
often.

Fixes a lot of validation errors.

Signed-off-by: Robert Quill <robert.quill@imgtec.com>
  • Loading branch information
robquill committed Aug 30, 2024
1 parent 08e73b9 commit c6b91c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ Image::init(void* data,
"Kompute Image data is smaller than the requested image size");
}

if (numChannels > 4) {
if (numChannels > 4 || numChannels == 3) {
throw std::runtime_error(
"Kompute Images can only have up to 4 channels");
"Kompute Images can only have up to 1, 2 or 4 channels");
}

if (tiling == vk::ImageTiling::eOptimal &&
Expand Down
11 changes: 10 additions & 1 deletion test/TestImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ TEST(TestImage, DataTypes)
const int height = 3;

for (int numChannels = 1; numChannels <= 4; numChannels++) {

// 3-channel images are not supported and should throw an exception.
// This is tested by a different test.
if (numChannels == 3)
{
continue;
}

{
std::vector<float> vec(width * height * numChannels);
std::shared_ptr<kp::ImageT<float>> image =
Expand Down Expand Up @@ -130,7 +138,8 @@ TEST(TestImage, InvalidNumberOfChannels)
// channels.
std::vector<float> vec(3 * 3 * 5);

// There should be between 1 and 4 channels.
// There should be 1,2 or 4 channels.
EXPECT_THROW(mgr.image(vec, 3, 3, 0), std::runtime_error);
EXPECT_THROW(mgr.image(vec, 3, 3, 3), std::runtime_error);
EXPECT_THROW(mgr.image(vec, 3, 3, 5), std::runtime_error);
}

0 comments on commit c6b91c4

Please sign in to comment.