Skip to content

Commit

Permalink
image: Convert usage to feature flags for format support checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
squidbus committed Sep 25, 2024
1 parent b57bbe7 commit c0d0e00
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
26 changes: 24 additions & 2 deletions src/video_core/texture_cache/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,28 @@ static vk::ImageUsageFlags ImageUsageFlags(const ImageInfo& info) {
return usage;
}

static vk::FormatFeatureFlags2 FormatFeatureFlags(const vk::ImageUsageFlags usage_flags) {
vk::FormatFeatureFlags2 feature_flags{};
if (usage_flags & vk::ImageUsageFlagBits::eTransferSrc) {
feature_flags |= vk::FormatFeatureFlagBits2::eTransferSrc;
}
if (usage_flags & vk::ImageUsageFlagBits::eTransferDst) {
feature_flags |= vk::FormatFeatureFlagBits2::eTransferDst;
}
if (usage_flags & vk::ImageUsageFlagBits::eSampled) {
feature_flags |= vk::FormatFeatureFlagBits2::eSampledImage;
}
if (usage_flags & vk::ImageUsageFlagBits::eColorAttachment) {
feature_flags |= vk::FormatFeatureFlagBits2::eColorAttachment;
}
if (usage_flags & vk::ImageUsageFlagBits::eDepthStencilAttachment) {
feature_flags |= vk::FormatFeatureFlagBits2::eDepthStencilAttachment;
}
// Note: StorageImage is intentionally ignored for now since it is always set, and can mess up
// compatibility checks.
return feature_flags;
}

UniqueImage::UniqueImage(vk::Device device_, VmaAllocator allocator_)
: device{device_}, allocator{allocator_} {}

Expand Down Expand Up @@ -132,6 +154,7 @@ Image::Image(const Vulkan::Instance& instance_, Vulkan::Scheduler& scheduler_,
}

usage = ImageUsageFlags(info);
format_features = FormatFeatureFlags(usage);

switch (info.pixel_format) {
case vk::Format::eD16Unorm:
Expand All @@ -149,8 +172,7 @@ Image::Image(const Vulkan::Instance& instance_, Vulkan::Scheduler& scheduler_,
}

constexpr auto tiling = vk::ImageTiling::eOptimal;
const auto supported_format =
instance->GetSupportedFormat(info.pixel_format, vk::FormatFeatureFlagBits2::eSampledImage);
const auto supported_format = instance->GetSupportedFormat(info.pixel_format, format_features);
const auto properties = instance->GetPhysicalDevice().getImageFormatProperties(
supported_format, info.type, tiling, usage, flags);
const auto supported_samples = properties.result == vk::Result::eSuccess
Expand Down
1 change: 1 addition & 0 deletions src/video_core/texture_cache/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ struct Image {

// Resource state tracking
vk::ImageUsageFlags usage;
vk::FormatFeatureFlags2 format_features;
struct State {
vk::Flags<vk::PipelineStageFlagBits2> pl_stage = vk::PipelineStageFlagBits2::eAllCommands;
vk::Flags<vk::AccessFlagBits2> access_mask = vk::AccessFlagBits2::eNone;
Expand Down
6 changes: 3 additions & 3 deletions src/video_core/texture_cache/image_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ ImageView::ImageView(const Vulkan::Instance& instance, const ImageViewInfo& info
.pNext = &usage_ci,
.image = image.image,
.viewType = info.type,
.format = instance.GetSupportedFormat(format, vk::FormatFeatureFlagBits2::eSampledImage),
.components = instance.GetSupportedComponentSwizzle(
format, info.mapping, vk::FormatFeatureFlagBits2::eSampledImage),
.format = instance.GetSupportedFormat(format, image.format_features),
.components =
instance.GetSupportedComponentSwizzle(format, info.mapping, image.format_features),
.subresourceRange{
.aspectMask = aspect,
.baseMipLevel = info.range.base.level,
Expand Down

0 comments on commit c0d0e00

Please sign in to comment.