Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
e87e8b012c | |||
e8f1ca8427 | |||
ad47bd2d4e |
@ -56,7 +56,6 @@ namespace Ryujinx.Graphics.GAL
|
||||
D32Float,
|
||||
D24UnormS8Uint,
|
||||
D32FloatS8Uint,
|
||||
R8G8B8X8Srgb,
|
||||
R8G8B8A8Srgb,
|
||||
R4G4Unorm,
|
||||
R4G4B4A4Unorm,
|
||||
@ -113,18 +112,6 @@ namespace Ryujinx.Graphics.GAL
|
||||
R10G10B10A2Sint,
|
||||
R10G10B10A2Uscaled,
|
||||
R10G10B10A2Sscaled,
|
||||
R8G8B8X8Unorm,
|
||||
R8G8B8X8Snorm,
|
||||
R8G8B8X8Uint,
|
||||
R8G8B8X8Sint,
|
||||
R16G16B16X16Float,
|
||||
R16G16B16X16Unorm,
|
||||
R16G16B16X16Snorm,
|
||||
R16G16B16X16Uint,
|
||||
R16G16B16X16Sint,
|
||||
R32G32B32X32Float,
|
||||
R32G32B32X32Uint,
|
||||
R32G32B32X32Sint,
|
||||
Astc4x4Unorm,
|
||||
Astc5x4Unorm,
|
||||
Astc5x5Unorm,
|
||||
@ -154,12 +141,9 @@ namespace Ryujinx.Graphics.GAL
|
||||
Astc12x10Srgb,
|
||||
Astc12x12Srgb,
|
||||
B5G6R5Unorm,
|
||||
B5G5R5X1Unorm,
|
||||
B5G5R5A1Unorm,
|
||||
A1B5G5R5Unorm,
|
||||
B8G8R8X8Unorm,
|
||||
B8G8R8A8Unorm,
|
||||
B8G8R8X8Srgb,
|
||||
B8G8R8A8Srgb
|
||||
}
|
||||
|
||||
@ -272,7 +256,6 @@ namespace Ryujinx.Graphics.GAL
|
||||
case Format.R8Snorm:
|
||||
case Format.R8Sint:
|
||||
case Format.R8Uint:
|
||||
case Format.B5G5R5X1Unorm:
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -357,11 +340,8 @@ namespace Ryujinx.Graphics.GAL
|
||||
switch (format)
|
||||
{
|
||||
case Format.B5G6R5Unorm:
|
||||
case Format.B5G5R5X1Unorm:
|
||||
case Format.B5G5R5A1Unorm:
|
||||
case Format.B8G8R8X8Unorm:
|
||||
case Format.B8G8R8A8Unorm:
|
||||
case Format.B8G8R8X8Srgb:
|
||||
case Format.B8G8R8A8Srgb:
|
||||
return true;
|
||||
}
|
||||
@ -412,9 +392,6 @@ namespace Ryujinx.Graphics.GAL
|
||||
case Format.R16G16B16A16Uint:
|
||||
case Format.R32G32B32A32Uint:
|
||||
case Format.R10G10B10A2Uint:
|
||||
case Format.R8G8B8X8Uint:
|
||||
case Format.R16G16B16X16Uint:
|
||||
case Format.R32G32B32X32Uint:
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -443,9 +420,6 @@ namespace Ryujinx.Graphics.GAL
|
||||
case Format.R16G16B16A16Sint:
|
||||
case Format.R32G32B32A32Sint:
|
||||
case Format.R10G10B10A2Sint:
|
||||
case Format.R8G8B8X8Sint:
|
||||
case Format.R16G16B16X16Sint:
|
||||
case Format.R32G32B32X32Sint:
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
|
||||
private uint _prevFirstVertex;
|
||||
private bool _prevTfEnable;
|
||||
|
||||
private uint _prevRtNoAlphaMask;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the state updater.
|
||||
/// </summary>
|
||||
@ -398,6 +400,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
|
||||
int clipRegionHeight = int.MaxValue;
|
||||
|
||||
bool changedScale = false;
|
||||
uint rtNoAlphaMask = 0;
|
||||
|
||||
for (int index = 0; index < Constants.TotalRenderTargets; index++)
|
||||
{
|
||||
@ -412,6 +415,11 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
|
||||
continue;
|
||||
}
|
||||
|
||||
if (colorState.Format.NoAlpha())
|
||||
{
|
||||
rtNoAlphaMask |= 1u << index;
|
||||
}
|
||||
|
||||
Image.Texture color = memoryManager.Physical.TextureCache.FindOrCreateTexture(
|
||||
memoryManager,
|
||||
colorState,
|
||||
@ -485,6 +493,13 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
|
||||
}
|
||||
|
||||
_channel.TextureManager.SetClipRegion(clipRegionWidth, clipRegionHeight);
|
||||
|
||||
if (useControl && _prevRtNoAlphaMask != rtNoAlphaMask)
|
||||
{
|
||||
_prevRtNoAlphaMask = rtNoAlphaMask;
|
||||
|
||||
UpdateBlendState();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -1056,44 +1071,80 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
|
||||
bool blendIndependent = _state.State.BlendIndependent;
|
||||
ColorF blendConstant = _state.State.BlendConstant;
|
||||
|
||||
for (int index = 0; index < Constants.TotalRenderTargets; index++)
|
||||
if (blendIndependent)
|
||||
{
|
||||
BlendDescriptor descriptor;
|
||||
|
||||
if (blendIndependent)
|
||||
for (int index = 0; index < Constants.TotalRenderTargets; index++)
|
||||
{
|
||||
bool enable = _state.State.BlendEnable[index];
|
||||
var blend = _state.State.BlendState[index];
|
||||
|
||||
descriptor = new BlendDescriptor(
|
||||
var descriptor = new BlendDescriptor(
|
||||
enable,
|
||||
blendConstant,
|
||||
blend.ColorOp,
|
||||
blend.ColorSrcFactor,
|
||||
blend.ColorDstFactor,
|
||||
FilterBlendFactor(blend.ColorSrcFactor, index),
|
||||
FilterBlendFactor(blend.ColorDstFactor, index),
|
||||
blend.AlphaOp,
|
||||
blend.AlphaSrcFactor,
|
||||
blend.AlphaDstFactor);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool enable = _state.State.BlendEnable[0];
|
||||
var blend = _state.State.BlendStateCommon;
|
||||
FilterBlendFactor(blend.AlphaSrcFactor, index),
|
||||
FilterBlendFactor(blend.AlphaDstFactor, index));
|
||||
|
||||
descriptor = new BlendDescriptor(
|
||||
enable,
|
||||
blendConstant,
|
||||
blend.ColorOp,
|
||||
blend.ColorSrcFactor,
|
||||
blend.ColorDstFactor,
|
||||
blend.AlphaOp,
|
||||
blend.AlphaSrcFactor,
|
||||
blend.AlphaDstFactor);
|
||||
_pipeline.BlendDescriptors[index] = descriptor;
|
||||
_context.Renderer.Pipeline.SetBlendState(index, descriptor);
|
||||
}
|
||||
|
||||
_pipeline.BlendDescriptors[index] = descriptor;
|
||||
_context.Renderer.Pipeline.SetBlendState(index, descriptor);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool enable = _state.State.BlendEnable[0];
|
||||
var blend = _state.State.BlendStateCommon;
|
||||
|
||||
var descriptor = new BlendDescriptor(
|
||||
enable,
|
||||
blendConstant,
|
||||
blend.ColorOp,
|
||||
FilterBlendFactor(blend.ColorSrcFactor, 0),
|
||||
FilterBlendFactor(blend.ColorDstFactor, 0),
|
||||
blend.AlphaOp,
|
||||
FilterBlendFactor(blend.AlphaSrcFactor, 0),
|
||||
FilterBlendFactor(blend.AlphaDstFactor, 0));
|
||||
|
||||
for (int index = 0; index < Constants.TotalRenderTargets; index++)
|
||||
{
|
||||
_pipeline.BlendDescriptors[index] = descriptor;
|
||||
_context.Renderer.Pipeline.SetBlendState(index, descriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a blend factor for the color target currently.
|
||||
/// This will return <paramref name="factor"/> unless the target format has no alpha component,
|
||||
/// in which case it will replace destination alpha factor with a constant factor of one or zero.
|
||||
/// </summary>
|
||||
/// <param name="factor">Input factor</param>
|
||||
/// <param name="index">Color target index</param>
|
||||
/// <returns>New blend factor</returns>
|
||||
private BlendFactor FilterBlendFactor(BlendFactor factor, int index)
|
||||
{
|
||||
// If any color target format without alpha is being used, we need to make sure that
|
||||
// if blend is active, it will not use destination alpha as a factor.
|
||||
// That is required because RGBX formats are emulated using host RGBA formats.
|
||||
|
||||
if (_state.State.RtColorState[index].Format.NoAlpha())
|
||||
{
|
||||
switch (factor)
|
||||
{
|
||||
case BlendFactor.DstAlpha:
|
||||
case BlendFactor.DstAlphaGl:
|
||||
factor = BlendFactor.One;
|
||||
break;
|
||||
case BlendFactor.OneMinusDstAlpha:
|
||||
case BlendFactor.OneMinusDstAlphaGl:
|
||||
factor = BlendFactor.Zero;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return factor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -1242,6 +1293,10 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
|
||||
_channel.BufferManager.SetGraphicsUniformBufferBindings(stage, info.CBuffers);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current texture pool state.
|
||||
/// </summary>
|
||||
/// <returns>Texture pool state</returns>
|
||||
private GpuChannelPoolState GetPoolState()
|
||||
{
|
||||
return new GpuChannelPoolState(
|
||||
@ -1286,6 +1341,10 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
|
||||
ref attributeTypes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the depth mode that is currently being used (zero to one or minus one to one).
|
||||
/// </summary>
|
||||
/// <returns>Current depth mode</returns>
|
||||
private DepthMode GetDepthMode()
|
||||
{
|
||||
ref var transform = ref _state.State.ViewportTransform[0];
|
||||
|
@ -124,11 +124,42 @@ namespace Ryujinx.Graphics.Gpu.Engine.Types
|
||||
ColorFormat.R8Snorm => new FormatInfo(Format.R8Snorm, 1, 1, 1, 1),
|
||||
ColorFormat.R8Sint => new FormatInfo(Format.R8Sint, 1, 1, 1, 1),
|
||||
ColorFormat.R8Uint => new FormatInfo(Format.R8Uint, 1, 1, 1, 1),
|
||||
ColorFormat.B5G5R5X1Unorm => new FormatInfo(Format.B5G5R5X1Unorm, 1, 1, 2, 4),
|
||||
ColorFormat.B5G5R5X1Unorm => new FormatInfo(Format.B5G5R5A1Unorm, 1, 1, 2, 4),
|
||||
ColorFormat.R8G8B8X8Unorm => new FormatInfo(Format.R8G8B8A8Unorm, 1, 1, 4, 4),
|
||||
ColorFormat.R8G8B8X8Srgb => new FormatInfo(Format.R8G8B8A8Srgb, 1, 1, 4, 4),
|
||||
_ => FormatInfo.Default
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a format has an alpha component.
|
||||
/// </summary>
|
||||
/// <param name="format">Format to be checked</param>
|
||||
/// <returns>True if the format has no alpha component (RGBX), false if it does (RGBA)</returns>
|
||||
public static bool NoAlpha(this ColorFormat format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case ColorFormat.R32G32B32X32Float:
|
||||
case ColorFormat.R32G32B32X32Sint:
|
||||
case ColorFormat.R32G32B32X32Uint:
|
||||
case ColorFormat.R16G16B16X16Unorm:
|
||||
case ColorFormat.R16G16B16X16Snorm:
|
||||
case ColorFormat.R16G16B16X16Sint:
|
||||
case ColorFormat.R16G16B16X16Uint:
|
||||
case ColorFormat.R16G16B16X16Float:
|
||||
case ColorFormat.R8G8B8X8Snorm:
|
||||
case ColorFormat.R8G8B8X8Sint:
|
||||
case ColorFormat.R8G8B8X8Uint:
|
||||
case ColorFormat.B8G8R8X8Unorm:
|
||||
case ColorFormat.B8G8R8X8Srgb:
|
||||
case ColorFormat.B5G5R5X1Unorm:
|
||||
case ColorFormat.R8G8B8X8Unorm:
|
||||
case ColorFormat.R8G8B8X8Srgb:
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -553,7 +553,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
|
||||
specStateMatches &= specState.MatchesTexture(stage, index, descriptor);
|
||||
|
||||
Sampler sampler = _samplerPool?.Get(samplerId);
|
||||
Sampler sampler = samplerPool?.Get(samplerId);
|
||||
|
||||
ITexture hostTexture = texture?.GetTargetTexture(bindingInfo.Target);
|
||||
ISampler hostSampler = sampler?.GetHostSampler(texture);
|
||||
|
@ -70,7 +70,6 @@ namespace Ryujinx.Graphics.OpenGL
|
||||
Add(Format.D32Float, new FormatInfo(1, false, false, All.DepthComponent32f, PixelFormat.DepthComponent, PixelType.Float));
|
||||
Add(Format.D24UnormS8Uint, new FormatInfo(1, false, false, All.Depth24Stencil8, PixelFormat.DepthStencil, PixelType.UnsignedInt248));
|
||||
Add(Format.D32FloatS8Uint, new FormatInfo(1, false, false, All.Depth32fStencil8, PixelFormat.DepthStencil, PixelType.Float32UnsignedInt248Rev));
|
||||
Add(Format.R8G8B8X8Srgb, new FormatInfo(4, false, false, All.Srgb8, PixelFormat.Rgba, PixelType.UnsignedByte));
|
||||
Add(Format.R8G8B8A8Srgb, new FormatInfo(4, false, false, All.Srgb8Alpha8, PixelFormat.Rgba, PixelType.UnsignedByte));
|
||||
Add(Format.R4G4B4A4Unorm, new FormatInfo(4, true, false, All.Rgba4, PixelFormat.Rgba, PixelType.UnsignedShort4444Reversed));
|
||||
Add(Format.R5G5B5X1Unorm, new FormatInfo(4, true, false, All.Rgb5, PixelFormat.Rgb, PixelType.UnsignedShort1555Reversed));
|
||||
@ -124,18 +123,6 @@ namespace Ryujinx.Graphics.OpenGL
|
||||
Add(Format.R10G10B10A2Sint, new FormatInfo(4, false, false, All.Rgb10A2, PixelFormat.RgbaInteger, (PixelType)All.Int2101010Rev));
|
||||
Add(Format.R10G10B10A2Uscaled, new FormatInfo(4, false, true, All.Rgb10A2ui, PixelFormat.RgbaInteger, PixelType.UnsignedInt2101010Reversed));
|
||||
Add(Format.R10G10B10A2Sscaled, new FormatInfo(4, false, true, All.Rgb10A2, PixelFormat.RgbaInteger, PixelType.UnsignedInt2101010Reversed));
|
||||
Add(Format.R8G8B8X8Unorm, new FormatInfo(4, true, false, All.Rgb8, PixelFormat.Rgba, PixelType.UnsignedByte));
|
||||
Add(Format.R8G8B8X8Snorm, new FormatInfo(4, true, false, All.Rgb8Snorm, PixelFormat.Rgba, PixelType.Byte));
|
||||
Add(Format.R8G8B8X8Uint, new FormatInfo(4, false, false, All.Rgb8ui, PixelFormat.RgbaInteger, PixelType.UnsignedByte));
|
||||
Add(Format.R8G8B8X8Sint, new FormatInfo(4, false, false, All.Rgb8i, PixelFormat.RgbaInteger, PixelType.Byte));
|
||||
Add(Format.R16G16B16X16Float, new FormatInfo(4, false, false, All.Rgb16f, PixelFormat.Rgba, PixelType.HalfFloat));
|
||||
Add(Format.R16G16B16X16Unorm, new FormatInfo(4, true, false, All.Rgb16, PixelFormat.Rgba, PixelType.UnsignedShort));
|
||||
Add(Format.R16G16B16X16Snorm, new FormatInfo(4, true, false, All.Rgb16Snorm, PixelFormat.Rgba, PixelType.Short));
|
||||
Add(Format.R16G16B16X16Uint, new FormatInfo(4, false, false, All.Rgb16ui, PixelFormat.RgbaInteger, PixelType.UnsignedShort));
|
||||
Add(Format.R16G16B16X16Sint, new FormatInfo(4, false, false, All.Rgb16i, PixelFormat.RgbaInteger, PixelType.Short));
|
||||
Add(Format.R32G32B32X32Float, new FormatInfo(4, false, false, All.Rgb32f, PixelFormat.Rgba, PixelType.Float));
|
||||
Add(Format.R32G32B32X32Uint, new FormatInfo(4, false, false, All.Rgb32ui, PixelFormat.RgbaInteger, PixelType.UnsignedInt));
|
||||
Add(Format.R32G32B32X32Sint, new FormatInfo(4, false, false, All.Rgb32i, PixelFormat.RgbaInteger, PixelType.Int));
|
||||
Add(Format.Astc4x4Unorm, new FormatInfo(4, true, false, All.CompressedRgbaAstc4X4Khr));
|
||||
Add(Format.Astc5x4Unorm, new FormatInfo(4, true, false, All.CompressedRgbaAstc5X4Khr));
|
||||
Add(Format.Astc5x5Unorm, new FormatInfo(4, true, false, All.CompressedRgbaAstc5X5Khr));
|
||||
@ -165,12 +152,9 @@ namespace Ryujinx.Graphics.OpenGL
|
||||
Add(Format.Astc12x10Srgb, new FormatInfo(4, false, false, All.CompressedSrgb8Alpha8Astc12X10Khr));
|
||||
Add(Format.Astc12x12Srgb, new FormatInfo(4, false, false, All.CompressedSrgb8Alpha8Astc12X12Khr));
|
||||
Add(Format.B5G6R5Unorm, new FormatInfo(3, true, false, All.Rgb565, PixelFormat.Rgb, PixelType.UnsignedShort565Reversed));
|
||||
Add(Format.B5G5R5X1Unorm, new FormatInfo(4, true, false, All.Rgb5, PixelFormat.Rgba, PixelType.UnsignedShort1555Reversed));
|
||||
Add(Format.B5G5R5A1Unorm, new FormatInfo(4, true, false, All.Rgb5A1, PixelFormat.Rgba, PixelType.UnsignedShort1555Reversed));
|
||||
Add(Format.A1B5G5R5Unorm, new FormatInfo(4, true, false, All.Rgb5A1, PixelFormat.Rgba, PixelType.UnsignedShort5551));
|
||||
Add(Format.B8G8R8X8Unorm, new FormatInfo(4, true, false, All.Rgba8, PixelFormat.Rgba, PixelType.UnsignedByte));
|
||||
Add(Format.B8G8R8A8Unorm, new FormatInfo(4, true, false, All.Rgba8, PixelFormat.Rgba, PixelType.UnsignedByte));
|
||||
Add(Format.B8G8R8X8Srgb, new FormatInfo(4, false, false, All.Srgb8, PixelFormat.Rgba, PixelType.UnsignedByte));
|
||||
Add(Format.B8G8R8A8Srgb, new FormatInfo(4, false, false, All.Srgb8Alpha8, PixelFormat.Rgba, PixelType.UnsignedByte));
|
||||
|
||||
Add(Format.R8Unorm, SizedInternalFormat.R8);
|
||||
|
@ -236,7 +236,7 @@ namespace Ryujinx.Graphics.OpenGL
|
||||
return;
|
||||
}
|
||||
|
||||
PreDraw();
|
||||
PreDraw(vertexCount);
|
||||
|
||||
if (_primitiveType == PrimitiveType.Quads && !HwCapabilities.SupportsQuads)
|
||||
{
|
||||
@ -354,7 +354,7 @@ namespace Ryujinx.Graphics.OpenGL
|
||||
return;
|
||||
}
|
||||
|
||||
PreDraw();
|
||||
PreDrawVbUnbounded();
|
||||
|
||||
int indexElemSize = 1;
|
||||
|
||||
@ -686,7 +686,7 @@ namespace Ryujinx.Graphics.OpenGL
|
||||
return;
|
||||
}
|
||||
|
||||
PreDraw();
|
||||
PreDrawVbUnbounded();
|
||||
|
||||
GL.BindBuffer((BufferTarget)All.DrawIndirectBuffer, indirectBuffer.Handle.ToInt32());
|
||||
GL.BindBuffer((BufferTarget)All.ParameterBuffer, parameterBuffer.Handle.ToInt32());
|
||||
@ -709,7 +709,7 @@ namespace Ryujinx.Graphics.OpenGL
|
||||
return;
|
||||
}
|
||||
|
||||
PreDraw();
|
||||
PreDrawVbUnbounded();
|
||||
|
||||
_vertexArray.SetRangeOfIndexBuffer();
|
||||
|
||||
@ -1515,11 +1515,22 @@ namespace Ryujinx.Graphics.OpenGL
|
||||
_supportBuffer.Commit();
|
||||
}
|
||||
|
||||
private void PreDraw(int vertexCount)
|
||||
{
|
||||
_vertexArray.PreDraw(vertexCount);
|
||||
PreDraw();
|
||||
}
|
||||
|
||||
private void PreDrawVbUnbounded()
|
||||
{
|
||||
_vertexArray.PreDrawVbUnbounded();
|
||||
PreDraw();
|
||||
}
|
||||
|
||||
private void PreDraw()
|
||||
{
|
||||
DrawCount++;
|
||||
|
||||
_vertexArray.Validate();
|
||||
_unit0Texture?.Bind(0);
|
||||
_supportBuffer.Commit();
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
using Ryujinx.Graphics.GAL;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Ryujinx.Graphics.OpenGL
|
||||
@ -16,12 +17,16 @@ namespace Ryujinx.Graphics.OpenGL
|
||||
|
||||
private int _vertexAttribsCount;
|
||||
private int _vertexBuffersCount;
|
||||
private int _minVertexCount;
|
||||
|
||||
private uint _vertexAttribsInUse;
|
||||
private uint _vertexBuffersInUse;
|
||||
private uint _vertexBuffersLimited;
|
||||
|
||||
private BufferRange _indexBuffer;
|
||||
private BufferHandle _tempIndexBuffer;
|
||||
private BufferHandle _tempVertexBuffer;
|
||||
private int _tempVertexBufferSize;
|
||||
|
||||
public VertexArray()
|
||||
{
|
||||
@ -40,6 +45,8 @@ namespace Ryujinx.Graphics.OpenGL
|
||||
|
||||
public void SetVertexBuffers(ReadOnlySpan<VertexBufferDescriptor> vertexBuffers)
|
||||
{
|
||||
int minVertexCount = int.MaxValue;
|
||||
|
||||
int bindingIndex;
|
||||
for (bindingIndex = 0; bindingIndex < vertexBuffers.Length; bindingIndex++)
|
||||
{
|
||||
@ -47,6 +54,12 @@ namespace Ryujinx.Graphics.OpenGL
|
||||
|
||||
if (vb.Buffer.Handle != BufferHandle.Null)
|
||||
{
|
||||
int vertexCount = vb.Stride <= 0 ? 0 : vb.Buffer.Size / vb.Stride;
|
||||
if (minVertexCount > vertexCount)
|
||||
{
|
||||
minVertexCount = vertexCount;
|
||||
}
|
||||
|
||||
GL.BindVertexBuffer(bindingIndex, vb.Buffer.Handle.ToInt32(), (IntPtr)vb.Buffer.Offset, vb.Stride);
|
||||
GL.VertexBindingDivisor(bindingIndex, vb.Divisor);
|
||||
_vertexBuffersInUse |= 1u << bindingIndex;
|
||||
@ -64,6 +77,7 @@ namespace Ryujinx.Graphics.OpenGL
|
||||
}
|
||||
|
||||
_vertexBuffersCount = bindingIndex;
|
||||
_minVertexCount = minVertexCount;
|
||||
_needsAttribsUpdate = true;
|
||||
}
|
||||
|
||||
@ -143,6 +157,101 @@ namespace Ryujinx.Graphics.OpenGL
|
||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, _indexBuffer.Handle.ToInt32());
|
||||
}
|
||||
|
||||
public void PreDraw(int vertexCount)
|
||||
{
|
||||
LimitVertexBuffers(vertexCount);
|
||||
Validate();
|
||||
}
|
||||
|
||||
public void PreDrawVbUnbounded()
|
||||
{
|
||||
UnlimitVertexBuffers();
|
||||
Validate();
|
||||
}
|
||||
|
||||
public void LimitVertexBuffers(int vertexCount)
|
||||
{
|
||||
// Is it possible for the draw to fetch outside the bounds of any vertex buffer currently bound?
|
||||
|
||||
if (vertexCount <= _minVertexCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// If the draw can fetch out of bounds, let's ensure that it will only fetch zeros rather than memory garbage.
|
||||
|
||||
int currentTempVbOffset = 0;
|
||||
uint buffersInUse = _vertexBuffersInUse;
|
||||
|
||||
while (buffersInUse != 0)
|
||||
{
|
||||
int vbIndex = BitOperations.TrailingZeroCount(buffersInUse);
|
||||
|
||||
ref var vb = ref _vertexBuffers[vbIndex];
|
||||
|
||||
int requiredSize = vertexCount * vb.Stride;
|
||||
|
||||
if (vb.Buffer.Size < requiredSize)
|
||||
{
|
||||
BufferHandle tempVertexBuffer = EnsureTempVertexBufferSize(currentTempVbOffset + requiredSize);
|
||||
|
||||
Buffer.Copy(vb.Buffer.Handle, tempVertexBuffer, vb.Buffer.Offset, currentTempVbOffset, vb.Buffer.Size);
|
||||
Buffer.Clear(tempVertexBuffer, currentTempVbOffset + vb.Buffer.Size, requiredSize - vb.Buffer.Size, 0);
|
||||
|
||||
GL.BindVertexBuffer(vbIndex, tempVertexBuffer.ToInt32(), (IntPtr)currentTempVbOffset, vb.Stride);
|
||||
|
||||
currentTempVbOffset += requiredSize;
|
||||
_vertexBuffersLimited |= 1u << vbIndex;
|
||||
}
|
||||
|
||||
buffersInUse &= ~(1u << vbIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private BufferHandle EnsureTempVertexBufferSize(int size)
|
||||
{
|
||||
BufferHandle tempVertexBuffer = _tempVertexBuffer;
|
||||
|
||||
if (_tempVertexBufferSize < size)
|
||||
{
|
||||
_tempVertexBufferSize = size;
|
||||
|
||||
if (tempVertexBuffer == BufferHandle.Null)
|
||||
{
|
||||
tempVertexBuffer = Buffer.Create(size);
|
||||
_tempVertexBuffer = tempVertexBuffer;
|
||||
return tempVertexBuffer;
|
||||
}
|
||||
|
||||
Buffer.Resize(_tempVertexBuffer, size);
|
||||
}
|
||||
|
||||
return tempVertexBuffer;
|
||||
}
|
||||
|
||||
public void UnlimitVertexBuffers()
|
||||
{
|
||||
uint buffersLimited = _vertexBuffersLimited;
|
||||
|
||||
if (buffersLimited == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while (buffersLimited != 0)
|
||||
{
|
||||
int vbIndex = BitOperations.TrailingZeroCount(buffersLimited);
|
||||
|
||||
ref var vb = ref _vertexBuffers[vbIndex];
|
||||
|
||||
GL.BindVertexBuffer(vbIndex, vb.Buffer.Handle.ToInt32(), (IntPtr)vb.Buffer.Offset, vb.Stride);
|
||||
|
||||
buffersLimited &= ~(1u << vbIndex);
|
||||
}
|
||||
|
||||
_vertexBuffersLimited = 0;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
for (int attribIndex = 0; attribIndex < _vertexAttribsCount; attribIndex++)
|
||||
|
@ -1,19 +0,0 @@
|
||||
using Ryujinx.Graphics.GAL;
|
||||
|
||||
namespace Ryujinx.Graphics.OpenGL
|
||||
{
|
||||
struct VertexBuffer
|
||||
{
|
||||
public BufferRange Range { get; }
|
||||
|
||||
public int Divisor { get; }
|
||||
public int Stride { get; }
|
||||
|
||||
public VertexBuffer(BufferRange range, int divisor, int stride)
|
||||
{
|
||||
Range = range;
|
||||
Divisor = divisor;
|
||||
Stride = stride;
|
||||
}
|
||||
}
|
||||
}
|
@ -66,7 +66,6 @@ namespace Ryujinx.Graphics.Vulkan
|
||||
Add(Format.D32Float, VkFormat.D32Sfloat);
|
||||
Add(Format.D24UnormS8Uint, VkFormat.D24UnormS8Uint);
|
||||
Add(Format.D32FloatS8Uint, VkFormat.D32SfloatS8Uint);
|
||||
Add(Format.R8G8B8X8Srgb, VkFormat.R8G8B8Srgb);
|
||||
Add(Format.R8G8B8A8Srgb, VkFormat.R8G8B8A8Srgb);
|
||||
Add(Format.R4G4Unorm, VkFormat.R4G4UnormPack8);
|
||||
Add(Format.R4G4B4A4Unorm, VkFormat.R4G4B4A4UnormPack16);
|
||||
@ -119,18 +118,6 @@ namespace Ryujinx.Graphics.Vulkan
|
||||
Add(Format.R10G10B10A2Sint, VkFormat.A2B10G10R10SintPack32);
|
||||
Add(Format.R10G10B10A2Uscaled, VkFormat.A2B10G10R10UscaledPack32);
|
||||
Add(Format.R10G10B10A2Sscaled, VkFormat.A2B10G10R10SscaledPack32);
|
||||
Add(Format.R8G8B8X8Unorm, VkFormat.R8G8B8Unorm);
|
||||
Add(Format.R8G8B8X8Snorm, VkFormat.R8G8B8SNorm);
|
||||
Add(Format.R8G8B8X8Uint, VkFormat.R8G8B8Uint);
|
||||
Add(Format.R8G8B8X8Sint, VkFormat.R8G8B8Sint);
|
||||
Add(Format.R16G16B16X16Float, VkFormat.R16G16B16Sfloat);
|
||||
Add(Format.R16G16B16X16Unorm, VkFormat.R16G16B16Unorm);
|
||||
Add(Format.R16G16B16X16Snorm, VkFormat.R16G16B16SNorm);
|
||||
Add(Format.R16G16B16X16Uint, VkFormat.R16G16B16Uint);
|
||||
Add(Format.R16G16B16X16Sint, VkFormat.R16G16B16Sint);
|
||||
Add(Format.R32G32B32X32Float, VkFormat.R32G32B32Sfloat);
|
||||
Add(Format.R32G32B32X32Uint, VkFormat.R32G32B32Uint);
|
||||
Add(Format.R32G32B32X32Sint, VkFormat.R32G32B32Sint);
|
||||
Add(Format.Astc4x4Unorm, VkFormat.Astc4x4UnormBlock);
|
||||
Add(Format.Astc5x4Unorm, VkFormat.Astc5x4UnormBlock);
|
||||
Add(Format.Astc5x5Unorm, VkFormat.Astc5x5UnormBlock);
|
||||
@ -160,12 +147,9 @@ namespace Ryujinx.Graphics.Vulkan
|
||||
Add(Format.Astc12x10Srgb, VkFormat.Astc12x10SrgbBlock);
|
||||
Add(Format.Astc12x12Srgb, VkFormat.Astc12x12SrgbBlock);
|
||||
Add(Format.B5G6R5Unorm, VkFormat.R5G6B5UnormPack16);
|
||||
Add(Format.B5G5R5X1Unorm, VkFormat.A1R5G5B5UnormPack16);
|
||||
Add(Format.B5G5R5A1Unorm, VkFormat.A1R5G5B5UnormPack16);
|
||||
Add(Format.A1B5G5R5Unorm, VkFormat.R5G5B5A1UnormPack16);
|
||||
Add(Format.B8G8R8X8Unorm, VkFormat.B8G8R8Unorm);
|
||||
Add(Format.B8G8R8A8Unorm, VkFormat.B8G8R8A8Unorm);
|
||||
Add(Format.B8G8R8X8Srgb, VkFormat.B8G8R8Srgb);
|
||||
Add(Format.B8G8R8A8Srgb, VkFormat.B8G8R8A8Srgb);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user