Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve Image Usage Validation Error #296

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Ryujinx.Graphics.Vulkan/FormatCapabilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public bool OptimalFormatSupports(FormatFeatureFlags flags, Format format)
return (formatFeatureFlags & flags) == flags;
}

public VkFormat ConvertToVkFormat(Format srcFormat)
public VkFormat ConvertToVkFormat(Format srcFormat, bool storageFeatureFlagRequired)
{
var format = FormatTable.GetFormat(srcFormat);

Expand All @@ -165,7 +165,7 @@ public VkFormat ConvertToVkFormat(Format srcFormat)
requiredFeatures |= FormatFeatureFlags.ColorAttachmentBit;
}

if (srcFormat.IsImageCompatible())
if (srcFormat.IsImageCompatible() && storageFeatureFlagRequired)
{
requiredFeatures |= FormatFeatureFlags.StorageImageBit;
}
Expand Down
20 changes: 16 additions & 4 deletions src/Ryujinx.Graphics.Vulkan/PipelineConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ public static unsafe DisposableRenderPass ToRenderPass(this ProgramPipelineState
int colorCount = 0;
int maxColorAttachmentIndex = -1;

bool isNotMsOrSupportsStorage = gd.Capabilities.SupportsShaderStorageImageMultisample ||
!state.DepthStencilFormat.IsImageCompatible();

for (int i = 0; i < state.AttachmentEnable.Length; i++)
{
if (state.AttachmentEnable[i])
{
attachmentFormats[attachmentCount] = gd.FormatCapabilities.ConvertToVkFormat(state.AttachmentFormats[i]);
bool isNotMsOrSupportsStorageAttachments = gd.Capabilities.SupportsShaderStorageImageMultisample ||
!state.AttachmentFormats[i].IsImageCompatible();

attachmentFormats[attachmentCount] = gd.FormatCapabilities.ConvertToVkFormat(state.AttachmentFormats[i], isNotMsOrSupportsStorageAttachments);

attachmentIndices[attachmentCount++] = i;
colorCount++;
Expand All @@ -43,7 +49,7 @@ public static unsafe DisposableRenderPass ToRenderPass(this ProgramPipelineState

if (state.DepthStencilEnable)
{
attachmentFormats[attachmentCount++] = gd.FormatCapabilities.ConvertToVkFormat(state.DepthStencilFormat);
attachmentFormats[attachmentCount++] = gd.FormatCapabilities.ConvertToVkFormat(state.DepthStencilFormat, isNotMsOrSupportsStorage);
}

if (attachmentCount != 0)
Expand Down Expand Up @@ -296,7 +302,10 @@ public static PipelineState ToVulkanPipelineState(this ProgramPipelineState stat
{
if (state.AttachmentEnable[i])
{
pipeline.Internal.AttachmentFormats[attachmentCount++] = gd.FormatCapabilities.ConvertToVkFormat(state.AttachmentFormats[i]);
bool isNotMsOrSupportsStorage = gd.Capabilities.SupportsShaderStorageImageMultisample ||
!state.AttachmentFormats[i].IsImageCompatible();

pipeline.Internal.AttachmentFormats[attachmentCount++] = gd.FormatCapabilities.ConvertToVkFormat(state.AttachmentFormats[i], isNotMsOrSupportsStorage);
maxColorAttachmentIndex = i;

if (state.AttachmentFormats[i].IsInteger())
Expand All @@ -310,7 +319,10 @@ public static PipelineState ToVulkanPipelineState(this ProgramPipelineState stat

if (state.DepthStencilEnable)
{
pipeline.Internal.AttachmentFormats[attachmentCount++] = gd.FormatCapabilities.ConvertToVkFormat(state.DepthStencilFormat);
bool isNotMsOrSupportsStorage = !state.DepthStencilFormat.IsImageCompatible() ||
gd.Capabilities.SupportsShaderStorageImageMultisample;

pipeline.Internal.AttachmentFormats[attachmentCount++] = gd.FormatCapabilities.ConvertToVkFormat(state.DepthStencilFormat, isNotMsOrSupportsStorage);
}

pipeline.ColorBlendAttachmentStateCount = (uint)(maxColorAttachmentIndex + 1);
Expand Down
12 changes: 6 additions & 6 deletions src/Ryujinx.Graphics.Vulkan/TextureStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ public unsafe TextureStorage(
_device = device;
_info = info;

var format = _gd.FormatCapabilities.ConvertToVkFormat(info.Format);
bool isMsImageStorageSupported = gd.Capabilities.SupportsShaderStorageImageMultisample || !info.Target.IsMultisample();

var format = _gd.FormatCapabilities.ConvertToVkFormat(info.Format, isMsImageStorageSupported);
var levels = (uint)info.Levels;
var layers = (uint)info.GetLayers();
var depth = (uint)(info.Target == Target.Texture3D ? info.Depth : 1);
Expand All @@ -91,7 +93,7 @@ public unsafe TextureStorage(

var sampleCountFlags = ConvertToSampleCountFlags(gd.Capabilities.SupportedSampleCounts, (uint)info.Samples);

var usage = GetImageUsage(info.Format, info.Target, gd.Capabilities);
var usage = GetImageUsage(info.Format, gd.Capabilities, isMsImageStorageSupported, true);

var flags = ImageCreateFlags.CreateMutableFormatBit | ImageCreateFlags.CreateExtendedUsageBit;

Expand Down Expand Up @@ -305,7 +307,7 @@ private unsafe void InitialTransition(ImageLayout srcLayout, ImageLayout dstLayo
}
}

public static ImageUsageFlags GetImageUsage(Format format, Target target, in HardwareCapabilities capabilities)
public static ImageUsageFlags GetImageUsage(Format format, in HardwareCapabilities capabilities, bool isMsImageStorageSupported, bool extendedUsage)
{
var usage = DefaultUsageFlags;

Expand All @@ -318,9 +320,7 @@ public static ImageUsageFlags GetImageUsage(Format format, Target target, in Har
usage |= ImageUsageFlags.ColorAttachmentBit;
}

bool supportsMsStorage = capabilities.SupportsShaderStorageImageMultisample;

if (format.IsImageCompatible() && (supportsMsStorage || !target.IsMultisample()))
if ((format.IsImageCompatible() && isMsImageStorageSupported) || extendedUsage)
{
usage |= ImageUsageFlags.StorageBit;
}
Expand Down
7 changes: 5 additions & 2 deletions src/Ryujinx.Graphics.Vulkan/TextureView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ public TextureView(

gd.Textures.Add(this);

var format = _gd.FormatCapabilities.ConvertToVkFormat(info.Format);
var usage = TextureStorage.GetImageUsage(info.Format, info.Target, gd.Capabilities);
bool isMsImageStorageSupported = gd.Capabilities.SupportsShaderStorageImageMultisample || !info.Target.IsMultisample();

var format = _gd.FormatCapabilities.ConvertToVkFormat(info.Format, isMsImageStorageSupported);
var usage = TextureStorage.GetImageUsage(info.Format, gd.Capabilities, isMsImageStorageSupported, false);

var levels = (uint)info.Levels;
var layers = (uint)info.GetLayers();

Expand Down
Loading