Skip to content

Commit

Permalink
vulkan: Limit multisampling to supported sample counts. (shadps4-emu#828
Browse files Browse the repository at this point in the history
)
  • Loading branch information
squidbus committed Sep 17, 2024
1 parent f497deb commit 3c4f6be
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
12 changes: 11 additions & 1 deletion src/video_core/renderer_vulkan/liverpool_to_vk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ vk::ClearValue ColorBufferClearValue(const AmdGpu::Liverpool::ColorBuffer& color
return {.color = color};
}

vk::SampleCountFlagBits NumSamples(u32 num_samples) {
vk::SampleCountFlagBits RawNumSamples(u32 num_samples) {
switch (num_samples) {
case 1:
return vk::SampleCountFlagBits::e1;
Expand All @@ -735,4 +735,14 @@ vk::SampleCountFlagBits NumSamples(u32 num_samples) {
}
}

vk::SampleCountFlagBits NumSamples(u32 num_samples, vk::SampleCountFlags supported_flags) {
vk::SampleCountFlagBits flags = RawNumSamples(num_samples);
// Half sample counts until supported, with a minimum of 1.
while (!(supported_flags & flags) && num_samples > 1) {
num_samples /= 2;
flags = RawNumSamples(num_samples);
}
return flags;
}

} // namespace Vulkan::LiverpoolToVK
2 changes: 1 addition & 1 deletion src/video_core/renderer_vulkan/liverpool_to_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ vk::Format DepthFormat(Liverpool::DepthBuffer::ZFormat z_format,

vk::ClearValue ColorBufferClearValue(const AmdGpu::Liverpool::ColorBuffer& color_buffer);

vk::SampleCountFlagBits NumSamples(u32 num_samples);
vk::SampleCountFlagBits NumSamples(u32 num_samples, vk::SampleCountFlags supported_flags);

void EmitQuadToTriangleListIndices(u8* out_indices, u32 num_vertices);

Expand Down
3 changes: 2 additions & 1 deletion src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ GraphicsPipeline::GraphicsPipeline(const Instance& instance_, Scheduler& schedul
};

const vk::PipelineMultisampleStateCreateInfo multisampling = {
.rasterizationSamples = LiverpoolToVK::NumSamples(key.num_samples),
.rasterizationSamples =
LiverpoolToVK::NumSamples(key.num_samples, instance.GetFramebufferSampleCounts()),
.sampleShadingEnable = false,
};

Expand Down
7 changes: 7 additions & 0 deletions src/video_core/renderer_vulkan/vk_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ class Instance {
return min_imported_host_pointer_alignment;
}

/// Returns the sample count flags supported by framebuffers.
vk::SampleCountFlags GetFramebufferSampleCounts() const {
return properties.limits.framebufferColorSampleCounts &
properties.limits.framebufferDepthSampleCounts &
properties.limits.framebufferStencilSampleCounts;
}

private:
/// Creates the logical device opportunistically enabling extensions
bool CreateDevice();
Expand Down
11 changes: 8 additions & 3 deletions src/video_core/texture_cache/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,24 @@ Image::Image(const Vulkan::Instance& instance_, Vulkan::Scheduler& scheduler_,
break;
}

constexpr auto tiling = vk::ImageTiling::eOptimal;
const auto supported_format = instance->GetSupportedFormat(info.pixel_format);
const auto properties = instance->GetPhysicalDevice().getImageFormatProperties(
supported_format, info.type, tiling, usage, flags);

const vk::ImageCreateInfo image_ci = {
.flags = flags,
.imageType = info.type,
.format = instance->GetSupportedFormat(info.pixel_format),
.format = supported_format,
.extent{
.width = info.size.width,
.height = info.size.height,
.depth = info.size.depth,
},
.mipLevels = static_cast<u32>(info.resources.levels),
.arrayLayers = static_cast<u32>(info.resources.layers),
.samples = LiverpoolToVK::NumSamples(info.num_samples),
.tiling = vk::ImageTiling::eOptimal,
.samples = LiverpoolToVK::NumSamples(info.num_samples, properties.sampleCounts),
.tiling = tiling,
.usage = usage,
.initialLayout = vk::ImageLayout::eUndefined,
};
Expand Down

0 comments on commit 3c4f6be

Please sign in to comment.