Memory Changes part 2 (ryubing/ryujinx!123)

See merge request ryubing/ryujinx!123
This commit is contained in:
LotP
2025-08-25 17:44:15 -05:00
parent d499449f57
commit 50ab108ee1
90 changed files with 2133 additions and 1159 deletions

View File

@@ -2,7 +2,8 @@ using Ryujinx.Common;
using Ryujinx.Graphics.GAL;
using Silk.NET.Vulkan;
using System;
using Format = Silk.NET.Vulkan.Format;
using VulkanFormat = Silk.NET.Vulkan.Format;
using GALFormat = Ryujinx.Graphics.GAL.Format;
using PolygonMode = Silk.NET.Vulkan.PolygonMode;
namespace Ryujinx.Graphics.Vulkan
@@ -23,7 +24,7 @@ namespace Ryujinx.Graphics.Vulkan
AttachmentReference* attachmentReferences = stackalloc AttachmentReference[MaxAttachments];
Span<int> attachmentIndices = stackalloc int[MaxAttachments];
Span<Format> attachmentFormats = stackalloc Format[MaxAttachments];
Span<VulkanFormat> attachmentFormats = stackalloc VulkanFormat[MaxAttachments];
int attachmentCount = 0;
int colorCount = 0;
@@ -32,14 +33,17 @@ namespace Ryujinx.Graphics.Vulkan
bool isNotMsOrSupportsStorage = gd.Capabilities.SupportsShaderStorageImageMultisample ||
!state.DepthStencilFormat.IsImageCompatible();
for (int i = 0; i < state.AttachmentEnable.Length; i++)
Span<bool> attachmentEnableSpan = state.AttachmentEnable.AsSpan();
Span<GALFormat> attachmentFormatsSpan = state.AttachmentFormats.AsSpan();
for (int i = 0; i < attachmentEnableSpan.Length; i++)
{
if (state.AttachmentEnable[i])
if (attachmentEnableSpan[i])
{
bool isNotMsOrSupportsStorageAttachments = gd.Capabilities.SupportsShaderStorageImageMultisample ||
!state.AttachmentFormats[i].IsImageCompatible();
!attachmentFormatsSpan[i].IsImageCompatible();
attachmentFormats[attachmentCount] = gd.FormatCapabilities.ConvertToVkFormat(state.AttachmentFormats[i], isNotMsOrSupportsStorageAttachments);
attachmentFormats[attachmentCount] = gd.FormatCapabilities.ConvertToVkFormat(attachmentFormatsSpan[i], isNotMsOrSupportsStorageAttachments);
attachmentIndices[attachmentCount++] = i;
colorCount++;
@@ -222,13 +226,15 @@ namespace Ryujinx.Graphics.Vulkan
int vbCount = Math.Min(Constants.MaxVertexBuffers, state.VertexBufferCount);
Span<int> vbScalarSizes = stackalloc int[vbCount];
Span<VertexAttribDescriptor> vertexAttribsSpan = state.VertexAttribs.AsSpan();
Span<VertexInputAttributeDescription> vertexAttributeDescriptionsSpan = pipeline.Internal.VertexAttributeDescriptions.AsSpan();
for (int i = 0; i < vaCount; i++)
{
VertexAttribDescriptor attribute = state.VertexAttribs[i];
VertexAttribDescriptor attribute = vertexAttribsSpan[i];
int bufferIndex = attribute.IsZero ? 0 : attribute.BufferIndex + 1;
pipeline.Internal.VertexAttributeDescriptions[i] = new VertexInputAttributeDescription(
vertexAttributeDescriptionsSpan[i] = new VertexInputAttributeDescription(
(uint)i,
(uint)bufferIndex,
gd.FormatCapabilities.ConvertToVertexVkFormat(attribute.Format),
@@ -243,9 +249,12 @@ namespace Ryujinx.Graphics.Vulkan
int descriptorIndex = 1;
pipeline.Internal.VertexBindingDescriptions[0] = new VertexInputBindingDescription(0, 0, VertexInputRate.Vertex);
Span<BufferPipelineDescriptor> vertexBuffersSpan = state.VertexBuffers.AsSpan();
Span<VertexInputBindingDescription> vertexBindingDescriptionsSpan = pipeline.Internal.VertexBindingDescriptions.AsSpan();
for (int i = 0; i < vbCount; i++)
{
BufferPipelineDescriptor vertexBuffer = state.VertexBuffers[i];
BufferPipelineDescriptor vertexBuffer = vertexBuffersSpan[i];
if (vertexBuffer.Enable)
{
@@ -259,7 +268,7 @@ namespace Ryujinx.Graphics.Vulkan
}
// TODO: Support divisor > 1
pipeline.Internal.VertexBindingDescriptions[descriptorIndex++] = new VertexInputBindingDescription(
vertexBindingDescriptionsSpan[descriptorIndex++] = new VertexInputBindingDescription(
(uint)i + 1,
(uint)alignedStride,
inputRate);
@@ -268,15 +277,19 @@ namespace Ryujinx.Graphics.Vulkan
pipeline.VertexBindingDescriptionsCount = (uint)descriptorIndex;
Span<BlendDescriptor> blendDescriptorsSpan = state.BlendDescriptors.AsSpan();
Span<uint> colorWriteMaskSpan = state.ColorWriteMask.AsSpan();
Span<PipelineColorBlendAttachmentState> colorBlendAttachmentStateSpan = pipeline.Internal.ColorBlendAttachmentState.AsSpan();
// NOTE: Viewports, Scissors are dynamic.
for (int i = 0; i < Constants.MaxRenderTargets; i++)
{
BlendDescriptor blend = state.BlendDescriptors[i];
BlendDescriptor blend = blendDescriptorsSpan[i];
if (blend.Enable && state.ColorWriteMask[i] != 0)
if (blend.Enable && colorWriteMaskSpan[i] != 0)
{
pipeline.Internal.ColorBlendAttachmentState[i] = new PipelineColorBlendAttachmentState(
colorBlendAttachmentStateSpan[i] = new PipelineColorBlendAttachmentState(
blend.Enable,
blend.ColorSrcFactor.Convert(),
blend.ColorDstFactor.Convert(),
@@ -284,12 +297,12 @@ namespace Ryujinx.Graphics.Vulkan
blend.AlphaSrcFactor.Convert(),
blend.AlphaDstFactor.Convert(),
blend.AlphaOp.Convert(),
(ColorComponentFlags)state.ColorWriteMask[i]);
(ColorComponentFlags)colorWriteMaskSpan[i]);
}
else
{
pipeline.Internal.ColorBlendAttachmentState[i] = new PipelineColorBlendAttachmentState(
colorWriteMask: (ColorComponentFlags)state.ColorWriteMask[i]);
colorBlendAttachmentStateSpan[i] = new PipelineColorBlendAttachmentState(
colorWriteMask: (ColorComponentFlags)colorWriteMaskSpan[i]);
}
}
@@ -297,23 +310,27 @@ namespace Ryujinx.Graphics.Vulkan
int maxColorAttachmentIndex = -1;
uint attachmentIntegerFormatMask = 0;
bool allFormatsFloatOrSrgb = true;
Span<bool> attachmentEnableSpan = state.AttachmentEnable.AsSpan();
Span<GALFormat> attachmentFormatsSpan = state.AttachmentFormats.AsSpan();
Span<VulkanFormat> pAttachmentFormatsSpan = pipeline.Internal.AttachmentFormats.AsSpan();
for (int i = 0; i < Constants.MaxRenderTargets; i++)
{
if (state.AttachmentEnable[i])
if (attachmentEnableSpan[i])
{
bool isNotMsOrSupportsStorage = gd.Capabilities.SupportsShaderStorageImageMultisample ||
!state.AttachmentFormats[i].IsImageCompatible();
!attachmentFormatsSpan[i].IsImageCompatible();
pipeline.Internal.AttachmentFormats[attachmentCount++] = gd.FormatCapabilities.ConvertToVkFormat(state.AttachmentFormats[i], isNotMsOrSupportsStorage);
pAttachmentFormatsSpan[attachmentCount++] = gd.FormatCapabilities.ConvertToVkFormat(attachmentFormatsSpan[i], isNotMsOrSupportsStorage);
maxColorAttachmentIndex = i;
if (state.AttachmentFormats[i].IsInteger())
if (attachmentFormatsSpan[i].IsInteger())
{
attachmentIntegerFormatMask |= 1u << i;
}
allFormatsFloatOrSrgb &= state.AttachmentFormats[i].IsFloatOrSrgb();
allFormatsFloatOrSrgb &= attachmentFormatsSpan[i].IsFloatOrSrgb();
}
}
@@ -322,7 +339,7 @@ namespace Ryujinx.Graphics.Vulkan
bool isNotMsOrSupportsStorage = !state.DepthStencilFormat.IsImageCompatible() ||
gd.Capabilities.SupportsShaderStorageImageMultisample;
pipeline.Internal.AttachmentFormats[attachmentCount++] = gd.FormatCapabilities.ConvertToVkFormat(state.DepthStencilFormat, isNotMsOrSupportsStorage);
pAttachmentFormatsSpan[attachmentCount++] = gd.FormatCapabilities.ConvertToVkFormat(state.DepthStencilFormat, isNotMsOrSupportsStorage);
}
pipeline.ColorBlendAttachmentStateCount = (uint)(maxColorAttachmentIndex + 1);