mirror of
https://github.com/GreemDev/Ryujinx.git
synced 2024-12-22 22:45:46 +00:00
Move support buffer update out of the backends (#5411)
* Move support buffer update out of the backends * Fix render scale init and remove redundant state from SupportBufferUpdater * Stop passing texture scale to the backends * XML docs for SupportBufferUpdater
This commit is contained in:
parent
fa32ef9275
commit
9c6071a645
51 changed files with 364 additions and 496 deletions
|
@ -79,7 +79,6 @@ namespace Ryujinx.Graphics.GAL
|
|||
|
||||
void SetRasterizerDiscard(bool discard);
|
||||
|
||||
void SetRenderTargetScale(float scale);
|
||||
void SetRenderTargetColorMasks(ReadOnlySpan<uint> componentMask);
|
||||
void SetRenderTargets(ITexture[] colors, ITexture depthStencil);
|
||||
|
||||
|
@ -99,7 +98,7 @@ namespace Ryujinx.Graphics.GAL
|
|||
void SetVertexAttribs(ReadOnlySpan<VertexAttribDescriptor> vertexAttribs);
|
||||
void SetVertexBuffers(ReadOnlySpan<VertexBufferDescriptor> vertexBuffers);
|
||||
|
||||
void SetViewports(ReadOnlySpan<Viewport> viewports, bool disableTransform);
|
||||
void SetViewports(ReadOnlySpan<Viewport> viewports);
|
||||
|
||||
void TextureBarrier();
|
||||
void TextureBarrierTiled();
|
||||
|
@ -107,7 +106,5 @@ namespace Ryujinx.Graphics.GAL
|
|||
bool TryHostConditionalRendering(ICounterEvent value, ulong compare, bool isEqual);
|
||||
bool TryHostConditionalRendering(ICounterEvent value, ICounterEvent compare, bool isEqual);
|
||||
void EndHostConditionalRendering();
|
||||
|
||||
void UpdateRenderScale(ReadOnlySpan<float> scales, int totalCount, int fragmentCount);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ namespace Ryujinx.Graphics.GAL
|
|||
void BackgroundContextAction(Action action, bool alwaysBackground = false);
|
||||
|
||||
BufferHandle CreateBuffer(int size, BufferHandle storageHint);
|
||||
|
||||
BufferHandle CreateBuffer(int size)
|
||||
{
|
||||
return CreateBuffer(size, BufferHandle.Null);
|
||||
|
@ -28,7 +27,7 @@ namespace Ryujinx.Graphics.GAL
|
|||
IProgram CreateProgram(ShaderSource[] shaders, ShaderInfo info);
|
||||
|
||||
ISampler CreateSampler(SamplerCreateInfo info);
|
||||
ITexture CreateTexture(TextureCreateInfo info, float scale);
|
||||
ITexture CreateTexture(TextureCreateInfo info);
|
||||
bool PrepareHostMapping(nint address, ulong size);
|
||||
|
||||
void CreateSync(ulong id, bool strict);
|
||||
|
@ -49,7 +48,7 @@ namespace Ryujinx.Graphics.GAL
|
|||
|
||||
void PreFrame();
|
||||
|
||||
ICounterEvent ReportCounter(CounterType type, EventHandler<ulong> resultHandler, bool hostReserved);
|
||||
ICounterEvent ReportCounter(CounterType type, EventHandler<ulong> resultHandler, float divisor, bool hostReserved);
|
||||
|
||||
void ResetCounter(CounterType type);
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ namespace Ryujinx.Graphics.GAL
|
|||
{
|
||||
int Width { get; }
|
||||
int Height { get; }
|
||||
float ScaleFactor { get; }
|
||||
|
||||
void CopyTo(ITexture destination, int firstLayer, int firstLevel);
|
||||
void CopyTo(ITexture destination, int srcLayer, int dstLayer, int srcLevel, int dstLevel);
|
||||
|
|
|
@ -125,7 +125,6 @@ namespace Ryujinx.Graphics.GAL.Multithreading
|
|||
Register<SetProgramCommand>(CommandType.SetProgram);
|
||||
Register<SetRasterizerDiscardCommand>(CommandType.SetRasterizerDiscard);
|
||||
Register<SetRenderTargetColorMasksCommand>(CommandType.SetRenderTargetColorMasks);
|
||||
Register<SetRenderTargetScaleCommand>(CommandType.SetRenderTargetScale);
|
||||
Register<SetRenderTargetsCommand>(CommandType.SetRenderTargets);
|
||||
Register<SetScissorsCommand>(CommandType.SetScissor);
|
||||
Register<SetStencilTestCommand>(CommandType.SetStencilTest);
|
||||
|
@ -138,7 +137,6 @@ namespace Ryujinx.Graphics.GAL.Multithreading
|
|||
Register<TextureBarrierTiledCommand>(CommandType.TextureBarrierTiled);
|
||||
Register<TryHostConditionalRenderingCommand>(CommandType.TryHostConditionalRendering);
|
||||
Register<TryHostConditionalRenderingFlushCommand>(CommandType.TryHostConditionalRenderingFlush);
|
||||
Register<UpdateRenderScaleCommand>(CommandType.UpdateRenderScale);
|
||||
|
||||
return maxCommandSize;
|
||||
}
|
||||
|
|
|
@ -87,7 +87,6 @@
|
|||
SetProgram,
|
||||
SetRasterizerDiscard,
|
||||
SetRenderTargetColorMasks,
|
||||
SetRenderTargetScale,
|
||||
SetRenderTargets,
|
||||
SetScissor,
|
||||
SetStencilTest,
|
||||
|
@ -100,6 +99,5 @@
|
|||
TextureBarrierTiled,
|
||||
TryHostConditionalRendering,
|
||||
TryHostConditionalRenderingFlush,
|
||||
UpdateRenderScale,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,18 +8,16 @@ namespace Ryujinx.Graphics.GAL.Multithreading.Commands.Renderer
|
|||
public readonly CommandType CommandType => CommandType.CreateTexture;
|
||||
private TableRef<ThreadedTexture> _texture;
|
||||
private TextureCreateInfo _info;
|
||||
private float _scale;
|
||||
|
||||
public void Set(TableRef<ThreadedTexture> texture, TextureCreateInfo info, float scale)
|
||||
public void Set(TableRef<ThreadedTexture> texture, TextureCreateInfo info)
|
||||
{
|
||||
_texture = texture;
|
||||
_info = info;
|
||||
_scale = scale;
|
||||
}
|
||||
|
||||
public static void Run(ref CreateTextureCommand command, ThreadedRenderer threaded, IRenderer renderer)
|
||||
{
|
||||
command._texture.Get(threaded).Base = renderer.CreateTexture(command._info, command._scale);
|
||||
command._texture.Get(threaded).Base = renderer.CreateTexture(command._info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,13 +10,15 @@ namespace Ryujinx.Graphics.GAL.Multithreading.Commands.Renderer
|
|||
private TableRef<ThreadedCounterEvent> _event;
|
||||
private CounterType _type;
|
||||
private TableRef<EventHandler<ulong>> _resultHandler;
|
||||
private float _divisor;
|
||||
private bool _hostReserved;
|
||||
|
||||
public void Set(TableRef<ThreadedCounterEvent> evt, CounterType type, TableRef<EventHandler<ulong>> resultHandler, bool hostReserved)
|
||||
public void Set(TableRef<ThreadedCounterEvent> evt, CounterType type, TableRef<EventHandler<ulong>> resultHandler, float divisor, bool hostReserved)
|
||||
{
|
||||
_event = evt;
|
||||
_type = type;
|
||||
_resultHandler = resultHandler;
|
||||
_divisor = divisor;
|
||||
_hostReserved = hostReserved;
|
||||
}
|
||||
|
||||
|
@ -24,7 +26,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading.Commands.Renderer
|
|||
{
|
||||
ThreadedCounterEvent evt = command._event.Get(threaded);
|
||||
|
||||
evt.Create(renderer, command._type, command._resultHandler.Get(threaded), command._hostReserved);
|
||||
evt.Create(renderer, command._type, command._resultHandler.Get(threaded), command._divisor, command._hostReserved);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
namespace Ryujinx.Graphics.GAL.Multithreading.Commands
|
||||
{
|
||||
struct SetRenderTargetScaleCommand : IGALCommand, IGALCommand<SetRenderTargetScaleCommand>
|
||||
{
|
||||
public readonly CommandType CommandType => CommandType.SetRenderTargetScale;
|
||||
private float _scale;
|
||||
|
||||
public void Set(float scale)
|
||||
{
|
||||
_scale = scale;
|
||||
}
|
||||
|
||||
public static void Run(ref SetRenderTargetScaleCommand command, ThreadedRenderer threaded, IRenderer renderer)
|
||||
{
|
||||
renderer.Pipeline.SetRenderTargetScale(command._scale);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,18 +7,16 @@ namespace Ryujinx.Graphics.GAL.Multithreading.Commands
|
|||
{
|
||||
public readonly CommandType CommandType => CommandType.SetViewports;
|
||||
private SpanRef<Viewport> _viewports;
|
||||
private bool _disableTransform;
|
||||
|
||||
public void Set(SpanRef<Viewport> viewports, bool disableTransform)
|
||||
public void Set(SpanRef<Viewport> viewports)
|
||||
{
|
||||
_viewports = viewports;
|
||||
_disableTransform = disableTransform;
|
||||
}
|
||||
|
||||
public static void Run(ref SetViewportsCommand command, ThreadedRenderer threaded, IRenderer renderer)
|
||||
{
|
||||
ReadOnlySpan<Viewport> viewports = command._viewports.Get(threaded);
|
||||
renderer.Pipeline.SetViewports(viewports, command._disableTransform);
|
||||
renderer.Pipeline.SetViewports(viewports);
|
||||
command._viewports.Dispose(threaded);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
using Ryujinx.Graphics.GAL.Multithreading.Model;
|
||||
|
||||
namespace Ryujinx.Graphics.GAL.Multithreading.Commands
|
||||
{
|
||||
struct UpdateRenderScaleCommand : IGALCommand, IGALCommand<UpdateRenderScaleCommand>
|
||||
{
|
||||
public readonly CommandType CommandType => CommandType.UpdateRenderScale;
|
||||
private SpanRef<float> _scales;
|
||||
private int _totalCount;
|
||||
private int _fragmentCount;
|
||||
|
||||
public void Set(SpanRef<float> scales, int totalCount, int fragmentCount)
|
||||
{
|
||||
_scales = scales;
|
||||
_totalCount = totalCount;
|
||||
_fragmentCount = fragmentCount;
|
||||
}
|
||||
|
||||
public static void Run(ref UpdateRenderScaleCommand command, ThreadedRenderer threaded, IRenderer renderer)
|
||||
{
|
||||
renderer.Pipeline.UpdateRenderScale(command._scales.Get(threaded), command._totalCount, command._fragmentCount);
|
||||
command._scales.Dispose(threaded);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -70,10 +70,10 @@ namespace Ryujinx.Graphics.GAL.Multithreading.Resources
|
|||
}
|
||||
}
|
||||
|
||||
public void Create(IRenderer renderer, CounterType type, System.EventHandler<ulong> eventHandler, bool hostReserved)
|
||||
public void Create(IRenderer renderer, CounterType type, System.EventHandler<ulong> eventHandler, float divisor, bool hostReserved)
|
||||
{
|
||||
ThreadedHelpers.SpinUntilExchange(ref _createLock, 1, 0);
|
||||
Base = renderer.ReportCounter(type, eventHandler, hostReserved || _reserved);
|
||||
Base = renderer.ReportCounter(type, eventHandler, divisor, hostReserved || _reserved);
|
||||
Volatile.Write(ref _createLock, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,13 +17,10 @@ namespace Ryujinx.Graphics.GAL.Multithreading.Resources
|
|||
|
||||
public int Height => _info.Height;
|
||||
|
||||
public float ScaleFactor { get; }
|
||||
|
||||
public ThreadedTexture(ThreadedRenderer renderer, TextureCreateInfo info, float scale)
|
||||
public ThreadedTexture(ThreadedRenderer renderer, TextureCreateInfo info)
|
||||
{
|
||||
_renderer = renderer;
|
||||
_info = info;
|
||||
ScaleFactor = scale;
|
||||
}
|
||||
|
||||
private TableRef<T> Ref<T>(T reference)
|
||||
|
@ -64,7 +61,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading.Resources
|
|||
|
||||
public ITexture CreateView(TextureCreateInfo info, int firstLayer, int firstLevel)
|
||||
{
|
||||
ThreadedTexture newTex = new(_renderer, info, ScaleFactor);
|
||||
ThreadedTexture newTex = new(_renderer, info);
|
||||
_renderer.New<TextureCreateViewCommand>().Set(Ref(this), Ref(newTex), info, firstLayer, firstLevel);
|
||||
_renderer.QueueCommand();
|
||||
|
||||
|
|
|
@ -261,12 +261,6 @@ namespace Ryujinx.Graphics.GAL.Multithreading
|
|||
_renderer.QueueCommand();
|
||||
}
|
||||
|
||||
public void SetRenderTargetScale(float scale)
|
||||
{
|
||||
_renderer.New<SetRenderTargetScaleCommand>().Set(scale);
|
||||
_renderer.QueueCommand();
|
||||
}
|
||||
|
||||
public void SetScissors(ReadOnlySpan<Rectangle<int>> scissors)
|
||||
{
|
||||
_renderer.New<SetScissorsCommand>().Set(_renderer.CopySpan(scissors));
|
||||
|
@ -321,9 +315,9 @@ namespace Ryujinx.Graphics.GAL.Multithreading
|
|||
_renderer.QueueCommand();
|
||||
}
|
||||
|
||||
public void SetViewports(ReadOnlySpan<Viewport> viewports, bool disableTransform)
|
||||
public void SetViewports(ReadOnlySpan<Viewport> viewports)
|
||||
{
|
||||
_renderer.New<SetViewportsCommand>().Set(_renderer.CopySpan(viewports), disableTransform);
|
||||
_renderer.New<SetViewportsCommand>().Set(_renderer.CopySpan(viewports));
|
||||
_renderer.QueueCommand();
|
||||
}
|
||||
|
||||
|
@ -368,11 +362,5 @@ namespace Ryujinx.Graphics.GAL.Multithreading
|
|||
_renderer.QueueCommand();
|
||||
return false;
|
||||
}
|
||||
|
||||
public void UpdateRenderScale(ReadOnlySpan<float> scales, int totalCount, int fragmentCount)
|
||||
{
|
||||
_renderer.New<UpdateRenderScaleCommand>().Set(_renderer.CopySpan(scales[..totalCount]), totalCount, fragmentCount);
|
||||
_renderer.QueueCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -320,21 +320,21 @@ namespace Ryujinx.Graphics.GAL.Multithreading
|
|||
QueueCommand();
|
||||
}
|
||||
|
||||
public ITexture CreateTexture(TextureCreateInfo info, float scale)
|
||||
public ITexture CreateTexture(TextureCreateInfo info)
|
||||
{
|
||||
if (IsGpuThread())
|
||||
{
|
||||
var texture = new ThreadedTexture(this, info, scale);
|
||||
New<CreateTextureCommand>().Set(Ref(texture), info, scale);
|
||||
var texture = new ThreadedTexture(this, info);
|
||||
New<CreateTextureCommand>().Set(Ref(texture), info);
|
||||
QueueCommand();
|
||||
|
||||
return texture;
|
||||
}
|
||||
else
|
||||
{
|
||||
var texture = new ThreadedTexture(this, info, scale)
|
||||
var texture = new ThreadedTexture(this, info)
|
||||
{
|
||||
Base = _baseRenderer.CreateTexture(info, scale),
|
||||
Base = _baseRenderer.CreateTexture(info),
|
||||
};
|
||||
|
||||
return texture;
|
||||
|
@ -410,10 +410,10 @@ namespace Ryujinx.Graphics.GAL.Multithreading
|
|||
QueueCommand();
|
||||
}
|
||||
|
||||
public ICounterEvent ReportCounter(CounterType type, EventHandler<ulong> resultHandler, bool hostReserved)
|
||||
public ICounterEvent ReportCounter(CounterType type, EventHandler<ulong> resultHandler, float divisor, bool hostReserved)
|
||||
{
|
||||
ThreadedCounterEvent evt = new(this, type, _lastSampleCounterClear);
|
||||
New<ReportCounterCommand>().Set(Ref(evt), type, Ref(resultHandler), hostReserved);
|
||||
ThreadedCounterEvent evt = new ThreadedCounterEvent(this, type, _lastSampleCounterClear);
|
||||
New<ReportCounterCommand>().Set(Ref(evt), type, Ref(resultHandler), divisor, hostReserved);
|
||||
QueueCommand();
|
||||
|
||||
if (type == CounterType.SamplesPassed)
|
||||
|
|
|
@ -1,102 +0,0 @@
|
|||
using Ryujinx.Graphics.Shader;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.Graphics.GAL
|
||||
{
|
||||
public class SupportBufferUpdater : IDisposable
|
||||
{
|
||||
public SupportBuffer Data;
|
||||
public BufferHandle Handle;
|
||||
|
||||
private readonly IRenderer _renderer;
|
||||
private int _startOffset = -1;
|
||||
private int _endOffset = -1;
|
||||
|
||||
public SupportBufferUpdater(IRenderer renderer)
|
||||
{
|
||||
_renderer = renderer;
|
||||
Handle = renderer.CreateBuffer(SupportBuffer.RequiredSize);
|
||||
renderer.Pipeline.ClearBuffer(Handle, 0, SupportBuffer.RequiredSize, 0);
|
||||
}
|
||||
|
||||
private void MarkDirty(int startOffset, int byteSize)
|
||||
{
|
||||
int endOffset = startOffset + byteSize;
|
||||
|
||||
if (_startOffset == -1)
|
||||
{
|
||||
_startOffset = startOffset;
|
||||
_endOffset = endOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (startOffset < _startOffset)
|
||||
{
|
||||
_startOffset = startOffset;
|
||||
}
|
||||
|
||||
if (endOffset > _endOffset)
|
||||
{
|
||||
_endOffset = endOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateFragmentRenderScaleCount(int count)
|
||||
{
|
||||
if (Data.FragmentRenderScaleCount.X != count)
|
||||
{
|
||||
Data.FragmentRenderScaleCount.X = count;
|
||||
|
||||
MarkDirty(SupportBuffer.FragmentRenderScaleCountOffset, sizeof(int));
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateGenericField<T>(int baseOffset, ReadOnlySpan<T> data, Span<T> target, int offset, int count) where T : unmanaged
|
||||
{
|
||||
data[..count].CopyTo(target[offset..]);
|
||||
|
||||
int elemSize = Unsafe.SizeOf<T>();
|
||||
|
||||
MarkDirty(baseOffset + offset * elemSize, count * elemSize);
|
||||
}
|
||||
|
||||
public void UpdateRenderScale(ReadOnlySpan<Vector4<float>> data, int offset, int count)
|
||||
{
|
||||
UpdateGenericField(SupportBuffer.GraphicsRenderScaleOffset, data, Data.RenderScale.AsSpan(), offset, count);
|
||||
}
|
||||
|
||||
public void UpdateFragmentIsBgra(ReadOnlySpan<Vector4<int>> data, int offset, int count)
|
||||
{
|
||||
UpdateGenericField(SupportBuffer.FragmentIsBgraOffset, data, Data.FragmentIsBgra.AsSpan(), offset, count);
|
||||
}
|
||||
|
||||
public void UpdateViewportInverse(Vector4<float> data)
|
||||
{
|
||||
Data.ViewportInverse = data;
|
||||
|
||||
MarkDirty(SupportBuffer.ViewportInverseOffset, SupportBuffer.FieldSize);
|
||||
}
|
||||
|
||||
public void Commit()
|
||||
{
|
||||
if (_startOffset != -1)
|
||||
{
|
||||
ReadOnlySpan<byte> data = MemoryMarshal.Cast<SupportBuffer, byte>(MemoryMarshal.CreateSpan(ref Data, 1));
|
||||
|
||||
_renderer.SetBufferData(Handle, _startOffset, data[_startOffset.._endOffset]);
|
||||
|
||||
_startOffset = -1;
|
||||
_endOffset = -1;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
_renderer.DeleteBuffer(Handle);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -177,13 +177,15 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
|
|||
resultHandler(null, (ulong)_state.State.SemaphorePayload);
|
||||
break;
|
||||
case ReportCounterType.SamplesPassed:
|
||||
counter = _context.Renderer.ReportCounter(CounterType.SamplesPassed, resultHandler, false);
|
||||
float scale = _channel.TextureManager.RenderTargetScale;
|
||||
float divisor = scale * scale;
|
||||
counter = _context.Renderer.ReportCounter(CounterType.SamplesPassed, resultHandler, divisor, false);
|
||||
break;
|
||||
case ReportCounterType.PrimitivesGenerated:
|
||||
counter = _context.Renderer.ReportCounter(CounterType.PrimitivesGenerated, resultHandler, false);
|
||||
counter = _context.Renderer.ReportCounter(CounterType.PrimitivesGenerated, resultHandler, 1f, false);
|
||||
break;
|
||||
case ReportCounterType.TransformFeedbackPrimitivesWritten:
|
||||
counter = _context.Renderer.ReportCounter(CounterType.TransformFeedbackPrimitivesWritten, resultHandler, false);
|
||||
counter = _context.Renderer.ReportCounter(CounterType.TransformFeedbackPrimitivesWritten, resultHandler, 1f, false);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -495,6 +495,11 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
|
|||
{
|
||||
clipRegionHeight = color.Height / samplesInY;
|
||||
}
|
||||
|
||||
if (!_context.Capabilities.SupportsBgraFormat)
|
||||
{
|
||||
_context.SupportBufferUpdater.SetRenderTargetIsBgra(index, color.Format.IsBgr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -539,7 +544,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
|
|||
|
||||
if (oldScale != _channel.TextureManager.RenderTargetScale)
|
||||
{
|
||||
_context.Renderer.Pipeline.SetRenderTargetScale(_channel.TextureManager.RenderTargetScale);
|
||||
_context.SupportBufferUpdater.SetRenderTargetScale(_channel.TextureManager.RenderTargetScale);
|
||||
|
||||
UpdateViewportTransform();
|
||||
UpdateScissorState();
|
||||
|
@ -758,9 +763,15 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
|
|||
}
|
||||
|
||||
_context.Renderer.Pipeline.SetDepthMode(GetDepthMode());
|
||||
_context.Renderer.Pipeline.SetViewports(viewports, disableTransform);
|
||||
_context.Renderer.Pipeline.SetViewports(viewports);
|
||||
|
||||
_currentSpecState.SetViewportTransformDisable(_state.State.ViewportTransformEnable == 0);
|
||||
_context.SupportBufferUpdater.SetViewportTransformDisable(
|
||||
viewports[0].Region.Width,
|
||||
viewports[0].Region.Height,
|
||||
_channel.TextureManager.RenderTargetScale,
|
||||
disableTransform);
|
||||
|
||||
_currentSpecState.SetViewportTransformDisable(disableTransform);
|
||||
_currentSpecState.SetDepthMode(GetDepthMode() == DepthMode.MinusOneToOne);
|
||||
}
|
||||
|
||||
|
|
|
@ -85,6 +85,11 @@ namespace Ryujinx.Graphics.Gpu
|
|||
/// </summary>
|
||||
internal ConcurrentDictionary<ulong, PhysicalMemory> PhysicalMemoryRegistry { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Support buffer updater.
|
||||
/// </summary>
|
||||
internal SupportBufferUpdater SupportBufferUpdater { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Host hardware capabilities.
|
||||
/// </summary>
|
||||
|
@ -125,6 +130,8 @@ namespace Ryujinx.Graphics.Gpu
|
|||
|
||||
PhysicalMemoryRegistry = new ConcurrentDictionary<ulong, PhysicalMemory>();
|
||||
|
||||
SupportBufferUpdater = new SupportBufferUpdater(renderer);
|
||||
|
||||
_firstTimestamp = ConvertNanosecondsToTicks((ulong)PerformanceCounter.ElapsedNanoseconds);
|
||||
}
|
||||
|
||||
|
@ -399,6 +406,8 @@ namespace Ryujinx.Graphics.Gpu
|
|||
physicalMemory.Dispose();
|
||||
}
|
||||
|
||||
SupportBufferUpdater.Dispose();
|
||||
|
||||
PhysicalMemoryRegistry.Clear();
|
||||
|
||||
RunDeferredActions();
|
||||
|
|
|
@ -278,7 +278,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||
Debug.Assert(!isView);
|
||||
|
||||
TextureCreateInfo createInfo = TextureCache.GetCreateInfo(Info, _context.Capabilities, ScaleFactor);
|
||||
HostTexture = _context.Renderer.CreateTexture(createInfo, ScaleFactor);
|
||||
HostTexture = _context.Renderer.CreateTexture(createInfo);
|
||||
|
||||
SynchronizeMemory(); // Load the data.
|
||||
if (ScaleMode == TextureScaleMode.Scaled)
|
||||
|
@ -302,7 +302,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||
}
|
||||
|
||||
TextureCreateInfo createInfo = TextureCache.GetCreateInfo(Info, _context.Capabilities, ScaleFactor);
|
||||
HostTexture = _context.Renderer.CreateTexture(createInfo, ScaleFactor);
|
||||
HostTexture = _context.Renderer.CreateTexture(createInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -490,7 +490,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||
if (storage == null)
|
||||
{
|
||||
TextureCreateInfo createInfo = TextureCache.GetCreateInfo(Info, _context.Capabilities, scale);
|
||||
storage = _context.Renderer.CreateTexture(createInfo, scale);
|
||||
storage = _context.Renderer.CreateTexture(createInfo);
|
||||
}
|
||||
|
||||
if (copy)
|
||||
|
|
|
@ -302,7 +302,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||
|
||||
_lastFragmentTotal = fragmentTotal;
|
||||
|
||||
_context.Renderer.Pipeline.UpdateRenderScale(_scales, total, fragmentTotal);
|
||||
_context.SupportBufferUpdater.UpdateRenderScale(_scales, total, fragmentTotal);
|
||||
|
||||
_scaleChanged = false;
|
||||
}
|
||||
|
|
|
@ -478,6 +478,8 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
|||
|
||||
// Force rebind after doing compute work.
|
||||
Rebind();
|
||||
|
||||
_context.SupportBufferUpdater.Commit();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -686,6 +688,8 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
|||
CommitBufferTextureBindings();
|
||||
|
||||
_rebind = false;
|
||||
|
||||
_context.SupportBufferUpdater.Commit();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
232
src/Ryujinx.Graphics.Gpu/Memory/SupportBufferUpdater.cs
Normal file
232
src/Ryujinx.Graphics.Gpu/Memory/SupportBufferUpdater.cs
Normal file
|
@ -0,0 +1,232 @@
|
|||
using Ryujinx.Graphics.GAL;
|
||||
using Ryujinx.Graphics.Shader;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.Graphics.Gpu.Memory
|
||||
{
|
||||
/// <summary>
|
||||
/// Support buffer data updater.
|
||||
/// </summary>
|
||||
class SupportBufferUpdater : IDisposable
|
||||
{
|
||||
private SupportBuffer _data;
|
||||
private BufferHandle _handle;
|
||||
|
||||
private readonly IRenderer _renderer;
|
||||
private int _startOffset = -1;
|
||||
private int _endOffset = -1;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the support buffer updater.
|
||||
/// </summary>
|
||||
/// <param name="renderer">Renderer that the support buffer will be used with</param>
|
||||
public SupportBufferUpdater(IRenderer renderer)
|
||||
{
|
||||
_renderer = renderer;
|
||||
|
||||
var defaultScale = new Vector4<float> { X = 1f, Y = 0f, Z = 0f, W = 0f };
|
||||
_data.RenderScale.AsSpan().Fill(defaultScale);
|
||||
DirtyRenderScale(0, SupportBuffer.RenderScaleMaxCount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mark a region of the support buffer as modified and needing to be sent to the GPU.
|
||||
/// </summary>
|
||||
/// <param name="startOffset">Start offset of the region in bytes</param>
|
||||
/// <param name="byteSize">Size of the region in bytes</param>
|
||||
private void MarkDirty(int startOffset, int byteSize)
|
||||
{
|
||||
int endOffset = startOffset + byteSize;
|
||||
|
||||
if (_startOffset == -1)
|
||||
{
|
||||
_startOffset = startOffset;
|
||||
_endOffset = endOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (startOffset < _startOffset)
|
||||
{
|
||||
_startOffset = startOffset;
|
||||
}
|
||||
|
||||
if (endOffset > _endOffset)
|
||||
{
|
||||
_endOffset = endOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks the fragment render scale count as being modified.
|
||||
/// </summary>
|
||||
private void DirtyFragmentRenderScaleCount()
|
||||
{
|
||||
MarkDirty(SupportBuffer.FragmentRenderScaleCountOffset, sizeof(int));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks data of a given type as being modified.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of the data</typeparam>
|
||||
/// <param name="baseOffset">Base offset of the data in bytes</param>
|
||||
/// <param name="offset">Index of the data, in elements</param>
|
||||
/// <param name="count">Number of elements</param>
|
||||
private void DirtyGenericField<T>(int baseOffset, int offset, int count) where T : unmanaged
|
||||
{
|
||||
int elemSize = Unsafe.SizeOf<T>();
|
||||
|
||||
MarkDirty(baseOffset + offset * elemSize, count * elemSize);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks render scales as being modified.
|
||||
/// </summary>
|
||||
/// <param name="offset">Index of the first scale that was modified</param>
|
||||
/// <param name="count">Number of modified scales</param>
|
||||
private void DirtyRenderScale(int offset, int count)
|
||||
{
|
||||
DirtyGenericField<Vector4<float>>(SupportBuffer.GraphicsRenderScaleOffset, offset, count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks render target BGRA format state as modified.
|
||||
/// </summary>
|
||||
/// <param name="offset">Index of the first render target that had its BGRA format modified</param>
|
||||
/// <param name="count">Number of render targets</param>
|
||||
private void DirtyFragmentIsBgra(int offset, int count)
|
||||
{
|
||||
DirtyGenericField<Vector4<int>>(SupportBuffer.FragmentIsBgraOffset, offset, count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the inverse viewport vector.
|
||||
/// </summary>
|
||||
/// <param name="data">Inverse viewport vector</param>
|
||||
private void UpdateViewportInverse(Vector4<float> data)
|
||||
{
|
||||
_data.ViewportInverse = data;
|
||||
|
||||
MarkDirty(SupportBuffer.ViewportInverseOffset, SupportBuffer.FieldSize);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the scale of all output render targets (they should all have the same scale).
|
||||
/// </summary>
|
||||
/// <param name="scale">Scale value</param>
|
||||
public void SetRenderTargetScale(float scale)
|
||||
{
|
||||
_data.RenderScale[0].X = scale;
|
||||
DirtyRenderScale(0, 1); // Just the first element.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the render scales for shader input textures or images.
|
||||
/// </summary>
|
||||
/// <param name="scales">Scale values</param>
|
||||
/// <param name="totalCount">Total number of scales across all stages</param>
|
||||
/// <param name="fragmentCount">Total number of scales on the fragment shader stage</param>
|
||||
public void UpdateRenderScale(ReadOnlySpan<float> scales, int totalCount, int fragmentCount)
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
for (int index = 0; index < totalCount; index++)
|
||||
{
|
||||
if (_data.RenderScale[1 + index].X != scales[index])
|
||||
{
|
||||
_data.RenderScale[1 + index].X = scales[index];
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Only update fragment count if there are scales after it for the vertex stage.
|
||||
if (fragmentCount != totalCount && fragmentCount != _data.FragmentRenderScaleCount.X)
|
||||
{
|
||||
_data.FragmentRenderScaleCount.X = fragmentCount;
|
||||
DirtyFragmentRenderScaleCount();
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
DirtyRenderScale(0, 1 + totalCount);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether the format of a given render target is a BGRA format.
|
||||
/// </summary>
|
||||
/// <param name="index">Render target index</param>
|
||||
/// <param name="isBgra">True if the format is BGRA< false otherwise</param>
|
||||
public void SetRenderTargetIsBgra(int index, bool isBgra)
|
||||
{
|
||||
bool isBgraChanged = (_data.FragmentIsBgra[index].X != 0) != isBgra;
|
||||
|
||||
if (isBgraChanged)
|
||||
{
|
||||
_data.FragmentIsBgra[index].X = isBgra ? 1 : 0;
|
||||
DirtyFragmentIsBgra(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether a viewport has transform disabled.
|
||||
/// </summary>
|
||||
/// <param name="viewportWidth">Value used as viewport width</param>
|
||||
/// <param name="viewportHeight">Value used as viewport height</param>
|
||||
/// <param name="scale">Render target scale</param>
|
||||
/// <param name="disableTransform">True if transform is disabled, false otherwise</param>
|
||||
public void SetViewportTransformDisable(float viewportWidth, float viewportHeight, float scale, bool disableTransform)
|
||||
{
|
||||
float disableTransformF = disableTransform ? 1.0f : 0.0f;
|
||||
if (_data.ViewportInverse.W != disableTransformF || disableTransform)
|
||||
{
|
||||
UpdateViewportInverse(new Vector4<float>
|
||||
{
|
||||
X = scale * 2f / viewportWidth,
|
||||
Y = scale * 2f / viewportHeight,
|
||||
Z = 1,
|
||||
W = disableTransformF
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Submits all pending buffer updates to the GPU.
|
||||
/// </summary>
|
||||
public void Commit()
|
||||
{
|
||||
if (_startOffset != -1)
|
||||
{
|
||||
if (_handle == BufferHandle.Null)
|
||||
{
|
||||
_handle = _renderer.CreateBuffer(SupportBuffer.RequiredSize);
|
||||
_renderer.Pipeline.ClearBuffer(_handle, 0, SupportBuffer.RequiredSize, 0);
|
||||
|
||||
var range = new BufferRange(_handle, 0, SupportBuffer.RequiredSize);
|
||||
_renderer.Pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(0, range) });
|
||||
}
|
||||
|
||||
ReadOnlySpan<byte> data = MemoryMarshal.Cast<SupportBuffer, byte>(MemoryMarshal.CreateSpan(ref _data, 1));
|
||||
|
||||
_renderer.SetBufferData(_handle, _startOffset, data.Slice(_startOffset, _endOffset - _startOffset));
|
||||
|
||||
_startOffset = -1;
|
||||
_endOffset = -1;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Destroys the support buffer.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
if (_handle != BufferHandle.Null)
|
||||
{
|
||||
_renderer.DeleteBuffer(_handle);
|
||||
_handle = BufferHandle.Null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -58,6 +58,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||
}
|
||||
|
||||
AddDescriptor(SupportBufferStages, ResourceType.UniformBuffer, UniformSetIndex, 0, 1);
|
||||
AddUsage(SupportBufferStages, ResourceType.UniformBuffer, ResourceAccess.Read, UniformSetIndex, 0, 1);
|
||||
|
||||
_reservedConstantBuffers = 1; // For the support buffer.
|
||||
|
||||
|
|
|
@ -208,7 +208,16 @@ namespace Ryujinx.Graphics.Gpu
|
|||
|
||||
texture.SynchronizeMemory();
|
||||
|
||||
ImageCrop crop = pt.Crop;
|
||||
ImageCrop crop = new ImageCrop(
|
||||
(int)(pt.Crop.Left * texture.ScaleFactor),
|
||||
(int)MathF.Ceiling(pt.Crop.Right * texture.ScaleFactor),
|
||||
(int)(pt.Crop.Top * texture.ScaleFactor),
|
||||
(int)MathF.Ceiling(pt.Crop.Bottom * texture.ScaleFactor),
|
||||
pt.Crop.FlipX,
|
||||
pt.Crop.FlipY,
|
||||
pt.Crop.IsStretched,
|
||||
pt.Crop.AspectRatioX,
|
||||
pt.Crop.AspectRatioY);
|
||||
|
||||
if (texture.Info.Width > pt.Info.Width || texture.Info.Height > pt.Info.Height)
|
||||
{
|
||||
|
|
|
@ -114,7 +114,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects
|
|||
originalInfo.SwizzleB,
|
||||
originalInfo.SwizzleA);
|
||||
|
||||
_intermediaryTexture = new TextureStorage(_renderer, info, view.ScaleFactor);
|
||||
_intermediaryTexture = new TextureStorage(_renderer, info);
|
||||
_intermediaryTexture.CreateDefaultView();
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects
|
|||
if (_textureStorage == null || _textureStorage.Info.Width != view.Width || _textureStorage.Info.Height != view.Height)
|
||||
{
|
||||
_textureStorage?.Dispose();
|
||||
_textureStorage = new TextureStorage(_renderer, view.Info, view.ScaleFactor);
|
||||
_textureStorage = new TextureStorage(_renderer, view.Info);
|
||||
_textureStorage.CreateDefaultView();
|
||||
}
|
||||
|
||||
|
|
|
@ -147,8 +147,8 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa
|
|||
SwizzleComponent.Blue,
|
||||
SwizzleComponent.Alpha);
|
||||
|
||||
_areaTexture = new TextureStorage(_renderer, areaInfo, 1);
|
||||
_searchTexture = new TextureStorage(_renderer, searchInfo, 1);
|
||||
_areaTexture = new TextureStorage(_renderer, areaInfo);
|
||||
_searchTexture = new TextureStorage(_renderer, searchInfo);
|
||||
|
||||
var areaTexture = EmbeddedResources.Read("Ryujinx.Graphics.OpenGL/Effects/Textures/SmaaAreaTexture.bin");
|
||||
var searchTexture = EmbeddedResources.Read("Ryujinx.Graphics.OpenGL/Effects/Textures/SmaaSearchTexture.bin");
|
||||
|
@ -165,11 +165,11 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa
|
|||
if (_outputTexture == null || _outputTexture.Info.Width != view.Width || _outputTexture.Info.Height != view.Height)
|
||||
{
|
||||
_outputTexture?.Dispose();
|
||||
_outputTexture = new TextureStorage(_renderer, view.Info, view.ScaleFactor);
|
||||
_outputTexture = new TextureStorage(_renderer, view.Info);
|
||||
_outputTexture.CreateDefaultView();
|
||||
_edgeOutputTexture = new TextureStorage(_renderer, view.Info, view.ScaleFactor);
|
||||
_edgeOutputTexture = new TextureStorage(_renderer, view.Info);
|
||||
_edgeOutputTexture.CreateDefaultView();
|
||||
_blendOutputTexture = new TextureStorage(_renderer, view.Info, view.ScaleFactor);
|
||||
_blendOutputTexture = new TextureStorage(_renderer, view.Info);
|
||||
_blendOutputTexture.CreateDefaultView();
|
||||
|
||||
DeleteShaders();
|
||||
|
|
|
@ -87,7 +87,7 @@ namespace Ryujinx.Graphics.OpenGL.Image
|
|||
SwizzleComponent.Red,
|
||||
SwizzleComponent.Green,
|
||||
SwizzleComponent.Blue,
|
||||
SwizzleComponent.Alpha), 1f);
|
||||
SwizzleComponent.Alpha));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
|
|
@ -11,15 +11,13 @@ namespace Ryujinx.Graphics.OpenGL.Image
|
|||
|
||||
public int Width => Info.Width;
|
||||
public int Height => Info.Height;
|
||||
public float ScaleFactor { get; }
|
||||
|
||||
public Target Target => Info.Target;
|
||||
public Format Format => Info.Format;
|
||||
|
||||
public TextureBase(TextureCreateInfo info, float scaleFactor = 1f)
|
||||
public TextureBase(TextureCreateInfo info)
|
||||
{
|
||||
Info = info;
|
||||
ScaleFactor = scaleFactor;
|
||||
|
||||
Handle = GL.GenTexture();
|
||||
}
|
||||
|
|
|
@ -349,7 +349,7 @@ namespace Ryujinx.Graphics.OpenGL.Image
|
|||
|
||||
public TextureView BgraSwap(TextureView from)
|
||||
{
|
||||
TextureView to = (TextureView)_renderer.CreateTexture(from.Info, from.ScaleFactor);
|
||||
TextureView to = (TextureView)_renderer.CreateTexture(from.Info);
|
||||
|
||||
EnsurePbo(from);
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ namespace Ryujinx.Graphics.OpenGL.Image
|
|||
{
|
||||
public ITextureInfo Storage => this;
|
||||
public int Handle { get; private set; }
|
||||
public float ScaleFactor { get; private set; }
|
||||
|
||||
public TextureCreateInfo Info { get; }
|
||||
|
||||
|
@ -18,13 +17,12 @@ namespace Ryujinx.Graphics.OpenGL.Image
|
|||
|
||||
internal ITexture DefaultView { get; private set; }
|
||||
|
||||
public TextureStorage(OpenGLRenderer renderer, TextureCreateInfo info, float scaleFactor)
|
||||
public TextureStorage(OpenGLRenderer renderer, TextureCreateInfo info)
|
||||
{
|
||||
_renderer = renderer;
|
||||
Info = info;
|
||||
|
||||
Handle = GL.GenTexture();
|
||||
ScaleFactor = scaleFactor;
|
||||
|
||||
CreateImmutableStorage();
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace Ryujinx.Graphics.OpenGL.Image
|
|||
TextureStorage parent,
|
||||
TextureCreateInfo info,
|
||||
int firstLayer,
|
||||
int firstLevel) : base(info, parent.ScaleFactor)
|
||||
int firstLevel) : base(info)
|
||||
{
|
||||
_renderer = renderer;
|
||||
_parent = parent;
|
||||
|
|
|
@ -95,7 +95,7 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
return new Sampler(info);
|
||||
}
|
||||
|
||||
public ITexture CreateTexture(TextureCreateInfo info, float scaleFactor)
|
||||
public ITexture CreateTexture(TextureCreateInfo info)
|
||||
{
|
||||
if (info.Target == Target.TextureBuffer)
|
||||
{
|
||||
|
@ -103,7 +103,7 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
}
|
||||
else
|
||||
{
|
||||
return ResourcePool.GetTextureOrNull(info, scaleFactor) ?? new TextureStorage(this, info, scaleFactor).CreateDefaultView();
|
||||
return ResourcePool.GetTextureOrNull(info) ?? new TextureStorage(this, info).CreateDefaultView();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -194,9 +194,9 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
ResourcePool.Tick();
|
||||
}
|
||||
|
||||
public ICounterEvent ReportCounter(CounterType type, EventHandler<ulong> resultHandler, bool hostReserved)
|
||||
public ICounterEvent ReportCounter(CounterType type, EventHandler<ulong> resultHandler, float divisor, bool hostReserved)
|
||||
{
|
||||
return _counters.QueueReport(type, resultHandler, _pipeline.DrawCount, hostReserved);
|
||||
return _counters.QueueReport(type, resultHandler, divisor, _pipeline.DrawCount, hostReserved);
|
||||
}
|
||||
|
||||
public void Initialize(GraphicsDebugLevel glLogLevel)
|
||||
|
@ -210,7 +210,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
GL.Arb.MaxShaderCompilerThreads(Math.Min(Environment.ProcessorCount, 8));
|
||||
}
|
||||
|
||||
_pipeline.Initialize(this);
|
||||
_counters.Initialize(_pipeline);
|
||||
|
||||
// This is required to disable [0, 1] clamping for SNorm outputs on compatibility profiles.
|
||||
|
|
|
@ -44,9 +44,7 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
|
||||
private CounterQueueEvent _activeConditionalRender;
|
||||
|
||||
private readonly Vector4<int>[] _fpIsBgra = new Vector4<int>[SupportBuffer.FragmentIsBgraCount];
|
||||
private readonly Vector4<float>[] _renderScale = new Vector4<float>[73];
|
||||
private int _fragmentScaleCount;
|
||||
private Vector4<int>[] _fpIsBgra = new Vector4<int>[SupportBuffer.FragmentIsBgraCount];
|
||||
|
||||
private readonly (TextureBase, Format)[] _images;
|
||||
private TextureBase _unit0Texture;
|
||||
|
@ -66,7 +64,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
private bool _tfEnabled;
|
||||
private TransformFeedbackPrimitiveType _tfTopology;
|
||||
|
||||
private SupportBufferUpdater _supportBuffer;
|
||||
private readonly BufferHandle[] _tfbs;
|
||||
private readonly BufferRange[] _tfbTargets;
|
||||
|
||||
|
@ -84,22 +81,10 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
|
||||
_images = new (TextureBase, Format)[SavedImages];
|
||||
|
||||
var defaultScale = new Vector4<float> { X = 1f, Y = 0f, Z = 0f, W = 0f };
|
||||
new Span<Vector4<float>>(_renderScale).Fill(defaultScale);
|
||||
|
||||
_tfbs = new BufferHandle[Constants.MaxTransformFeedbackBuffers];
|
||||
_tfbTargets = new BufferRange[Constants.MaxTransformFeedbackBuffers];
|
||||
}
|
||||
|
||||
public void Initialize(OpenGLRenderer renderer)
|
||||
{
|
||||
_supportBuffer = new SupportBufferUpdater(renderer);
|
||||
GL.BindBufferBase(BufferRangeTarget.UniformBuffer, 0, Unsafe.As<BufferHandle, int>(ref _supportBuffer.Handle));
|
||||
|
||||
_supportBuffer.UpdateFragmentIsBgra(_fpIsBgra, 0, SupportBuffer.FragmentIsBgraCount);
|
||||
_supportBuffer.UpdateRenderScale(_renderScale, 0, SupportBuffer.RenderScaleMaxCount);
|
||||
}
|
||||
|
||||
public void Barrier()
|
||||
{
|
||||
GL.MemoryBarrier(MemoryBarrierFlags.AllBarrierBits);
|
||||
|
@ -684,8 +669,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
{
|
||||
if (texture is TextureView view && sampler is Sampler samp)
|
||||
{
|
||||
_supportBuffer.Commit();
|
||||
|
||||
if (HwCapabilities.SupportsDrawTexture)
|
||||
{
|
||||
GL.NV.DrawTexture(
|
||||
|
@ -777,16 +760,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
_tfEnabled = false;
|
||||
}
|
||||
|
||||
public double GetCounterDivisor(CounterType type)
|
||||
{
|
||||
if (type == CounterType.SamplesPassed)
|
||||
{
|
||||
return _renderScale[0].X * _renderScale[0].X;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void SetAlphaTest(bool enable, float reference, CompareOp op)
|
||||
{
|
||||
if (!enable)
|
||||
|
@ -1172,12 +1145,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
_rasterizerDiscard = discard;
|
||||
}
|
||||
|
||||
public void SetRenderTargetScale(float scale)
|
||||
{
|
||||
_renderScale[0].X = scale;
|
||||
_supportBuffer.UpdateRenderScale(_renderScale, 0, 1); // Just the first element.
|
||||
}
|
||||
|
||||
public void SetRenderTargetColorMasks(ReadOnlySpan<uint> componentMasks)
|
||||
{
|
||||
_componentMasks = 0;
|
||||
|
@ -1194,8 +1161,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
{
|
||||
EnsureFramebuffer();
|
||||
|
||||
bool isBgraChanged = false;
|
||||
|
||||
for (int index = 0; index < colors.Length; index++)
|
||||
{
|
||||
TextureView color = (TextureView)colors[index];
|
||||
|
@ -1209,18 +1174,12 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
if (_fpIsBgra[index].X != isBgra)
|
||||
{
|
||||
_fpIsBgra[index].X = isBgra;
|
||||
isBgraChanged = true;
|
||||
|
||||
RestoreComponentMask(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isBgraChanged)
|
||||
{
|
||||
_supportBuffer.UpdateFragmentIsBgra(_fpIsBgra, 0, SupportBuffer.FragmentIsBgraCount);
|
||||
}
|
||||
|
||||
TextureView depthStencilView = (TextureView)depthStencil;
|
||||
|
||||
_framebuffer.AttachDepthStencil(depthStencilView);
|
||||
|
@ -1411,7 +1370,7 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
_vertexArray.SetVertexBuffers(vertexBuffers);
|
||||
}
|
||||
|
||||
public void SetViewports(ReadOnlySpan<Viewport> viewports, bool disableTransform)
|
||||
public void SetViewports(ReadOnlySpan<Viewport> viewports)
|
||||
{
|
||||
Array.Resize(ref _viewportArray, viewports.Length * 4);
|
||||
Array.Resize(ref _depthRangeArray, viewports.Length * 2);
|
||||
|
@ -1450,19 +1409,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
|
||||
GL.ViewportArray(0, viewports.Length, viewportArray);
|
||||
GL.DepthRangeArray(0, viewports.Length, depthRangeArray);
|
||||
|
||||
float disableTransformF = disableTransform ? 1.0f : 0.0f;
|
||||
if (_supportBuffer.Data.ViewportInverse.W != disableTransformF || disableTransform)
|
||||
{
|
||||
float scale = _renderScale[0].X;
|
||||
_supportBuffer.UpdateViewportInverse(new Vector4<float>
|
||||
{
|
||||
X = scale * 2f / viewports[0].Region.Width,
|
||||
Y = scale * 2f / viewports[0].Region.Height,
|
||||
Z = 1,
|
||||
W = disableTransformF
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void TextureBarrier()
|
||||
|
@ -1552,36 +1498,9 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
return (_boundDrawFramebuffer, _boundReadFramebuffer);
|
||||
}
|
||||
|
||||
public void UpdateRenderScale(ReadOnlySpan<float> scales, int totalCount, int fragmentCount)
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
for (int index = 0; index < totalCount; index++)
|
||||
{
|
||||
if (_renderScale[1 + index].X != scales[index])
|
||||
{
|
||||
_renderScale[1 + index].X = scales[index];
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Only update fragment count if there are scales after it for the vertex stage.
|
||||
if (fragmentCount != totalCount && fragmentCount != _fragmentScaleCount)
|
||||
{
|
||||
_fragmentScaleCount = fragmentCount;
|
||||
_supportBuffer.UpdateFragmentRenderScaleCount(_fragmentScaleCount);
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
_supportBuffer.UpdateRenderScale(_renderScale, 0, 1 + totalCount);
|
||||
}
|
||||
}
|
||||
|
||||
private void PrepareForDispatch()
|
||||
{
|
||||
_unit0Texture?.Bind(0);
|
||||
_supportBuffer.Commit();
|
||||
}
|
||||
|
||||
private void PreDraw(int vertexCount)
|
||||
|
@ -1601,7 +1520,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
DrawCount++;
|
||||
|
||||
_unit0Texture?.Bind(0);
|
||||
_supportBuffer.Commit();
|
||||
}
|
||||
|
||||
private void PostDraw()
|
||||
|
@ -1752,8 +1670,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
|
||||
public void Dispose()
|
||||
{
|
||||
_supportBuffer?.Dispose();
|
||||
|
||||
for (int i = 0; i < Constants.MaxTransformFeedbackBuffers; i++)
|
||||
{
|
||||
if (_tfbs[i] != BufferHandle.Null)
|
||||
|
|
|
@ -107,7 +107,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries
|
|||
}
|
||||
}
|
||||
|
||||
public CounterQueueEvent QueueReport(EventHandler<ulong> resultHandler, ulong lastDrawIndex, bool hostReserved)
|
||||
public CounterQueueEvent QueueReport(EventHandler<ulong> resultHandler, float divisor, ulong lastDrawIndex, bool hostReserved)
|
||||
{
|
||||
CounterQueueEvent result;
|
||||
ulong draws = lastDrawIndex - _current.DrawIndex;
|
||||
|
@ -123,7 +123,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries
|
|||
_current.ReserveForHostAccess();
|
||||
}
|
||||
|
||||
_current.Complete(draws > 0, _pipeline.GetCounterDivisor(Type));
|
||||
_current.Complete(draws > 0, divisor);
|
||||
_events.Enqueue(_current);
|
||||
|
||||
_current.OnResult += resultHandler;
|
||||
|
|
|
@ -23,9 +23,9 @@ namespace Ryujinx.Graphics.OpenGL.Queries
|
|||
}
|
||||
}
|
||||
|
||||
public CounterQueueEvent QueueReport(CounterType type, EventHandler<ulong> resultHandler, ulong lastDrawIndex, bool hostReserved)
|
||||
public CounterQueueEvent QueueReport(CounterType type, EventHandler<ulong> resultHandler, float divisor, ulong lastDrawIndex, bool hostReserved)
|
||||
{
|
||||
return _counterQueues[(int)type].QueueReport(resultHandler, lastDrawIndex, hostReserved);
|
||||
return _counterQueues[(int)type].QueueReport(resultHandler, divisor, lastDrawIndex, hostReserved);
|
||||
}
|
||||
|
||||
public void QueueReset(CounterType type)
|
||||
|
|
|
@ -9,7 +9,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
{
|
||||
public TextureCreateInfo Info;
|
||||
public TextureView View;
|
||||
public float ScaleFactor;
|
||||
public int RemainingFrames;
|
||||
}
|
||||
|
||||
|
@ -42,7 +41,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
{
|
||||
Info = view.Info,
|
||||
View = view,
|
||||
ScaleFactor = view.ScaleFactor,
|
||||
RemainingFrames = DisposedLiveFrames
|
||||
});
|
||||
}
|
||||
|
@ -52,9 +50,8 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
/// Attempt to obtain a texture from the resource cache with the desired parameters.
|
||||
/// </summary>
|
||||
/// <param name="info">The creation info for the desired texture</param>
|
||||
/// <param name="scaleFactor">The scale factor for the desired texture</param>
|
||||
/// <returns>A TextureView with the description specified, or null if one was not found.</returns>
|
||||
public TextureView GetTextureOrNull(TextureCreateInfo info, float scaleFactor)
|
||||
public TextureView GetTextureOrNull(TextureCreateInfo info)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
|
@ -65,11 +62,8 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
|
||||
foreach (DisposedTexture texture in list)
|
||||
{
|
||||
if (scaleFactor == texture.ScaleFactor)
|
||||
{
|
||||
list.Remove(texture);
|
||||
return texture.View;
|
||||
}
|
||||
list.Remove(texture);
|
||||
return texture.View;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -111,12 +111,11 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
GL.Clear(ClearBufferMask.ColorBufferBit);
|
||||
|
||||
int srcX0, srcX1, srcY0, srcY1;
|
||||
float scale = viewConverted.ScaleFactor;
|
||||
|
||||
if (crop.Left == 0 && crop.Right == 0)
|
||||
{
|
||||
srcX0 = 0;
|
||||
srcX1 = (int)(viewConverted.Width / scale);
|
||||
srcX1 = viewConverted.Width;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -127,7 +126,7 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
if (crop.Top == 0 && crop.Bottom == 0)
|
||||
{
|
||||
srcY0 = 0;
|
||||
srcY1 = (int)(viewConverted.Height / scale);
|
||||
srcY1 = viewConverted.Height;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -135,14 +134,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
srcY1 = crop.Bottom;
|
||||
}
|
||||
|
||||
if (scale != 1f)
|
||||
{
|
||||
srcX0 = (int)(srcX0 * scale);
|
||||
srcY0 = (int)(srcY0 * scale);
|
||||
srcX1 = (int)Math.Ceiling(srcX1 * scale);
|
||||
srcY1 = (int)Math.Ceiling(srcY1 * scale);
|
||||
}
|
||||
|
||||
float ratioX = crop.IsStretched ? 1.0f : MathF.Min(1.0f, _height * crop.AspectRatioX / (_width * crop.AspectRatioY));
|
||||
float ratioY = crop.IsStretched ? 1.0f : MathF.Min(1.0f, _width * crop.AspectRatioY / (_height * crop.AspectRatioX));
|
||||
|
||||
|
@ -408,7 +399,7 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
SwizzleComponent.Alpha);
|
||||
|
||||
_isBgra = forceBgra;
|
||||
_upscaledTexture = _renderer.CreateTexture(info, 1) as TextureView;
|
||||
_upscaledTexture = _renderer.CreateTexture(info) as TextureView;
|
||||
}
|
||||
|
||||
public void SetScalingFilterLevel(float level)
|
||||
|
|
|
@ -35,7 +35,6 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
|
||||
private readonly bool[] _uniformSet;
|
||||
private readonly bool[] _storageSet;
|
||||
private Buffer _cachedSupportBuffer;
|
||||
|
||||
[Flags]
|
||||
private enum DirtyFlags
|
||||
|
@ -115,7 +114,7 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
SwizzleComponent.Red,
|
||||
SwizzleComponent.Green,
|
||||
SwizzleComponent.Blue,
|
||||
SwizzleComponent.Alpha), 1f);
|
||||
SwizzleComponent.Alpha));
|
||||
|
||||
_dummySampler = (SamplerHolder)gd.CreateSampler(new SamplerCreateInfo(
|
||||
MinFilter.Nearest,
|
||||
|
@ -392,26 +391,6 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
{
|
||||
Initialize(cbs, setIndex, dsc);
|
||||
}
|
||||
|
||||
if (setIndex == PipelineBase.UniformSetIndex)
|
||||
{
|
||||
Span<DescriptorBufferInfo> uniformBuffer = stackalloc DescriptorBufferInfo[1];
|
||||
|
||||
if (!_uniformSet[0])
|
||||
{
|
||||
_cachedSupportBuffer = _gd.BufferManager.GetBuffer(cbs.CommandBuffer, _pipeline.SupportBufferUpdater.Handle, false).Get(cbs, 0, SupportBuffer.RequiredSize).Value;
|
||||
_uniformSet[0] = true;
|
||||
}
|
||||
|
||||
uniformBuffer[0] = new DescriptorBufferInfo
|
||||
{
|
||||
Offset = 0,
|
||||
Range = (ulong)SupportBuffer.RequiredSize,
|
||||
Buffer = _cachedSupportBuffer,
|
||||
};
|
||||
|
||||
dsc.UpdateBuffers(0, 0, uniformBuffer, DescriptorType.UniformBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (ResourceBindingSegment segment in bindingSegments)
|
||||
|
@ -553,22 +532,6 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void UpdateAndBindUniformBufferPd(CommandBufferScoped cbs, PipelineBindPoint pbp)
|
||||
{
|
||||
if (!_uniformSet[0])
|
||||
{
|
||||
Span<DescriptorBufferInfo> uniformBuffer = stackalloc DescriptorBufferInfo[1];
|
||||
|
||||
uniformBuffer[0] = new DescriptorBufferInfo
|
||||
{
|
||||
Offset = 0,
|
||||
Range = (ulong)SupportBuffer.RequiredSize,
|
||||
Buffer = _gd.BufferManager.GetBuffer(cbs.CommandBuffer, _pipeline.SupportBufferUpdater.Handle, false).Get(cbs, 0, SupportBuffer.RequiredSize).Value,
|
||||
};
|
||||
|
||||
_uniformSet[0] = true;
|
||||
|
||||
UpdateBuffers(cbs, pbp, 0, uniformBuffer, DescriptorType.UniformBuffer);
|
||||
}
|
||||
|
||||
var bindingSegments = _program.BindingSegments[PipelineBase.UniformSetIndex];
|
||||
var dummyBuffer = _dummyBuffer?.GetBuffer();
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ namespace Ryujinx.Graphics.Vulkan.Effects
|
|||
originalInfo.SwizzleB,
|
||||
originalInfo.SwizzleA);
|
||||
_intermediaryTexture?.Dispose();
|
||||
_intermediaryTexture = _renderer.CreateTexture(info, view.ScaleFactor) as TextureView;
|
||||
_intermediaryTexture = _renderer.CreateTexture(info) as TextureView;
|
||||
}
|
||||
|
||||
_pipeline.SetCommandBuffer(cbs);
|
||||
|
|
|
@ -57,7 +57,7 @@ namespace Ryujinx.Graphics.Vulkan.Effects
|
|||
if (_texture == null || _texture.Width != view.Width || _texture.Height != view.Height)
|
||||
{
|
||||
_texture?.Dispose();
|
||||
_texture = _renderer.CreateTexture(view.Info, view.ScaleFactor) as TextureView;
|
||||
_texture = _renderer.CreateTexture(view.Info) as TextureView;
|
||||
}
|
||||
|
||||
_pipeline.SetCommandBuffer(cbs);
|
||||
|
|
|
@ -177,8 +177,8 @@ namespace Ryujinx.Graphics.Vulkan.Effects
|
|||
var areaTexture = EmbeddedResources.Read("Ryujinx.Graphics.Vulkan/Effects/Textures/SmaaAreaTexture.bin");
|
||||
var searchTexture = EmbeddedResources.Read("Ryujinx.Graphics.Vulkan/Effects/Textures/SmaaSearchTexture.bin");
|
||||
|
||||
_areaTexture = _renderer.CreateTexture(areaInfo, 1) as TextureView;
|
||||
_searchTexture = _renderer.CreateTexture(searchInfo, 1) as TextureView;
|
||||
_areaTexture = _renderer.CreateTexture(areaInfo) as TextureView;
|
||||
_searchTexture = _renderer.CreateTexture(searchInfo) as TextureView;
|
||||
|
||||
_areaTexture.SetData(areaTexture);
|
||||
_searchTexture.SetData(searchTexture);
|
||||
|
@ -193,9 +193,9 @@ namespace Ryujinx.Graphics.Vulkan.Effects
|
|||
_edgeOutputTexture?.Dispose();
|
||||
_blendOutputTexture?.Dispose();
|
||||
|
||||
_outputTexture = _renderer.CreateTexture(view.Info, view.ScaleFactor) as TextureView;
|
||||
_edgeOutputTexture = _renderer.CreateTexture(view.Info, view.ScaleFactor) as TextureView;
|
||||
_blendOutputTexture = _renderer.CreateTexture(view.Info, view.ScaleFactor) as TextureView;
|
||||
_outputTexture = _renderer.CreateTexture(view.Info) as TextureView;
|
||||
_edgeOutputTexture = _renderer.CreateTexture(view.Info) as TextureView;
|
||||
_blendOutputTexture = _renderer.CreateTexture(view.Info) as TextureView;
|
||||
}
|
||||
|
||||
_pipeline.SetCommandBuffer(cbs);
|
||||
|
|
|
@ -470,7 +470,7 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
_pipeline.ClearRenderTargetColor(0, 0, 1, new ColorF(0f, 0f, 0f, 1f));
|
||||
}
|
||||
|
||||
_pipeline.SetViewports(viewports, false);
|
||||
_pipeline.SetViewports(viewports);
|
||||
_pipeline.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);
|
||||
_pipeline.Draw(4, 1, 0, 0);
|
||||
|
||||
|
@ -546,7 +546,7 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
|
||||
_pipeline.SetRenderTarget(dst, (uint)dstWidth, (uint)dstHeight, (uint)dstSamples, true, dstFormat);
|
||||
_pipeline.SetScissors(scissors);
|
||||
_pipeline.SetViewports(viewports, false);
|
||||
_pipeline.SetViewports(viewports);
|
||||
_pipeline.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);
|
||||
|
||||
var aspectFlags = src.Info.Format.ConvertAspectFlags();
|
||||
|
@ -710,7 +710,7 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
_pipeline.SetProgram(program);
|
||||
_pipeline.SetRenderTarget(dst, (uint)dstWidth, (uint)dstHeight, false, dstFormat);
|
||||
_pipeline.SetRenderTargetColorMasks(new[] { componentMask });
|
||||
_pipeline.SetViewports(viewports, false);
|
||||
_pipeline.SetViewports(viewports);
|
||||
_pipeline.SetScissors(scissors);
|
||||
_pipeline.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);
|
||||
_pipeline.Draw(4, 1, 0, 0);
|
||||
|
@ -774,7 +774,7 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
Span<Rectangle<int>> scissors = stackalloc Rectangle<int>[1];
|
||||
|
||||
pipeline.SetProgram(_programColorBlit);
|
||||
pipeline.SetViewports(viewports, false);
|
||||
pipeline.SetViewports(viewports);
|
||||
pipeline.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);
|
||||
pipeline.Draw(4, 1, 0, 0);
|
||||
|
||||
|
@ -1117,7 +1117,7 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
scissors[0] = new Rectangle<int>(0, 0, dst.Width, dst.Height);
|
||||
|
||||
_pipeline.SetScissors(scissors);
|
||||
_pipeline.SetViewports(viewports, false);
|
||||
_pipeline.SetViewports(viewports);
|
||||
_pipeline.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);
|
||||
|
||||
for (int z = 0; z < depth; z++)
|
||||
|
@ -1250,7 +1250,7 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
|
||||
_pipeline.SetRenderTargetColorMasks(new uint[] { 0xf });
|
||||
_pipeline.SetScissors(scissors);
|
||||
_pipeline.SetViewports(viewports, false);
|
||||
_pipeline.SetViewports(viewports);
|
||||
_pipeline.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);
|
||||
|
||||
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(0, new BufferRange(bufferHandle, 0, ParamsBufferSize)) });
|
||||
|
|
|
@ -50,9 +50,6 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
|
||||
private ShaderCollection _program;
|
||||
|
||||
private readonly Vector4<float>[] _renderScale = new Vector4<float>[73];
|
||||
private int _fragmentScaleCount;
|
||||
|
||||
protected FramebufferParams FramebufferParams;
|
||||
private Auto<DisposableFramebuffer> _framebuffer;
|
||||
private Auto<DisposableRenderPass> _renderPass;
|
||||
|
@ -74,7 +71,6 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
|
||||
private readonly VertexBufferUpdater _vertexBufferUpdater;
|
||||
|
||||
public SupportBufferUpdater SupportBufferUpdater;
|
||||
public IndexBufferPattern QuadsToTrisPattern;
|
||||
public IndexBufferPattern TriFanToTrisPattern;
|
||||
|
||||
|
@ -119,9 +115,6 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
|
||||
ClearScissor = new Rectangle<int>(0, 0, 0xffff, 0xffff);
|
||||
|
||||
var defaultScale = new Vector4<float> { X = 1f, Y = 0f, Z = 0f, W = 0f };
|
||||
new Span<Vector4<float>>(_renderScale).Fill(defaultScale);
|
||||
|
||||
_storedBlend = new PipelineColorBlendAttachmentState[Constants.MaxRenderTargets];
|
||||
|
||||
_newState.Initialize();
|
||||
|
@ -131,9 +124,6 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
{
|
||||
_descriptorSetUpdater.Initialize();
|
||||
|
||||
SupportBufferUpdater = new SupportBufferUpdater(Gd);
|
||||
SupportBufferUpdater.UpdateRenderScale(_renderScale, 0, SupportBuffer.RenderScaleMaxCount);
|
||||
|
||||
QuadsToTrisPattern = new IndexBufferPattern(Gd, 4, 6, 0, new[] { 0, 1, 2, 0, 2, 3 }, 4, false);
|
||||
TriFanToTrisPattern = new IndexBufferPattern(Gd, 3, 3, 2, new[] { int.MinValue, -1, 0 }, 1, true);
|
||||
}
|
||||
|
@ -666,8 +656,6 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
{
|
||||
if (texture is TextureView srcTexture)
|
||||
{
|
||||
SupportBufferUpdater.Commit();
|
||||
|
||||
var oldCullMode = _newState.CullMode;
|
||||
var oldStencilTestEnable = _newState.StencilTestEnable;
|
||||
var oldDepthTestEnable = _newState.DepthTestEnable;
|
||||
|
@ -709,16 +697,6 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
_tfEnabled = false;
|
||||
}
|
||||
|
||||
public double GetCounterDivisor(CounterType type)
|
||||
{
|
||||
if (type == CounterType.SamplesPassed)
|
||||
{
|
||||
return _renderScale[0].X * _renderScale[0].X;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
public bool IsCommandBufferActive(CommandBuffer cb)
|
||||
{
|
||||
return CommandBuffer.Handle == cb.Handle;
|
||||
|
@ -1050,12 +1028,6 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
SetRenderTargetsInternal(colors, depthStencil, Gd.IsTBDR);
|
||||
}
|
||||
|
||||
public void SetRenderTargetScale(float scale)
|
||||
{
|
||||
_renderScale[0].X = scale;
|
||||
SupportBufferUpdater.UpdateRenderScale(_renderScale, 0, 1); // Just the first element.
|
||||
}
|
||||
|
||||
public void SetScissors(ReadOnlySpan<Rectangle<int>> regions)
|
||||
{
|
||||
int maxScissors = Gd.Capabilities.SupportsMultiView ? Constants.MaxViewports : 1;
|
||||
|
@ -1303,7 +1275,7 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
SignalStateChange();
|
||||
}
|
||||
|
||||
public void SetViewports(ReadOnlySpan<Viewport> viewports, bool disableTransform)
|
||||
public void SetViewports(ReadOnlySpan<Viewport> viewports)
|
||||
{
|
||||
int maxViewports = Gd.Capabilities.SupportsMultiView ? Constants.MaxViewports : 1;
|
||||
int count = Math.Min(maxViewports, viewports.Length);
|
||||
|
@ -1328,19 +1300,6 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
Clamp(viewport.DepthFar)));
|
||||
}
|
||||
|
||||
float disableTransformF = disableTransform ? 1.0f : 0.0f;
|
||||
if (SupportBufferUpdater.Data.ViewportInverse.W != disableTransformF || disableTransform)
|
||||
{
|
||||
float scale = _renderScale[0].X;
|
||||
SupportBufferUpdater.UpdateViewportInverse(new Vector4<float>
|
||||
{
|
||||
X = scale * 2f / viewports[0].Region.Width,
|
||||
Y = scale * 2f / viewports[0].Region.Height,
|
||||
Z = 1,
|
||||
W = disableTransformF,
|
||||
});
|
||||
}
|
||||
|
||||
_newState.ViewportsCount = (uint)count;
|
||||
SignalStateChange();
|
||||
}
|
||||
|
@ -1391,32 +1350,6 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
TextureBarrier();
|
||||
}
|
||||
|
||||
public void UpdateRenderScale(ReadOnlySpan<float> scales, int totalCount, int fragmentCount)
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
for (int index = 0; index < totalCount; index++)
|
||||
{
|
||||
if (_renderScale[1 + index].X != scales[index])
|
||||
{
|
||||
_renderScale[1 + index].X = scales[index];
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Only update fragment count if there are scales after it for the vertex stage.
|
||||
if (fragmentCount != totalCount && fragmentCount != _fragmentScaleCount)
|
||||
{
|
||||
_fragmentScaleCount = fragmentCount;
|
||||
SupportBufferUpdater.UpdateFragmentRenderScaleCount(_fragmentScaleCount);
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
SupportBufferUpdater.UpdateRenderScale(_renderScale, 0, 1 + totalCount);
|
||||
}
|
||||
}
|
||||
|
||||
protected void SignalCommandBufferChange()
|
||||
{
|
||||
_needsIndexBufferRebind = true;
|
||||
|
@ -1614,9 +1547,6 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
|
||||
DynamicState.ReplayIfDirty(Gd.Api, CommandBuffer);
|
||||
|
||||
// Commit changes to the support buffer before drawing.
|
||||
SupportBufferUpdater.Commit();
|
||||
|
||||
if (_needsIndexBufferRebind && _indexBufferPattern == null)
|
||||
{
|
||||
_indexBuffer.BindIndexBuffer(Gd, Cbs);
|
||||
|
@ -1777,8 +1707,6 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
{
|
||||
Gd.Api.DestroyPipelineCache(Device, PipelineCache, null);
|
||||
}
|
||||
|
||||
SupportBufferUpdater.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@ namespace Ryujinx.Graphics.Vulkan.Queries
|
|||
}
|
||||
}
|
||||
|
||||
public CounterQueueEvent QueueReport(EventHandler<ulong> resultHandler, ulong lastDrawIndex, bool hostReserved)
|
||||
public CounterQueueEvent QueueReport(EventHandler<ulong> resultHandler, float divisor, ulong lastDrawIndex, bool hostReserved)
|
||||
{
|
||||
CounterQueueEvent result;
|
||||
ulong draws = lastDrawIndex - _current.DrawIndex;
|
||||
|
@ -146,7 +146,7 @@ namespace Ryujinx.Graphics.Vulkan.Queries
|
|||
_current.ReserveForHostAccess();
|
||||
}
|
||||
|
||||
_current.Complete(draws > 0 && Type != CounterType.TransformFeedbackPrimitivesWritten, _pipeline.GetCounterDivisor(Type));
|
||||
_current.Complete(draws > 0 && Type != CounterType.TransformFeedbackPrimitivesWritten, divisor);
|
||||
_events.Enqueue(_current);
|
||||
|
||||
_current.OnResult += resultHandler;
|
||||
|
|
|
@ -37,9 +37,9 @@ namespace Ryujinx.Graphics.Vulkan.Queries
|
|||
_counterQueues[(int)CounterType.SamplesPassed].ResetFutureCounters(cmd, count);
|
||||
}
|
||||
|
||||
public CounterQueueEvent QueueReport(CounterType type, EventHandler<ulong> resultHandler, bool hostReserved)
|
||||
public CounterQueueEvent QueueReport(CounterType type, EventHandler<ulong> resultHandler, float divisor, bool hostReserved)
|
||||
{
|
||||
return _counterQueues[(int)type].QueueReport(resultHandler, _pipeline.DrawCount, hostReserved);
|
||||
return _counterQueues[(int)type].QueueReport(resultHandler, divisor, _pipeline.DrawCount, hostReserved);
|
||||
}
|
||||
|
||||
public void QueueReset(CounterType type)
|
||||
|
|
|
@ -25,15 +25,12 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
|
||||
public VkFormat VkFormat { get; }
|
||||
|
||||
public float ScaleFactor { get; }
|
||||
|
||||
public TextureBuffer(VulkanRenderer gd, TextureCreateInfo info, float scale)
|
||||
public TextureBuffer(VulkanRenderer gd, TextureCreateInfo info)
|
||||
{
|
||||
_gd = gd;
|
||||
Width = info.Width;
|
||||
Height = info.Height;
|
||||
VkFormat = FormatTable.GetFormat(info.Format);
|
||||
ScaleFactor = scale;
|
||||
|
||||
gd.Textures.Add(this);
|
||||
}
|
||||
|
|
|
@ -54,19 +54,16 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
private readonly ulong _size;
|
||||
|
||||
public VkFormat VkFormat { get; }
|
||||
public float ScaleFactor { get; }
|
||||
|
||||
public unsafe TextureStorage(
|
||||
VulkanRenderer gd,
|
||||
Device device,
|
||||
TextureCreateInfo info,
|
||||
float scaleFactor,
|
||||
Auto<MemoryAllocation> foreignAllocation = null)
|
||||
{
|
||||
_gd = gd;
|
||||
_device = device;
|
||||
_info = info;
|
||||
ScaleFactor = scaleFactor;
|
||||
|
||||
var format = _gd.FormatCapabilities.ConvertToVkFormat(info.Format);
|
||||
var levels = (uint)info.Levels;
|
||||
|
@ -175,7 +172,7 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
|
||||
var info = NewCreateInfoWith(ref _info, format, _info.BytesPerPixel);
|
||||
|
||||
storage = new TextureStorage(_gd, _device, info, ScaleFactor, _allocationAuto);
|
||||
storage = new TextureStorage(_gd, _device, info, _allocationAuto);
|
||||
|
||||
_aliasedStorages.Add(format, storage);
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
public int Layers => Info.GetDepthOrLayers();
|
||||
public int FirstLayer { get; }
|
||||
public int FirstLevel { get; }
|
||||
public float ScaleFactor => Storage.ScaleFactor;
|
||||
public VkFormat VkFormat { get; }
|
||||
public bool Valid { get; private set; }
|
||||
|
||||
|
|
|
@ -432,26 +432,26 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
return new SamplerHolder(this, _device, info);
|
||||
}
|
||||
|
||||
public ITexture CreateTexture(TextureCreateInfo info, float scale)
|
||||
public ITexture CreateTexture(TextureCreateInfo info)
|
||||
{
|
||||
if (info.Target == Target.TextureBuffer)
|
||||
{
|
||||
return new TextureBuffer(this, info, scale);
|
||||
return new TextureBuffer(this, info);
|
||||
}
|
||||
|
||||
return CreateTextureView(info, scale);
|
||||
return CreateTextureView(info);
|
||||
}
|
||||
|
||||
internal TextureView CreateTextureView(TextureCreateInfo info, float scale)
|
||||
internal TextureView CreateTextureView(TextureCreateInfo info)
|
||||
{
|
||||
// This should be disposed when all views are destroyed.
|
||||
var storage = CreateTextureStorage(info, scale);
|
||||
var storage = CreateTextureStorage(info);
|
||||
return storage.CreateView(info, 0, 0);
|
||||
}
|
||||
|
||||
internal TextureStorage CreateTextureStorage(TextureCreateInfo info, float scale)
|
||||
internal TextureStorage CreateTextureStorage(TextureCreateInfo info)
|
||||
{
|
||||
return new TextureStorage(this, _device, info, scale);
|
||||
return new TextureStorage(this, _device, info);
|
||||
}
|
||||
|
||||
public void DeleteBuffer(BufferHandle buffer)
|
||||
|
@ -753,9 +753,9 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
SyncManager.Cleanup();
|
||||
}
|
||||
|
||||
public ICounterEvent ReportCounter(CounterType type, EventHandler<ulong> resultHandler, bool hostReserved)
|
||||
public ICounterEvent ReportCounter(CounterType type, EventHandler<ulong> resultHandler, float divisor, bool hostReserved)
|
||||
{
|
||||
return _counters.QueueReport(type, resultHandler, hostReserved);
|
||||
return _counters.QueueReport(type, resultHandler, divisor, hostReserved);
|
||||
}
|
||||
|
||||
public void ResetCounter(CounterType type)
|
||||
|
|
|
@ -294,12 +294,11 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
}
|
||||
|
||||
int srcX0, srcX1, srcY0, srcY1;
|
||||
float scale = view.ScaleFactor;
|
||||
|
||||
if (crop.Left == 0 && crop.Right == 0)
|
||||
{
|
||||
srcX0 = 0;
|
||||
srcX1 = (int)(view.Width / scale);
|
||||
srcX1 = view.Width;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -310,7 +309,7 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
if (crop.Top == 0 && crop.Bottom == 0)
|
||||
{
|
||||
srcY0 = 0;
|
||||
srcY1 = (int)(view.Height / scale);
|
||||
srcY1 = view.Height;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -318,14 +317,6 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
srcY1 = crop.Bottom;
|
||||
}
|
||||
|
||||
if (scale != 1f)
|
||||
{
|
||||
srcX0 = (int)(srcX0 * scale);
|
||||
srcY0 = (int)(srcY0 * scale);
|
||||
srcX1 = (int)Math.Ceiling(srcX1 * scale);
|
||||
srcY1 = (int)Math.Ceiling(srcY1 * scale);
|
||||
}
|
||||
|
||||
if (ScreenCaptureRequested)
|
||||
{
|
||||
if (_effect != null)
|
||||
|
|
Loading…
Reference in a new issue