|
|
@@ -43,16 +43,9 @@ namespace Ryujinx.Graphics.OpenGL
|
|
|
|
|
|
private CounterQueueEvent _activeConditionalRender;
|
|
|
|
|
|
- private struct Vector4<T>
|
|
|
- {
|
|
|
- public T X;
|
|
|
- public T Y;
|
|
|
- public T Z;
|
|
|
- public T W;
|
|
|
- }
|
|
|
-
|
|
|
private Vector4<int>[] _fpIsBgra = new Vector4<int>[SupportBuffer.FragmentIsBgraCount];
|
|
|
private Vector4<float>[] _renderScale = new Vector4<float>[65];
|
|
|
+ private int _fragmentScaleCount;
|
|
|
|
|
|
private TextureBase _unit0Texture;
|
|
|
private Sampler _unit0Sampler;
|
|
|
@@ -68,7 +61,7 @@ namespace Ryujinx.Graphics.OpenGL
|
|
|
private bool _tfEnabled;
|
|
|
private TransformFeedbackPrimitiveType _tfTopology;
|
|
|
|
|
|
- private BufferHandle _supportBuffer;
|
|
|
+ private SupportBufferUpdater _supportBuffer;
|
|
|
private readonly BufferHandle[] _tfbs;
|
|
|
private readonly BufferRange[] _tfbTargets;
|
|
|
|
|
|
@@ -95,13 +88,13 @@ namespace Ryujinx.Graphics.OpenGL
|
|
|
_tfbTargets = new BufferRange[Constants.MaxTransformFeedbackBuffers];
|
|
|
}
|
|
|
|
|
|
- public void Initialize()
|
|
|
+ public void Initialize(Renderer renderer)
|
|
|
{
|
|
|
- _supportBuffer = Buffer.Create(SupportBuffer.RequiredSize);
|
|
|
- GL.BindBufferBase(BufferRangeTarget.UniformBuffer, 0, Unsafe.As<BufferHandle, int>(ref _supportBuffer));
|
|
|
+ _supportBuffer = new SupportBufferUpdater(renderer);
|
|
|
+ GL.BindBufferBase(BufferRangeTarget.UniformBuffer, 0, Unsafe.As<BufferHandle, int>(ref _supportBuffer.Handle));
|
|
|
|
|
|
- SetSupportBufferData<Vector4<int>>(SupportBuffer.FragmentIsBgraOffset, _fpIsBgra, SupportBuffer.FragmentIsBgraCount);
|
|
|
- SetSupportBufferData<Vector4<float>>(SupportBuffer.FragmentRenderScaleOffset, _renderScale, SupportBuffer.RenderScaleMaxCount);
|
|
|
+ _supportBuffer.UpdateFragmentIsBgra(_fpIsBgra, 0, SupportBuffer.FragmentIsBgraCount);
|
|
|
+ _supportBuffer.UpdateRenderScale(_renderScale, 0, SupportBuffer.RenderScaleMaxCount);
|
|
|
}
|
|
|
|
|
|
public void Barrier()
|
|
|
@@ -558,6 +551,8 @@ namespace Ryujinx.Graphics.OpenGL
|
|
|
{
|
|
|
if (texture is TextureView view && sampler is Sampler samp)
|
|
|
{
|
|
|
+ _supportBuffer.Commit();
|
|
|
+
|
|
|
if (HwCapabilities.SupportsDrawTexture)
|
|
|
{
|
|
|
GL.NV.DrawTexture(
|
|
|
@@ -1038,7 +1033,7 @@ namespace Ryujinx.Graphics.OpenGL
|
|
|
public void SetRenderTargetScale(float scale)
|
|
|
{
|
|
|
_renderScale[0].X = scale;
|
|
|
- SetSupportBufferData<Vector4<float>>(SupportBuffer.FragmentRenderScaleOffset, _renderScale, 1); // Just the first element.
|
|
|
+ _supportBuffer.UpdateRenderScale(_renderScale, 0, 1); // Just the first element.
|
|
|
}
|
|
|
|
|
|
public void SetRenderTargetColorMasks(ReadOnlySpan<uint> componentMasks)
|
|
|
@@ -1076,7 +1071,7 @@ namespace Ryujinx.Graphics.OpenGL
|
|
|
|
|
|
if (isBgraChanged)
|
|
|
{
|
|
|
- SetSupportBufferData<Vector4<int>>(SupportBuffer.FragmentIsBgraOffset, _fpIsBgra, SupportBuffer.FragmentIsBgraCount);
|
|
|
+ _supportBuffer.UpdateFragmentIsBgra(_fpIsBgra, 0, SupportBuffer.FragmentIsBgraCount);
|
|
|
}
|
|
|
|
|
|
TextureView depthStencilView = (TextureView)depthStencil;
|
|
|
@@ -1384,16 +1379,11 @@ namespace Ryujinx.Graphics.OpenGL
|
|
|
return (_boundDrawFramebuffer, _boundReadFramebuffer);
|
|
|
}
|
|
|
|
|
|
- public void UpdateRenderScale(ShaderStage stage, ReadOnlySpan<float> scales, int textureCount, int imageCount)
|
|
|
+ public void UpdateRenderScale(ReadOnlySpan<float> scales, int totalCount, int fragmentCount)
|
|
|
{
|
|
|
- if (stage != ShaderStage.Compute && stage != ShaderStage.Fragment)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
bool changed = false;
|
|
|
|
|
|
- for (int index = 0; index < textureCount + imageCount; index++)
|
|
|
+ for (int index = 0; index < totalCount; index++)
|
|
|
{
|
|
|
if (_renderScale[1 + index].X != scales[index])
|
|
|
{
|
|
|
@@ -1402,20 +1392,23 @@ namespace Ryujinx.Graphics.OpenGL
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (changed)
|
|
|
+ // Only update fragment count if there are scales after it for the vertex stage.
|
|
|
+ if (fragmentCount != totalCount && fragmentCount != _fragmentScaleCount)
|
|
|
{
|
|
|
- SetSupportBufferData<Vector4<float>>(SupportBuffer.FragmentRenderScaleOffset, _renderScale, 1 + textureCount + imageCount);
|
|
|
+ _fragmentScaleCount = fragmentCount;
|
|
|
+ _supportBuffer.UpdateFragmentRenderScaleCount(_fragmentScaleCount);
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- private void SetSupportBufferData<T>(int offset, ReadOnlySpan<T> data, int count) where T : unmanaged
|
|
|
- {
|
|
|
- Buffer.SetData(_supportBuffer, offset, MemoryMarshal.Cast<T, byte>(data.Slice(0, count)));
|
|
|
+ if (changed)
|
|
|
+ {
|
|
|
+ _supportBuffer.UpdateRenderScale(_renderScale, 0, 1 + totalCount);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void PrepareForDispatch()
|
|
|
{
|
|
|
_unit0Texture?.Bind(0);
|
|
|
+ _supportBuffer.Commit();
|
|
|
}
|
|
|
|
|
|
private void PreDraw()
|
|
|
@@ -1424,6 +1417,7 @@ namespace Ryujinx.Graphics.OpenGL
|
|
|
|
|
|
_vertexArray.Validate();
|
|
|
_unit0Texture?.Bind(0);
|
|
|
+ _supportBuffer.Commit();
|
|
|
}
|
|
|
|
|
|
private void PostDraw()
|
|
|
@@ -1521,11 +1515,7 @@ namespace Ryujinx.Graphics.OpenGL
|
|
|
|
|
|
public void Dispose()
|
|
|
{
|
|
|
- if (_supportBuffer != BufferHandle.Null)
|
|
|
- {
|
|
|
- Buffer.Delete(_supportBuffer);
|
|
|
- _supportBuffer = BufferHandle.Null;
|
|
|
- }
|
|
|
+ _supportBuffer?.Dispose();
|
|
|
|
|
|
for (int i = 0; i < Constants.MaxTransformFeedbackBuffers; i++)
|
|
|
{
|